[BUG] Body() descriptions cause generated OpenAPI to use `allOf`instead of schema
See original GitHub issueDescribe the bug
When defining a route with a Body
parameter, if a description
is added to the Body
, FastAPI generates an allOf
field in the requestBody schema. This breaks OpenAPI Generator, and according to the spec, allOf
should be used for object composition.
To Reproduce Create a route with a Body parameter ie:
@route.patch("/{request_id}")
def update_request(request_id: UUID, update:RequestModel = Body(..., description="Blah blah")
return "stuff"
OpenAPI Result:
"requestBody": {
"content": {
"application/json": {
"schema": {
"title": "Update",
"allOf": [
{
"$ref": "#/components/schemas/RequestModel"
}
],
"description": ""Blah blah"
}
}
},
"required": true
},
Removing the description generates the requestBody without the allOf
(and without the description).
Expected behavior
"requestBody": {
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/RequestModel"
"description": "Blah blah"
}
}
}
**Environment:**
- OS: macOS
- FastAPI Version 0.42.0
- Python 3.7.4
Issue Analytics
- State:
- Created 4 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
OpenAPI Specification - IntelliJ IDEA Documentation - JetBrains
An OpenAPI Specification (OAS) is a description format for REST APIs. Swagger is a set of tools based on this specification for writing,...
Read more >ng-openapi-gen - npm
This project is a NPM module that generates model interfaces and web service clients from an OpenApi 3 specification. The generated classes ...
Read more >SwaggerUI is defaulting to version 2 when a Springboot ...
java -jar openapi-generator-cli.jar generate -i stack.yml -g spring -p java8=true. I created the project and the Error class is showing up:
Read more >OpenAPI CodeGen Extensions - APIMatic Documentation
How to use APIMatic Code Generation extensions for OpenAPI/Swagger to customize SDKs generated using APIMatic.
Read more >Using the OpenAPI Generator for Spring Boot - mimacom blog
In this blog post, I would like to have a closer look at the basic project setup for generating code from the API...
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
Thank you for the response. I missed that in the OpenAPI specs.
It’s part of the OpenAPI spec. When using
$ref
, the object containing it cannot contain any additional properties. So the only way to have a$ref
and a description is throughallOf
.https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.2.md#fixed-fields-19