How to define schema arbitrary JSON object?

584 views Asked by At

I am trying to define a API using OAS v2 that will return a payload along with some metadata.

In other words, the response to the API will be:

{
  "metadata":[
   {
     "key" :"key1",
     "value": "value1"
   }
  ],
  "payload": {Valid JSON}
}

The payload can be anything, and different for different scenarios, the only constraint being it will be a valid JSON format. So, at this point in time, I would like to define it just as a JSON object without defining the field level details.

How can I do that in OAS2/JSON schema?

Thanks in advance.

1

There are 1 answers

0
vearutop On

In this case you can use an empty schema ({}) for payload.

JSON Schema relies on valid JSON value and you won't be able to supply it if your response is a malformed JSON.

If payload value is malformed, whole response will not be a valid JSON.

In other words, this issue is out of JSON Schema scope, but rather in scope of your response decoder (that should fail on malformed response body).