[ 
https://issues.apache.org/jira/browse/CAMEL-18040?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17532030#comment-17532030
 ] 

Johnathan Ingram edited comment on CAMEL-18040 at 5/5/22 4:20 AM:
------------------------------------------------------------------

Hi

I have created the pull request.

Test cases are included in the pull request.

Sample OpenApi Spec Generated by the test case
{code:java}
{
  "openapi" : "3.0.2",
  "servers" : [ {
    "url" : "http://localhost:8080/api";
  } ],
  "paths" : {
    "/form/oneOf" : {
      "post" : {
        "requestBody" : {
          "description" : "",
          "content" : {
            "application/json" : {
              "schema" : {
                "$ref" : "#/components/schemas/OneOfFormWrapper"
              }
            }
          },
          "required" : true
        },
        "tags" : [ "OneOf" ],
        "responses" : {
          "200" : {
            "description" : "Ok"
          }
        },
        "operationId" : "verb1",
        "summary" : "OneOf rest service",
        "x-camelContextId" : "camel-1"
      }
    },
    "/form/allOf" : {
      "post" : {
        "requestBody" : {
          "description" : "",
          "content" : {
            "application/json" : {
              "schema" : {
                "$ref" : "#/components/schemas/AllOfFormWrapper"
              }
            }
          },
          "required" : true
        },
        "tags" : [ "AllOf" ],
        "responses" : {
          "200" : {
            "description" : "Ok"
          }
        },
        "operationId" : "verb2",
        "summary" : "AllOf rest service",
        "x-camelContextId" : "camel-1"
      }
    },
    "/form/anyOf" : {
      "post" : {
        "requestBody" : {
          "description" : "",
          "content" : {
            "application/json" : {
              "schema" : {
                "$ref" : "#/components/schemas/AnyOfFormWrapper"
              }
            }
          },
          "required" : true
        },
        "tags" : [ "AnyOf" ],
        "responses" : {
          "200" : {
            "description" : "Ok"
          }
        },
        "operationId" : "verb3",
        "summary" : "AnyOf rest service",
        "x-camelContextId" : "camel-1"
      }
    }
  },
  "components" : {
    "schemas" : {
      "OneOfForm" : {
        "oneOf" : [ {
          "$ref" : "#/components/schemas/XOfFormA"
        }, {
          "$ref" : "#/components/schemas/XOfFormB"
        } ],
        "x-className" : {
          "format" : "org.apache.camel.openapi.model.OneOfForm",
          "type" : "string"
        }
      },
      "OneOfFormWrapper" : {
        "type" : "object",
        "properties" : {
          "formType" : {
            "type" : "string"
          },
          "form" : {
            "$ref" : "#/components/schemas/OneOfForm"
          }
        },
        "x-className" : {
          "format" : "org.apache.camel.openapi.model.OneOfFormWrapper",
          "type" : "string"
        }
      },
      "XOfFormA" : {
        "type" : "object",
        "properties" : {
          "code" : {
            "type" : "string"
          },
          "a" : {
            "type" : "string"
          },
          "b" : {
            "format" : "int32",
            "type" : "integer"
          }
        },
        "x-className" : {
          "format" : "org.apache.camel.openapi.model.XOfFormA",
          "type" : "string"
        }
      },
      "XOfFormB" : {
        "type" : "object",
        "properties" : {
          "code" : {
            "type" : "string"
          },
          "x" : {
            "format" : "int32",
            "type" : "integer"
          },
          "y" : {
            "type" : "string"
          }
        },
        "x-className" : {
          "format" : "org.apache.camel.openapi.model.XOfFormB",
          "type" : "string"
        }
      },
      "AllOfForm" : {
        "allOf" : [ {
          "$ref" : "#/components/schemas/XOfFormA"
        }, {
          "$ref" : "#/components/schemas/XOfFormB"
        } ],
        "x-className" : {
          "format" : "org.apache.camel.openapi.model.AllOfForm",
          "type" : "string"
        }
      },
      "AllOfFormWrapper" : {
        "type" : "object",
        "properties" : {
          "fullForm" : {
            "$ref" : "#/components/schemas/AllOfForm"
          }
        },
        "x-className" : {
          "format" : "org.apache.camel.openapi.model.AllOfFormWrapper",
          "type" : "string"
        }
      },
      "AnyOfForm" : {
        "anyOf" : [ {
          "$ref" : "#/components/schemas/XOfFormA"
        }, {
          "$ref" : "#/components/schemas/XOfFormB"
        } ],
        "x-className" : {
          "format" : "org.apache.camel.openapi.model.AnyOfForm",
          "type" : "string"
        }
      },
      "AnyOfFormWrapper" : {
        "type" : "object",
        "properties" : {
          "formElements" : {
            "$ref" : "#/components/schemas/AnyOfForm"
          }
        },
        "x-className" : {
          "format" : "org.apache.camel.openapi.model.AnyOfFormWrapper",
          "type" : "string"
        }
      }
    }
  },
  "tags" : [ {
    "name" : "OneOf"
  }, {
    "name" : "AnyOf"
  }, {
    "name" : "AllOf"
  } ]
} {code}


was (Author: JIRAUSER283740):
Hi

I have created the pull request.

Test cases are included in the pull request

> 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 
> -----------------------------------------------------------------------------------------------------------------------------------------------------------------
>
>                 Key: CAMEL-18040
>                 URL: https://issues.apache.org/jira/browse/CAMEL-18040
>             Project: Camel
>          Issue Type: Improvement
>          Components: camel-openapi-java
>    Affects Versions: 3.14.2
>            Reporter: Johnathan Ingram
>            Priority: Minor
>
>  
> Given the following classes
> {code:java}
> @Schema(oneOf = {FormA.class, FormB.class})
> public abstract class Form {    
> } {code}
>  
>  
>  
> {code:java}
> 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;    }
> } {code}
>  
> {code:java}
> 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;    }
> } {code}
> {code:java}
> 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;    }
> } {code}
> And finally the request of a Camel Rest Endpoint
> {code:java}
> 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() 
> ....{code}
> The OpenAPI specification is correct except for the Form class in the schema 
> components section
> {code:java}
> "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"
>           }
>         }
>       }
>     }
>  {code}
> NOTE: Form should be
> {code:java}
> "Form" : { 
> "oneOf" : [
>    ....
> ] 
> },  {code}
>  
>  



--
This message was sent by Atlassian Jira
(v8.20.7#820007)

Reply via email to