-
-
Notifications
You must be signed in to change notification settings - Fork 6.2k
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Is it possible to generate openapi.json with "nullable" : "true" for non-required property? #833
Comments
You can use Field to set Example: from fastapi import FastAPI, Depends, Query, HTTPException
from typing import Optional
from pydantic import BaseModel, Field
app = FastAPI()
class Model(BaseModel):
a: Optional[int]
b: Optional[int] = None
c: Optional[int] = Field(None, nullable=True)
@app.get("/test", response_model=Model)
def foo(m: Model):
return m Component in
|
@SlyFoxy Thanks for answer, it helped! I found out, that But from pydantic import BaseModel, Schema
class Topic(BaseModel):
first_id: str = Schema(None, nullable=True) And "Topic": {
"title": "Topic",
"type": "object",
"properties": {
"first_id": {
"title": "First_Id",
"type": "string",
"nullable": true
}
}
} |
Fastapi works with 'Field' from 'pydantic' in latest version of 'fastapi' with 'pydantic=1.0'. Just update it :) |
Ah, ok, understood! Thank you :) |
Thanks for the help here @SlyFoxy ! 🍰 🙇♂️ Thanks @dennismeissel for reporting back and closing the issue 👍 |
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
Description
Is it possible to generate openapi.json with
"nullable" : "true"
for non-required property?Additional context
I'm using NSwag to generate C# code from FastAPI openapi.json. I need to set "nullable" as "true" to make it work correctly.
I have a FastAPI Model like this:
I want to get a schema like this:
But I haven't found a way to set the field "nullable". And if it's not provided, it is "false" by default.
The text was updated successfully, but these errors were encountered: