Hi,

I have two classes, one of which is a request model, and the other one is a
response model of a REST API. camel-swagger annotation and methods work
great, when I use only the request type, or only response type(s). When I
specified both the request object and the response object, the input body
type becomes un-referenced, and becomes "undefined" on the swagger-ui. Is
this expected behavior or am I missing something?

Here's what I mean:
When the route is in this way;

        public void configure() throws Exception {

                String host = "localhost";
                String port = "8888";
                String baseUri = "v1";

                restConfiguration().component("jetty")                          
                                .host(host)
                                .port(port)
                                .contextPath(baseUri)

                                // API Docs
                                .apiContextPath("/api-docs")
                                .apiProperty("api.title", "User Service by Rest 
DSL")
                                .apiProperty("api.version", "v1")
                                .apiProperty("base.path", baseUri)      
                ;

                rest("/user")
                                .post("/").description("Send user info to the 
queue")
                                .type(User.class)
                                
.param().name("body").type(RestParamType.body).description("User
Info").endParam()

                                .to("mock:post_user")
                ;
        }

Then it generates the json as this:
{
  "swagger" : "2.0",
  "info" : {
    "version" : "v1",
    "title" : "User Service by Rest DSL"
  },
  "host" : "localhost:8888",
  "basePath" : "/v1",
  "tags" : [ {
    "name" : "user"
  } ],
  "schemes" : [ "http" ],
  "paths" : {
    "/user/" : {
      "post" : {
        "tags" : [ "user" ],
        "summary" : "Send user info to the queue",
        "parameters" : [* {
          "in" : "body",
          "name" : "body",
          "description" : "User Info",
          "required" : true,
          "schema" : {
            "$ref" : "#/definitions/User"
          }
        }* ],
        "x-camelContextId" : "camel-1",
        "x-routeId" : "route1"
      }
    }
  },
  "definitions" : {
    "User" : {
      "type" : "object",
      "properties" : {
        "FirstName" : {
          "type" : "string",
          "description" : "First Name"
        },
        "LastName" : {
          "type" : "string",
          "description" : "Last Name"
        }
      },
      "description" : "User Model",
      *"x-className" : {
        "type" : "string",
        "format" : "model.User"
      }*
    }
  }
}

But as soon as I add a response model as;

        public void configure() throws Exception {

                String host = "localhost";
                String port = "8888";
                String baseUri = "v1";

                restConfiguration().component("jetty")                          
                                .host(host)
                                .port(port)
                                .contextPath(baseUri)

                                // API Docs
                                .apiContextPath("/api-docs")
                                .apiProperty("api.title", "User Service by Rest 
DSL")
                                .apiProperty("api.version", "v1")
                                .apiProperty("base.path", baseUri)      
                ;

                rest("/user")
                                .post("/").description("Send user info to the 
queue")
                                .type(User.class)
                                
.param().name("body").type(RestParamType.body).description("User
Info").endParam()
                        
*.responseMessage().code(200).responseModel(HttpResponse.class).message("Success").endResponseMessage()*
                                .to("mock:post_user")
                ;
        }

And then the generated json becomes following;

{
  "swagger" : "2.0",
  "info" : {
    "version" : "v1",
    "title" : "User Service by Rest DSL"
  },
  "host" : "localhost:8888",
  "basePath" : "/v1",
  "tags" : [ {
    "name" : "user"
  } ],
  "schemes" : [ "http" ],
  "paths" : {
    "/user/" : {
      "post" : {
        "tags" : [ "user" ],
        "summary" : "Send user info to the queue",
        "parameters" : [ *{
          "in" : "body",
          "name" : "body",
          "description" : "User Info",
          "required" : true
        }* ],
        "responses" : {
          "200" : {
            "description" : "Success",
            "schema" : {
              "$ref" : "#/definitions/HttpResponse"
            }
          }
        },
        "x-camelContextId" : "camel-1",
        "x-routeId" : "route1"
      }
    }
  },
  "definitions" : {
    "User" : {
      "type" : "object",
      "properties" : {
        "FirstName" : {
          "type" : "string",
          "description" : "First Name"
        },
        "LastName" : {
          "type" : "string",
          "description" : "Last Name"
        }
      },
      "description" : "User Model"
    },
    "HttpResponse" : {
      "type" : "object",
      "properties" : {
        "ResponseCode" : {
          "type" : "integer",
          "format" : "int32",
          "description" : "HTTP Response Code"
        },
        "Result" : {
          "type" : "string",
          "description" : "Result of the operation"
        },
        "Message" : {
          "type" : "string",
          "description" : "Response message"
        },
        "Errors" : {
          "type" : "array",
          "description" : "Error messages",
          "items" : {
            "type" : "string"
          }
        },
        "Request" : {
          "description" : "Requested data",
          "$ref" : "#/definitions/User"
        }
      },
      "description" : "HTTP Response Model",
      "x-className" : {
        "type" : "string",
        "format" : "model.HttpResponse"
      }
    }
  }
}


And notice the "scheme" and "$ref" properties are gone from the User model
definition now for the body parameter in json, which turns to show
"undefined" in swagger-ui.

Could someone help me out??

Thank you so much,

Kaori





--
View this message in context: 
http://camel.465427.n5.nabble.com/camel-swagger-Type-Reference-Question-tp5783330.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Reply via email to