From 998475e88f1ce3c6e496e611250efd477dbcf2b0 Mon Sep 17 00:00:00 2001 From: Timothee Guerin Date: Mon, 6 Dec 2021 15:43:28 -0800 Subject: [PATCH] Fix: flattened properties causing duplicates (#4383) --- packages/extensions/core/package.json | 2 +- .../extensions/modelerfour/CHANGELOG.json | 12 ++++++++++++ packages/extensions/modelerfour/CHANGELOG.md | 9 ++++++++- packages/extensions/modelerfour/package.json | 2 +- .../modelerfour/src/prenamer/prenamer.ts | 3 +-- .../test/prenamer/prenamer.test.ts | 19 +++++++++++++++++-- packages/libs/oai2-to-oai3/CHANGELOG.json | 12 ++++++++++++ packages/libs/oai2-to-oai3/CHANGELOG.md | 9 ++++++++- packages/libs/oai2-to-oai3/package.json | 2 +- packages/libs/oai2-to-oai3/src/oai2/paths.ts | 2 +- regression-tests/regression-compare.yaml | 4 ++-- 11 files changed, 64 insertions(+), 12 deletions(-) diff --git a/packages/extensions/core/package.json b/packages/extensions/core/package.json index 004e381ea..7cadcce1d 100644 --- a/packages/extensions/core/package.json +++ b/packages/extensions/core/package.json @@ -53,7 +53,7 @@ "@azure-tools/extension": "~3.4.0", "@azure-tools/json": "~1.2.1", "@azure-tools/jsonschema": "~1.1.0", - "@azure-tools/oai2-to-oai3": "~4.5.0", + "@azure-tools/oai2-to-oai3": "~4.5.1", "@azure-tools/object-comparison": "~3.0.0", "@azure-tools/openapi": "~3.2.2", "@azure-tools/tasks": "~3.0.0", diff --git a/packages/extensions/modelerfour/CHANGELOG.json b/packages/extensions/modelerfour/CHANGELOG.json index ef143090a..2c0026368 100644 --- a/packages/extensions/modelerfour/CHANGELOG.json +++ b/packages/extensions/modelerfour/CHANGELOG.json @@ -1,6 +1,18 @@ { "name": "@autorest/modelerfour", "entries": [ + { + "version": "4.22.2", + "tag": "@autorest/modelerfour_v4.22.2", + "date": "Mon, 06 Dec 2021 20:16:04 GMT", + "comments": { + "patch": [ + { + "comment": "**Fix** Flattened models with duplicate properties using `AutoGenerated` name instead of flattened path based" + } + ] + } + }, { "version": "4.22.1", "tag": "@autorest/modelerfour_v4.22.1", diff --git a/packages/extensions/modelerfour/CHANGELOG.md b/packages/extensions/modelerfour/CHANGELOG.md index a9e300363..15b255528 100644 --- a/packages/extensions/modelerfour/CHANGELOG.md +++ b/packages/extensions/modelerfour/CHANGELOG.md @@ -1,6 +1,13 @@ # Change Log - @autorest/modelerfour -This log was last generated on Mon, 22 Nov 2021 21:55:51 GMT and should not be manually modified. +This log was last generated on Mon, 06 Dec 2021 20:16:04 GMT and should not be manually modified. + +## 4.22.2 +Mon, 06 Dec 2021 20:16:04 GMT + +### Patches + +- **Fix** Flattened models with duplicate properties using `AutoGenerated` name instead of flattened path based ## 4.22.1 Mon, 22 Nov 2021 21:55:51 GMT diff --git a/packages/extensions/modelerfour/package.json b/packages/extensions/modelerfour/package.json index a3a41538b..4d6f5b60e 100644 --- a/packages/extensions/modelerfour/package.json +++ b/packages/extensions/modelerfour/package.json @@ -1,6 +1,6 @@ { "name": "@autorest/modelerfour", - "version": "4.22.1", + "version": "4.22.2", "description": "AutoRest Modeler Version Four (component)", "directories": { "doc": "docs" diff --git a/packages/extensions/modelerfour/src/prenamer/prenamer.ts b/packages/extensions/modelerfour/src/prenamer/prenamer.ts index c2d4f5c7a..212719e98 100644 --- a/packages/extensions/modelerfour/src/prenamer/prenamer.ts +++ b/packages/extensions/modelerfour/src/prenamer/prenamer.ts @@ -170,13 +170,12 @@ export class PreNamer { scopeNamer.add(schema, this.format.type, ""); const propertyScopeName = new ScopeNamer(this.session, { - deduplicateNames: true, + deduplicateNames: false, overrides: this.format.override, }); for (const property of values(schema.properties)) { propertyScopeName.add(property, this.format.property, ""); - // setName(property, this.format.property, "", this.format.override); } propertyScopeName.process(); } diff --git a/packages/extensions/modelerfour/test/prenamer/prenamer.test.ts b/packages/extensions/modelerfour/test/prenamer/prenamer.test.ts index 040f23806..5fae4842f 100644 --- a/packages/extensions/modelerfour/test/prenamer/prenamer.test.ts +++ b/packages/extensions/modelerfour/test/prenamer/prenamer.test.ts @@ -99,7 +99,7 @@ describe("Prenamer", () => { expect(obj?.properties?.[1].language.default.name).toEqual("fooBarBar"); }); - it("deduplicate property names if it can't find a better name", async () => { + it("doesn't deduplicate property names if it can't find a better name. This is not supported", async () => { const schema = new ObjectSchema("MyObject", "Description"); schema.addProperty(new Property("fooBar", "desc", stringSchema)); schema.addProperty(new Property("fooBarBar", "desc", stringSchema)); @@ -109,7 +109,22 @@ describe("Prenamer", () => { const obj = result.schemas.objects?.[0]; expect(obj?.properties?.[0].language.default.name).toEqual("fooBar"); expect(obj?.properties?.[1].language.default.name).toEqual("fooBarBar"); - expect(obj?.properties?.[2].language.default.name).toEqual("fooBarBarAutoGenerated"); + expect(obj?.properties?.[2].language.default.name).toEqual("fooBarBar"); + }); + + it("deduplicate names if coming from flattened property", async () => { + const schema = new ObjectSchema("MyObject", "Description"); + schema.addProperty(new Property("foo", "desc", stringSchema)); + schema.addProperty( + new Property("foo", "desc", stringSchema, { + flattenedNames: ["nested", "foo"], + }), + ); + model.schemas.add(schema); + const result = await runPrenamer(model); + const obj = result.schemas.objects?.[0]; + expect(obj?.properties?.[0].language.default.name).toEqual("foo"); + expect(obj?.properties?.[1].language.default.name).toEqual("fooNestedFoo"); }); }); diff --git a/packages/libs/oai2-to-oai3/CHANGELOG.json b/packages/libs/oai2-to-oai3/CHANGELOG.json index d9df1b493..b3cd6315b 100644 --- a/packages/libs/oai2-to-oai3/CHANGELOG.json +++ b/packages/libs/oai2-to-oai3/CHANGELOG.json @@ -1,6 +1,18 @@ { "name": "@azure-tools/oai2-to-oai3", "entries": [ + { + "version": "4.5.1", + "tag": "@azure-tools/oai2-to-oai3_v4.5.1", + "date": "Mon, 06 Dec 2021 20:16:04 GMT", + "comments": { + "patch": [ + { + "comment": "**Internal** type fix" + } + ] + } + }, { "version": "4.5.0", "tag": "@azure-tools/oai2-to-oai3_v4.5.0", diff --git a/packages/libs/oai2-to-oai3/CHANGELOG.md b/packages/libs/oai2-to-oai3/CHANGELOG.md index 515d02eea..36c4abf95 100644 --- a/packages/libs/oai2-to-oai3/CHANGELOG.md +++ b/packages/libs/oai2-to-oai3/CHANGELOG.md @@ -1,6 +1,13 @@ # Change Log - @azure-tools/oai2-to-oai3 -This log was last generated on Fri, 19 Nov 2021 04:23:43 GMT and should not be manually modified. +This log was last generated on Mon, 06 Dec 2021 20:16:04 GMT and should not be manually modified. + +## 4.5.1 +Mon, 06 Dec 2021 20:16:04 GMT + +### Patches + +- **Internal** type fix ## 4.5.0 Fri, 19 Nov 2021 04:23:43 GMT diff --git a/packages/libs/oai2-to-oai3/package.json b/packages/libs/oai2-to-oai3/package.json index 1e3aba0ee..6f3137b45 100644 --- a/packages/libs/oai2-to-oai3/package.json +++ b/packages/libs/oai2-to-oai3/package.json @@ -1,6 +1,6 @@ { "name": "@azure-tools/oai2-to-oai3", - "version": "4.5.0", + "version": "4.5.1", "description": "OpenAPI2 to OpenAPI3 conversion library that maintains souremaps for use with AutoRest", "main": "./dist/src/index.js", "typings": "./dist/src/index.d.ts", diff --git a/packages/libs/oai2-to-oai3/src/oai2/paths.ts b/packages/libs/oai2-to-oai3/src/oai2/paths.ts index f09fd7188..6466ed8f8 100644 --- a/packages/libs/oai2-to-oai3/src/oai2/paths.ts +++ b/packages/libs/oai2-to-oai3/src/oai2/paths.ts @@ -10,7 +10,7 @@ export type HttpMethodCustom = "x-trace"; export type HttpMethod = "get" | "post" | "patch" | "put" | "delete" | "options" | "head" | "trace" | "x-trace"; export type OpenAPI2Path = { - [method in HttpMethod]: OpenAPI2Path; + [method in HttpMethod]: OpenAPI2Operation; } & { parameters: any[]; }; diff --git a/regression-tests/regression-compare.yaml b/regression-tests/regression-compare.yaml index ba18c32a8..3c146b62a 100644 --- a/regression-tests/regression-compare.yaml +++ b/regression-tests/regression-compare.yaml @@ -64,12 +64,12 @@ languages: oldArgs: - --version:3.6.2 - --use:@autorest/modelerfour@4.21.1 - - --use:@autorest/python@5.9.1 + - --use:@autorest/python@5.12.0 - --modelerfour.treat-type-object-as-anything newArgs: - --version:../packages/extensions/core - --use:../packages/extensions/modelerfour - - --use:@autorest/python@5.9.1 + - --use:@autorest/python@5.12.0 - --modelerfour.treat-type-object-as-anything - language: typescript