-
Notifications
You must be signed in to change notification settings - Fork 9.1k
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
Clarify allowEmptyValue
#1573
Comments
This is a good point. I'm also interested what should happen if Does this say "it can be 'empty', but if it's not, it must be at least 10 characters long"? |
Just reading this section of the spec, I have to say I'm not 100% certain of the intent, but here's what I think is a likely interpretation: I think In the first form, Unless the But OpenAPI doesn't specify what kinds of values should be serialized as an empty-valued query parameter, nor what representation an empty-valued parameter should be deserialized to. So this is application-defined. I suspect this is because different type systems, in different programming languages, can have many different value representations that could be interpreted as "empty." The serialization style examples include a JSON string, an object, and an array. But I don't think these are intended to specify a literal mapping of JSON values to serialized parameters. A mapping like that wouldn't be very useful in the usual case, where parameter values are directly read, written, or mapped to an in-memory representation, entirely dependent on the programming language. JSON isn't part of the picture here, so a direct JSON mapping isn't meaningful, in the concrete sense. So I interpret those JSON values in the style examples as generic placeholders for what we commonly think of as strings, objects, and arrays, as common constructs used in many programming languages. It might be helpful to add an "empty" example there too. But in that case, if I understand the intent correctly, the spec needs to be clear that it is not prescribing what should constitute an empty value. A given API might expect certain query parameters to always be empty-valued. It might be nice if OpenAPI allowed us to specify this explicitly, but it doesn't. That expectation would have to be captured in a parameter Another API might allow certain query parameters to have empty or non-empty values. In the case of an empty (omitted) parameter value, the So I can attempt an answer to the specific questions here:
IIUC, this is application-defined.
Yes. If the parameter appears without a value, then schema constraints are ignored. If it has a value, the value must conform to the schema. It would be great if one of the authors of this part of the spec could please confirm or correct my interpretation here... |
This seems to make lots of sense to me. I.e. in a nutshell:
If this is the intent, should it be explicitly stated in the specification? A follow-up question is: can a |
So here's the clarification, and we can add more information in the spec if needed.
Combining As for the follow-up question: yes, a |
@webron , your answer seems to conflict with what's shown in the style examples table. There, we can see that an empty-valued parameter with |
You're right, only the conflict is worse. If you read the description of |
I did some research into this, and here's the history, as far as I can piece it together:
|
@webron, in light of the above history: I guess my interpretation was not far off from the original intent. It does seem that when
If you can point us to the TSC conversation, it would help to see that. I honestly don't understand the claim that name-only parameters don't exist, when clearly they do exist in the wild. We can ask whether it's good practice. And we can ask what's the best way to model them. But "don't exist" isn't making much sense to me. I don't have a strong opinion that name-only parameters are good practice. But there is one significant argument for allowing them: It means that OpenAPI can be used to describe existing APIs that use these parameters.
Does that specifically mean a zero-length string, as opposed to an empty array or empty object? And in that case, is OpenAPI saying that conforming implementations SHOULD or MUST interpret an empty parameter, in the specified syntax (from the 'empty' column in the style table) as an empty string?
In that case:
This seems like it needs to be given some more thought... |
Those two statements lead to: However |
I still think there's fundamental confusion about the original intent of Here's how I see it:
|
RFC 6570 is explicit about whether the
The equal sign is included only for query string parameters. As far as I understood, |
I don't think this would have made much sense, given that OpenAPI 2.0 Parameter Objects already had I've attempted to pull together the history, and the evidence seems to suggest that
There are other possible semantics:
It might be most accurate to say that |
I like the alignment with RFC 6570. RFC 6570 seems to model parameter values only in terms of strings, string arrays, and Map<string, string> associative arrays. So mapping OpenAPI's schema object to RFC 6570 seems to require some extra interpretation, and I'm not sure (yet) whether this is fully captured in the "style" table in the spec. And of course, adopting serialization rules like RFC 6570 clashes with options like |
@tedepstein Yes, based on your comment about On the other hand, maybe we do want to flag style query parameters even though, RFC6570 doesn't. At which point, maybe allowEmptyValues can keep that meaning. If you are available for the TSC meeting, we can discuss it further. I'm sure @webron will have some light to shine on the subject. |
@darrelmiller although these relate to OAS 2.0 - two (and only two) Microsoft Azure API definitions specifiy
Perhaps reaching out to find the intent of using the flag in these cases might be an interesting data point? Only two other API definitions across the whole of APIs.guru (1,400+ definitions) use |
Thanks @MikeRalphson. APIs.guru is an awesome resource. Very helpful in situations like this. I looked at these: applicationinsights/resource-manager/microsoft.insights/stable/2015-05-01/favorites_API`
This looks like an Unassigned Value or Unspecified Value use case, though it's not clear which one. With Unassigned Value, sending an empty value would override the default value of "other" with null or empty string. With Unspecified Value, it would be the equivalent of omitting the parameter altogether, and therefore applying the default value of "other." trafficmanager/resource-manager/Microsoft.Network/preview/2017-09-01-preview/trafficmanageranalytics
Probably the Unspecified Value use case, equivalent to omitting the parameters. |
Apologies to @webron, who has apparently been through a couple of frustrating episodes with After today's call, and taking into account the apparent low usage as reported in the APIs.guru directory, it seems like we really should deprecate this feature. Aside from having a somewhat misleading name, and seemingly conflating at least two different use cases, it clashes with RFC 6570 because it tries to dictate syntax independently of the schema and serialization rules. Whether or not we deprecate it, we should agree on its meaning, and update the spec to clarify accordingly. I was arguing for a more permissive interpretation, in line with the original spec as I understood it. But if we're deprecating this anyway, we probably want to stick with the narrower definition that was intended in the 3.0 revision, and just add language to make that meaning more clear. If everyone agrees with the following plan, I'll open a PR with the required changes:
|
In PR #1573, targeted for the 3.0.2 patch revision, we have made use of We can revisit in OpenAPI 4.x if there's a good use case. |
Thanks, @tedepstein! Closing. |
it's a crazy spec) |
From the specification it is a little ambiguous what the
allowEmptyValue
entails, notably whatempty
means:query
parameter when its value is oftype: string
? Or would0
,false
,[]
or{}
qualify asempty
when aquery
parameter is of anothertype
?The text was updated successfully, but these errors were encountered: