Set 'default' field type as anything possible#105
Open
MathieuAvila wants to merge 1 commit intoDorthu:masterfrom
Open
Set 'default' field type as anything possible#105MathieuAvila wants to merge 1 commit intoDorthu:masterfrom
MathieuAvila wants to merge 1 commit intoDorthu:masterfrom
Conversation
Owner
|
The jsonschema spec says the following about
That's not exactly prescriptive, but per RFC-2119:
As written today, this example schema is invalid: Example:
type: integer
default: "this is a string"That's clearly an oversimplified example, but I guess the question is: why would |
Dorthu
reviewed
Aug 3, 2023
| self.description = self._get("description", str) | ||
| self.format = self._get("format", str) | ||
| self.default = self._get("default", TYPE_LOOKUP.get(self.type, str)) # TODO - str as a default? | ||
| self.default = self._get("default", [list, dict, str, int, float, bool]) # TODO - str as a default? |
Owner
There was a problem hiding this comment.
If we wanted to accept any type here, a wildcard would be more appropriate:
Suggested change
| self.default = self._get("default", [list, dict, str, int, float, bool]) # TODO - str as a default? | |
| self.default = self._get("default", "*") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Default can be anything.
Same problem than MR #104 : unable to write UT, the following error occurs:
============================================================================================== ERRORS =============================================================================================== ______________________________________________________________________________ ERROR collecting tests/fastapi_test.py _______________________________________________________________________________ tests/fastapi_test.py:15: in <module> from api.main import app tests/api/main.py:59: in <module> def getPet(pet_id: int = Query(..., alias='petId')) -> Pets: ../.local/lib/python3.10/site-packages/fastapi/routing.py:706: in decorator self.add_api_route( ../.local/lib/python3.10/site-packages/fastapi/routing.py:645: in add_api_route route = route_class( ../.local/lib/python3.10/site-packages/fastapi/routing.py:491: in __init__ self.dependant = get_dependant(path=self.path_format, call=self.endpoint) ../.local/lib/python3.10/site-packages/fastapi/dependencies/utils.py:261: in get_dependant type_annotation, depends, param_field = analyze_param( ../.local/lib/python3.10/site-packages/fastapi/dependencies/utils.py:410: in analyze_param assert isinstance(field_info, params.Path), ( E AssertionError: Cannot useQueryfor path param 'pet_id' ====================================================================================== short test summary info ====================================================================================== ERROR tests/fastapi_test.py - AssertionError: Cannot useQueryfor path param 'pet_id' !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Interrupted: 1 error during collection !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ========================================================================================= 1 error in 0.49s ==========================================================================================