swagger-request-validator-core OpenApiInteractionValidator cannot validate response which is array type

Issue #358 new
Former user created an issue

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)

  1. Jackie chen

    this is the version that is used

    <dependency>
        <groupId>com.atlassian.oai</groupId>
        <artifactId>swagger-request-validator-core</artifactId>
        <version>2.18.1</version>
    </dependency>
    

    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.

  2. Log in to comment