Is your feature request related to a problem? Please describe.
Some schemas include a member with a common name across multiple definitions, but uniquely defined inside each one.
{
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "example",
"type": "object",
"definitions": {
"A": {
"type": "object",
"properties": {
"body": {
"type": "object",
"properties": {
"a_data": {"type":"string"}
},
"required": ["a_data"]
}
},
"required": ["body"]
},
"B": {
"type": "object",
"properties": {
"body": {
"type": "object",
"properties": {
"b_data": {"type":"string"}
},
"required": ["b_data"]
}
},
"required": ["body"]
}
}
}
Currently, this is handled by creating a new definition for each one, with the name being derived from the key name and thus name collisions need to be avoided by adding numbers to later instances.
Describe the solution you'd like
Prefix the model name with the parent model name. This is more readable and provides clearer disambiguation for developers.
from __future__ import annotations
from pydantic import BaseModel
class Example(BaseModel):
pass
class ABody(BaseModel):
a_data: str
class A(BaseModel):
body: ABody
class BBody(BaseModel):
b_data: str
class B(BaseModel):
body: BBody
(note that BBody
would be currently named Body1
)
Describe alternatives you've considered
Additional context
See DAP for an actual schema with this property, getting to Body11
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