Usage of the validator in a pure validation scenario

Issue #168 resolved
Canon created an issue

Hi, Outside the realm of Spring or test, assuming I want to use the validator to validate a JSON retrieved from say, a rabbit mq message, against a swagger spec, how do I go about doing so? I am not sure of the entry point - as far as I understand, I can directly use the swagger-request-validator-core in my pom and proceed to build a validator and call the validate method to get the report. But from the readme page, I dont see what the request and the response would be - my input JSON is the contents of a message and I want to validate that against a swagger URL.

If there is any sample I can refer to, it would be splendid!

UPDATE : I tried to build a SimpleRequest/SimpleResponse but that does not serve my purpose as there is no REST call. I have a String rep of a JSON that I want to validate against my validator that I constructed as below: OpenApiInteractionValidator.createFor(SWAGGER_JSON_URL).build();

Is there any way to achieve the above? Any help would be most appreciated :)

Ananth

Comments (5)

  1. James Navin

    I don’t think the swagger-request-validator is the best tool for what you’re describing. You could probably make it work by having a dummy request path in your API spec for these async messages, and then crafting a SimpleRequest instance with the message payload + that dummy request path, but it feels like the wrong fit.

    My recommendation would probably be to use JSON schema validation directly (something like https://github.com/java-json-tools/json-schema-validator) or look at what tooling exists for the recent AsyncAPI initiative.

  2. Log in to comment