Skip to content

Rename List methods to Get #7588

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

Merged
merged 1 commit into from
Jun 9, 2025
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
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ public ScmMethodProviderCollection(InputServiceMethod serviceMethod, TypeProvide
{
ServiceMethod = serviceMethod;
EnclosingType = enclosingType;
_cleanOperationName = serviceMethod.Operation.Name.ToIdentifierName();
_cleanOperationName = GetCleanOperationName(serviceMethod);

Client = enclosingType as ClientProvider ?? throw new InvalidOperationException("Scm methods can only be built for client types.");
_createRequestMethod = Client.RestClient.GetCreateRequestMethod(ServiceMethod.Operation);

Expand All @@ -73,6 +74,17 @@ public ScmMethodProviderCollection(InputServiceMethod serviceMethod, TypeProvide
}
}

private static string GetCleanOperationName(InputServiceMethod serviceMethod)
{
var operationName = serviceMethod.Operation.Name.ToIdentifierName();
// Replace List with Get as .NET convention is to use Get for list operations.
if (operationName.StartsWith("List", StringComparison.Ordinal))
{
operationName = $"Get{operationName.Substring(4)}";
}
return operationName;
}

protected virtual IReadOnlyList<ScmMethodProvider> BuildMethods()
{
var syncProtocol = BuildProtocolMethod(_createRequestMethod, false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,35 @@ public void RequestBodyConstructedRespectingRequestContentApi(InputType inputTyp
}
}

[Test]
public void ListMethodIsRenamedToGet()
{
MockHelpers.LoadMockGenerator(requestContentApi: TestRequestContentApi.Instance);

var inputOperation = InputFactory.Operation(
"ListCats");

var inputServiceMethod = InputFactory.BasicServiceMethod("ListCats", inputOperation);

var inputClient = InputFactory.Client("TestClient", methods: [inputServiceMethod]);

var client = ScmCodeModelGenerator.Instance.TypeFactory.CreateClient(inputClient);

var methodCollection = new ScmMethodProviderCollection(inputServiceMethod, client!);
Assert.IsNotNull(methodCollection);
foreach (var method in methodCollection)
{
if (method.Signature.Modifiers.HasFlag(MethodSignatureModifiers.Async))
{
Assert.AreEqual("GetCatsAsync", method.Signature.Name);
}
else
{
Assert.AreEqual("GetCats", method.Signature.Name);
}
}
}

public static IEnumerable<TestCaseData> DefaultCSharpMethodCollectionTestCases
{
get
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1284,7 +1284,7 @@ public virtual async Task<ClientResult> WithApiVersionAsync(string p1, Cancellat
/// <param name="options"> The request options, which can override default behaviors of the client pipeline on a per-call basis. </param>
/// <exception cref="ClientResultException"> Service returned a non-success status code. </exception>
/// <returns> The response returned from the service. </returns>
public virtual CollectionResult ListWithNextLink(RequestOptions options)
public virtual CollectionResult GetWithNextLink(RequestOptions options)
{
return new SampleTypeSpecClientListWithNextLinkCollectionResult(this, null, options);
}
Expand All @@ -1300,23 +1300,23 @@ public virtual CollectionResult ListWithNextLink(RequestOptions options)
/// <param name="options"> The request options, which can override default behaviors of the client pipeline on a per-call basis. </param>
/// <exception cref="ClientResultException"> Service returned a non-success status code. </exception>
/// <returns> The response returned from the service. </returns>
public virtual AsyncCollectionResult ListWithNextLinkAsync(RequestOptions options)
public virtual AsyncCollectionResult GetWithNextLinkAsync(RequestOptions options)
{
return new SampleTypeSpecClientListWithNextLinkAsyncCollectionResult(this, null, options);
}

/// <summary> List things with nextlink. </summary>
/// <param name="cancellationToken"> The cancellation token that can be used to cancel the operation. </param>
/// <exception cref="ClientResultException"> Service returned a non-success status code. </exception>
public virtual CollectionResult<Thing> ListWithNextLink(CancellationToken cancellationToken = default)
public virtual CollectionResult<Thing> GetWithNextLink(CancellationToken cancellationToken = default)
{
return new SampleTypeSpecClientListWithNextLinkCollectionResultOfT(this, null, cancellationToken.CanBeCanceled ? new RequestOptions { CancellationToken = cancellationToken } : null);
}

/// <summary> List things with nextlink. </summary>
/// <param name="cancellationToken"> The cancellation token that can be used to cancel the operation. </param>
/// <exception cref="ClientResultException"> Service returned a non-success status code. </exception>
public virtual AsyncCollectionResult<Thing> ListWithNextLinkAsync(CancellationToken cancellationToken = default)
public virtual AsyncCollectionResult<Thing> GetWithNextLinkAsync(CancellationToken cancellationToken = default)
{
return new SampleTypeSpecClientListWithNextLinkAsyncCollectionResultOfT(this, null, cancellationToken.CanBeCanceled ? new RequestOptions { CancellationToken = cancellationToken } : null);
}
Expand All @@ -1333,7 +1333,7 @@ public virtual AsyncCollectionResult<Thing> ListWithNextLinkAsync(CancellationTo
/// <param name="options"> The request options, which can override default behaviors of the client pipeline on a per-call basis. </param>
/// <exception cref="ClientResultException"> Service returned a non-success status code. </exception>
/// <returns> The response returned from the service. </returns>
public virtual CollectionResult ListWithContinuationToken(string token, RequestOptions options)
public virtual CollectionResult GetWithContinuationToken(string token, RequestOptions options)
{
return new SampleTypeSpecClientListWithContinuationTokenCollectionResult(this, token, options);
}
Expand All @@ -1350,7 +1350,7 @@ public virtual CollectionResult ListWithContinuationToken(string token, RequestO
/// <param name="options"> The request options, which can override default behaviors of the client pipeline on a per-call basis. </param>
/// <exception cref="ClientResultException"> Service returned a non-success status code. </exception>
/// <returns> The response returned from the service. </returns>
public virtual AsyncCollectionResult ListWithContinuationTokenAsync(string token, RequestOptions options)
public virtual AsyncCollectionResult GetWithContinuationTokenAsync(string token, RequestOptions options)
{
return new SampleTypeSpecClientListWithContinuationTokenAsyncCollectionResult(this, token, options);
}
Expand All @@ -1359,7 +1359,7 @@ public virtual AsyncCollectionResult ListWithContinuationTokenAsync(string token
/// <param name="token"></param>
/// <param name="cancellationToken"> The cancellation token that can be used to cancel the operation. </param>
/// <exception cref="ClientResultException"> Service returned a non-success status code. </exception>
public virtual CollectionResult<Thing> ListWithContinuationToken(string token = default, CancellationToken cancellationToken = default)
public virtual CollectionResult<Thing> GetWithContinuationToken(string token = default, CancellationToken cancellationToken = default)
{
return new SampleTypeSpecClientListWithContinuationTokenCollectionResultOfT(this, token, cancellationToken.CanBeCanceled ? new RequestOptions { CancellationToken = cancellationToken } : null);
}
Expand All @@ -1368,7 +1368,7 @@ public virtual CollectionResult<Thing> ListWithContinuationToken(string token =
/// <param name="token"></param>
/// <param name="cancellationToken"> The cancellation token that can be used to cancel the operation. </param>
/// <exception cref="ClientResultException"> Service returned a non-success status code. </exception>
public virtual AsyncCollectionResult<Thing> ListWithContinuationTokenAsync(string token = default, CancellationToken cancellationToken = default)
public virtual AsyncCollectionResult<Thing> GetWithContinuationTokenAsync(string token = default, CancellationToken cancellationToken = default)
{
return new SampleTypeSpecClientListWithContinuationTokenAsyncCollectionResultOfT(this, token, cancellationToken.CanBeCanceled ? new RequestOptions { CancellationToken = cancellationToken } : null);
}
Expand All @@ -1385,7 +1385,7 @@ public virtual AsyncCollectionResult<Thing> ListWithContinuationTokenAsync(strin
/// <param name="options"> The request options, which can override default behaviors of the client pipeline on a per-call basis. </param>
/// <exception cref="ClientResultException"> Service returned a non-success status code. </exception>
/// <returns> The response returned from the service. </returns>
public virtual CollectionResult ListWithContinuationTokenHeaderResponse(string token, RequestOptions options)
public virtual CollectionResult GetWithContinuationTokenHeaderResponse(string token, RequestOptions options)
{
return new SampleTypeSpecClientListWithContinuationTokenHeaderResponseCollectionResult(this, token, options);
}
Expand All @@ -1402,7 +1402,7 @@ public virtual CollectionResult ListWithContinuationTokenHeaderResponse(string t
/// <param name="options"> The request options, which can override default behaviors of the client pipeline on a per-call basis. </param>
/// <exception cref="ClientResultException"> Service returned a non-success status code. </exception>
/// <returns> The response returned from the service. </returns>
public virtual AsyncCollectionResult ListWithContinuationTokenHeaderResponseAsync(string token, RequestOptions options)
public virtual AsyncCollectionResult GetWithContinuationTokenHeaderResponseAsync(string token, RequestOptions options)
{
return new SampleTypeSpecClientListWithContinuationTokenHeaderResponseAsyncCollectionResult(this, token, options);
}
Expand All @@ -1411,7 +1411,7 @@ public virtual AsyncCollectionResult ListWithContinuationTokenHeaderResponseAsyn
/// <param name="token"></param>
/// <param name="cancellationToken"> The cancellation token that can be used to cancel the operation. </param>
/// <exception cref="ClientResultException"> Service returned a non-success status code. </exception>
public virtual CollectionResult<Thing> ListWithContinuationTokenHeaderResponse(string token = default, CancellationToken cancellationToken = default)
public virtual CollectionResult<Thing> GetWithContinuationTokenHeaderResponse(string token = default, CancellationToken cancellationToken = default)
{
return new SampleTypeSpecClientListWithContinuationTokenHeaderResponseCollectionResultOfT(this, token, cancellationToken.CanBeCanceled ? new RequestOptions { CancellationToken = cancellationToken } : null);
}
Expand All @@ -1420,7 +1420,7 @@ public virtual CollectionResult<Thing> ListWithContinuationTokenHeaderResponse(s
/// <param name="token"></param>
/// <param name="cancellationToken"> The cancellation token that can be used to cancel the operation. </param>
/// <exception cref="ClientResultException"> Service returned a non-success status code. </exception>
public virtual AsyncCollectionResult<Thing> ListWithContinuationTokenHeaderResponseAsync(string token = default, CancellationToken cancellationToken = default)
public virtual AsyncCollectionResult<Thing> GetWithContinuationTokenHeaderResponseAsync(string token = default, CancellationToken cancellationToken = default)
{
return new SampleTypeSpecClientListWithContinuationTokenHeaderResponseAsyncCollectionResultOfT(this, token, cancellationToken.CanBeCanceled ? new RequestOptions { CancellationToken = cancellationToken } : null);
}
Expand All @@ -1436,7 +1436,7 @@ public virtual AsyncCollectionResult<Thing> ListWithContinuationTokenHeaderRespo
/// <param name="options"> The request options, which can override default behaviors of the client pipeline on a per-call basis. </param>
/// <exception cref="ClientResultException"> Service returned a non-success status code. </exception>
/// <returns> The response returned from the service. </returns>
public virtual CollectionResult ListWithPaging(RequestOptions options)
public virtual CollectionResult GetWithPaging(RequestOptions options)
{
return new SampleTypeSpecClientListWithPagingCollectionResult(this, options);
}
Expand All @@ -1452,23 +1452,23 @@ public virtual CollectionResult ListWithPaging(RequestOptions options)
/// <param name="options"> The request options, which can override default behaviors of the client pipeline on a per-call basis. </param>
/// <exception cref="ClientResultException"> Service returned a non-success status code. </exception>
/// <returns> The response returned from the service. </returns>
public virtual AsyncCollectionResult ListWithPagingAsync(RequestOptions options)
public virtual AsyncCollectionResult GetWithPagingAsync(RequestOptions options)
{
return new SampleTypeSpecClientListWithPagingAsyncCollectionResult(this, options);
}

/// <summary> List things with paging. </summary>
/// <param name="cancellationToken"> The cancellation token that can be used to cancel the operation. </param>
/// <exception cref="ClientResultException"> Service returned a non-success status code. </exception>
public virtual CollectionResult<Thing> ListWithPaging(CancellationToken cancellationToken = default)
public virtual CollectionResult<Thing> GetWithPaging(CancellationToken cancellationToken = default)
{
return new SampleTypeSpecClientListWithPagingCollectionResultOfT(this, cancellationToken.CanBeCanceled ? new RequestOptions { CancellationToken = cancellationToken } : null);
}

/// <summary> List things with paging. </summary>
/// <param name="cancellationToken"> The cancellation token that can be used to cancel the operation. </param>
/// <exception cref="ClientResultException"> Service returned a non-success status code. </exception>
public virtual AsyncCollectionResult<Thing> ListWithPagingAsync(CancellationToken cancellationToken = default)
public virtual AsyncCollectionResult<Thing> GetWithPagingAsync(CancellationToken cancellationToken = default)
{
return new SampleTypeSpecClientListWithPagingAsyncCollectionResultOfT(this, cancellationToken.CanBeCanceled ? new RequestOptions { CancellationToken = cancellationToken } : null);
}
Expand Down
Loading