Given the following specification:
info:
title: Example API
version: '1.0'
openapi: 3.0.0
components:
schemas:
MyType:
x-type-metadata:
type-metadata-1: type md 1 value
type-metadata-2: type md 2 value
type: object
properties:
myProperty:
type: string
x-field-metadata:
field-metadata-1: field md 1 value
field-metadata-2: field md 2 value
and the following code to generate the Pydantic model:
generate(
openapi_yaml,
input_file_type=InputFileType.OpenAPI,
output_model_type=DataModelType.PydanticV2BaseModel,
target_python_version=PythonVersion.PY_312,
use_double_quotes=True,
disable_timestamp=True,
set_default_enum_member=True,
collapse_root_models=True,
allow_extra_fields=False,
use_schema_description=True,
use_field_description=True,
field_extra_keys_without_x_prefix={
"x-type-metadata",
"x-field-metadata",
},
)
Generates the following:
# generated by datamodel-codegen:
# filename: <stdin>
from __future__ import annotations
from typing import Optional
from pydantic import BaseModel, Field
class MyType(BaseModel):
myProperty: Optional[str] = Field(
None,
json_schema_extra={
"field-metadata": {
"field-metadata-1": "field md 1 value",
"field-metadata-2": "field md 2 value",
}
},
)
It would be very useful to have the type level "x-*" (in the above example "x-type-metadata") metadata included in the generated code in a similar way that the field metadata is preserved in the json_schema_extra property.
Pay now to fund the work behind this issue.
Get updates on progress being made.
Maintainer is rewarded once the issue is completed.
You're funding impactful open source efforts
You want to contribute to this effort
You want to get funding like this too