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

Return NoContent when mocking HTTP 204 operations #2000

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

julienschuermans
Copy link
Contributor

@julienschuermans julienschuermans commented Nov 21, 2024

There's never a need to return a response for HTTP 204 - and these code are unlikely to have any "example" response documented in the spec.

Avoids a uvicorn RuntimeError "Response content longer than Content-Length" when mocking a (3.0) spec containing:

...
      responses:
        '204':
          description: No Content
        '401':
          description: Unauthorized
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ProblemDetails'
...
  • We could also move this if/else check into the operation's example_response method. Thoughts?

Never a need to return a response for HTTP 204
@coveralls
Copy link

coveralls commented Nov 21, 2024

Coverage Status

coverage: 94.388% (-0.02%) from 94.408%
when pulling 0e626b3 on julienschuermans:patch-1
into 3450a60 on spec-first:main.

@chrisinmtown
Copy link
Contributor

I guess you'll have to add/extend a test case to cover the newly added lines?

leverage HTTP Status Enum and NoContent as resp
change import order
@julienschuermans julienschuermans changed the title Update mock.py Return NoContent when mocking HTTP 204 operations Nov 22, 2024
@julienschuermans
Copy link
Contributor Author

julienschuermans commented Nov 22, 2024

I guess you'll have to add/extend a test case to cover the newly added lines?

I can do that - not sure where to place this though. In test_mock.py, test_mock2.py or test_mock3.py ? I guess we want to test behaviour for both Swagger 2.0 and OpenAPI 3? @RobbeSneyders do you have any input?

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.

3 participants