Search code examples
xsdjsonschemaapi-designraml

How to include an XML schema (.xsd) in a JSON schema?


I want to define a JSON API response using JSON Schema.

Embedded in part of the API response is a complete, well-formed, schema valid XML string. The XSD of this XML string is a given.

Two part question:

  1. How do I include the XSD in the JSON Schema such that the JSON Schema will also require the XML string to be schema valid in order for the whole API response to be valid?

  2. If this is not possible, does anyone have another suggestion how to include the XSD at least in the specification? I'm working in RAML 0.8.


Solution

  • How do I include the XSD in the JSON Schema such that the JSON Schema will also require the XML string to be schema valid in order for the whole API response to be valid?

    You cannot. The only thing you can do is validate the JSON and then at a later point extract the XML and validate it separately.

    If this is not possible, does anyone have another suggestion how to include the XSD at least in the specification? I'm working in RAML 0.8.

    I've only used Swagger, not RAML. Swagger is also based on JsonSchema.

    The only thing you can do here is to include a detailed specification that the contained XML should be compliant against such-and-such an XSD. You can do this by using the "description" functionality in swagger (or equivalent if it exists in RAML). This allows you to create a description (which supports markdown) and attach it to any element in the definition