Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

x-extendedDiscriminator does not work in redoc 2.X #496

Closed
jeremycohensolal opened this issue May 16, 2018 · 4 comments · Fixed by #549
Closed

x-extendedDiscriminator does not work in redoc 2.X #496

jeremycohensolal opened this issue May 16, 2018 · 4 comments · Fixed by #549

Comments

@jeremycohensolal
Copy link

Hello
I have a reduce case with x-extendedDiscriminator which works well on 1.X release but doesn't work anymore on 2.X release.

Here is the yaml file:

swagger: '2.0'
info:
  version: 1.0.0
  title: Test API

host: test.api.int.com
basePath: /v2
schemes:
  - https
securityDefinitions:
  basic:
    type: basic
consumes:
  - application/json
produces:
  - application/json

paths:
  '/transactions/{id}':
    get:
      summary: Get a transaction by ID
      description: Get a `Transaction` object by ID
      parameters:
        - name: id
          in: path
          description: The transaction ID
          required: true
          type: string
          format: uuid
      responses:
        '200':
          description: The Transaction
          schema:
            $ref: '#/definitions/Transaction'

parameters:

definitions:
  Transaction:
    type: object
    properties:
      id:
        type: string
        example: A11234
        pattern: '[A-Z][0-9]{1,32}'
        readOnly: true
      account_id:
        type: string
        example: 05a2106b-92a4-4ee3-a6a3-c32f8b609de1
        format: uuid
        readOnly: true
      operation_type:
        type: string
        enum:
          - payment
          - refund
        example: payment
      payment_method:
        $ref: '#/definitions/PaymentMethod'

  PaymentMethod:
    type: object
    x-extendedDiscriminator: type
    properties:
      type:
        description: The type of Payment Method used for Transaction
        type: string

  paymentMethodVisa:
    description: A visa
    allOf:
      - $ref: '#/definitions/PaymentMethod'
      - properties:
          prop1:
            type: string
            description: A custom prop
            enum:
              - type1
              - type2
      - properties:
          type:
            type: string
            enum:
              - visa

  paymentMethodMastercard:
    description: A mastercard
    allOf:
      - $ref: '#/definitions/PaymentMethod'
      - properties:
          prop1:
            type: string
            description: A custom prop
            enum:
              - type3
              - type4
      - properties:
          type:
            type: string
            enum:
              - mastercard
  paymentMethodAmex:
    description: A amex
    allOf:
      - $ref: '#/definitions/PaymentMethod'
      - properties:
          prop1:
            type: string
            description: A custom prop
            enum:
              - type5
      - properties:
          type:
            type: string
            enum:
              - amex

Here is my html page displaying the yaml

<!DOCTYPE html>
<html>
<head>
</head>
<body>

  <redoc
      spec-url="openapi.yaml"
      lazy-rendering="true"
      expand-responses="200,201,204"
      required-props-first="true" ></redoc>
  <script src="https://cdn.jsdelivr.net/npm/redoc@next/bundles/redoc.standalone.js"></script>
  <!-- script src="https://rebilly.github.io/ReDoc/releases/latest/redoc.min.js"></script -->

</body>
</html>

As you can see I use the latest version of 2.X and 1.X.

Here is the result with 1.X

image

So it works just well.

And here is the same yaml with latest 2.X redoc version:

image

In both case, I don't have any warnings.

@RomanHotsiy
Copy link
Member

@nemenemsrouge thanks for issue report.

Most likely x-extendedDiscriminator will be deprecated in ReDoc 2.x.
I will backport how it is done in OpenAPI 3.0. It will look like:

x-discriminator:
  propertyName: type
  mapping:
    visa: "#/definitions/paymentMethodVisa"
    mastercard: "#/definitions/paymentMethodMastercard"
    amex: "#/definitions/paymentMethodAmex"

I will try to implement this till the end of the week.

@jeremycohensolal
Copy link
Author

Thank you very much!
Redoc is really an awesome tool (the best I think in all the openapi world) :)

@RomanHotsiy
Copy link
Member

Related issue: Mermade/oas-kit#70

RomanHotsiy added a commit that referenced this issue May 29, 2018
@leonardehrenfried
Copy link
Contributor

leonardehrenfried commented Jun 22, 2018

Is this supposed to work as of today? I'm using 2.0.0-alpha-24 but I can't get the dropdowns to show up.

@nemenemsrouge Does it work for you?

I'm using the following yml:

swagger: '2.0'
info:
  version: 1.0.0
  title: Test API

host: test.api.int.com
basePath: /v2
schemes:
  - https
securityDefinitions:
  basic:
    type: basic
consumes:
  - application/json
produces:
  - application/json

paths:
  '/transactions/{id}':
    get:
      summary: Get a transaction by ID
      description: Get a `Transaction` object by ID
      parameters:
        - name: id
          in: path
          description: The transaction ID
          required: true
          type: string
          format: uuid
      responses:
        '200':
          description: The Transaction
          schema:
            $ref: '#/definitions/Transaction'

parameters:

definitions:
  Transaction:
    type: object
    properties:
      id:
        type: string
        example: A11234
        pattern: '[A-Z][0-9]{1,32}'
        readOnly: true
      account_id:
        type: string
        example: 05a2106b-92a4-4ee3-a6a3-c32f8b609de1
        format: uuid
        readOnly: true
      operation_type:
        type: string
        enum:
          - payment
          - refund
        example: payment
      payment_method:
        $ref: '#/definitions/PaymentMethod'

  PaymentMethod:
    type: object
    x-discriminator:
      propertyName: type
      mapping:
        visa: "#/definitions/paymentMethodVisa"
        mastercard: "#/definitions/paymentMethodMastercard"
        amex: "#/definitions/paymentMethodAmex"
    properties:
      type:
        description: The type of Payment Method used for Transaction
        type: string

  paymentMethodVisa:
    description: A visa
    allOf:
      - $ref: '#/definitions/PaymentMethod'
      - properties:
          prop1:
            type: string
            description: A custom prop
            enum:
              - type1
              - type2
      - properties:
          type:
            type: string
            enum:
              - visa

  paymentMethodMastercard:
    description: A mastercard
    allOf:
      - $ref: '#/definitions/PaymentMethod'
      - properties:
          prop1:
            type: string
            description: A custom prop
            enum:
              - type3
              - type4
      - properties:
          type:
            type: string
            enum:
              - mastercard
  paymentMethodAmex:
    description: A amex
    allOf:
      - $ref: '#/definitions/PaymentMethod'
      - properties:
          prop1:
            type: string
            description: A custom prop
            enum:
              - type5
      - properties:
          type:
            type: string
            enum:
              - amex

RomanHotsiy pushed a commit that referenced this issue Jun 28, 2018
This includes the fix for x-discriminator. 

Fixes #496.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants