Uploaded image for project: 'Camel'
  1. Camel
  2. CAMEL-18066

OpenApi Specification Generator: Add support for discriminator for xOf

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Resolved
    • Minor
    • Resolution: Fixed
    • 3.14.2
    • 3.17.0
    • camel-openapi-java
    • None
    • Unknown

    Description

      Add support for the OpenApi spec 'discriminator' allowing for explicit selection of a schema type based on a property value.

      https://redocly.com/docs/resources/discriminator/

       

      This class 

      @Schema(oneOf = { XOfFormA.class, XOfFormB.class },
              discriminatorProperty = "code",
              discriminatorMapping = {
                      @DiscriminatorMapping(value = "a-123", schema = XOfFormA.class),
                      @DiscriminatorMapping(value = "b-456", schema = XOfFormB.class) })
      public interface OneOfForm {
          // The discriminator explicitly declares which property you can inspect to determine the object type.
          // The discriminator must apply to the same level of the schema it is declared in (common mistake when using nested objects).
      } 

      will generate

      "components" : {
          "schemas" : {
            "OneOfForm" : {
              "oneOf" : [ {
                "$ref" : "#/components/schemas/XOfFormA"
              }, {
                "$ref" : "#/components/schemas/XOfFormB"
              } ],
              "discriminator" : {
                "propertyName" : "code",
                "mapping" : {
                  "a-123" : "#/components/schemas/org.apache.camel.openapi.model.XOfFormA",
                  "b-456" : "#/components/schemas/org.apache.camel.openapi.model.XOfFormB"
                }
              },
      
      ...

       

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              johnathani Johnathan Ingram
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: