Skip to content

Commit c8252d7

Browse files
authored
Support isProtocol and isConvenient decorator (#3063)
* Support isProtocol and isConvenient decorator * Fix * Update * Fix
1 parent ac0f9e9 commit c8252d7

File tree

57 files changed

+850
-142
lines changed

Some content is hidden

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

57 files changed

+850
-142
lines changed

eng/Generate.ps1

Lines changed: 1 addition & 1 deletion
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'
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'
2323

2424
function Add-Swagger ([string]$name, [string]$output, [string]$arguments) {
2525
$swaggerDefinitions[$name] = @{

samples/AnomalyDetector/Generated/cadl.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2211,6 +2211,7 @@
22112211
"application/json"
22122212
],
22132213
"BufferResponse": true,
2214+
"GenerateProtocolMethod": true,
22142215
"GenerateConvenienceMethod": true
22152216
},
22162217
{
@@ -2321,6 +2322,7 @@
23212322
"application/json"
23222323
],
23232324
"BufferResponse": true,
2325+
"GenerateProtocolMethod": true,
23242326
"GenerateConvenienceMethod": true
23252327
},
23262328
{
@@ -2431,6 +2433,7 @@
24312433
"application/json"
24322434
],
24332435
"BufferResponse": true,
2436+
"GenerateProtocolMethod": true,
24342437
"GenerateConvenienceMethod": true
24352438
},
24362439
{
@@ -2514,6 +2517,7 @@
25142517
"Uri": "{Endpoint}/anomalydetector/{ApiVersion}",
25152518
"Path": "/multivariate/detect-batch/{resultId}",
25162519
"BufferResponse": true,
2520+
"GenerateProtocolMethod": true,
25172521
"GenerateConvenienceMethod": true
25182522
},
25192523
{
@@ -2637,6 +2641,7 @@
26372641
"application/json"
26382642
],
26392643
"BufferResponse": true,
2644+
"GenerateProtocolMethod": true,
26402645
"GenerateConvenienceMethod": true
26412646
},
26422647
{
@@ -2746,6 +2751,7 @@
27462751
"NextLinkName": "nextLink",
27472752
"ItemName": "models"
27482753
},
2754+
"GenerateProtocolMethod": true,
27492755
"GenerateConvenienceMethod": true
27502756
},
27512757
{
@@ -2826,6 +2832,7 @@
28262832
"Uri": "{Endpoint}/anomalydetector/{ApiVersion}",
28272833
"Path": "/multivariate/models/{modelId}",
28282834
"BufferResponse": true,
2835+
"GenerateProtocolMethod": true,
28292836
"GenerateConvenienceMethod": true
28302837
},
28312838
{
@@ -2909,6 +2916,7 @@
29092916
"Uri": "{Endpoint}/anomalydetector/{ApiVersion}",
29102917
"Path": "/multivariate/models/{modelId}",
29112918
"BufferResponse": true,
2919+
"GenerateProtocolMethod": true,
29122920
"GenerateConvenienceMethod": true
29132921
},
29142922
{
@@ -3065,6 +3073,7 @@
30653073
"application/json"
30663074
],
30673075
"BufferResponse": true,
3076+
"GenerateProtocolMethod": true,
30683077
"GenerateConvenienceMethod": true
30693078
},
30703079
{
@@ -3196,6 +3205,7 @@
31963205
"application/json"
31973206
],
31983207
"BufferResponse": true,
3208+
"GenerateProtocolMethod": true,
31993209
"GenerateConvenienceMethod": true
32003210
}
32013211
],

samples/AnomalyDetector/client.cadl

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@ import "./main.cadl";
33

44
using Azure.DPG;
55

6-
@@convenienceAPI(AnomalyDetector.Multivariate.GetMultivariateBatchDetectionResult)
7-
@@convenienceAPI(AnomalyDetector.Multivariate.TrainMultivariateModel)
8-
@@convenienceAPI(AnomalyDetector.Multivariate.ListMultivariateModels)
9-
@@convenienceAPI(AnomalyDetector.Multivariate.DeleteMultivariateModel)
10-
@@convenienceAPI(AnomalyDetector.Multivariate.GetMultivariateModel)
11-
@@convenienceAPI(AnomalyDetector.Multivariate.DetectMultivariateBatchAnomaly)
12-
@@convenienceAPI(AnomalyDetector.Multivariate.DetectMultivariateLastAnomaly)
6+
@@convenientAPI(AnomalyDetector.Multivariate.GetMultivariateBatchDetectionResult, true)
7+
@@convenientAPI(AnomalyDetector.Multivariate.TrainMultivariateModel, true)
8+
@@convenientAPI(AnomalyDetector.Multivariate.ListMultivariateModels, true)
9+
@@convenientAPI(AnomalyDetector.Multivariate.DeleteMultivariateModel, true)
10+
@@convenientAPI(AnomalyDetector.Multivariate.GetMultivariateModel, true)
11+
@@convenientAPI(AnomalyDetector.Multivariate.DetectMultivariateBatchAnomaly, true)
12+
@@convenientAPI(AnomalyDetector.Multivariate.DetectMultivariateLastAnomaly, true)
1313

14-
@@convenienceAPI(AnomalyDetector.Univariate.DetectUnivariateEntireSeries)
15-
@@convenienceAPI(AnomalyDetector.Univariate.DetectUnivariateLastPoint)
16-
@@convenienceAPI(AnomalyDetector.Univariate.DetectUnivariateChangePoint)
14+
@@convenientAPI(AnomalyDetector.Univariate.DetectUnivariateEntireSeries, true)
15+
@@convenientAPI(AnomalyDetector.Univariate.DetectUnivariateLastPoint, true)
16+
@@convenientAPI(AnomalyDetector.Univariate.DetectUnivariateChangePoint, true)

src/AutoRest.CSharp/Common/Input/CodeModelConverter.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ private InputOperation CreateOperation(ServiceRequest serviceRequest, Operation
102102
BufferResponse: operation.Extensions?.BufferResponse ?? true,
103103
LongRunning: CreateLongRunning(operation),
104104
Paging: CreateOperationPaging(operation),
105+
GenerateProtocolMethod: true,
105106
GenerateConvenienceMethod: false);
106107

107108
_inputOperationToOperationMap[inputOperation] = operation;

src/AutoRest.CSharp/Common/Input/Inputs.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ internal record InputOperation(
6262
bool BufferResponse,
6363
OperationLongRunning? LongRunning,
6464
OperationPaging? Paging,
65+
bool GenerateProtocolMethod,
6566
bool GenerateConvenienceMethod)
6667
{
6768
public InputOperation() : this(
@@ -82,6 +83,7 @@ public InputOperation() : this(
8283
BufferResponse: false,
8384
LongRunning: null,
8485
Paging: null,
86+
GenerateProtocolMethod: true,
8587
GenerateConvenienceMethod: false)
8688
{ }
8789
}

src/AutoRest.CSharp/Common/Output/Models/CmcRestClientBuilder.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ private InputOperation CreateInputOperation(Operation operation)
142142
BufferResponse: operation.Extensions?.BufferResponse ?? true,
143143
LongRunning: null,
144144
Paging: CreateOperationPaging(operation),
145+
true,
145146
false);
146147
}
147148
return new InputOperation();

src/AutoRest.CSharp/LowLevel/Output/OperationMethodChainBuilder.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,8 @@ public LowLevelClientMethod BuildOperationMethodChain()
8585
? new[] { new CSharpAttribute(typeof(ObsoleteAttribute), deprecated) }
8686
: Array.Empty<CSharpAttribute>();
8787
var protocolMethodParameters = _orderedParameters.Select(p => p.Protocol).WhereNotNull().ToArray();
88-
var protocolMethodSignature = new MethodSignature(_restClientMethod.Name, _restClientMethod.Summary, _restClientMethod.Description, _restClientMethod.Accessibility | Virtual, returnTypeChain.Protocol, null, protocolMethodParameters, protocolMethodAttributes);
88+
var protocolMethodModifiers = (Operation.GenerateProtocolMethod ? _restClientMethod.Accessibility : MethodSignatureModifiers.Internal) | Virtual;
89+
var protocolMethodSignature = new MethodSignature(_restClientMethod.Name, _restClientMethod.Summary, _restClientMethod.Description, protocolMethodModifiers, returnTypeChain.Protocol, null, protocolMethodParameters, protocolMethodAttributes);
8990
var convenienceMethod = ShouldConvenienceMethodGenerated(returnTypeChain) ? BuildConvenienceMethod(returnTypeChain) : null;
9091

9192
var diagnostic = new Diagnostic($"{_clientName}.{_restClientMethod.Name}");
@@ -98,7 +99,8 @@ public LowLevelClientMethod BuildOperationMethodChain()
9899
private bool ShouldConvenienceMethodGenerated(ReturnTypeChain returnTypeChain)
99100
{
100101
return Operation.GenerateConvenienceMethod
101-
&& (_orderedParameters.Where(parameter => parameter.Convenience != KnownParameters.CancellationTokenParameter).Any(parameter => !IsParameterTypeSame(parameter.Convenience, parameter.Protocol))
102+
&& (!Operation.GenerateProtocolMethod
103+
|| _orderedParameters.Where(parameter => parameter.Convenience != KnownParameters.CancellationTokenParameter).Any(parameter => !IsParameterTypeSame(parameter.Convenience, parameter.Protocol))
102104
|| !returnTypeChain.Convenience.Equals(returnTypeChain.Protocol));
103105
}
104106

src/CADL.Extension/Emitter.Csharp/samples/CadlFirstTest/Generated/cadl.json

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
],
3131
"IsExtensible": false,
3232
"IsNullable": false,
33-
"Usage": "None"
33+
"Usage": "Input"
3434
},
3535
{
3636
"$id": "6",
@@ -57,7 +57,7 @@
5757
],
5858
"IsExtensible": true,
5959
"IsNullable": false,
60-
"Usage": "None"
60+
"Usage": "Input"
6161
}
6262
],
6363
"Models": [
@@ -66,7 +66,7 @@
6666
"Name": "Thing",
6767
"Namespace": "Demo.HelloWorld",
6868
"IsNullable": false,
69-
"Usage": "None",
69+
"Usage": "RoundTrip",
7070
"Properties": [
7171
{
7272
"$id": "11",
@@ -90,7 +90,7 @@
9090
"Name": "RoundTripModel",
9191
"Namespace": "Demo.HelloWorld",
9292
"IsNullable": false,
93-
"Usage": "None",
93+
"Usage": "Input",
9494
"Properties": [
9595
{
9696
"$id": "14",
@@ -275,7 +275,8 @@
275275
"Uri": "",
276276
"Path": "/top/{action}",
277277
"BufferResponse": true,
278-
"GenerateConvenienceMethod": false
278+
"GenerateProtocolMethod": true,
279+
"GenerateConvenienceMethod": true
279280
},
280281
{
281282
"$id": "35",
@@ -333,7 +334,8 @@
333334
"Uri": "",
334335
"Path": "/top2",
335336
"BufferResponse": true,
336-
"GenerateConvenienceMethod": false
337+
"GenerateProtocolMethod": true,
338+
"GenerateConvenienceMethod": true
337339
},
338340
{
339341
"$id": "40",
@@ -438,7 +440,8 @@
438440
"application/json"
439441
],
440442
"BufferResponse": true,
441-
"GenerateConvenienceMethod": false
443+
"GenerateProtocolMethod": true,
444+
"GenerateConvenienceMethod": true
442445
},
443446
{
444447
"$id": "49",
@@ -496,7 +499,8 @@
496499
"Uri": "",
497500
"Path": "/hello",
498501
"BufferResponse": true,
499-
"GenerateConvenienceMethod": false
502+
"GenerateProtocolMethod": true,
503+
"GenerateConvenienceMethod": true
500504
},
501505
{
502506
"$id": "54",
@@ -601,7 +605,8 @@
601605
"application/json"
602606
],
603607
"BufferResponse": true,
604-
"GenerateConvenienceMethod": false
608+
"GenerateProtocolMethod": true,
609+
"GenerateConvenienceMethod": true
605610
},
606611
{
607612
"$id": "63",
@@ -659,7 +664,8 @@
659664
"Uri": "",
660665
"Path": "/demoHi",
661666
"BufferResponse": true,
662-
"GenerateConvenienceMethod": false
667+
"GenerateProtocolMethod": true,
668+
"GenerateConvenienceMethod": true
663669
}
664670
],
665671
"Protocol": {

src/CADL.Extension/Emitter.Csharp/samples/petStore/Generated/cadl.json

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"Name": "Pet",
1313
"Namespace": "PetStore",
1414
"IsNullable": false,
15-
"Usage": "None",
15+
"Usage": "RoundTrip",
1616
"Properties": [
1717
{
1818
"$id": "3",
@@ -66,7 +66,7 @@
6666
"Name": "ToyListResults",
6767
"Namespace": "PetStore",
6868
"IsNullable": false,
69-
"Usage": "None",
69+
"Usage": "Output",
7070
"Properties": [
7171
{
7272
"$id": "10",
@@ -81,7 +81,7 @@
8181
"Name": "Toy",
8282
"Namespace": "PetStore",
8383
"IsNullable": false,
84-
"Usage": "None",
84+
"Usage": "Output",
8585
"Properties": [
8686
{
8787
"$id": "13",
@@ -286,7 +286,8 @@
286286
"Uri": "{petStoreUrl}",
287287
"Path": "/pets/{petId}",
288288
"BufferResponse": true,
289-
"GenerateConvenienceMethod": false
289+
"GenerateProtocolMethod": true,
290+
"GenerateConvenienceMethod": true
290291
},
291292
{
292293
"$id": "35",
@@ -380,7 +381,8 @@
380381
"Uri": "{petStoreUrl}",
381382
"Path": "/pets/{petId}",
382383
"BufferResponse": true,
383-
"GenerateConvenienceMethod": false
384+
"GenerateProtocolMethod": true,
385+
"GenerateConvenienceMethod": true
384386
},
385387
{
386388
"$id": "43",
@@ -487,7 +489,8 @@
487489
"application/json"
488490
],
489491
"BufferResponse": true,
490-
"GenerateConvenienceMethod": false
492+
"GenerateProtocolMethod": true,
493+
"GenerateConvenienceMethod": true
491494
},
492495
{
493496
"$id": "52",
@@ -587,7 +590,8 @@
587590
"Uri": "{petStoreUrl}",
588591
"Path": "/pets/{petId}/toys",
589592
"BufferResponse": true,
590-
"GenerateConvenienceMethod": false
593+
"GenerateProtocolMethod": true,
594+
"GenerateConvenienceMethod": true
591595
}
592596
],
593597
"Protocol": {

0 commit comments

Comments
 (0)