Open gitgithan opened 2 years ago
The interactive API docs is based on Swagger, which is an open source tool generating this JavaScript interface from an OpenAPI specification. This OpenAPI specification is automatically generated by FastAPI from the constraint you define in Query
and other dependencies. You can actually access it from http://localhost:8000/openapi.json
.
To help you interact with your API, Swagger automatically adds browser validation on the parameters from this specification. This is why the interface doesn't allow you to trigger the request if the parameter is not valid.
This is why I prefer to recommend HTTPie, because it has no hidden magic: it lets you make the query exactly as you like and then see what the server has to answer to this request.
The book demonstrates calling using httpie, so i wanted to test calling from the docs page since it provides convenience in
chapter5_function_dependency_03
However I am unable to leave it empty. If i type gibberish, then it gives in response
Question Where is the validation on the docs defined? It seems like a separate system from fastapi? When things like Query(...,ge=0) are defined and you enter -1, the docs do not even allow Execute to be clicked, showing a red background in the textbox. What is causing this? I also noticed in
chapter5_function_dependency_02
ifskip: int = Query(0, ge=0)
was changed toskip: int = Query(0, gt=0)
,minimum: 0
will disappear from the docs, how does this happen?What is the difference between calling from httpie, docs or other tools?