art049 / art049/odmantic

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

Open
#360 0 comments 1 reaction 0 assignees View on GitHub
bug
Dominant language
Python
Stars
1.2k
Forks
97
PR merge metrics
No merged PRs in 30d

Description

# 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:

```python
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

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
```

Contributor guide

Open the contributing guide

Research direction

Reproduce the issue with the shown Odmantic Model, FastAPI endpoint, and /openapi.json entry point using the reported versions. Trace how the response_model becomes the OpenAPI schema, then verify that the generated schema is named TestModel rather than TestModel.__pydantic_model__.

Written by the indexing model from the issue text.

Assessment

Tech stack
fastapi, openapi, python
Domain
api, databases
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.