Comments (2)
Hi,
Out of my own curiosity, I decided to do a little investigation ... It turns out that the event of the unexpected deletion in your example happens in the handle_ref_overrides
method of the GenerateJsonSchema
class (link to the exact line).
The documentation of the method partially explains a notion of deleting sibling keys (here key title
with value "MyInnerModel"
in inner_1
and MyInnerModel
). I am not fluent in the doings of the Pydantic's schema generation so unfortunately I can't provide you with explanation nor fix.
Since I spend some time on this issue I will try to delve into this topic if I find some free time and no one else has addressed your question yet 🙂
But at the moment, my money is on this being an expected behavior. I believe that what the Field(title="...")
does is some kind of renaming of the title of MyInnerModel
type, which by default is a class' name. The title of the MyInnerModel
type in the inner_1
is handled by the $ref
to the MyInnerModel
class, hence the missing "title"
key in the schema["properties"]["inner_1"]
.
from pydantic.
Hi folks!
I believe @antoni-jamiolkowski is on the right track here - I think this is the expected behavior - the title is by default the class name, so during JSON schema generation, we remove redundant title information. I think if you want to retain the redundancy, custom JSON schema generation would be the best route to go for now!
from pydantic.
Related Issues (20)
- Json field display garbled characters when ensure_ascii=True HOT 4
- Union discriminator validation raises irrelevant errors HOT 1
- Pydantic generic models fail to generate schema with typing-extensions 4.12 TypeVar HOT 5
- Pydantic model fails to generate with annotated list of models using discriminated union and typing-extensions==4.12.0 HOT 8
- PositiveInt behavior differs between v1 and v2 HOT 1
- New model config option: `warn_on_extra` HOT 1
- Broken decimal parsing when using BeforeValidator HOT 7
- Reading pickled model with new schema does not initialise defaults HOT 1
- Allow for model discrimination without the creation of another BaseModel HOT 3
- ambiguous union discrimination when multiple models correspond to the input arguments HOT 1
- Random fails in field serialization HOT 4
- Validation issue with alias fields and init args HOT 9
- "in-congruent" format validation behavior when exported to jsonschema HOT 2
- Failed to create model with two generic parameters when Typevar.default is set HOT 1
- Discriminator on non-Union types HOT 1
- Write new feature pattern docs HOT 1
- `AnyUrl` requires host for validation but `.host` is typed `None | str` HOT 3
- Increase tests coverage for new pipeline API HOT 4
- `model_json_schema()` fails to include annotated third-party types: "Default value is not JSON serializable [non-serializable-default]" HOT 3
- Dynamically include/exclude fields from dumps HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pydantic.