Skip to content

Expose GetCreateRequestMethod and GetMethodCollectionByOperation #7358

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ private record OAuth2Fields(FieldProvider AuthField, FieldProvider Authorization
private readonly IReadOnlyList<InputParameter> _allClientParameters;
private Lazy<IReadOnlyList<FieldProvider>> _additionalClientFields;

private Dictionary<InputOperation, ScmMethodProviderCollection>? _methodCache;
private Dictionary<InputOperation, ScmMethodProviderCollection> MethodCache => _methodCache ??= [];

private Lazy<ParameterProvider?> ClientOptionsParameter { get; }

protected override FormattableString Description { get; }
Expand Down Expand Up @@ -505,6 +508,12 @@ [.. primaryCtorOrderedParams.Select(p => p.InitializationValue ?? p)
this);
}

public ScmMethodProviderCollection GetMethodCollectionByOperation(InputOperation operation)
{
_ = Methods; // Ensure methods are built
return MethodCache[operation];
}

protected override ScmMethodProvider[] BuildMethods()
{
var subClients = _subClients.Value;
Expand All @@ -516,6 +525,7 @@ protected override ScmMethodProvider[] BuildMethods()
var clientMethods = ScmCodeModelGenerator.Instance.TypeFactory.CreateMethods(serviceMethod, this);
if (clientMethods != null)
{
MethodCache[serviceMethod.Operation] = clientMethods;
methods.AddRange(clientMethods);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ internal class CollectionResultDefinition : TypeProvider

private readonly string _itemsPropertyName;
private readonly InputPagingServiceMetadata _paging;
private readonly FieldProvider[] _requestFields;
private readonly IReadOnlyList<FieldProvider> _requestFields;
private readonly IReadOnlyList<ParameterProvider> _createRequestParameters;
private readonly int? _nextTokenParameterIndex;

Expand Down Expand Up @@ -73,7 +73,7 @@ public CollectionResultDefinition(ClientProvider client, InputPagingServiceMetho
}
}

_requestFields = fields.ToArray();
_requestFields = fields;

_itemModelType = itemModelType;
_isAsync = isAsync;
Expand Down Expand Up @@ -431,7 +431,7 @@ private MethodBodyStatement[] AssignAndCheckNextPageVariable(ClientResponseApi r
private ScopedApi<PipelineMessage> InvokeCreateRequestForNextLink(ValueExpression nextPageUri) => _clientField.Invoke(
$"Create{_operation.Name.ToCleanName()}Request",
// we replace the first argument (the initialUri) with the nextPageUri
[nextPageUri, .. _requestFields[1..]])
[nextPageUri, .. _requestFields.Skip(1)])
.As<PipelineMessage>();

private ScopedApi<PipelineMessage> InvokeCreateRequestForContinuationToken(ValueExpression nextToken)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,7 @@ private static List<int> GetSuccessStatusCodes(InputOperation operation)
return [.. statusCodes.OrderBy(i => i)];
}

internal MethodProvider GetCreateRequestMethod(InputOperation operation)
public MethodProvider GetCreateRequestMethod(InputOperation operation)
{
_ = Methods; // Ensure methods are built
return MethodCache[operation];
Expand Down
Loading