зеркало из https://github.com/Azure/autorest.git
Resolve duplicate property name when deduplicating consecutive words (#4378)
This commit is contained in:
Родитель
4d8bb54469
Коммит
61e6986369
|
@ -0,0 +1,11 @@
|
||||||
|
{
|
||||||
|
"changes": [
|
||||||
|
{
|
||||||
|
"packageName": "@autorest/modelerfour",
|
||||||
|
"comment": "**Fix** issue with properties causing name conflict when consecutive words are deduplicated",
|
||||||
|
"type": "patch"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"packageName": "@autorest/modelerfour",
|
||||||
|
"email": "tiguerin@microsoft.com"
|
||||||
|
}
|
|
@ -169,9 +169,16 @@ export class PreNamer {
|
||||||
for (const schema of values(this.codeModel.schemas.objects)) {
|
for (const schema of values(this.codeModel.schemas.objects)) {
|
||||||
scopeNamer.add(schema, this.format.type, "");
|
scopeNamer.add(schema, this.format.type, "");
|
||||||
|
|
||||||
|
const propertyScopeName = new ScopeNamer(this.session, {
|
||||||
|
deduplicateNames: true,
|
||||||
|
overrides: this.format.override,
|
||||||
|
});
|
||||||
|
|
||||||
for (const property of values(schema.properties)) {
|
for (const property of values(schema.properties)) {
|
||||||
setName(property, this.format.property, "", this.format.override);
|
propertyScopeName.add(property, this.format.property, "");
|
||||||
|
// setName(property, this.format.property, "", this.format.override);
|
||||||
}
|
}
|
||||||
|
propertyScopeName.process();
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const schema of values(this.codeModel.schemas.groups)) {
|
for (const schema of values(this.codeModel.schemas.groups)) {
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { ChoiceSchema, CodeModel, ObjectSchema, Operation } from "@autorest/codemodel";
|
import { ChoiceSchema, CodeModel, ObjectSchema, Operation, Property, StringSchema } from "@autorest/codemodel";
|
||||||
import { ModelerFourOptions } from "modeler/modelerfour-options";
|
import { ModelerFourOptions } from "modeler/modelerfour-options";
|
||||||
import { PreNamer } from "../../src/prenamer/prenamer";
|
import { PreNamer } from "../../src/prenamer/prenamer";
|
||||||
import { createTestSessionFromModel } from "../utils";
|
import { createTestSessionFromModel } from "../utils";
|
||||||
|
@ -12,6 +12,8 @@ const runPrenamer = async (model: CodeModel, options: ModelerFourOptions = {}) =
|
||||||
|
|
||||||
describe("Prenamer", () => {
|
describe("Prenamer", () => {
|
||||||
let model: CodeModel;
|
let model: CodeModel;
|
||||||
|
const stringSchema = new StringSchema("", "");
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
model = new CodeModel("TestPrenamer");
|
model = new CodeModel("TestPrenamer");
|
||||||
});
|
});
|
||||||
|
@ -65,6 +67,52 @@ describe("Prenamer", () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("in objects properties", () => {
|
||||||
|
it("Remove duplicate consecutive words by default", async () => {
|
||||||
|
const schema = new ObjectSchema("MyObject", "Description");
|
||||||
|
schema.addProperty(new Property("fooBarBar", "desc", stringSchema));
|
||||||
|
model.schemas.add(schema);
|
||||||
|
const result = await runPrenamer(model);
|
||||||
|
const obj = result.schemas.objects?.[0];
|
||||||
|
expect(obj?.properties?.[0].language.default.name).toEqual("fooBar");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("Keeps duplicate consecutive words if the new name already exists", async () => {
|
||||||
|
const schema = new ObjectSchema("MyObject", "Description");
|
||||||
|
schema.addProperty(new Property("fooBar", "desc", stringSchema));
|
||||||
|
schema.addProperty(new Property("fooBarBar", "desc", stringSchema));
|
||||||
|
model.schemas.add(schema);
|
||||||
|
const result = await runPrenamer(model);
|
||||||
|
const obj = result.schemas.objects?.[0];
|
||||||
|
expect(obj?.properties?.[0].language.default.name).toEqual("fooBar");
|
||||||
|
expect(obj?.properties?.[1].language.default.name).toEqual("fooBarBar");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("Keeps duplicate consecutive words if the new name already exists and still style the word", async () => {
|
||||||
|
const schema = new ObjectSchema("MyObject", "Description");
|
||||||
|
schema.addProperty(new Property("fooBar", "desc", stringSchema));
|
||||||
|
schema.addProperty(new Property("fooBar-Bar", "desc", stringSchema));
|
||||||
|
model.schemas.add(schema);
|
||||||
|
const result = await runPrenamer(model);
|
||||||
|
const obj = result.schemas.objects?.[0];
|
||||||
|
expect(obj?.properties?.[0].language.default.name).toEqual("fooBar");
|
||||||
|
expect(obj?.properties?.[1].language.default.name).toEqual("fooBarBar");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("deduplicate property names if it can't find a better name", async () => {
|
||||||
|
const schema = new ObjectSchema("MyObject", "Description");
|
||||||
|
schema.addProperty(new Property("fooBar", "desc", stringSchema));
|
||||||
|
schema.addProperty(new Property("fooBarBar", "desc", stringSchema));
|
||||||
|
schema.addProperty(new Property("fooBar-Bar", "desc", stringSchema));
|
||||||
|
model.schemas.add(schema);
|
||||||
|
const result = await runPrenamer(model);
|
||||||
|
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");
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe("in operation names", () => {
|
describe("in operation names", () => {
|
||||||
it("Remove duplicate consecutive words by default", async () => {
|
it("Remove duplicate consecutive words by default", async () => {
|
||||||
model.getOperationGroup("foo").addOperation(
|
model.getOperationGroup("foo").addOperation(
|
||||||
|
|
Загрузка…
Ссылка в новой задаче