-
-
Notifications
You must be signed in to change notification settings - Fork 247
Support patterned and default HTTP status codes #1303
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
Conversation
6cf48dd
to
888d881
Compare
2f8bf10
to
3df0ba6
Compare
3df0ba6
to
05367ca
Compare
d70d32c
to
201973b
Compare
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.
Pull Request Overview
This PR implements support for patterned and default HTTP status codes in OpenAPI specifications, enabling the use of status code patterns like 2XX
, 4XX
, and default
in addition to specific status codes like 200
.
- Introduces new
HTTPStatusPattern
class to handle parsing and validation of status code patterns - Refactors response handling to support both specific codes and ranges with proper precedence ordering
- Updates template generation to handle default responses and status code ranges in generated client code
Reviewed Changes
Copilot reviewed 72 out of 72 changed files in this pull request and generated 3 comments.
Show a summary per file
File | Description |
---|---|
openapi_python_client/parser/responses.py | Adds HTTPStatusPattern class and Responses container with pattern/default separation |
openapi_python_client/parser/openapi.py | Updates Endpoint class to use new response structure and pattern parsing |
openapi_python_client/templates/endpoint_module.py.jinja | Modifies template to generate range checks and handle default responses |
tests/test_parser/test_responses.py | Updates tests to use HTTPStatusPattern instead of HTTPStatus |
end_to_end_tests/ | Adds new test endpoints and updates generated client files for pattern support |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
Just gotta add tests for coverage |
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.
Pull Request Overview
This PR adds support for HTTP status code patterns (2XX
, 4XX
, etc.) and the special default
status code in OpenAPI specifications. This closes issues #1271 and #832.
- Replaces the simple integer status code handling with a new
HTTPStatusPattern
class that can parse patterns like "2XX" and "default" - Refactors endpoint responses to use a new
Responses
container that separates patterned responses from default responses - Updates template generation to handle status code ranges and proper precedence ordering (specific codes first, then patterns, then default)
Reviewed Changes
Copilot reviewed 72 out of 72 changed files in this pull request and generated 1 comment.
Show a summary per file
File | Description |
---|---|
openapi_python_client/parser/responses.py |
Core implementation of HTTPStatusPattern class and Responses container for handling status code patterns |
openapi_python_client/parser/openapi.py |
Updated endpoint parsing to use new status pattern system and response organization |
openapi_python_client/templates/endpoint_module.py.jinja |
Modified response parsing template to handle status code ranges and default responses |
tests/test_parser/test_responses.py |
Updated tests to use new HTTPStatusPattern objects instead of integer status codes |
Multiple generated API files | Generated code showing proper handling of status code patterns with range checks and blank lines |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
@@ -12,7 +12,7 @@ from ... import errors | |||
{% endfor %} | |||
|
|||
{% from "endpoint_macros.py.jinja" import header_params, cookie_params, query_params, | |||
arguments, client, kwargs, parse_response, docstring, body_to_kwarg %} | |||
arguments, client, kwargs, parse_response, docstring, body_to_kwarg, parse_response %} |
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.
The parse_response
macro is imported twice in the same import statement, which is redundant and could cause confusion.
arguments, client, kwargs, parse_response, docstring, body_to_kwarg, parse_response %} | |
arguments, client, kwargs, parse_response, docstring, body_to_kwarg %} |
Copilot uses AI. Check for mistakes.
201973b
to
f492d41
Compare
Co-Authored-By: Jonathan Goodson <jonathan.goodson@nih.gov> Co-Authored-By: Peter Kolloch <peter.kolloch@observeinc.com>
f492d41
to
6fb3bb3
Compare
> [!IMPORTANT] > Merging this pull request will create this release ## Breaking Changes ### Change some union variant names When creating a union with `oneOf`, `anyOf`, or a list of `type`, the name of each variant used to be `type_{index}` where the index is based on the order of the types in the union. This made some modules difficult to understand, what is a `my_type_type_0` after all? It also meant that reordering union members, while not a breaking change to the API, _would_ be a breaking change for generated clients. Now, if an individual variant has a `title` attribute, that `title` will be used in the name instead. This is only an enhancement for documents which use `title` in union variants, and only a breaking change for _inline models_ (not `#/components/schemas` which should already have used more descriptive names). Thanks @wallagib for PR #962! ## Features ### Support patterned and default HTTP statuses HTTP statuses like `2XX` and `default` are now supported! A big thank you to: - @PSU3D0 for PR #973 (eons ago 😅) - @obs-gh-peterkolloch for PR #1300 - @goodsonjr for PR #1304 Closes #1271 and #832 > [!NOTE] > Custom template users: the `endpoint.responses` type has changed quite a bit. Check out #1303 for the changes. Co-authored-by: knope-bot[bot] <152252888+knope-bot[bot]@users.noreply.github.com>
Thank you, @dbanty! I upgraded to 0.26.0 and it did not result in code generation differences relative to my pull request. Yours is definitely an improvement! Thanks. |
Closes #1271 and #832