I am trying to define an API using Swagger 2.0. In my model I have some object which have optional attributes, so I am trying to insert the Swagger tag "required:false".
When I insert the "required" tag, I am getting an error in the editor and I can't figure why..
My Swagger definition is:
definitions:
Error:
type: object
properties:
code:
type: integer
message:
type: string
fields:
type: string
This is perfectly working. Now I want to specify that the 'message' parameter (for example) is optional. So I try the following:
definitions:
Error:
type: object
properties:
code:
type: integer
message:
type: string
required: false
fields:
type: string
And now I have an error in the Swagger Editor:
Swagger Error
Expected type array but found type boolean
Error details are:
Details
Object
code: "INVALID_TYPE"
message: "Expected type array but found type boolean"
path: Array [5]
0: "definitions"
1: "Error"
2: "properties"
3: "message"
4: "required"
level: 900
type: "Swagger Error"
description: "Expected type array but found type boolean"
lineNumber: 41
Lines:
[40] message:
[41] type: string
[42] required: false
Did someone have an idea about what I am doing wrong ?
If only code and fields are mandatory you can do something like:
definitions:
Error:
type: object
required: [code, fields]
properties:
code:
type: integer
message:
type: string
fields:
type: string