Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swagger 2.0 - how to make "one or the other" parameter required?

Tags:

swagger

I have a swagger 2.0 resource defined below. How can I make "param1 or param2" required? Caller has to pass either param1 or param2.

/some/res: put:   summary: some resource   responses:     200:       description: Successful response       schema:         $ref: '#/definitions/SomeResponse'   parameters:     - name: param1       type: string       description: param1       in: formData       required: false     - name: param2       type: string       description: param2       in: formData       required: false 
like image 680
Vineet Bhatia Avatar asked Apr 17 '15 20:04

Vineet Bhatia


People also ask

How do you make parameter optional in Swagger?

Required and Optional Parameters By default, Swagger treats all request parameters as optional. You can add required: true to mark a parameter as required. Note that path parameters must have required: true , because they are always required. description: Numeric ID of the user to get.

How do you specify a path parameter in Swagger?

Given that path parameter must be required according to the OpenAPI/Swagger spec, you can consider adding 2 separate endpoints with the following paths: /get/{param1}/{param2} when param2 is provided. /get/{param1}/ when param2 is not provided.

What is additional properties in Swagger?

The additionalProperties keyword specifies the type of values in the dictionary. Values can be primitives (strings, numbers or boolean values), arrays or objects. For example, a string-to-object dictionary can be defined as follows: type: object.


1 Answers

OpenAPI (fka Swagger) Specification does not support conditional or mutually exclusive parameters (of any type).

There is an open feature request:
Support interdependencies between query parameters

like image 195
Ron Avatar answered Oct 11 '22 13:10

Ron