Fix: flattened properties causing duplicates (#4383)

This commit is contained in:
Timothee Guerin 2021-12-06 15:43:28 -08:00 коммит произвёл GitHub
Родитель 6ae7291dcf
Коммит 998475e88f
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
11 изменённых файлов: 64 добавлений и 12 удалений

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

@ -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",

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

@ -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",

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

@ -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

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

@ -1,6 +1,6 @@
{
"name": "@autorest/modelerfour",
"version": "4.22.1",
"version": "4.22.2",
"description": "AutoRest Modeler Version Four (component)",
"directories": {
"doc": "docs"

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

@ -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();
}

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

@ -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");
});
});

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

@ -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",

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

@ -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

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

@ -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",

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

@ -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[];
};

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

@ -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