-
Notifications
You must be signed in to change notification settings - Fork 92
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
Support polymorphic validation #28
Comments
Is this blocked by the ambiguities in the spec (OAI/OpenAPI-Specification#403)? |
Yes and no. I think in the linked swagger-tools issue I got a good enough feel for how to do this but it's just not been a high priority. I do plan on it being done by |
@whitlockjc Do you have any progress on this? |
I'm up for any help I can get, I've punted on this long enough. I've thought about this a few times but I have to tell you that this likely won't be easy. I've thought about it a few times but not recently. Let me give this some thought and I'll get back to you. |
I experience |
Wait...so you don't want to implement discriminator validation, you just want to stop indirectly used references (discriminator) from being marked as |
As I think about this, I realize that the easiest way to do this might be to leverage JSON Schema, like we do for non-body parameters. |
@whitlockjc Do you mean converting |
You closed #58 as duplicate of this and it referenced swagger-api/swagger-editor#765 which is exactly what I want to fix. |
Ah, maybe I assumed on #58. "Support Discriminator" is a duplicate of this, as this issue is about general support for discriminator. I'm just saying that there are multiple parts to this:
Did that clear things up? As for how we'll do it, my though of using |
Any progress on this? (I'm also only interested in the unused definition warning) |
I thought @IvanGoncharov had an incoming PR for that but maybe I was wrong. I'm working on json-refs stuff now with hopes of releasing a new sway version within the next few days. At that time, I'll revisit this if Ivan hasn't. |
@whitlockjc We working on an alternative approach for Swagger validation. Currently, our implementation is in proof-of-concept stage and we still working on defining architecture. |
That sucks. It would had been cool to make sway better instead of ending up with a competitor but such is life. Let me know if I can help. |
@whitlockjc It highly experimental so we don't know if this approach will work or not. So as you see it very different from |
That would be great. You've been a great help with the Swagger tooling I've written and I'd rather us work together. So if I can help, let me know. Also, if there is anything in Sway that could be done better/different to make it more useful, please don't hesitate. |
Any update on the validation part? I want my request and response to be validated based on the discriminator field. Currently it validate only against the Base definitions. It would be great if this gets fixed. Let me know the current progress please |
There is nothing to report yet. I've been on vacation and I haven't worked on anything in a few weeks. I'm back and I hope to get to this soon. |
I'm interested in helping out. Here's where I'm unsure of how to proceed. Is the problem here that the Swagger Spec is ambiguous in terms of validation, or in terms of code generation? Seems like there is some confusion as to what the blocking issue is. I'm seeing a few goals that may be colliding.
My difficulty in understanding is coming from some ambiguity around whether the Swagger 2.0 Spec actually supports substitutability, aka "polymorphism through inheritance." According to the "discriminator" property specifier, I believe the construction is sound, and doable. However, I'm lacking some background in the semantics of JSON Schema's allOf, and whether or where anyOf comes into play. Perhaps one issue here is the combination of composition with sum types. This type of construction makes it tricky to deal with disambiguation of members, and allows for strange partial slicing of base types, or double type checking. Although, if I'm not mistaken, the usage of allOf should ensure that a subtype is a superset of the dimensions of its supertype. |
While the Swagger Specification is not very clear on things, there are a lot of details in apigee-127/swagger-tools#241 that help explain how this should work. I think the reason this hasn't been done yet is really about the scope of the work. Right now, we can rely on a JSON Schema validator to do the work. Since discriminator support is not something a JSON Schema validator can use, we have to come up with a way to basically write our own validator. If discriminators were only at one level, this would be really simple but since any schema object could have a discriminator, it very quickly becomes quite painful to support this. I'm not saying it can't be done, I'm just saying this quickly grows in terms of difficulty and scope. That being said, I have thought about this some. One of the options that seems to have the most potential, and the least amount of reinventing of the wheel, is attempting to use JSON Schema primitives like I'd love to talk about it more. |
Sounds like you are focused primarily on the validation side of the equation, which makes sense. That's probably more important than my main concern, which is document generation. This may be better suited for the swagger-spec issues board, but just to keep the conversation alive, I looked into how RAML is specifying this specific construct. It looks like they:
|
Yeah, we're into the realm of the OpenAPI Specification now. As for the context that matters to swagger-tools/sway, it's purely from a validation perspective. |
Any update on this? |
Although we have implemented polymorphic validation in our tool oav using the If we do not want to use oneOf then there is another approach that can be used, a little cumbersome but will give better error messages.
After making the modification at runtime, give the updated schema to z-schema for validation. This should then do the validation correctly.
This becomes way more complex. Hence validating using Another important point to model validation is setting |
Suggestion: Sway could maintain different copies of the spec internally for semantic and model validation, thereby avoiding the problem of using non 2.0 open api specification keywords like |
Originally reported here: apigee-127/swagger-tools#241
The text was updated successfully, but these errors were encountered: