Skip to content

Commit

Permalink
CAMEL-8897: Polished the rest param a bit and added for the xml example
Browse files Browse the repository at this point in the history
  • Loading branch information
davsclaus committed Jul 1, 2015
1 parent 46d5e4d commit a80e4d1
Show file tree
Hide file tree
Showing 15 changed files with 58 additions and 62 deletions.
Expand Up @@ -46,11 +46,11 @@ public class RestOperationParamDefinition {
private VerbDefinition verb; private VerbDefinition verb;


@XmlAttribute(required = true) @XmlAttribute(required = true)
@Metadata(defaultValue = "path") private String name;
private RestParamType paramType;


@XmlAttribute(required = true) @XmlAttribute(required = true)
private String name; @Metadata(defaultValue = "path")
private RestParamType type;


@XmlAttribute @XmlAttribute
@Metadata(defaultValue = "") @Metadata(defaultValue = "")
Expand Down Expand Up @@ -78,7 +78,7 @@ public class RestOperationParamDefinition {


@XmlAttribute @XmlAttribute
@Metadata(defaultValue = "") @Metadata(defaultValue = "")
private String paramAccess; private String access;


public RestOperationParamDefinition() { public RestOperationParamDefinition() {
} }
Expand All @@ -87,15 +87,15 @@ public RestOperationParamDefinition(VerbDefinition verb) {
this.verb = verb; this.verb = verb;
} }


public RestParamType getParamType() { public RestParamType getType() {
return paramType != null ? paramType : RestParamType.path; return type != null ? type : RestParamType.path;
} }


/** /**
* Sets the Swagger Parameter type. * Sets the Swagger Parameter type.
*/ */
public void setParamType(RestParamType paramType) { public void setType(RestParamType type) {
this.paramType = paramType; this.type = type;
} }


public String getName() { public String getName() {
Expand Down Expand Up @@ -154,7 +154,7 @@ public void setAllowMultiple(Boolean allowMultiple) {
} }


public String getDataType() { public String getDataType() {
return dataType != null ? dataType : "string"; return dataType;
} }


/** /**
Expand All @@ -179,15 +179,15 @@ public void setAllowableValues(List<String> allowableValues) {
this.allowableValues = allowableValues; this.allowableValues = allowableValues;
} }


public String getParamAccess() { public String getAccess() {
return paramAccess != null ? paramAccess : ""; return access != null ? access : "";
} }


/** /**
* Sets the Swagger Parameter paramAccess flag. * Sets the Swagger Parameter paramAccess flag.
*/ */
public void setParamAccess(String paramAccess) { public void setAccess(String access) {
this.paramAccess = paramAccess; this.access = access;
} }


/** /**
Expand Down Expand Up @@ -233,7 +233,7 @@ public RestOperationParamDefinition allowMultiple(Boolean allowMultiple) {
} }


/** /**
* The data type of the parameter such as string,int * The data type of the parameter such as <tt>string</tt>, <tt>long</tt>, <tt>int</tt>, <tt>boolean</tt>
*/ */
public RestOperationParamDefinition dataType(String type) { public RestOperationParamDefinition dataType(String type) {
setDataType(type); setDataType(type);
Expand All @@ -260,15 +260,16 @@ public RestOperationParamDefinition allowableValues(String... allowableValues) {
* The parameter type such as body, form, header, path, query * The parameter type such as body, form, header, path, query
*/ */
public RestOperationParamDefinition type(RestParamType type) { public RestOperationParamDefinition type(RestParamType type) {
setParamType(type); setType(type);
return this; return this;
} }


/** /**
* A flag to hide the parameter if set to false * Parameter access. Use <tt>false</tt> or <tt>internal</tt> to indicate the parameter
* should be hidden for the public.
*/ */
public RestOperationParamDefinition paramAccess(String paramAccess) { public RestOperationParamDefinition access(String paramAccess) {
setParamAccess(paramAccess); setAccess(paramAccess);
return this; return this;
} }


Expand Down
Expand Up @@ -16,8 +16,6 @@
*/ */
package org.apache.camel.component.rest; package org.apache.camel.component.rest;


import java.util.Arrays;

import org.apache.camel.builder.RouteBuilder; import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.model.rest.RestParamType; import org.apache.camel.model.rest.RestParamType;


Expand All @@ -37,10 +35,10 @@ public void configure() throws Exception {
rest("dummy-rest").path("/say/bye") rest("dummy-rest").path("/say/bye")
.get().consumes("application/json") .get().consumes("application/json")
.param().type(RestParamType.header).description("header param description1").dataType("integer").allowableValues("1", "2", "3", "4") .param().type(RestParamType.header).description("header param description1").dataType("integer").allowableValues("1", "2", "3", "4")
.defaultValue("1").allowMultiple(false).name("header_count").required(true).paramAccess("acc1") .defaultValue("1").allowMultiple(false).name("header_count").required(true).access("acc1")
.endParam(). .endParam().
param().type(RestParamType.query).description("header param description2").dataType("string").allowableValues("a", "b", "c", "d") param().type(RestParamType.query).description("header param description2").dataType("string").allowableValues("a", "b", "c", "d")
.defaultValue("b").allowMultiple(true).name("header_letter").required(false).paramAccess("acc2") .defaultValue("b").allowMultiple(true).name("header_letter").required(false).access("acc2")
.endParam() .endParam()
.responseMessage().code(300).message("test msg").responseModel(Integer.class).endResponseMessage() .responseMessage().code(300).message("test msg").responseModel(Integer.class).endResponseMessage()
.to("direct:bye") .to("direct:bye")
Expand Down
Expand Up @@ -56,8 +56,8 @@ public void testFromRestModel() throws Exception {
assertEquals("application/json", rest.getVerbs().get(0).getConsumes()); assertEquals("application/json", rest.getVerbs().get(0).getConsumes());


assertEquals(2, rest.getVerbs().get(0).getParams().size()); assertEquals(2, rest.getVerbs().get(0).getParams().size());
assertEquals(RestParamType.header, rest.getVerbs().get(0).getParams().get(0).getParamType()); assertEquals(RestParamType.header, rest.getVerbs().get(0).getParams().get(0).getType());
assertEquals(RestParamType.query, rest.getVerbs().get(0).getParams().get(1).getParamType()); assertEquals(RestParamType.query, rest.getVerbs().get(0).getParams().get(1).getType());


assertEquals("header param description1", rest.getVerbs().get(0).getParams().get(0).getDescription()); assertEquals("header param description1", rest.getVerbs().get(0).getParams().get(0).getDescription());
assertEquals("header param description2", rest.getVerbs().get(0).getParams().get(1).getDescription()); assertEquals("header param description2", rest.getVerbs().get(0).getParams().get(1).getDescription());
Expand All @@ -76,8 +76,8 @@ public void testFromRestModel() throws Exception {
assertEquals("header_letter", rest.getVerbs().get(0).getParams().get(1).getName()); assertEquals("header_letter", rest.getVerbs().get(0).getParams().get(1).getName());
assertEquals(Boolean.TRUE, rest.getVerbs().get(0).getParams().get(0).getRequired()); assertEquals(Boolean.TRUE, rest.getVerbs().get(0).getParams().get(0).getRequired());
assertEquals(Boolean.FALSE, rest.getVerbs().get(0).getParams().get(1).getRequired()); assertEquals(Boolean.FALSE, rest.getVerbs().get(0).getParams().get(1).getRequired());
assertEquals("acc1", rest.getVerbs().get(0).getParams().get(0).getParamAccess()); assertEquals("acc1", rest.getVerbs().get(0).getParams().get(0).getAccess());
assertEquals("acc2", rest.getVerbs().get(0).getParams().get(1).getParamAccess()); assertEquals("acc2", rest.getVerbs().get(0).getParams().get(1).getAccess());


assertEquals(300, rest.getVerbs().get(0).getResponseMsgs().get(0).getCode()); assertEquals(300, rest.getVerbs().get(0).getResponseMsgs().get(0).getCode());
assertEquals("test msg", rest.getVerbs().get(0).getResponseMsgs().get(0).getMessage()); assertEquals("test msg", rest.getVerbs().get(0).getResponseMsgs().get(0).getMessage());
Expand Down Expand Up @@ -109,10 +109,10 @@ public void configure() throws Exception {
rest("/say/bye") rest("/say/bye")
.get().consumes("application/json") .get().consumes("application/json")
.param().type(RestParamType.header).description("header param description1").dataType("integer").allowableValues("1", "2", "3", "4") .param().type(RestParamType.header).description("header param description1").dataType("integer").allowableValues("1", "2", "3", "4")
.defaultValue("1").allowMultiple(false).name("header_count").required(true).paramAccess("acc1") .defaultValue("1").allowMultiple(false).name("header_count").required(true).access("acc1")
.endParam(). .endParam().
param().type(RestParamType.query).description("header param description2").dataType("string").allowableValues("a", "b", "c", "d") param().type(RestParamType.query).description("header param description2").dataType("string").allowableValues("a", "b", "c", "d")
.defaultValue("b").allowMultiple(true).name("header_letter").required(false).paramAccess("acc2") .defaultValue("b").allowMultiple(true).name("header_letter").required(false).access("acc2")
.endParam() .endParam()
.responseMessage().code(300).message("test msg").responseModel(Integer.class).endResponseMessage() .responseMessage().code(300).message("test msg").responseModel(Integer.class).endResponseMessage()
.to("direct:bye") .to("direct:bye")
Expand Down
Expand Up @@ -16,8 +16,6 @@
*/ */
package org.apache.camel.component.rest; package org.apache.camel.component.rest;


import java.util.Arrays;

import org.apache.camel.builder.RouteBuilder; import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.model.rest.RestDefinition; import org.apache.camel.model.rest.RestDefinition;
import org.apache.camel.model.rest.RestParamType; import org.apache.camel.model.rest.RestParamType;
Expand Down Expand Up @@ -55,10 +53,10 @@ public void configure() throws Exception {
rest("/say/bye").description("bye", "Bye Service", "en") rest("/say/bye").description("bye", "Bye Service", "en")
.get().description("Says bye to you").consumes("application/json") .get().description("Says bye to you").consumes("application/json")
.param().type(RestParamType.header).description("header param description1").dataType("integer").allowableValues("1", "2", "3", "4") .param().type(RestParamType.header).description("header param description1").dataType("integer").allowableValues("1", "2", "3", "4")
.defaultValue("1").allowMultiple(false).name("header_count").required(true).paramAccess("acc1") .defaultValue("1").allowMultiple(false).name("header_count").required(true).access("acc1")
.endParam(). .endParam().
param().type(RestParamType.query).description("header param description2").dataType("string").allowableValues("a", "b", "c", "d") param().type(RestParamType.query).description("header param description2").dataType("string").allowableValues("a", "b", "c", "d")
.defaultValue("b").allowMultiple(true).name("header_letter").required(false).paramAccess("acc2") .defaultValue("b").allowMultiple(true).name("header_letter").required(false).access("acc2")
.endParam() .endParam()
.responseMessage().code(300).message("test msg").responseModel(Integer.class).endResponseMessage() .responseMessage().code(300).message("test msg").responseModel(Integer.class).endResponseMessage()
.to("direct:bye") .to("direct:bye")
Expand Down
Expand Up @@ -61,17 +61,15 @@ public void testFromRestModel() throws Exception {
assertTrue(xml.contains("application/json")); assertTrue(xml.contains("application/json"));
assertTrue(xml.contains("</rests>")); assertTrue(xml.contains("</rests>"));


assertTrue(xml.contains("<param paramType=\"query\" name=\"header_letter\" description=\"header param description2\"" assertTrue(xml.contains("<param name=\"header_letter\" type=\"query\" description=\"header param description2\""
+ " defaultValue=\"b\" required=\"false\" allowMultiple=\"true\" dataType=\"string\" paramAccess=\"acc2\">")); + " defaultValue=\"b\" required=\"false\" allowMultiple=\"true\" dataType=\"string\" access=\"acc2\">"));
assertTrue(xml.contains("<param paramType=\"header\" name=\"header_count\" description=\"header param description1\" " assertTrue(xml.contains("<param name=\"header_count\" type=\"header\" description=\"header param description1\" "
+ "defaultValue=\"1\" required=\"true\" allowMultiple=\"false\" dataType=\"integer\" paramAccess=\"acc1\">")); + "defaultValue=\"1\" required=\"true\" allowMultiple=\"false\" dataType=\"integer\" access=\"acc1\">"));
assertTrue(xml.contains("<value>1</value>")); assertTrue(xml.contains("<value>1</value>"));
assertTrue(xml.contains("<value>a</value>")); assertTrue(xml.contains("<value>a</value>"));


assertTrue(xml.contains("<responseMessage code=\"300\" message=\"test msg\" responseModel=\"java.lang.Integer\"/>")); assertTrue(xml.contains("<responseMessage code=\"300\" message=\"test msg\" responseModel=\"java.lang.Integer\"/>"));




String xml2 = (String) mbeanServer.invoke(on, "dumpRoutesAsXml", null, null); String xml2 = (String) mbeanServer.invoke(on, "dumpRoutesAsXml", null, null);
log.info(xml2); log.info(xml2);
// and we should have rest in the routes that indicate its from a rest dsl // and we should have rest in the routes that indicate its from a rest dsl
Expand All @@ -93,10 +91,10 @@ public void configure() throws Exception {
rest("/say/bye") rest("/say/bye")
.get().consumes("application/json") .get().consumes("application/json")
.param().type(RestParamType.header).description("header param description1").dataType("integer").allowableValues(Arrays.asList("1", "2", "3", "4")) .param().type(RestParamType.header).description("header param description1").dataType("integer").allowableValues(Arrays.asList("1", "2", "3", "4"))
.defaultValue("1").allowMultiple(false).name("header_count").required(true).paramAccess("acc1") .defaultValue("1").allowMultiple(false).name("header_count").required(true).access("acc1")
.endParam(). .endParam().
param().type(RestParamType.query).description("header param description2").dataType("string").allowableValues(Arrays.asList("a", "b", "c", "d")) param().type(RestParamType.query).description("header param description2").dataType("string").allowableValues(Arrays.asList("a", "b", "c", "d"))
.defaultValue("b").allowMultiple(true).name("header_letter").required(false).paramAccess("acc2") .defaultValue("b").allowMultiple(true).name("header_letter").required(false).access("acc2")
.endParam() .endParam()
.responseMessage().code(300).message("test msg").responseModel(Integer.class).endResponseMessage() .responseMessage().code(300).message("test msg").responseModel(Integer.class).endResponseMessage()
.to("direct:bye") .to("direct:bye")
Expand Down
Expand Up @@ -41,15 +41,15 @@
</rest> </rest>
<rest path="/say/bye"> <rest path="/say/bye">
<get consumes="application/json"> <get consumes="application/json">
<param paramType="header" description="header param description1" dataType="integer" defaultValue="1" allowMultiple="false" name="header_count" required="true" paramAccess="acc1"> <param name="header_count" type="header" description="header param description1" dataType="integer" defaultValue="1" allowMultiple="false" required="true" access="acc1">
<allowableValues> <allowableValues>
<value>1</value> <value>1</value>
<value>2</value> <value>2</value>
<value>3</value> <value>3</value>
<value>4</value> <value>4</value>
</allowableValues> </allowableValues>
</param> </param>
<param paramType="query" description="header param description2" dataType="string" defaultValue="b" allowMultiple="true" name="header_letter" required="false" paramAccess="acc2"> <param name="header_letter" type="query" description="header param description2" dataType="string" defaultValue="b" allowMultiple="true" required="false" access="acc2">
<allowableValues> <allowableValues>
<value>a</value> <value>a</value>
<value>b</value> <value>b</value>
Expand Down
Expand Up @@ -34,15 +34,15 @@
</rest> </rest>
<rest path="/say/bye"> <rest path="/say/bye">
<get consumes="application/json"> <get consumes="application/json">
<param paramType="header" description="header param description1" dataType="integer" defaultValue="1" allowMultiple="false" name="header_count" required="true" paramAccess="acc1"> <param name="header_count" type="header" description="header param description1" dataType="integer" defaultValue="1" allowMultiple="false" required="true" access="acc1">
<allowableValues> <allowableValues>
<value>1</value> <value>1</value>
<value>2</value> <value>2</value>
<value>3</value> <value>3</value>
<value>4</value> <value>4</value>
</allowableValues> </allowableValues>
</param> </param>
<param paramType="query" description="header param description2" dataType="string" defaultValue="b" allowMultiple="true" name="header_letter" required="false" paramAccess="acc2"> <param name="header_letter" type="query" description="header param description2" dataType="string" defaultValue="b" allowMultiple="true" required="false" access="acc2">
<allowableValues> <allowableValues>
<value>a</value> <value>a</value>
<value>b</value> <value>b</value>
Expand Down
Expand Up @@ -38,15 +38,15 @@
<description lang="en">Bye Service</description> <description lang="en">Bye Service</description>
<get consumes="application/json"> <get consumes="application/json">
<description>Says bye to you</description> <description>Says bye to you</description>
<param paramType="header" description="header param description1" dataType="integer" defaultValue="1" allowMultiple="false" name="header_count" required="true" paramAccess="acc1"> <param name="header_count" type="header" description="header param description1" dataType="integer" defaultValue="1" allowMultiple="false" required="true" access="acc1">
<allowableValues> <allowableValues>
<value>1</value> <value>1</value>
<value>2</value> <value>2</value>
<value>3</value> <value>3</value>
<value>4</value> <value>4</value>
</allowableValues> </allowableValues>
</param> </param>
<param paramType="query" description="header param description2" dataType="string" defaultValue="b" allowMultiple="true" name="header_letter" required="false" paramAccess="acc2"> <param name="header_letter" type="query" description="header param description2" dataType="string" defaultValue="b" allowMultiple="true" required="false" access="acc2">
<allowableValues> <allowableValues>
<value>a</value> <value>a</value>
<value>b</value> <value>b</value>
Expand Down
Expand Up @@ -205,8 +205,8 @@ class RestSwaggerReader {
if (param.getAllowMultiple != null) param.getAllowMultiple.booleanValue() else false, if (param.getAllowMultiple != null) param.getAllowMultiple.booleanValue() else false,
param.getDataType, param.getDataType,
allowValues, allowValues,
param.getParamType.toString, param.getType.toString,
Some(param.getParamAccess) Some(param.getAccess)
) )
} }


Expand Down
Expand Up @@ -53,8 +53,8 @@ public void testFromRestModel() throws Exception {
assertEquals("application/json", rest.getVerbs().get(0).getConsumes()); assertEquals("application/json", rest.getVerbs().get(0).getConsumes());


assertEquals(2, rest.getVerbs().get(0).getParams().size()); assertEquals(2, rest.getVerbs().get(0).getParams().size());
assertEquals(RestParamType.header, rest.getVerbs().get(0).getParams().get(0).getParamType()); assertEquals(RestParamType.header, rest.getVerbs().get(0).getParams().get(0).getType());
assertEquals(RestParamType.query, rest.getVerbs().get(0).getParams().get(1).getParamType()); assertEquals(RestParamType.query, rest.getVerbs().get(0).getParams().get(1).getType());


assertEquals("header param description1", rest.getVerbs().get(0).getParams().get(0).getDescription()); assertEquals("header param description1", rest.getVerbs().get(0).getParams().get(0).getDescription());
assertEquals("header param description2", rest.getVerbs().get(0).getParams().get(1).getDescription()); assertEquals("header param description2", rest.getVerbs().get(0).getParams().get(1).getDescription());
Expand All @@ -73,8 +73,8 @@ public void testFromRestModel() throws Exception {
assertEquals("header_letter", rest.getVerbs().get(0).getParams().get(1).getName()); assertEquals("header_letter", rest.getVerbs().get(0).getParams().get(1).getName());
assertEquals(Boolean.TRUE, rest.getVerbs().get(0).getParams().get(0).getRequired()); assertEquals(Boolean.TRUE, rest.getVerbs().get(0).getParams().get(0).getRequired());
assertEquals(Boolean.FALSE, rest.getVerbs().get(0).getParams().get(1).getRequired()); assertEquals(Boolean.FALSE, rest.getVerbs().get(0).getParams().get(1).getRequired());
assertEquals("acc1", rest.getVerbs().get(0).getParams().get(0).getParamAccess()); assertEquals("acc1", rest.getVerbs().get(0).getParams().get(0).getAccess());
assertEquals("acc2", rest.getVerbs().get(0).getParams().get(1).getParamAccess()); assertEquals("acc2", rest.getVerbs().get(0).getParams().get(1).getAccess());


assertEquals(300, rest.getVerbs().get(0).getResponseMsgs().get(0).getCode()); assertEquals(300, rest.getVerbs().get(0).getResponseMsgs().get(0).getCode());
assertEquals("test msg", rest.getVerbs().get(0).getResponseMsgs().get(0).getMessage()); assertEquals("test msg", rest.getVerbs().get(0).getResponseMsgs().get(0).getMessage());
Expand Down
Expand Up @@ -39,15 +39,15 @@
</rest> </rest>
<rest path="/say/bye"> <rest path="/say/bye">
<get consumes="application/json"> <get consumes="application/json">
<param paramType="header" description="header param description1" dataType="integer" defaultValue="1" allowMultiple="false" name="header_count" required="true" paramAccess="acc1"> <param name="header_count" type="header" description="header param description1" dataType="integer" defaultValue="1" allowMultiple="false" required="true" access="acc1">
<allowableValues> <allowableValues>
<value>1</value> <value>1</value>
<value>2</value> <value>2</value>
<value>3</value> <value>3</value>
<value>4</value> <value>4</value>
</allowableValues> </allowableValues>
</param> </param>
<param paramType="query" description="header param description2" dataType="string" defaultValue="b" allowMultiple="true" name="header_letter" required="false" paramAccess="acc2"> <param name="header_letter" type="query" description="header param description2" dataType="string" defaultValue="b" allowMultiple="true" required="false" access="acc2">
<allowableValues> <allowableValues>
<value>a</value> <value>a</value>
<value>b</value> <value>b</value>
Expand Down
Expand Up @@ -32,15 +32,15 @@
</rest> </rest>
<rest path="/say/bye"> <rest path="/say/bye">
<get consumes="application/json"> <get consumes="application/json">
<param paramType="header" description="header param description1" dataType="integer" defaultValue="1" allowMultiple="false" name="header_count" required="true" paramAccess="acc1"> <param name="header_count" type="header" description="header param description1" dataType="integer" defaultValue="1" allowMultiple="false" required="true" access="acc1">
<allowableValues> <allowableValues>
<value>1</value> <value>1</value>
<value>2</value> <value>2</value>
<value>3</value> <value>3</value>
<value>4</value> <value>4</value>
</allowableValues> </allowableValues>
</param> </param>
<param paramType="query" description="header param description2" dataType="string" defaultValue="b" allowMultiple="true" name="header_letter" required="false" paramAccess="acc2"> <param name="header_letter" type="query" description="header param description2" dataType="string" defaultValue="b" allowMultiple="true" required="false" access="acc2">
<allowableValues> <allowableValues>
<value>a</value> <value>a</value>
<value>b</value> <value>b</value>
Expand Down

0 comments on commit a80e4d1

Please sign in to comment.