-
Notifications
You must be signed in to change notification settings - Fork 762
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
[develop 2.0] support allOf in models #188
Comments
Does this include the |
the intent of this issue is to support the spec, for purposes of composition which means adding the discriminator. |
Technically, you can use Though if this issue includes both, that's great. |
yes, we'd like to use it for composition, to reuse schema instead of copy/paste (and to model property inheritance). |
I just gave it a try in #264 - this seems to be working: definitions:
AbstractObject:
properties:
id:
type: string
MyObject:
allOf:
-
$ref: "#/definitions/AbstractObject"
-
type: object
required:
- name
properties:
name:
type: string
ListOfMyObject:
type: array
items:
$ref: "#/definitions/MyObject" Only errors I see so far is that the Model is not shown in ListOfMyObject - but the ModelSchema is shown correctly. |
I wonder how we would end up displaying it, as technically this is not a single model but a set of models to be checked against. |
How do you think this should be displayed? A lot of work recently has been done to properly support arrays, inline schemas and references but to fix this we need to know just how to display ancestors/included models. |
@whitlockjc, I think, we just need to get all schemas from |
@m8rge - unfortunately, The solution should probably be closer to an array of schema possibilities. |
@webron This is spec-related question: https://github.com/swagger-api/swagger-spec/blob/master/versions/2.0.md#composition-and-inheritance-polymorphism |
What's the question? |
Answer to this question must be in spec: https://github.com/swagger-api/swagger-spec/blob/master/versions/2.0.md#composition-and-inheritance-polymorphism |
It's not a question, it's a statement. The spec can't deal with people's mistakes. |
If developer make mistake in schema - this is his fault. This is his pain, not swgger-js developers. I am right? |
Who said we can't add support to it? I just said the meaning of |
We could definitely make this work but we need to figure out the best way to display this stuff. If we could agree on that, we'd be able to do the work. |
+1 |
As far as displaying I think a nice option would be to list the super-class/schema and all children-schemes when the used type is of the super-schema (similar to what is done with compound types). I would mark all child-schemes with "inherits from ..." or something in that manner. |
IMO the
With that in mind: I'd recommend splitting these issues up.
|
If only |
@webron Well, it sort of is, there is just a tiny conditional: if merging 2 properties with the same name, their schema definitions must match. From a JSON schema resource:
Though there may be some cases where one of the schemas is almost the same as the other and, when merged, might not present conflicts for which validation fails, it would appear that, in general, overlapping schema properties would need to match in order to render correctly after a merge. I must concede, however, that I am in agreement with @m8rge about implementation mistakes being the developer's fault. |
@Smolations - thanks, that's indeed a good reference. But it also goes to show you have much There are many subtle technicalities when it comes to JSON Schema, While we can't (and shouldn't) deal with use errors, this does impose some difficulties in what we end up representing in the UI. Please note I'm not looking to argue the semantics of merging, it just really isn't merging at all. For what it's worth, draft 5 currently has a proposal for |
@webron Totally. So while merging the schemas for use in the UI might work for many, if not most, cases, some validator would need to be written in the library and I can understand the hesitation with a lift like that. In any case, as long as "allOf", "anyOf", "oneOf", and "not" eventually get implemented, I'll be happy. 😄 |
Well, can't comment regarding the other keywords other than |
👍 to get this working |
allOf is supported in devleop_2.0. discriminator support is tracked here: |
would it be possible to get inspired by swagger-editor for the display? |
This is still not working but I have found a fix that can be added to the source code. If you place this code in between lines 491 and 492 of the signature.js file it will fix the issue.
|
Currently the 2.0 spec supports
allOf
constructs but the js library does not.swagger-api/swagger-ui#723
The text was updated successfully, but these errors were encountered: