-
-
Notifications
You must be signed in to change notification settings - Fork 313
No method of reusing definitions in object without using a sub-object. #796
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
Comments
There is a solution to this already. This boils down to where you can and cannot have a subschema. It's fine to use
You would have to remove the |
In my opinion this does not solve a problem that cannot be solved differently already, so 👎 |
Using allOf is a really awkward way of doing something that should be simple. ;-) Yes....this prevents you from using $copy as a property, but only if you use a $ref with it. If a $copy property is defined using any schema other than $ref, you could still create such a property. |
I'm afraid your solution is far more akward when you look at the bigger picture. |
If you add obscure syntax for every little corner case you end up with a monstrosity of a specification. |
@chaeron In any event, people have been using Your solution complicates the processing model (it violates the principle that each schema object can be evaluated on its own by splicing two partial schemas together) and saves maybe one level of indentation somewhere. It is similar to Note that we recommend against using |
Thanks for all the considered responses. When I get some time, I'll make my schema (and code generation that depends on it) to conform to the allOf approach for doing this kind of reuse of definitions. |
@chaeron You're welcome! Please do continue to ask questions and make suggestions. We strive to try and fully understand your point of view and requirements. It often turns out things are a lot more complex than we first anticipate, so you're in good company. |
Where can I find more info about unevaluatedProperties, more specifically examples of usage? Thanks! |
@chaeron there will be more as we publish the spec. Right now the same people working to finish the spec are the ones who will need to add guides and examples on the web site. And everyone's on vacation b/c end of summer / labor day weekend. Check back in a few weeks! |
Thanks....I posted my question too soon. Found a good explanation here: Posting in case anyone else is looking, prior to finalization of the spec and revision of examples/documentation. ;-) |
The current Draft-8 spec (or any prior versions of JSON Schema) do not allow for a method of reusing a definition in an object directly, without embedding that definition as a sub-object.
For example, if I have timestamps defined as follows:
There is no way to directly "copy" the timestamp property definitions into a schema object where the created_at & updated_at properties are at the same level as the top level properties of the object. What I want is to be able to validate an object such as:
but using the timestamps definition (since timestamps could be used in many sub-objects in a schema).
Currently the only way to do this is to use a schema like the following:
But that forces the created_at/updated to be in a sub-object as follows:
...which is not the desired result.
What I have done is to create a new applicator called $copy in my schemas (which I use for code generation in my particular application), so the schema looks like this:
but alas, that applicator is not part of the spec. Maybe it should be, to handle this particular use case?
Thanks for following along and giving the idea of a $copy applicator some thought.
.....Andrzej
The text was updated successfully, but these errors were encountered: