Skip to content

Conversation

dbanty
Copy link
Collaborator

@dbanty dbanty commented Aug 19, 2025

Closes #1271 and #832

@dbanty dbanty force-pushed the support-patterned-status-codes-1271 branch from 6cf48dd to 888d881 Compare August 19, 2025 02:37
@dbanty dbanty force-pushed the support-patterned-status-codes-1271 branch from 2f8bf10 to 3df0ba6 Compare August 24, 2025 01:51
@dbanty dbanty changed the title feat: Support simple patterned http status codes Support patterned and default HTTP status codes Aug 24, 2025
@dbanty dbanty force-pushed the support-patterned-status-codes-1271 branch from 3df0ba6 to 05367ca Compare August 24, 2025 03:11
@dbanty dbanty force-pushed the support-patterned-status-codes-1271 branch 3 times, most recently from d70d32c to 201973b Compare August 24, 2025 03:19
@dbanty dbanty requested a review from Copilot August 24, 2025 03:20
Copy link

@Copilot Copilot AI left a 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.

@dbanty
Copy link
Collaborator Author

dbanty commented Aug 24, 2025

Just gotta add tests for coverage

Copilot

This comment was marked as outdated.

@dbanty dbanty requested a review from Copilot August 25, 2025 22:02
Copy link

@Copilot Copilot AI left a 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 %}
Copy link
Preview

Copilot AI Aug 25, 2025

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.

Suggested change
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.

@dbanty dbanty force-pushed the support-patterned-status-codes-1271 branch from 201973b to f492d41 Compare August 26, 2025 01:51
Co-Authored-By: Jonathan Goodson <jonathan.goodson@nih.gov>
Co-Authored-By: Peter Kolloch <peter.kolloch@observeinc.com>
@dbanty dbanty force-pushed the support-patterned-status-codes-1271 branch from f492d41 to 6fb3bb3 Compare August 26, 2025 02:31
@dbanty dbanty merged commit f9f0ad0 into main Aug 26, 2025
22 checks passed
@dbanty dbanty deleted the support-patterned-status-codes-1271 branch August 26, 2025 02:50
This was referenced Aug 26, 2025
github-merge-queue bot pushed a commit that referenced this pull request Aug 26, 2025
> [!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>
@obs-gh-peterkolloch
Copy link
Contributor

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.

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.

Patterned (4XX) HTTP Status Codes not respected
2 participants