make sure OpenAPI contract says there is a 422 return exception and i…#666
make sure OpenAPI contract says there is a 422 return exception and i…#666
Conversation
There was a problem hiding this comment.
Pull request overview
This PR updates the “answer additional question” API endpoint contract/behavior so request validation errors are represented as standard FastAPI/Pydantic 422s in the OpenAPI spec, and adjusts tests around invalid “time” answers.
Changes:
- Removes the dynamic request-body dependency that injected
typebased onquestion_id, letting FastAPI validateAnswerInputUniondirectly. - Updates the OpenAPI
responsesfor the answer-question endpoint (removing thedefault_responseentry). - Expands and tightens the time-answer validation tests (adds
Noneas an invalid input and asserts additional error details).
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
tests/api/v1/endpoints/test_melding.py |
Extends invalid time input cases and adds assertions on the returned validation error shape. |
meldingen/api/v1/endpoints/melding.py |
Simplifies the answer-question endpoint input handling to rely on direct AnswerInputUnion body parsing and adjusts documented responses. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
| (1000, "Input should be a valid string"), | ||
| (10.00, "Input should be a valid string"), | ||
| (None, "Input should be a valid string"), | ||
| ], |
There was a problem hiding this comment.
This parametrization now includes None, but the test function annotates time_value as str | int a few lines below. With mypy --strict enabled in pre-commit, this will likely introduce a new type error; please widen the annotation to include None (or use a broader type) to keep the test type-checking clean.
| assert len(detail) == 1 | ||
| assert detail[0].get("msg") == error_message | ||
| assert detail[0].get("type") == "string_type" |
There was a problem hiding this comment.
The assertion detail[0].get("type") == "string_type" is not correct for the first parametrized cases where time_value is a string but fails the regex pattern; Pydantic/FastAPI typically reports those as a pattern-mismatch error type (not a string-type error). Consider parametrizing the expected type alongside msg, or only asserting type == "string_type" for the non-string inputs.
| responses={ | ||
| **not_found_response, | ||
| **unauthorized_response, |
There was a problem hiding this comment.
The openapi_extra requestBody example just above this responses={...} block omits the required type discriminator for AnswerInputUnion (it only shows { "text": ... }). Since this endpoint now accepts AnswerInputUnion directly, update the example to include type so the OpenAPI documentation matches the actual request schema.
…mprove tests
Meldingen
Ticket: SIG-1234
Before opening a pull request, please ensure your branch is based on
mainand targetsmain.Check requirements when they are met (strikethrough when not applicable):
Be kind to code reviewers, please try to keep pull requests as small and focused as possible :)