feat: Add handling of OpenAPI endpoint default responses #1304
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Addresses feature request for handling default responses: #832
This treats the string literal
"default"
as an alternative form of status code for the internalResponse
object and handles parsing it appropriately in theEndpoint
class parser. This takes the form of replacing a few instances ofHTTPStatus
with a union type alias and a conditional check on consuming that response field. Since this is now a normalResponse
object added to theEndpoint
, the return type handling includes its output type appropriately.This additionally modifies the endpoint template to consume this alternative form of status code, making that default
Response
the handler for any unspecified status codes. Since now all status codes are now handled, it removes the fallback unexpected status handler code and changes the return typing of the_parse_response
function to match. This breaks out the response handling into a Jinja macro so as to not duplicate that code template bit.The effect of this is that when
default
is used as a possible response for an endpoint, it will be treated as any other response type/code would be except that it serves as the fallback for all possible HTTP responses in the runtime response parser, which is how I understand the spec to describe this feature. If a default response object is not present, there are no changes to the generated code compared to before these changes (except for the addition of a blank line, if this is a problem I still need to figure out how to make it go away, it wasn't straightforward to me).I wasn't totally sure about testing, so I added a functional test that ensures that the generated endpoint contains the changes to the return typing now that it will always return some (only if there is a default response object) and added a new endpoint to both the 3.0 and 3.1 e2e test APIs and regenerated the snapshots. I'm happy to take feedback and change how the testing works if this isn't appropriate.