Skip to content

Commit b8ebef7

Browse files
authored
Remove the parameter generateConvenienceAPI (#3069)
* Remove the parameter generateConvenienceAPI * Update * Fix * Add tests for model usage * Update
1 parent 38393fe commit b8ebef7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+3480
-83
lines changed

eng/Generate.ps1

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ $sharedSource = Join-Path $repoRoot 'src' 'assets'
1919
$configurationPath = Join-Path $repoRoot 'readme.md'
2020
$testServerSwaggerPath = Join-Path $repoRoot 'node_modules' '@microsoft.azure' 'autorest.testserver' 'swagger'
2121
$cadlRanchFilePath = Join-Path $repoRoot 'node_modules' '@azure-tools' 'cadl-ranch-specs' 'http'
22-
$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'
22+
$cadlEmitOptions = '--option @azure-tools/cadl-csharp.save-inputs=true --option @azure-tools/cadl-csharp.clear-output-folder=true'
2323

2424
function Add-Swagger ([string]$name, [string]$output, [string]$arguments) {
2525
$swaggerDefinitions[$name] = @{
@@ -56,7 +56,7 @@ function Add-TestServer-Swagger ([string]$testName, [string]$projectSuffix, [str
5656
function Add-CadlRanch-Cadl([string]$testName, [string]$projectPrefix, [string]$cadlRanchProjectsDirectory) {
5757
$projectDirectory = Join-Path $cadlRanchProjectsDirectory $testName
5858
$cadlMain = Join-Path $cadlRanchFilePath $testName "main.cadl"
59-
Add-Cadl "$projectPrefix$testName" $projectDirectory $cadlMain "--option @azure-tools/cadl-csharp.generateConvenienceAPI=true --option @azure-tools/cadl-csharp.unreferenced-types-handling=keepAll"
59+
Add-Cadl "$projectPrefix$testName" $projectDirectory $cadlMain "--option @azure-tools/cadl-csharp.unreferenced-types-handling=keepAll"
6060
}
6161

6262
$testNames =
@@ -194,7 +194,7 @@ if (!($Exclude -contains "TestProjects"))
194194
continue
195195
}
196196
if ($testName.EndsWith("Cadl")) {
197-
Add-Cadl $testName $directory
197+
Add-Cadl $testName $directory "" "--option @azure-tools/cadl-csharp.generate-convenience-methods=false"
198198
} else {
199199
if (Test-Path $readmeConfigurationPath)
200200
{
@@ -246,7 +246,7 @@ if (!($Exclude -contains "Samples"))
246246
$cadlMain = Join-Path $projectDirectory "main.cadl"
247247
$cadlClient = Join-Path $projectDirectory "client.cadl"
248248
$mainCadlFile = If (Test-Path "$cadlClient") { Resolve-Path "$cadlClient" } Else { Resolve-Path "$cadlMain"}
249-
Add-Cadl $projectName $projectDirectory $mainCadlFile "--option @azure-tools/cadl-csharp.generateConvenienceAPI=true"
249+
Add-Cadl $projectName $projectDirectory $mainCadlFile
250250
}
251251
}
252252

@@ -256,7 +256,8 @@ $cadlRanchProjectPaths =
256256
'authentication/api-key',
257257
'authentication/oauth2',
258258
'models/property-optional',
259-
'models/property-types'
259+
'models/property-types',
260+
'models/usage'
260261

261262
if (!($Exclude -contains "CadlRanchProjects"))
262263
{

src/AutoRest.CSharp/Properties/launchSettings.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,10 @@
180180
"commandName": "Project",
181181
"commandLineArgs": "--standalone $(SolutionDir)\\test\\CadlRanchProjects\\models\\property-types\\Generated"
182182
},
183+
"cadl-models/usage": {
184+
"commandName": "Project",
185+
"commandLineArgs": "--standalone $(SolutionDir)\\test\\CadlRanchProjects\\models\\usage\\Generated"
186+
},
183187
"ClientAndOperationGroup-Cadl": {
184188
"commandName": "Project",
185189
"commandLineArgs": "--standalone $(SolutionDir)\\test\\TestProjects\\ClientAndOperationGroup-Cadl\\Generated"

src/CADL.Extension/Emitter.Csharp/src/emitter.ts

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,6 @@ export type NetEmitterOptions = {
101101
"library-name"?: string;
102102
"single-top-level-client"?: boolean;
103103
skipSDKGeneration?: boolean;
104-
generateConvenienceAPI?: boolean; //workaround for cadl-ranch project
105104
"unreferenced-types-handling"?:
106105
| "removeOrInternalize"
107106
| "internalize"
@@ -136,7 +135,6 @@ const NetEmitterOptionsSchema: JSONSchemaType<NetEmitterOptions> = {
136135
"library-name": { type: "string", nullable: true },
137136
"single-top-level-client": { type: "boolean", nullable: true },
138137
skipSDKGeneration: { type: "boolean", default: false, nullable: true },
139-
generateConvenienceAPI: { type: "boolean", nullable: true },
140138
"unreferenced-types-handling": {
141139
type: "string",
142140
enum: ["removeOrInternalize", "internalize", "keepAll"],
@@ -179,7 +177,6 @@ export async function $onEmit(context: EmitContext<NetEmitterOptions>) {
179177
resolvedOptions.logFile
180178
),
181179
skipSDKGeneration: resolvedOptions.skipSDKGeneration,
182-
generateConvenienceAPI: resolvedOptions.generateConvenienceAPI ?? false,
183180
"unreferenced-types-handling":
184181
resolvedOptions["unreferenced-types-handling"],
185182
"new-project": resolvedOptions["new-project"],
@@ -193,7 +190,7 @@ export async function $onEmit(context: EmitContext<NetEmitterOptions>) {
193190
// Write out the dotnet model to the output path
194191
const namespace = getServiceNamespaceString(program) || "";
195192

196-
const root = createModel(context, options.generateConvenienceAPI);
193+
const root = createModel(context);
197194
// await program.host.writeFile(outPath, prettierOutput(JSON.stringify(root, null, 2)));
198195
if (root) {
199196
const generatedFolder = resolvePath(outputFolder, "Generated");
@@ -304,10 +301,7 @@ function getClient(
304301
return undefined;
305302
}
306303

307-
function createModel(
308-
context: EmitContext<NetEmitterOptions>,
309-
generateConvenienceAPI: boolean = false
310-
): any {
304+
function createModel(context: EmitContext<NetEmitterOptions>): any {
311305
const program = context.program;
312306
const serviceNamespaceType = getServiceNamespace(program);
313307
if (!serviceNamespaceType) {
@@ -509,10 +503,7 @@ function createModel(
509503

510504
applyDefaultContentTypeAndAcceptParameter(inputOperation);
511505
inputClient.Operations.push(inputOperation);
512-
if (
513-
inputOperation.GenerateConvenienceMethod ||
514-
generateConvenienceAPI
515-
)
506+
if (inputOperation.GenerateConvenienceMethod)
516507
convenienceOperations.push(httpOperation);
517508
}
518509
return inputClient;

test/CadlRanchProjects.Tests/api-key.cs renamed to test/CadlRanchProjects.Tests/authentication-api-key.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
namespace CadlRanchProjects.Tests
1111
{
12-
public class ApiKeyTests : CadlRanchTestBase
12+
public class AuthenticationApiKeyTests : CadlRanchTestBase
1313
{
1414
[Test]
1515
public Task Authentication_ApiKey_valid() => Test(async (host) =>

test/CadlRanchProjects.Tests/oauth2.cs renamed to test/CadlRanchProjects.Tests/authentication-oauth2.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
namespace CadlRanchProjects.Tests
1919
{
20-
public class OAuth2Tests: CadlRanchTestBase
20+
public class AuthenticationOAuth2Tests: CadlRanchTestBase
2121
{
2222
[Test]
2323
public Task Authentication_OAuth2_valid() => Test(async (host) =>

test/CadlRanchProjects.Tests/property-optional.cs renamed to test/CadlRanchProjects.Tests/models-property-optional.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
namespace CadlRanchProjects.Tests
1414
{
15-
public class PropertyOptionalTests : CadlRanchTestBase
15+
public class ModelsPropertyOptionalTests : CadlRanchTestBase
1616
{
1717
[Test]
1818
public Task Models_Property_Optional_String_getAll() => Test(async (host) =>

test/CadlRanchProjects.Tests/property-types.cs renamed to test/CadlRanchProjects.Tests/models-property-types.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
namespace CadlRanchProjects.Tests
1515
{
16-
public class property_types : CadlRanchTestBase
16+
public class ModelsPropertyTypesTests : CadlRanchTestBase
1717
{
1818
[Test]
1919
public Task Models_Property_Types_Boolean_get() => Test(async (host) =>
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
using System.Threading.Tasks;
5+
using AutoRest.TestServer.Tests.Infrastructure;
6+
using Azure;
7+
using Models.Usage;
8+
using Models.Usage.Models;
9+
using NUnit.Framework;
10+
11+
namespace CadlRanchProjects.Tests
12+
{
13+
public class ModelsUsageTests : CadlRanchTestBase
14+
{
15+
[Test]
16+
public Task Models_Usage_input() => Test(async (host) =>
17+
{
18+
Response response = await new UsageClient(host, null).InputAsync(new InputRecord("example-value"));
19+
Assert.AreEqual(204, response.Status);
20+
});
21+
22+
[Test]
23+
public Task Models_Usage_output() => Test(async (host) =>
24+
{
25+
OutputRecord response = await new UsageClient(host, null).OutputValueAsync();
26+
Assert.AreEqual("example-value", response.RequiredProp);
27+
});
28+
29+
[Test]
30+
public Task Models_Usage_inputAndOutput() => Test(async (host) =>
31+
{
32+
InputOutputRecord response = await new UsageClient(host, null).InputAndOutputAsync(new InputOutputRecord("example-value"));
33+
Assert.AreEqual("example-value", response.RequiredProp);
34+
});
35+
}
36+
}

test/CadlRanchProjects/authentication/api-key/Generated/cadl.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@
151151
"Path": "/authentication/api-key/valid",
152152
"BufferResponse": true,
153153
"GenerateProtocolMethod": true,
154-
"GenerateConvenienceMethod": false
154+
"GenerateConvenienceMethod": true
155155
},
156156
{
157157
"$id": "19",
@@ -222,7 +222,7 @@
222222
"Path": "/authentication/api-key/invalid",
223223
"BufferResponse": true,
224224
"GenerateProtocolMethod": true,
225-
"GenerateConvenienceMethod": false
225+
"GenerateConvenienceMethod": true
226226
}
227227
],
228228
"Protocol": {

test/CadlRanchProjects/authentication/oauth2/Generated/cadl.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@
151151
"Path": "/authentication/oauth2/valid",
152152
"BufferResponse": true,
153153
"GenerateProtocolMethod": true,
154-
"GenerateConvenienceMethod": false
154+
"GenerateConvenienceMethod": true
155155
},
156156
{
157157
"$id": "19",
@@ -222,7 +222,7 @@
222222
"Path": "/authentication/oauth2/invalid",
223223
"BufferResponse": true,
224224
"GenerateProtocolMethod": true,
225-
"GenerateConvenienceMethod": false
225+
"GenerateConvenienceMethod": true
226226
}
227227
],
228228
"Protocol": {

0 commit comments

Comments
 (0)