Repository navigation
Support for parameter interdependencies #100
Replies: 7 comments 8 replies
|
Just realized that I have not accounted for the OpenAPI 3.x |
|
@mikekistler - so just focusing on the use case: (to keep it simple for now). SHOULD we use anything but JSON Schema? |
|
Notes from Moonwalk-sig meeting 4/9
|
|
In today's meeting I mentioned an old draft RFC for query strings, so here is a link to that: It wasn't developed very far but might be of interest given that the WHATWG spec only defines algorithms and not grammars. I imagine they don't produce identical sets of valid strings, but that itself might be interesting. There are several other relevant Moonwalk discussions, including ones on the scope of query string / headers / cookies, which is a decision I suggested could be made separately (maybe I'll look into that- I'll update that discussion if so) and also one about the similar issues around response headers, which is part of what I was talking about for the scope (request headers are params in OAS 3, but response headers are separate):
The other point I made is that the query string can be any string, it does not need to be in |
|
I like that it would now be possible to specify dependencies between other parameter types (previously it was only possible with 'query' paramters, see below), and also between parameters of different types (e.g. if a particular path parameter is seen, require or disallow a particular header). I have questions regarding the proposal as written: Query parameters can be named as (for example) The current mechanism for deserializing all query parameters to a single object for schema verification can be done like so (following the example in the 3.1 spec): - name: color
style: form
explode: true
schema:
type: object
required: [R, G, B]The uri: But if |
|
It is surprising and a bit disturbing that Looking back through the examples from Alberto's talk, these all seem to be cases of interdependencies between query parameters. So, e.g., the "Requires" example could be described in OpenAPI 3.0.x with: I will not argue that this is easy for tooling ... but it is worth noting (as @karenetheridge did above) that it is already possible in OpenAPI 3.0.x. |
|
Inter-dependency implies a bunch of logic checks in tooling that would require work before tooling authors could claim full-support. For example, what would we expect from tools like Swagger UI or Postman when consumers are crafting a request? [I think inter-dependency would at least show some sort of warning if you've created a malformed request (like an onblur check that the other inter-dependent input field had a value).] If this complexity is worth that investment, we should do it--I'd just prefer it to be obvious that this creates much more value in the world than it costs. It does seem like there is enthusiasm in this thread for such a feature. I wonder if we might see this utility demonstrated with |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Moonwalk should allow API designers to express interdependencies between the parameters of an operation.
This is part of the initial Moonwalk Proposal and is broken out here to refine the ideas before creating the ADR.
The Problem to be Solved
All prior versions of OpenAPI used an array to define parameters for an operation. This approach does not provide any formal mechanism for describing interdependencies between parameters. Research [1] has shown that interdependencies are not uncommon in real-world APIs and come in a variety of forms. Issue #256 (opened in 2015) requested this feature and has received over 600 up-votes.
Proposed solution
Rather than using an array to define the parameters for an operation, we should use a JSON Schema. The parameters schema must be an object schema and must not have
additionalProperties. Each named property of the parameters schema defines an operation parameter. Property names of the parameter schema have the form[<in>.]name, where<in>may be "query", "header", "path", or "cookie". When not specified,<in>defaults to "query".Note: Combining the
<in>andnameallows parameters with the same name but different<in>, as is permitted in prior versions of OpenAPI. It also avoids the need to augment JSON Schema for this purpose.The
parameterSchemafield would be supported on Operations and on Path Items. If specified on a Path Item, the effective parameter schema for an operation would be theallOfof the path item schema and the operation schema.The parameter schema may contain JSON Schema assertions to express interdependencies between parameters. Some common interdependencies are described below.
Requires
The presence of a parameter (or a specific parameter value) requires the presence of another parameter.
Example:
answerCountmust be specified ifpromoteis specified.Or
Given a set of parameters, one or more of them must be included.
Example: either
titleordescriptionmust be specified.OnlyOne
Given a set of parameters, one and only one of them must be included.
Example: either
fromormessagingServiceIdmust be specified but not both.AllOrNone
Given a set of parameters, either all of them are provided or none of them is.
Example:
subject_typeandsubject_idare both specified or neither is specified.Example:
valueis present if and only iftypeis "bucket"ZeroOrOne
Given a set of parameters, at most one of can be included.
Example: specify zero or one of
forContentOwner,forDeveloper,forMine, orrelatedToVideoId:Note: There is probably an easier way to express this. Happy for feedback here.
Compatibility with OpenAPI 3.x
I believe that no functionality of OpenAPI 3.x is lost with this proposal. It should be straightforward to transform an existing
parametersarray to an equivalentparameterSchema.All reactions