OpenAPI-Specification icon indicating copy to clipboard operation
OpenAPI-Specification copied to clipboard

Error 'required' should not have fewer than 1 items

Open sourabhagrawal23 opened this issue 3 years ago • 1 comments
trafficstars

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.

image

sourabhagrawal23 avatar Jul 27 '22 07:07 sourabhagrawal23

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.

hkosova avatar Aug 03 '22 13:08 hkosova

Thanks @hkosova. @sourabhagrawal23 please chase if the above didn't answer your question.

MikeRalphson avatar Feb 21 '23 12:02 MikeRalphson