Skip to content
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

[TCGC][LRO] LRO initial response model should not be generated #1750

Closed
Tracked by #2931
haolingdong-msft opened this issue Oct 28, 2024 · 3 comments
Closed
Tracked by #2931
Assignees
Labels
lib:tcgc Issues for @azure-tools/typespec-client-generator-core library

Comments

@haolingdong-msft
Copy link
Member

haolingdong-msft commented Oct 28, 2024

Link #1538 (comment), create a seperate issue to make it more clear.

Issue

For below example, LroOperationStatus model is initial response, and should not be generated. But TCGC will return the model with name LroOperationStatusError and 'public' access, thus after adopting TCGC's access, this model will be generated, which is incorrect.

model LroOperationStatus<TStatusResult = never, TStatusError = Foundations.Error> {
    @key("operationId")
    @visibility("read")
    id: Azure.Core.uuid;

    @visibility("read")
    @lroStatus
    status: JobStatus;

    @visibility("read")
    createdDateTime?: utcDateTime;

    @visibility("read")
    expirationDateTime?: utcDateTime;

    @visibility("read")
    lastUpdateDateTime?: utcDateTime;

    error?: TStatusError;
    result?: TStatusResult;
  }

  op LroLongRunningRpcOperation<
    TParams extends TypeSpec.Reflection.Model,
    TResponse extends TypeSpec.Reflection.Model,
    Traits extends {} = {}
  > is Azure.Core.RpcOperation<
    TParams & RepeatabilityRequestHeaders,
    Foundations.AcceptedResponse<LroLongRunningStatusLocation<TResponse> &
      Foundations.RetryAfterHeader> &
      RepeatabilityResponseHeaders &
      LroOperationStatus,
    Traits
  >;

  @route("/jobs/{id}")
  op getJob is LroLongRunningPollOperation<JobResult>;

  @pollingOperation(LongRunning.getJob)
  @route("/jobs")
  op createJob is LroLongRunningRpcOperation<
    {
      @body body: JobData;
    },
    JobResult
  >;

Solution

TCGC returns usage 0 to indicate the model should not be generated.

@haolingdong-msft haolingdong-msft added the lib:tcgc Issues for @azure-tools/typespec-client-generator-core library label Oct 28, 2024
@ArcturusZhang
Copy link
Member

I personally do not think so.
TCGC should not make assumptions how a SDK generator would use those models related with an operation.
A generator could decide to generate the initial response as part of its API, and this model is really one of the possible return types of this operation.
Therefore from TCGC's perspective, this is by design and correct.

@ArcturusZhang
Copy link
Member

Duplicated with #1678
Close this in favor of #1678

@haolingdong-msft
Copy link
Member Author

If TCGC keeps the current usage and access for LRO intial response, we should have a way to let emitter know when to update access and do not generate this model. But this will make TCGC's access less helpful as emitter still need to update it based on usage.
/cc @ArcturusZhang @tadelesh

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lib:tcgc Issues for @azure-tools/typespec-client-generator-core library
Projects
None yet
Development

No branches or pull requests

2 participants