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

Easier sub-schema navigation #15

Closed
shadow-cs opened this issue Oct 5, 2020 · 5 comments
Closed

Easier sub-schema navigation #15

shadow-cs opened this issue Oct 5, 2020 · 5 comments
Labels
enhancement New feature in an existing library

Comments

@shadow-cs
Copy link
Contributor

It would be helpful if we can traverse sub-schemas more easily. Currently specific types which hold sub-schemas have to be traversed manually since they share o common ancestor/interface.

A switch over all keywords (which have sub-schemas) is currently necessary, see here.

Original discussion: #8.

@gregsdennis
Copy link
Owner

I agree with the motivation for this, but I'm struggling to find an elegant solution.

For reference:

I started trying to add a subschemas property to the IRefResolvable interface, but I found that the main problem is that the keywords expose subschemas differently. Some have a single subschema (contains), while others have multiple (anyOf). For the ones with multiple, the subschema is a direct descendant in an array (anyOf), while for others, the schema is nested under keys ($defs, properties), both of which differently affect how references would be resolved.

This means that the "better" solution is actually to create three different interfaces (single schema, multiple indexed subschemas, multiple keyed subschemas) rather than adding onto IRefResolvable, but I'm not sure that really helps navigating the schema structure.

@gregsdennis
Copy link
Owner

@shadow-cs I'd like to discuss some things about your gist that caught my eye, but such a conversation doesn't suit GitHub well. Do you mind joining my Slack workspace and DM-ing me?

@gregsdennis gregsdennis added the enhancement New feature in an existing library label Oct 9, 2020
@gregsdennis
Copy link
Owner

Offline, @shadow-cs and I discussed and we agree that the best approach would be to add three new interfaces to describe the different types of schema-carrying keywords.

  • single child schema
  • list of schemas
  • string-keyed dictionary of schemas

Keywords will implement these keywords as appropriate. This also provides a mechanism for custom keywords to be included in the kind of navigation that's desired.

@gregsdennis
Copy link
Owner

Do you have any issue with these interfaces being implemented explicitly? This means that you'd have to cast to the interface to see the properties. It means that I don't have to rename properties, which would be a breaking change.

@shadow-cs
Copy link
Contributor Author

Works like a charm, no problems with explicit casting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature in an existing library
Projects
None yet
Development

No branches or pull requests

2 participants