-
Notifications
You must be signed in to change notification settings - Fork 243
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 - add heuristics for operation response generation #5831
tsp-openapi3 - add heuristics for operation response generation #5831
Conversation
All changed packages have been documented.
Show changes
|
You can try these changes here
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks so much better, one thing I wish is just if we could maybe not use @defaultResponse
…osoft#5831) Fixes microsoft#3765 This PR primarily changes the way operation return types are handled when converting an Open API 3 doc to TypeSpec. Previously, a separate model was generated for every possible response per operation. This quickly exploded the number of models generated if multiple status codes or content types were defined for an operation. Now, those models are in-lined per operation rather than declared. Additionally, some heuristics are employed to trim down each model expression to remove fields that have TypeSpec-defined default values, and whose status code matches a model from the `@typespec/http` library. To support `@defaultResponse`, a `GeneratedHelpers.DefaultResponse` template is created - only when needed - and is referenced by the generated operations. I also made 3 changes related to response generation as part of this PR: 1. Response headers that use `$ref` are now supported 2. Responses that use `$ref` are now supported 3. Switched to using the OpenAPI parser's `$ref` resolution to resolve refs instead of the more fragile `$ref` string parsing that was being used before. Combined with using the parser's `bundle` feature (which was already used) - this should resolve any edge cases around following `$refs` that point to different files. ~TODO: double-check that the parser-related changes doesn't break the playground importer~ --------- Co-authored-by: Christopher Radek <[email protected]>
Fixes #3765
This PR primarily changes the way operation return types are handled when converting an Open API 3 doc to TypeSpec.
Previously, a separate model was generated for every possible response per operation. This quickly exploded the number of models generated if multiple status codes or content types were defined for an operation.
Now, those models are in-lined per operation rather than declared. Additionally, some heuristics are employed to trim down each model expression to remove fields that have TypeSpec-defined default values, and whose status code matches a model from the
@typespec/http
library.To support
@defaultResponse
, aGeneratedHelpers.DefaultResponse
template is created - only when needed - and is referenced by the generated operations.I also made 3 changes related to response generation as part of this PR:
$ref
are now supported$ref
are now supported$ref
resolution to resolve refs instead of the more fragile$ref
string parsing that was being used before. Combined with using the parser'sbundle
feature (which was already used) - this should resolve any edge cases around following$refs
that point to different files.TODO: double-check that the parser-related changes doesn't break the playground importer