Fix responses with `$ref` and array x-ms-client-name in array (#4525)

This commit is contained in:
Timothee Guerin 2022-05-02 12:25:59 -07:00 коммит произвёл GitHub
Родитель 34a9352054
Коммит a608c3d143
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
13 изменённых файлов: 174 добавлений и 9 удалений

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

@ -1,6 +1,21 @@
{
"name": "@autorest/core",
"entries": [
{
"version": "3.8.4",
"tag": "@autorest/core_v3.8.4",
"date": "Wed, 27 Apr 2022 18:53:11 GMT",
"comments": {
"patch": [
{
"comment": "Fix issue with using $ref in responses inserterting $ref in the parent."
},
{
"comment": "Fix issue with `x-ms-client-name` on inline array type."
}
]
}
},
{
"version": "3.8.3",
"tag": "@autorest/core_v3.8.3",

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

@ -1,6 +1,14 @@
# Change Log - @autorest/core
This log was last generated on Tue, 22 Mar 2022 20:26:28 GMT and should not be manually modified.
This log was last generated on Wed, 27 Apr 2022 18:53:11 GMT and should not be manually modified.
## 3.8.4
Wed, 27 Apr 2022 18:53:11 GMT
### Patches
- Fix issue with using $ref in responses inserterting $ref in the parent.
- "Fix issue with `x-ms-client-name` on inline array type.
## 3.8.3
Tue, 22 Mar 2022 20:26:28 GMT
@ -246,7 +254,7 @@ Fri, 09 Apr 2021 19:53:22 GMT
### Minor changes
- **Added** Semantic validator plugin
- **Added** Semantic validator plugin
- **Feature** Add sourcemap support for errors providing original location of problem
- **Added** support for emitting statistics of the specs and resuting model
@ -392,7 +400,7 @@ Tue, 4 Feb 2020 00:00:00 GMT
- rebuild to pick up latest data-store to fix the caching filename size
- OAI2-to-OAI3 converter update in perks.
- TransformerViaPointer was turning null into {}
- TransformerViaPointer was turning null into {}
- rebuild to fix NPM publishing problem.
- remove additionalProperties: false so v2 generators don't choke.
- rebuild to pick up perks change to fix multibyte utf8 over byte boundary problem

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

@ -1,6 +1,6 @@
{
"name": "@autorest/core",
"version": "3.8.3",
"version": "3.8.4",
"description": "AutoRest core module",
"engines": {
"node": ">=12.0.0"
@ -53,7 +53,7 @@
"@azure-tools/extension": "~3.5.0",
"@azure-tools/json": "~1.2.2",
"@azure-tools/jsonschema": "~1.2.0",
"@azure-tools/oai2-to-oai3": "~4.6.0",
"@azure-tools/oai2-to-oai3": "~4.6.1",
"@azure-tools/object-comparison": "~3.0.0",
"@azure-tools/openapi": "~3.3.0",
"@azure-tools/tasks": "~3.0.0",

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

@ -81,6 +81,30 @@ describe("Tree shaker", () => {
expect(result.components.schemas["FooItem"]["x-ms-client-name"]).toEqual("CustomFooClientItem");
});
it("remove x-ms-client-name on the extraced type on inline array type", async () => {
const result = await shake({
components: {
schemas: {
Foo: {
properties: {
prop: {
type: "array",
"x-ms-client-name": "CustomFooClientItem",
items: {
type: "object",
properties: {
name: { type: "string" },
},
},
},
},
},
},
},
});
expect(result.components.schemas["Foo-prop"]["x-ms-client-name"]).toBeUndefined();
});
it("removes x-ms-client-name on shaked model when used on property with inline model definition", async () => {
const result = await shake({
components: {

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

@ -477,6 +477,7 @@ export class OAI3Shaker extends Transformer<AnyObject, AnyObject> {
value,
children,
nameHint,
true,
);
}
}

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

@ -1,6 +1,18 @@
{
"name": "@azure-tools/oai2-to-oai3",
"entries": [
{
"version": "4.6.1",
"tag": "@azure-tools/oai2-to-oai3_v4.6.1",
"date": "Wed, 27 Apr 2022 18:53:11 GMT",
"comments": {
"patch": [
{
"comment": "Fix issue with using $ref in responses inserterting $ref in the parent"
}
]
}
},
{
"version": "4.6.0",
"tag": "@azure-tools/oai2-to-oai3_v4.6.0",

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

@ -1,6 +1,13 @@
# Change Log - @azure-tools/oai2-to-oai3
This log was last generated on Tue, 15 Mar 2022 16:00:38 GMT and should not be manually modified.
This log was last generated on Wed, 27 Apr 2022 18:53:11 GMT and should not be manually modified.
## 4.6.1
Wed, 27 Apr 2022 18:53:11 GMT
### Patches
- Fix issue with using $ref in responses inserterting $ref in the parent
## 4.6.0
Tue, 15 Mar 2022 16:00:38 GMT

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

@ -1,6 +1,6 @@
{
"name": "@azure-tools/oai2-to-oai3",
"version": "4.6.0",
"version": "4.6.1",
"description": "OpenAPI2 to OpenAPI3 conversion library that maintains souremaps for use with AutoRest",
"main": "./dist/index.js",
"typings": "./dist/index.d.ts",

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

@ -268,6 +268,7 @@ export class Oai2ToOai3 {
break;
}
}
return this.generated;
}
@ -1131,8 +1132,8 @@ export class Oai2ToOai3 {
) {
for (const { key, value, pointer, childIterator } of responsesItemMembers) {
target.__set__(key, this.newObject(pointer));
if (this.isTargetReference(target, value)) {
return this.copyRef(target, value, pointer);
if (this.isTargetReference(target[key], value)) {
return this.copyRef(target[key] as any, value, pointer);
} else if (isExtensionKey(key)) {
await this.visitExtensions(target[key], key, value, pointer);
} else {

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

@ -0,0 +1,39 @@
{
"servers": [],
"openapi": "3.0.0",
"info": {
"version": "1.0",
"title": "test",
"description": "Test"
},
"paths": {
"/calling": {
"delete": {
"tags": [
"Recording"
],
"summary": "Stop recording the call.",
"operationId": "ServerCalls_StopRecording",
"responses": {
"401": {
"$ref": "#/components/responses/401"
}
}
}
}
},
"components": {
"responses": {
"401": {
"description": "Unauthorized",
"content": {
"application/json": {
"schema": {
"type": "object"
}
}
}
}
}
}
}

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

@ -0,0 +1,22 @@
/openapi => /swagger
/info => /info
/info/version => /info/version
/info/title => /info/title
/info/description => /info/description
/paths => /paths
/paths/~1calling => /paths/~1calling
/paths/~1calling/delete => /paths/~1calling/delete
/paths/~1calling/delete/tags => /paths/~1calling/delete/tags
/paths/~1calling/delete/summary => /paths/~1calling/delete/summary
/paths/~1calling/delete/operationId => /paths/~1calling/delete/operationId
/paths/~1calling/delete/responses => /paths/~1calling/delete/responses
/paths/~1calling/delete/responses/401 => /paths/~1calling/delete/responses/401
/paths/~1calling/delete/responses/401/$ref => /paths/~1calling/delete/responses/401
/components => /responses
/components/responses => /responses
/components/responses/401 => /responses/401
/components/responses/401/description => /responses/401
/components/responses/401/content => /responses/401
/components/responses/401/content/application~1json => /responses/401
/components/responses/401/content/application~1json/schema => /responses/401
/components/responses/401/content/application~1json/schema/type => /responses/401/schema/type

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

@ -0,0 +1,32 @@
{
"swagger": "2.0",
"info": {
"version": "1.0",
"title": "test",
"description": "Test"
},
"produces": ["application/json"],
"consumes": ["application/json"],
"paths": {
"/calling": {
"delete": {
"tags": ["Recording"],
"summary": "Stop recording the call.",
"operationId": "ServerCalls_StopRecording",
"responses": {
"401": {
"$ref": "#/responses/401"
}
}
}
}
},
"responses": {
"401": {
"description": "Unauthorized",
"schema": {
"type": "object"
}
}
}
}

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

@ -101,4 +101,8 @@ describe("Scenario testings", () => {
],
});
});
it("responses using ref keep reference", async () => {
await expectInputsMatchSnapshots("responses-ref", ["swagger.json"]);
});
});