You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# generated by datamodel-codegen:
# filename: v5.json
# timestamp: 2024-12-18T16:56:18+00:00
from __future__ import annotations
from enum import Enum
from typing import Any
from pydantic import AnyUrl, Extra, Field, confloat, constr
from pydantic_v2 import BaseModel
...
Expected behavior
The import statements should be a valid import statement.
It should use RootModel instead of BaseModel.
# generated by datamodel-codegen:
# filename: v5.json
# timestamp: 2024-09-30T08:54:36+00:00
from __future__ import annotations
from enum import Enum
from typing import Any, Literal
from pydantic import AnyUrl, BaseModel, ConfigDict, Field, RootModel
...
Version:
OS: Ubuntu 20.04
Python version: 3.11.6
datamodel-code-generator version: 0.26.4
Additional context
I managed to generate the correct model a few month ago but I lost the exact command I used. So I have the expected code.
Describe the bug
I want to generate models from this schema https://vega.github.io/schema/vega-lite/v5.json. I want to use pydantic v2 but the generated code is incorrect.
Firstly, the BaseModel is imported like this :
from pydantic_v2 import BaseModel
Secondly, it uses the BaseModel but I expect it to use the RootModel.
To Reproduce
Example schema:
https://vega.github.io/schema/vega-lite/v5.json
Used commandline:
Observed behavior
Expected behavior
The import statements should be a valid import statement.
It should use RootModel instead of BaseModel.
Version:
Additional context
I managed to generate the correct model a few month ago but I lost the exact command I used. So I have the expected code.
Related Issues
#2201
#1435
The text was updated successfully, but these errors were encountered: