Support for Either
hi.
Would like to be able present a type of Either[Dog,Cat] (or in clojure (either Dog, Cat, Moose) in the Spec. Quite common construct in the FP land. Would be like a enum, but with values of any type.
Currently such a thing could be presented as a complex type with optional fields for all the value => at least the swagger-ui would be able to generate sample models (with all possible alternatives in place) for it. Not perfect, but ~works. Requires also special coercion in the server side to map back into Either.
http://www.scala-lang.org/api/2.11.0/index.html#scala.util.Either
https://github.com/Prismatic/schema/blob/master/test/cljx/schema/core_test.cljx#L194-L203
I just stumbled upon this issue and can barely believe that this hasn't been resolved after 2 (!) years. I am currently working on a 'real world' project implementing an API, and having to use type: any instead of the proper types with 'anyOf' is a serious limitation. I can just guess why this issue hasn't gotten as much attention as it deserves: it is not common with statically typed languages where handling optional fields causes great pain (think Javas message format classes for deserialization, Go is similar I believe). Users of those languages seem to be the main audience of Swagger/OAI tooling). As of today however there is plenty of languages (Node, Ruby, Python, browser-based JS come to mind) that have absolutely no problem with that kind of API design. It is often even preferable to an increased number of endpoints or a 'wide-table'-like schema with a lot of optional attributes (see for example the search example mentioned). So +1 from me, don't let us hipster language users down ;)
Hi guys,
after reading a lot, about this issue, I just want to throw in my vote for this to be supported soon.
If I understand all correctly it is currently not possible to state that an array must only consist of objects of a matching some given types?
My issue is simple, except in openAPI this seems not to be possible: have an array of articles that can have article-object that are either of type news or slides.
I want to use it for a teaser carousel, hence it is not possible to create something like this:
articles:
type: array
items:
$ref: "#/definitions/article"
article:
type: object
required:
- id
- headline
properties:
id:
type: number
format: int64
headline:
type: string
content:
anyOf:
- $ref: "#/definitions/news"
- $ref: "#/definitions/video"
Instead there is this discriminator Solution:
article:
type: object
discriminator: articleType
required:
- id
- headline
- articleType
properties:
id:
type: number
format: int64
headline:
type: string
articleType:
type: string
default: news
enum:
- news
- video
However, this solutions leads to false warnings, if you do not use news or video as a reference somewhere else (is already a bug-ticket somewhere).
Further, I don't get how this discriminator-Field helps? At least in the Editor, it is not even mentioned nor does anything seem to be different. And I can't see the sub-type-details through the article, only the type.
Hope anyOf will be supported soon, this feels like a gap.
@blindsteal the fact that it hasn't been addressed isn't due to sheer laziness. It's because it hasn't made sense for a variety of reasons. You can read up on the history, etc., but we don't add support for things that we don't think belong in the spec. Not saying it won't ever happen, but if we just did everything that people asked for without thinking about the impact, we'd end up with a useless ball of mud.
@fehguy @jookshub I would suggest to find some middle ground. I think discriminator was a move in the right direction, but we need to provide an improved version of it. So I would love to hear your opinion on #707.
hi @fehguy ! I didn't mean to imply it was because of laziness, sorry 😁 I was just surprised because the history of this thread actually read like 4 out of 5 people were agreeing with the endeavour.
discriminator solves a lot of my problems though, and probably the rest will vanish if #707 gets resolved :)
@blindsteal consider joining the convo on #707 with some example use cases that discriminator may help with
Tackling PR: #741
allOf, oneOf, not will be supported in 3.0 spec. Approval by @OAI/tdc in comments, implementation details will be in this PR:
https://github.com/OAI/OpenAPI-Specification/pull/741
Changes are in, closing as done!
It's a shame this never made it to swagger 2. Makes it hacky to describe JSONAPI interfaces where lists can be of mixed types (for instance, includes).