I have the following need: Input is a JSON object got from a messaging (or Kafka) queue. My need to is to validate the above JSON message against a Swagger specification. I am not able to find any reliable solution to converting swagger to JSON schema, and so I decided to see if could use the com.atlassian.oai.validator for achieving this.
However, the challenge is that in just using the core validator, we are forced to formulate a request/response in the strict sense, but all I want is a JSON schema like validation (primarily the JSON structure, data contents, etc.). How can I achieve this using this validator?
Sample code is as below:
private static final String SWAGGER_JSON_URL = "http://petstore.swagger.io/v2/swagger.json";
String inputJSON = "{"
+ " \"id\": 1,"
+ " \"category\": {"
+ " \"id\": 0,"
+ " \"name\": \"string\""
+ " },"
+ " \"name\": \"doggie\","
+ " \"photoUrls\": ["
+ " \"string\""
+ " ],"
+ " \"tags\": ["
+ " {"
+ " \"id\": 2,"
+ " \"name\": \"string\""
+ " }"
+ " ],"
+ " \"status\": \"available\""
+ "}";
OpenApiInteractionValidator validator =
OpenApiInteractionValidator.createFor(SWAGGER_JSON_URL).build();
How can I call the validator.validate and provide the inputJSON as a parameter?
I tried the following by creating a simpleresponse to see if that would help, but again I did not find a way to call the validateResponse method as it was insisting on many parameters that I do not have:
final Response response = SimpleResponse.Builder.ok()
.withContentType("application/json")
.withBody(inputJSON)
.build();
ValidationReport report = validator.validateResponse(response);
Am I using the wrong thing to achieve my want? Is there another solution for achieving this?