-
First Check
Commit to Help
Example Codecustom_openapi = [{
"apisSorter": "alpha"
}]
tags_metadata = [
{
'name': 'Log',
'description': 'Software Logs.',
},
{
'name': 'Redis',
'description': 'Volatile DB.',
},
]
app = FastAPI(
title='XXXX DMS API',
description=(
'API REST'
f' | Copyright © {date.today().year}'
' All rights reserved'),
openapi_tags=tags_metadata,
openapi_schema=custom_openapi,
docs_url=None,
swagger_ui_parameters={"defaultModelsExpandDepth": -1},
) DescriptionHi everyone I may have found a bug. I was using fastapi 0.97.0 for my projects and today when I upgraded it to 0.99.1, I'm getting this error when trying to access the docs page: As you can see, the image shows that the openapi version returned is 3.1.0 and the error page is telling me that I should use a 3.0.x version. The image below, shows fastapi 0.97.0 returning the openapi version as 3.0.2, as it should. Sorry if it isn't a bug, but I couldn't find a proper solution anywhere. Operating SystemLinux Operating System DetailsI have a MacBook Pro M1 and I'm running an Ubuntu 20 virtual machine with Parallels on it FastAPI Version0.99.1 Python Version3.10.12 Additional ContextNo response |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 18 replies
-
I think your swagger-ui.js is cached and the cached one is version 4. FastAPI uses swagger ui 5 now ( a recent change ) that supports 3.1 Try and make sure that JS is the correct one (seen here) |
Beta Was this translation helpful? Give feedback.
-
on the other hand, I need it to be set as app = FastAPI(
title="name",
version=metadata.version("name"),
docs_url="/api/docs",
redoc_url="/api/redoc",
openapi_version="3.0.2",
openapi_url="/api/openapi.json",
default_response_class=UJSONResponse,
) However, when I checked the JSON it is still curl http://localhost:8000/api/openapi.json | jq .openapi
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 57869 100 57869 0 0 5926k 0 --:--:-- --:--:-- --:--:-- 27.5M
"3.1.0" am I missing something? |
Beta Was this translation helpful? Give feedback.
-
This is pretty big annoyance for us at my $WORK We're using some We've had to resort to a janky handmade conversion script I cobbled together. Here's what I have so far: import typing as t
Json = dict[str | t.Literal["anyOf", "type"], "Json"] | list["Json"] | str | bool
def convert_3_dot_1_to_3_dot_0(json: dict[str, Json]):
"""Will attempt to convert version 3.1.0 of some openAPI json into 3.0.2
Usage:
>>> from pprint import pprint
>>> json = {
... "some_irrelevant_keys": {...},
... "nested_dict": {"nested_key": {"anyOf": [{"type": "string"}, {"type": "null"}]}},
... "examples": [{...}, {...}]
... }
>>> convert_3_dot_1_to_3_dot_0(json)
>>> pprint(json)
{'example': {Ellipsis},
'nested_dict': {'nested_key': {'anyOf': [{'type': 'string'}],
'nullable': True}},
'openapi': '3.0.2',
'some_irrelevant_keys': {Ellipsis}}
"""
json["openapi"] = "3.0.2"
def inner(yaml_dict: Json):
if isinstance(yaml_dict, dict):
if "anyOf" in yaml_dict and isinstance((anyOf := yaml_dict["anyOf"]), list):
for i, item in enumerate(anyOf):
if isinstance(item, dict) and item.get("type") == "null":
anyOf.pop(i)
yaml_dict["nullable"] = True
if "examples" in yaml_dict:
examples = yaml_dict["examples"]
del yaml_dict["examples"]
if isinstance(examples, list) and len(examples):
yaml_dict["example"] = examples[0]
for value in yaml_dict.values():
inner(value)
elif isinstance(yaml_dict, list):
for item in yaml_dict:
inner(item)
inner(json) |
Beta Was this translation helpful? Give feedback.
I think your swagger-ui.js is cached and the cached one is version 4.
FastAPI uses swagger ui 5 now ( a recent change ) that supports 3.1
0.97 uses version 4
Try and make sure that JS is the correct one (seen here)