Closed StarProxima closed 1 year ago
Is there any annotation in your backend so that nullable
is used?
"last_name": {
"type": "string",
"nullable": true,
"title": "Last Name"
}
Is there any annotation in your backend so that
nullable
is used?"last_name": { "type": "string", "nullable": true, "title": "Last Name" }
After talking to the backend team, there is an option to add nullable, but the type will also be set via anyOf:
"last_name": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"nullable": true,
"title": "Last Name"
}
So far, the only solution to the problem seems to me to support setting nullable type via anyOf.
@Carapacik This feature looks more difficult than adding a flag. I think it is better to be implemented by a maintainer, because you need a good understanding of the package structure. What do you think about it?
Already think about that in https://github.com/Carapacik/swagger_parser/issues/5
Found a workaround using a self-describing class on the backend:
Annotated[Union[UUID | SkipJsonSchema[None]], Field(json_schema_extra=lambda x: x.pop('default', None))]
The new pydantic 2.1 on backend (Python, FastApi) describes nullable types in the anyOf specification. It would be nice to support this way of specifying a nullable type.
Small example:
Result:
Expected result:
OpenApi: