[QUESTION] How to specify json data input in docs for request?
See original GitHub issueQuestion
How can I make my Input parameters show up in the swagger docs for a JSON request? I make requests like this …
curl 'http://127.0.0.1:5000/predict' -H "Content-Type: application/json" --data '{"data": ["string1", "string2"]}'
from fastapi import FastAPI
from starlette.requests import Request
from pydantic import BaseModel
from typing import List
app = FastAPI()
class Prediction(BaseModel):
term: str
label: str
score: str
class Output(BaseModel):
success: bool
prediction: List[Prediction] = []
# .. this is probably wrong.
class Input(Request, BaseModel):
data: List[str] = []
@app.post('/predict', response_model=Output)
async def predict(request: Input):
data = Output(success=False)
try:
params = await request.json()
except Exception as e:
print(e)
...
data.success = True
return data
Swagger docs without input parameters
I would like this to show the input schema so the user knows they’re supposed to POST with {"data": [list of strings])
Issue Analytics
- State:
- Created 4 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Working with JSON data in Google Standard SQL | BigQuery
Given a JSON type in BigQuery, you can access the fields in a JSON expression by using the field access operator. The following...
Read more >sending file and json in POST multipart/form-data request with ...
I managed to make a correct request via Postman, by sending document as a .json file. Though I discovered this only works on...
Read more >Working with JSON - Learn web development | MDN
In this article, we've given you a simple guide to using JSON in your programs, including how to create and parse JSON, and...
Read more >Getting Started Step-By-Step - JSON Schema
To start a schema definition, let's begin with a basic JSON schema. We start with four properties called keywords which are expressed as...
Read more >Using REST to Invoke the API | Programmable Search Engine
This document describes how to use the Custom Search JSON API. ... Search query - Use the q query parameter to specify your...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@Shane-Neeley You don’t need to
await request.json()
. You can take @iishyfishyy’s advice and remove theRequest
inheritance:fastapi will take care of deserializing the body into
request
for you, so there’s no need toawait request.json()
. Also note that it will show up as a “Request body.” “Parameters” is for url (query) params.Shouldn’t this
be this
I don’t think you need
Request
in your input model.