Validation of the combined schemas

Issue #157 invalid
Alexander Khadzhinov created an issue

Suppose we have the following schemas:

openapi: "3.0.1"
components:
  schemas:
    BaseEntity:
      type: object
      description: Base entity fields
      properties:
        createdAt:
          description: UTC date and time when entity created
          type: string
          format: iso8601
          readOnly: true
          nullable: false

    Application:
      type: object
      description: application
      properties:
        id:
          description: Application id
          type: string
          format: uuid
          readOnly: true
          nullable: false
        title:
          description: Application title
          type: string
          nullable: false
      allOf:
        - $ref: '#/components/schemas/BaseEntity'
paths:
  /applications:
    get:
      responses:
        200:
          description: Paged list of applications
          content:
            application/json:
              schema:
                type: object
                properties:
                  content:
                    type: array
                    items:
                      $ref: '#/components/schemas/Application'
                allOf:
                  - $ref: '#/components/schemas/PagedResponse'

Swagger UI shows this combined schemas correctly, but when I use swagger-request-validator-mockmvc for validating the controller answer I receive the following errors:

  • Object instance has properties which are not allowed by the schema: [\"first\",\"last\",\"number\",\"numberOfElements\",\"pageable\",\"size\",\"sort\",\"totalElements\",\"totalPages\"]"
  • "/allOf/0: Object instance has properties which are not allowed by the schema: [\"content\"]"
  • [Path '/content/0'] Object instance has properties which are not allowed by the schema: [\"createdAt\",\"deleted\"]
  • "/components/schemas/Application/allOf/0: Object instance has properties which are not allowed by the schema: [\"appType\",\"customer\",\"id\",\"title\"]"

As I understood validator validates each schema independently, but not whole combined schema, right? If I want to reuse properties between different objects what should I do?

Comments (3)

  1. James Navin

    Hi Alexander. This looks a lot like the known additionalProperties problem. Can you please take a look at the FAQ (in the docs folder) and try disabling the additionalProperties validation as described there.

  2. Alexander Khadzhinov reporter

    Hi James, Yes, with validation.schema.additionalProperties=IGNORE in swagger-validator.properties the problem is gone. Thank you. I guess we can close this issue.

  3. Log in to comment