Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swagger require all properties

Given the following schema definition (which is a valid way to define required properties):

MySchema:
 type: object
 required: [property1, property2, property3]
 properties:
  property1:
   type: integer
  property2:
   type: integer
  property3:
   type: integer

Is there a way to specify that all the properties are required?

Clarification: I'm looking for a way to say that all the properties are required, without specifying it one by one.

To be even more explicit: this does not answer my question.

like image 370
JeB Avatar asked Sep 08 '16 10:09

JeB


People also ask

How do you pass multiple parameters in swagger?

If you are trying to send a body with multiple parameters, add an object model in the definitions section and refer it in your body parameter, see below (works with editor.swagger.io):

What are swagger properties?

The properties keyword is used to define the object properties – you need to list the property names and specify a schema for each property.

How do you specify optional parameters in swagger?

You can use the default key to specify the default value for an optional parameter. The default value is the one that the server uses if the client does not supply the parameter value in the request. The value type must be the same as the parameter's data type.


1 Answers

That's the correct way to define model properties as required and I'm not aware of any other way to specify that all the properties are required.

For parameters, the required attribute is a boolean (true/false) instead of a list of required parameter's name. e.g.

name: avatar
in: formData
description: The avatar of the user
required: true
type: file
like image 83
William Cheng Avatar answered Sep 22 '22 08:09

William Cheng