Add support of custom field for resolviong discriminator value instead of using definition name

Issue #90 closed
Valeriy Churkin created an issue

Currently validation of discriminator value is based on it's children definition names, which is not very flexible, especially when you need to have several object definitions with the same descriminator value for different parent discriminators. See:

"definitions": {
    "PetRequest": {
      "discriminator": "petType",
      ...
    },
    "PetResponse": {
      "discriminator": "petType",
      ...
    },
    "CatRequest": {
      "allOf": [
        {
          "$ref": "#/definitions/PetRequest"
        },
        ...
      ]
    },
    "CatResponse": {
      "allOf": [
        {
          "$ref": "#/definitions/PetResponse"
        },
        ...
      ]
    }
  }

In this case you can not use discriminator value "Cat" for both CatRequest and CatResponse. I suggest adding custom configurable vendor field for resolving discriminator value, for example:

"definitions": {
    "CatRequest": {
      "x-discriminatorValue": "Cat",
      "allOf": [
        {
          "$ref": "#/definitions/PetRequest"
        },
        ...
      ]
    },
    "CatResponse": {
      "x-discriminatorValue": "Cat",
      "allOf": [
        {
          "$ref": "#/definitions/PetResponse"
        },
        ...
      ]
    }
  }

If such field is present, it would be used as a discriminator value instend of definition name, otherwise everything works as before.

Comments (2)

  1. James Navin

    Closed due to inactivity.

    I believe the requested functionality is now available via the OpenAPI v3 spec format.

    Please feel free to re-open this if it is still an issue.

  2. Log in to comment