OpenAPI-Specification
OpenAPI-Specification copied to clipboard
Error 'required' should not have fewer than 1 items
Hi, Is there any way to make the body optional in Swagger v2?
I am getting error as the required array is empty in the "Formatting" definition:
"Formatting": { "required": [], "type": "object", "properties": { "code": { "type": "string" } } },
The endpoint does not necessarily need any body. hence, there are no required fields as such.

If all properties are optional, do not include the required keyword.
"Formatting": {
"type": "object",
"properties": {
"code": {
"type": "string"
}
}
},
OpenAPI 2.0 uses a version of JSON Schema where the required list, if specified, cannot be empty so you would only include this keyword if a schema has at least 1 required property.
An empty list required: [] is allowed in later JSON Schema versions, such as the one that's used by default in OpenAPI 3.1.
Thanks @hkosova. @sourabhagrawal23 please chase if the above didn't answer your question.