RepreZen / KaiZen-OpenApi-Parser

High-performance Parser, Validator, and Java Object Model for OpenAPI 3.x
130 stars 31 forks source link

Validating Schema of the Response #40

Open LakshmananVignesh opened 7 years ago

LakshmananVignesh commented 7 years ago

Hi , I am working with the kaizen parser and open API 3.0, I am having a doubt whether there is a solution. I am writing a specification for a list of APIs in open API 3.0 and the same schema is used for testing purposes I have written the specification in YAML. My requirement is that I have to verify the response from the server is having the same schema as the one mentioned in the specification. Is there a way to verify the schema of the response with kaizen parser ...

tedepstein commented 7 years ago

Thanks @LakshmananVignesh . Totally agree that validating embedded (or referenced) examples against the provided schema is important and useful. You're describing a somewhat different validation scenario, separate from parsing, but I would like to a see a solution that address both of these use cases.

The core validation could be relatively straightforward for media type application/json, especially where the example is provided as embedded JSON, or a string that evaluates as JSON. Maybe slightly harder if the example is provided using YAML. XML might be considered in scope, but validation implementation would have to be done separately. Validating any other media type would probably be out of scope.

In the JSON case, most of the validation logic can come from a validating JSON parser, like Jackson. But it would require some specialized logic. For example:

It would make sense to factor this specialized schema validation into a library that could be used not only to validate example messages in an OpenAPI spec, but also messages returned from a service implementation, or from elsewhere. I don't know whether this library should be part of KaiZen OpenAPI Parser, or its own component, used by KZOP.

In the meantime, we'll keep this on the backlog, and look into it once more of the essential parsing and validation functionality is implemented here. If this is important to you, and you want to contribute your own implementation here, let us know.