Skip to content

Commit

Permalink
fix(dpg): protocol/convenience method parameters should order by defa…
Browse files Browse the repository at this point in the history
…ult value

- fix the sequence of parameters not sorted by default value (e.g. optional parameters should be at the end)
- fix a method access privilege
- regen samples & tests

fix Azure#2766
  • Loading branch information
archerzz committed Oct 13, 2022
1 parent e270655 commit 584d741
Showing 1 changed file with 4 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public void BuildNextPageMethod(IReadOnlyDictionary<InputOperation, OperationMet
public LowLevelClientMethod BuildOperationMethodChain()
{
var returnTypeChain = BuildReturnTypes();
var protocolMethodParameters = _orderedParameters.Select(p => p.Protocol).WhereNotNull().ToArray();
var protocolMethodParameters = _orderedParameters.Select(p => p.Protocol).WhereNotNull().OrderBy(p => p.DefaultValue != null).ToArray();
var protocolMethodSignature = new MethodSignature(_restClientMethod.Name, _restClientMethod.Summary, _restClientMethod.Description, _restClientMethod.Accessibility | Virtual, returnTypeChain.Protocol, null, protocolMethodParameters);
var convenienceMethod = ShouldConvenienceMethodGenerated(returnTypeChain) ? BuildConvenienceMethod(returnTypeChain) : null;

Expand Down Expand Up @@ -173,9 +173,10 @@ private ConvenienceMethod BuildConvenienceMethod(ReturnTypeChain returnTypeChain
name = _restClientMethod.Name.IsLastWordSingular() ? $"{_restClientMethod.Name}Value" : $"{_restClientMethod.Name.LastWordToSingular()}Values";
}

var parameters = _orderedParameters.Select(p => p.Convenience).WhereNotNull().ToArray();
var parameters = _orderedParameters.Select(p => p.Convenience).WhereNotNull().OrderBy(p => p.DefaultValue != null).ToArray();
var protocolToConvenience = _orderedParameters
.Where(p => p.Protocol != null)
.OrderBy(p => p.Protocol!.DefaultValue != null)
.Select(p => (p.Protocol!, p.Convenience))
.ToArray();

Expand All @@ -184,7 +185,7 @@ private ConvenienceMethod BuildConvenienceMethod(ReturnTypeChain returnTypeChain
return new ConvenienceMethod(convenienceSignature, protocolToConvenience, returnTypeChain.ConvenienceResponseType, diagnostic);
}

public void BuildParameters()
private void BuildParameters()
{
var operationParameters = Operation.Parameters.Where(rp => !RestClientBuilder.IsIgnoredHeaderParameter(rp));

Expand Down

0 comments on commit 584d741

Please sign in to comment.