Skip to content

[Feature Request] list of all properties (resolving references) #437

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

Closed
lzkelley opened this issue Jul 18, 2018 · 4 comments
Closed

[Feature Request] list of all properties (resolving references) #437

lzkelley opened this issue Jul 18, 2018 · 4 comments

Comments

@lzkelley
Copy link

lzkelley commented Jul 18, 2018

I'm working with a "complex" set of schema that each use references from numerous other files. It would be super useful if there was an easy way to get a list of all of the references, combining the relevant references in the schema. Perhaps a schema class that could give general derived properties would be helpful, i.e. so that you could do things like,

schema = jsonschema.load_schema(schema_filename)
print(schema.properties)
print(schema.required)
@Julian
Copy link
Member

Julian commented Jul 18, 2018

Hi, thanks!

Not sure I fully follow your example -- from the text it sounds like you're asking for something like #419 or jsonref, but from your code it sounds like you're talking about being able to access dict keys as attributes.

Which of those two (if either) is this about?

@lzkelley
Copy link
Author

lzkelley commented Jul 18, 2018

@Julian Sorry, that was a very vague FR, but I think both of those tools are all that would be required to make my request trivial. I think I'm actually missing how they are different. I was imagining something that would not only dereference/combine-references but also resolve conditional logic (if needed). Thinking that through a bit more, I guess that would actually be non-trivial to determine different nesting levels (and possible recursions) and how to deal with anyOf versus allOf etc.

I haven't looked much at the internal machinery in the jsonschema package, but it seems like the functionality of jsonref must be happening internally, right? There's no easy access to achieve the same effect as jsonref.loads?
I do think the PR: #419 would at least almost completely solve my desired use cases!

@Julian
Copy link
Member

Julian commented Jul 18, 2018

A schema is currently a dict, and resolving a schema is just replacing any instances of $ref with what is currently found at the $ref, so, in slightly mathematical terms, it's a function resolve(schema) that returns a new thing with all $refs replaced with their target.

#419 I think implements one way to do that resolve function (jsonref is another). I'm not super in love with the implementation in #419 (because it couples that resolve function to a schema store rather than just being a function defined to take a schema and resolve it), but I haven't left comments there for its author yet so I can imagine they might be amenable to make it look more like that :).

Once that function exists though, you'd be able to resolve(schema) a schema, and if that schema previously had schema["properties"]["foo"] = {"$ref": someURI}, you'd now have in hand a schema that had schema["properties"]["foo"]["properties"]["someStuffThatCameFromTheReffedSchema"].

The confusion was because your example (and now your last comment) is talking about schema.properties, i.e. attribute access (which I'm very strongly against providing, so if you want that, there are unfortunate libraries that can offer you the ability to access dict keys as attributes), and your last comment about combining *Of is likely yet another unrelated feature where you attempt to flatten out a schema, but as you noted, it's not possible to do that in general, you can have conflicting definitions in different branches.

@lzkelley
Copy link
Author

Yeah, you're right of course. The ability to access a complete list of properties (even solely at the top level) could be quite difficult depending on the structure of the schema in question. The ability to do that easily is prefaced on the structure of the schema, and thus isn't a good, general-purpose method.

Julian added a commit that referenced this issue Oct 4, 2020
96742ba3 Merge pull request #438 from Zac-HD/overflow-with-multipleOf
c5ba4ba3 Check for multipleOf overflow
c12b0db8 Merge pull request #437 from gregsdennis/if-then-else-sequencing
bd148eb7 copy/paste error
3ca7c419 Added if/then/else sequencing tests; resolves #436
fa73bc8d Merge pull request #435 from jviotti/unevaluated-items-typo
2d6de7cb Fix "unevaluted" typos in "unevaluatedItems" suite
2a9be81d Merge pull request #1 from json-schema-org/master

git-subtree-dir: json
git-subtree-split: 96742ba3c4a1eff6de45f0c50a66a975796b7c37
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

No branches or pull requests

2 participants