Skip to content

Generate AOT compatible code when an operation returns a primitive #11930

Description

ACA has the following operation:

model GetSandboxesCountResult {
  /** HTTP response status code. */
  @statusCode statusCode: 200;

  /** Response body. */
  @body body: int32;
}


/** Gets the total count of sandboxes. */
  @summary("Gets the total count of sandboxes.")
  @route("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/sandboxGroups/{sandboxGroupName}/sandboxes/count")
  @get
  getSandboxesCount is Foundations.Operation<
    {
      ...AzureResourceScope;
    },
    GetSandboxesCountResult,
    DataPlaneStandardTraits,
    GetSandboxesCountErrors
  >;

which simply returns an integer with the count. The generated operation is generated, but is not AOT compatible:

public virtual async Task<Response<int>> GetSnapshotsCountAsync(string subscriptionId, string resourceGroupName, string sandboxGroupName, CancellationToken cancellationToken = default)
{
    Argument.AssertNotNullOrEmpty(subscriptionId, nameof(subscriptionId));
    Argument.AssertNotNullOrEmpty(resourceGroupName, nameof(resourceGroupName));
    Argument.AssertNotNullOrEmpty(sandboxGroupName, nameof(sandboxGroupName));

    Response result = await GetSnapshotsCountAsync(subscriptionId, resourceGroupName, sandboxGroupName, cancellationToken.ToRequestContext()).ConfigureAwait(false);
    return Response.FromValue(result.Content.ToObjectFromJson<int>(), result);
}

this can simply be generated as:

public virtual async Task<Response<int>> GetSnapshotsCountAsync(
    string subscriptionId,
    string resourceGroupName,
    string sandboxGroupName,
    CancellationToken cancellationToken = default)
{
    Argument.AssertNotNullOrEmpty(subscriptionId, nameof(subscriptionId));
    Argument.AssertNotNullOrEmpty(resourceGroupName, nameof(resourceGroupName));
    Argument.AssertNotNullOrEmpty(sandboxGroupName, nameof(sandboxGroupName));

    Response result = await GetSnapshotsCountAsync(
        subscriptionId,
        resourceGroupName,
        sandboxGroupName,
        cancellationToken.ToRequestContext()).ConfigureAwait(false);

    using JsonDocument document = JsonDocument.Parse(result.Content);
    int count = document.RootElement.GetInt32();

    return Response.FromValue(count, result);
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

emitter:client:csharpIssue for the C# client emitter: @typespec/http-client-csharp

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions