swagger-parser icon indicating copy to clipboard operation
swagger-parser copied to clipboard

Dereference discriminator mappings

Open Gi60s opened this issue 5 years ago • 1 comments

I've noticed that the swagger-parser doesn't dereference discriminator mappings. I realize that is not part of the JSON schema spec, but it is part of the OpenAPI spec. Are there plans to add this functionality?

Here is an example. The $ref is dereferenced just fine, but the mappings are ignored.

I realize this would probably break a lot of libraries that are using this tool, so if it's implemented I think an option to enable or disable would be best.

openapi: '3.0.0'
info:
  title: ''
  version: ''
paths:
  /:
    get:
      responses:
        200:
          description: ''
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/OneOf'
components:
  schemas:
    OneOf:
      oneOf:
        - $ref: '#/components/schemas/A'
        - $ref: '#/components/schemas/B'
      discriminator:
        propertyName: type
        mapping:
          A: '#/components/schemas/A'
          B: '#/components/schemas/B'
    A:
      type: object
      properties:
        type:
          type: string
        a:
          type: boolean
    B:
      type: object
      properties:
        type:
          type: string
        b:
          type: boolean

Gi60s avatar Oct 28 '19 14:10 Gi60s

You can't really dereference them. Since discriminator only works if you have referenceable schemas, the right way to go would be to drop discriminator during dereferencing, otherwise the resulting OpenAPI doc would be invalid.

letmaik avatar Oct 15 '20 12:10 letmaik