0

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.

TechiRik
  • 1,893
  • 6
  • 27
  • 37
  • Possible duplicate of [Swagger 2.0: what schema to accept any (complex) JSON value](https://stackoverflow.com/questions/32841298/swagger-2-0-what-schema-to-accept-any-complex-json-value), [Freeform subobject in Swagger](https://stackoverflow.com/q/41606152/113116) and [How to receive a dynamic response in a Swagger spec](https://stackoverflow.com/q/35782175/113116). – Helen Oct 05 '18 at 20:29

1 Answers1

0

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).

vearutop
  • 3,924
  • 24
  • 41