-
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
add "null value support" in spec? #229
Comments
Love to see this. Especially helpful for us with some of the datetime requirements we have. Right now I'm resorting to |
I'd like to see this too. I'm trying to define a Accepting a document with (This usecase appears to be similar to chimmelb's referenced above. I could use JSONpatch, but it is overcomplex and requires |
Having
instead of
|
@z0r1k - In your example, wouldn't it make more sense to just have the following if there's no payload? {
"status": "ok"
} To me, |
I'm in similar situation with jphastings (and chimmelb). Allowing null values is required for |
+1. Nullability is a sort of awkward thing to not have. It's definitely a distinct case from required. One is KEY must be present. One is VALUE of key must be present. |
+1. We're using the good suggestion by @enkafan too. |
+1 ran into this today, trying to validate responses in tests against Swagger schema. A suggestion for a non-breaking change: |
If you're suggesting |
On Sat, Dec 20, 2014 at 03:22:16PM -0800, Tony Tam wrote:
I bumped into this for enums (swagger-api/swagger-js#507) and was sent I restrict the information that gets returned to a user based on their Is the resistance to nulls in enums “this is too much work to |
The 'resistance' is that 2.0 is finalized and won't change. There's no resistance to include it in a newer version of the spec (just need to make sure that we agree on the details). |
On Thu, Jun 25, 2015 at 12:51:54PM -0700, Ron wrote:
The swagger 2.0 spec just defers to JSON Schema (latest!) for the enum |
|
On Thu, Jun 25, 2015 at 01:08:54PM -0700, Ron wrote:
Ah, that makes sense.
The current spec does allow it in x-* fields, but yeah, I think more So that clears me up on the 2.0 issue. How do I go about working |
This is the issue. Nothing to PR on swagger-js, it won't change we start an official process for the next iteration of the spec (and I don't know when that will be). |
On Thu, Jun 25, 2015 at 01:19:11PM -0700, Ron wrote:
No hurry, I'll just patch my copy locally until we get to it. |
Sounds good! Hopefully in the (not too far) future will have easier support for extensions (via vendor extensions) to the UI and that would make your patching easier, but can't make any promises as to when. |
Avoid 'too much recursion' errors with properties like: "species": { "type": "string", "enum": [ null, "cat", "dog" ] } The JSON Schema spec says for enums [1]: > Elements in the array MAY be of any type, including null. But they aren't supported by Swagger 2.0, because null isn't one of Swagger 2's types [2,3]. This commit gives a more obvious hint about that. It would be nice to have clarification in the spec so we could link to tidier docs than the GitHub issue too [2]. It would be nice if I could point to line numbers (or the chain of keys?) to find the broken entry in the parsed spec, but it doesn't seem like that information is available in resolveAllOf and I'm not clear enough on the larger picture here to know where that would plug in. [1]: http://json-schema.org/latest/json-schema-validation.html#anchor77 [2]: OAI/OpenAPI-Specification#229 (comment) [3]: https://github.com/swagger-api/swagger-spec/blob/master/versions/2.0.md#data-types
I run into this same issue today. Specifically to my case, this makes Swagger harder to add support for in legacy systems, where breaking the API contract is not ideal or requires great effort. +1 for supporting |
I started getting this error after using the spec converter to upgrade my working 1.2 spec to 2.0. I hate null as much as the next guy but, this is the real world, and we can't just pretend that it doesn't exist. It does and, as such, it needs to be represented. What I've always liked about swagger was that it allowed me to describe my API without trying to force me to restructure it and this seems, at least to me, to be a major and very unsettling deviation from that role in my stack. For the time being, I appear to have been given no choice but to continue using my 1.2 spec until this issue is addressed. |
Well, technically 1.2 doesn't allow it either. Just because the tools may be forgiving about it, doesn't mean it's supported. |
Something to note: |
Hi, Thx. |
Hey, it's the future! What's up April people. How are things looking today? @webron I appreciate your strong stance, and your wish to avoid another bikeshed. It seems like there has been a lot of conversation around this, and I'd be interested to see the archives. For the casual observer however, it looks like this whole "type should be a string" thing is a cruel and unnecessary deviation from JSON Schema. I've put off using Swagger for a very long time due to the whole "it's kinda JSON Schema, but an old version, and we added some bits, and ignored some bits" situation. I think Open API 3.0 would be an absolutely amazing time to resolve a bunch of these known deviations, even if it involves a bit of extra work right now. Do you have a link to a convincing argument for why (And yeah I know we can |
@philsturgeon swagger is used to generate code including in strongly typed languages so it' not possible to support multi type fields. |
@cbornet I've always felt like that should up to the implementors. There's no reason a generator for a dynamic language couldn't allow multi types, but a strongly typed language generator could restrict it. |
@natebrunette This is a slippery slope to allowing tool vendors to optionally implement anything at which point, the value of the standard is severely reduced. |
The particular case of ["string", "null"] should be OK for a strongly-typed language. The type could be tested for null or a generator could create a type called StringOrNull with an isNull() method. |
Are strongly typed languages the only use case for swagger? Dynamically typed languages are common in web programming, to put it mildly. Crippling them for the sake of strong static typing is an odd choice. If an API does not want to support clients in strongly typed languages that's a valid decision. |
I mean edit: anyway it seems this matter is still at its same status from a few months ago. Just sayin. |
Yeah, @darrelmiller, I don't think this is a conversation about "Yolo everyone can just do whatever they want.", I think @natebrunette was more suggesting that if a strongly typed language does not support union types, there are ways to handle JSON Schema's multiple types in that language that dont blow the whole thing up. Value objects are a thing. |
@philsturgeon This whole conversation is much bigger than just type being an array. JSON Schema is much more suited to validating instance documents than it is at describing the shape of things. There are so many things you can do with JSON Schema that make projecting types from it challenging. I'd rather move to using a far more constrained version of JSON schema that allows users to unambiguously describe the shape of payloads than to enable the full expressiveness of JSON Schema for validation. However, I'm not sure that the subset of JSON Schema for modelling should be defined within the scope of the OAI and instead think it should be done under the umbrella of the JSON Schema work. With all the V3 work going on I haven't had time to bring this to the JSON Schema folks yet. |
This discussion is causing flashbacks to the challenges with supporting xsd:any, xsd:anyType in the XML glory days. I'm not advocating for reintroducing the horrors of xsd:any or xsd:anyType, but maybe the equivalent of xsi:nil. |
@cipresso And the new nullable property in V3 does that https://github.com/OAI/OpenAPI-Specification/blob/OpenAPI.next/versions/3.0.md#fixed-fields-20 Admittedly not in the same way JSON Schema normally does it, but that's because we didn't want to re-open this can of worms :-) |
It is actually one of the three proposed new vocabularies, and the only one currently lacking a champion :-) We haven't really started any of these projects b/c all of the main contributors had Life Stuff(tm) going on for the last few months, but I do expect things to start moving on at least UI and Documentation soon (I see the Documentation vocabulary as focusing on the challenges of dynamic hypermedia as opposed to OpenAPI's focus on statically describable APIs). https://github.com/json-schema-org/json-schema-vocabularies |
Also I'll add (again) that the swagger field "format" would be incompatible with an array of types. |
+1 for subset of json schema for structure/shape definition. While working with FHIR standard, which also mix structure definition and validation, i came up to conclusion - that separation of this concerns is a good thing (as well as tricky;) From other side you also could provide a different place in swagger doc for |
Per swagger-api/swagger-core#459 there are cases where passing null is important. For example:
will be quite different than
[]
. See if this can be an optionThe text was updated successfully, but these errors were encountered: