From c7a152e93ca07a9785b3a0c19fba66295552eed5 Mon Sep 17 00:00:00 2001 From: pshao25 <97225342+pshao25@users.noreply.github.com> Date: Fri, 3 Feb 2023 13:35:50 +0800 Subject: [PATCH 1/4] Support isProtocol and isConvenient decorator --- eng/Generate.ps1 | 2 +- samples/AnomalyDetector/Generated/cadl.json | 10 + samples/AnomalyDetector/client.cadl | 20 +- .../Common/Input/CodeModelConverter.cs | 1 + src/AutoRest.CSharp/Common/Input/Inputs.cs | 2 + .../Output/Models/CmcRestClientBuilder.cs | 1 + .../Output/OperationMethodChainBuilder.cs | 6 +- .../Emitter.Csharp/src/emitter.ts | 35 ++-- .../Emitter.Csharp/src/type/InputOperation.ts | 1 + .../TestProjects/interface/interface.cadl | 2 +- .../api-key/Generated/cadl.json | 2 + .../inheritance/Generated/cadl.json | 9 + .../inheritance/inheritance-cadl.cadl | 18 +- .../oauth2/Generated/cadl.json | 2 + .../property-optional/Generated/cadl.json | 28 +++ .../property-types/Generated/cadl.json | 30 +++ .../ApiVersion-Cadl/ApiVersion-Cadl.cadl | 2 +- .../ApiVersion-Cadl/Generated/cadl.json | 1 + .../Authoring-Cadl/Authoring-Cadl.cadl | 4 +- .../Authoring-Cadl/Generated/cadl.json | 16 ++ .../Generated/cadl.json | 6 + .../Customizations-Cadl.cadl | 2 +- .../Customizations-Cadl/Generated/cadl.json | 1 + .../FirstTest-Cadl/FirstTest-Cadl.cadl | 28 ++- .../Generated/CadlFirstTestClient.cs | 186 +++++++++++++++++ .../Generated/Docs/CadlFirstTestClient.xml | 124 ++++++++++++ .../FirstTest-Cadl/Generated/cadl.json | 187 +++++++++++++++++- .../Lro-Basic-Cadl/Generated/cadl.json | 3 + .../Lro-Basic-Cadl/Lro-Basic-Cadl.cadl | 8 +- .../MixAPIVersion-Cadl/Generated/cadl.json | 4 + .../Models-Cadl/Generated/cadl.json | 9 + .../TestProjects/Models-Cadl/Models-Cadl.cadl | 18 +- .../Pagination-Cadl/Generated/cadl.json | 2 + .../Pagination-Cadl/Pagination-Cadl.cadl | 4 +- .../Parameters-Cadl/Generated/cadl.json | 2 + .../Parameters-Cadl/Parameters-Cadl.cadl | 4 +- .../PetStore-Cadl/Generated/cadl.json | 5 + .../PetStore-Cadl/PetStore-Cadl.cadl | 10 +- .../RenameGetList-Cadl/Generated/cadl.json | 4 + .../Spread-Cadl/Generated/cadl.json | 5 + .../TestProjects/Spread-Cadl/Spread-Cadl.cadl | 10 +- 41 files changed, 737 insertions(+), 77 deletions(-) diff --git a/eng/Generate.ps1 b/eng/Generate.ps1 index b5ae5e897a0..3420b1075db 100644 --- a/eng/Generate.ps1 +++ b/eng/Generate.ps1 @@ -19,7 +19,7 @@ $sharedSource = Join-Path $repoRoot 'src' 'assets' $configurationPath = Join-Path $repoRoot 'readme.md' $testServerSwaggerPath = Join-Path $repoRoot 'node_modules' '@microsoft.azure' 'autorest.testserver' 'swagger' $cadlRanchFilePath = Join-Path $repoRoot 'node_modules' '@azure-tools' 'cadl-ranch-specs' 'http' -$cadlEmitOptions = '--option @azure-tools/cadl-csharp.save-inputs=true --option @azure-tools/cadl-csharp.clear-output-folder=true' +$cadlEmitOptions = '--option @azure-tools/cadl-csharp.save-inputs=true --option @azure-tools/cadl-csharp.clear-output-folder=true --option @azure-tools/cadl-csharp.generate-convenience-methods=false' function Add-Swagger ([string]$name, [string]$output, [string]$arguments) { $swaggerDefinitions[$name] = @{ diff --git a/samples/AnomalyDetector/Generated/cadl.json b/samples/AnomalyDetector/Generated/cadl.json index fd14b27df1e..30dd9d4e045 100644 --- a/samples/AnomalyDetector/Generated/cadl.json +++ b/samples/AnomalyDetector/Generated/cadl.json @@ -2211,6 +2211,7 @@ "application/json" ], "BufferResponse": true, + "GenerateProtocolMethod": true, "GenerateConvenienceMethod": true }, { @@ -2321,6 +2322,7 @@ "application/json" ], "BufferResponse": true, + "GenerateProtocolMethod": true, "GenerateConvenienceMethod": true }, { @@ -2431,6 +2433,7 @@ "application/json" ], "BufferResponse": true, + "GenerateProtocolMethod": true, "GenerateConvenienceMethod": true }, { @@ -2514,6 +2517,7 @@ "Uri": "{Endpoint}/anomalydetector/{ApiVersion}", "Path": "/multivariate/detect-batch/{resultId}", "BufferResponse": true, + "GenerateProtocolMethod": true, "GenerateConvenienceMethod": true }, { @@ -2637,6 +2641,7 @@ "application/json" ], "BufferResponse": true, + "GenerateProtocolMethod": true, "GenerateConvenienceMethod": true }, { @@ -2746,6 +2751,7 @@ "NextLinkName": "nextLink", "ItemName": "models" }, + "GenerateProtocolMethod": true, "GenerateConvenienceMethod": true }, { @@ -2826,6 +2832,7 @@ "Uri": "{Endpoint}/anomalydetector/{ApiVersion}", "Path": "/multivariate/models/{modelId}", "BufferResponse": true, + "GenerateProtocolMethod": true, "GenerateConvenienceMethod": true }, { @@ -2909,6 +2916,7 @@ "Uri": "{Endpoint}/anomalydetector/{ApiVersion}", "Path": "/multivariate/models/{modelId}", "BufferResponse": true, + "GenerateProtocolMethod": true, "GenerateConvenienceMethod": true }, { @@ -3065,6 +3073,7 @@ "application/json" ], "BufferResponse": true, + "GenerateProtocolMethod": true, "GenerateConvenienceMethod": true }, { @@ -3196,6 +3205,7 @@ "application/json" ], "BufferResponse": true, + "GenerateProtocolMethod": true, "GenerateConvenienceMethod": true } ], diff --git a/samples/AnomalyDetector/client.cadl b/samples/AnomalyDetector/client.cadl index a96c92e747b..3801beafead 100644 --- a/samples/AnomalyDetector/client.cadl +++ b/samples/AnomalyDetector/client.cadl @@ -3,14 +3,14 @@ import "./main.cadl"; using Azure.DPG; -@@convenienceAPI(AnomalyDetector.Multivariate.GetMultivariateBatchDetectionResult) -@@convenienceAPI(AnomalyDetector.Multivariate.TrainMultivariateModel) -@@convenienceAPI(AnomalyDetector.Multivariate.ListMultivariateModels) -@@convenienceAPI(AnomalyDetector.Multivariate.DeleteMultivariateModel) -@@convenienceAPI(AnomalyDetector.Multivariate.GetMultivariateModel) -@@convenienceAPI(AnomalyDetector.Multivariate.DetectMultivariateBatchAnomaly) -@@convenienceAPI(AnomalyDetector.Multivariate.DetectMultivariateLastAnomaly) +@@convenientAPI(AnomalyDetector.Multivariate.GetMultivariateBatchDetectionResult, true) +@@convenientAPI(AnomalyDetector.Multivariate.TrainMultivariateModel, true) +@@convenientAPI(AnomalyDetector.Multivariate.ListMultivariateModels, true) +@@convenientAPI(AnomalyDetector.Multivariate.DeleteMultivariateModel, true) +@@convenientAPI(AnomalyDetector.Multivariate.GetMultivariateModel, true) +@@convenientAPI(AnomalyDetector.Multivariate.DetectMultivariateBatchAnomaly, true) +@@convenientAPI(AnomalyDetector.Multivariate.DetectMultivariateLastAnomaly, true) -@@convenienceAPI(AnomalyDetector.Univariate.DetectUnivariateEntireSeries) -@@convenienceAPI(AnomalyDetector.Univariate.DetectUnivariateLastPoint) -@@convenienceAPI(AnomalyDetector.Univariate.DetectUnivariateChangePoint) +@@convenientAPI(AnomalyDetector.Univariate.DetectUnivariateEntireSeries, true) +@@convenientAPI(AnomalyDetector.Univariate.DetectUnivariateLastPoint, true) +@@convenientAPI(AnomalyDetector.Univariate.DetectUnivariateChangePoint, true) diff --git a/src/AutoRest.CSharp/Common/Input/CodeModelConverter.cs b/src/AutoRest.CSharp/Common/Input/CodeModelConverter.cs index ce69fbb5b96..1de48810052 100644 --- a/src/AutoRest.CSharp/Common/Input/CodeModelConverter.cs +++ b/src/AutoRest.CSharp/Common/Input/CodeModelConverter.cs @@ -102,6 +102,7 @@ private InputOperation CreateOperation(ServiceRequest serviceRequest, Operation BufferResponse: operation.Extensions?.BufferResponse ?? true, LongRunning: CreateLongRunning(operation), Paging: CreateOperationPaging(operation), + GenerateProtocolMethod: true, GenerateConvenienceMethod: false); _inputOperationToOperationMap[inputOperation] = operation; diff --git a/src/AutoRest.CSharp/Common/Input/Inputs.cs b/src/AutoRest.CSharp/Common/Input/Inputs.cs index 11f3d39a494..02d31cb676d 100644 --- a/src/AutoRest.CSharp/Common/Input/Inputs.cs +++ b/src/AutoRest.CSharp/Common/Input/Inputs.cs @@ -62,6 +62,7 @@ internal record InputOperation( bool BufferResponse, OperationLongRunning? LongRunning, OperationPaging? Paging, + bool GenerateProtocolMethod, bool GenerateConvenienceMethod) { public InputOperation() : this( @@ -82,6 +83,7 @@ public InputOperation() : this( BufferResponse: false, LongRunning: null, Paging: null, + GenerateProtocolMethod: true, GenerateConvenienceMethod: false) { } } diff --git a/src/AutoRest.CSharp/Common/Output/Models/CmcRestClientBuilder.cs b/src/AutoRest.CSharp/Common/Output/Models/CmcRestClientBuilder.cs index 27ee8916884..7f9edbd92e5 100644 --- a/src/AutoRest.CSharp/Common/Output/Models/CmcRestClientBuilder.cs +++ b/src/AutoRest.CSharp/Common/Output/Models/CmcRestClientBuilder.cs @@ -142,6 +142,7 @@ private InputOperation CreateInputOperation(Operation operation) BufferResponse: operation.Extensions?.BufferResponse ?? true, LongRunning: null, Paging: CreateOperationPaging(operation), + true, false); } return new InputOperation(); diff --git a/src/AutoRest.CSharp/LowLevel/Output/OperationMethodChainBuilder.cs b/src/AutoRest.CSharp/LowLevel/Output/OperationMethodChainBuilder.cs index 914b29d02fc..1be2794ee11 100644 --- a/src/AutoRest.CSharp/LowLevel/Output/OperationMethodChainBuilder.cs +++ b/src/AutoRest.CSharp/LowLevel/Output/OperationMethodChainBuilder.cs @@ -85,7 +85,8 @@ public LowLevelClientMethod BuildOperationMethodChain() ? new[] { new CSharpAttribute(typeof(ObsoleteAttribute), deprecated) } : Array.Empty(); var protocolMethodParameters = _orderedParameters.Select(p => p.Protocol).WhereNotNull().ToArray(); - var protocolMethodSignature = new MethodSignature(_restClientMethod.Name, _restClientMethod.Summary, _restClientMethod.Description, _restClientMethod.Accessibility | Virtual, returnTypeChain.Protocol, null, protocolMethodParameters, protocolMethodAttributes); + var protocolMethodModifiers = (Operation.GenerateProtocolMethod ? _restClientMethod.Accessibility : MethodSignatureModifiers.Internal) | Virtual; + var protocolMethodSignature = new MethodSignature(_restClientMethod.Name, _restClientMethod.Summary, _restClientMethod.Description, protocolMethodModifiers, returnTypeChain.Protocol, null, protocolMethodParameters, protocolMethodAttributes); var convenienceMethod = ShouldConvenienceMethodGenerated(returnTypeChain) ? BuildConvenienceMethod(returnTypeChain) : null; var diagnostic = new Diagnostic($"{_clientName}.{_restClientMethod.Name}"); @@ -98,7 +99,8 @@ public LowLevelClientMethod BuildOperationMethodChain() private bool ShouldConvenienceMethodGenerated(ReturnTypeChain returnTypeChain) { return Operation.GenerateConvenienceMethod - && (_orderedParameters.Where(parameter => parameter.Convenience != KnownParameters.CancellationTokenParameter).Any(parameter => !IsParameterTypeSame(parameter.Convenience, parameter.Protocol)) + && (!Operation.GenerateProtocolMethod + || _orderedParameters.Where(parameter => parameter.Convenience != KnownParameters.CancellationTokenParameter).Any(parameter => !IsParameterTypeSame(parameter.Convenience, parameter.Protocol)) || !returnTypeChain.Convenience.Equals(returnTypeChain.Protocol)); } diff --git a/src/CADL.Extension/Emitter.Csharp/src/emitter.ts b/src/CADL.Extension/Emitter.Csharp/src/emitter.ts index 4eccd387213..549bbe3a4ec 100644 --- a/src/CADL.Extension/Emitter.Csharp/src/emitter.ts +++ b/src/CADL.Extension/Emitter.Csharp/src/emitter.ts @@ -77,13 +77,16 @@ import { dllFilePath } from "@autorest/csharp"; import { execSync } from "child_process"; import { Client, + createDpgContext, getConvenienceAPIName, isApiVersion, isOperationGroup, listClients, listOperationGroups, listOperationsInOperationGroup, - OperationGroup + OperationGroup, + shouldGenerateConvenient, + shouldGenerateProtocol } from "@azure-tools/cadl-dpg"; import { ClientKind } from "./type/ClientKind.js"; import { getVersions } from "@cadl-lang/versioning"; @@ -107,6 +110,9 @@ export interface NetEmitterOptions { "clear-output-folder"?: boolean; "save-inputs"?: boolean; "model-namespace"?: boolean; + "generate-protocol-methods"?: boolean; + "generate-convenience-methods"?: boolean; + "package-name"?: string; } const defaultOptions = { @@ -143,7 +149,10 @@ const NetEmitterOptionsSchema: JSONSchemaType = { }, "clear-output-folder": { type: "boolean", nullable: true }, "save-inputs": { type: "boolean", nullable: true }, - "model-namespace": { type: "boolean", nullable: true } + "model-namespace": { type: "boolean", nullable: true }, + "generate-protocol-methods": { type: "boolean", nullable: true }, + "generate-convenience-methods": { type: "boolean", nullable: true }, + "package-name": { type: "string", nullable: true } }, required: [] }; @@ -161,7 +170,6 @@ export async function $onEmit(context: EmitContext) { const emitterOptions = context.options; const emitterOutputDir = context.emitterOutputDir; const resolvedOptions = { ...defaultOptions, ...emitterOptions }; - const resolvedSharedFolders: string[] = []; const outputFolder = resolvePath(emitterOutputDir ?? "./cadl-output"); const options: NetEmitterOptions = { outputFile: resolvePath(outputFolder, resolvedOptions.outputFile), @@ -179,12 +187,12 @@ export async function $onEmit(context: EmitContext) { "save-inputs": resolvedOptions["save-inputs"], "model-namespace": resolvedOptions["model-namespace"] }; - const version: string = ""; + if (!program.compilerOptions.noEmit && !program.hasError()) { // Write out the dotnet model to the output path const namespace = getServiceNamespaceString(program) || ""; - const root = createModel(program, options.generateConvenienceAPI); + const root = createModel(context, options.generateConvenienceAPI); // await program.host.writeFile(outPath, prettierOutput(JSON.stringify(root, null, 2))); if (root) { const generatedFolder = resolvePath(outputFolder, "Generated"); @@ -296,9 +304,10 @@ function getClient( } function createModel( - program: Program, + context: EmitContext, generateConvenienceAPI: boolean = false ): any { + const program = context.program; const serviceNamespaceType = getServiceNamespace(program); if (!serviceNamespaceType) { return; @@ -489,7 +498,7 @@ function createModel( getHttpOperation(program, op) ); const inputOperation: InputOperation = loadOperation( - program, + context, httpOperation, url, urlParameters, @@ -677,13 +686,14 @@ function getOperationGroupName(program: Program, operation: Operation): string { } function loadOperation( - program: Program, + context: EmitContext, operation: HttpOperation, uri: string, urlParameters: InputParameter[] | undefined = undefined, models: Map, enums: Map ): InputOperation { + const program = context.program; const { path: fullPath, operation: op, @@ -758,10 +768,8 @@ function loadOperation( mediaTypes.push(contentTypeParameter.DefaultValue?.Value); } const requestMethod = parseHttpRequestMethod(verb); - const convenienceApiDecorator: boolean = - getConvenienceAPIName(program, op) !== undefined; - const generateConvenienceMethod: boolean = - requestMethod !== RequestMethod.PATCH && convenienceApiDecorator; + const generateProtocol: boolean = shouldGenerateProtocol(createDpgContext(context), op); + const generateConvenience: boolean = requestMethod !== RequestMethod.PATCH && (shouldGenerateConvenient(createDpgContext(context), op) || getConvenienceAPIName(program, op) !== undefined); /* handle lro */ /* handle paging. */ @@ -811,7 +819,8 @@ function loadOperation( resourceOperation ), Paging: paging, - GenerateConvenienceMethod: generateConvenienceMethod + GenerateProtocolMethod: generateProtocol, + GenerateConvenienceMethod: generateConvenience } as InputOperation; function loadOperationParameter( diff --git a/src/CADL.Extension/Emitter.Csharp/src/type/InputOperation.ts b/src/CADL.Extension/Emitter.Csharp/src/type/InputOperation.ts index 80d509313a3..57385dadd1a 100644 --- a/src/CADL.Extension/Emitter.Csharp/src/type/InputOperation.ts +++ b/src/CADL.Extension/Emitter.Csharp/src/type/InputOperation.ts @@ -32,5 +32,6 @@ export interface InputOperation { BufferResponse: boolean; LongRunning?: OperationLongRunning; Paging?: OperationPaging; + GenerateProtocolMethod: boolean; GenerateConvenienceMethod: boolean; } diff --git a/src/CADL.Extension/Emitter.Csharp/test/TestProjects/interface/interface.cadl b/src/CADL.Extension/Emitter.Csharp/test/TestProjects/interface/interface.cadl index 4ec0bef5009..afc487c24ed 100644 --- a/src/CADL.Extension/Emitter.Csharp/test/TestProjects/interface/interface.cadl +++ b/src/CADL.Extension/Emitter.Csharp/test/TestProjects/interface/interface.cadl @@ -27,7 +27,7 @@ model Cat { interface dogs { @doc("Illustrate grouping operations on subclient.") @get - @convenienceAPI + @convenientAPI(true) getDogsConvenient(): Dog; @doc("Illustrate grouping operations on subclient.") diff --git a/test/CadlRanchProjects/api-key/Generated/cadl.json b/test/CadlRanchProjects/api-key/Generated/cadl.json index 4ac0f5f5add..0d673afe55e 100644 --- a/test/CadlRanchProjects/api-key/Generated/cadl.json +++ b/test/CadlRanchProjects/api-key/Generated/cadl.json @@ -150,6 +150,7 @@ "Uri": "{host}", "Path": "/authentication/api-key/valid", "BufferResponse": true, + "GenerateProtocolMethod": true, "GenerateConvenienceMethod": false }, { @@ -220,6 +221,7 @@ "Uri": "{host}", "Path": "/authentication/api-key/invalid", "BufferResponse": true, + "GenerateProtocolMethod": true, "GenerateConvenienceMethod": false } ], diff --git a/test/CadlRanchProjects/inheritance/Generated/cadl.json b/test/CadlRanchProjects/inheritance/Generated/cadl.json index 9af57368e70..164af5d8874 100644 --- a/test/CadlRanchProjects/inheritance/Generated/cadl.json +++ b/test/CadlRanchProjects/inheritance/Generated/cadl.json @@ -345,6 +345,7 @@ "application/json" ], "BufferResponse": true, + "GenerateProtocolMethod": true, "GenerateConvenienceMethod": true }, { @@ -405,6 +406,7 @@ "Uri": "{host}", "Path": "/models/inheritance/valid", "BufferResponse": true, + "GenerateProtocolMethod": true, "GenerateConvenienceMethod": true }, { @@ -512,6 +514,7 @@ "application/json" ], "BufferResponse": true, + "GenerateProtocolMethod": true, "GenerateConvenienceMethod": true }, { @@ -572,6 +575,7 @@ "Uri": "{host}", "Path": "/models/inheritance/discriminated/model", "BufferResponse": true, + "GenerateProtocolMethod": true, "GenerateConvenienceMethod": true }, { @@ -676,6 +680,7 @@ "application/json" ], "BufferResponse": true, + "GenerateProtocolMethod": true, "GenerateConvenienceMethod": true }, { @@ -736,6 +741,7 @@ "Uri": "{host}", "Path": "/models/inheritance/discriminated/recursivemodel", "BufferResponse": true, + "GenerateProtocolMethod": true, "GenerateConvenienceMethod": true }, { @@ -840,6 +846,7 @@ "application/json" ], "BufferResponse": true, + "GenerateProtocolMethod": true, "GenerateConvenienceMethod": true }, { @@ -900,6 +907,7 @@ "Uri": "{host}", "Path": "/models/inheritance/discriminated/missingdiscriminator", "BufferResponse": true, + "GenerateProtocolMethod": true, "GenerateConvenienceMethod": true }, { @@ -960,6 +968,7 @@ "Uri": "{host}", "Path": "/models/inheritance/discriminated/wrongdiscriminator", "BufferResponse": true, + "GenerateProtocolMethod": true, "GenerateConvenienceMethod": true } ], diff --git a/test/CadlRanchProjects/inheritance/inheritance-cadl.cadl b/test/CadlRanchProjects/inheritance/inheritance-cadl.cadl index 6c2b7050df2..21d93ba4a62 100644 --- a/test/CadlRanchProjects/inheritance/inheritance-cadl.cadl +++ b/test/CadlRanchProjects/inheritance/inheritance-cadl.cadl @@ -70,7 +70,7 @@ Expected input body: """) @route("/valid") @post -@convenienceAPI +@convenientAPI(true) op postValid(@body input: Siamese): OkResponse; @scenario @@ -83,14 +83,14 @@ Expected response body: """) @route("/valid") @get -@convenienceAPI +@convenientAPI(true) op getValid(): Siamese; @scenario @scenarioDoc("Generate, send, and receive round-trip bottom model.") @route("/valid") @put -@convenienceAPI +@convenientAPI(true) op putValid(@body input: Siamese): Siamese; @route("/discriminated") @@ -105,7 +105,7 @@ interface Discriminated { ``` """) @get - @convenienceAPI + @convenientAPI(true) getModel(): Fish; @scenario @@ -118,7 +118,7 @@ interface Discriminated { ``` """) @put - @convenienceAPI + @convenientAPI(true) putModel(@body input: Fish): OkResponse; @scenario @@ -187,7 +187,7 @@ interface Discriminated { ``` """) @get - @convenienceAPI + @convenientAPI(true) getRecursiveModel(): Fish; @scenario @@ -256,7 +256,7 @@ interface Discriminated { ``` """) @put - @convenienceAPI + @convenientAPI(true) putRecursiveModel(@body input: Fish): OkResponse; @scenario @@ -269,7 +269,7 @@ interface Discriminated { ``` """) @get - @convenienceAPI + @convenientAPI(true) getMissingDiscriminator(): Fish; @scenario @@ -282,6 +282,6 @@ interface Discriminated { ``` """) @get - @convenienceAPI + @convenientAPI(true) getWrongDiscriminator(): Fish; } diff --git a/test/CadlRanchProjects/oauth2/Generated/cadl.json b/test/CadlRanchProjects/oauth2/Generated/cadl.json index 4f79b332237..08807a3c769 100644 --- a/test/CadlRanchProjects/oauth2/Generated/cadl.json +++ b/test/CadlRanchProjects/oauth2/Generated/cadl.json @@ -150,6 +150,7 @@ "Uri": "{host}", "Path": "/authentication/oauth2/valid", "BufferResponse": true, + "GenerateProtocolMethod": true, "GenerateConvenienceMethod": false }, { @@ -220,6 +221,7 @@ "Uri": "{host}", "Path": "/authentication/oauth2/invalid", "BufferResponse": true, + "GenerateProtocolMethod": true, "GenerateConvenienceMethod": false } ], diff --git a/test/CadlRanchProjects/property-optional/Generated/cadl.json b/test/CadlRanchProjects/property-optional/Generated/cadl.json index 1a1c38633e0..02b8d4a584d 100644 --- a/test/CadlRanchProjects/property-optional/Generated/cadl.json +++ b/test/CadlRanchProjects/property-optional/Generated/cadl.json @@ -336,6 +336,7 @@ "Uri": "{host}", "Path": "/models/properties/optional/string/all", "BufferResponse": true, + "GenerateProtocolMethod": true, "GenerateConvenienceMethod": false }, { @@ -397,6 +398,7 @@ "Uri": "{host}", "Path": "/models/properties/optional/string/default", "BufferResponse": true, + "GenerateProtocolMethod": true, "GenerateConvenienceMethod": false }, { @@ -502,6 +504,7 @@ "application/json" ], "BufferResponse": true, + "GenerateProtocolMethod": true, "GenerateConvenienceMethod": false }, { @@ -607,6 +610,7 @@ "application/json" ], "BufferResponse": true, + "GenerateProtocolMethod": true, "GenerateConvenienceMethod": false } ], @@ -680,6 +684,7 @@ "Uri": "{host}", "Path": "/models/properties/optional/bytes/all", "BufferResponse": true, + "GenerateProtocolMethod": true, "GenerateConvenienceMethod": false }, { @@ -741,6 +746,7 @@ "Uri": "{host}", "Path": "/models/properties/optional/bytes/default", "BufferResponse": true, + "GenerateProtocolMethod": true, "GenerateConvenienceMethod": false }, { @@ -846,6 +852,7 @@ "application/json" ], "BufferResponse": true, + "GenerateProtocolMethod": true, "GenerateConvenienceMethod": false }, { @@ -951,6 +958,7 @@ "application/json" ], "BufferResponse": true, + "GenerateProtocolMethod": true, "GenerateConvenienceMethod": false } ], @@ -1024,6 +1032,7 @@ "Uri": "{host}", "Path": "/models/properties/optional/datetime/all", "BufferResponse": true, + "GenerateProtocolMethod": true, "GenerateConvenienceMethod": false }, { @@ -1085,6 +1094,7 @@ "Uri": "{host}", "Path": "/models/properties/optional/datetime/default", "BufferResponse": true, + "GenerateProtocolMethod": true, "GenerateConvenienceMethod": false }, { @@ -1190,6 +1200,7 @@ "application/json" ], "BufferResponse": true, + "GenerateProtocolMethod": true, "GenerateConvenienceMethod": false }, { @@ -1295,6 +1306,7 @@ "application/json" ], "BufferResponse": true, + "GenerateProtocolMethod": true, "GenerateConvenienceMethod": false } ], @@ -1368,6 +1380,7 @@ "Uri": "{host}", "Path": "/models/properties/optional/duration/all", "BufferResponse": true, + "GenerateProtocolMethod": true, "GenerateConvenienceMethod": false }, { @@ -1429,6 +1442,7 @@ "Uri": "{host}", "Path": "/models/properties/optional/duration/default", "BufferResponse": true, + "GenerateProtocolMethod": true, "GenerateConvenienceMethod": false }, { @@ -1534,6 +1548,7 @@ "application/json" ], "BufferResponse": true, + "GenerateProtocolMethod": true, "GenerateConvenienceMethod": false }, { @@ -1639,6 +1654,7 @@ "application/json" ], "BufferResponse": true, + "GenerateProtocolMethod": true, "GenerateConvenienceMethod": false } ], @@ -1712,6 +1728,7 @@ "Uri": "{host}", "Path": "/models/properties/optional/collections/bytes/all", "BufferResponse": true, + "GenerateProtocolMethod": true, "GenerateConvenienceMethod": false }, { @@ -1773,6 +1790,7 @@ "Uri": "{host}", "Path": "/models/properties/optional/collections/bytes/default", "BufferResponse": true, + "GenerateProtocolMethod": true, "GenerateConvenienceMethod": false }, { @@ -1878,6 +1896,7 @@ "application/json" ], "BufferResponse": true, + "GenerateProtocolMethod": true, "GenerateConvenienceMethod": false }, { @@ -1983,6 +2002,7 @@ "application/json" ], "BufferResponse": true, + "GenerateProtocolMethod": true, "GenerateConvenienceMethod": false } ], @@ -2056,6 +2076,7 @@ "Uri": "{host}", "Path": "/models/properties/optional/collections/model/all", "BufferResponse": true, + "GenerateProtocolMethod": true, "GenerateConvenienceMethod": false }, { @@ -2117,6 +2138,7 @@ "Uri": "{host}", "Path": "/models/properties/optional/collections/model/default", "BufferResponse": true, + "GenerateProtocolMethod": true, "GenerateConvenienceMethod": false }, { @@ -2222,6 +2244,7 @@ "application/json" ], "BufferResponse": true, + "GenerateProtocolMethod": true, "GenerateConvenienceMethod": false }, { @@ -2327,6 +2350,7 @@ "application/json" ], "BufferResponse": true, + "GenerateProtocolMethod": true, "GenerateConvenienceMethod": false } ], @@ -2400,6 +2424,7 @@ "Uri": "{host}", "Path": "/models/properties/optional/requiredAndOptional/all", "BufferResponse": true, + "GenerateProtocolMethod": true, "GenerateConvenienceMethod": false }, { @@ -2461,6 +2486,7 @@ "Uri": "{host}", "Path": "/models/properties/optional/requiredAndOptional/requiredOnly", "BufferResponse": true, + "GenerateProtocolMethod": true, "GenerateConvenienceMethod": false }, { @@ -2566,6 +2592,7 @@ "application/json" ], "BufferResponse": true, + "GenerateProtocolMethod": true, "GenerateConvenienceMethod": false }, { @@ -2671,6 +2698,7 @@ "application/json" ], "BufferResponse": true, + "GenerateProtocolMethod": true, "GenerateConvenienceMethod": false } ], diff --git a/test/CadlRanchProjects/property-types/Generated/cadl.json b/test/CadlRanchProjects/property-types/Generated/cadl.json index d247494b412..81e55d5fa2d 100644 --- a/test/CadlRanchProjects/property-types/Generated/cadl.json +++ b/test/CadlRanchProjects/property-types/Generated/cadl.json @@ -586,6 +586,7 @@ "Uri": "{host}", "Path": "/models/properties/types/boolean", "BufferResponse": true, + "GenerateProtocolMethod": true, "GenerateConvenienceMethod": false }, { @@ -692,6 +693,7 @@ "application/json" ], "BufferResponse": true, + "GenerateProtocolMethod": true, "GenerateConvenienceMethod": false } ], @@ -765,6 +767,7 @@ "Uri": "{host}", "Path": "/models/properties/types/string", "BufferResponse": true, + "GenerateProtocolMethod": true, "GenerateConvenienceMethod": false }, { @@ -871,6 +874,7 @@ "application/json" ], "BufferResponse": true, + "GenerateProtocolMethod": true, "GenerateConvenienceMethod": false } ], @@ -944,6 +948,7 @@ "Uri": "{host}", "Path": "/models/properties/types/bytes", "BufferResponse": true, + "GenerateProtocolMethod": true, "GenerateConvenienceMethod": false }, { @@ -1050,6 +1055,7 @@ "application/json" ], "BufferResponse": true, + "GenerateProtocolMethod": true, "GenerateConvenienceMethod": false } ], @@ -1123,6 +1129,7 @@ "Uri": "{host}", "Path": "/models/properties/types/int", "BufferResponse": true, + "GenerateProtocolMethod": true, "GenerateConvenienceMethod": false }, { @@ -1229,6 +1236,7 @@ "application/json" ], "BufferResponse": true, + "GenerateProtocolMethod": true, "GenerateConvenienceMethod": false } ], @@ -1302,6 +1310,7 @@ "Uri": "{host}", "Path": "/models/properties/types/float", "BufferResponse": true, + "GenerateProtocolMethod": true, "GenerateConvenienceMethod": false }, { @@ -1408,6 +1417,7 @@ "application/json" ], "BufferResponse": true, + "GenerateProtocolMethod": true, "GenerateConvenienceMethod": false } ], @@ -1481,6 +1491,7 @@ "Uri": "{host}", "Path": "/models/properties/types/datetime", "BufferResponse": true, + "GenerateProtocolMethod": true, "GenerateConvenienceMethod": false }, { @@ -1587,6 +1598,7 @@ "application/json" ], "BufferResponse": true, + "GenerateProtocolMethod": true, "GenerateConvenienceMethod": false } ], @@ -1660,6 +1672,7 @@ "Uri": "{host}", "Path": "/models/properties/types/duration", "BufferResponse": true, + "GenerateProtocolMethod": true, "GenerateConvenienceMethod": false }, { @@ -1766,6 +1779,7 @@ "application/json" ], "BufferResponse": true, + "GenerateProtocolMethod": true, "GenerateConvenienceMethod": false } ], @@ -1839,6 +1853,7 @@ "Uri": "{host}", "Path": "/models/properties/types/enum", "BufferResponse": true, + "GenerateProtocolMethod": true, "GenerateConvenienceMethod": false }, { @@ -1945,6 +1960,7 @@ "application/json" ], "BufferResponse": true, + "GenerateProtocolMethod": true, "GenerateConvenienceMethod": false } ], @@ -2018,6 +2034,7 @@ "Uri": "{host}", "Path": "/models/properties/types/extensible-enum", "BufferResponse": true, + "GenerateProtocolMethod": true, "GenerateConvenienceMethod": false }, { @@ -2124,6 +2141,7 @@ "application/json" ], "BufferResponse": true, + "GenerateProtocolMethod": true, "GenerateConvenienceMethod": false } ], @@ -2197,6 +2215,7 @@ "Uri": "{host}", "Path": "/models/properties/types/model", "BufferResponse": true, + "GenerateProtocolMethod": true, "GenerateConvenienceMethod": false }, { @@ -2303,6 +2322,7 @@ "application/json" ], "BufferResponse": true, + "GenerateProtocolMethod": true, "GenerateConvenienceMethod": false } ], @@ -2376,6 +2396,7 @@ "Uri": "{host}", "Path": "/models/properties/types/collections/string", "BufferResponse": true, + "GenerateProtocolMethod": true, "GenerateConvenienceMethod": false }, { @@ -2482,6 +2503,7 @@ "application/json" ], "BufferResponse": true, + "GenerateProtocolMethod": true, "GenerateConvenienceMethod": false } ], @@ -2555,6 +2577,7 @@ "Uri": "{host}", "Path": "/models/properties/types/collections/int", "BufferResponse": true, + "GenerateProtocolMethod": true, "GenerateConvenienceMethod": false }, { @@ -2661,6 +2684,7 @@ "application/json" ], "BufferResponse": true, + "GenerateProtocolMethod": true, "GenerateConvenienceMethod": false } ], @@ -2734,6 +2758,7 @@ "Uri": "{host}", "Path": "/models/properties/types/collections/model", "BufferResponse": true, + "GenerateProtocolMethod": true, "GenerateConvenienceMethod": false }, { @@ -2840,6 +2865,7 @@ "application/json" ], "BufferResponse": true, + "GenerateProtocolMethod": true, "GenerateConvenienceMethod": false } ], @@ -2913,6 +2939,7 @@ "Uri": "{host}", "Path": "/models/properties/types/dictionary/string", "BufferResponse": true, + "GenerateProtocolMethod": true, "GenerateConvenienceMethod": false }, { @@ -3019,6 +3046,7 @@ "application/json" ], "BufferResponse": true, + "GenerateProtocolMethod": true, "GenerateConvenienceMethod": false } ], @@ -3092,6 +3120,7 @@ "Uri": "{host}", "Path": "/models/properties/types/never", "BufferResponse": true, + "GenerateProtocolMethod": true, "GenerateConvenienceMethod": false }, { @@ -3198,6 +3227,7 @@ "application/json" ], "BufferResponse": true, + "GenerateProtocolMethod": true, "GenerateConvenienceMethod": false } ], diff --git a/test/TestProjects/ApiVersion-Cadl/ApiVersion-Cadl.cadl b/test/TestProjects/ApiVersion-Cadl/ApiVersion-Cadl.cadl index 0009c373aeb..52b84ea48e2 100644 --- a/test/TestProjects/ApiVersion-Cadl/ApiVersion-Cadl.cadl +++ b/test/TestProjects/ApiVersion-Cadl/ApiVersion-Cadl.cadl @@ -51,7 +51,7 @@ model DetectionResult { For asynchronous inference, get multivariate anomaly detection result based on resultId returned by the BatchDetectAnomaly api. """) -@convenienceAPI("ConvenienceGet") +@convenientAPI(true) op GetBatchDetectionResult( @format("uuid") @path resultId: string, diff --git a/test/TestProjects/ApiVersion-Cadl/Generated/cadl.json b/test/TestProjects/ApiVersion-Cadl/Generated/cadl.json index 619ff0eb028..4f10f1b1310 100644 --- a/test/TestProjects/ApiVersion-Cadl/Generated/cadl.json +++ b/test/TestProjects/ApiVersion-Cadl/Generated/cadl.json @@ -185,6 +185,7 @@ "Uri": "{Endpoint}/anomalydetector/{ApiVersion}", "Path": "/multivariate/detect-batch/{resultId}", "BufferResponse": true, + "GenerateProtocolMethod": true, "GenerateConvenienceMethod": true } ], diff --git a/test/TestProjects/Authoring-Cadl/Authoring-Cadl.cadl b/test/TestProjects/Authoring-Cadl/Authoring-Cadl.cadl index f003424a345..01959b4b9a8 100644 --- a/test/TestProjects/Authoring-Cadl/Authoring-Cadl.cadl +++ b/test/TestProjects/Authoring-Cadl/Authoring-Cadl.cadl @@ -287,11 +287,11 @@ interface Deployments { interface Jobs { @doc("Gets the status of an existing deployment job.") - @convenienceAPI + @convenientAPI(true) getDeploymentStatus is ResourceRead; @doc("Gets the status of an existing swap deployment job.") - @convenienceAPI + @convenientAPI(true) getSwapDeploymentsStatus is ResourceRead; } diff --git a/test/TestProjects/Authoring-Cadl/Generated/cadl.json b/test/TestProjects/Authoring-Cadl/Generated/cadl.json index 5b05fa3c6ef..a4afb4bf01e 100644 --- a/test/TestProjects/Authoring-Cadl/Generated/cadl.json +++ b/test/TestProjects/Authoring-Cadl/Generated/cadl.json @@ -1195,6 +1195,7 @@ "application/merge-patch+json" ], "BufferResponse": true, + "GenerateProtocolMethod": true, "GenerateConvenienceMethod": false }, { @@ -1276,6 +1277,7 @@ "Uri": "{Endpoint}/language", "Path": "/authoring/analyze-text/projects/{projectName}", "BufferResponse": true, + "GenerateProtocolMethod": true, "GenerateConvenienceMethod": false }, { @@ -1370,6 +1372,7 @@ "Uri": "{Endpoint}/language", "Path": "/authoring/analyze-text/projects/{projectName}", "BufferResponse": true, + "GenerateProtocolMethod": true, "GenerateConvenienceMethod": false }, { @@ -1436,6 +1439,7 @@ "NextLinkName": "nextLink", "ItemName": "value" }, + "GenerateProtocolMethod": true, "GenerateConvenienceMethod": false }, { @@ -1547,6 +1551,7 @@ "Uri": "{Endpoint}/language", "Path": "/authoring/analyze-text/projects/{projectName}:export", "BufferResponse": true, + "GenerateProtocolMethod": true, "GenerateConvenienceMethod": false }, { @@ -1638,6 +1643,7 @@ "Uri": "{Endpoint}/language", "Path": "/authoring/analyze-text/projects/{projectName}:importx", "BufferResponse": true, + "GenerateProtocolMethod": true, "GenerateConvenienceMethod": false }, { @@ -1776,6 +1782,7 @@ "application/json" ], "BufferResponse": true, + "GenerateProtocolMethod": true, "GenerateConvenienceMethod": false }, { @@ -1877,6 +1884,7 @@ "Uri": "{Endpoint}/language", "Path": "/authoring/analyze-text/projects/{projectName}/deployments/{deploymentName}", "BufferResponse": true, + "GenerateProtocolMethod": true, "GenerateConvenienceMethod": false }, { @@ -2064,6 +2072,7 @@ "application/json" ], "BufferResponse": true, + "GenerateProtocolMethod": true, "GenerateConvenienceMethod": false }, { @@ -2178,6 +2187,7 @@ "Uri": "{Endpoint}/language", "Path": "/authoring/analyze-text/projects/{projectName}/deployments/{deploymentName}", "BufferResponse": true, + "GenerateProtocolMethod": true, "GenerateConvenienceMethod": false }, { @@ -2264,6 +2274,7 @@ "NextLinkName": "nextLink", "ItemName": "value" }, + "GenerateProtocolMethod": true, "GenerateConvenienceMethod": false }, { @@ -2403,6 +2414,7 @@ "application/json" ], "BufferResponse": true, + "GenerateProtocolMethod": true, "GenerateConvenienceMethod": false }, { @@ -2524,6 +2536,7 @@ "Uri": "{Endpoint}/language", "Path": "/authoring/analyze-text/projects/{projectName}/deployments/{deploymentName}/jobs/{jobId}", "BufferResponse": true, + "GenerateProtocolMethod": true, "GenerateConvenienceMethod": true }, { @@ -2645,6 +2658,7 @@ "Uri": "{Endpoint}/language", "Path": "/authoring/analyze-text/projects/{projectName}/deployments/{deploymentName}/swap/jobs/{jobId}", "BufferResponse": true, + "GenerateProtocolMethod": true, "GenerateConvenienceMethod": true }, { @@ -2770,6 +2784,7 @@ "NextLinkName": "nextLink", "ItemName": "value" }, + "GenerateProtocolMethod": true, "GenerateConvenienceMethod": false }, { @@ -2895,6 +2910,7 @@ "NextLinkName": "nextLink", "ItemName": "value" }, + "GenerateProtocolMethod": true, "GenerateConvenienceMethod": false } ], diff --git a/test/TestProjects/ClientAndOperationGroup-Cadl/Generated/cadl.json b/test/TestProjects/ClientAndOperationGroup-Cadl/Generated/cadl.json index 3508857884b..89c672e2f53 100644 --- a/test/TestProjects/ClientAndOperationGroup-Cadl/Generated/cadl.json +++ b/test/TestProjects/ClientAndOperationGroup-Cadl/Generated/cadl.json @@ -118,6 +118,7 @@ "Uri": "{operationGroupServiceUrl}", "Path": "/top", "BufferResponse": true, + "GenerateProtocolMethod": true, "GenerateConvenienceMethod": false }, { @@ -181,6 +182,7 @@ "Uri": "{operationGroupServiceUrl}", "Path": "/Alpha", "BufferResponse": true, + "GenerateProtocolMethod": true, "GenerateConvenienceMethod": false } ], @@ -255,6 +257,7 @@ "Uri": "{operationGroupServiceUrl}", "Path": "/Beta", "BufferResponse": true, + "GenerateProtocolMethod": true, "GenerateConvenienceMethod": false }, { @@ -318,6 +321,7 @@ "Uri": "{operationGroupServiceUrl}", "Path": "/SubBeta", "BufferResponse": true, + "GenerateProtocolMethod": true, "GenerateConvenienceMethod": false } ], @@ -393,6 +397,7 @@ "Uri": "{operationGroupServiceUrl}", "Path": "/Gamma", "BufferResponse": true, + "GenerateProtocolMethod": true, "GenerateConvenienceMethod": false }, { @@ -456,6 +461,7 @@ "Uri": "{operationGroupServiceUrl}", "Path": "/Gamma", "BufferResponse": true, + "GenerateProtocolMethod": true, "GenerateConvenienceMethod": false } ], diff --git a/test/TestProjects/Customizations-Cadl/Customizations-Cadl.cadl b/test/TestProjects/Customizations-Cadl/Customizations-Cadl.cadl index 7976269555d..0f25b94ed04 100644 --- a/test/TestProjects/Customizations-Cadl/Customizations-Cadl.cadl +++ b/test/TestProjects/Customizations-Cadl/Customizations-Cadl.cadl @@ -108,5 +108,5 @@ model RootModel { @route("/inputToRoundTrip") @doc("RoundTrip operation to make RootModel round-trip") @get -@convenienceAPI +@convenientAPI(true) op roundTrip(@body input: RootModel): RootModel; \ No newline at end of file diff --git a/test/TestProjects/Customizations-Cadl/Generated/cadl.json b/test/TestProjects/Customizations-Cadl/Generated/cadl.json index 2c7c65e1e9f..b6f0dc0fceb 100644 --- a/test/TestProjects/Customizations-Cadl/Generated/cadl.json +++ b/test/TestProjects/Customizations-Cadl/Generated/cadl.json @@ -526,6 +526,7 @@ "application/json" ], "BufferResponse": true, + "GenerateProtocolMethod": true, "GenerateConvenienceMethod": true } ], diff --git a/test/TestProjects/FirstTest-Cadl/FirstTest-Cadl.cadl b/test/TestProjects/FirstTest-Cadl/FirstTest-Cadl.cadl index 1a4e0a30d05..22e763aada9 100644 --- a/test/TestProjects/FirstTest-Cadl/FirstTest-Cadl.cadl +++ b/test/TestProjects/FirstTest-Cadl/FirstTest-Cadl.cadl @@ -96,7 +96,7 @@ namespace Hello.Demo2 { @route("/againHi") @doc("Return hi again") @get - @convenienceAPI + @convenientAPI(true) op helloAgain(@header p1: string, @body action: RoundTripModel, @Cadl.Http.header contentType: "text/plain", @path p2: string): Thing; @route("/noContentType") @@ -105,7 +105,7 @@ namespace Hello.Demo2 { op noContentType(@header p1: string, @body action: RoundTripModel, @path p2: string): Thing; @route("/demoHi") - @convenienceAPI + @convenientAPI(true) @doc("Return hi in demo2") @get op helloDemo2(): Thing; @@ -114,7 +114,7 @@ namespace Hello.Demo2 { @route("/top") @doc("top level method") @get -@convenienceAPI +@convenientAPI(true) op topAction(@path @format("date") action: string): Thing; @route("/top2") @@ -126,19 +126,19 @@ op topAction2(): Thing; @route("/patch") @doc("top level patch") @patch -@convenienceAPI +@convenientAPI(true) op patchAction(@body body: Thing): Thing; @route("/anonymousBody") @doc("body parameter without body decorator") @post -@convenienceAPI +@convenientAPI(true) op anonymousBody( ...Thing ): Thing; @route("/friendlyName") @doc("Model can have its friendly name") @post -@convenienceAPI +@convenientAPI(true) op friendlyModel(...NotFriend): NotFriend; op addTimeHeader(@header("Repeatability-First-Sent") repeatabilityFirstSent?: zonedDateTime): void; @@ -149,3 +149,19 @@ namespace EnumTest { @doc("get extensible enum") op getUnknownValue(): DaysOfWeekExtensibleEnum; } + +namespace ProtocolAndConvenient { + @doc("When set protocol false and convenient true, then the protocol method should be internal") + @route("internalProtocol") + @post + @convenientAPI(true) + @protocolAPI(false) + op internalProtocol(@body body: Thing): Thing; + + @doc("When set protocol false and convenient true, the convenient method should be generated even it has the same signature as protocol one") + @route("stillConvenient") + @get + @convenientAPI(true) + @protocolAPI(false) + op stillConvenient(): void; +} diff --git a/test/TestProjects/FirstTest-Cadl/Generated/CadlFirstTestClient.cs b/test/TestProjects/FirstTest-Cadl/Generated/CadlFirstTestClient.cs index 7d38f85705c..9710a1e28f7 100644 --- a/test/TestProjects/FirstTest-Cadl/Generated/CadlFirstTestClient.cs +++ b/test/TestProjects/FirstTest-Cadl/Generated/CadlFirstTestClient.cs @@ -808,6 +808,162 @@ public virtual Response GetUnknownValue(RequestContext context = null) } } + /// When set protocol false and convenient true, then the protocol method should be internal. + /// The Thing to use. + /// The cancellation token to use. + /// is null. + public virtual async Task> InternalProtocolAsync(Thing body, CancellationToken cancellationToken = default) + { + Argument.AssertNotNull(body, nameof(body)); + + RequestContext context = FromCancellationToken(cancellationToken); + Response response = await InternalProtocolAsync(body.ToRequestContent(), context).ConfigureAwait(false); + return Response.FromValue(Thing.FromResponse(response), response); + } + + /// When set protocol false and convenient true, then the protocol method should be internal. + /// The Thing to use. + /// The cancellation token to use. + /// is null. + public virtual Response InternalProtocol(Thing body, CancellationToken cancellationToken = default) + { + Argument.AssertNotNull(body, nameof(body)); + + RequestContext context = FromCancellationToken(cancellationToken); + Response response = InternalProtocol(body.ToRequestContent(), context); + return Response.FromValue(Thing.FromResponse(response), response); + } + + /// When set protocol false and convenient true, then the protocol method should be internal. + /// The content to send as the body of the request. Details of the request body schema are in the Remarks section below. + /// The request context, which can override default behaviors of the client pipeline on a per-call basis. + /// is null. + /// Service returned a non-success status code. + /// The response returned from the service. Details of the response body schema are in the Remarks section below. + /// + internal virtual async Task InternalProtocolAsync(RequestContent content, RequestContext context = null) + { + Argument.AssertNotNull(content, nameof(content)); + + using var scope = ClientDiagnostics.CreateScope("CadlFirstTestClient.InternalProtocol"); + scope.Start(); + try + { + using HttpMessage message = CreateInternalProtocolRequest(content, context); + return await _pipeline.ProcessMessageAsync(message, context).ConfigureAwait(false); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// When set protocol false and convenient true, then the protocol method should be internal. + /// The content to send as the body of the request. Details of the request body schema are in the Remarks section below. + /// The request context, which can override default behaviors of the client pipeline on a per-call basis. + /// is null. + /// Service returned a non-success status code. + /// The response returned from the service. Details of the response body schema are in the Remarks section below. + /// + internal virtual Response InternalProtocol(RequestContent content, RequestContext context = null) + { + Argument.AssertNotNull(content, nameof(content)); + + using var scope = ClientDiagnostics.CreateScope("CadlFirstTestClient.InternalProtocol"); + scope.Start(); + try + { + using HttpMessage message = CreateInternalProtocolRequest(content, context); + return _pipeline.ProcessMessage(message, context); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// When set protocol false and convenient true, the convenient method should be generated even it has the same signature as protocol one. + /// The cancellation token to use. + public virtual async Task StillConvenientValueAsync(CancellationToken cancellationToken = default) + { + using var scope = ClientDiagnostics.CreateScope("CadlFirstTestClient.StillConvenientValue"); + scope.Start(); + try + { + RequestContext context = FromCancellationToken(cancellationToken); + Response response = await StillConvenientAsync(context).ConfigureAwait(false); + return response; + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// When set protocol false and convenient true, the convenient method should be generated even it has the same signature as protocol one. + /// The cancellation token to use. + public virtual Response StillConvenientValue(CancellationToken cancellationToken = default) + { + using var scope = ClientDiagnostics.CreateScope("CadlFirstTestClient.StillConvenientValue"); + scope.Start(); + try + { + RequestContext context = FromCancellationToken(cancellationToken); + Response response = StillConvenient(context); + return response; + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// When set protocol false and convenient true, the convenient method should be generated even it has the same signature as protocol one. + /// The request context, which can override default behaviors of the client pipeline on a per-call basis. + /// Service returned a non-success status code. + /// The response returned from the service. + /// + internal virtual async Task StillConvenientAsync(RequestContext context = null) + { + using var scope = ClientDiagnostics.CreateScope("CadlFirstTestClient.StillConvenient"); + scope.Start(); + try + { + using HttpMessage message = CreateStillConvenientRequest(context); + return await _pipeline.ProcessMessageAsync(message, context).ConfigureAwait(false); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// When set protocol false and convenient true, the convenient method should be generated even it has the same signature as protocol one. + /// The request context, which can override default behaviors of the client pipeline on a per-call basis. + /// Service returned a non-success status code. + /// The response returned from the service. + /// + internal virtual Response StillConvenient(RequestContext context = null) + { + using var scope = ClientDiagnostics.CreateScope("CadlFirstTestClient.StillConvenient"); + scope.Start(); + try + { + using HttpMessage message = CreateStillConvenientRequest(context); + return _pipeline.ProcessMessage(message, context); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + internal HttpMessage CreateTopActionRequest(string action, RequestContext context) { var message = _pipeline.CreateMessage(context, ResponseClassifier200); @@ -987,6 +1143,36 @@ internal HttpMessage CreateGetUnknownValueRequest(RequestContext context) return message; } + internal HttpMessage CreateInternalProtocolRequest(RequestContent content, RequestContext context) + { + var message = _pipeline.CreateMessage(context, ResponseClassifier200); + var request = message.Request; + request.Method = RequestMethod.Post; + var uri = new RawRequestUriBuilder(); + uri.Reset(_endpoint); + uri.AppendPath("/internalProtocol", false); + uri.AppendQuery("api-version", _apiVersion, true); + request.Uri = uri; + request.Headers.Add("Accept", "application/json"); + request.Headers.Add("Content-Type", "application/json"); + request.Content = content; + return message; + } + + internal HttpMessage CreateStillConvenientRequest(RequestContext context) + { + var message = _pipeline.CreateMessage(context, ResponseClassifier204); + var request = message.Request; + request.Method = RequestMethod.Get; + var uri = new RawRequestUriBuilder(); + uri.Reset(_endpoint); + uri.AppendPath("/stillConvenient", false); + uri.AppendQuery("api-version", _apiVersion, true); + request.Uri = uri; + request.Headers.Add("Accept", "application/json"); + return message; + } + private static RequestContext DefaultRequestContext = new RequestContext(); internal static RequestContext FromCancellationToken(CancellationToken cancellationToken = default) { diff --git a/test/TestProjects/FirstTest-Cadl/Generated/Docs/CadlFirstTestClient.xml b/test/TestProjects/FirstTest-Cadl/Generated/Docs/CadlFirstTestClient.xml index a079bc174cd..31eb68d102a 100644 --- a/test/TestProjects/FirstTest-Cadl/Generated/Docs/CadlFirstTestClient.xml +++ b/test/TestProjects/FirstTest-Cadl/Generated/Docs/CadlFirstTestClient.xml @@ -889,6 +889,130 @@ Response response = client.GetUnknownValue(); JsonElement result = JsonDocument.Parse(response.ContentStream).RootElement; Console.WriteLine(result.ToString()); ]]> + + + + +This sample shows how to call InternalProtocolAsync with required request content and parse the result. +"); +var client = new CadlFirstTestClient(credential); + +var data = new { + name = "", + requiredUnion = new {}, + requiredLiteral = new {}, + requiredBadDescription = "", +}; + +Response response = await client.InternalProtocolAsync(RequestContent.Create(data)); + +JsonElement result = JsonDocument.Parse(response.ContentStream).RootElement; +Console.WriteLine(result.GetProperty("name").ToString()); +Console.WriteLine(result.GetProperty("requiredUnion").ToString()); +Console.WriteLine(result.GetProperty("requiredLiteral").ToString()); +Console.WriteLine(result.GetProperty("requiredBadDescription").ToString()); +]]> + + +Below is the JSON schema for the request and response payloads. + +Request Body: + +Schema for Thing: +{ + name: string, # Required. name of the Thing + requiredUnion: Union, # Required. required Union + requiredLiteral: Literal, # Required. required literal type + requiredBadDescription: string, # Required. description with xml &lt;|endoftext|&gt; +} + + +Response Body: + +Schema for Thing: +{ + name: string, # Required. name of the Thing + requiredUnion: Union, # Required. required Union + requiredLiteral: Literal, # Required. required literal type + requiredBadDescription: string, # Required. description with xml &lt;|endoftext|&gt; +} + + + + + + +This sample shows how to call InternalProtocol with required request content and parse the result. +"); +var client = new CadlFirstTestClient(credential); + +var data = new { + name = "", + requiredUnion = new {}, + requiredLiteral = new {}, + requiredBadDescription = "", +}; + +Response response = client.InternalProtocol(RequestContent.Create(data)); + +JsonElement result = JsonDocument.Parse(response.ContentStream).RootElement; +Console.WriteLine(result.GetProperty("name").ToString()); +Console.WriteLine(result.GetProperty("requiredUnion").ToString()); +Console.WriteLine(result.GetProperty("requiredLiteral").ToString()); +Console.WriteLine(result.GetProperty("requiredBadDescription").ToString()); +]]> + + +Below is the JSON schema for the request and response payloads. + +Request Body: + +Schema for Thing: +{ + name: string, # Required. name of the Thing + requiredUnion: Union, # Required. required Union + requiredLiteral: Literal, # Required. required literal type + requiredBadDescription: string, # Required. description with xml &lt;|endoftext|&gt; +} + + +Response Body: + +Schema for Thing: +{ + name: string, # Required. name of the Thing + requiredUnion: Union, # Required. required Union + requiredLiteral: Literal, # Required. required literal type + requiredBadDescription: string, # Required. description with xml &lt;|endoftext|&gt; +} + + + + + + +This sample shows how to call StillConvenientAsync. +"); +var client = new CadlFirstTestClient(credential); + +Response response = await client.StillConvenientAsync(); +Console.WriteLine(response.Status); +]]> + + + + +This sample shows how to call StillConvenient. +"); +var client = new CadlFirstTestClient(credential); + +Response response = client.StillConvenient(); +Console.WriteLine(response.Status); +]]> diff --git a/test/TestProjects/FirstTest-Cadl/Generated/cadl.json b/test/TestProjects/FirstTest-Cadl/Generated/cadl.json index 920988a1a3e..51c06509f5a 100644 --- a/test/TestProjects/FirstTest-Cadl/Generated/cadl.json +++ b/test/TestProjects/FirstTest-Cadl/Generated/cadl.json @@ -465,6 +465,7 @@ "Uri": "{host}", "Path": "/top/{action}", "BufferResponse": true, + "GenerateProtocolMethod": true, "GenerateConvenienceMethod": true }, { @@ -526,6 +527,7 @@ "Uri": "{host}", "Path": "/top2", "BufferResponse": true, + "GenerateProtocolMethod": true, "GenerateConvenienceMethod": false }, { @@ -634,6 +636,7 @@ "application/json" ], "BufferResponse": true, + "GenerateProtocolMethod": true, "GenerateConvenienceMethod": false }, { @@ -742,6 +745,7 @@ "application/json" ], "BufferResponse": true, + "GenerateProtocolMethod": true, "GenerateConvenienceMethod": true }, { @@ -850,6 +854,7 @@ "application/json" ], "BufferResponse": true, + "GenerateProtocolMethod": true, "GenerateConvenienceMethod": true }, { @@ -927,6 +932,7 @@ "Uri": "{host}", "Path": "/", "BufferResponse": true, + "GenerateProtocolMethod": true, "GenerateConvenienceMethod": false }, { @@ -1048,6 +1054,7 @@ "Uri": "{host}", "Path": "/hello", "BufferResponse": true, + "GenerateProtocolMethod": true, "GenerateConvenienceMethod": false }, { @@ -1202,6 +1209,7 @@ "text/plain" ], "BufferResponse": true, + "GenerateProtocolMethod": true, "GenerateConvenienceMethod": true }, { @@ -1350,6 +1358,7 @@ "application/json" ], "BufferResponse": true, + "GenerateProtocolMethod": true, "GenerateConvenienceMethod": false }, { @@ -1411,6 +1420,7 @@ "Uri": "{host}", "Path": "/demoHi", "BufferResponse": true, + "GenerateProtocolMethod": true, "GenerateConvenienceMethod": true }, { @@ -1472,23 +1482,192 @@ "Uri": "{host}", "Path": "/unknown-value", "BufferResponse": true, + "GenerateProtocolMethod": true, "GenerateConvenienceMethod": false + }, + { + "$id": "149", + "Name": "internalProtocol", + "ResourceName": "ProtocolAndConvenient", + "Description": "When set protocol false and convenient true, then the protocol method should be internal", + "Parameters": [ + { + "$ref": "48" + }, + { + "$id": "150", + "Name": "body", + "NameInRequest": "body", + "Type": { + "$ref": "18" + }, + "Location": "Body", + "IsRequired": true, + "IsApiVersion": false, + "IsResourceParameter": false, + "IsContentType": false, + "IsEndpoint": false, + "SkipUrlEncoding": false, + "Explode": false, + "Kind": "Method" + }, + { + "$id": "151", + "Name": "contentType", + "NameInRequest": "Content-Type", + "Type": { + "$id": "152", + "Name": "String", + "Kind": "String", + "IsNullable": false + }, + "Location": "Header", + "IsApiVersion": false, + "IsResourceParameter": false, + "IsContentType": true, + "IsRequired": true, + "IsEndpoint": false, + "SkipUrlEncoding": false, + "Explode": false, + "Kind": "Constant", + "DefaultValue": { + "$id": "153", + "Type": { + "$ref": "152" + }, + "Value": "application/json" + } + }, + { + "$id": "154", + "Name": "accept", + "NameInRequest": "Accept", + "Type": { + "$id": "155", + "Name": "String", + "Kind": "String", + "IsNullable": false + }, + "Location": "Header", + "IsApiVersion": false, + "IsResourceParameter": false, + "IsContentType": false, + "IsRequired": true, + "IsEndpoint": false, + "SkipUrlEncoding": false, + "Explode": false, + "Kind": "Constant", + "DefaultValue": { + "$id": "156", + "Type": { + "$ref": "155" + }, + "Value": "application/json" + } + }, + { + "$ref": "57" + } + ], + "Responses": [ + { + "$id": "157", + "StatusCodes": [ + 200 + ], + "BodyType": { + "$ref": "18" + }, + "BodyMediaType": "Json", + "Headers": [], + "IsErrorResponse": false + } + ], + "HttpMethod": "POST", + "RequestBodyMediaType": "Json", + "Uri": "{host}", + "Path": "/internalProtocol", + "RequestMediaTypes": [ + "application/json" + ], + "BufferResponse": true, + "GenerateProtocolMethod": false, + "GenerateConvenienceMethod": true + }, + { + "$id": "158", + "Name": "stillConvenient", + "ResourceName": "ProtocolAndConvenient", + "Description": "When set protocol false and convenient true, the convenient method should be generated even it has the same signature as protocol one", + "Parameters": [ + { + "$ref": "48" + }, + { + "$id": "159", + "Name": "accept", + "NameInRequest": "Accept", + "Type": { + "$id": "160", + "Name": "String", + "Kind": "String", + "IsNullable": false + }, + "Location": "Header", + "IsApiVersion": false, + "IsResourceParameter": false, + "IsContentType": false, + "IsRequired": true, + "IsEndpoint": false, + "SkipUrlEncoding": false, + "Explode": false, + "Kind": "Constant", + "DefaultValue": { + "$id": "161", + "Type": { + "$ref": "160" + }, + "Value": "application/json" + } + }, + { + "$ref": "57" + } + ], + "Responses": [ + { + "$id": "162", + "StatusCodes": [ + 204 + ], + "BodyMediaType": "Json", + "Headers": [], + "IsErrorResponse": false + } + ], + "HttpMethod": "GET", + "RequestBodyMediaType": "Json", + "Uri": "{host}", + "Path": "/stillConvenient", + "BufferResponse": true, + "GenerateProtocolMethod": false, + "GenerateConvenienceMethod": true } ], "Protocol": { - "$id": "149" + "$id": "163" }, "Creatable": true } ], "Auth": { - "$id": "150", + "$id": "164", "ApiKey": { - "$id": "151", + "$id": "165", "Name": "x-ms-api-key" }, "OAuth2": { - "$id": "152", + "$id": "166", "Scopes": [ "https://api.example.com/.default" ] diff --git a/test/TestProjects/Lro-Basic-Cadl/Generated/cadl.json b/test/TestProjects/Lro-Basic-Cadl/Generated/cadl.json index d41822e808b..8ee1262f412 100644 --- a/test/TestProjects/Lro-Basic-Cadl/Generated/cadl.json +++ b/test/TestProjects/Lro-Basic-Cadl/Generated/cadl.json @@ -278,6 +278,7 @@ "IsErrorResponse": false } }, + "GenerateProtocolMethod": true, "GenerateConvenienceMethod": true }, { @@ -473,6 +474,7 @@ "IsErrorResponse": false } }, + "GenerateProtocolMethod": true, "GenerateConvenienceMethod": true }, { @@ -623,6 +625,7 @@ "IsErrorResponse": false } }, + "GenerateProtocolMethod": true, "GenerateConvenienceMethod": true } ], diff --git a/test/TestProjects/Lro-Basic-Cadl/Lro-Basic-Cadl.cadl b/test/TestProjects/Lro-Basic-Cadl/Lro-Basic-Cadl.cadl index d69ac74b092..b46274386ae 100644 --- a/test/TestProjects/Lro-Basic-Cadl/Lro-Basic-Cadl.cadl +++ b/test/TestProjects/Lro-Basic-Cadl/Lro-Basic-Cadl.cadl @@ -38,15 +38,15 @@ model Thing { interface Authoring { createProjectStatusMonitor is CustomCore.PollingOperation; - @convenienceAPI + @convenientAPI(true) @Azure.Core.pollingOperation(Authoring.createProjectStatusMonitor) createProject is Azure.Core.LongRunningResourceCreateWithServiceProvidedName; - @convenienceAPI + @convenientAPI(true) @Azure.Core.pollingOperation(Authoring.createProjectStatusMonitor) op updateProject is Azure.Core.LongRunningResourceCreateOrReplace; - @convenienceAPI + @convenientAPI(true) @Azure.Core.pollingOperation(Authoring.createProjectStatusMonitor) op createThing is CustomCore.LongRunningRpcOperation; } @@ -59,7 +59,7 @@ namespace CustomCore { } @Cadl.Http.route("operations") - @convenienceAPI + @convenientAPI(true) op PollingOperation is Azure.Core.ResourceRead>; @doc("Long running RPC operation template") diff --git a/test/TestProjects/MixAPIVersion-Cadl/Generated/cadl.json b/test/TestProjects/MixAPIVersion-Cadl/Generated/cadl.json index a2fb64eb699..993e0d7c970 100644 --- a/test/TestProjects/MixAPIVersion-Cadl/Generated/cadl.json +++ b/test/TestProjects/MixAPIVersion-Cadl/Generated/cadl.json @@ -288,6 +288,7 @@ "Uri": "{petStoreUrl}", "Path": "/pets/Pet/{name}", "BufferResponse": true, + "GenerateProtocolMethod": true, "GenerateConvenienceMethod": false }, { @@ -382,6 +383,7 @@ "Uri": "{petStoreUrl}", "Path": "/pets/{petId}", "BufferResponse": true, + "GenerateProtocolMethod": true, "GenerateConvenienceMethod": false }, { @@ -519,6 +521,7 @@ "application/json" ], "BufferResponse": true, + "GenerateProtocolMethod": true, "GenerateConvenienceMethod": false }, { @@ -586,6 +589,7 @@ "NextLinkName": "nextLink", "ItemName": "value" }, + "GenerateProtocolMethod": true, "GenerateConvenienceMethod": false } ], diff --git a/test/TestProjects/Models-Cadl/Generated/cadl.json b/test/TestProjects/Models-Cadl/Generated/cadl.json index 12464b615f9..e1d5f6d9da2 100644 --- a/test/TestProjects/Models-Cadl/Generated/cadl.json +++ b/test/TestProjects/Models-Cadl/Generated/cadl.json @@ -1747,6 +1747,7 @@ "application/json" ], "BufferResponse": true, + "GenerateProtocolMethod": true, "GenerateConvenienceMethod": true }, { @@ -1852,6 +1853,7 @@ "application/json" ], "BufferResponse": true, + "GenerateProtocolMethod": true, "GenerateConvenienceMethod": true }, { @@ -1957,6 +1959,7 @@ "application/json" ], "BufferResponse": true, + "GenerateProtocolMethod": true, "GenerateConvenienceMethod": true }, { @@ -2063,6 +2066,7 @@ "application/json" ], "BufferResponse": true, + "GenerateProtocolMethod": true, "GenerateConvenienceMethod": true }, { @@ -2168,6 +2172,7 @@ "application/json" ], "BufferResponse": true, + "GenerateProtocolMethod": true, "GenerateConvenienceMethod": true }, { @@ -2270,6 +2275,7 @@ "application/json" ], "BufferResponse": true, + "GenerateProtocolMethod": true, "GenerateConvenienceMethod": true }, { @@ -2375,6 +2381,7 @@ "application/json" ], "BufferResponse": true, + "GenerateProtocolMethod": true, "GenerateConvenienceMethod": true }, { @@ -2433,6 +2440,7 @@ "Uri": "", "Path": "/selfReference", "BufferResponse": true, + "GenerateProtocolMethod": true, "GenerateConvenienceMethod": true }, { @@ -2538,6 +2546,7 @@ "application/json" ], "BufferResponse": true, + "GenerateProtocolMethod": true, "GenerateConvenienceMethod": true } ], diff --git a/test/TestProjects/Models-Cadl/Models-Cadl.cadl b/test/TestProjects/Models-Cadl/Models-Cadl.cadl index 541fc5ea8a7..6aeb8ca32fb 100644 --- a/test/TestProjects/Models-Cadl/Models-Cadl.cadl +++ b/test/TestProjects/Models-Cadl/Models-Cadl.cadl @@ -361,50 +361,50 @@ model RoundTripRecursiveModel { @route("/inputToRoundTrip") @doc("Input to RoundTrip") @get -@convenienceAPI +@convenientAPI(true) op inputToRoundTrip(@body input: InputModel): RoundTripModel; @route("/inputToRoundTripPrimitive") @doc("Input to RoundTripPrimitive") @get -@convenienceAPI +@convenientAPI(true) op inputToRoundTripPrimitive(@body input: InputModel): RoundTripPrimitiveModel; @route("/inputToRoundTripOptional") @doc("Input to RoundTripOptional") @get -@convenienceAPI +@convenientAPI(true) op inputToRoundTripOptional(@body input: RoundTripOptionalModel): RoundTripOptionalModel; @route("/inputToRoundTripReadOnly") @doc("Input to RoundTripReadOnly") @get -@convenienceAPI +@convenientAPI(true) @deprecated("deprecated for test") op inputToRoundTripReadOnly(@body input: InputModel): RoundTripReadOnlyModel; @route("/roundTripToOutput") @doc("RoundTrip to Output") @get -@convenienceAPI +@convenientAPI(true) op roundTripToOutput(@body input: RoundTripModel): OutputModel; @route("/inputRecursive") @doc("Input recursive model") @post -@convenienceAPI +@convenientAPI(true) op InputRecursive(@body input: InputRecursiveModel): Response<200>|ErrorModel; @route("/roundTripRecursive") @doc("RoundTrip recursive model") @put -@convenienceAPI +@convenientAPI(true) op roundTripRecursive(@body input: RoundTripRecursiveModel): RoundTripRecursiveModel; @route("/selfReference") @doc("Returns model that has property of its own type") @get -@convenienceAPI +@convenientAPI(true) op selfReference(): ErrorModel; @doc("Base model") @@ -421,5 +421,5 @@ model RoundTripOnNoUse extends NoUseBase { @doc("Returns RoundTripOnNoUse") @get -@convenienceAPI +@convenientAPI(true) op roundTripToOutputWithNoUseBase(@body input: RoundTripOnNoUse): RoundTripOnNoUse; diff --git a/test/TestProjects/Pagination-Cadl/Generated/cadl.json b/test/TestProjects/Pagination-Cadl/Generated/cadl.json index 871acb15e14..4186dc864f8 100644 --- a/test/TestProjects/Pagination-Cadl/Generated/cadl.json +++ b/test/TestProjects/Pagination-Cadl/Generated/cadl.json @@ -349,6 +349,7 @@ "NextLinkName": "customNextLink", "ItemName": "entries" }, + "GenerateProtocolMethod": true, "GenerateConvenienceMethod": true }, { @@ -415,6 +416,7 @@ "NextLinkName": "nextLink", "ItemName": "value" }, + "GenerateProtocolMethod": true, "GenerateConvenienceMethod": true } ], diff --git a/test/TestProjects/Pagination-Cadl/Pagination-Cadl.cadl b/test/TestProjects/Pagination-Cadl/Pagination-Cadl.cadl index e487fd27783..4301fb33ed9 100644 --- a/test/TestProjects/Pagination-Cadl/Pagination-Cadl.cadl +++ b/test/TestProjects/Pagination-Cadl/Pagination-Cadl.cadl @@ -185,13 +185,13 @@ namespace Pagination { @summary("Gets ledger entries from a collection corresponding to a range.") @doc("A collection id may optionally be specified. Only entries in the specified (or default) collection will be returned.") - @convenienceAPI + @convenientAPI(true) op ListPaginationLedgerEntries is Azure.Core.Foundations.ResourceList; } @route("/adp") interface UseFoundationsResourceList { @doc("List upload detail for the discovery resource.") - @convenienceAPI + @convenientAPI(true) list is CustomResourceList; } diff --git a/test/TestProjects/Parameters-Cadl/Generated/cadl.json b/test/TestProjects/Parameters-Cadl/Generated/cadl.json index fda11351637..0e48666599c 100644 --- a/test/TestProjects/Parameters-Cadl/Generated/cadl.json +++ b/test/TestProjects/Parameters-Cadl/Generated/cadl.json @@ -160,6 +160,7 @@ "Uri": "", "Path": "/parameterOrders", "BufferResponse": true, + "GenerateProtocolMethod": true, "GenerateConvenienceMethod": true }, { @@ -257,6 +258,7 @@ "Uri": "", "Path": "/parameterOrders", "BufferResponse": true, + "GenerateProtocolMethod": true, "GenerateConvenienceMethod": true } ], diff --git a/test/TestProjects/Parameters-Cadl/Parameters-Cadl.cadl b/test/TestProjects/Parameters-Cadl/Parameters-Cadl.cadl index 22e7a531830..f9c40ff7270 100644 --- a/test/TestProjects/Parameters-Cadl/Parameters-Cadl.cadl +++ b/test/TestProjects/Parameters-Cadl/Parameters-Cadl.cadl @@ -18,10 +18,10 @@ namespace ParameterOrders { id: string } - @convenienceAPI + @convenientAPI(true) op Operation(@query start: int32, @query end?: int32): Result; - @convenienceAPI + @convenientAPI(true) @head op Operation2(@query start?: int32, @query end: int32): Result; } diff --git a/test/TestProjects/PetStore-Cadl/Generated/cadl.json b/test/TestProjects/PetStore-Cadl/Generated/cadl.json index 22cc8c66e25..aa60d814546 100644 --- a/test/TestProjects/PetStore-Cadl/Generated/cadl.json +++ b/test/TestProjects/PetStore-Cadl/Generated/cadl.json @@ -214,6 +214,7 @@ "Uri": "{petStoreUrl}", "Path": "/pets/{petId}", "BufferResponse": true, + "GenerateProtocolMethod": true, "GenerateConvenienceMethod": true }, { @@ -308,6 +309,7 @@ "Uri": "{petStoreUrl}", "Path": "/pets/{petId}", "BufferResponse": true, + "GenerateProtocolMethod": true, "GenerateConvenienceMethod": true }, { @@ -415,6 +417,7 @@ "application/json" ], "BufferResponse": true, + "GenerateProtocolMethod": true, "GenerateConvenienceMethod": true }, { @@ -492,6 +495,7 @@ "Uri": "{petStoreUrl}", "Path": "/pets/{kind}", "BufferResponse": true, + "GenerateProtocolMethod": true, "GenerateConvenienceMethod": true }, { @@ -572,6 +576,7 @@ "Uri": "{petStoreUrl}", "Path": "/pets", "BufferResponse": true, + "GenerateProtocolMethod": true, "GenerateConvenienceMethod": true } ], diff --git a/test/TestProjects/PetStore-Cadl/PetStore-Cadl.cadl b/test/TestProjects/PetStore-Cadl/PetStore-Cadl.cadl index 4ba5577ef90..6d8e1a8614c 100644 --- a/test/TestProjects/PetStore-Cadl/PetStore-Cadl.cadl +++ b/test/TestProjects/PetStore-Cadl/PetStore-Cadl.cadl @@ -72,22 +72,22 @@ namespace Pets { @doc("Delete a pet.") @summary("delete.") @delete - @convenienceAPI + @convenientAPI(true) op delete(...PetId): Response<200> | Error; // @fancyDoc("List pets.") // op list(@query nextLink?: string): OkResponse> | Error; @doc("Returns a pet. Supports eTags.") - @convenienceAPI + @convenientAPI(true) op read(...PetId): Pet | (NotModifiedResponse & Pet) | Error; - @convenienceAPI + @convenientAPI(true) @post op create(@body pet: Pet): Pet | Error; - @convenienceAPI + @convenientAPI(true) @get op getPetByKind(@path kind: PetKind): Pet | Error; - @convenienceAPI + @convenientAPI(true) @get op GetFirstPet(@query start?: int32): Pet | Error; } diff --git a/test/TestProjects/RenameGetList-Cadl/Generated/cadl.json b/test/TestProjects/RenameGetList-Cadl/Generated/cadl.json index 6fbaa15b509..f79c2e664aa 100644 --- a/test/TestProjects/RenameGetList-Cadl/Generated/cadl.json +++ b/test/TestProjects/RenameGetList-Cadl/Generated/cadl.json @@ -416,6 +416,7 @@ "Uri": "{Endpoint}/language", "Path": "/authoring/analyze-text/projects/{projectName}", "BufferResponse": true, + "GenerateProtocolMethod": true, "GenerateConvenienceMethod": false }, { @@ -482,6 +483,7 @@ "NextLinkName": "nextLink", "ItemName": "value" }, + "GenerateProtocolMethod": true, "GenerateConvenienceMethod": false }, { @@ -583,6 +585,7 @@ "Uri": "{Endpoint}/language", "Path": "/authoring/analyze-text/projects/{projectName}/deployments/{deploymentName}", "BufferResponse": true, + "GenerateProtocolMethod": true, "GenerateConvenienceMethod": false }, { @@ -669,6 +672,7 @@ "NextLinkName": "nextLink", "ItemName": "value" }, + "GenerateProtocolMethod": true, "GenerateConvenienceMethod": false } ], diff --git a/test/TestProjects/Spread-Cadl/Generated/cadl.json b/test/TestProjects/Spread-Cadl/Generated/cadl.json index e12cdf6a13f..670ff977873 100644 --- a/test/TestProjects/Spread-Cadl/Generated/cadl.json +++ b/test/TestProjects/Spread-Cadl/Generated/cadl.json @@ -318,6 +318,7 @@ "application/json" ], "BufferResponse": true, + "GenerateProtocolMethod": true, "GenerateConvenienceMethod": true }, { @@ -423,6 +424,7 @@ "application/json" ], "BufferResponse": true, + "GenerateProtocolMethod": true, "GenerateConvenienceMethod": true }, { @@ -568,6 +570,7 @@ "application/json" ], "BufferResponse": true, + "GenerateProtocolMethod": true, "GenerateConvenienceMethod": true }, { @@ -713,6 +716,7 @@ "application/json" ], "BufferResponse": true, + "GenerateProtocolMethod": true, "GenerateConvenienceMethod": true }, { @@ -858,6 +862,7 @@ "application/json" ], "BufferResponse": true, + "GenerateProtocolMethod": true, "GenerateConvenienceMethod": true } ], diff --git a/test/TestProjects/Spread-Cadl/Spread-Cadl.cadl b/test/TestProjects/Spread-Cadl/Spread-Cadl.cadl index 08e6c132b6c..8f7cca19da9 100644 --- a/test/TestProjects/Spread-Cadl/Spread-Cadl.cadl +++ b/test/TestProjects/Spread-Cadl/Spread-Cadl.cadl @@ -63,29 +63,29 @@ alias ThingAliasWithSpreadAlias = { @route("/spreadModel") @doc("spread a model as body.") @post -@convenienceAPI +@convenientAPI(true) op spreadModel( ...Thing ): void; @route("/spreadAlias") @doc("spread an alias as body.") @post -@convenienceAPI +@convenientAPI(true) op spreadAlias( ...ThingAlias ): void; @route("/spreadMultiTargetAlias") @doc("spread an alias which has multiple target property as body.") @post -@convenienceAPI +@convenientAPI(true) op spreadMultiTargetAlias( ...ThingMultiTargetAlias ): void; @route("/spreadAliasWithModel") @doc("spread an alias which contains a complex model property as body.") @post -@convenienceAPI +@convenientAPI(true) op spreadAliasWithModel( ...ThingAliasWithModel ): void; @route("/spreadAliasWithSpreadAlias") @doc("spread an alias with contains another alias property as body.") @post -@convenienceAPI +@convenientAPI(true) op spreadAliasWithSpreadAlias( ...ThingAliasWithSpreadAlias ): void; \ No newline at end of file From 953df6002184c3962015521dfa79e30124ff11c6 Mon Sep 17 00:00:00 2001 From: pshao25 <97225342+pshao25@users.noreply.github.com> Date: Fri, 3 Feb 2023 13:48:15 +0800 Subject: [PATCH 2/4] Fix --- src/CADL.Extension/Emitter.Csharp/src/emitter.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/CADL.Extension/Emitter.Csharp/src/emitter.ts b/src/CADL.Extension/Emitter.Csharp/src/emitter.ts index 549bbe3a4ec..1a7aec851ca 100644 --- a/src/CADL.Extension/Emitter.Csharp/src/emitter.ts +++ b/src/CADL.Extension/Emitter.Csharp/src/emitter.ts @@ -768,8 +768,14 @@ function loadOperation( mediaTypes.push(contentTypeParameter.DefaultValue?.Value); } const requestMethod = parseHttpRequestMethod(verb); - const generateProtocol: boolean = shouldGenerateProtocol(createDpgContext(context), op); - const generateConvenience: boolean = requestMethod !== RequestMethod.PATCH && (shouldGenerateConvenient(createDpgContext(context), op) || getConvenienceAPIName(program, op) !== undefined); + const generateProtocol: boolean = shouldGenerateProtocol( + createDpgContext(context), + op + ); + const generateConvenience: boolean = + requestMethod !== RequestMethod.PATCH && + (shouldGenerateConvenient(createDpgContext(context), op) || + getConvenienceAPIName(program, op) !== undefined); /* handle lro */ /* handle paging. */ From 9d122f346982725fe88a8b4e7bcd7c443fec0958 Mon Sep 17 00:00:00 2001 From: pshao25 <97225342+pshao25@users.noreply.github.com> Date: Fri, 3 Feb 2023 14:10:25 +0800 Subject: [PATCH 3/4] Update --- .../samples/CadlFirstTest/Generated/cadl.json | 26 ++++++++++++------- .../samples/petStore/Generated/cadl.json | 18 ++++++++----- .../TestProjects/array/Generated/cadl.json | 5 ++-- .../TestProjects/client/Generated/cadl.json | 12 ++++++--- .../TestProjects/endpoint/Generated/cadl.json | 3 ++- .../Generated/cadl.json | 3 ++- .../TestProjects/enum/Generated/cadl.json | 11 ++++---- .../TestProjects/head/Generated/cadl.json | 8 +++--- .../interface/Generated/cadl.json | 14 ++++++---- .../test/TestProjects/lro/Generated/cadl.json | 1 + .../operationGroup/Generated/cadl.json | 18 ++++++++----- .../pagination/Generated/cadl.json | 7 ++--- .../polymorphism/Generated/cadl.json | 25 +++++++++++------- .../TestProjects/security/Generated/cadl.json | 3 ++- .../string-format/Generated/cadl.json | 6 +++-- .../visibility/Generated/cadl.json | 5 ++-- 16 files changed, 103 insertions(+), 62 deletions(-) diff --git a/src/CADL.Extension/Emitter.Csharp/samples/CadlFirstTest/Generated/cadl.json b/src/CADL.Extension/Emitter.Csharp/samples/CadlFirstTest/Generated/cadl.json index f2c8c90623d..bf262d93bd7 100644 --- a/src/CADL.Extension/Emitter.Csharp/samples/CadlFirstTest/Generated/cadl.json +++ b/src/CADL.Extension/Emitter.Csharp/samples/CadlFirstTest/Generated/cadl.json @@ -30,7 +30,7 @@ ], "IsExtensible": false, "IsNullable": false, - "Usage": "None" + "Usage": "Input" }, { "$id": "6", @@ -57,7 +57,7 @@ ], "IsExtensible": true, "IsNullable": false, - "Usage": "None" + "Usage": "Input" } ], "Models": [ @@ -66,7 +66,7 @@ "Name": "Thing", "Namespace": "Demo.HelloWorld", "IsNullable": false, - "Usage": "None", + "Usage": "RoundTrip", "Properties": [ { "$id": "11", @@ -90,7 +90,7 @@ "Name": "RoundTripModel", "Namespace": "Demo.HelloWorld", "IsNullable": false, - "Usage": "None", + "Usage": "Input", "Properties": [ { "$id": "14", @@ -275,7 +275,8 @@ "Uri": "", "Path": "/top/{action}", "BufferResponse": true, - "GenerateConvenienceMethod": false + "GenerateProtocolMethod": true, + "GenerateConvenienceMethod": true }, { "$id": "35", @@ -333,7 +334,8 @@ "Uri": "", "Path": "/top2", "BufferResponse": true, - "GenerateConvenienceMethod": false + "GenerateProtocolMethod": true, + "GenerateConvenienceMethod": true }, { "$id": "40", @@ -438,7 +440,8 @@ "application/json" ], "BufferResponse": true, - "GenerateConvenienceMethod": false + "GenerateProtocolMethod": true, + "GenerateConvenienceMethod": true }, { "$id": "49", @@ -496,7 +499,8 @@ "Uri": "", "Path": "/hello", "BufferResponse": true, - "GenerateConvenienceMethod": false + "GenerateProtocolMethod": true, + "GenerateConvenienceMethod": true }, { "$id": "54", @@ -601,7 +605,8 @@ "application/json" ], "BufferResponse": true, - "GenerateConvenienceMethod": false + "GenerateProtocolMethod": true, + "GenerateConvenienceMethod": true }, { "$id": "63", @@ -659,7 +664,8 @@ "Uri": "", "Path": "/demoHi", "BufferResponse": true, - "GenerateConvenienceMethod": false + "GenerateProtocolMethod": true, + "GenerateConvenienceMethod": true } ], "Protocol": { diff --git a/src/CADL.Extension/Emitter.Csharp/samples/petStore/Generated/cadl.json b/src/CADL.Extension/Emitter.Csharp/samples/petStore/Generated/cadl.json index 450a60f74f4..408183e1700 100644 --- a/src/CADL.Extension/Emitter.Csharp/samples/petStore/Generated/cadl.json +++ b/src/CADL.Extension/Emitter.Csharp/samples/petStore/Generated/cadl.json @@ -12,7 +12,7 @@ "Name": "Pet", "Namespace": "PetStore", "IsNullable": false, - "Usage": "None", + "Usage": "RoundTrip", "Properties": [ { "$id": "3", @@ -66,7 +66,7 @@ "Name": "ToyListResults", "Namespace": "PetStore", "IsNullable": false, - "Usage": "None", + "Usage": "Output", "Properties": [ { "$id": "10", @@ -81,7 +81,7 @@ "Name": "Toy", "Namespace": "PetStore", "IsNullable": false, - "Usage": "None", + "Usage": "Output", "Properties": [ { "$id": "13", @@ -286,7 +286,8 @@ "Uri": "{petStoreUrl}", "Path": "/pets/{petId}", "BufferResponse": true, - "GenerateConvenienceMethod": false + "GenerateProtocolMethod": true, + "GenerateConvenienceMethod": true }, { "$id": "35", @@ -380,7 +381,8 @@ "Uri": "{petStoreUrl}", "Path": "/pets/{petId}", "BufferResponse": true, - "GenerateConvenienceMethod": false + "GenerateProtocolMethod": true, + "GenerateConvenienceMethod": true }, { "$id": "43", @@ -487,7 +489,8 @@ "application/json" ], "BufferResponse": true, - "GenerateConvenienceMethod": false + "GenerateProtocolMethod": true, + "GenerateConvenienceMethod": true }, { "$id": "52", @@ -587,7 +590,8 @@ "Uri": "{petStoreUrl}", "Path": "/pets/{petId}/toys", "BufferResponse": true, - "GenerateConvenienceMethod": false + "GenerateProtocolMethod": true, + "GenerateConvenienceMethod": true } ], "Protocol": { diff --git a/src/CADL.Extension/Emitter.Csharp/test/TestProjects/array/Generated/cadl.json b/src/CADL.Extension/Emitter.Csharp/test/TestProjects/array/Generated/cadl.json index 7cce1a0868d..e28598b9125 100644 --- a/src/CADL.Extension/Emitter.Csharp/test/TestProjects/array/Generated/cadl.json +++ b/src/CADL.Extension/Emitter.Csharp/test/TestProjects/array/Generated/cadl.json @@ -12,7 +12,7 @@ "Name": "Pet", "Namespace": "Cadl.TestServer.ArrayBasic", "IsNullable": false, - "Usage": "None", + "Usage": "Output", "Properties": [ { "$id": "3", @@ -209,7 +209,8 @@ "Uri": "{host}", "Path": "/pets", "BufferResponse": true, - "GenerateConvenienceMethod": false + "GenerateProtocolMethod": true, + "GenerateConvenienceMethod": true } ], "Protocol": { diff --git a/src/CADL.Extension/Emitter.Csharp/test/TestProjects/client/Generated/cadl.json b/src/CADL.Extension/Emitter.Csharp/test/TestProjects/client/Generated/cadl.json index d34cb6d197d..3159d523061 100644 --- a/src/CADL.Extension/Emitter.Csharp/test/TestProjects/client/Generated/cadl.json +++ b/src/CADL.Extension/Emitter.Csharp/test/TestProjects/client/Generated/cadl.json @@ -118,7 +118,8 @@ "Uri": "{clientServiceUrl}", "Path": "/Alpha", "BufferResponse": true, - "GenerateConvenienceMethod": false + "GenerateProtocolMethod": true, + "GenerateConvenienceMethod": true } ], "Protocol": { @@ -192,7 +193,8 @@ "Uri": "{clientServiceUrl}", "Path": "/Beta", "BufferResponse": true, - "GenerateConvenienceMethod": false + "GenerateProtocolMethod": true, + "GenerateConvenienceMethod": true } ], "Protocol": { @@ -266,7 +268,8 @@ "Uri": "{clientServiceUrl}", "Path": "/Gamma", "BufferResponse": true, - "GenerateConvenienceMethod": false + "GenerateProtocolMethod": true, + "GenerateConvenienceMethod": true }, { "$id": "31", @@ -329,7 +332,8 @@ "Uri": "{clientServiceUrl}", "Path": "/Gamma", "BufferResponse": true, - "GenerateConvenienceMethod": false + "GenerateProtocolMethod": true, + "GenerateConvenienceMethod": true } ], "Protocol": { diff --git a/src/CADL.Extension/Emitter.Csharp/test/TestProjects/endpoint/Generated/cadl.json b/src/CADL.Extension/Emitter.Csharp/test/TestProjects/endpoint/Generated/cadl.json index 5760989cdd9..41648fc07a1 100644 --- a/src/CADL.Extension/Emitter.Csharp/test/TestProjects/endpoint/Generated/cadl.json +++ b/src/CADL.Extension/Emitter.Csharp/test/TestProjects/endpoint/Generated/cadl.json @@ -133,7 +133,8 @@ "Uri": "{endpointServiceUrl}", "Path": "/endpoint/{action}", "BufferResponse": true, - "GenerateConvenienceMethod": false + "GenerateProtocolMethod": true, + "GenerateConvenienceMethod": true } ], "Protocol": { diff --git a/src/CADL.Extension/Emitter.Csharp/test/TestProjects/endpointWithMultiplePart/Generated/cadl.json b/src/CADL.Extension/Emitter.Csharp/test/TestProjects/endpointWithMultiplePart/Generated/cadl.json index 99a630d13f7..e0ac8fbd048 100644 --- a/src/CADL.Extension/Emitter.Csharp/test/TestProjects/endpointWithMultiplePart/Generated/cadl.json +++ b/src/CADL.Extension/Emitter.Csharp/test/TestProjects/endpointWithMultiplePart/Generated/cadl.json @@ -153,7 +153,8 @@ "Uri": "{endpointServiceUrl}/id/{id}", "Path": "/endpoint/{action}", "BufferResponse": true, - "GenerateConvenienceMethod": false + "GenerateProtocolMethod": true, + "GenerateConvenienceMethod": true } ], "Protocol": { diff --git a/src/CADL.Extension/Emitter.Csharp/test/TestProjects/enum/Generated/cadl.json b/src/CADL.Extension/Emitter.Csharp/test/TestProjects/enum/Generated/cadl.json index 88928670aa0..463e17abf5c 100644 --- a/src/CADL.Extension/Emitter.Csharp/test/TestProjects/enum/Generated/cadl.json +++ b/src/CADL.Extension/Emitter.Csharp/test/TestProjects/enum/Generated/cadl.json @@ -52,7 +52,7 @@ ], "IsExtensible": true, "IsNullable": false, - "Usage": "None" + "Usage": "Input" }, { "$id": "10", @@ -100,7 +100,7 @@ ], "IsExtensible": false, "IsNullable": false, - "Usage": "None" + "Usage": "Input" }, { "$id": "18", @@ -162,7 +162,7 @@ ], "IsExtensible": true, "IsNullable": false, - "Usage": "None" + "Usage": "Input" } ], "Models": [ @@ -172,7 +172,7 @@ "Namespace": "Cadl.EnumPropertiesBasic", "Description": "Input model with enum properties.", "IsNullable": false, - "Usage": "None", + "Usage": "Input", "Properties": [ { "$id": "28", @@ -389,7 +389,8 @@ "application/json" ], "BufferResponse": true, - "GenerateConvenienceMethod": false + "GenerateProtocolMethod": true, + "GenerateConvenienceMethod": true } ], "Protocol": { diff --git a/src/CADL.Extension/Emitter.Csharp/test/TestProjects/head/Generated/cadl.json b/src/CADL.Extension/Emitter.Csharp/test/TestProjects/head/Generated/cadl.json index b3e3eec07f0..cbf4424f853 100644 --- a/src/CADL.Extension/Emitter.Csharp/test/TestProjects/head/Generated/cadl.json +++ b/src/CADL.Extension/Emitter.Csharp/test/TestProjects/head/Generated/cadl.json @@ -12,7 +12,7 @@ "Name": "Thing", "Namespace": "Cadl.HeadClient", "IsNullable": false, - "Usage": "None", + "Usage": "Input", "Properties": [ { "$id": "3", @@ -216,7 +216,8 @@ "application/json" ], "BufferResponse": true, - "GenerateConvenienceMethod": false + "GenerateProtocolMethod": true, + "GenerateConvenienceMethod": true }, { "$id": "25", @@ -326,7 +327,8 @@ "text/plain" ], "BufferResponse": true, - "GenerateConvenienceMethod": false + "GenerateProtocolMethod": true, + "GenerateConvenienceMethod": true } ], "Protocol": { diff --git a/src/CADL.Extension/Emitter.Csharp/test/TestProjects/interface/Generated/cadl.json b/src/CADL.Extension/Emitter.Csharp/test/TestProjects/interface/Generated/cadl.json index 46797891675..8125d1b7809 100644 --- a/src/CADL.Extension/Emitter.Csharp/test/TestProjects/interface/Generated/cadl.json +++ b/src/CADL.Extension/Emitter.Csharp/test/TestProjects/interface/Generated/cadl.json @@ -13,7 +13,7 @@ "Namespace": "Cadl.TestServer.MultiInterfaceClient", "Description": "Simple model.", "IsNullable": false, - "Usage": "Output", + "Usage": "RoundTrip", "Properties": [ { "$id": "3", @@ -38,7 +38,7 @@ "Namespace": "Cadl.TestServer.MultiInterfaceClient", "Description": "Simple model.", "IsNullable": false, - "Usage": "None", + "Usage": "RoundTrip", "Properties": [ { "$id": "6", @@ -179,6 +179,7 @@ "Uri": "{host}", "Path": "/dogs", "BufferResponse": true, + "GenerateProtocolMethod": true, "GenerateConvenienceMethod": true }, { @@ -287,7 +288,8 @@ "application/json" ], "BufferResponse": true, - "GenerateConvenienceMethod": false + "GenerateProtocolMethod": true, + "GenerateConvenienceMethod": true }, { "$id": "31", @@ -348,7 +350,8 @@ "Uri": "{host}", "Path": "/cats", "BufferResponse": true, - "GenerateConvenienceMethod": false + "GenerateProtocolMethod": true, + "GenerateConvenienceMethod": true }, { "$id": "36", @@ -456,7 +459,8 @@ "application/json" ], "BufferResponse": true, - "GenerateConvenienceMethod": false + "GenerateProtocolMethod": true, + "GenerateConvenienceMethod": true } ], "Protocol": { diff --git a/src/CADL.Extension/Emitter.Csharp/test/TestProjects/lro/Generated/cadl.json b/src/CADL.Extension/Emitter.Csharp/test/TestProjects/lro/Generated/cadl.json index c509df5308b..52673cf1385 100644 --- a/src/CADL.Extension/Emitter.Csharp/test/TestProjects/lro/Generated/cadl.json +++ b/src/CADL.Extension/Emitter.Csharp/test/TestProjects/lro/Generated/cadl.json @@ -284,6 +284,7 @@ "application/merge-patch+json" ], "BufferResponse": true, + "GenerateProtocolMethod": true, "GenerateConvenienceMethod": false } ], diff --git a/src/CADL.Extension/Emitter.Csharp/test/TestProjects/operationGroup/Generated/cadl.json b/src/CADL.Extension/Emitter.Csharp/test/TestProjects/operationGroup/Generated/cadl.json index 10396945583..cb62a049fdd 100644 --- a/src/CADL.Extension/Emitter.Csharp/test/TestProjects/operationGroup/Generated/cadl.json +++ b/src/CADL.Extension/Emitter.Csharp/test/TestProjects/operationGroup/Generated/cadl.json @@ -118,7 +118,8 @@ "Uri": "{operationGroupServiceUrl}", "Path": "/top", "BufferResponse": true, - "GenerateConvenienceMethod": false + "GenerateProtocolMethod": true, + "GenerateConvenienceMethod": true }, { "$id": "15", @@ -181,7 +182,8 @@ "Uri": "{operationGroupServiceUrl}", "Path": "/Alpha", "BufferResponse": true, - "GenerateConvenienceMethod": false + "GenerateProtocolMethod": true, + "GenerateConvenienceMethod": true } ], "Protocol": { @@ -255,7 +257,8 @@ "Uri": "{operationGroupServiceUrl}", "Path": "/Beta", "BufferResponse": true, - "GenerateConvenienceMethod": false + "GenerateProtocolMethod": true, + "GenerateConvenienceMethod": true }, { "$id": "29", @@ -318,7 +321,8 @@ "Uri": "{operationGroupServiceUrl}", "Path": "/SubBeta", "BufferResponse": true, - "GenerateConvenienceMethod": false + "GenerateProtocolMethod": true, + "GenerateConvenienceMethod": true } ], "Protocol": { @@ -393,7 +397,8 @@ "Uri": "{operationGroupServiceUrl}", "Path": "/Gamma", "BufferResponse": true, - "GenerateConvenienceMethod": false + "GenerateProtocolMethod": true, + "GenerateConvenienceMethod": true }, { "$id": "43", @@ -456,7 +461,8 @@ "Uri": "{operationGroupServiceUrl}", "Path": "/Gamma", "BufferResponse": true, - "GenerateConvenienceMethod": false + "GenerateProtocolMethod": true, + "GenerateConvenienceMethod": true } ], "Protocol": { diff --git a/src/CADL.Extension/Emitter.Csharp/test/TestProjects/pagination/Generated/cadl.json b/src/CADL.Extension/Emitter.Csharp/test/TestProjects/pagination/Generated/cadl.json index cfc7c3c193e..c50eb1eeba9 100644 --- a/src/CADL.Extension/Emitter.Csharp/test/TestProjects/pagination/Generated/cadl.json +++ b/src/CADL.Extension/Emitter.Csharp/test/TestProjects/pagination/Generated/cadl.json @@ -12,7 +12,7 @@ "Namespace": "Azure.Core.Foundations", "Description": "Paged collection of LedgerEntry items", "IsNullable": false, - "Usage": "None", + "Usage": "Output", "Properties": [ { "$id": "3", @@ -27,7 +27,7 @@ "Name": "LedgerEntry", "Namespace": "Pagination", "IsNullable": false, - "Usage": "None", + "Usage": "Output", "Properties": [ { "$id": "6", @@ -219,7 +219,8 @@ "NextLinkName": "nextLink", "ItemName": "value" }, - "GenerateConvenienceMethod": false + "GenerateProtocolMethod": true, + "GenerateConvenienceMethod": true } ], "Protocol": { diff --git a/src/CADL.Extension/Emitter.Csharp/test/TestProjects/polymorphism/Generated/cadl.json b/src/CADL.Extension/Emitter.Csharp/test/TestProjects/polymorphism/Generated/cadl.json index b8a9d26c806..8af81470879 100644 --- a/src/CADL.Extension/Emitter.Csharp/test/TestProjects/polymorphism/Generated/cadl.json +++ b/src/CADL.Extension/Emitter.Csharp/test/TestProjects/polymorphism/Generated/cadl.json @@ -13,7 +13,7 @@ "Description": "This is base model for polymorphic multiple levels inheritance with a discriminator.", "IsNullable": false, "DiscriminatorPropertyName": "kind", - "Usage": "None", + "Usage": "RoundTrip", "Properties": [ { "$id": "3", @@ -43,7 +43,7 @@ "BaseModel": { "$ref": "2" }, - "Usage": "None", + "Usage": "RoundTrip", "Properties": [] }, { @@ -56,7 +56,7 @@ "BaseModel": { "$ref": "5" }, - "Usage": "None", + "Usage": "RoundTrip", "Properties": [] }, { @@ -69,7 +69,7 @@ "BaseModel": { "$ref": "5" }, - "Usage": "None", + "Usage": "RoundTrip", "Properties": [] }, { @@ -82,7 +82,7 @@ "BaseModel": { "$ref": "2" }, - "Usage": "None", + "Usage": "RoundTrip", "Properties": [ { "$id": "9", @@ -293,7 +293,8 @@ "application/json" ], "BufferResponse": true, - "GenerateConvenienceMethod": false + "GenerateProtocolMethod": true, + "GenerateConvenienceMethod": true }, { "$id": "31", @@ -354,7 +355,8 @@ "Uri": "{Endpoint}", "Path": "/discriminated/recursivemodel", "BufferResponse": true, - "GenerateConvenienceMethod": false + "GenerateProtocolMethod": true, + "GenerateConvenienceMethod": true }, { "$id": "36", @@ -459,7 +461,8 @@ "application/json" ], "BufferResponse": true, - "GenerateConvenienceMethod": false + "GenerateProtocolMethod": true, + "GenerateConvenienceMethod": true }, { "$id": "45", @@ -520,7 +523,8 @@ "Uri": "{Endpoint}", "Path": "/discriminated/missingdiscriminator", "BufferResponse": true, - "GenerateConvenienceMethod": false + "GenerateProtocolMethod": true, + "GenerateConvenienceMethod": true }, { "$id": "50", @@ -581,7 +585,8 @@ "Uri": "{Endpoint}", "Path": "/discriminated/wrongdiscriminator", "BufferResponse": true, - "GenerateConvenienceMethod": false + "GenerateProtocolMethod": true, + "GenerateConvenienceMethod": true } ], "Protocol": { diff --git a/src/CADL.Extension/Emitter.Csharp/test/TestProjects/security/Generated/cadl.json b/src/CADL.Extension/Emitter.Csharp/test/TestProjects/security/Generated/cadl.json index df75301bd51..68f1fdef03c 100644 --- a/src/CADL.Extension/Emitter.Csharp/test/TestProjects/security/Generated/cadl.json +++ b/src/CADL.Extension/Emitter.Csharp/test/TestProjects/security/Generated/cadl.json @@ -125,7 +125,8 @@ "Uri": "{host}", "Path": "/security", "BufferResponse": true, - "GenerateConvenienceMethod": false + "GenerateProtocolMethod": true, + "GenerateConvenienceMethod": true } ], "Protocol": { diff --git a/src/CADL.Extension/Emitter.Csharp/test/TestProjects/string-format/Generated/cadl.json b/src/CADL.Extension/Emitter.Csharp/test/TestProjects/string-format/Generated/cadl.json index fe938019ce3..80a697e74ff 100644 --- a/src/CADL.Extension/Emitter.Csharp/test/TestProjects/string-format/Generated/cadl.json +++ b/src/CADL.Extension/Emitter.Csharp/test/TestProjects/string-format/Generated/cadl.json @@ -113,7 +113,8 @@ "Uri": "", "Path": "/zonedDateTime/{time}", "BufferResponse": true, - "GenerateConvenienceMethod": false + "GenerateProtocolMethod": true, + "GenerateConvenienceMethod": true }, { "$id": "14", @@ -188,7 +189,8 @@ "Uri": "", "Path": "/uri/{uri}", "BufferResponse": true, - "GenerateConvenienceMethod": false + "GenerateProtocolMethod": true, + "GenerateConvenienceMethod": true } ], "Protocol": { diff --git a/src/CADL.Extension/Emitter.Csharp/test/TestProjects/visibility/Generated/cadl.json b/src/CADL.Extension/Emitter.Csharp/test/TestProjects/visibility/Generated/cadl.json index b9cadde66f3..596033a7fbd 100644 --- a/src/CADL.Extension/Emitter.Csharp/test/TestProjects/visibility/Generated/cadl.json +++ b/src/CADL.Extension/Emitter.Csharp/test/TestProjects/visibility/Generated/cadl.json @@ -12,7 +12,7 @@ "Name": "Dog", "Namespace": "Cadl.visibility", "IsNullable": false, - "Usage": "None", + "Usage": "Input", "Properties": [ { "$id": "3", @@ -226,7 +226,8 @@ "application/json" ], "BufferResponse": true, - "GenerateConvenienceMethod": false + "GenerateProtocolMethod": true, + "GenerateConvenienceMethod": true } ], "Protocol": { From d489583cf63f642eda7ffde3bff64e5640cc775f Mon Sep 17 00:00:00 2001 From: pshao25 <97225342+pshao25@users.noreply.github.com> Date: Fri, 3 Feb 2023 15:47:48 +0800 Subject: [PATCH 4/4] Fix --- src/CADL.Extension/Emitter.Csharp/src/emitter.ts | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/CADL.Extension/Emitter.Csharp/src/emitter.ts b/src/CADL.Extension/Emitter.Csharp/src/emitter.ts index 1a7aec851ca..4921415cc1d 100644 --- a/src/CADL.Extension/Emitter.Csharp/src/emitter.ts +++ b/src/CADL.Extension/Emitter.Csharp/src/emitter.ts @@ -78,6 +78,7 @@ import { execSync } from "child_process"; import { Client, createDpgContext, + DpgEmitterOptions, getConvenienceAPIName, isApiVersion, isOperationGroup, @@ -93,7 +94,7 @@ import { getVersions } from "@cadl-lang/versioning"; import { EmitContext } from "@cadl-lang/compiler/*"; import { capitalize } from "./lib/utils.js"; -export interface NetEmitterOptions { +export type NetEmitterOptions = { outputFile?: string; logFile?: string; namespace?: string; @@ -110,10 +111,7 @@ export interface NetEmitterOptions { "clear-output-folder"?: boolean; "save-inputs"?: boolean; "model-namespace"?: boolean; - "generate-protocol-methods"?: boolean; - "generate-convenience-methods"?: boolean; - "package-name"?: string; -} +} & DpgEmitterOptions; const defaultOptions = { outputFile: "cadl.json", @@ -122,7 +120,10 @@ const defaultOptions = { "new-project": false, csharpGeneratorPath: dllFilePath, "clear-output-folder": false, - "save-inputs": false + "save-inputs": false, + "generate-protocol-methods": true, + "generate-convenience-methods": true, + "package-name": undefined }; const NetEmitterOptionsSchema: JSONSchemaType = {