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] [Bug] response/request header schema should not be generated #1749

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

Comments

@haolingdong-msft
Copy link
Member

haolingdong-msft commented Oct 28, 2024

Issue

For below case, RepeatabilityResult is as response header model, and should not be generated. But TCGC returns access for the model as public and usage = 4, thus after adopting TCGC access and usage, it gets generated.

alias RepeatableOperationsWithTraits = global.Azure.Core.ResourceOperations<SupportsRepeatableRequests &
  NoConditionalRequests &
  NoClientRequestId>;

op repeatableAction is RepeatableOperationsWithTraits.ResourceAction<
  User,
  BodyParameter<UserActionParam>,
  UserActionResponse
>;

/**
 * Provides repeatable request headers for requests and responses.
 * @template VersionAdded The version when the trait was added to the specification.
 *           Leave this empty if the trait is always supported.
 */
@trait("RepeatableRequests")
@traitAdded(VersionAdded)
model SupportsRepeatableRequests<VersionAdded extends EnumMember | null = null> {
  #suppress "@azure-tools/typespec-providerhub/no-inline-model" "This inline model is never used directly in operations."
  @traitContext(
    TraitContext.Create | TraitContext.Update | TraitContext.Delete | TraitContext.Action
  )
  repeatableRequests: {
    @traitLocation(TraitLocation.Parameters)
    parameters: RepeatabilityRequestHeaders;

    @traitLocation(TraitLocation.Response)
    response: RepeatabilityResponseHeaders;
  };
}

  @doc("Provides the 'Repeatability-*' headers to enable repeatable requests.")
  model RepeatabilityResponseHeaders {
    @visibility("read")
    @header("Repeatability-Result")
    @doc("Indicates whether the repeatable request was accepted or rejected.")
    repeatabilityResult?: RepeatabilityResult;
  }

detailed test case

Image

Solution

TCGC return usage as 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
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

1 participant