Add put x-ms-original-file injection behind flag (#4305)

* original file location behind flag

* Changes
This commit is contained in:
Timothee Guerin 2021-09-24 08:39:39 -07:00 коммит произвёл GitHub
Родитель e2acd6c223
Коммит d0a7293a7b
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
11 изменённых файлов: 73 добавлений и 14 удалений

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

@ -40,8 +40,8 @@
},
"typings": "./dist/exports.d.ts",
"devDependencies": {
"@autorest/configuration": "~1.7.1",
"@autorest/core": "~3.6.2",
"@autorest/configuration": "~1.7.2",
"@autorest/core": "~3.6.3",
"@autorest/common": "~1.3.0",
"@azure-tools/async-io": "~3.0.0",
"@azure-tools/extension": "~3.3.1",

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

@ -1,6 +1,23 @@
{
"name": "@autorest/core",
"entries": [
{
"version": "3.6.3",
"tag": "@autorest/core_v3.6.3",
"date": "Thu, 23 Sep 2021 19:51:32 GMT",
"comments": {
"patch": [
{
"comment": "**Added** `include-x-ms-examples-original-file` flag to activate `x-ms-original-file` injection in `x-ms-examples`"
}
],
"dependency": [
{
"comment": "Updating dependency \"@autorest/configuration\" from `~1.7.1` to `~1.7.2`"
}
]
}
},
{
"version": "3.6.2",
"tag": "@autorest/core_v3.6.2",

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

@ -1,6 +1,13 @@
# Change Log - @autorest/core
This log was last generated on Fri, 17 Sep 2021 17:52:01 GMT and should not be manually modified.
This log was last generated on Thu, 23 Sep 2021 19:51:32 GMT and should not be manually modified.
## 3.6.3
Thu, 23 Sep 2021 19:51:32 GMT
### Patches
- **Added** `include-x-ms-examples-original-file` flag to activate `x-ms-original-file` injection in `x-ms-examples`
## 3.6.2
Fri, 17 Sep 2021 17:52:01 GMT

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

@ -1,6 +1,6 @@
{
"name": "@autorest/core",
"version": "3.6.2",
"version": "3.6.3",
"description": "AutoRest core module",
"engines": {
"node": ">=12.0.0"
@ -43,7 +43,7 @@
"typings": "./dist/exports.d.ts",
"devDependencies": {
"@autorest/common": "~1.3.0",
"@autorest/configuration": "~1.7.1",
"@autorest/configuration": "~1.7.2",
"@autorest/schemas": "~1.3.1",
"@autorest/test-utils": "~0.4.0",
"@azure-tools/async-io": "~3.0.0",

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

@ -1,10 +1,9 @@
import { AnyObject, DataHandle, DataSink, DataSource, Node, Transformer, visit } from "@azure-tools/datastore";
import { resolveUri } from "@azure-tools/uri";
import { AutorestContext } from "../context";
import { Channel } from "../message";
export async function crawlReferences(
config: AutorestContext,
context: AutorestContext,
inputScope: DataSource,
filesToCrawl: Array<DataHandle>,
sink: DataSink,
@ -21,13 +20,15 @@ export async function crawlReferences(
/** crawls a file for $refs and then recurses to get the $ref'd files */
async function crawl(file: DataHandle) {
const refProcessor = new RefProcessor(file, inputScope);
const refProcessor = new RefProcessor(file, inputScope, {
includeXmsExamplesOriginalFileLocation: context.config["include-x-ms-examples-original-file"],
});
const output = await refProcessor.getOutput();
for (const fileUri of [...refProcessor.filesReferenced].filter((each) => !queued.has(each))) {
queued.add(fileUri);
config.verbose(`Reading $ref'd file ${fileUri}`);
context.verbose(`Reading $ref'd file ${fileUri}`);
const secondaryFile = await inputScope.readStrict(fileUri);
// mark secondary files with a tag so that we don't process operations for them.
@ -77,12 +78,16 @@ export async function crawlReferences(
return [...primary, ...secondary];
}
interface RefProcessorOptions {
includeXmsExamplesOriginalFileLocation?: boolean;
}
class RefProcessor extends Transformer<any, any> {
public promises = new Array<Promise<void>>();
public filesReferenced = new Set<string>();
private originalFileLocation: string;
constructor(originalFile: DataHandle, private inputScope: DataSource) {
constructor(originalFile: DataHandle, private inputScope: DataSource, private options: RefProcessorOptions = {}) {
super(originalFile);
this.originalFileLocation = resolveUri(originalFile.originalDirectory, originalFile.identity[0]);
@ -98,7 +103,9 @@ class RefProcessor extends Transformer<any, any> {
const refUri = resolveUri(this.originalFileLocation, refPath);
const handle = await this.inputScope.readStrict(refUri);
const exampleData = await handle.readObject<AnyObject>();
xmsExamples[key] = { ...exampleData, "x-ms-original-file": refUri };
xmsExamples[key] = this.options.includeXmsExamplesOriginalFileLocation
? { ...exampleData, "x-ms-original-file": refUri }
: exampleData;
} catch {
// skip examples that are not nice to us.
}

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

@ -1,6 +1,18 @@
{
"name": "@autorest/configuration",
"entries": [
{
"version": "1.7.2",
"tag": "@autorest/configuration_v1.7.2",
"date": "Thu, 23 Sep 2021 19:51:32 GMT",
"comments": {
"patch": [
{
"comment": "**Added** `include-x-ms-examples-original-file` flag to activate `x-ms-original-file` injection in `x-ms-examples`"
}
]
}
},
{
"version": "1.7.1",
"tag": "@autorest/configuration_v1.7.1",

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

@ -1,6 +1,13 @@
# Change Log - @autorest/configuration
This log was last generated on Wed, 22 Sep 2021 15:23:39 GMT and should not be manually modified.
This log was last generated on Thu, 23 Sep 2021 19:51:32 GMT and should not be manually modified.
## 1.7.2
Thu, 23 Sep 2021 19:51:32 GMT
### Patches
- **Added** `include-x-ms-examples-original-file` flag to activate `x-ms-original-file` injection in `x-ms-examples`
## 1.7.1
Wed, 22 Sep 2021 15:23:39 GMT

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

@ -1,6 +1,6 @@
{
"name": "@autorest/configuration",
"version": "1.7.1",
"version": "1.7.2",
"description": "Autorest configuration",
"main": "dist/index.js",
"typings": "dist/index.d.ts",

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

@ -86,6 +86,11 @@ export interface AutorestNormalizedConfiguration extends AutorestRawConfiguratio
*/
eol?: "default" | "lf" | "crlf";
/**
* Include x-ms-original-file property to x-ms-examples to get path to the original file where example was.
*/
"include-x-ms-examples-original-file"?: boolean;
/**
* Feature flags. Those flags enable/disable certain features
*/

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

@ -66,6 +66,10 @@ export const AUTOREST_CONFIGURATION_SCHEMA = {
description: "Force updating the version of core even if there is a local version satisfying the requirement.",
},
memory: { type: "string", description: "Configure max memory allowed for autorest process(s)" },
"include-x-ms-examples-original-file": {
type: "boolean",
description: "Include x-ms-original-file property in x-ms-examples",
},
// Feature flags
"deduplicate-inline-models": { type: "boolean" },

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

@ -30,7 +30,7 @@
},
"homepage": "https://github.com/Azure/autorest#readme",
"dependencies": {
"@autorest/core": "~3.6.2",
"@autorest/core": "~3.6.3",
"autorest": "~3.4.0",
"source-map-support": "^0.5.19"
},