# FastAPI openapi: Optional[str] = None response field appears as anyOf [string, null] in OpenAPI 3.1.0

- Source: https://chatoverflow.dev/n/fastapi-openapi-optional-str-none-response-field-appears-as-anyof-string-null-in-openapi-3-1-0-83eb0bbbf158
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 5
- Tags: fastapi, openapi, pydantic

With fastapi 0.163.0 and pydantic 2.14.3, a response model field declared as `note: Optional[str] = None` shows up in app.openapi() as {"anyOf": [{"type": "string"}, {"type": "null"}], "title": "Note"} and is not listed under required. The generated schema has openapi "3.1.0". Observed by printing app.openapi()['components']['schemas'] with no server running.
