Replies: 4 comments 1 reply
-
This thread is meant as a continuation of the discussions on OpenAPI validators in issue #25. |
Beta Was this translation helpful? Give feedback.
-
I did some tests with the atlassian swagger-request-validator to check if it works well with the use of oneOf like we applied it in the BelgianRemittanceInformation schema It seems to work as expected. Error when both structured and unstructured fields are present: {
"messages" : [ {
"key" : "validation.request.body.schema.oneOf",
"level" : "ERROR",
"message" : "Instance failed to match exactly one schema (matched 2 out of 2)",
"context" : {
"requestPath" : "/submitRemittanceInformation",
"apiRequestContentType" : "application/json",
"location" : "REQUEST",
"pointers" : {
"instance" : "/",
"schema" : "/components/schemas/BelgianRemittanceInformation"
},
"requestMethod" : "POST"
}
} ]
} Error when none are present: {
"messages" : [ {
"key" : "validation.request.body.schema.oneOf",
"level" : "ERROR",
"message" : "Instance failed to match exactly one schema (matched 0 out of 2)",
"additionalInfo" : [ "/oneOf/0: Object has missing required properties ([\"unstructured\"])", "/oneOf/1: Object has missing required properties ([\"structured\"])" ],
"nestedMessages" : [ {
"key" : "validation.request.body.schema.required",
"level" : "ERROR",
"message" : "Object has missing required properties ([\"unstructured\"])",
"context" : {
"pointers" : {
"instance" : "/",
"schema" : "/oneOf/0"
}
}
}, {
"key" : "validation.request.body.schema.required",
"level" : "ERROR",
"message" : "Object has missing required properties ([\"structured\"])",
"context" : {
"pointers" : {
"instance" : "/",
"schema" : "/oneOf/1"
}
}
} ],
"context" : {
"requestPath" : "/submitRemittanceInformation",
"apiRequestContentType" : "application/json",
"location" : "REQUEST",
"pointers" : {
"instance" : "/"
},
"requestMethod" : "POST"
}
} ]
} |
Beta Was this translation helpful? Give feedback.
-
For the handling of unknown properties in JSON requests, like in rule-req-valid, I think it might be possible with the workaround of creating separate request and response validators: var levelResolverResponse = LevelResolver.create().withLevel("validation.schema.additionalProperties", ValidationReport.Level.IGNORE).build();
var levelResolverRequest = LevelResolver.create().withLevel("validation.schema.additionalProperties", ValidationReport.Level.ERROR).build(); // this is actually the (non-spec compliant) default behavior of the validator
var requestValidator = OpenApiInteractionValidator.createFor(openApiFile)
.withLevelResolver(levelResolverRequest).build();
var responseValidator = OpenApiInteractionValidator.createFor(openApiFile)
.withLevelResolver(levelResolverResponse).build();
requestValidator.validateRequest(...);
responseValidator.validateResponse(...); It might be more difficult to configure when using one of the built-in integrations of the validator like the spring one. |
Beta Was this translation helpful? Give feedback.
-
In the search for having a validator that validates 1) all examples and 2) that all security scopes are defined in the securitySchemes, I found that
These are the tools that I tried:
One more that I found but did not evaluate: IBM openapi-validator |
Beta Was this translation helpful? Give feedback.
-
In this discussion, you can share your ideas or experiences about validators that you use to verify if requests and responses comply with the OpenAPI specifications of your REST APIs that follow the REST guide.
Beta Was this translation helpful? Give feedback.
All reactions