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

[discussion] [tcgc] Do we imply JSON serialization for orphan model with access=public #2311

Open
weidongxu-microsoft opened this issue Mar 5, 2025 · 3 comments
Assignees
Labels
lib:tcgc Issues for @azure-tools/typespec-client-generator-core library

Comments

@weidongxu-microsoft
Copy link
Member

weidongxu-microsoft commented Mar 5, 2025

Context:

There were tons of model not used by operation in eventgrid (and maybe other services), that need be generated in SDK via access=public
https://github.com/Azure/azure-rest-api-specs/blob/main/specification/eventgrid/Azure.Messaging.EventGrid.SystemEvents/Microsoft.Storage/client.tsp

However, without association with an operation, we cannot definitely know whether the serialization for the model be (JSON? or XML? or None).
We can do None and generate a model that does not support any type of serialization, but this likely not what service wishes.
I would think service typically want JSON.

Current TCGC will not have a serializationOptions for property in such model.
If emitter interprets them as JSON, it had to use property.__raw?.name. See #2118 (comment)

Do we default the serialization to JSON for an orphan model? Or do we require service always add a e.g. @usage(output | json) or @mediaType("application/json") to the model?

@lmazuel
Copy link
Member

lmazuel commented Mar 5, 2025

First, it doesn't have to be a problem in the first place. A model describes a model, and serialization is another layer of usage of this model. IOW, there could be a design where the model is serializationn-agnostic, and conceptually you could do:

serializeXML(model) // get a XML tree
serializeJSON(model) // get a JSON tree

So that's a design choice to tight a model to a serialization, and it doesn't have to be necessary, it's not a curse :).

Now, assuming that a given language has tight serialization to their model, yes we should consider JSON the default, as factually, this is 99% of our usages. Even more, we don't know any situation today, where a model-only generation is expected to work with XML.

@weidongxu-microsoft
Copy link
Member Author

weidongxu-microsoft commented Mar 6, 2025

Agreement is that by default, orphan model should support JSON serialization.

We can consider

  • default-serialization-format=json emitter option for models (that made "public") not associated to an op.
  • In future, about how we can let service say "I want XML instead", or "I want JSON and XML", or maybe "I don't want serialization on the model" (not sure whether this be useful).

@tadelesh
Copy link
Member

tadelesh commented Mar 6, 2025

i prefer to add a default to SerializationOptions. languages could choose their own fallbacks. we could think about how to add serialization indicator for orphan model in the future.

@tadelesh tadelesh self-assigned this Mar 6, 2025
@tadelesh tadelesh added lib:tcgc Issues for @azure-tools/typespec-client-generator-core library and removed needs-area labels Mar 6, 2025
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

3 participants