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] should tcgc unify the content type logic for bytes format inference #1999

Open
qiaozha opened this issue Dec 18, 2024 · 0 comments
Open
Assignees
Labels
lib:tcgc Issues for @azure-tools/typespec-client-generator-core library

Comments

@qiaozha
Copy link
Member

qiaozha commented Dec 18, 2024

for this case, the contentType is a union of application/json or text, but tcgc returns bytes as the default encoding

  @get
  getSchemaByVersion is Azure.Core.Foundations.Operation<
    Azure.Core.Foundations.ItemKeysOf<Version>,
    OkResponse & SchemaContent & SchemaContentType
  >;

@doc("The content type for given schema. Each schema type has an associated content-type.")
model SchemaContentType {
  @doc("The content type for given schema.")
  @header("Content-Type")
  contentType: SchemaContentTypeValues;
}

@doc("Content of the schema.")
model SchemaContent {
  @body
  @doc("String representation (UTF-8) of the schema.")
  content: bytes;
}

union SchemaContentTypeValues {
  avro: "application/json; serialization=Avro",
  @added(ServiceApiVersions.V2022_10)
  json: "application/json; serialization=json",
  @added(ServiceApiVersions.V2022_10)
  custom: "text/plain; charset=utf-8",
  @added(ServiceApiVersions.V2023_07_01)
  protobuf: "text/vnd.ms.protobuf",
}

After some investigation with @tadelesh offline, tcgc is using strict equal to "application/json" to set the default encoding as base64

} else if (!defaultContentType || defaultContentType === "application/json") {

But, previously, we have an ask from client emitter side that suggests us to leverage the logic from dotnet Azure/autorest.typescript#2200 and fixed in https://github.com/Azure/autorest.typescript/pull/2258/files#diff-7dd8f9407e7839a21c48e98c9da493fa7da52885017e1df4dbf18a346b9933c8

I wonder if tcgc could also leverage this ?

@tadelesh tadelesh self-assigned this Dec 18, 2024
@tadelesh tadelesh added the lib:tcgc Issues for @azure-tools/typespec-client-generator-core library label Dec 18, 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

2 participants