Skip to content
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

JSON Schema only use $def for selected types, need better way to reference other files #105

Open
fivegrant opened this issue Jan 24, 2024 · 3 comments

Comments

@fivegrant
Copy link
Collaborator

If I validate an object against a JSON Schema, it will check all $defs. This behavior ends up being too permissive since some types will be objects with arbitrary fields due to the Object InterType. This means nearly any JSON will validate against it which defeats the purpose of a JSON Schema.

A solution to this may be just selecting the InterTypes you want for the JSON Schema using its specific generate_module method's kwargs:

generate_module(mod, JSONTarget; exposed_intertypes=[:SomeType, :AnotherType])

Note that this isn't a problem with Pydantic since the constructor is called explicitly.

(Encountered this problem when reviewing this PR)

@jpfairbanks
Copy link
Member

By introducing the exposed intertypes, those would be the ones that have specifications we could correctly validate, or those are the ones to permissively allow anything?

@fivegrant
Copy link
Collaborator Author

It would be the former. An "exposed" InterType is something we'd want to validate against.

@fivegrant fivegrant changed the title When generating a JSON Schema, only use $def for selected types. JSON Schema only use $def for selected types, need better way to reference other files Feb 1, 2024
@fivegrant
Copy link
Collaborator Author

fivegrant commented Feb 1, 2024

Additionally, references are broken in the JSON Schema. Perhaps specifying a prefix like https://raw.githubusercontent.com/user/repo/some/path would add the path in front of all $refs

For JSON Schema to be usable, I think it has to support:

generate_module(mod, JSONTarget; exposed_intertypes=[:SomeType, :AnotherType], prefix="https://raw.githubusercontent.com/user/repo/some/path" )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants