Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Odmantic model names in openapi.json from FastAPI have __pydantic_model__ suffix #360

Open
sfeltman opened this issue Jul 14, 2023 · 0 comments
Labels
bug Something isn't working

Comments

@sfeltman
Copy link

sfeltman commented Jul 14, 2023

Bug

Odmantic model names in openapi.json from FastAPI have .__pydantic_model__ suffix.

Current Behavior

  1. Create an Odmantic model and use with a FastAPI end-point.
  2. Goto the openapi.json url for the FastAPI site (like localhost:8080/openapi.json for example)
  3. Notice the model will have the name .__pydantic_model__ as a suffix

For example:

from fastapi import FastAPI
from odmantic import Field, Model

class TestModel(Model):
    name: str = Field()

app = FastAPI()

@app.get(
    "/test",
    response_model=TestModel
)
async def test():
    return TestModel(name="testing")

This defines the model in openapi.json as components/schemas/TestModel.__pydantic_model__.
Finally, this leads to openapi-generator-cli outputing a model name as "TestModelPydanticModel".

Expected behavior

The model name in openapi.json should be components/schemas/TestModel not components/schemas/TestModel.__pydantic_model__.

Environment

  • ODMantic version: 0.9.2
  • MongoDB version: N/A
  • Pydantic infos (output of python -c "import pydantic.utils; print(pydantic.utils.version_info())):
             pydantic version: 1.10.7
            pydantic compiled: True
                 install path: ./venv/lib/python3.9/site-packages/pydantic
               python version: 3.9.16 (main, Dec  7 2022, 10:15:43)  [Clang 14.0.0 (clang-1400.0.29.202)]
                     platform: macOS-12.6.5-x86_64-i386-64bit
     optional deps. installed: ['dotenv', 'typing-extensions']
  • Version of additional modules (if relevant):
    • fastapi==0.95.1

Using https://hub.docker.com/layers/openapitools/openapi-generator-cli/v6.6.0/images/sha256-54381220aecf2e77bb4b6694c4e1a03e733b49453292cd1af6f48b510f1f008a?context=explore

Using openapi-generator-cli from docker to generate typescript bindings as follows:

docker run --rm \
		--volume ${PWD}:/work \
		--workdir=/work \
		openapitools/openapi-generator-cli:v6.6.0 \
			generate \
				--generator-name typescript-axios \
				--package-name test-api \
				--input-spec openapi.json \
				--skip-validate-spec \
				--output test-api
@sfeltman sfeltman added the bug Something isn't working label Jul 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant