mac- / ratify

A Hapi plugin for validating the schema of path, query, request body, and response body params using JSON-schema
MIT License
71 stars 27 forks source link

JSON schema oneOf support for swagger #45

Closed Verlic closed 8 years ago

Verlic commented 8 years ago

Brief

Adds support to detect the oneOf property and replace the value with the first defined schema in the array. This prevents swagger from breaking as they don't support oneOf.

E.g.:

response: {
    schema: {
         oneOf: [
              { type: 'object', properties: { ... } },
              { type: 'array', items: { ... } }
         ]
   }
}

Will replace the node oneOf with the first defined schema, i.e. with { type: 'object', properties: { ... } }. This way Swagger continues to work showing the documentation for the first schema in the array.

Note: It does not support definitions. It'll only work for inline schemas as the example above.