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

tsp-openapi3 - improve model generation of schemas using allOf #4232

Merged
merged 5 commits into from
Aug 29, 2024

Conversation

chrisradek
Copy link
Member

Fixes #4152
Depends on #4216

This PR updates how tsp-openapi3 handles generating models for schemas that use allOf.

Currently allOf is ignored unless there is only 1 member and that member is a schema reference. In this scenario, the model extends the single member.

This update now takes all of the schema allOf members into consideration when generating a model.

  • inline-schemas have their properties merged into the model's properties
  • schema references without a discriminator defined are spread into the model
  • if only 1 schema reference contains a discriminator, then the model extends it, otherwise these schema references are spread as well.

@azure-sdk
Copy link
Collaborator

azure-sdk commented Aug 21, 2024

All changed packages have been documented.

  • @typespec/openapi3
Show changes

@typespec/openapi3 - fix ✏️

Improves tsp-openapi3 model generation from schemas utilizing allOf. Models will now extend an allOf member if it is a schema reference and the only member with a discriminator. Other members will be spread into the model if defined as a schema reference, or have their properties treated as top-level properties if they are an inline-schema.

@azure-sdk
Copy link
Collaborator

You can try these changes here

🛝 Playground 🌐 Website 📚 Next docs

@chrisradek chrisradek changed the title [don't merge] tsp-openapi3 - improve model generation of schemas using allOf tsp-openapi3 - improve model generation of schemas using allOf Aug 29, 2024
@chrisradek chrisradek marked this pull request as ready for review August 29, 2024 21:27
@chrisradek chrisradek added this pull request to the merge queue Aug 29, 2024
Merged via the queue into microsoft:main with commit 2278c42 Aug 29, 2024
22 checks passed
@chrisradek chrisradek deleted the tsp-openapi3-improve-allof branch August 29, 2024 22:12
weidongxu-microsoft pushed a commit to weidongxu-microsoft/typespec that referenced this pull request Sep 3, 2024
…soft#4232)

Fixes microsoft#4152
Depends on microsoft#4216

This PR updates how tsp-openapi3 handles generating models for schemas
that use `allOf`.

Currently `allOf` is ignored unless there is only 1 member and that
member is a schema reference. In this scenario, the model extends the
single member.

This update now takes all of the schema `allOf` members into
consideration when generating a model.
- inline-schemas have their properties merged into the model's
properties
- schema references without a discriminator defined are spread into the
model
- if only 1 schema reference contains a discriminator, then the model
extends it, otherwise these schema references are spread as well.

---------

Co-authored-by: Christopher Radek <Christopher.Radek@microsoft.com>
sarangan12 pushed a commit to sarangan12/typespec that referenced this pull request Sep 16, 2024
…soft#4232)

Fixes microsoft#4152
Depends on microsoft#4216

This PR updates how tsp-openapi3 handles generating models for schemas
that use `allOf`.

Currently `allOf` is ignored unless there is only 1 member and that
member is a schema reference. In this scenario, the model extends the
single member.

This update now takes all of the schema `allOf` members into
consideration when generating a model.
- inline-schemas have their properties merged into the model's
properties
- schema references without a discriminator defined are spread into the
model
- if only 1 schema reference contains a discriminator, then the model
extends it, otherwise these schema references are spread as well.

---------

Co-authored-by: Christopher Radek <Christopher.Radek@microsoft.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

tsp-openapi3 - allOf with more than one member not supported
4 participants