-
Notifications
You must be signed in to change notification settings - Fork 9.1k
Standardize Parameter Models #301
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
This was done intentionally to avoid allowing to define objects as non-body parameters. It would probably change for some types of form parameters but is unlikely to change for path/query/header parameters. |
I see, yet still it seems like an un-needed branching logic we have to deal with. Its seems pretty obvious that one cannot have objects in query/path/header and cookies. From a consumption-tooling perspective I'd prefer to not have different logic based on the type of parameter and rely on a schema property that will give information about the model. |
It's not really that obvious. In 1.2, you technically could have models as types for query and path parameters, which pretty much lead to this structure. I don't disagree the divergence is inconvenient for tooling (and iirc, I wasn't too happy about it when we decided to do that in 2.0), but sometimes it's about finding the balance between helping the tools and helping people create proper specs. I tend to think it's more important to protect from human-errors than make tooling-development easier. It's all in the numbers. |
There is a valid concern about ensuring people don't define impossible things. However, within a technically valid swagger spec someone could already declare, e.g.:
Supporting the 'schema' attr for all parameters allows better reuse of code and communication of intent. ("Ah, I see that the Swagger validation could still check that the 'schema' doesn't try anything invalid, some of which can be performed by the 'schema.json' definition. |
Even if we allowed referencing a 'schema object', to keep a similar structure, it would be a different limited 'schema object', so the structure of the parameter would be the same, but the validation will not. It'll complicate the spec, but it may be a necessary evil. |
@webron I would argue that it could be a complete schema... If the intersection of "valid swagger parameter" and "schema validation" is a NULL set, that parameter just won't be able to be used. (Friendly implementations, editors etc could detect and advise) |
Considering we don't allow model definitions in parameters other than body parameters, I don't see how that's going to work. |
@webron I'm not advocating 'model' definitions in parameters, or object-type parameters. I'm advocating allowing 'schema', so that schemas that are defined elsewhere already can be reused. (as well as standardization benefits etc) A simple example;
B: GET "/person/{id}" is a path returning a person object.
which I'll argue is difficult to read, difficult to maintain (what if the person_id schema changes?), and not semantically helpful.
Your concern about developers defining invalid parameter types is justified, but it is possible for a library to catch that; the swagger schema checker can use something like |
Interesting. So to refine the concept, the following fields would be part of a
All other fields could be referenced from a So to take your examples a bit further, you could end up with this:
From here, you could also expect to use +1 |
@jasonh-n-austin yes that's correct. My example was kept very simple to avoid confusion, but one would probably use a reference for the parameter too. I think for backwards-compatibility Swagger should continue to support those current validation fields, allow 'schema', and implementations should check values against both if both are defined. |
Maybe I came off wrong. I'm all for allowing reusability for primitive definitions. The only restrictions is that we should limit those to primitive definitions. This will be more challenging when it comes to the JSON schema of the spec, the spec document itself, and possibly some aspects of the tooling, but in this case, I don't think these factors should stop us from providing support for it. |
Sounds good to me, at least as far as; A solution to the "reusability" issue should not try to completely change other aspects of the spec. |
Parent issue: #565. |
@dilipkrish - I believe this can be closed following #654. Please reopen if you feel otherwise. |
It seems odd that
Serializable
parameters be treated differently that Body Parameters. In the interest of consistency, I would think that regardless of the type of parameter it should always have a schema property.I would expect it to be rendered as shown below
The text was updated successfully, but these errors were encountered: