fastapi / fastapi

FastAPI framework, high performance, easy to learn, fast to code, ready for production

Home Page:https://fastapi.tiangolo.com/

Repository from Github https://github.comfastapi/fastapiRepository from Github https://github.comfastapi/fastapi

Fetch errorInternal Server Error /openapi.json

akzenith opened this issue · comments

First Check

  • I added a very descriptive title to this issue.
  • I used the GitHub search to find a similar issue and didn't find it.
  • I searched the FastAPI documentation, with the integrated search.
  • I already searched in Google "How to X in FastAPI" and didn't find any information.
  • I already read and followed all the tutorial in the docs and didn't find an answer.
  • I already checked if it is not related to FastAPI but to Pydantic.
  • I already checked if it is not related to FastAPI but to Swagger UI.
  • I already checked if it is not related to FastAPI but to ReDoc.

Commit to Help

  • I commit to help with one of those options 👆

Example Code

INFO:     127.0.0.1:55111 - "GET / HTTP/1.1" 200 OK
INFO:     127.0.0.1:52235 - "GET /docs HTTP/1.1" 200 OK
INFO:     127.0.0.1:52235 - "GET /openapi.json HTTP/1.1" 500 Internal Server Error
ERROR:    Exception in ASGI application
Traceback (most recent call last):
  File "C:\Users\me\Anaconda3\lib\site-packages\uvicorn\protocols\http\h11_impl.py", line 373, in run_asgi
    result = await app(self.scope, self.receive, self.send)
  File "C:\Users\me\Anaconda3\lib\site-packages\uvicorn\middleware\proxy_headers.py", line 75, in __call__
    return await self.app(scope, receive, send)
  File "C:\Users\me\Anaconda3\lib\site-packages\fastapi\applications.py", line 210, in __call__
    await super().__call__(scope, receive, send)  # pragma: no cover
  File "C:\Users\me\Anaconda3\lib\site-packages\starlette\applications.py", line 112, in __call__
    await self.middleware_stack(scope, receive, send)
  File "C:\Users\me\Anaconda3\lib\site-packages\starlette\middleware\errors.py", line 181, in __call__
    raise exc from None
  File "C:\Users\me\Anaconda3\lib\site-packages\starlette\middleware\errors.py", line 159, in __call__
    await self.app(scope, receive, _send)
  File "C:\Users\me\Anaconda3\lib\site-packages\starlette\exceptions.py", line 82, in __call__
    raise exc from None
  File "C:\Users\me\Anaconda3\lib\site-packages\starlette\exceptions.py", line 71, in __call__
    await self.app(scope, receive, sender)
  File "C:\Users\me\Anaconda3\lib\site-packages\starlette\routing.py", line 580, in __call__
    await route.handle(scope, receive, send)
  File "C:\Users\me\Anaconda3\lib\site-packages\starlette\routing.py", line 241, in handle
    await self.app(scope, receive, send)
  File "C:\Users\me\Anaconda3\lib\site-packages\starlette\routing.py", line 52, in app
    response = await func(request)
  File "C:\Users\me\Anaconda3\lib\site-packages\fastapi\applications.py", line 161, in openapi
    return JSONResponse(self.openapi())
  File "C:\Users\me\Anaconda3\lib\site-packages\fastapi\applications.py", line 146, in openapi
    servers=self.servers,
  File "C:\Users\me\Anaconda3\lib\site-packages\fastapi\openapi\utils.py", line 388, in get_openapi
    flat_models=flat_models, model_name_map=model_name_map
  File "C:\Users\me\Anaconda3\lib\site-packages\fastapi\utils.py", line 25, in get_model_definitions
    model, model_name_map=model_name_map, ref_prefix=REF_PREFIX
  File "pydantic\schema.py", line 548, in pydantic.schema.model_process_schema
  File "pydantic\schema.py", line 589, in pydantic.schema.model_type_schema
  File "pydantic\schema.py", line 241, in pydantic.schema.field_schema
  File "pydantic\schema.py", line 495, in pydantic.schema.field_type_schema
  File "pydantic\schema.py", line 863, in pydantic.schema.field_singleton_schema
ValueError: Value not declarable with JSON Schema, field: name='Fuel_Type_Petrol' type=Optional[object] required=True

Description

I am new to FastAPI, and I came across this error and don't know how to deal with it. Please, help me solve this.

Operating System

Windows

Operating System Details

No response

FastAPI Version

0.68.1

Python Version

3.6

Additional Context

No response

Can you add example code? You just added the console output

Can you add example code? You just added the console output

I was using 'object' in place of 'str' in: from pydantic import BaseModel
It is working now!