- 
                Notifications
    You must be signed in to change notification settings 
- Fork 317
Emit decorator list #3905
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
          
     Merged
      
      
    
  
     Merged
                    Emit decorator list #3905
Changes from all commits
      Commits
    
    
            Show all changes
          
          
            46 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      547d878
              
                add decorator field
              
              
                chunyu3 52e3975
              
                Merge branch 'main' of https://github.com/microsoft/typespec into emi…
              
              
                chunyu3 3fa1d91
              
                add Decorators field in inputModel
              
              
                chunyu3 5573a8a
              
                set additionalDecorators
              
              
                chunyu3 ad8c4c2
              
                Merge branch 'main' of https://github.com/microsoft/typespec into emi…
              
              
                chunyu3 301151c
              
                remove predefined decorator list
              
              
                chunyu3 8faa44c
              
                add decorator list in inputModel
              
              
                chunyu3 40cc2da
              
                update test
              
              
                chunyu3 d4fef8b
              
                Merge branch 'main' into emitDecorator
              
              
                chunyu3 c670145
              
                Merge branch 'main' into emitDecorator
              
              
                chunyu3 763c72a
              
                update emitter unit test
              
              
                chunyu3 79e9264
              
                Merge branch 'main' of https://github.com/microsoft/typespec into emi…
              
              
                chunyu3 287f9a0
              
                Merge branch 'main' into emitDecorator
              
              
                chunyu3 71c824c
              
                Merge branch 'main' of https://github.com/microsoft/typespec into emi…
              
              
                chunyu3 ea197fc
              
                regen
              
              
                chunyu3 8dc93e6
              
                Merge branch 'emitDecorator' of https://github.com/chunyu3/typespec i…
              
              
                chunyu3 217d5cd
              
                Merge branch 'main' of https://github.com/microsoft/typespec into emi…
              
              
                chunyu3 2209a51
              
                format
              
              
                chunyu3 f1c2493
              
                resolve comments
              
              
                chunyu3 8048701
              
                move decorated type to Input namespace
              
              
                chunyu3 5c27360
              
                add decorator list for client and operations
              
              
                chunyu3 94708d9
              
                Merge branch 'main' of https://github.com/microsoft/typespec into emi…
              
              
                chunyu3 3f83ee0
              
                don't pass down the decorator list when convert inputType to InputNul…
              
              
                chunyu3 00cf5ca
              
                Merge branch 'main' of https://github.com/microsoft/typespec into emi…
              
              
                chunyu3 1931848
              
                remove the createSdkContextOptions
              
              
                chunyu3 b97ad40
              
                update test
              
              
                chunyu3 f5dee16
              
                Merge branch 'main' into emitDecorator
              
              
                chunyu3 ae71642
              
                resolve test failure
              
              
                chunyu3 511b524
              
                Merge branch 'main' of https://github.com/microsoft/typespec into emi…
              
              
                chunyu3 b57c47f
              
                Merge branch 'main' of https://github.com/microsoft/typespec into emi…
              
              
                chunyu3 b682f28
              
                add unit test
              
              
                chunyu3 4d0fd38
              
                Merge branch 'main' of https://github.com/microsoft/typespec into emi…
              
              
                chunyu3 015e389
              
                set default value for decorators parameter in constructor
              
              
                chunyu3 e6af815
              
                refine test
              
              
                chunyu3 243e7ce
              
                Merge branch 'main' into emitDecorator
              
              
                chunyu3 403867f
              
                remove decorators parameter in input model client constructor
              
              
                chunyu3 4b75fe1
              
                Merge branch 'emitDecorator' of https://github.com/chunyu3/typespec i…
              
              
                chunyu3 9280ae9
              
                refine test
              
              
                chunyu3 f9f4c58
              
                Merge branch 'main' of https://github.com/microsoft/typespec into emi…
              
              
                chunyu3 eb63edc
              
                Merge branch 'main' of https://github.com/microsoft/typespec into emi…
              
              
                chunyu3 5b30017
              
                remove decorators parameter from constructor
              
              
                chunyu3 d58b79a
              
                regen test
              
              
                chunyu3 ad3fa9e
              
                remove unused import
              
              
                chunyu3 9d4308a
              
                use simple empty array
              
              
                chunyu3 1717e2d
              
                add reference resolve for TypeSpecInputDecoratorInfoConvertor
              
              
                chunyu3 5df28e7
              
                Merge branch 'main' of https://github.com/microsoft/typespec into emi…
              
              
                chunyu3 File filter
Filter by extension
Conversations
          Failed to load comments.   
        
        
          
      Loading
        
  Jump to
        
          Jump to file
        
      
      
          Failed to load files.   
        
        
          
      Loading
        
  Diff view
Diff view
There are no files selected for viewing
  
    
      This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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.
        
    
  
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
Uh oh!
There was an error while loading. Please reload this page.