-
Notifications
You must be signed in to change notification settings - Fork 226
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix #4031 When we specify the allowed-emit-decorators in emitter, TCGC will help to emit out decoration information for each item (client, property, operation), e.g final-state-var, our .NET input-Model need to contain this information. This PR will - emit decorators to all kind of models, operations and operations - add reference resolve strategy in TypeSpecInputDecoratorInfoConverter to support parse by reference
- Loading branch information
Showing
45 changed files
with
2,253 additions
and
1,141 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
packages/http-client-csharp/emitter/src/type/input-enum-type-value.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,11 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. See License.txt in the project root for license information. | ||
|
||
import { DecoratorInfo } from "@azure-tools/typespec-client-generator-core"; | ||
|
||
export interface InputEnumTypeValue { | ||
Name: string; | ||
Value: any; | ||
Description?: string; | ||
Decorators?: DecoratorInfo[]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
163 changes: 163 additions & 0 deletions
163
packages/http-client-csharp/emitter/test/Unit/emit-decorator-list.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,163 @@ | ||
import { TestHost } from "@typespec/compiler/testing"; | ||
import { deepStrictEqual, strictEqual } from "assert"; | ||
import { beforeEach, describe, it } from "vitest"; | ||
import { createModel } from "../../src/lib/client-model-builder.js"; | ||
import { | ||
createEmitterContext, | ||
createEmitterTestHost, | ||
createNetSdkContext, | ||
typeSpecCompile, | ||
} from "./utils/test-util.js"; | ||
|
||
describe("Test emitting decorator list", () => { | ||
let runner: TestHost; | ||
|
||
beforeEach(async () => { | ||
runner = await createEmitterTestHost(); | ||
}); | ||
|
||
it("emit decorator list on a client", async () => { | ||
const program = await typeSpecCompile( | ||
` | ||
@clientName("CsharpBookClient") | ||
interface BookClient { | ||
op test(): void; | ||
} | ||
`, | ||
runner, | ||
{ IsTCGCNeeded: true, IsXmlNeeded: true } | ||
); | ||
const context = createEmitterContext(program); | ||
const sdkContext = await createNetSdkContext(context, { | ||
additionalDecorators: ["Azure\\.ClientGenerator\\.Core\\.@clientName"], | ||
}); | ||
const root = createModel(sdkContext); | ||
const clients = root.Clients; | ||
strictEqual(clients.length, 2); | ||
deepStrictEqual(clients[1].Decorators, [ | ||
{ | ||
name: "Azure.ClientGenerator.Core.@clientName", | ||
arguments: { | ||
rename: "CsharpBookClient", | ||
}, | ||
}, | ||
]); | ||
}); | ||
|
||
it("emit decorator list on a operation", async () => { | ||
const program = await typeSpecCompile( | ||
` | ||
model Book { | ||
content: string; | ||
} | ||
@clientName("ClientTestOperation") | ||
op test(): Book; | ||
`, | ||
runner, | ||
{ IsTCGCNeeded: true, IsXmlNeeded: true } | ||
); | ||
const context = createEmitterContext(program); | ||
const sdkContext = await createNetSdkContext(context, { | ||
additionalDecorators: ["Azure\\.ClientGenerator\\.Core\\.@clientName"], | ||
}); | ||
const root = createModel(sdkContext); | ||
const operations = root.Clients[0].Operations; | ||
strictEqual(operations.length, 1); | ||
deepStrictEqual(operations[0].Decorators, [ | ||
{ | ||
name: "Azure.ClientGenerator.Core.@clientName", | ||
arguments: { | ||
rename: "ClientTestOperation", | ||
}, | ||
}, | ||
]); | ||
}); | ||
|
||
it("emit decorator list on a model", async () => { | ||
const program = await typeSpecCompile( | ||
` | ||
@clientName("ClientBook") | ||
model Book { | ||
content: string; | ||
} | ||
op test(): Book; | ||
`, | ||
runner, | ||
{ IsTCGCNeeded: true, IsXmlNeeded: true } | ||
); | ||
const context = createEmitterContext(program); | ||
const sdkContext = await createNetSdkContext(context, { | ||
additionalDecorators: ["Azure\\.ClientGenerator\\.Core\\.@clientName"], | ||
}); | ||
const root = createModel(sdkContext); | ||
const models = root.Models; | ||
strictEqual(models.length, 1); | ||
deepStrictEqual(models[0].Decorators, [ | ||
{ | ||
name: "Azure.ClientGenerator.Core.@clientName", | ||
arguments: { | ||
rename: "ClientBook", | ||
}, | ||
}, | ||
]); | ||
}); | ||
|
||
it("emit decorator list on a model property", async () => { | ||
const program = await typeSpecCompile( | ||
` | ||
model Book { | ||
@clientName("ClientContent") | ||
content: string; | ||
} | ||
op test(): Book; | ||
`, | ||
runner, | ||
{ IsTCGCNeeded: true, IsXmlNeeded: true } | ||
); | ||
const context = createEmitterContext(program); | ||
const sdkContext = await createNetSdkContext(context, { | ||
additionalDecorators: ["Azure\\.ClientGenerator\\.Core\\.@clientName"], | ||
}); | ||
const root = createModel(sdkContext); | ||
const models = root.Models; | ||
strictEqual(models.length, 1); | ||
deepStrictEqual(models[0].Properties[0].Decorators, [ | ||
{ | ||
name: "Azure.ClientGenerator.Core.@clientName", | ||
arguments: { | ||
rename: "ClientContent", | ||
}, | ||
}, | ||
]); | ||
}); | ||
|
||
it("emit decorator list on a parameter", async () => { | ||
const program = await typeSpecCompile( | ||
` | ||
@clientName("ClientTestOperation") | ||
op test(@clientName("ClientId") @header id: string): void; | ||
`, | ||
runner, | ||
{ IsTCGCNeeded: true, IsXmlNeeded: true } | ||
); | ||
const context = createEmitterContext(program); | ||
const sdkContext = await createNetSdkContext(context, { | ||
additionalDecorators: ["Azure\\.ClientGenerator\\.Core\\.@clientName"], | ||
}); | ||
const root = createModel(sdkContext); | ||
const operations = root.Clients[0].Operations; | ||
strictEqual(operations.length, 1); | ||
const idParameters = operations[0].Parameters.filter((p) => p.Name === "ClientId"); | ||
strictEqual(idParameters.length, 1); | ||
deepStrictEqual(idParameters[0].Decorators, [ | ||
{ | ||
name: "Azure.ClientGenerator.Core.@clientName", | ||
arguments: { | ||
rename: "ClientId", | ||
}, | ||
}, | ||
]); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.