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

OpenApi Specification Generator Does not generate oneOf, allOf and anyOf when annotation @Schema(oneOf|allOf|anyOf = {X.class, Y.class}) is specified on a class

    XMLWordPrintableJSON

Details

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

    Description

       

      Given the following classes

      @Schema(oneOf = {FormA.class, FormB.class})
      public abstract class Form {    
      } 

       

       

       

      public class FormA extends Form {    
          String code;
          String a;    
          int b;
          
          public String getCode() {        return this.code;    }
          public void setCode(String code) {        this.code = code;    }
          public String getA() {        return this.a;    }
          public void setA(String a) {        this.a = a;    }
          public int getB() {        return this.b;    }
          public void setB(int b) {        this.b = b;    }
      } 

       

      public class FormB extends Form {    
          String code;
          int x;    
          String y;
      
          public String getCode() {        return this.code;    }
          public void setCode(String code) {        this.code = code;    }
          public int getX() {        return this.x;    }
          public void setX(int x) {        this.x = x;    }
          public String getY() {        return this.y;    }
          public void setY(String y) {        this.y = y;    }
      } 
      public class Wrapper {        
          @JsonProperty("system")    String system;
          @JsonProperty("form")    Form form;
      
          public String getSystem() {        return this.system;    }
          public void setSystem(String system) {        this.system = system;    }
          public Form getForm() {        return this.form;    }
          @JsonTypeInfo(        use = JsonTypeInfo.Id.NAME,         include = JsonTypeInfo.As.EXTERNAL_PROPERTY,         property = "system")      @JsonSubTypes({         @Type(value = FormA.class, name = "Form A"),         @Type(value = FormB.class, name = "Form B")       })              
          public void setForm(Form form) {        this.form = form;    }
      } 

      And finally the request of a Camel Rest Endpoint

      rest("/prototype/")           
      .id("rest.proto.oneof")            
      .post("oneof")            
      .bindingMode(RestBindingMode.json)                        .description("Prototype OneOf")            
      .id("proto.oneof")                        
      .consumes("application/json")            
      .produces(MediaType.APPLICATION_JSON )            
      .type(Wrapper.class)                                    
      .responseMessage()                
      .code(200).message("Oneof working")            
      .endResponseMessage() 
      
      ....

      The OpenAPI specification is correct except for the Form class in the schema components section

      "Form" : {        
         "type" : "object"      
      },      
      "FormA" : {        
         "type" : "object",        
         "properties" : {
                "code" : {
                  "type" : "string"
                },
                "a" : {
                  "type" : "string"
                },
                "b" : {
                  "format" : "int32",
                  "type" : "integer"
                }
              }
            },
      "FormB" : {
              "type" : "object",
              "properties" : {
                "code" : {
                  "type" : "string"
                },
                "x" : {
                  "format" : "int32",
                  "type" : "integer"
                },
                "y" : {
                  "type" : "string"
                }
              }
            },
            "Wrapper" : {
              "type" : "object",
              "properties" : {
                "system" : {
                  "type" : "string"
                },
                "form" : {
                  "$ref" : "#/components/schemas/Form"
                }
              }
            }
          }
       

      NOTE: Form should be

      "Form" : { 
      "oneOf" : [
         ....
      ] 
      },  

       

       

      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: