swagger-request-validator-core OpenApiInteractionValidator cannot validate response which is array type
Issue #358
new
The validation does not fail when there is an invalid schema in JSON response of array type:
E.g.
"\/endpoint": {
"get": {
"summary": "Summary of the endpoint",
"deprecated": false,
"produces": ["application\/json"],
"operationId": "getDataWithGET",
"responses": {
"200": {
"schema": {
"type": "array",
"items": {
"$ref": "#\/definitions\/Data_Sample"
}
},
"description": "OK"
}
},
"tags": ["Sample Endpoints"]
JSONObject jsonObject = readSpecUrll( specUrl );
String schema = removeParams( jsonObject.toString(), map );
final OpenApiInteractionValidator validator = OpenApiInteractionValidator.createForInlineApiSpecification( schema ).withWhitelist( whitelist() ).build();
final com.atlassian.oai.validator.model.Response response = SimpleResponse.Builder.status( 200 )
.withBody(
"[{"invalid":"sample"}]" )
.withContentType( "application/json" )
.build();
final ValidationReport report = validator.validateResponse( path, Request.Method.GET, response );
if( report.hasErrors() ) { << Validation does not fail
System.out.println( SimpleValidationReportFormat.getInstance().apply( report ) );
}
Comments (3)
-
-
@James Navin
Could you please have a look at this later when you have time?
Thank you.
-
I met same issue. Can you help look at this?
- Log in to comment
this is the version that is used
the code above can detect if the response is not an array but it does not fail when there is an invalid parameter which is not supported in the swagger specification. this happens only the array type, while it works fine for object type.