allOf Not respecting additionalProperties false

Issue #279 resolved
Former user created an issue

We are using the followig dependency in build.gradle:

implementation group: 'com.atlassian.oai', name: 'swagger-request-validator-springmvc', version: '2.10.0'

In our openapi yaml file (version 3.0) we have several component schemas defined as follows:

components:

  schemas:

    DwmAccount:
      type: object
      properties:
        label:
          type: string

    DwmEmailAccountPost:
      allOf:
        - $ref: '#/components/schemas/DwmAccount'
        - type: object
          properties:
            email:
              type: string
              format: email
          required:  [ label, email ]

The above validates perfectly against a request body that looks like:

{
    "email": {
        "label": "label",
        "email": "email address"
    }
}

However, we don't want additional properties to be allowed so if we add that we have the following:

    DwmEmailAccountPost:
      allOf:
        - $ref: '#/components/schemas/DwmAccount'
        - type: object
          properties:
            email:
              type: string
              format: email
          required:  [ label, email ]
          additionalProperties:  false

Which cause validation to fail. The error message is:

#!

[Path '/email'] Object instance has properties which are not allowed by the schema: [\"label\"]

Which is clearly not true.

Below is our config, Note with LevelResolverFactory.withAdditionalPropertiesIgnored() :

private OpenApiValidationInterceptor initInterceptor(final Resource apiSpecification) throws IOException {
    final var specResource = new EncodedResource(apiSpecification, "UTF-8");
    final var validator = OpenApiInteractionValidator
            .createForInlineApiSpecification(IOUtils.toString(specResource.getReader()))
            .withLevelResolver(LevelResolverFactory.withAdditionalPropertiesIgnored())
            .build();
    this.validationInterceptor = new OpenApiValidationInterceptor(validator);
    return validationInterceptor;
}

Comments (2)

  1. Log in to comment