-
Notifications
You must be signed in to change notification settings - Fork 4
There was an error parsing the body #110
-
i follow you tutorial . but i have error . i want get form input openAPI post method
https://eadwincode.github.io/ellar/overview/controllers/#enabling-openapi-docs
code
schemas.py
from ellar.common import Serializer
from pydantic import Field
class CreateCarSerializer(Serializer):
name: str
year: int = Field(..., gt=0)
model: str
class CarListFilter(Serializer):
offset: int = 1
limit: int = 10
class CarSerializer(Serializer):
id: str
name: str
year: int
model: str
controllers.py
from ellar.common import Body, Controller, ControllerBase, delete, get, post, put, Query
from ellar.core import Request
from .schemas import CreateCarSerializer, CarListFilter
@Controller
class CatsController(ControllerBase):
@post()
async def create(self, payload: CreateCarSerializer = Body()):
result = payload.dict()
result.update(message='This action adds a new car')
return result
@put('/{car_id:str}')
async def update(self, car_id: str, payload: CreateCarSerializer = Body()):
result = payload.dict()
result.update(message=f'This action updated #{car_id} car resource')
return result
@get('/{car_id:str}')
async def get_one(self, car_id: str):
return f"This action returns a #{car_id} car"
@delete('/{car_id:str}')
async def delete(self, car_id: str):
return f"This action removes a #{car_id} car"
Beta Was this translation helpful? Give feedback.
All reactions
Everything works fine with the code you posted here.
However, there is no form field on the code you shared. And all Body() fields accept application/json body format.
checkout form inputs doc here
Replies: 2 comments 2 replies
-
error message
{
"detail": "There was an error parsing the body",
"status_code": 400
}
Beta Was this translation helpful? Give feedback.
All reactions
-
Everything works fine with the code you posted here.
However, there is no form field on the code you shared. And all Body() fields accept application/json body format.
checkout form inputs doc here
Beta Was this translation helpful? Give feedback.
All reactions
-
Also, it would be helpful if you can share the log that generated this error. Thanks
Beta Was this translation helpful? Give feedback.
All reactions
-
@bobwatcherx Thanks... I will look at this
Beta Was this translation helpful? Give feedback.