Specify body must not be empty and it has to conform to schema


#1

Is there a way, besides specifying that a structure of a request body has to adhere to given schema, at the same time to specify that a request body must not be empty?


#2

I don’t believe so.


#3

In JSON schemas you can define “required” elements.

{
"type": "object",
"properties": {
"name": { "type": "string" },
"email": { "type": "string" },
"address": { "type": "string" },
"telephone": { "type": "string" }
},
"required": ["name", "email"]
}

But this is where json schemas get muddy… dont know how to do it on xml, and I would assume that if you use non-schema definitions (i.e. application/x-www-form-urlencoded)

/service1:
  post:
    body:
      application/x-www-form-urlencoded:
        formParameters:
          param1:
              description: Param1 description...
              required: true
              type: string
              enum: [details, method, location]
              example: details   

you can specify if each body param is required or not.