Skip to content

Conversation

@jeliebig
Copy link

@jeliebig jeliebig commented Nov 2, 2025

This PR changes the json_schema() method to add basic support for patternProperties and for schemas as additionalProperties.

A good example of what I wanted to achieve with these changes can be seen here: https://json-schema.org/learn/file-system#referencing-entry

Previously when calling json_schema() additionalProperties could only be set to true or false.
With this change the generated schemas are a bit more accurate and can be used to validate (or write) data objects containing variable string keys with specified values.

I noticed that previously additionalProperties was set to true when a object key was present, but that doesn't really make sense for a JSON schema (at least if I'm not missing anything), so now additionalProperties is only set to true if ignore_extra_keys is true.

To set additionalProperties to a schema, ignore_extra_keys must be false and only one str key must be present.

I added tests and adapted the README.rst accordingly, but I don't have much experience with rst, so if something looks weird, please let me know.


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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Schema.json_schema() does not return properties for a dict of dicts where first level key can be any string

1 participant