apigee-127 / swagger-tools

A Node.js and browser module that provides tooling around Swagger.
MIT License
702 stars 373 forks source link

Issue with using `discriminator` #590

Closed DavidFaizulaev closed 5 years ago

DavidFaizulaev commented 5 years ago

Hello,

I'm trying to use discriminator but when the validation occurs, it gets the discriminator name, and that's it, I does not get the relevant object.

For example

  payment_method:
    type: object
    required:
    - payment_method_type
    discriminator: payment_method_type
    properties:
      payment_method_type:
        type: string
        enum:
        - Crypto
        - CreditCard

The schema gets payment_method_type as String - for example it equals Crypto but it does not get the definition of Crypto and compares the request to this object.

Please advise.

whitlockjc commented 5 years ago

discriminator support was never implemented. #241 is for tracking this.

DavidFaizulaev commented 5 years ago

@whitlockjc , thank you for the reply, do you believe adding support for discriminator is possible in a relatively short amount of time? I saw that the project is using schema from 'http://json-schema.org/draft-04/schema' and that discriminator is configured as a String, do you know of any json-schema that has the discriminator configured properly?

Also, I saw the sway project, does it have support for discriminator?

whitlockjc commented 5 years ago

The discriminator in OAS is very complex to implement. It seems simple but since any model can have a discriminator, you have to walk a schema and its referenced/sub schemas and basically turn them into an anyOf. It's quite complex. sway is where the current work is happening since swagger-tools is deprecated (See #335).