-
-
Notifications
You must be signed in to change notification settings - Fork 325
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unable to generate models for meta jsonschema #447
Comments
@Skeen |
I ran datamodel-code-generator for the schema
I check the detail of the schema.
I don't understand why What do you think about it? |
This is unexpected to me too, I'd have imagined either a type definition or a reference within an object, not just |
I was toying around with this issue and it seems like the main problem is that there are several fields (e.g. Would be nice if it could self-bootstrap the jsonschema spec itself :) Was able to make a tiny bit of progress by amending items to allow for bool:
This required messing with That just leaves the fields in draft-07.json ... Ok I messed around with it for a while and found these locations which seem to be amenable. Obviously I'd want to clean these up but I think I have at least found the pain points. I also need to dig into the spec to determine what the intent of these https://github.com/xkortex/datamodel-code-generator/tree/xkortex/447/handle_true_attributes Also I found a bug in the way the NonNegativeIntegerDefault0 is being generated:
should be more like this I believe:
|
Possibly relevant: OAI/OpenAPI-Specification#668 (comment) So I think we might be able to substitute in the empty object in places where we encounter these Also I was thinking about the whole self-hosting thing a bit more. In theory, since the json-schema describes itself, we ought to be able to compile the json-schema draft (e.g. draft-7.json) to python, then use that to parse that very same draft. The output of that parse should compile back to python. This could be a very useful way to test the veracity of the parser and generator. In fact, that "self-compiling" python code could act as the main parser in the library. It's much, much shorter, so I wonder why there is so much manual logic in the current JsonSchemaObject. Maybe that's the bootstrapping overhead? :) |
@xkortex I was checking out that thread and it looks like, yep, the jsonschema spec treats I also think your idea about the self-describing schema is excellent; maybe worth a separate issue? update: this seems to clear things up per the latest openapi docs:
So... a "true" just means there's a subschema that can be empty, while a "false" is a subschema that cannot be empty? |
Also I believe this would solve #696 |
My understanding of the v7 specification is that array with items "true" are tuples, not lists where additional items are accepted (would false otherwise) see https://json-schema.org/understanding-json-schema/reference/array.html#items under the tuple section. |
I'm sorry for my too-late reply. |
Thank you for all the good work! |
Describe the bug
I expected to be able to generate Pydanic models for validating JSONSchemas themselves.
To Reproduce
Fetch the json-schema meta-schema draft 7:
Run datamodel-codegen:
Expected behavior
I expected data-models able to parse JSONSchemas to be generated.
Version:
The text was updated successfully, but these errors were encountered: