0

I am trying to find a json schema which should act as a "envelope" for all other schemas in the system. It should contain some basic properties and then the actual other schema. It should be possible to validate the outer schema as well as the actual schema inside the "envelope" separately. The idea is that in a system all schema should be wrapped in the schema.

For a better visualisation here is an example json:

{
"timestamp": "452366",
"version": "2424",
"actualData":{
    "schemaId": "http://someDomain.com/schemas/bodyschema123",
    "dynamicData1":"foobar",
    "dynamicData2":"barfoo",
    // and so on

    }  
}

How should my schema look like especially when I also want to have the option to only validate the header and/or the body but also have one validation for both.

zlZimon
  • 2,334
  • 4
  • 21
  • 51
  • I think you may be confused about something. JSON Schema does not have the context of an HTTP request. JSON Schema is often used for API payloads, such as in OpenAPI, but JSON Schema itself doesn't know about any request or response. If you wanted, you could construct your request into JSON and pass it to a validator in the structure you want to validate. – Relequestual Jun 15 '20 at 08:26
  • No I just used the header / body analogy to visualize my problem. I just need a schema where one part is always the same and should be validated but one part is another schema which can be any schema and should be validated in a second step. Since this apparently causes confusion I will rewrite it – zlZimon Jun 15 '20 at 11:01
  • In which case, it sounds like what you want is quite simple, but I'll wait for you to update your question first. – Relequestual Jun 15 '20 at 11:05
  • See also https://stackoverflow.com/questions/9989135/when-in-my-rest-api-should-i-use-an-envelope-if-i-use-it-in-one-place-should-i and 'let's make SOAP but, like, with JSON' https://stackoverflow.com/questions/12806386/standard-json-api-response-format – Pete Kirkham Jun 15 '20 at 11:21
  • yea, well I think I am not sure how the schema should look like. And for the validation part I guess there has to be custom code which first validates the while thing and then graps the `actualData` and validates that seperatly? – zlZimon Jun 15 '20 at 13:50
  • So my problem is how the `actualData` is defined in the schema since it can be any other schema itself, if that makes sense. – zlZimon Jun 16 '20 at 10:17

0 Answers0