Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swagger 2.0 Anyof

What is the equivalent of anyof in Swagger version 2.0, Please tell me how to update my json file because I want to upgrade my documentation from swagger 1.0 to 2.0.

Thank You for your Help.

like image 366
Mohcine Aterhzaz Avatar asked Jan 18 '16 20:01

Mohcine Aterhzaz


People also ask

What is anyOf in Swagger?

anyOf – validates the value against any (one or more) of the subschemas.

What is anyOf in JSON Schema?

allOf: (AND) Must be valid against all of the subschemas. anyOf: (OR) Must be valid against any of the subschemas. oneOf: (XOR) Must be valid against exactly one of the subschemas.

How do you get the request body required in Swagger?

requestBody, content and Media Types content lists the media types consumed by the operation (such as application/json ) and specifies the schema for each media type. Request bodies are optional by default. To mark the body as required, use required: true .


2 Answers

I don't think there is one and it feels like a big shortcoming. It's definitely not mentioned in the Schema Object portion of the specification. They call out the elements there that have been adopted from the JSON Schema and anyOf isn't among them:

The following properties are taken directly from the JSON Schema definition and follow the same specifications:

  • $ref - As a JSON Reference
  • format (See Data Type Formats for further details)
  • title
  • description (GFM syntax can be used for rich text representation)
  • default (Unlike JSON Schema, the value MUST conform to the defined type for the Schema Object)
  • multipleOf
  • maximum
  • exclusiveMaximum
  • minimum
  • exclusiveMinimum
  • maxLength
  • minLength
  • pattern
  • maxItems
  • minItems
  • uniqueItems
  • maxProperties
  • minProperties
  • required
  • enum
  • type

The following properties are taken from the JSON Schema definition but their definitions were adjusted to the Swagger Specification. Their definition is the same as the one from JSON Schema, only where the original definition references the JSON Schema definition, the Schema Object definition is used instead.

  • items
  • allOf
  • properties
  • additionalProperties

I think the closest thing is the discriminator field, but that means you've got to structure your output to accommodate Swagger.

like image 164
drewish Avatar answered Sep 22 '22 09:09

drewish


anyOf and oneOf are now supported in OpenAPI Specification 3.0 (released on July 26, 2017).

like image 26
Helen Avatar answered Sep 19 '22 09:09

Helen