[QUESTION] Is it possible to generate openapi.json with "nullable" : "true" for non-required property?
See original GitHub issueDescription
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:
class Topic(BaseModel):
first_id: str = None
I want to get a schema like this:
"Topic": {
"title": "Topic",
"type": "object",
"properties": {
"first_id": {
"title": "First_Id",
"type": "string",
"nullable" : "true"
}
}
}
But I haven’t found a way to set the field “nullable”. And if it’s not provided, it is “false” by default.
Issue Analytics
- State:
- Created 4 years ago
- Comments:5 (1 by maintainers)
Top Results From Across the Web
Swashbuckle: Make non-nullable properties required
I found a solution for this: I was able to implement a Swashbuckle ISchemaFilter that does the trick. Implementation is:
Read more >How to specify a property can be null or a reference
This is a real-world problem for my project: complex objects reference other objects, but in some cases, the referenced object is NULL, i.e, ......
Read more >Model generation · GitBook - Goswagger.Io
Non-required or nullable property? Use-Case: when a definition has a property N, if N is a number and is not required, the corresponding...
Read more >How to manage nullable properties - Jane - Read the Docs
You can use it as follows: type: string x-nullable: true. If you are using OpenAPI v2, consider migrating to OpenAPI v3 to get...
Read more >Solving OpenAPI and JSON Schema Divergence - Medium
Creating json -schema-to-openapi was mostly just a case of flipping the tests ... in OpenAPI; Switches type: ['foo', 'null'] to type: foo and...
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
You can use Field to set
nullable=True
by default.Example:
Component in
/openapi.json
@Slyfoxy Thanks for answer, it helped!
I found out, that
Field
is not working with FastAPIBut
Schema
did the job!And
/openapi.json