Allow null in JSON schema from Pydantic

Viewed 1128

I'm trying to allow null in the JSON schema for this object:

from pydantic import BaseModel
from typing import Optional

class NextSong(BaseModel):
    song_title: Optional[str] = ...

but the schema which results is as follows:

'{"title": "NextSong", "type": "object", "properties": {"song_title": {"title": "Song Title", "type": "string"}}, "required": ["song_title"]}'

The resulting schema isn't allowing null for the value of song_title, which isn't as intended, but I'm not sure how else to specify that null is allowed, but that the field is still required.

0 Answers
Related