asyncapi / saunter

Saunter is a code-first AsyncAPI documentation generator for dotnet.
https://www.asyncapi.com/
MIT License
199 stars 56 forks source link

Add code-first discriminator support #85

Closed gomete closed 3 years ago

gomete commented 3 years ago

Add discriminator support. It is in the specification and currently, there is no way to mark the polymorphism and inheritance using discriminators.

image

"oneOf" is not part of the schema but it is supported in the AsyncAPI playground:

image

{
  "asyncapi": "2.0.0",
  "info": {
    "title": "Example AsyncAPI",
    "version": "v1"
  },
  "defaultContentType": "application/json",
  "channels": {
    "MessagePublished": {
      "publish": {
        "operationId": "events",
        "message": {
          "payload": { "$ref": "#/components/schemas/event" },
          "name": "event"
        }
      }
    }
  },
  "components": {
    "schemas": {
      "event": {
        "required": ["provider"],
        "discriminator": "provider",
        "oneOf": [
          { "$ref": "#/components/schemas/aEventSubType" },
          { "$ref": "#/components/schemas/otherEventSubType" }
        ]
      },
      "aEventSubType": {
        "required": ["provider", "name"],
        "properties": {
          "provider": {
            "type": "string",
            "description": "aEventSubType."
          },
          "name": {
            "type": "string",
            "description": "aEventSubType name."
          }
        }
      },
      "otherEventSubType": {
        "required": ["provider", "name"],
        "properties": {
          "provider": {
            "type": "string",
            "description": "otherEventSubType."
          },
          "name": {
            "type": "string",
            "description": "otherEventSubType name."
          },
          "additionalProperty": {
            "type": "string",
            "description": "otherEventSubType additionalProperty."
          }
        }
      }
    }
  }
}
m-wild commented 3 years ago

Closed by #86