Fix tree shaked number enum to follow same logic as string enums (#4100)

This commit is contained in:
Timothee Guerin 2021-04-26 17:29:19 -07:00 коммит произвёл GitHub
Родитель 6d994fd0a5
Коммит 8579200012
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
8 изменённых файлов: 35 добавлений и 12 удалений

Просмотреть файл

@ -0,0 +1,11 @@
{
"changes": [
{
"packageName": "@autorest/configuration",
"comment": "",
"type": "none"
}
],
"packageName": "@autorest/configuration",
"email": "tiguerin@microsoft.com"
}

Просмотреть файл

@ -0,0 +1,11 @@
{
"changes": [
{
"packageName": "@autorest/core",
"comment": "**Fix** Tree Shaking number enums same as string enum. This allows those enum to get a better auto generated name if no name is provided",
"type": "patch"
}
],
"packageName": "@autorest/core",
"email": "tiguerin@microsoft.com"
}

Просмотреть файл

@ -179,7 +179,6 @@ async function currentMain(autorestArgs: Array<string>): Promise<number> {
const logger = new RootLogger();
const args = parseAutorestCliArgs([...autorestArgs, ...more], { logger });
console.error("Try require", more, args);
if (!args.options["message-format"] || args.options["message-format"] === "regular") {
console.log(color(`> Loading AutoRest core '${__dirname}' (${VERSION})`));

Просмотреть файл

@ -101,7 +101,7 @@ export class AutorestContextLoader {
...configs: AutorestRawConfiguration[]
): Promise<AutorestContext> {
const logger: AutorestLogger = new AutorestCoreLogger(
mergeConfigurations(...configs) as any,
mergeConfigurations(configs) as any,
messageEmitter,
AutorestLoggingSession,
);

Просмотреть файл

@ -5,7 +5,6 @@ import {
DataSink,
DataSource,
Node,
parseJsonPointer,
Transformer,
QuickDataSource,
JsonPath,
@ -16,6 +15,7 @@ import { PipelinePlugin } from "../../pipeline/common";
import { values, length } from "@azure-tools/linq";
import { createHash } from "crypto";
import { SchemaStats } from "../../stats";
import { parseJsonPointer } from "@azure-tools/json";
/**
* parses a json pointer, and inserts a string into the returned array
@ -509,11 +509,13 @@ export class OAI3Shaker extends Transformer<AnyObject, AnyObject> {
visitProperties(targetParent: AnyObject, originalNodes: Iterable<Node>, requiredProperties: Array<string>) {
for (const { value, key, pointer, children } of originalNodes) {
// if the property has a schema that type 'boolean', 'integer', 'number' then we'll just leave it inline
// we will leave strings inlined only if they ask for simple-tree-shake. Also, if it's a string + enum + required + single val enum
// if the property has a schema that type 'boolean' then we'll just leave it inline
// we will leave strings, number and integer inlined only if they ask for simple-tree-shake. Also, if it's a string + enum + required + single val enum
// reason: old modeler does not handle non-inlined string properties.
switch (value.type) {
case "string":
case "integer":
case "number":
if (this.isSimpleTreeShake) {
this.clone(targetParent, key, pointer, value);
} else {
@ -532,8 +534,6 @@ export class OAI3Shaker extends Transformer<AnyObject, AnyObject> {
}
break;
case "boolean":
case "integer":
case "number":
this.clone(targetParent, key, pointer, value);
break;
case "array":

Просмотреть файл

@ -22,7 +22,9 @@ export function parseAutorestCliArgs(cliArgs: string[], options: ParseAutorestCl
const configFileOrFolder = parsedArgs.positional[0];
const optionsAsObjects = parsedArgs.optionList.map(({ key, value }) => CreateObject(key.split("."), value));
const config = mergeConfigurations(AUTOREST_INITIAL_CONFIG, ...optionsAsObjects);
const config = mergeConfigurations([AUTOREST_INITIAL_CONFIG, ...optionsAsObjects.reverse()], {
arrayMergeStrategy: "low-pri-first",
});
const result = autorestConfigurationProcessor.processConfiguration(config, {
logger: options.logger,
});

Просмотреть файл

@ -110,7 +110,7 @@ export const extendAutorestConfiguration = (
config: AutorestConfiguration,
overrides: AutorestNormalizedConfiguration[],
): AutorestConfiguration => {
const rawConfig = mergeConfigurations(...overrides, config.raw);
const rawConfig = mergeConfigurations([...overrides, config.raw]);
const newConfig = createConfigFromRawConfig(config.configFileFolderUri, rawConfig, config.configurationFiles);
newConfig.inputFileUris = config.inputFileUris;
return newConfig;

Просмотреть файл

@ -1,5 +1,5 @@
import { mergeOverwriteOrAppend } from "@autorest/common";
import { MergeOptions, mergeOverwriteOrAppend } from "@autorest/common";
export function mergeConfigurations<T>(...configs: Array<T>): T {
return configs.reduce((result, config) => mergeOverwriteOrAppend(result, config), {}) as T;
export function mergeConfigurations<T>(configs: Array<T>, options: MergeOptions = {}): T {
return configs.reduce((result, config) => mergeOverwriteOrAppend(result, config), options) as T;
}