Validating schema that uses discriminator in swagger 2.0 not working

Issue #242 new
Former user created an issue

I am using Swagger 2.0 with discriminator.

swagger: '2.0'
info:
  title: test
  version: '1.0'
produces:
  - application/json
paths:
  /test:
    post:
      operationId: test
      consumes:
      - application/json
      parameters:
      - name: param
        in: body
        schema:
          $ref: '#/definitions/Base'
      responses:
        '202':
          description: Accepted
definitions:
  Base:
    type: object
    discriminator: type
    required: [name, type]
    properties:
      name:
        type: string
      type:
        type: string

  First:
    allOf:
    - $ref: '#/definitions/Base'
    - type: object
      required: [first]
      properties:
        first:
          type: string

  Second:
    allOf:
    - $ref: '#/definitions/Base'
    - type: object
      required: [second]
      properties:
        second:
          type: string

  Third:
    type: object
    required: [third]
    properties:
      third:
        type: string

I am validating a request object:

{
    "name": "name",
    "type": "First",
    "first": "first"
}

But I get an exception:

[ERROR - Failed validation of discriminator schema '/components/schemas/First': []]

I would expect there will be no exception.

I would also expect the path to the definition to be 'definitions/First' instead of '/components/schemas/First'.

If I change type to "Third", I get this validation report, which indicates that allowed discriminators were recognized correctly:

[ERROR - Discriminator field 'type' value 'Third' is not the name of a valid definition (possible values: [Second, First]): [], ERROR - Failed validation of discriminator schema '/components/schemas/Third': []]

If I change type to "Fourth", I get this validation report, which indicates, it fails internally for unknown discriminator values:

[ERROR - An error occurred during schema validation - com.google.common.util.concurrent.UncheckedExecutionException: java.lang.NullPointerException.: []]

Comments (0)

  1. Log in to comment