Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion eng/Generate.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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] = @{
Expand Down
10 changes: 10 additions & 0 deletions samples/AnomalyDetector/Generated/cadl.json
Original file line number Diff line number Diff line change
Expand Up @@ -2211,6 +2211,7 @@
"application/json"
],
"BufferResponse": true,
"GenerateProtocolMethod": true,
"GenerateConvenienceMethod": true
},
{
Expand Down Expand Up @@ -2321,6 +2322,7 @@
"application/json"
],
"BufferResponse": true,
"GenerateProtocolMethod": true,
"GenerateConvenienceMethod": true
},
{
Expand Down Expand Up @@ -2431,6 +2433,7 @@
"application/json"
],
"BufferResponse": true,
"GenerateProtocolMethod": true,
"GenerateConvenienceMethod": true
},
{
Expand Down Expand Up @@ -2514,6 +2517,7 @@
"Uri": "{Endpoint}/anomalydetector/{ApiVersion}",
"Path": "/multivariate/detect-batch/{resultId}",
"BufferResponse": true,
"GenerateProtocolMethod": true,
"GenerateConvenienceMethod": true
},
{
Expand Down Expand Up @@ -2637,6 +2641,7 @@
"application/json"
],
"BufferResponse": true,
"GenerateProtocolMethod": true,
"GenerateConvenienceMethod": true
},
{
Expand Down Expand Up @@ -2746,6 +2751,7 @@
"NextLinkName": "nextLink",
"ItemName": "models"
},
"GenerateProtocolMethod": true,
"GenerateConvenienceMethod": true
},
{
Expand Down Expand Up @@ -2826,6 +2832,7 @@
"Uri": "{Endpoint}/anomalydetector/{ApiVersion}",
"Path": "/multivariate/models/{modelId}",
"BufferResponse": true,
"GenerateProtocolMethod": true,
"GenerateConvenienceMethod": true
},
{
Expand Down Expand Up @@ -2909,6 +2916,7 @@
"Uri": "{Endpoint}/anomalydetector/{ApiVersion}",
"Path": "/multivariate/models/{modelId}",
"BufferResponse": true,
"GenerateProtocolMethod": true,
"GenerateConvenienceMethod": true
},
{
Expand Down Expand Up @@ -3065,6 +3073,7 @@
"application/json"
],
"BufferResponse": true,
"GenerateProtocolMethod": true,
"GenerateConvenienceMethod": true
},
{
Expand Down Expand Up @@ -3196,6 +3205,7 @@
"application/json"
],
"BufferResponse": true,
"GenerateProtocolMethod": true,
"GenerateConvenienceMethod": true
}
],
Expand Down
20 changes: 10 additions & 10 deletions samples/AnomalyDetector/client.cadl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
1 change: 1 addition & 0 deletions src/AutoRest.CSharp/Common/Input/CodeModelConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions src/AutoRest.CSharp/Common/Input/Inputs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ internal record InputOperation(
bool BufferResponse,
OperationLongRunning? LongRunning,
OperationPaging? Paging,
bool GenerateProtocolMethod,
bool GenerateConvenienceMethod)
{
public InputOperation() : this(
Expand All @@ -82,6 +83,7 @@ public InputOperation() : this(
BufferResponse: false,
LongRunning: null,
Paging: null,
GenerateProtocolMethod: true,
GenerateConvenienceMethod: false)
{ }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ private InputOperation CreateInputOperation(Operation operation)
BufferResponse: operation.Extensions?.BufferResponse ?? true,
LongRunning: null,
Paging: CreateOperationPaging(operation),
true,
false);
}
return new InputOperation();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ public LowLevelClientMethod BuildOperationMethodChain()
? new[] { new CSharpAttribute(typeof(ObsoleteAttribute), deprecated) }
: Array.Empty<CSharpAttribute>();
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}");
Expand All @@ -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));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
],
"IsExtensible": false,
"IsNullable": false,
"Usage": "None"
"Usage": "Input"
},
{
"$id": "6",
Expand All @@ -57,7 +57,7 @@
],
"IsExtensible": true,
"IsNullable": false,
"Usage": "None"
"Usage": "Input"
}
],
"Models": [
Expand All @@ -66,7 +66,7 @@
"Name": "Thing",
"Namespace": "Demo.HelloWorld",
"IsNullable": false,
"Usage": "None",
"Usage": "RoundTrip",
"Properties": [
{
"$id": "11",
Expand All @@ -90,7 +90,7 @@
"Name": "RoundTripModel",
"Namespace": "Demo.HelloWorld",
"IsNullable": false,
"Usage": "None",
"Usage": "Input",
"Properties": [
{
"$id": "14",
Expand Down Expand Up @@ -275,7 +275,8 @@
"Uri": "",
"Path": "/top/{action}",
"BufferResponse": true,
"GenerateConvenienceMethod": false
"GenerateProtocolMethod": true,
"GenerateConvenienceMethod": true
},
{
"$id": "35",
Expand Down Expand Up @@ -333,7 +334,8 @@
"Uri": "",
"Path": "/top2",
"BufferResponse": true,
"GenerateConvenienceMethod": false
"GenerateProtocolMethod": true,
"GenerateConvenienceMethod": true
},
{
"$id": "40",
Expand Down Expand Up @@ -438,7 +440,8 @@
"application/json"
],
"BufferResponse": true,
"GenerateConvenienceMethod": false
"GenerateProtocolMethod": true,
"GenerateConvenienceMethod": true
},
{
"$id": "49",
Expand Down Expand Up @@ -496,7 +499,8 @@
"Uri": "",
"Path": "/hello",
"BufferResponse": true,
"GenerateConvenienceMethod": false
"GenerateProtocolMethod": true,
"GenerateConvenienceMethod": true
},
{
"$id": "54",
Expand Down Expand Up @@ -601,7 +605,8 @@
"application/json"
],
"BufferResponse": true,
"GenerateConvenienceMethod": false
"GenerateProtocolMethod": true,
"GenerateConvenienceMethod": true
},
{
"$id": "63",
Expand Down Expand Up @@ -659,7 +664,8 @@
"Uri": "",
"Path": "/demoHi",
"BufferResponse": true,
"GenerateConvenienceMethod": false
"GenerateProtocolMethod": true,
"GenerateConvenienceMethod": true
}
],
"Protocol": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"Name": "Pet",
"Namespace": "PetStore",
"IsNullable": false,
"Usage": "None",
"Usage": "RoundTrip",
"Properties": [
{
"$id": "3",
Expand Down Expand Up @@ -66,7 +66,7 @@
"Name": "ToyListResults",
"Namespace": "PetStore",
"IsNullable": false,
"Usage": "None",
"Usage": "Output",
"Properties": [
{
"$id": "10",
Expand All @@ -81,7 +81,7 @@
"Name": "Toy",
"Namespace": "PetStore",
"IsNullable": false,
"Usage": "None",
"Usage": "Output",
"Properties": [
{
"$id": "13",
Expand Down Expand Up @@ -286,7 +286,8 @@
"Uri": "{petStoreUrl}",
"Path": "/pets/{petId}",
"BufferResponse": true,
"GenerateConvenienceMethod": false
"GenerateProtocolMethod": true,
"GenerateConvenienceMethod": true
},
{
"$id": "35",
Expand Down Expand Up @@ -380,7 +381,8 @@
"Uri": "{petStoreUrl}",
"Path": "/pets/{petId}",
"BufferResponse": true,
"GenerateConvenienceMethod": false
"GenerateProtocolMethod": true,
"GenerateConvenienceMethod": true
},
{
"$id": "43",
Expand Down Expand Up @@ -487,7 +489,8 @@
"application/json"
],
"BufferResponse": true,
"GenerateConvenienceMethod": false
"GenerateProtocolMethod": true,
"GenerateConvenienceMethod": true
},
{
"$id": "52",
Expand Down Expand Up @@ -587,7 +590,8 @@
"Uri": "{petStoreUrl}",
"Path": "/pets/{petId}/toys",
"BufferResponse": true,
"GenerateConvenienceMethod": false
"GenerateProtocolMethod": true,
"GenerateConvenienceMethod": true
}
],
"Protocol": {
Expand Down
Loading