You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@juneau.apache.org by ja...@apache.org on 2018/06/09 05:39:34 UTC
[juneau] branch master updated: Swagger tests.
This is an automated email from the ASF dual-hosted git repository.
jamesbognar pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/juneau.git
The following commit(s) were added to refs/heads/master by this push:
new 65c56d2 Swagger tests.
65c56d2 is described below
commit 65c56d2968416c3de71f126a26708e7c9a2abb51
Author: JamesBognar <ja...@apache.org>
AuthorDate: Sat Jun 9 01:39:12 2018 -0400
Swagger tests.
---
.../juneau/json/JsonParserEdgeCasesTest.java | 2 +-
.../src/main/java/org/apache/juneau/Session.java | 2 +-
.../org/apache/juneau/json/JsonParserSession.java | 13 +-
.../apache/juneau/rest/BasicRestCallHandler.java | 2 +-
.../apache/juneau/rest/BasicRestInfoProvider.java | 41 +-
.../org/apache/juneau/rest/RestMethodReturn.java | 2 +-
.../org/apache/juneau/rest/RestMethodThrown.java | 2 +-
.../org/apache/juneau/rest/RestParamDefaults.java | 2 +-
.../apache/juneau/rest/annotation/Response.java | 2 +
.../apache/juneau/rest/util/AnnotationUtils.java | 26 +-
.../juneau/rest/BasicRestInfoProviderTest.java | 46 +-
.../juneau/rest/annotation/BodyAnnotationTest.java | 376 ++++++----
.../rest/annotation/FormDataAnnotationTest.java | 615 ++++++++++++----
.../rest/annotation/HeaderAnnotationTest.java | 581 +++++++++++----
.../juneau/rest/annotation/PathAnnotationTest.java | 476 +++++++++----
.../rest/annotation/QueryAnnotationTest.java | 532 +++++++++++---
.../rest/annotation/ResponseAnnotationTest.java | 788 ++++++++++-----------
.../annotation/ResponseHeaderAnnotationTest.java | 378 +++++++---
.../annotation/ResponseStatusAnnotationTest.java | 4 +-
.../rest/annotation/ResponsesAnnotationTest.java | 264 +++++++
20 files changed, 2952 insertions(+), 1202 deletions(-)
diff --git a/juneau-core/juneau-core-test/src/test/java/org/apache/juneau/json/JsonParserEdgeCasesTest.java b/juneau-core/juneau-core-test/src/test/java/org/apache/juneau/json/JsonParserEdgeCasesTest.java
index 30166c3..9d86810 100644
--- a/juneau-core/juneau-core-test/src/test/java/org/apache/juneau/json/JsonParserEdgeCasesTest.java
+++ b/juneau-core/juneau-core-test/src/test/java/org/apache/juneau/json/JsonParserEdgeCasesTest.java
@@ -129,7 +129,7 @@ public class JsonParserEdgeCasesTest {
{ 94, "n_object_garbage_at_end", "{\"a\":\"a\" 123}", "Could not find '}'" },
{ 95, "n_object_key_with_single_quotes", "{key: 'value'}", "Unquoted attribute detected" },
{ 96, "n_object_missing_colon", "{\"a\" b}", "Could not find ':'" },
- { 97, "n_object_missing_key", "{:\"b\"}", "Unquoted attribute detected" },
+ { 97, "n_object_missing_key", "{:\"b\"}", null },
{ 98, "n_object_missing_semicolon", "{\"a\" \"b\"}", "Could not find ':'" },
{ 99, "n_object_missing_value", "{\"a\":", "Unrecognized syntax" },
{ 100, "n_object_no-colon", "{\"a\"", "Could not find ':'" },
diff --git a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/Session.java b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/Session.java
index 0f758df..5c09eaa 100644
--- a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/Session.java
+++ b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/Session.java
@@ -314,7 +314,7 @@ public abstract class Session {
* Throws a {@link BeanRuntimeException} if any warnings occurred in this session.
*/
public void checkForWarnings() {
- if (! warnings.isEmpty())
+ if (warnings != null && ! warnings.isEmpty())
throw new BeanRuntimeException("Warnings occurred in session: \n" + join(getWarnings(), "\n"));
}
}
diff --git a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/json/JsonParserSession.java b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/json/JsonParserSession.java
index 0dc02f7..5d2edae 100644
--- a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/json/JsonParserSession.java
+++ b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/json/JsonParserSession.java
@@ -386,11 +386,13 @@ public final class JsonParserSession extends ReaderParserSession {
return parseString(r);
if (isStrict())
throw new ParseException(this, "Unquoted attribute detected.");
+ if (! VALID_BARE_CHARS.contains(c))
+ throw new ParseException(this, "Could not find the start of the field name.");
r.mark();
// Look for whitespace.
while (c != -1) {
c = r.read();
- if (c == ':' || isWhitespace(c) || c == '/') {
+ if (! VALID_BARE_CHARS.contains(c)) {
r.unread();
String s = r.getMarked().intern();
return s.equals("null") ? null : s;
@@ -398,6 +400,8 @@ public final class JsonParserSession extends ReaderParserSession {
}
throw new ParseException(this, "Could not find the end of the field name.");
}
+
+ private static final AsciiSet VALID_BARE_CHARS = AsciiSet.create().range('A','Z').range('a','z').range('0','9').chars("$_-.").build();
private <E> Collection<E> parseIntoCollection2(ParserReader r, Collection<E> l,
ClassMeta<?> type, BeanPropertyMeta pMeta) throws Exception {
@@ -478,8 +482,13 @@ public final class JsonParserSession extends ReaderParserSession {
while (c != -1) {
c = r.read();
if (state == S0) {
- if (c == '{')
+ if (c == '{') {
state = S1;
+ } else if (isCommentOrWhitespace(c)) {
+ skipCommentsAndSpace(r.unread());
+ } else {
+ break;
+ }
} else if (state == S1) {
if (c == '}') {
return m;
diff --git a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/BasicRestCallHandler.java b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/BasicRestCallHandler.java
index e304b9b..6ff40d7 100644
--- a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/BasicRestCallHandler.java
+++ b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/BasicRestCallHandler.java
@@ -198,7 +198,7 @@ public class BasicRestCallHandler implements RestCallHandler {
handleError(r1, r2, e);
} catch (Throwable e) {
Response ri = e.getClass().getAnnotation(Response.class);
- int code = ri == null ? SC_INTERNAL_SERVER_ERROR : ObjectUtils.firstNonZero(ri.code(), SC_INTERNAL_SERVER_ERROR);
+ int code = ri == null ? SC_INTERNAL_SERVER_ERROR : ObjectUtils.firstNonZero(ri.code(), ri.value(), SC_INTERNAL_SERVER_ERROR);
RestException e2 = new RestException(e, code);
r1.setAttribute("Exception", e);
r1.setAttribute("ExecTime", System.currentTimeMillis() - startTime);
diff --git a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/BasicRestInfoProvider.java b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/BasicRestInfoProvider.java
index ae198d7..886b3ea 100644
--- a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/BasicRestInfoProvider.java
+++ b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/BasicRestInfoProvider.java
@@ -252,6 +252,8 @@ public class BasicRestInfoProvider implements RestInfoProvider {
info.appendSkipEmpty("termsOfService", resolve(vr, mb.findFirstString(locale, "termsOfService")));
info.appendSkipEmpty("contact", parseMap(vr, mb.findFirstString(locale, "contact"), "Messages/contact on class {0}", c));
info.appendSkipEmpty("license", parseMap(vr, mb.findFirstString(locale, "license"), "Messages/license on class {0}", c));
+ if (info.isEmpty())
+ omSwagger.remove("info");
ObjectList
produces = omSwagger.getObjectList("produces", true),
@@ -513,7 +515,7 @@ public class BasicRestInfoProvider implements RestInfoProvider {
header.appendSkipEmpty("exclusiveMaximum", resolve(vr, pi2.getString("exclusiveMaximum")));
header.appendSkipEmpty("exclusiveMinimum", resolve(vr, pi2.getString("exclusiveMinimum")));
header.appendSkipEmpty("uniqueItems", resolve(vr, pi2.getString("uniqueItems")));
- header.appendSkipEmpty("default", JsonParser.DEFAULT.parse(vr.resolve(pi2.getString("default")), Object.class));
+ header.appendSkipEmpty("default", parseAnything(vr, pi2.getString("default"), "@ResponseHeader/default on class {0} method {1}", c, m));
header.appendSkipEmpty("enum", parseListOrCdl(vr, pi2.getString("enum"), "@ResponseHeader/enum on class {0} method {1}", c, m));
header.appendSkipEmpty("x-example", parseAnything(vr, pi2.getString("example"), "@ResponseHeader/example on class {0} method {1}", c, m));
header.appendSkipEmpty("examples", parseMap(vr, pi2.get("examples"), "@ResponseHeader/examples on class {0} method {1}", c, m));
@@ -584,7 +586,9 @@ public class BasicRestInfoProvider implements RestInfoProvider {
if (js.getBeanDefs() != null)
for (Map.Entry<String,ObjectMap> e : js.getBeanDefs().entrySet())
definitions.put(e.getKey(), fixSwaggerExtensions(e.getValue()));
-
+ if (definitions.isEmpty())
+ omSwagger.remove("definitions");
+
if (! tagMap.isEmpty())
omSwagger.put("tags", tagMap.values());
@@ -593,6 +597,14 @@ public class BasicRestInfoProvider implements RestInfoProvider {
if (produces.isEmpty())
omSwagger.remove("produces");
+// try {
+// if (! omSwagger.isEmpty())
+// assertNoEmpties(omSwagger);
+// } catch (SwaggerException e1) {
+// System.err.println(omSwagger.toString(JsonSerializer.DEFAULT_LAX_READABLE));
+// throw e1;
+// }
+
try {
String swaggerJson = omSwagger.toString(JsonSerializer.DEFAULT_LAX_READABLE);
swagger = jp.parse(swaggerJson, Swagger.class);
@@ -601,11 +613,32 @@ public class BasicRestInfoProvider implements RestInfoProvider {
}
swaggers.get(locale).put(hashCode, swagger);
-
-// JsonSerializer.DEFAULT_LAX_READABLE.println(swagger);
return swagger;
}
+
+// private static void assertNoEmpties(ObjectMap om) throws SwaggerException {
+// if (om.isEmpty())
+// throw new SwaggerException(null, "Empty map detected.");
+// for (Map.Entry<String,Object> e : om.entrySet()) {
+// Object val = e.getValue();
+// if (val instanceof ObjectMap)
+// assertNoEmpties((ObjectMap)val);
+// if (val instanceof ObjectList)
+// assertNoEmpties((ObjectList)val);
+// }
+// }
+//
+// private static void assertNoEmpties(ObjectList ol) throws SwaggerException {
+// if (ol.isEmpty())
+// throw new SwaggerException(null, "Empty list detected.");
+// for (Object val : ol) {
+// if (val instanceof ObjectMap)
+// assertNoEmpties((ObjectMap)val);
+// if (val instanceof ObjectList)
+// assertNoEmpties((ObjectList)val);
+// }
+// }
//=================================================================================================================
// Utility methods
diff --git a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestMethodReturn.java b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestMethodReturn.java
index b485be3..b50a31d 100644
--- a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestMethodReturn.java
+++ b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestMethodReturn.java
@@ -37,7 +37,7 @@ public class RestMethodReturn {
int code = 200;
if (type instanceof Class)
for (Response ri : ReflectionUtils.findAnnotationsParentFirst(Response.class, (Class<?>)type)) {
- code = ObjectUtils.firstNonZero(ri.code(), code);
+ code = ObjectUtils.firstNonZero(ri.code(), ri.value(), code);
om = merge(om, ri);
}
diff --git a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestMethodThrown.java b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestMethodThrown.java
index 477f105..f45fe26 100644
--- a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestMethodThrown.java
+++ b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestMethodThrown.java
@@ -36,7 +36,7 @@ public class RestMethodThrown {
int code = 500;
for (Response ri : ReflectionUtils.findAnnotationsParentFirst(Response.class, type)) {
- code = ObjectUtils.firstNonZero(ri.code(), code);
+ code = ObjectUtils.firstNonZero(ri.code(), ri.value(), code);
om = merge(om, ri);
}
diff --git a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestParamDefaults.java b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestParamDefaults.java
index 7da7916..1425dfd 100644
--- a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestParamDefaults.java
+++ b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestParamDefaults.java
@@ -710,7 +710,7 @@ class RestParamDefaults {
if (a == null)
return om;
om = om.modifiable();
- int status = ObjectUtils.firstNonZero(a.code(), 200);
+ int status = ObjectUtils.firstNonZero(a.code(), a.value(), 200);
merge(om.getObjectMap(String.valueOf(status), true), a);
return om;
}
diff --git a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/annotation/Response.java b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/annotation/Response.java
index 29e77fa..e8acd8d 100644
--- a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/annotation/Response.java
+++ b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/annotation/Response.java
@@ -103,6 +103,8 @@ public @interface Response {
*/
int code() default 0;
+ int value() default 0;
+
String[] api() default {};
/**
diff --git a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/util/AnnotationUtils.java b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/util/AnnotationUtils.java
index 166b3cd..c3ea808 100644
--- a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/util/AnnotationUtils.java
+++ b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/util/AnnotationUtils.java
@@ -50,7 +50,7 @@ public class AnnotationUtils {
.appendSkipEmpty("required", a.required())
.appendSkipEmpty("example", joinnl(a.example()))
.appendSkipEmpty("examples", joinnl(a.examples()))
- .append("schema", merge(om.getObjectMap("schema"), a.schema()));
+ .appendSkipEmpty("schema", merge(om.getObjectMap("schema"), a.schema()));
}
/**
@@ -104,14 +104,14 @@ public class AnnotationUtils {
.appendSkipEmpty("required", a.required())
.appendSkipEmpty("enum", joinnl(a._enum()))
.appendSkipEmpty("type", a.type())
- .append("items", merge(om.getObjectMap("items"), a.items()))
+ .appendSkipEmpty("items", merge(om.getObjectMap("items"), a.items()))
.appendSkipEmpty("allOf", joinnl(a.allOf()))
.appendSkipEmpty("properties", joinnl(a.properties()))
.appendSkipEmpty("additionalProperties", joinnl(a.additionalProperties()))
.appendSkipEmpty("discriminator", a.discriminator())
.appendSkipEmpty("readOnly", a.readOnly())
.appendSkipEmpty("xml", joinnl(a.xml()))
- .append("externalDocs", merge(om.getObjectMap("externalDocs"), a.externalDocs()))
+ .appendSkipEmpty("externalDocs", merge(om.getObjectMap("externalDocs"), a.externalDocs()))
.appendSkipEmpty("example", joinnl(a.example()))
.appendSkipEmpty("examples", joinnl(a.examples()))
.appendSkipEmpty("ignore", a.ignore() ? "true" : null);
@@ -133,8 +133,8 @@ public class AnnotationUtils {
.appendSkipEmpty("description", joinnl(a.description()))
.appendSkipEmpty("example", joinnl(a.example()))
.appendSkipEmpty("examples", joinnl(a.examples()))
- .append("schema", merge(om.getObjectMap("schema"), a.schema()))
- .append("headers", merge(om.getObjectMap("headers"), a.headers()));
+ .appendSkipEmpty("schema", merge(om.getObjectMap("schema"), a.schema()))
+ .appendSkipEmpty("headers", merge(om.getObjectMap("headers"), a.headers()));
}
/**
@@ -218,7 +218,7 @@ public class AnnotationUtils {
.appendSkipEmpty("exclusiveMinimum", a.exclusiveMinimum())
.appendSkipEmpty("uniqueItems", a.uniqueItems())
.appendSkipEmpty("default", joinnl(a._default()))
- .append("items", merge(om.getObjectMap("items"), a.items()))
+ .appendSkipEmpty("items", merge(om.getObjectMap("items"), a.items()))
.appendSkipEmpty("default", joinnl(a._default()))
.appendSkipEmpty("enum", joinnl(a._enum()))
.appendSkipEmpty("example", joinnl(a.example()));
@@ -249,7 +249,7 @@ public class AnnotationUtils {
.appendSkipEmpty("allowEmptyValue", a.allowEmptyValue())
.appendSkipEmpty("exclusiveMaximum", a.exclusiveMaximum())
.appendSkipEmpty("exclusiveMinimum", a.exclusiveMinimum())
- .append("schema", merge(om.getObjectMap("schema"), a.schema()))
+ .appendSkipEmpty("schema", merge(om.getObjectMap("schema"), a.schema()))
.appendSkipEmpty("enum", joinnl(a._enum()))
.appendSkipEmpty("example", joinnl(a.example()));
}
@@ -284,10 +284,10 @@ public class AnnotationUtils {
.appendSkipEmpty("exclusiveMaximum", a.exclusiveMaximum())
.appendSkipEmpty("exclusiveMinimum", a.exclusiveMinimum())
.appendSkipEmpty("uniqueItems", a.uniqueItems())
- .append("schema", merge(om.getObjectMap("schema"), a.schema()))
+ .appendSkipEmpty("schema", merge(om.getObjectMap("schema"), a.schema()))
.appendSkipEmpty("default", joinnl(a._default()))
.appendSkipEmpty("enum", joinnl(a._enum()))
- .append("items", merge(om.getObjectMap("items"), a.items()))
+ .appendSkipEmpty("items", merge(om.getObjectMap("items"), a.items()))
.appendSkipEmpty("example", joinnl(a.example()));
}
@@ -321,10 +321,10 @@ public class AnnotationUtils {
.appendSkipEmpty("exclusiveMaximum", a.exclusiveMaximum())
.appendSkipEmpty("exclusiveMinimum", a.exclusiveMinimum())
.appendSkipEmpty("uniqueItems", a.uniqueItems())
- .append("schema", merge(om.getObjectMap("schema"), a.schema()))
+ .appendSkipEmpty("schema", merge(om.getObjectMap("schema"), a.schema()))
.appendSkipEmpty("default", joinnl(a._default()))
.appendSkipEmpty("enum", joinnl(a._enum()))
- .append("items", merge(om.getObjectMap("items"), a.items()))
+ .appendSkipEmpty("items", merge(om.getObjectMap("items"), a.items()))
.appendSkipEmpty("example", joinnl(a.example()));
}
@@ -358,10 +358,10 @@ public class AnnotationUtils {
.appendSkipEmpty("exclusiveMaximum", a.exclusiveMaximum())
.appendSkipEmpty("exclusiveMinimum", a.exclusiveMinimum())
.appendSkipEmpty("uniqueItems", a.uniqueItems())
- .append("schema", merge(om.getObjectMap("schema"), a.schema()))
+ .appendSkipEmpty("schema", merge(om.getObjectMap("schema"), a.schema()))
.appendSkipEmpty("default", joinnl(a._default()))
.appendSkipEmpty("enum", joinnl(a._enum()))
- .append("items", merge(om.getObjectMap("items"), a.items()))
+ .appendSkipEmpty("items", merge(om.getObjectMap("items"), a.items()))
.appendSkipEmpty("example", joinnl(a.example()));
}
diff --git a/juneau-rest/juneau-rest-server/src/test/java/org/apache/juneau/rest/BasicRestInfoProviderTest.java b/juneau-rest/juneau-rest-server/src/test/java/org/apache/juneau/rest/BasicRestInfoProviderTest.java
index 6586b28..05abba4 100644
--- a/juneau-rest/juneau-rest-server/src/test/java/org/apache/juneau/rest/BasicRestInfoProviderTest.java
+++ b/juneau-rest/juneau-rest-server/src/test/java/org/apache/juneau/rest/BasicRestInfoProviderTest.java
@@ -71,7 +71,7 @@ public class BasicRestInfoProviderTest {
// /<root>
//=================================================================================================================
- @RestResource()
+ @RestResource
public static class A01 {}
@Test
@@ -334,7 +334,7 @@ public class BasicRestInfoProviderTest {
// /tags
//=================================================================================================================
- @RestResource()
+ @RestResource
public static class C01 {}
@Test
@@ -469,7 +469,7 @@ public class BasicRestInfoProviderTest {
}
// Auto-detect tags defined on methods.
- @RestResource()
+ @RestResource
public static class C08 {
@RestMethod(swagger=@MethodSwagger(tags="foo"))
public void doFoo() {}
@@ -487,7 +487,7 @@ public class BasicRestInfoProviderTest {
}
// Comma-delimited list
- @RestResource()
+ @RestResource
public static class C09 {
@RestMethod(swagger=@MethodSwagger(tags=" foo, bar "))
public void doFoo() {}
@@ -505,7 +505,7 @@ public class BasicRestInfoProviderTest {
}
// ObjectList
- @RestResource()
+ @RestResource
public static class C10 {
@RestMethod(swagger=@MethodSwagger(tags="['foo', 'bar']"))
public void doFoo() {}
@@ -562,7 +562,7 @@ public class BasicRestInfoProviderTest {
// /externalDocs
//=================================================================================================================
- @RestResource()
+ @RestResource
public static class D01 {}
@Test
@@ -656,7 +656,7 @@ public class BasicRestInfoProviderTest {
// /paths/<path>/<method>
//=================================================================================================================
- @RestResource()
+ @RestResource
public static class E01 {
@RestMethod(name=GET,path="/path/{foo}")
public Foo doFoo() {
@@ -884,7 +884,7 @@ public class BasicRestInfoProviderTest {
// /paths/<path>/<method>/tags
//=================================================================================================================
- @RestResource()
+ @RestResource
public static class MD01 {
@RestMethod(name=GET,path="/path/{foo}")
@@ -973,7 +973,7 @@ public class BasicRestInfoProviderTest {
// /paths/<path>/<method>/externalDocs
//=================================================================================================================
- @RestResource()
+ @RestResource
public static class ME01 {
@RestMethod(name=GET,path="/path/{foo}")
@@ -1062,7 +1062,7 @@ public class BasicRestInfoProviderTest {
// /paths/<path>/<method>/consumes
//=================================================================================================================
- @RestResource()
+ @RestResource
public static class MF01 {
@RestMethod(name=GET,path="/path/{foo}")
@@ -1193,7 +1193,7 @@ public class BasicRestInfoProviderTest {
// /paths/<path>/<method>/produces
//=================================================================================================================
- @RestResource()
+ @RestResource
public static class MG01 {
@RestMethod(name=GET,path="/path/{foo}")
@@ -1324,7 +1324,7 @@ public class BasicRestInfoProviderTest {
// /paths/<path>/<method>/deprecated
//=================================================================================================================
- @RestResource()
+ @RestResource
public static class MH06 {
@RestMethod(name=GET,path="/path2/{foo}")
@Deprecated
@@ -1339,7 +1339,7 @@ public class BasicRestInfoProviderTest {
assertObjectEquals("true", getSwaggerWithFile(new MH06()).getPaths().get("/path2/{foo}").get("get").getDeprecated());
}
- @RestResource()
+ @RestResource
@Deprecated
public static class MH07 {
@RestMethod(name=GET,path="/path2/{foo}")
@@ -1358,7 +1358,7 @@ public class BasicRestInfoProviderTest {
// /paths/<path>/<method>/parameters/query
//=================================================================================================================
- @RestResource()
+ @RestResource
public static class NA01 {
@RestMethod(name=GET,path="/path/{foo}/query")
public Foo doFoo(@Query("foo") Foo foo) {
@@ -1776,7 +1776,7 @@ public class BasicRestInfoProviderTest {
// /paths/<path>/<method>/parameters/query/example
//=================================================================================================================
- @RestResource()
+ @RestResource
public static class NR01 {
@RestMethod(name=GET,path="/path/{foo}/query")
public Foo doFoo(@Query("foo") Foo foo) {
@@ -1850,7 +1850,7 @@ public class BasicRestInfoProviderTest {
// /paths/<path>/<method>/parameters/body/examples
//=================================================================================================================
- @RestResource()
+ @RestResource
public static class NS01 {
@RestMethod(name=GET,path="/path/{foo}/body")
public Foo doFoo(@Body Foo foo) {
@@ -1924,7 +1924,7 @@ public class BasicRestInfoProviderTest {
// /paths/<path>/<method>/parameters/query/schema
//=================================================================================================================
- @RestResource()
+ @RestResource
public static class NT01 {
@RestMethod(name=GET,path="/path/{foo}/query")
public Foo doFoo(@Query("foo") Foo foo) {
@@ -1999,10 +1999,10 @@ public class BasicRestInfoProviderTest {
// /paths/<path>/<method>/responses/<response>/description
//=================================================================================================================
- @RestResource()
+ @RestResource
public static class OA01 {
@RestMethod(name=GET,path="/path/{foo}/responses/100")
- public Foo doFoo(@Response(code=100) Value<Foo> foo) {
+ public Foo doFoo(@Response(100) Value<Foo> foo) {
return null;
}
}
@@ -2073,7 +2073,7 @@ public class BasicRestInfoProviderTest {
// /paths/<path>/<method>/responses/<response>/headers
//=================================================================================================================
- @RestResource()
+ @RestResource
public static class OB01 {
@RestMethod(name=GET,path="/path/{foo}/responses/100")
public Foo doFoo(@Response(code=100) Value<Foo> foo) {
@@ -2147,7 +2147,7 @@ public class BasicRestInfoProviderTest {
// /paths/<path>/<method>/responses/<response>/example
//=================================================================================================================
- @RestResource()
+ @RestResource
public static class OC01 {
@RestMethod(name=GET,path="/path/{foo}/responses/100")
public Foo doFoo(@Response(code=100) Value<Foo> foo) {
@@ -2221,7 +2221,7 @@ public class BasicRestInfoProviderTest {
// /paths/<path>/<method>/responses/<response>/examples
//=================================================================================================================
- @RestResource()
+ @RestResource
public static class OD01 {
@RestMethod(name=GET,path="/path/{foo}/responses/100")
public Foo doFoo(@Response(code=100) Value<Foo> foo) {
@@ -2295,7 +2295,7 @@ public class BasicRestInfoProviderTest {
// /paths/<path>/<method>/responses/<response>/schema
//=================================================================================================================
- @RestResource()
+ @RestResource
public static class OE01 {
@RestMethod(name=GET,path="/path/{foo}/responses/100")
public Foo doFoo(@Response(code=100) Value<Foo> foo) {
diff --git a/juneau-rest/juneau-rest-server/src/test/java/org/apache/juneau/rest/annotation/BodyAnnotationTest.java b/juneau-rest/juneau-rest-server/src/test/java/org/apache/juneau/rest/annotation/BodyAnnotationTest.java
index 732a2b5..ed94ce6 100644
--- a/juneau-rest/juneau-rest-server/src/test/java/org/apache/juneau/rest/annotation/BodyAnnotationTest.java
+++ b/juneau-rest/juneau-rest-server/src/test/java/org/apache/juneau/rest/annotation/BodyAnnotationTest.java
@@ -773,7 +773,11 @@ public class BodyAnnotationTest {
// Swagger - @Body on POJO
//=================================================================================================================
- @RestResource()
+ //-----------------------------------------------------------------------------------------------------------------
+ // Basic tests
+ //-----------------------------------------------------------------------------------------------------------------
+
+ @RestResource
public static class SA {
@Body(
@@ -783,116 +787,156 @@ public class BodyAnnotationTest {
example=" 'a' ",
examples="{foo:'bar'}"
)
- public static class SA00 {
- public SA00(String x) {}
+ public static class SA01 {
+ public SA01(String x) {}
}
-
@RestMethod(name=GET,path="/basic")
- public void sa00(SA00 h) {}
+ public void sa01(SA01 h) {}
+
+ @Body({
+ "description:'a\nb',",
+ "required:true,",
+ "schema:{type:'a'},",
+ "example:'a',",
+ "examples:{foo:'bar'}"
+ })
+ public static class SA02 {
+ public SA02(String x) {}
+ }
+ @RestMethod(name=GET,path="/api")
+ public void sa02(SA02 h) {}
@Body(
value={
"description:'a\nb',",
"required:true,",
"schema:{type:'a'},",
+ "example:'a',",
"examples:{foo:'bar'}"
- }
+ },
+ description={"b","c"},
+ required="false",
+ schema=@Schema(type="b"),
+ example="b",
+ examples="{foo:'baz'}"
)
- public static class SA01 {
- public SA01(String x) {}
+ public static class SA03 {
+ public SA03(String x) {}
}
+ @RestMethod(name=GET,path="/mixed")
+ public void sa03(SA03 h) {}
+ }
- @RestMethod(name=GET,path="/api")
- public void sa01(SA01 h) {}
+ @Test
+ public void sa01_Body_onPojo_basic() throws Exception {
+ ParameterInfo x = getSwagger(new SA()).getPaths().get("/basic").get("get").getParameter("body", null);
+ assertEquals("a\nb", x.getDescription());
+ assertObjectEquals("true", x.getRequired());
+ assertObjectEquals("{type:'a'}", x.getSchema());
+ assertObjectEquals("'a'", x.getExample());
+ assertObjectEquals("{foo:'bar'}", x.getExamples());
+ }
+ @Test
+ public void sa02_Body_onPojo_api() throws Exception {
+ ParameterInfo x = getSwagger(new SA()).getPaths().get("/api").get("get").getParameter("body", null);
+ assertEquals("a\nb", x.getDescription());
+ assertObjectEquals("true", x.getRequired());
+ assertObjectEquals("{type:'a'}", x.getSchema());
+ assertObjectEquals("'a'", x.getExample());
+ assertObjectEquals("{foo:'bar'}", x.getExamples());
+ }
+ @Test
+ public void sa03_Body_onPojo_mixed() throws Exception {
+ ParameterInfo x = getSwagger(new SA()).getPaths().get("/mixed").get("get").getParameter("body", null);
+ assertEquals("b\nc", x.getDescription());
+ assertObjectEquals("false", x.getRequired());
+ assertObjectEquals("{type:'b'}", x.getSchema());
+ assertObjectEquals("'b'", x.getExample());
+ assertObjectEquals("{foo:'baz'}", x.getExamples());
+ }
+
+ //-----------------------------------------------------------------------------------------------------------------
+ // Schema
+ //-----------------------------------------------------------------------------------------------------------------
- @Body(schema=@Schema(" type:'b' "))
- public static class SA18b {}
+ @RestResource
+ public static class SB {
- @RestMethod(name=GET,path="/schema2")
- public void sa18b(SA18b h) {}
+ @Body(schema=@Schema(" type:'b' "))
+ public static class SB01 {}
+ @RestMethod(name=GET,path="/schemaValue")
+ public void sb10(SB01 h) {}
@Body
- public static class SA18c {
+ public static class SB02 {
public String f1;
}
-
- @RestMethod(name=GET,path="/schema3")
- public void sa18c(SA18c b) {}
+ @RestMethod(name=GET,path="/autoDetectBean")
+ public void sb02(SB02 b) {}
@Body
- public static class SA18d extends LinkedList<String> {
+ public static class SB03 extends LinkedList<String> {
private static final long serialVersionUID = 1L;
}
-
- @RestMethod(name=GET,path="/schema4")
- public void sa18d(SA18d b) {}
+ @RestMethod(name=GET,path="/autoDetectList")
+ public void sb03(SB03 b) {}
@Body
- public static class SA18e {}
-
- @RestMethod(name=GET,path="/schema5")
- public void sa18e(SA18e b) {}
-
- @Body(example=" {f1:'b'} ")
- public static class SA27 {
- public String f1;
- }
-
- @RestMethod(name=GET,path="/example2")
- public void sa27(SA27 h) {}
-
- @Body(examples={" foo:'bar' "})
- public static class SA29 {}
-
- @RestMethod(name=GET,path="/examples2")
- public void sa29(SA29 h) {}
+ public static class SB04 {}
+ @RestMethod(name=GET,path="/autoDetectStringObject")
+ public void sb04(SB04 b) {}
}
-
+
@Test
- public void sa00_Body_onPojo_basic() throws Exception {
- ParameterInfo x = getSwagger(new SA()).getPaths().get("/basic").get("get").getParameter("body", null);
- assertEquals("a\nb", x.getDescription());
- assertObjectEquals("true", x.getRequired());
- assertObjectEquals("{type:'a'}", x.getSchema());
- assertObjectEquals("'a'", x.getExample());
- assertObjectEquals("{foo:'bar'}", x.getExamples());
- }
-// @Test
-// public void sa01_Body_onPojo_api() throws Exception {
-// ParameterInfo x = getSwagger(new SA()).getPaths().get("/api").get("get").getParameter("body", null);
-// assertEquals("a\nb", x.getDescription());
-// assertObjectEquals("true", x.getRequired());
-// assertObjectEquals("{type:'a'}", x.getSchema());
-// assertObjectEquals("{foo:'bar'}", x.getExamples());
-// }
- @Test
- public void sa18b_Body_onPojo_schema2() throws Exception {
- ParameterInfo x = getSwagger(new SA()).getPaths().get("/schema2").get("get").getParameter("body", null);
+ public void sb01_Body_onPojo_schemaValue() throws Exception {
+ ParameterInfo x = getSwagger(new SB()).getPaths().get("/schemaValue").get("get").getParameter("body", null);
assertObjectEquals("{type:'b'}", x.getSchema());
}
@Test
- public void sa18c_Body_onPojo_schema3() throws Exception {
- ParameterInfo x = getSwagger(new SA()).getPaths().get("/schema3").get("get").getParameter("body", null);
+ public void sb02_Body_onPojo_autoDetectBean() throws Exception {
+ ParameterInfo x = getSwagger(new SB()).getPaths().get("/autoDetectBean").get("get").getParameter("body", null);
assertObjectEquals("{type:'object',properties:{f1:{type:'string'}}}", x.getSchema());
}
@Test
- public void sa18d_Body_onPojo_schema4() throws Exception {
- ParameterInfo x = getSwagger(new SA()).getPaths().get("/schema4").get("get").getParameter("body", null);
+ public void sb03_Body_onPojo_autoDetectList() throws Exception {
+ ParameterInfo x = getSwagger(new SB()).getPaths().get("/autoDetectList").get("get").getParameter("body", null);
assertObjectEquals("{type:'array',items:{type:'string'}}", x.getSchema());
}
@Test
- public void sa18e_Body_onPojo_schema5() throws Exception {
- ParameterInfo x = getSwagger(new SA()).getPaths().get("/schema5").get("get").getParameter("body", null);
+ public void sb04_Body_onPojo_autoDetectStringObject() throws Exception {
+ ParameterInfo x = getSwagger(new SB()).getPaths().get("/autoDetectStringObject").get("get").getParameter("body", null);
assertObjectEquals("{type:'string'}", x.getSchema());
}
+
+ //-----------------------------------------------------------------------------------------------------------------
+ // Examples
+ //-----------------------------------------------------------------------------------------------------------------
+
+ @RestResource
+ public static class SC {
+
+ @Body(example=" {f1:'b'} ")
+ public static class SC01 {
+ public String f1;
+ }
+ @RestMethod(name=GET,path="/example")
+ public void sc01(SC01 h) {}
+
+ @Body(examples={" foo:'bar' "})
+ public static class SC02 {}
+ @RestMethod(name=GET,path="/examples")
+ public void sc02(SC02 h) {}
+ }
+
+
@Test
- public void sa27_Body_onPojo_example2() throws Exception {
- ParameterInfo x = getSwagger(new SA()).getPaths().get("/example2").get("get").getParameter("body", null);
+ public void sc01_Body_onPojo_example() throws Exception {
+ ParameterInfo x = getSwagger(new SC()).getPaths().get("/example").get("get").getParameter("body", null);
assertObjectEquals("{f1:'b'}", x.getExample());
}
@Test
- public void sa29_Body_onPojo_examples2() throws Exception {
- ParameterInfo x = getSwagger(new SA()).getPaths().get("/examples2").get("get").getParameter("body", null);
+ public void sc02_Body_onPojo_examples() throws Exception {
+ ParameterInfo x = getSwagger(new SC()).getPaths().get("/examples").get("get").getParameter("body", null);
assertObjectEquals("{foo:'bar'}", x.getExamples());
}
@@ -900,69 +944,75 @@ public class BodyAnnotationTest {
// @Body on parameter
//=================================================================================================================
- @RestResource()
- public static class SB {
+ //-----------------------------------------------------------------------------------------------------------------
+ // Basic tests
+ //-----------------------------------------------------------------------------------------------------------------
+
+ @RestResource
+ public static class TA {
- public static class SB01 {
- public SB01(String x) {}
+ public static class TA01 {
+ public TA01(String x) {}
}
@RestMethod(name=GET, path="/basic")
- public void sb01(
+ public void ta01(
@Body(
description= {"a","b"},
required="true",
schema=@Schema(type="a"),
example="'a'",
examples=" {foo:'bar'} "
- ) SB01 b) {}
+ ) TA01 b) {}
- public static class SB18b {}
-
- @RestMethod(name=GET,path="/schema2")
- public void sb18b(@Body(schema=@Schema(" { type:'b' } ")) SB18b b) {}
-
- public static class SB18c {
- public String f1;
- }
-
- @RestMethod(name=GET,path="/schema3")
- public void sb18c(@Body SB18c b) {}
-
- public static class SB18d extends LinkedList<String> {
- private static final long serialVersionUID = 1L;
+ public static class TA02 {
+ public TA02(String x) {}
}
- @RestMethod(name=GET,path="/schema4")
- public void sb18d(@Body SB18d b) {}
-
- public static class SB18e {}
-
- @RestMethod(name=GET,path="/schema5")
- public void sb18e(@Body SB18e b) {}
-
- @RestMethod(name=GET,path="/schema6")
- public void sb18f(@Body Integer b) {}
-
- @RestMethod(name=GET,path="/schema7")
- public void sb18g(@Body Boolean b) {}
-
- public static class SB27 {
- public String f1;
+ @RestMethod(name=GET, path="/api")
+ public void ta02(
+ @Body({
+ "description:'a\nb',",
+ "required:true,",
+ "schema:{type:'a'},",
+ "example:'a',",
+ "examples:{foo:'bar'}"
+ }) TA02 b) {}
+
+ public static class TA03 {
+ public TA03(String x) {}
}
- @RestMethod(name=GET,path="/example2")
- public void sb27(@Body(example="{f1:'b'}") SB27 b) {}
-
- public static class SB29 {}
-
- @RestMethod(name=GET,path="/examples2")
- public void sb29(@Body(examples={" foo:'bar' "}) SB29 b) {}
+ @RestMethod(name=GET, path="/mixed")
+ public void ta03(
+ @Body(
+ value= {
+ "description:'a\nb',",
+ "required:true,",
+ "schema:{type:'a'},",
+ "example:'a',",
+ "examples:{foo:'bar'}"
+ },
+ description= {"b","c"},
+ required="false",
+ schema=@Schema(type="b"),
+ example="b",
+ examples=" {foo:'baz'} "
+ ) TA03 b) {}
}
@Test
- public void sb00_Body_onParameter_basic() throws Exception {
- ParameterInfo x = getSwagger(new SB()).getPaths().get("/basic").get("get").getParameter("body", null);
+ public void ta01_Body_onParameter_basic() throws Exception {
+ ParameterInfo x = getSwagger(new TA()).getPaths().get("/basic").get("get").getParameter("body", null);
+ assertEquals("a\nb", x.getDescription());
+ assertObjectEquals("true", x.getRequired());
+ assertObjectEquals("{type:'a'}", x.getSchema());
+ assertObjectEquals("'a'", x.getExample());
+ assertObjectEquals("{foo:'bar'}", x.getExamples());
+ }
+ @Test
+ public void ta02_Body_onParameter_api() throws Exception {
+ ParameterInfo x = getSwagger(new TA()).getPaths().get("/api").get("get").getParameter("body", null);
assertEquals("a\nb", x.getDescription());
assertObjectEquals("true", x.getRequired());
assertObjectEquals("{type:'a'}", x.getSchema());
@@ -970,44 +1020,106 @@ public class BodyAnnotationTest {
assertObjectEquals("{foo:'bar'}", x.getExamples());
}
@Test
- public void sb18b_Body_onParameter_schema2() throws Exception {
- ParameterInfo x = getSwagger(new SB()).getPaths().get("/schema2").get("get").getParameter("body", null);
+ public void ta03_Body_onParameter_mixed() throws Exception {
+ ParameterInfo x = getSwagger(new TA()).getPaths().get("/mixed").get("get").getParameter("body", null);
+ assertEquals("b\nc", x.getDescription());
+ assertObjectEquals("false", x.getRequired());
+ assertObjectEquals("{type:'b'}", x.getSchema());
+ assertObjectEquals("'b'", x.getExample());
+ assertObjectEquals("{foo:'baz'}", x.getExamples());
+ }
+
+ //-----------------------------------------------------------------------------------------------------------------
+ // Schema
+ //-----------------------------------------------------------------------------------------------------------------
+
+ @RestResource
+ public static class TB {
+
+ public static class TB01 {}
+ @RestMethod(name=GET,path="/schemaValue")
+ public void tb01(@Body(schema=@Schema(" { type:'b' } ")) TB01 b) {}
+
+ public static class TB02 {
+ public String f1;
+ }
+ @RestMethod(name=GET,path="/autoDetectBean")
+ public void sc02(@Body TB02 b) {}
+
+ public static class TB03 extends LinkedList<String> {
+ private static final long serialVersionUID = 1L;
+ }
+ @RestMethod(name=GET,path="/autoDetectList")
+ public void tb03(@Body TB03 b) {}
+
+ public static class TB04 {}
+ @RestMethod(name=GET,path="/autoDetectStringObject")
+ public void tb04(@Body TB04 b) {}
+
+ @RestMethod(name=GET,path="/autoDetectInteger")
+ public void tb05(@Body Integer b) {}
+
+ @RestMethod(name=GET,path="/autoDetectBoolean")
+ public void tb06(@Body Boolean b) {}
+ }
+
+ @Test
+ public void tb01_Body_onParameter_schemaValue() throws Exception {
+ ParameterInfo x = getSwagger(new TB()).getPaths().get("/schemaValue").get("get").getParameter("body", null);
assertObjectEquals("{type:'b'}", x.getSchema());
}
@Test
- public void sb18c_Body_onParameter_schema3() throws Exception {
- ParameterInfo x = getSwagger(new SB()).getPaths().get("/schema3").get("get").getParameter("body", null);
+ public void tb02_Body_onParameter_autoDetectBean() throws Exception {
+ ParameterInfo x = getSwagger(new TB()).getPaths().get("/autoDetectBean").get("get").getParameter("body", null);
assertObjectEquals("{type:'object',properties:{f1:{type:'string'}}}", x.getSchema());
}
@Test
- public void sb18d_Body_onParameter_schema4() throws Exception {
- ParameterInfo x = getSwagger(new SB()).getPaths().get("/schema4").get("get").getParameter("body", null);
+ public void tb03_Body_onParameter_autoDetectList() throws Exception {
+ ParameterInfo x = getSwagger(new TB()).getPaths().get("/autoDetectList").get("get").getParameter("body", null);
assertObjectEquals("{type:'array',items:{type:'string'}}", x.getSchema());
}
@Test
- public void sb18e_Body_onParameter_schema5() throws Exception {
- ParameterInfo x = getSwagger(new SB()).getPaths().get("/schema5").get("get").getParameter("body", null);
+ public void tb04_Body_onParameter_autoDetectStringObject() throws Exception {
+ ParameterInfo x = getSwagger(new TB()).getPaths().get("/autoDetectStringObject").get("get").getParameter("body", null);
assertObjectEquals("{type:'string'}", x.getSchema());
}
@Test
- public void sb18e_Body_onParameter_schema6() throws Exception {
- ParameterInfo x = getSwagger(new SB()).getPaths().get("/schema6").get("get").getParameter("body", null);
+ public void tb05_Body_onParameter_autoDetectInteger() throws Exception {
+ ParameterInfo x = getSwagger(new TB()).getPaths().get("/autoDetectInteger").get("get").getParameter("body", null);
assertObjectEquals("{format:'int32',type:'integer'}", x.getSchema());
}
@Test
- public void sb18e_Body_onParameter_schema7() throws Exception {
- ParameterInfo x = getSwagger(new SB()).getPaths().get("/schema7").get("get").getParameter("body", null);
+ public void tb06_Body_onParameter_autoDetectBoolean() throws Exception {
+ ParameterInfo x = getSwagger(new TB()).getPaths().get("/autoDetectBoolean").get("get").getParameter("body", null);
assertObjectEquals("{type:'boolean'}", x.getSchema());
}
+
+ //-----------------------------------------------------------------------------------------------------------------
+ // Examples
+ //-----------------------------------------------------------------------------------------------------------------
+
+ @RestResource
+ public static class TC {
+
+ public static class TC01 {
+ public String f1;
+ }
+ @RestMethod(name=GET,path="/example")
+ public void tc01(@Body(example="{f1:'b'}") TC01 b) {}
+
+ public static class TC02 {}
+ @RestMethod(name=GET,path="/examples")
+ public void tc02(@Body(examples={" foo:'bar' "}) TC02 b) {}
+ }
+
@Test
- public void sb27_Body_onParameter_example2() throws Exception {
- ParameterInfo x = getSwagger(new SB()).getPaths().get("/example2").get("get").getParameter("body", null);
+ public void tc01_Body_onParameter_example() throws Exception {
+ ParameterInfo x = getSwagger(new TC()).getPaths().get("/example").get("get").getParameter("body", null);
assertObjectEquals("{f1:'b'}", x.getExample());
}
@Test
- public void sb29_Body_onParameter_examples2() throws Exception {
- ParameterInfo x = getSwagger(new SB()).getPaths().get("/examples2").get("get").getParameter("body", null);
+ public void tc02_Body_onParameter_examples() throws Exception {
+ ParameterInfo x = getSwagger(new TC()).getPaths().get("/examples").get("get").getParameter("body", null);
assertObjectEquals("{foo:'bar'}", x.getExamples());
}
-
}
diff --git a/juneau-rest/juneau-rest-server/src/test/java/org/apache/juneau/rest/annotation/FormDataAnnotationTest.java b/juneau-rest/juneau-rest-server/src/test/java/org/apache/juneau/rest/annotation/FormDataAnnotationTest.java
index f4d2005..914b385 100644
--- a/juneau-rest/juneau-rest-server/src/test/java/org/apache/juneau/rest/annotation/FormDataAnnotationTest.java
+++ b/juneau-rest/juneau-rest-server/src/test/java/org/apache/juneau/rest/annotation/FormDataAnnotationTest.java
@@ -161,7 +161,11 @@ public class FormDataAnnotationTest {
// @FormData on POJO
//=================================================================================================================
- @RestResource()
+ //-----------------------------------------------------------------------------------------------------------------
+ // Basic tests
+ //-----------------------------------------------------------------------------------------------------------------
+
+ @RestResource
public static class SA {
@FormData(
@@ -189,76 +193,123 @@ public class FormDataAnnotationTest {
items=@Items(type="a"),
example="a"
)
- public static class SA00 {
- public SA00(String x) {}
+ public static class SA01 {
+ public SA01(String x) {}
}
-
@RestMethod(name=GET,path="/basic")
- public void sa00(SA00 f) {}
+ public void sa01(SA01 f) {}
- @FormData("F")
- public static class SA02 {}
-
- @RestMethod(name=GET,path="/value")
+ @FormData(
+ name="F",
+ api={
+ "description:'a\nb',",
+ "required:'true',",
+ "type:'a',",
+ "format:'a',",
+ "pattern:'a',",
+ "collectionFormat:'a',",
+ "maximum:'1',",
+ "minimum:'1',",
+ "multipleOf:'1',",
+ "maxLength:'1',",
+ "minLength:'1',",
+ "maxItems:'1',",
+ "minItems:'1',",
+ "allowEmptyValue:'true',",
+ "exclusiveMaximum:'true',",
+ "exclusiveMinimum:'true',",
+ "uniqueItems:'true',",
+ "schema:{type:'a'},",
+ "default:'a',",
+ "enum:' a,b ',",
+ "items:{type:'a'},",
+ "example:'a'"
+ }
+ )
+ public static class SA02 {
+ public SA02(String x) {}
+ }
+ @RestMethod(name=GET,path="/api")
public void sa02(SA02 f) {}
- @FormData(name="F", schema=@Schema(" type:'b' "))
- public static class SA20b {}
-
- @RestMethod(name=GET,path="/schema2")
- public void sa20b(SA20b f) {}
-
- @FormData("F")
- public static class SA20c {
- public String f1;
- }
-
- @RestMethod(name=GET,path="/schema3")
- public void sa20c(SA20c f) {}
-
- @FormData("F")
- public static class SA20d extends LinkedList<String> {
- private static final long serialVersionUID = 1L;
+ @FormData(
+ name="F",
+ api={
+ "description:'b\nc',",
+ "required:'false',",
+ "type:'b',",
+ "format:'b',",
+ "pattern:'b',",
+ "collectionFormat:'b',",
+ "maximum:'2',",
+ "minimum:'2',",
+ "multipleOf:'2',",
+ "maxLength:'2',",
+ "minLength:'2',",
+ "maxItems:'2',",
+ "minItems:'2',",
+ "allowEmptyValue:'false',",
+ "exclusiveMaximum:'false',",
+ "exclusiveMinimum:'false',",
+ "uniqueItems:'false',",
+ "schema:{type:'a'},",
+ "default:'a',",
+ "enum:' a,b ',",
+ "items:{type:'a'},",
+ "example:'b'"
+ },
+ description= {"a","b"},
+ required="true",
+ type="a",
+ format="a",
+ pattern="a",
+ collectionFormat="a",
+ maximum="1",
+ minimum="1",
+ multipleOf="1",
+ maxLength="1",
+ minLength="1",
+ maxItems="1",
+ minItems="1",
+ allowEmptyValue="true",
+ exclusiveMaximum="true",
+ exclusiveMinimum="true",
+ uniqueItems="true",
+ schema=@Schema(type="a"),
+ _default="a",
+ _enum=" a,b ",
+ items=@Items(type="a"),
+ example="a"
+ )
+ public static class SA03 {
+ public SA03(String x) {}
}
-
- @RestMethod(name=GET,path="/schema4")
- public void sa20d(SA20d f) {}
-
+ @RestMethod(name=GET,path="/mixed")
+ public void sa03(SA03 f) {}
+
@FormData("F")
- public static class SA20e {}
-
- @RestMethod(name=GET,path="/schema5")
- public void sa20e(SA20e f) {}
-
+ public static class SA04 {}
+ @RestMethod(name=GET,path="/value")
+ public void sa04(SA04 f) {}
+
@FormData(name="F", _default={"a","b"})
- public static class SA23 {}
+ public static class SA05 {}
+ @RestMethod(name=GET,path="/default")
+ public void sa05(SA05 f) {}
- @RestMethod(name=GET,path="/_default2")
- public void sa23(SA23 f) {}
-
@FormData(name="F", _enum={ "['a','b']" })
- public static class SA25 {}
+ public static class SA06 {}
+ @RestMethod(name=GET,path="/enum")
+ public void sa06(SA06 f) {}
- @RestMethod(name=GET,path="/_enum2")
- public void sa25(SA25 f) {}
-
@FormData(name="F", items=@Items(" type:'b' "))
- public static class SA27 {}
-
- @RestMethod(name=GET,path="/items2")
- public void sa27(SA27 f) {}
-
- @FormData(name="F", example={"{f1:'a'}"})
- public static class SA29 {
- public String f1;
- }
-
- @RestMethod(name=GET,path="/example2")
- public void sa29(SA29 f) {}
+ public static class SA07 {}
+ @RestMethod(name=GET,path="/items")
+ public void sa07(SA07 f) {}
}
@Test
- public void sa00_FormData_onPojo_basic() throws Exception {
+ public void sa01_FormData_onPojo_basic() throws Exception {
ParameterInfo x = getSwagger(new SA()).getPaths().get("/basic").get("get").getParameter("formData", "F");
assertEquals("F", x.getName());
assertEquals("a\nb", x.getDescription());
@@ -285,48 +336,151 @@ public class FormDataAnnotationTest {
assertEquals("a", x.getExample());
}
@Test
- public void sa02_FormData_onPojo_value() throws Exception {
+ public void sa02_FormData_onPojo_api() throws Exception {
+ ParameterInfo x = getSwagger(new SA()).getPaths().get("/api").get("get").getParameter("formData", "F");
+ assertEquals("F", x.getName());
+ assertEquals("a\nb", x.getDescription());
+ assertObjectEquals("true", x.getRequired());
+ assertEquals("a", x.getType());
+ assertEquals("a", x.getFormat());
+ assertEquals("a", x.getPattern());
+ assertEquals("a", x.getCollectionFormat());
+ assertObjectEquals("1", x.getMaximum());
+ assertObjectEquals("1", x.getMinimum());
+ assertObjectEquals("1", x.getMultipleOf());
+ assertObjectEquals("1", x.getMaxLength());
+ assertObjectEquals("1", x.getMinLength());
+ assertObjectEquals("1", x.getMaxItems());
+ assertObjectEquals("1", x.getMinItems());
+ assertObjectEquals("true", x.getAllowEmptyValue());
+ assertObjectEquals("true", x.getExclusiveMaximum());
+ assertObjectEquals("true", x.getExclusiveMinimum());
+ assertObjectEquals("true", x.getUniqueItems());
+ assertObjectEquals("{type:'a'}", x.getSchema());
+ assertEquals("a", x.getDefault());
+ assertObjectEquals("['a','b']", x.getEnum());
+ assertObjectEquals("{type:'a'}", x.getItems());
+ assertEquals("a", x.getExample());
+ }
+ @Test
+ public void sa03_FormData_onPojo_mixed() throws Exception {
+ ParameterInfo x = getSwagger(new SA()).getPaths().get("/mixed").get("get").getParameter("formData", "F");
+ assertEquals("F", x.getName());
+ assertEquals("a\nb", x.getDescription());
+ assertObjectEquals("true", x.getRequired());
+ assertEquals("a", x.getType());
+ assertEquals("a", x.getFormat());
+ assertEquals("a", x.getPattern());
+ assertEquals("a", x.getCollectionFormat());
+ assertObjectEquals("1", x.getMaximum());
+ assertObjectEquals("1", x.getMinimum());
+ assertObjectEquals("1", x.getMultipleOf());
+ assertObjectEquals("1", x.getMaxLength());
+ assertObjectEquals("1", x.getMinLength());
+ assertObjectEquals("1", x.getMaxItems());
+ assertObjectEquals("1", x.getMinItems());
+ assertObjectEquals("true", x.getAllowEmptyValue());
+ assertObjectEquals("true", x.getExclusiveMaximum());
+ assertObjectEquals("true", x.getExclusiveMinimum());
+ assertObjectEquals("true", x.getUniqueItems());
+ assertObjectEquals("{type:'a'}", x.getSchema());
+ assertEquals("a", x.getDefault());
+ assertObjectEquals("['a','b']", x.getEnum());
+ assertObjectEquals("{type:'a'}", x.getItems());
+ assertEquals("a", x.getExample());
+ }
+ @Test
+ public void sa04_FormData_onPojo_value() throws Exception {
ParameterInfo x = getSwagger(new SA()).getPaths().get("/value").get("get").getParameter("formData", "F");
assertEquals("F", x.getName());
}
@Test
- public void sa20b_FormData_onPojo_schema2() throws Exception {
- ParameterInfo x = getSwagger(new SA()).getPaths().get("/schema2").get("get").getParameter("formData", "F");
- assertObjectEquals("{type:'b'}", x.getSchema());
+ public void sa05_FormData_onPojo__default2() throws Exception {
+ ParameterInfo x = getSwagger(new SA()).getPaths().get("/default").get("get").getParameter("formData", "F");
+ assertEquals("a\nb", x.getDefault());
}
@Test
- public void sa20c_FormData_onPojo_schema3() throws Exception {
- ParameterInfo x = getSwagger(new SA()).getPaths().get("/schema3").get("get").getParameter("formData", "F");
- assertObjectEquals("{type:'object',properties:{f1:{type:'string'}}}", x.getSchema());
+ public void sa06_FormData_onPojo__enum2() throws Exception {
+ ParameterInfo x = getSwagger(new SA()).getPaths().get("/enum").get("get").getParameter("formData", "F");
+ assertObjectEquals("['a','b']", x.getEnum());
}
@Test
- public void sa20d_FormData_onPojo_schema4() throws Exception {
- ParameterInfo x = getSwagger(new SA()).getPaths().get("/schema4").get("get").getParameter("formData", "F");
- assertObjectEquals("{type:'array',items:{type:'string'}}", x.getSchema());
+ public void sa07_FormData_onPojo_items2() throws Exception {
+ ParameterInfo x = getSwagger(new SA()).getPaths().get("/items").get("get").getParameter("formData", "F");
+ assertObjectEquals("{type:'b'}", x.getItems());
+ }
+
+ //-----------------------------------------------------------------------------------------------------------------
+ // Schema
+ //-----------------------------------------------------------------------------------------------------------------
+
+ @RestResource
+ public static class SB {
+
+ @FormData(name="F", schema=@Schema(" type:'b' "))
+ public static class SB01 {}
+ @RestMethod(name=GET,path="/value")
+ public void sb01(SB01 f) {}
+
+ @FormData("F")
+ public static class SB02 {
+ public String f1;
+ }
+ @RestMethod(name=GET,path="/autoDetectBean")
+ public void sb02(SB02 f) {}
+
+ @FormData("F")
+ public static class SB03 extends LinkedList<String> {
+ private static final long serialVersionUID = 1L;
+ }
+ @RestMethod(name=GET,path="/autoDetectList")
+ public void sb03(SB03 f) {}
+
+ @FormData("F")
+ public static class SB04 {}
+ @RestMethod(name=GET,path="/autoDetectStringObject")
+ public void sb04(SB04 f) {}
}
+
@Test
- public void sa20e_FormData_onPojo_schema5() throws Exception {
- ParameterInfo x = getSwagger(new SA()).getPaths().get("/schema5").get("get").getParameter("formData", "F");
- assertObjectEquals("{type:'string'}", x.getSchema());
+ public void sb01_FormData_onPojo_value() throws Exception {
+ ParameterInfo x = getSwagger(new SB()).getPaths().get("/value").get("get").getParameter("formData", "F");
+ assertObjectEquals("{type:'b'}", x.getSchema());
}
@Test
- public void sa23_FormData_onPojo__default2() throws Exception {
- ParameterInfo x = getSwagger(new SA()).getPaths().get("/_default2").get("get").getParameter("formData", "F");
- assertEquals("a\nb", x.getDefault());
+ public void sb02_FormData_onPojo_autoDetectBean() throws Exception {
+ ParameterInfo x = getSwagger(new SB()).getPaths().get("/autoDetectBean").get("get").getParameter("formData", "F");
+ assertObjectEquals("{type:'object',properties:{f1:{type:'string'}}}", x.getSchema());
}
@Test
- public void sa25_FormData_onPojo__enum2() throws Exception {
- ParameterInfo x = getSwagger(new SA()).getPaths().get("/_enum2").get("get").getParameter("formData", "F");
- assertObjectEquals("['a','b']", x.getEnum());
+ public void sb03_FormData_onPojo_autoDetectList() throws Exception {
+ ParameterInfo x = getSwagger(new SB()).getPaths().get("/autoDetectList").get("get").getParameter("formData", "F");
+ assertObjectEquals("{type:'array',items:{type:'string'}}", x.getSchema());
}
@Test
- public void sa27_FormData_onPojo_items2() throws Exception {
- ParameterInfo x = getSwagger(new SA()).getPaths().get("/items2").get("get").getParameter("formData", "F");
- assertObjectEquals("{type:'b'}", x.getItems());
+ public void sb04_FormData_onPojo_autoDetectStringObject() throws Exception {
+ ParameterInfo x = getSwagger(new SB()).getPaths().get("/autoDetectStringObject").get("get").getParameter("formData", "F");
+ assertObjectEquals("{type:'string'}", x.getSchema());
}
+
+ //-----------------------------------------------------------------------------------------------------------------
+ // Examples
+ //-----------------------------------------------------------------------------------------------------------------
+
+ @RestResource
+ public static class SC {
+
+ @FormData(name="F", example={"{f1:'a'}"})
+ public static class SC01 {
+ public String f1;
+ }
+ @RestMethod(name=GET,path="/example")
+ public void sc01(SC01 f) {}
+ }
+
@Test
- public void sa29_FormData_onPojo_example2() throws Exception {
- ParameterInfo x = getSwagger(new SA()).getPaths().get("/example2").get("get").getParameter("formData", "F");
+ public void sc01_FormData_onPojo_example() throws Exception {
+ ParameterInfo x = getSwagger(new SC()).getPaths().get("/example").get("get").getParameter("formData", "F");
assertObjectEquals("{f1:'a'}", x.getExample());
}
@@ -334,11 +488,15 @@ public class FormDataAnnotationTest {
// @FormData on parameter
//=================================================================================================================
- @RestResource()
- public static class SB {
+ //-----------------------------------------------------------------------------------------------------------------
+ // Basic tests
+ //-----------------------------------------------------------------------------------------------------------------
+
+ @RestResource
+ public static class TA {
@RestMethod(name=GET,path="/basic")
- public void sb00(
+ public void ta01(
@FormData(
name="F",
description={"a","b"},
@@ -365,53 +523,104 @@ public class FormDataAnnotationTest {
example="'a'"
) String f) {}
- @RestMethod(name=GET,path="/value")
- public void sb02(@FormData("F") String f) {}
-
- @RestMethod(name=GET,path="/schema2")
- public void sb21b(@FormData(name="F", schema=@Schema(" type:'b' ")) String f) {}
-
- public static class SB21c {
- public String f1;
- }
-
- @RestMethod(name=GET,path="/schema3")
- public void sb21c(@FormData("F") SB21c b) {}
-
- public static class SB21d extends LinkedList<String> {
- private static final long serialVersionUID = 1L;
- }
-
- @RestMethod(name=GET,path="/schema4")
- public void sb21d(@FormData("F") SB21d b) {}
-
- public static class SB21e {}
-
- @RestMethod(name=GET,path="/schema5")
- public void sb21e(@FormData("F") SB21e b) {}
-
- @RestMethod(name=GET,path="/schema6")
- public void sb21f(@FormData("F") Integer b) {}
-
- @RestMethod(name=GET,path="/schema7")
- public void sb21g(@FormData("F") Boolean b) {}
+ @RestMethod(name=GET,path="/api")
+ public void ta02(
+ @FormData(
+ name="F",
+ api={
+ "description:'a\nb',",
+ "required:'true',",
+ "type:'a',",
+ "format:'a',",
+ "pattern:'a',",
+ "collectionFormat:'a',",
+ "maximum:'1',",
+ "minimum:'1',",
+ "multipleOf:'1',",
+ "maxLength:'1',",
+ "minLength:'1',",
+ "maxItems:'1',",
+ "minItems:'1',",
+ "allowEmptyValue:'true',",
+ "exclusiveMaximum:'true',",
+ "exclusiveMinimum:'true',",
+ "uniqueItems:'true',",
+ "schema:{type:'a'},",
+ "default:'a',",
+ "enum:' a,b ',",
+ "items:{type:'a'},",
+ "example:'a'"
+ }
+ ) String f) {}
- @RestMethod(name=GET,path="/_default2")
- public void sb24(@FormData(name="F", _default={"a","b"}) String f) {}
+ @RestMethod(name=GET,path="/mixed")
+ public void ta03(
+ @FormData(
+ name="F",
+ api={
+ "description:'b\nc',",
+ "required:'false',",
+ "type:'b',",
+ "format:'b',",
+ "pattern:'b',",
+ "collectionFormat:'b',",
+ "maximum:'2',",
+ "minimum:'2',",
+ "multipleOf:'2',",
+ "maxLength:'2',",
+ "minLength:'2',",
+ "maxItems:'2',",
+ "minItems:'2',",
+ "allowEmptyValue:'false',",
+ "exclusiveMaximum:'false',",
+ "exclusiveMinimum:'false',",
+ "uniqueItems:'false',",
+ "schema:{type:'b'},",
+ "default:'b',",
+ "enum:' b,c ',",
+ "items:{type:'b'},",
+ "example:'b'"
+ },
+ description={"a","b"},
+ required="true",
+ type="a",
+ format="a",
+ pattern="a",
+ collectionFormat="a",
+ maximum="1",
+ minimum="1",
+ multipleOf="1",
+ maxLength="1",
+ minLength="1",
+ maxItems="1",
+ minItems="1",
+ allowEmptyValue="true",
+ exclusiveMaximum="true",
+ exclusiveMinimum="true",
+ uniqueItems="true",
+ schema=@Schema(type="a"),
+ _default="a",
+ _enum="a,b",
+ items=@Items(type="a"),
+ example="'a'"
+ ) String f) {}
- @RestMethod(name=GET,path="/_enum2")
- public void sb26(@FormData(name="F", _enum={" ['a','b'] "}) String f) {}
+ @RestMethod(name=GET,path="/value")
+ public void ta04(@FormData("F") String f) {}
+
+ @RestMethod(name=GET,path="/default")
+ public void ta05(@FormData(name="F", _default={"a","b"}) String f) {}
- @RestMethod(name=GET,path="/items2")
- public void sb28(@FormData(name="F", items=@Items(" type:'b' ")) String f) {}
+ @RestMethod(name=GET,path="/enum")
+ public void ta06(@FormData(name="F", _enum={" ['a','b'] "}) String f) {}
- @RestMethod(name=GET,path="/example2")
- public void sb30(@FormData(name="F", example="{f1:'a'}") String f) {}
+ @RestMethod(name=GET,path="/items")
+ public void ta07(@FormData(name="F", items=@Items(" type:'b' ")) String f) {}
}
@Test
- public void sb00_FormData_onParameter_basic() throws Exception {
- ParameterInfo x = getSwagger(new SB()).getPaths().get("/basic").get("get").getParameter("formData", "F");
+ public void ta01_FormData_onParameter_basic() throws Exception {
+ ParameterInfo x = getSwagger(new TA()).getPaths().get("/basic").get("get").getParameter("formData", "F");
assertEquals("F", x.getName());
assertEquals("a\nb", x.getDescription());
assertObjectEquals("true", x.getRequired());
@@ -437,58 +646,158 @@ public class FormDataAnnotationTest {
assertObjectEquals("'a'", x.getExample());
}
@Test
- public void sb02_FormData_onParameter_value() throws Exception {
- ParameterInfo x = getSwagger(new SB()).getPaths().get("/value").get("get").getParameter("formData", "F");
+ public void ta02_FormData_onParameter_api() throws Exception {
+ ParameterInfo x = getSwagger(new TA()).getPaths().get("/api").get("get").getParameter("formData", "F");
+ assertEquals("F", x.getName());
+ assertEquals("a\nb", x.getDescription());
+ assertObjectEquals("true", x.getRequired());
+ assertEquals("a", x.getType());
+ assertEquals("a", x.getFormat());
+ assertEquals("a", x.getPattern());
+ assertEquals("a", x.getCollectionFormat());
+ assertObjectEquals("1", x.getMaximum());
+ assertObjectEquals("1", x.getMinimum());
+ assertObjectEquals("1", x.getMultipleOf());
+ assertObjectEquals("1", x.getMaxLength());
+ assertObjectEquals("1", x.getMinLength());
+ assertObjectEquals("1", x.getMaxItems());
+ assertObjectEquals("1", x.getMinItems());
+ assertObjectEquals("true", x.getAllowEmptyValue());
+ assertObjectEquals("true", x.getExclusiveMaximum());
+ assertObjectEquals("true", x.getExclusiveMinimum());
+ assertObjectEquals("true", x.getUniqueItems());
+ assertObjectEquals("{type:'a'}", x.getSchema());
+ assertEquals("a", x.getDefault());
+ assertObjectEquals("['a','b']", x.getEnum());
+ assertObjectEquals("{type:'a'}", x.getItems());
+ assertObjectEquals("'a'", x.getExample());
+ }
+ @Test
+ public void ta03_FormData_onParameter_mixed() throws Exception {
+ ParameterInfo x = getSwagger(new TA()).getPaths().get("/mixed").get("get").getParameter("formData", "F");
+ assertEquals("F", x.getName());
+ assertEquals("a\nb", x.getDescription());
+ assertObjectEquals("true", x.getRequired());
+ assertEquals("a", x.getType());
+ assertEquals("a", x.getFormat());
+ assertEquals("a", x.getPattern());
+ assertEquals("a", x.getCollectionFormat());
+ assertObjectEquals("1", x.getMaximum());
+ assertObjectEquals("1", x.getMinimum());
+ assertObjectEquals("1", x.getMultipleOf());
+ assertObjectEquals("1", x.getMaxLength());
+ assertObjectEquals("1", x.getMinLength());
+ assertObjectEquals("1", x.getMaxItems());
+ assertObjectEquals("1", x.getMinItems());
+ assertObjectEquals("true", x.getAllowEmptyValue());
+ assertObjectEquals("true", x.getExclusiveMaximum());
+ assertObjectEquals("true", x.getExclusiveMinimum());
+ assertObjectEquals("true", x.getUniqueItems());
+ assertObjectEquals("{type:'a'}", x.getSchema());
+ assertEquals("a", x.getDefault());
+ assertObjectEquals("['a','b']", x.getEnum());
+ assertObjectEquals("{type:'a'}", x.getItems());
+ assertObjectEquals("'a'", x.getExample());
+ }
+ @Test
+ public void ta04_FormData_onParameter_value() throws Exception {
+ ParameterInfo x = getSwagger(new TA()).getPaths().get("/value").get("get").getParameter("formData", "F");
assertEquals("F", x.getName());
}
@Test
- public void sb21b_FormData_onParameter_schema2() throws Exception {
- ParameterInfo x = getSwagger(new SB()).getPaths().get("/schema2").get("get").getParameter("formData", "F");
+ public void ta05_FormData_onParameter_default() throws Exception {
+ ParameterInfo x = getSwagger(new TA()).getPaths().get("/default").get("get").getParameter("formData", "F");
+ assertEquals("a\nb", x.getDefault());
+ }
+ @Test
+ public void ta06_FormData_onParameter_enum() throws Exception {
+ ParameterInfo x = getSwagger(new TA()).getPaths().get("/enum").get("get").getParameter("formData", "F");
+ assertObjectEquals("['a','b']", x.getEnum());
+ }
+ @Test
+ public void ta07_FormData_onParameter_items() throws Exception {
+ ParameterInfo x = getSwagger(new TA()).getPaths().get("/items").get("get").getParameter("formData", "F");
+ assertObjectEquals("{type:'b'}", x.getItems());
+ }
+
+ //-----------------------------------------------------------------------------------------------------------------
+ // Schema
+ //-----------------------------------------------------------------------------------------------------------------
+
+ @RestResource
+ public static class TB {
+
+ @RestMethod(name=GET,path="/schemaValue")
+ public void tb01(@FormData(name="F", schema=@Schema(" type:'b' ")) String f) {}
+
+ public static class TB02 {
+ public String f1;
+ }
+ @RestMethod(name=GET,path="/autoDetectBean")
+ public void tb02(@FormData("F") TB02 b) {}
+
+ public static class TB03 extends LinkedList<String> {
+ private static final long serialVersionUID = 1L;
+ }
+ @RestMethod(name=GET,path="/autoDetectList")
+ public void tb03(@FormData("F") TB03 b) {}
+
+ public static class TB04 {}
+ @RestMethod(name=GET,path="/autoDetectStringObject")
+ public void tb04(@FormData("F") TB04 b) {}
+
+ @RestMethod(name=GET,path="/autoDetectInteger")
+ public void tb05(@FormData("F") Integer b) {}
+
+ @RestMethod(name=GET,path="/autoDetectBoolean")
+ public void tb06(@FormData("F") Boolean b) {}
+ }
+
+ @Test
+ public void tb01_FormData_onParameter_schemaValue() throws Exception {
+ ParameterInfo x = getSwagger(new TB()).getPaths().get("/schemaValue").get("get").getParameter("formData", "F");
assertObjectEquals("{type:'b'}", x.getSchema());
}
@Test
- public void sb21c_FormData_onParameter_schema3() throws Exception {
- ParameterInfo x = getSwagger(new SB()).getPaths().get("/schema3").get("get").getParameter("formData", "F");
+ public void tb02_FormData_onParameter_autoDetectBean() throws Exception {
+ ParameterInfo x = getSwagger(new TB()).getPaths().get("/autoDetectBean").get("get").getParameter("formData", "F");
assertObjectEquals("{type:'object',properties:{f1:{type:'string'}}}", x.getSchema());
}
@Test
- public void sb21d_FormData_onParameter_schema4() throws Exception {
- ParameterInfo x = getSwagger(new SB()).getPaths().get("/schema4").get("get").getParameter("formData", "F");
+ public void tb03_FormData_onParameter_autoDetectList() throws Exception {
+ ParameterInfo x = getSwagger(new TB()).getPaths().get("/autoDetectList").get("get").getParameter("formData", "F");
assertObjectEquals("{type:'array',items:{type:'string'}}", x.getSchema());
}
@Test
- public void sb21e_FormData_onParameter_schema5() throws Exception {
- ParameterInfo x = getSwagger(new SB()).getPaths().get("/schema5").get("get").getParameter("formData", "F");
+ public void tb04_FormData_onParameter_autoDetectStringObject() throws Exception {
+ ParameterInfo x = getSwagger(new TB()).getPaths().get("/autoDetectStringObject").get("get").getParameter("formData", "F");
assertObjectEquals("{type:'string'}", x.getSchema());
}
@Test
- public void sb21f_FormData_onParameter_schema6() throws Exception {
- ParameterInfo x = getSwagger(new SB()).getPaths().get("/schema6").get("get").getParameter("formData", "F");
+ public void tb05_FormData_onParameter_autoDetectInteger() throws Exception {
+ ParameterInfo x = getSwagger(new TB()).getPaths().get("/autoDetectInteger").get("get").getParameter("formData", "F");
assertObjectEquals("{format:'int32',type:'integer'}", x.getSchema());
}
@Test
- public void sb21g_FormData_onParameter_schema7() throws Exception {
- ParameterInfo x = getSwagger(new SB()).getPaths().get("/schema7").get("get").getParameter("formData", "F");
+ public void tb06_FormData_onParameter_autoDetectBoolean() throws Exception {
+ ParameterInfo x = getSwagger(new TB()).getPaths().get("/autoDetectBoolean").get("get").getParameter("formData", "F");
assertObjectEquals("{type:'boolean'}", x.getSchema());
}
- @Test
- public void sb24_FormData_onParameter__default2() throws Exception {
- ParameterInfo x = getSwagger(new SB()).getPaths().get("/_default2").get("get").getParameter("formData", "F");
- assertEquals("a\nb", x.getDefault());
- }
- @Test
- public void sb26_FormData_onParameter__enum2() throws Exception {
- ParameterInfo x = getSwagger(new SB()).getPaths().get("/_enum2").get("get").getParameter("formData", "F");
- assertObjectEquals("['a','b']", x.getEnum());
- }
- @Test
- public void sb28_FormData_onParameter_items2() throws Exception {
- ParameterInfo x = getSwagger(new SB()).getPaths().get("/items2").get("get").getParameter("formData", "F");
- assertObjectEquals("{type:'b'}", x.getItems());
+
+ //-----------------------------------------------------------------------------------------------------------------
+ // Examples
+ //-----------------------------------------------------------------------------------------------------------------
+
+ @RestResource
+ public static class TC {
+
+ @RestMethod(name=GET,path="/example")
+ public void tc01(@FormData(name="F", example="{f1:'a'}") String f) {}
}
+
@Test
- public void sb30_FormData_onParameter_example2() throws Exception {
- ParameterInfo x = getSwagger(new SB()).getPaths().get("/example2").get("get").getParameter("formData", "F");
+ public void tc01_FormData_onParameter_example() throws Exception {
+ ParameterInfo x = getSwagger(new TC()).getPaths().get("/example").get("get").getParameter("formData", "F");
assertObjectEquals("{f1:'a'}", x.getExample());
}
}
diff --git a/juneau-rest/juneau-rest-server/src/test/java/org/apache/juneau/rest/annotation/HeaderAnnotationTest.java b/juneau-rest/juneau-rest-server/src/test/java/org/apache/juneau/rest/annotation/HeaderAnnotationTest.java
index 276dca2..9e8d4eb 100644
--- a/juneau-rest/juneau-rest-server/src/test/java/org/apache/juneau/rest/annotation/HeaderAnnotationTest.java
+++ b/juneau-rest/juneau-rest-server/src/test/java/org/apache/juneau/rest/annotation/HeaderAnnotationTest.java
@@ -47,7 +47,11 @@ public class HeaderAnnotationTest {
// @Header on POJO
//=================================================================================================================
- @RestResource()
+ //-----------------------------------------------------------------------------------------------------------------
+ // Basic tests
+ //-----------------------------------------------------------------------------------------------------------------
+
+ @RestResource
public static class SA {
@Header(
@@ -75,64 +79,113 @@ public class HeaderAnnotationTest {
items=@Items(type="a"),
schema=@Schema(type="a")
)
- public static class SA00 {
- public SA00(String x) {}
+ public static class SA01 {
+ public SA01(String x) {}
}
-
@RestMethod(name=GET,path="/basic")
- public void sa00(SA00 h) {}
+ public void sa01(SA01 h) {}
- @Header(name="H", _enum="['A','B','C']")
- public static class SA03 {}
-
- @RestMethod(name=GET,path="/_enum2")
- public void sa03(SA03 h) {}
-
- @Header(name="H", example="{f1:'a'}")
- public static class SA08b {
- public String f1;
+ @Header(
+ name="H",
+ api={
+ "default:'a',",
+ "allowEmptyValue:'true',",
+ "collectionFormat:'A',",
+ "description:'a\nb',",
+ "exclusiveMaximum:'true',",
+ "exclusiveMinimum:'true',",
+ "format:'a',",
+ "maximum:'1',",
+ "maxItems:'1',",
+ "maxLength:'1',",
+ "minimum:'1',",
+ "minItems:'1',",
+ "minLength:'1',",
+ "multipleOf:'1',",
+ "pattern:'a',",
+ "required:'true',",
+ "type:'a',",
+ "uniqueItems:'true',",
+ "enum:'A,B,C',",
+ "example:'a',",
+ "items:{type:'a'},",
+ "schema:{type:'a'}"
+ }
+ )
+ public static class SA02 {
+ public SA02(String x) {}
+ }
+ @RestMethod(name=GET,path="/api")
+ public void sa02(SA02 h) {}
+
+ @Header(
+ name="H",
+ api={
+ "default:'b',",
+ "allowEmptyValue:'false',",
+ "collectionFormat:'b',",
+ "description:'b\nc',",
+ "exclusiveMaximum:'false',",
+ "exclusiveMinimum:'false',",
+ "format:'b',",
+ "maximum:'2',",
+ "maxItems:'2',",
+ "maxLength:'2',",
+ "minimum:'2',",
+ "minItems:'2',",
+ "minLength:'2',",
+ "multipleOf:'2',",
+ "pattern:'b',",
+ "required:'false',",
+ "type:'v',",
+ "uniqueItems:'false',",
+ "enum:'D,E,F',",
+ "example:'b',",
+ "items:{type:'b'},",
+ "schema:{type:'b'}"
+ },
+ _default="a",
+ allowEmptyValue="true",
+ collectionFormat="A",
+ description={"a","b"},
+ exclusiveMaximum="true",
+ exclusiveMinimum="true",
+ format="a",
+ maximum="1",
+ maxItems="1",
+ maxLength="1",
+ minimum="1",
+ minItems="1",
+ minLength="1",
+ multipleOf="1",
+ pattern="a",
+ required="true",
+ type="a",
+ uniqueItems="true",
+ _enum="A,B,C",
+ example="a",
+ items=@Items(type="a"),
+ schema=@Schema(type="a")
+ )
+ public static class SA03 {
+ public SA03(String x) {}
}
+ @RestMethod(name=GET,path="/mixed")
+ public void sa03(SA03 h) {}
- @RestMethod(name=GET,path="/example2")
- public void sa08b(SA08b h) {}
+ @Header(name="H", _enum="['A','B','C']")
+ public static class SA04 {}
+ @RestMethod(name=GET,path="/enum")
+ public void sa04(SA04 h) {}
@Header(name="H", items=@Items(" type:'a' "))
- public static class SA13 {}
-
- @RestMethod(name=GET,path="/items2")
- public void sa13(SA13 h) {}
-
- @Header(name="H", schema=@Schema(" type:'a' "))
- public static class SA23b {}
-
- @RestMethod(name=GET,path="/schema2")
- public void sa23(SA23b h) {}
-
- @Header(name="H")
- public static class SA23c {
- public String f1;
- }
-
- @RestMethod(name=GET,path="/schema3")
- public void sa23c(SA23c b) {}
-
- @Header(name="H")
- public static class SA23d extends LinkedList<String> {
- private static final long serialVersionUID = 1L;
- }
-
- @RestMethod(name=GET,path="/schema4")
- public void sa23d(SA23d b) {}
-
- @Header(name="H")
- public static class SA23e {}
-
- @RestMethod(name=GET,path="/schema5")
- public void sa23e(SA23e b) {}
+ public static class SA05 {}
+ @RestMethod(name=GET,path="/items")
+ public void sa05(SA05 h) {}
}
-
+
@Test
- public void sa00_Header_onPojo_basic() throws Exception {
+ public void sa01_Header_onPojo_basic() throws Exception {
ParameterInfo x = getSwagger(new SA()).getPaths().get("/basic").get("get").getParameter("header", "H");
assertObjectEquals("'a'", x.getDefault());
assertEquals(true, x.getAllowEmptyValue());
@@ -158,50 +211,154 @@ public class HeaderAnnotationTest {
assertObjectEquals("{type:'a'}", x.getSchema());
}
@Test
- public void sa03_Header_onPojo_enum2() throws Exception {
- ParameterInfo x = getSwagger(new SA()).getPaths().get("/_enum2").get("get").getParameter("header", "H");
+ public void sa02_Header_onPojo_api() throws Exception {
+ ParameterInfo x = getSwagger(new SA()).getPaths().get("/api").get("get").getParameter("header", "H");
+ assertObjectEquals("'a'", x.getDefault());
+ assertEquals(true, x.getAllowEmptyValue());
+ assertEquals("A", x.getCollectionFormat());
+ assertEquals("a\nb", x.getDescription());
+ assertEquals(true, x.getExclusiveMaximum());
+ assertEquals(true, x.getExclusiveMinimum());
+ assertEquals("a", x.getFormat());
+ assertObjectEquals("1", x.getMaximum());
+ assertObjectEquals("1", x.getMaxItems());
+ assertObjectEquals("1", x.getMaxLength());
+ assertObjectEquals("1", x.getMinimum());
+ assertObjectEquals("1", x.getMinItems());
+ assertObjectEquals("1", x.getMinLength());
+ assertObjectEquals("1", x.getMultipleOf());
+ assertObjectEquals("'a'", x.getPattern());
+ assertObjectEquals("true", x.getRequired());
+ assertObjectEquals("'a'", x.getType());
+ assertObjectEquals("true", x.getUniqueItems());
assertObjectEquals("['A','B','C']", x.getEnum());
+ assertEquals("a", x.getExample());
+ assertObjectEquals("{type:'a'}", x.getItems());
+ assertObjectEquals("{type:'a'}", x.getSchema());
}
@Test
- public void sa08b_Header_onPojo_example2() throws Exception {
- ParameterInfo x = getSwagger(new SA()).getPaths().get("/example2").get("get").getParameter("header", "H");
- assertObjectEquals("{f1:'a'}", x.getExample());
+ public void sa03_Header_onPojo_mixed() throws Exception {
+ ParameterInfo x = getSwagger(new SA()).getPaths().get("/mixed").get("get").getParameter("header", "H");
+ assertObjectEquals("'a'", x.getDefault());
+ assertEquals(true, x.getAllowEmptyValue());
+ assertEquals("A", x.getCollectionFormat());
+ assertEquals("a\nb", x.getDescription());
+ assertEquals(true, x.getExclusiveMaximum());
+ assertEquals(true, x.getExclusiveMinimum());
+ assertEquals("a", x.getFormat());
+ assertObjectEquals("1", x.getMaximum());
+ assertObjectEquals("1", x.getMaxItems());
+ assertObjectEquals("1", x.getMaxLength());
+ assertObjectEquals("1", x.getMinimum());
+ assertObjectEquals("1", x.getMinItems());
+ assertObjectEquals("1", x.getMinLength());
+ assertObjectEquals("1", x.getMultipleOf());
+ assertObjectEquals("'a'", x.getPattern());
+ assertObjectEquals("true", x.getRequired());
+ assertObjectEquals("'a'", x.getType());
+ assertObjectEquals("true", x.getUniqueItems());
+ assertObjectEquals("['A','B','C']", x.getEnum());
+ assertEquals("a", x.getExample());
+ assertObjectEquals("{type:'a'}", x.getItems());
+ assertObjectEquals("{type:'a'}", x.getSchema());
}
@Test
- public void sa13_Header_onPojo_items2() throws Exception {
- ParameterInfo x = getSwagger(new SA()).getPaths().get("/items2").get("get").getParameter("header", "H");
+ public void sa04_Header_onPojo_enum() throws Exception {
+ ParameterInfo x = getSwagger(new SA()).getPaths().get("/enum").get("get").getParameter("header", "H");
+ assertObjectEquals("['A','B','C']", x.getEnum());
+ }
+ @Test
+ public void sa05_Header_onPojo_items() throws Exception {
+ ParameterInfo x = getSwagger(new SA()).getPaths().get("/items").get("get").getParameter("header", "H");
assertObjectEquals("{type:'a'}", x.getItems());
}
+
+ //-----------------------------------------------------------------------------------------------------------------
+ // Schema
+ //-----------------------------------------------------------------------------------------------------------------
+
+ @RestResource
+ public static class SB {
+
+ @Header(name="H", schema=@Schema(" type:'a' "))
+ public static class SB01 {}
+ @RestMethod(name=GET,path="/schemaValue")
+ public void sb01(SB01 h) {}
+
+ @Header(name="H")
+ public static class SB02 {
+ public String f1;
+ }
+ @RestMethod(name=GET,path="/autoDetectBean")
+ public void sb02(SB02 b) {}
+
+ @Header(name="H")
+ public static class SB03 extends LinkedList<String> {
+ private static final long serialVersionUID = 1L;
+ }
+ @RestMethod(name=GET,path="/autoDetectList")
+ public void sb03(SB03 b) {}
+
+ @Header(name="H")
+ public static class SB04 {}
+ @RestMethod(name=GET,path="/autoDetectStringObject")
+ public void sb04(SB04 b) {}
+ }
@Test
- public void sa23b_Header_onPojo_schema2() throws Exception {
- ParameterInfo x = getSwagger(new SA()).getPaths().get("/schema2").get("get").getParameter("header", "H");
+ public void sb01_Header_onPojo_schemaValue() throws Exception {
+ ParameterInfo x = getSwagger(new SB()).getPaths().get("/schemaValue").get("get").getParameter("header", "H");
assertObjectEquals("{type:'a'}", x.getSchema());
}
@Test
- public void sa23c_Header_onPojo_schema3() throws Exception {
- ParameterInfo x = getSwagger(new SA()).getPaths().get("/schema3").get("get").getParameter("header", "H");
+ public void sb02_Header_onPojo_autoDetectBean() throws Exception {
+ ParameterInfo x = getSwagger(new SB()).getPaths().get("/autoDetectBean").get("get").getParameter("header", "H");
assertObjectEquals("{type:'object',properties:{f1:{type:'string'}}}", x.getSchema());
}
@Test
- public void sa23d_Header_onPojo_schema4() throws Exception {
- ParameterInfo x = getSwagger(new SA()).getPaths().get("/schema4").get("get").getParameter("header", "H");
+ public void sb03_Header_onPojo_autoDetectList() throws Exception {
+ ParameterInfo x = getSwagger(new SB()).getPaths().get("/autoDetectList").get("get").getParameter("header", "H");
assertObjectEquals("{type:'array',items:{type:'string'}}", x.getSchema());
}
@Test
- public void sa23e_Header_onPojo_schema5() throws Exception {
- ParameterInfo x = getSwagger(new SA()).getPaths().get("/schema5").get("get").getParameter("header", "H");
+ public void sb04_Header_onPojo_autoDetectStringObject() throws Exception {
+ ParameterInfo x = getSwagger(new SB()).getPaths().get("/autoDetectStringObject").get("get").getParameter("header", "H");
assertObjectEquals("{type:'string'}", x.getSchema());
}
+ //-----------------------------------------------------------------------------------------------------------------
+ // Examples
+ //-----------------------------------------------------------------------------------------------------------------
+
+ @RestResource
+ public static class SC {
+
+ @Header(name="H", example="{f1:'a'}")
+ public static class SC01 {
+ public String f1;
+ }
+ @RestMethod(name=GET,path="/example")
+ public void sc01(SC01 h) {}
+ }
+
+ @Test
+ public void sc01_Header_onPojo_example() throws Exception {
+ ParameterInfo x = getSwagger(new SC()).getPaths().get("/example").get("get").getParameter("header", "H");
+ assertObjectEquals("{f1:'a'}", x.getExample());
+ }
+
//=================================================================================================================
- // @Header on sarameter
+ // @Header on parameter
//=================================================================================================================
- @RestResource()
- public static class SB {
+ //-----------------------------------------------------------------------------------------------------------------
+ // Basic tests
+ //-----------------------------------------------------------------------------------------------------------------
+
+ @RestResource
+ public static class TA {
@RestMethod(name=GET,path="/basic")
- public void sb00(
+ public void ta01(
@Header(
name="H",
description={"a","b"},
@@ -227,53 +384,127 @@ public class HeaderAnnotationTest {
example="a,b"
) String h) {}
- @RestMethod(name=GET,path="/value")
- public void sb02(@Header("H") String h) {}
-
- @RestMethod(name=GET,path="/schema2")
- public void sb19b(@Header(name="H", schema=@Schema(" type:'b' ")) String h) {}
-
- public static class SB19c {
- public String f1;
- }
-
- @RestMethod(name=GET,path="/schema3")
- public void sb19c(@Header("H") SB19c b) {}
-
- public static class SB19d extends LinkedList<String> {
- private static final long serialVersionUID = 1L;
- }
-
- @RestMethod(name=GET,path="/schema4")
- public void sb19d(@Header("H") SB19d b) {}
-
- public static class SB19e {}
-
- @RestMethod(name=GET,path="/schema5")
- public void sb19e(@Header("H") SB19e b) {}
-
- @RestMethod(name=GET,path="/schema6")
- public void sb19f(@Header("H") Integer b) {}
-
- @RestMethod(name=GET,path="/schema7")
- public void sb19g(@Header("H") Boolean b) {}
+ @RestMethod(name=GET,path="/api")
+ public void ta02(
+ @Header(
+ name="H",
+ api={
+ "description:'a\nb',",
+ "type:'a',",
+ "format:'a',",
+ "pattern:'a',",
+ "collectionFormat:'a',",
+ "maximum:'1',",
+ "minimum:'1',",
+ "multipleOf:'1',",
+ "maxLength:'1',",
+ "minLength:'1',",
+ "maxItems:'1',",
+ "minItems:'1',",
+ "allowEmptyValue:'true',",
+ "exclusiveMaximum:'true',",
+ "exclusiveMinimum:'true',",
+ "uniqueItems:'true',",
+ "schema:{type:'a'},",
+ "default:'a',",
+ "enum:'a,b',",
+ "items:{type:'a'},",
+ "example:'a,b'"
+ }
+ ) String h) {}
- @RestMethod(name=GET,path="/_default2")
- public void sb20b(@Header(name="H", _default={"a","b"}) String h) {}
+ @RestMethod(name=GET,path="/mixed")
+ public void ta03(
+ @Header(
+ name="H",
+ api={
+ "description:'b\nc',",
+ "type:'b',",
+ "format:'b',",
+ "pattern:'b',",
+ "collectionFormat:'b',",
+ "maximum:'2',",
+ "minimum:'2',",
+ "multipleOf:'2',",
+ "maxLength:'2',",
+ "minLength:'2',",
+ "maxItems:'2',",
+ "minItems:'2',",
+ "allowEmptyValue:'false',",
+ "exclusiveMaximum:'false',",
+ "exclusiveMinimum:'false',",
+ "uniqueItems:'false',",
+ "schema:{type:'b'},",
+ "default:'b',",
+ "enum:'b,c',",
+ "items:{type:'b'},",
+ "example:'b,c'"
+ },
+ description={"a","b"},
+ type="a",
+ format="a",
+ pattern="a",
+ collectionFormat="a",
+ maximum="1",
+ minimum="1",
+ multipleOf="1",
+ maxLength="1",
+ minLength="1",
+ maxItems="1",
+ minItems="1",
+ allowEmptyValue="true",
+ exclusiveMaximum="true",
+ exclusiveMinimum="true",
+ uniqueItems="true",
+ schema=@Schema(type="a"),
+ _default="a",
+ _enum="a,b",
+ items=@Items(type="a"),
+ example="a,b"
+ ) String h) {}
- @RestMethod(name=GET,path="/_enum2")
- public void sb21b(@Header(name="H", _enum={"['a','b']"}) String h) {}
+ @RestMethod(name=GET,path="/value")
+ public void ta04(@Header("H") String h) {}
+
+ @RestMethod(name=GET,path="/default")
+ public void ta05(@Header(name="H", _default={"a","b"}) String h) {}
- @RestMethod(name=GET,path="/items2")
- public void sb22b(@Header(name="H", items=@Items(" type:'b' ")) String h) {}
+ @RestMethod(name=GET,path="/enum")
+ public void ta06(@Header(name="H", _enum={"['a','b']"}) String h) {}
- @RestMethod(name=GET,path="/example2")
- public void sb23b(@Header(name="H", example={"a","b"}) String h) {}
+ @RestMethod(name=GET,path="/items")
+ public void ta07(@Header(name="H", items=@Items(" type:'b' ")) String h) {}
}
@Test
- public void sb00_Header_onParameter_basic() throws Exception {
- ParameterInfo x = getSwagger(new SB()).getPaths().get("/basic").get("get").getParameter("header", "H");
+ public void ta01_Header_onParameter_basic() throws Exception {
+ ParameterInfo x = getSwagger(new TA()).getPaths().get("/basic").get("get").getParameter("header", "H");
+ assertEquals("H", x.getName());
+ assertEquals("a\nb", x.getDescription());
+ assertEquals("a", x.getType());
+ assertEquals("a", x.getFormat());
+ assertEquals("a", x.getPattern());
+ assertEquals("a", x.getCollectionFormat());
+ assertObjectEquals("1", x.getMaximum());
+ assertObjectEquals("1", x.getMinimum());
+ assertObjectEquals("1", x.getMultipleOf());
+ assertObjectEquals("1", x.getMaxLength());
+ assertObjectEquals("1", x.getMinLength());
+ assertObjectEquals("1", x.getMaxItems());
+ assertObjectEquals("1", x.getMinItems());
+ assertObjectEquals("true", x.getAllowEmptyValue());
+ assertObjectEquals("true", x.getExclusiveMaximum());
+ assertObjectEquals("true", x.getExclusiveMinimum());
+ assertObjectEquals("true", x.getUniqueItems());
+ assertObjectEquals("{type:'a'}", x.getSchema());
+ assertObjectEquals("'a'", x.getDefault());
+ assertObjectEquals("['a','b']", x.getEnum());
+ assertObjectEquals("{type:'a'}", x.getItems());
+ assertEquals("a,b", x.getExample());
+ }
+ @Test
+ public void ta02_Header_onParameter_api() throws Exception {
+ ParameterInfo x = getSwagger(new TA()).getPaths().get("/api").get("get").getParameter("header", "H");
assertEquals("H", x.getName());
assertEquals("a\nb", x.getDescription());
assertEquals("a", x.getType());
@@ -298,58 +529,130 @@ public class HeaderAnnotationTest {
assertEquals("a,b", x.getExample());
}
@Test
- public void sb02_Header_onParameter_value() throws Exception {
- ParameterInfo x = getSwagger(new SB()).getPaths().get("/value").get("get").getParameter("header", "H");
+ public void ta03_Header_onParameter_mixed() throws Exception {
+ ParameterInfo x = getSwagger(new TA()).getPaths().get("/mixed").get("get").getParameter("header", "H");
assertEquals("H", x.getName());
+ assertEquals("a\nb", x.getDescription());
+ assertEquals("a", x.getType());
+ assertEquals("a", x.getFormat());
+ assertEquals("a", x.getPattern());
+ assertEquals("a", x.getCollectionFormat());
+ assertObjectEquals("1", x.getMaximum());
+ assertObjectEquals("1", x.getMinimum());
+ assertObjectEquals("1", x.getMultipleOf());
+ assertObjectEquals("1", x.getMaxLength());
+ assertObjectEquals("1", x.getMinLength());
+ assertObjectEquals("1", x.getMaxItems());
+ assertObjectEquals("1", x.getMinItems());
+ assertObjectEquals("true", x.getAllowEmptyValue());
+ assertObjectEquals("true", x.getExclusiveMaximum());
+ assertObjectEquals("true", x.getExclusiveMinimum());
+ assertObjectEquals("true", x.getUniqueItems());
+ assertObjectEquals("{type:'a'}", x.getSchema());
+ assertObjectEquals("'a'", x.getDefault());
+ assertObjectEquals("['a','b']", x.getEnum());
+ assertObjectEquals("{type:'a'}", x.getItems());
+ assertEquals("a,b", x.getExample());
+ }
+ @Test
+ public void ta04_Header_onParameter_value() throws Exception {
+ ParameterInfo x = getSwagger(new TA()).getPaths().get("/value").get("get").getParameter("header", "H");
+ assertEquals("H", x.getName());
+ }
+ @Test
+ public void ta05_Header_onParameter_default() throws Exception {
+ ParameterInfo x = getSwagger(new TA()).getPaths().get("/default").get("get").getParameter("header", "H");
+ assertObjectEquals("'a\\nb'", x.getDefault());
}
@Test
- public void sb19b_Header_onParameter_schema2() throws Exception {
- ParameterInfo x = getSwagger(new SB()).getPaths().get("/schema2").get("get").getParameter("header", "H");
+ public void ta06_Header_onParameter_enum() throws Exception {
+ ParameterInfo x = getSwagger(new TA()).getPaths().get("/enum").get("get").getParameter("header", "H");
+ assertObjectEquals("['a','b']", x.getEnum());
+ }
+ @Test
+ public void ta07_Header_onParameter_items() throws Exception {
+ ParameterInfo x = getSwagger(new TA()).getPaths().get("/items").get("get").getParameter("header", "H");
+ assertObjectEquals("{type:'b'}", x.getItems());
+ }
+
+ //-----------------------------------------------------------------------------------------------------------------
+ // Schema
+ //-----------------------------------------------------------------------------------------------------------------
+
+ @RestResource
+ public static class TB {
+
+ @RestMethod(name=GET,path="/schemaValue")
+ public void tb01(@Header(name="H", schema=@Schema(" type:'b' ")) String h) {}
+
+ public static class TB02 {
+ public String f1;
+ }
+ @RestMethod(name=GET,path="/autoDetectBean")
+ public void tb02(@Header("H") TB02 b) {}
+
+ public static class TB03 extends LinkedList<String> {
+ private static final long serialVersionUID = 1L;
+ }
+ @RestMethod(name=GET,path="/autoDetectList")
+ public void tb03(@Header("H") TB03 b) {}
+
+ public static class TB04 {}
+ @RestMethod(name=GET,path="/autoDetectStringObject")
+ public void tb04(@Header("H") TB04 b) {}
+
+ @RestMethod(name=GET,path="/autoDetectInteger")
+ public void tb05(@Header("H") Integer b) {}
+
+ @RestMethod(name=GET,path="/autoDetectBoolean")
+ public void tbo6(@Header("H") Boolean b) {}
+ }
+
+ @Test
+ public void tb01_Header_onParameter_schema2() throws Exception {
+ ParameterInfo x = getSwagger(new TB()).getPaths().get("/schemaValue").get("get").getParameter("header", "H");
assertObjectEquals("{type:'b'}", x.getSchema());
}
@Test
- public void sb19c_Header_onParameter_schema3() throws Exception {
- ParameterInfo x = getSwagger(new SB()).getPaths().get("/schema3").get("get").getParameter("header", "H");
+ public void tb02_Header_onParameter_schema3() throws Exception {
+ ParameterInfo x = getSwagger(new TB()).getPaths().get("/autoDetectBean").get("get").getParameter("header", "H");
assertObjectEquals("{type:'object',properties:{f1:{type:'string'}}}", x.getSchema());
}
@Test
- public void sb19d_Header_onParameter_schema4() throws Exception {
- ParameterInfo x = getSwagger(new SB()).getPaths().get("/schema4").get("get").getParameter("header", "H");
+ public void tb03_Header_onParameter_schema4() throws Exception {
+ ParameterInfo x = getSwagger(new TB()).getPaths().get("/autoDetectList").get("get").getParameter("header", "H");
assertObjectEquals("{type:'array',items:{type:'string'}}", x.getSchema());
}
@Test
- public void sb19e_Header_onParameter_schema5() throws Exception {
- ParameterInfo x = getSwagger(new SB()).getPaths().get("/schema5").get("get").getParameter("header", "H");
+ public void tb04_Header_onParameter_schema5() throws Exception {
+ ParameterInfo x = getSwagger(new TB()).getPaths().get("/autoDetectStringObject").get("get").getParameter("header", "H");
assertObjectEquals("{type:'string'}", x.getSchema());
}
@Test
- public void sb19f_Header_onParameter_schema6() throws Exception {
- ParameterInfo x = getSwagger(new SB()).getPaths().get("/schema6").get("get").getParameter("header", "H");
+ public void tb05_Header_onParameter_schema6() throws Exception {
+ ParameterInfo x = getSwagger(new TB()).getPaths().get("/autoDetectInteger").get("get").getParameter("header", "H");
assertObjectEquals("{format:'int32',type:'integer'}", x.getSchema());
}
@Test
- public void sb19g_Header_onParameter_schema7() throws Exception {
- ParameterInfo x = getSwagger(new SB()).getPaths().get("/schema7").get("get").getParameter("header", "H");
+ public void tb06_Header_onParameter_schema7() throws Exception {
+ ParameterInfo x = getSwagger(new TB()).getPaths().get("/autoDetectBoolean").get("get").getParameter("header", "H");
assertObjectEquals("{type:'boolean'}", x.getSchema());
}
- @Test
- public void sb20b_Header_onParameter__default2() throws Exception {
- ParameterInfo x = getSwagger(new SB()).getPaths().get("/_default2").get("get").getParameter("header", "H");
- assertObjectEquals("'a\\nb'", x.getDefault());
- }
- @Test
- public void sb21b_Header_onParameter__enum2() throws Exception {
- ParameterInfo x = getSwagger(new SB()).getPaths().get("/_enum2").get("get").getParameter("header", "H");
- assertObjectEquals("['a','b']", x.getEnum());
- }
- @Test
- public void sb22b_Header_onParameter_items2() throws Exception {
- ParameterInfo x = getSwagger(new SB()).getPaths().get("/items2").get("get").getParameter("header", "H");
- assertObjectEquals("{type:'b'}", x.getItems());
+
+ //-----------------------------------------------------------------------------------------------------------------
+ // Examples
+ //-----------------------------------------------------------------------------------------------------------------
+
+ @RestResource
+ public static class TC {
+
+ @RestMethod(name=GET,path="/example")
+ public void tc01(@Header(name="H", example={"a","b"}) String h) {}
}
+
@Test
- public void sb23b_Header_onParameter_example2() throws Exception {
- ParameterInfo x = getSwagger(new SB()).getPaths().get("/example2").get("get").getParameter("header", "H");
+ public void tc01_Header_onParameter_example() throws Exception {
+ ParameterInfo x = getSwagger(new TC()).getPaths().get("/example").get("get").getParameter("header", "H");
assertEquals("a\nb", x.getExample());
}
}
diff --git a/juneau-rest/juneau-rest-server/src/test/java/org/apache/juneau/rest/annotation/PathAnnotationTest.java b/juneau-rest/juneau-rest-server/src/test/java/org/apache/juneau/rest/annotation/PathAnnotationTest.java
index b7bcfe3..7e12106 100644
--- a/juneau-rest/juneau-rest-server/src/test/java/org/apache/juneau/rest/annotation/PathAnnotationTest.java
+++ b/juneau-rest/juneau-rest-server/src/test/java/org/apache/juneau/rest/annotation/PathAnnotationTest.java
@@ -294,7 +294,11 @@ public class PathAnnotationTest {
// @Path on POJO
//=================================================================================================================
- @RestResource()
+ //-----------------------------------------------------------------------------------------------------------------
+ // Basic tests
+ //-----------------------------------------------------------------------------------------------------------------
+
+ @RestResource
public static class SA {
@Path(
@@ -315,67 +319,93 @@ public class PathAnnotationTest {
_enum="a,b",
example="'a'"
)
- public static class SA00 {
- public SA00(String x) {}
+ public static class SA01 {
+ public SA01(String x) {}
}
-
@RestMethod(name=GET,path="/basic/{P}")
- public void sa00(SA00 f) {}
-
- @Path("P")
- public static class SA02 {}
-
- @RestMethod(name=GET,path="/value/{P}")
- public void sa02(SA02 f) {}
+ public void sa01(SA01 f) {}
- @Path(name="P", description="a")
- public static class SA03 {}
-
- @Path(name="P", schema=@Schema(" type:'b' "))
- public static class SA16b {}
-
- @RestMethod(name=GET,path="/schema2/{P}")
- public void sa16b(SA16b f) {}
-
- @Path("P")
- public static class SA16c {
- public String f1;
+ @Path(
+ name="P",
+ api={
+ "description:'a\nb',",
+ "type:'a',",
+ "format:'a',",
+ "pattern:'a',",
+ "maximum:'1',",
+ "minimum:'1',",
+ "multipleOf:'1',",
+ "maxLength:'1',",
+ "minLength:'1',",
+ "allowEmptyValue:'true',",
+ "exclusiveMaximum:'true',",
+ "exclusiveMinimum:'true',",
+ "schema:{type:'a'},",
+ "enum:'a,b',",
+ "example:'a'"
+ }
+ )
+ public static class SA02 {
+ public SA02(String x) {}
}
+ @RestMethod(name=GET,path="/api/{P}")
+ public void sa02(SA02 f) {}
- @RestMethod(name=GET,path="/schema3/{P}")
- public void sa16c(SA16c b) {}
-
- @Path("P")
- public static class SA16d extends LinkedList<String> {
- private static final long serialVersionUID = 1L;
+ @Path(
+ name="P",
+ api={
+ "description:'b\nc',",
+ "type:'b',",
+ "format:'b',",
+ "pattern:'b',",
+ "maximum:'2',",
+ "minimum:'2',",
+ "multipleOf:'2',",
+ "maxLength:'2',",
+ "minLength:'2',",
+ "allowEmptyValue:'false',",
+ "exclusiveMaximum:'false',",
+ "exclusiveMinimum:'false',",
+ "schema:{type:'b'},",
+ "enum:'b,c',",
+ "example:'b'"
+ },
+ description={"a","b"},
+ type="a",
+ format="a",
+ pattern="a",
+ maximum="1",
+ minimum="1",
+ multipleOf="1",
+ maxLength="1",
+ minLength="1",
+ allowEmptyValue="true",
+ exclusiveMaximum="true",
+ exclusiveMinimum="true",
+ schema=@Schema(type="a"),
+ _enum="a,b",
+ example="'a'"
+ )
+ public static class SA03 {
+ public SA03(String x) {}
}
+ @RestMethod(name=GET,path="/mixed/{P}")
+ public void sa03(SA03 f) {}
- @RestMethod(name=GET,path="/schema4/{P}")
- public void sa16d(SA16d b) {}
-
+
@Path("P")
- public static class SA16e {}
-
- @RestMethod(name=GET,path="/schema5/{P}")
- public void sa16e(SA16e b) {}
+ public static class SA04 {}
+ @RestMethod(name=GET,path="/value/{P}")
+ public void sa04(SA04 f) {}
@Path(name="P", _enum={" ['a','b'] "})
public static class SA19 {}
-
- @RestMethod(name=GET,path="/_enum2/{P}")
+ @RestMethod(name=GET,path="/enum/{P}")
public void sa19(SA19 f) {}
-
- @Path(name="P", example={" {f1:'a'} "})
- public static class SA21 {
- public String f1;
- }
-
- @RestMethod(name=GET,path="/example2/{P}")
- public void sa21(SA21 f) {}
}
@Test
- public void sa00_Path_onPojo_basic() throws Exception {
+ public void sa01_Path_onPojo_basic() throws Exception {
ParameterInfo x = getSwagger(new SA()).getPaths().get("/basic/{P}").get("get").getParameter("path", "P");
assertEquals("P", x.getName());
assertEquals("a\nb", x.getDescription());
@@ -395,38 +425,128 @@ public class PathAnnotationTest {
assertObjectEquals("'a'", x.getExample());
}
@Test
- public void sa02_Path_onPojo_value() throws Exception {
+ public void sa02_Path_onPojo_api() throws Exception {
+ ParameterInfo x = getSwagger(new SA()).getPaths().get("/api/{P}").get("get").getParameter("path", "P");
+ assertEquals("P", x.getName());
+ assertEquals("a\nb", x.getDescription());
+ assertEquals("a", x.getType());
+ assertEquals("a", x.getFormat());
+ assertEquals("a", x.getPattern());
+ assertObjectEquals("1", x.getMaximum());
+ assertObjectEquals("1", x.getMinimum());
+ assertObjectEquals("1", x.getMultipleOf());
+ assertObjectEquals("1", x.getMaxLength());
+ assertObjectEquals("1", x.getMinLength());
+ assertObjectEquals("true", x.getAllowEmptyValue());
+ assertObjectEquals("true", x.getExclusiveMaximum());
+ assertObjectEquals("true", x.getExclusiveMinimum());
+ assertObjectEquals("{type:'a'}", x.getSchema());
+ assertObjectEquals("['a','b']", x.getEnum());
+ assertObjectEquals("'a'", x.getExample());
+ }
+ @Test
+ public void sa03_Path_onPojo_mixed() throws Exception {
+ ParameterInfo x = getSwagger(new SA()).getPaths().get("/mixed/{P}").get("get").getParameter("path", "P");
+ assertEquals("P", x.getName());
+ assertEquals("a\nb", x.getDescription());
+ assertEquals("a", x.getType());
+ assertEquals("a", x.getFormat());
+ assertEquals("a", x.getPattern());
+ assertObjectEquals("1", x.getMaximum());
+ assertObjectEquals("1", x.getMinimum());
+ assertObjectEquals("1", x.getMultipleOf());
+ assertObjectEquals("1", x.getMaxLength());
+ assertObjectEquals("1", x.getMinLength());
+ assertObjectEquals("true", x.getAllowEmptyValue());
+ assertObjectEquals("true", x.getExclusiveMaximum());
+ assertObjectEquals("true", x.getExclusiveMinimum());
+ assertObjectEquals("{type:'a'}", x.getSchema());
+ assertObjectEquals("['a','b']", x.getEnum());
+ assertObjectEquals("'a'", x.getExample());
+ }
+ @Test
+ public void sa04_Path_onPojo_value() throws Exception {
ParameterInfo x = getSwagger(new SA()).getPaths().get("/value/{P}").get("get").getParameter("path", "P");
assertEquals("P", x.getName());
}
@Test
- public void sa16b_Path_onPojo_schema2() throws Exception {
- ParameterInfo x = getSwagger(new SA()).getPaths().get("/schema2/{P}").get("get").getParameter("path", "P");
+ public void sa05_Path_onPojo_enum() throws Exception {
+ ParameterInfo x = getSwagger(new SA()).getPaths().get("/enum/{P}").get("get").getParameter("path", "P");
+ assertObjectEquals("['a','b']", x.getEnum());
+ }
+
+ //-----------------------------------------------------------------------------------------------------------------
+ // Schema
+ //-----------------------------------------------------------------------------------------------------------------
+
+ @RestResource
+ public static class SB {
+
+ @Path(name="P", schema=@Schema(" type:'b' "))
+ public static class SB01 {}
+ @RestMethod(name=GET,path="/schemaValue/{P}")
+ public void sb01(SB01 f) {}
+
+ @Path("P")
+ public static class SB02 {
+ public String f1;
+ }
+ @RestMethod(name=GET,path="/autoDetectBean/{P}")
+ public void sb02(SB02 b) {}
+
+ @Path("P")
+ public static class SB03 extends LinkedList<String> {
+ private static final long serialVersionUID = 1L;
+ }
+ @RestMethod(name=GET,path="/autoDetectList/{P}")
+ public void sb03(SB03 b) {}
+
+ @Path("P")
+ public static class SB04 {}
+ @RestMethod(name=GET,path="/autoDetectStringObject/{P}")
+ public void sb04(SB04 b) {}
+ }
+
+ @Test
+ public void sb01_Path_onPojo_schemaValue() throws Exception {
+ ParameterInfo x = getSwagger(new SB()).getPaths().get("/schemaValue/{P}").get("get").getParameter("path", "P");
assertObjectEquals("{type:'b'}", x.getSchema());
}
@Test
- public void sa16c_Path_onPojo_schema3() throws Exception {
- ParameterInfo x = getSwagger(new SA()).getPaths().get("/schema3/{P}").get("get").getParameter("path", "P");
+ public void sb02_Path_onPojo_autoDetectBean() throws Exception {
+ ParameterInfo x = getSwagger(new SB()).getPaths().get("/autoDetectBean/{P}").get("get").getParameter("path", "P");
assertObjectEquals("{type:'object',properties:{f1:{type:'string'}}}", x.getSchema());
}
@Test
- public void sa16d_Path_onPojo_schema4() throws Exception {
- ParameterInfo x = getSwagger(new SA()).getPaths().get("/schema4/{P}").get("get").getParameter("path", "P");
+ public void sb03_Path_onPojo_autoDetectList() throws Exception {
+ ParameterInfo x = getSwagger(new SB()).getPaths().get("/autoDetectList/{P}").get("get").getParameter("path", "P");
assertObjectEquals("{type:'array',items:{type:'string'}}", x.getSchema());
}
@Test
- public void sa16e_Path_onPojo_schema5() throws Exception {
- ParameterInfo x = getSwagger(new SA()).getPaths().get("/schema5/{P}").get("get").getParameter("path", "P");
+ public void sb04_Path_onPojo_sautoDetectStringObject() throws Exception {
+ ParameterInfo x = getSwagger(new SB()).getPaths().get("/autoDetectStringObject/{P}").get("get").getParameter("path", "P");
assertObjectEquals("{type:'string'}", x.getSchema());
}
- @Test
- public void sa19_Path_onPojo__enum2() throws Exception {
- ParameterInfo x = getSwagger(new SA()).getPaths().get("/_enum2/{P}").get("get").getParameter("path", "P");
- assertObjectEquals("['a','b']", x.getEnum());
+
+ //-----------------------------------------------------------------------------------------------------------------
+ // Examples
+ //-----------------------------------------------------------------------------------------------------------------
+
+ @RestResource
+ public static class SC {
+
+ @Path(name="P", example={" {f1:'a'} "})
+ public static class SC01 {
+ public String f1;
+ }
+ @RestMethod(name=GET,path="/example/{P}")
+ public void sc01(SC01 f) {}
}
+
+
@Test
- public void sa21_Path_onPojo_example2() throws Exception {
- ParameterInfo x = getSwagger(new SA()).getPaths().get("/example2/{P}").get("get").getParameter("path", "P");
+ public void sc01_Path_onPojo_example() throws Exception {
+ ParameterInfo x = getSwagger(new SC()).getPaths().get("/example/{P}").get("get").getParameter("path", "P");
assertObjectEquals("{f1:'a'}", x.getExample());
}
@@ -434,11 +554,15 @@ public class PathAnnotationTest {
// @Path on parameter
//=================================================================================================================
- @RestResource()
- public static class SB {
+ //-----------------------------------------------------------------------------------------------------------------
+ // Basic tests
+ //-----------------------------------------------------------------------------------------------------------------
+
+ @RestResource
+ public static class TA {
@RestMethod(name=GET,path="/basic/{P}")
- public void sb00(@Path(
+ public void ta01(@Path(
name="P",
description="a",
type="a",
@@ -457,47 +581,94 @@ public class PathAnnotationTest {
example="'a'"
) String h) {}
- @RestMethod(name=GET,path="/value/{P}")
- public void sb02(@Path("P") String h) {}
-
- @RestMethod(name=GET,path="/schema2/{P}")
- public void sb16b(@Path(name="P", schema=@Schema(" type:'b' ")) String h) {}
-
- public static class SB16c {
- public String f1;
- }
-
- @RestMethod(name=GET,path="/schema3/{P}")
- public void sb16c(@Path("P") SB16c b) {}
-
- public static class SB16d extends LinkedList<String> {
- private static final long serialVersionUID = 1L;
- }
-
- @RestMethod(name=GET,path="/schema4/{P}")
- public void sb16d(@Path("P") SB16d b) {}
-
- public static class SB16e {}
+ @RestMethod(name=GET,path="/api/{P}")
+ public void ta02(@Path(
+ name="P",
+ api={
+ "description:'a',",
+ "type:'a',",
+ "format:'a',",
+ "pattern:'a',",
+ "maximum:'1',",
+ "minimum:'1',",
+ "multipleOf:'1',",
+ "maxLength:'1',",
+ "minLength:'1',",
+ "allowEmptyValue:'true',",
+ "exclusiveMaximum:'true',",
+ "exclusiveMinimum:'true',",
+ "schema:{type:'a'},",
+ "enum:'a,b',",
+ "example:'a'"
+ }
+ ) String h) {}
- @RestMethod(name=GET,path="/schema5/{P}")
- public void sb16e(@Path("P") SB16e b) {}
+ @RestMethod(name=GET,path="/mixed/{P}")
+ public void ta03(@Path(
+ name="P",
+ api={
+ "description:'b',",
+ "type:'b',",
+ "format:'b',",
+ "pattern:'b',",
+ "maximum:'2',",
+ "minimum:'2',",
+ "multipleOf:'2',",
+ "maxLength:'2',",
+ "minLength:'2',",
+ "allowEmptyValue:'false',",
+ "exclusiveMaximum:'false',",
+ "exclusiveMinimum:'false',",
+ "schema:{type:'b'},",
+ "enum:'b,c',",
+ "example:'b'"
+ },
+ description="a",
+ type="a",
+ format="a",
+ pattern="a",
+ maximum="1",
+ minimum="1",
+ multipleOf="1",
+ maxLength="1",
+ minLength="1",
+ allowEmptyValue="true",
+ exclusiveMaximum="true",
+ exclusiveMinimum="true",
+ schema=@Schema(type="a"),
+ _enum=" a,b ",
+ example="'a'"
+ ) String h) {}
- @RestMethod(name=GET,path="/schema6/{P}")
- public void sb16f(@Path("P") Integer b) {}
+ @RestMethod(name=GET,path="/value/{P}")
+ public void ta04(@Path("P") String h) {}
- @RestMethod(name=GET,path="/schema7/{P}")
- public void sb16g(@Path("P") Boolean b) {}
-
- @RestMethod(name=GET,path="/enum2/{P}")
- public void sb19(@Path(name="P", _enum={" ['a','b'] "}) String h) {}
+ @RestMethod(name=GET,path="/enum/{P}")
+ public void ta05(@Path(name="P", _enum={" ['a','b'] "}) String h) {}
+ }
- @RestMethod(name=GET,path="/example2/{P}")
- public void sb21(@Path(name="P", example="{f1:'b'}") String h) {}
+ @Test
+ public void ta01_Path_onParameter_basic() throws Exception {
+ ParameterInfo x = getSwagger(new TA()).getPaths().get("/basic/{P}").get("get").getParameter("path", "P");
+ assertEquals("a", x.getDescription());
+ assertEquals("a", x.getType());
+ assertEquals("a", x.getFormat());
+ assertEquals("a", x.getPattern());
+ assertObjectEquals("1", x.getMaximum());
+ assertObjectEquals("1", x.getMinimum());
+ assertObjectEquals("1", x.getMultipleOf());
+ assertObjectEquals("1", x.getMaxLength());
+ assertObjectEquals("1", x.getMinLength());
+ assertObjectEquals("true", x.getAllowEmptyValue());
+ assertObjectEquals("true", x.getExclusiveMaximum());
+ assertObjectEquals("true", x.getExclusiveMinimum());
+ assertObjectEquals("{type:'a'}", x.getSchema());
+ assertObjectEquals("['a','b']", x.getEnum());
+ assertObjectEquals("'a'", x.getExample());
}
-
@Test
- public void sb00_Path_onParameter_basic() throws Exception {
- ParameterInfo x = getSwagger(new SB()).getPaths().get("/basic/{P}").get("get").getParameter("path", "P");
+ public void ta02_Path_onParameter_api() throws Exception {
+ ParameterInfo x = getSwagger(new TA()).getPaths().get("/api/{P}").get("get").getParameter("path", "P");
assertEquals("a", x.getDescription());
assertEquals("a", x.getType());
assertEquals("a", x.getFormat());
@@ -515,48 +686,113 @@ public class PathAnnotationTest {
assertObjectEquals("'a'", x.getExample());
}
@Test
- public void sb02_Path_onParameter_value() throws Exception {
- ParameterInfo x = getSwagger(new SB()).getPaths().get("/value/{P}").get("get").getParameter("path", "P");
+ public void ta03_Path_onParameter_mixed() throws Exception {
+ ParameterInfo x = getSwagger(new TA()).getPaths().get("/mixed/{P}").get("get").getParameter("path", "P");
+ assertEquals("a", x.getDescription());
+ assertEquals("a", x.getType());
+ assertEquals("a", x.getFormat());
+ assertEquals("a", x.getPattern());
+ assertObjectEquals("1", x.getMaximum());
+ assertObjectEquals("1", x.getMinimum());
+ assertObjectEquals("1", x.getMultipleOf());
+ assertObjectEquals("1", x.getMaxLength());
+ assertObjectEquals("1", x.getMinLength());
+ assertObjectEquals("true", x.getAllowEmptyValue());
+ assertObjectEquals("true", x.getExclusiveMaximum());
+ assertObjectEquals("true", x.getExclusiveMinimum());
+ assertObjectEquals("{type:'a'}", x.getSchema());
+ assertObjectEquals("['a','b']", x.getEnum());
+ assertObjectEquals("'a'", x.getExample());
+ }
+ @Test
+ public void ta04_Path_onParameter_value() throws Exception {
+ ParameterInfo x = getSwagger(new TA()).getPaths().get("/value/{P}").get("get").getParameter("path", "P");
assertEquals("P", x.getName());
}
@Test
- public void sb16b_Path_onParameter_schema2() throws Exception {
- ParameterInfo x = getSwagger(new SB()).getPaths().get("/schema2/{P}").get("get").getParameter("path", "P");
+ public void ta05_Path_onParameter_enum() throws Exception {
+ ParameterInfo x = getSwagger(new TA()).getPaths().get("/enum/{P}").get("get").getParameter("path", "P");
+ assertObjectEquals("['a','b']", x.getEnum());
+ }
+
+ //-----------------------------------------------------------------------------------------------------------------
+ // Schema
+ //-----------------------------------------------------------------------------------------------------------------
+
+ @RestResource
+ public static class TB {
+
+ @RestMethod(name=GET,path="/schemaValue/{P}")
+ public void tb01(@Path(name="P", schema=@Schema(" type:'b' ")) String h) {}
+
+ public static class TB02 {
+ public String f1;
+ }
+ @RestMethod(name=GET,path="/autoDetectBean/{P}")
+ public void tb02(@Path("P") TB02 b) {}
+
+ public static class TB03 extends LinkedList<String> {
+ private static final long serialVersionUID = 1L;
+ }
+ @RestMethod(name=GET,path="/autoDetectList/{P}")
+ public void tb03(@Path("P") TB03 b) {}
+
+ public static class TB04 {}
+ @RestMethod(name=GET,path="/autoDetectStringObject/{P}")
+ public void tb04(@Path("P") TB04 b) {}
+
+ @RestMethod(name=GET,path="/autoDetectInteger/{P}")
+ public void tb05(@Path("P") Integer b) {}
+
+ @RestMethod(name=GET,path="/autoDetectBoolean/{P}")
+ public void tb06(@Path("P") Boolean b) {}
+ }
+
+ @Test
+ public void tb01_Path_onParameter_schemaValue() throws Exception {
+ ParameterInfo x = getSwagger(new TB()).getPaths().get("/schemaValue/{P}").get("get").getParameter("path", "P");
assertObjectEquals("{type:'b'}", x.getSchema());
}
@Test
- public void sb16c_Path_onParameter_schema3() throws Exception {
- ParameterInfo x = getSwagger(new SB()).getPaths().get("/schema3/{P}").get("get").getParameter("path", "P");
+ public void tb02_Path_onParameter_autoDetectBean() throws Exception {
+ ParameterInfo x = getSwagger(new TB()).getPaths().get("/autoDetectBean/{P}").get("get").getParameter("path", "P");
assertObjectEquals("{type:'object',properties:{f1:{type:'string'}}}", x.getSchema());
}
@Test
- public void sb16d_Path_onParameter_schema4() throws Exception {
- ParameterInfo x = getSwagger(new SB()).getPaths().get("/schema4/{P}").get("get").getParameter("path", "P");
+ public void tb03_Path_onParameter_autoDetectList() throws Exception {
+ ParameterInfo x = getSwagger(new TB()).getPaths().get("/autoDetectList/{P}").get("get").getParameter("path", "P");
assertObjectEquals("{type:'array',items:{type:'string'}}", x.getSchema());
}
@Test
- public void sb16e_Path_onParameter_schema5() throws Exception {
- ParameterInfo x = getSwagger(new SB()).getPaths().get("/schema5/{P}").get("get").getParameter("path", "P");
+ public void tb04_Path_onParameter_autoDetectStringObject() throws Exception {
+ ParameterInfo x = getSwagger(new TB()).getPaths().get("/autoDetectStringObject/{P}").get("get").getParameter("path", "P");
assertObjectEquals("{type:'string'}", x.getSchema());
}
@Test
- public void sb16f_Path_onParameter_schema6() throws Exception {
- ParameterInfo x = getSwagger(new SB()).getPaths().get("/schema6/{P}").get("get").getParameter("path", "P");
+ public void tb05_Path_onParameter_autoDetectInteger() throws Exception {
+ ParameterInfo x = getSwagger(new TB()).getPaths().get("/autoDetectInteger/{P}").get("get").getParameter("path", "P");
assertObjectEquals("{format:'int32',type:'integer'}", x.getSchema());
}
@Test
- public void sb16g_Path_onParameter_schema7() throws Exception {
- ParameterInfo x = getSwagger(new SB()).getPaths().get("/schema7/{P}").get("get").getParameter("path", "P");
+ public void tb06_Path_onParameter_autoDetectBoolean() throws Exception {
+ ParameterInfo x = getSwagger(new TB()).getPaths().get("/autoDetectBoolean/{P}").get("get").getParameter("path", "P");
assertObjectEquals("{type:'boolean'}", x.getSchema());
}
- @Test
- public void sb19_Path_onParameter__enum2() throws Exception {
- ParameterInfo x = getSwagger(new SB()).getPaths().get("/enum2/{P}").get("get").getParameter("path", "P");
- assertObjectEquals("['a','b']", x.getEnum());
+
+ //-----------------------------------------------------------------------------------------------------------------
+ // Examples
+ //-----------------------------------------------------------------------------------------------------------------
+
+ @RestResource
+ public static class TC {
+
+ @RestMethod(name=GET,path="/example/{P}")
+ public void ta21(@Path(name="P", example="{f1:'b'}") String h) {}
}
+
@Test
- public void sb21_Path_onParameter_example2() throws Exception {
- ParameterInfo x = getSwagger(new SB()).getPaths().get("/example2/{P}").get("get").getParameter("path", "P");
+ public void tc01_Path_onParameter_example2() throws Exception {
+ ParameterInfo x = getSwagger(new TC()).getPaths().get("/example/{P}").get("get").getParameter("path", "P");
assertObjectEquals("{f1:'b'}", x.getExample());
}
}
\ No newline at end of file
diff --git a/juneau-rest/juneau-rest-server/src/test/java/org/apache/juneau/rest/annotation/QueryAnnotationTest.java b/juneau-rest/juneau-rest-server/src/test/java/org/apache/juneau/rest/annotation/QueryAnnotationTest.java
index 406bb6c..52cfe48 100644
--- a/juneau-rest/juneau-rest-server/src/test/java/org/apache/juneau/rest/annotation/QueryAnnotationTest.java
+++ b/juneau-rest/juneau-rest-server/src/test/java/org/apache/juneau/rest/annotation/QueryAnnotationTest.java
@@ -261,7 +261,11 @@ public class QueryAnnotationTest {
// @Query on POJO
//=================================================================================================================
- @RestResource()
+ //-----------------------------------------------------------------------------------------------------------------
+ // Basic tests
+ //-----------------------------------------------------------------------------------------------------------------
+
+ @RestResource
public static class SA {
@Query(
@@ -289,76 +293,123 @@ public class QueryAnnotationTest {
items=@Items(type="a"),
example="'a'"
)
- public static class SA00 {
- public SA00(String x) {}
+ public static class SA01 {
+ public SA01(String x) {}
}
-
@RestMethod(name=GET, path="/basic")
- public void sa00(SA00 q) {}
-
- @Query("Q")
- public static class SA01 {}
-
- @RestMethod(name=GET,path="/value")
public void sa01(SA01 q) {}
- @Query(name="Q", schema=@Schema(" type:'b' "))
- public static class SA19b {}
-
- @RestMethod(name=GET,path="/schema2")
- public void sa19b(SA19b q) {}
-
- @Query("Q")
- public static class SA19c {
- public String f1;
+ @Query(
+ name="Q",
+ api={
+ "description: 'a\nb',",
+ "required:'true',",
+ "type:'a',",
+ "format:'a',",
+ "pattern:'a',",
+ "collectionFormat:'a',",
+ "maximum:'1',",
+ "minimum:'1',",
+ "multipleOf:'1',",
+ "maxLength:'1',",
+ "minLength:'1',",
+ "maxItems:'1',",
+ "minItems:'1',",
+ "allowEmptyValue:'true',",
+ "exclusiveMaximum:'true',",
+ "exclusiveMinimum:'true',",
+ "uniqueItems:'true',",
+ "schema:{type:'a'},",
+ "default:'a',",
+ "enum:'a, b',",
+ "items:{type:'a'},",
+ "example:'a'"
+ }
+ )
+ public static class SA02 {
+ public SA02(String x) {}
}
+ @RestMethod(name=GET, path="/api")
+ public void sa02(SA02 q) {}
- @RestMethod(name=GET,path="/schema3")
- public void sa19c(SA19c q) {}
-
- @Query("Q")
- public static class SA19d extends LinkedList<String> {
- private static final long serialVersionUID = 1L;
+ @Query(
+ name="Q",
+ api={
+ "description: 'b\nc',",
+ "required:'false',",
+ "type:'b',",
+ "format:'b',",
+ "pattern:'b',",
+ "collectionFormat:'b',",
+ "maximum:'2',",
+ "minimum:'2',",
+ "multipleOf:'2',",
+ "maxLength:'2',",
+ "minLength:'2',",
+ "maxItems:'2',",
+ "minItems:'2',",
+ "allowEmptyValue:'false',",
+ "exclusiveMaximum:'false',",
+ "exclusiveMinimum:'false',",
+ "uniqueItems:'false',",
+ "schema:{type:'b'},",
+ "default:'b',",
+ "enum:'b, c',",
+ "items:{type:'b'},",
+ "example:'b'"
+ },
+ description= {"a","b"},
+ required="true",
+ type="a",
+ format="a",
+ pattern="a",
+ collectionFormat="a",
+ maximum="1",
+ minimum="1",
+ multipleOf="1",
+ maxLength="1",
+ minLength="1",
+ maxItems="1",
+ minItems="1",
+ allowEmptyValue="true",
+ exclusiveMaximum="true",
+ exclusiveMinimum="true",
+ uniqueItems="true",
+ schema=@Schema(type="a"),
+ _default="a",
+ _enum="a, b",
+ items=@Items(type="a"),
+ example="'a'"
+ )
+ public static class SA03 {
+ public SA03(String x) {}
}
-
- @RestMethod(name=GET,path="/schema4")
- public void sa19d(SA19d q) {}
+ @RestMethod(name=GET, path="/mixed")
+ public void sa03(SA03 q) {}
@Query("Q")
- public static class SA19e {}
+ public static class SA04 {}
+ @RestMethod(name=GET,path="/value")
+ public void sa04(SA04 q) {}
- @RestMethod(name=GET,path="/schema5")
- public void sa19e(SA19e q) {}
-
@Query(name="Q", _default={"a","b"})
- public static class SA21b {}
-
- @RestMethod(name=GET,path="/_default2")
- public void sa21b(SA21b q) {}
+ public static class SA05 {}
+ @RestMethod(name=GET,path="/default")
+ public void sa05(SA05 q) {}
@Query(name="Q", _enum={" ['a','b'] "})
- public static class SA22b {}
-
- @RestMethod(name=GET,path="/_enum2")
- public void sa22b(SA22b q) {}
+ public static class SA06 {}
+ @RestMethod(name=GET,path="/enum")
+ public void sa06(SA06 q) {}
@Query(name="Q", items=@Items(" type: 'b' "))
- public static class SA23b {}
-
- @RestMethod(name=GET,path="/items2")
- public void sa23b(SA23b q) {}
-
- @Query(name="Q", example={"{f1:'a'}"})
- public static class SA24b {
- public String f1;
- }
-
- @RestMethod(name=GET,path="/example2")
- public void sa24b(SA24b q) {}
+ public static class SA07 {}
+ @RestMethod(name=GET,path="/items")
+ public void sa07(SA07 q) {}
}
-
+
@Test
- public void sa00a_Query_onPojo_basic() throws Exception {
+ public void sa01_Query_onPojo_basic() throws Exception {
ParameterInfo x = getSwagger(new SA()).getPaths().get("/basic").get("get").getParameter("query", "Q");
assertEquals("Q", x.getName());
assertEquals("a\nb", x.getDescription());
@@ -385,48 +436,151 @@ public class QueryAnnotationTest {
assertObjectEquals("'a'", x.getExample());
}
@Test
- public void sa01_Query_onPojo_value() throws Exception {
+ public void sa02_Query_onPojo_api() throws Exception {
+ ParameterInfo x = getSwagger(new SA()).getPaths().get("/api").get("get").getParameter("query", "Q");
+ assertEquals("Q", x.getName());
+ assertEquals("a\nb", x.getDescription());
+ assertObjectEquals("true", x.getRequired());
+ assertEquals("a", x.getType());
+ assertEquals("a", x.getFormat());
+ assertEquals("a", x.getPattern());
+ assertEquals("a", x.getCollectionFormat());
+ assertObjectEquals("1", x.getMaximum());
+ assertObjectEquals("1", x.getMinimum());
+ assertObjectEquals("1", x.getMultipleOf());
+ assertObjectEquals("1", x.getMaxLength());
+ assertObjectEquals("1", x.getMinLength());
+ assertObjectEquals("1", x.getMaxItems());
+ assertObjectEquals("1", x.getMinItems());
+ assertObjectEquals("true", x.getAllowEmptyValue());
+ assertObjectEquals("true", x.getExclusiveMaximum());
+ assertObjectEquals("true", x.getExclusiveMinimum());
+ assertObjectEquals("true", x.getUniqueItems());
+ assertObjectEquals("{type:'a'}", x.getSchema());
+ assertEquals("a", x.getDefault());
+ assertObjectEquals("['a','b']", x.getEnum());
+ assertObjectEquals("{type:'a'}", x.getItems());
+ assertObjectEquals("'a'", x.getExample());
+ }
+ @Test
+ public void sa03_Query_onPojo_mixed() throws Exception {
+ ParameterInfo x = getSwagger(new SA()).getPaths().get("/mixed").get("get").getParameter("query", "Q");
+ assertEquals("Q", x.getName());
+ assertEquals("a\nb", x.getDescription());
+ assertObjectEquals("true", x.getRequired());
+ assertEquals("a", x.getType());
+ assertEquals("a", x.getFormat());
+ assertEquals("a", x.getPattern());
+ assertEquals("a", x.getCollectionFormat());
+ assertObjectEquals("1", x.getMaximum());
+ assertObjectEquals("1", x.getMinimum());
+ assertObjectEquals("1", x.getMultipleOf());
+ assertObjectEquals("1", x.getMaxLength());
+ assertObjectEquals("1", x.getMinLength());
+ assertObjectEquals("1", x.getMaxItems());
+ assertObjectEquals("1", x.getMinItems());
+ assertObjectEquals("true", x.getAllowEmptyValue());
+ assertObjectEquals("true", x.getExclusiveMaximum());
+ assertObjectEquals("true", x.getExclusiveMinimum());
+ assertObjectEquals("true", x.getUniqueItems());
+ assertObjectEquals("{type:'a'}", x.getSchema());
+ assertEquals("a", x.getDefault());
+ assertObjectEquals("['a','b']", x.getEnum());
+ assertObjectEquals("{type:'a'}", x.getItems());
+ assertObjectEquals("'a'", x.getExample());
+ }
+ @Test
+ public void sa04_Query_onPojo_value() throws Exception {
ParameterInfo x = getSwagger(new SA()).getPaths().get("/value").get("get").getParameter("query", "Q");
assertEquals("Q", x.getName());
}
@Test
- public void sa19b_Query_onPojo_schema2() throws Exception {
- ParameterInfo x = getSwagger(new SA()).getPaths().get("/schema2").get("get").getParameter("query", "Q");
- assertObjectEquals("{type:'b'}", x.getSchema());
+ public void sa05_Query_onPojo_default() throws Exception {
+ ParameterInfo x = getSwagger(new SA()).getPaths().get("/default").get("get").getParameter("query", "Q");
+ assertEquals("a\nb", x.getDefault());
}
@Test
- public void sa19c_Query_onPojo_schema3() throws Exception {
- ParameterInfo x = getSwagger(new SA()).getPaths().get("/schema3").get("get").getParameter("query", "Q");
- assertObjectEquals("{type:'object',properties:{f1:{type:'string'}}}", x.getSchema());
+ public void sa06_Query_onPojo_enum() throws Exception {
+ ParameterInfo x = getSwagger(new SA()).getPaths().get("/enum").get("get").getParameter("query", "Q");
+ assertObjectEquals("['a','b']", x.getEnum());
}
@Test
- public void sa19d_Query_onPojo_schema4() throws Exception {
- ParameterInfo x = getSwagger(new SA()).getPaths().get("/schema4").get("get").getParameter("query", "Q");
- assertObjectEquals("{type:'array',items:{type:'string'}}", x.getSchema());
+ public void sa07_Query_onPojo_items() throws Exception {
+ ParameterInfo x = getSwagger(new SA()).getPaths().get("/items").get("get").getParameter("query", "Q");
+ assertObjectEquals("{type:'b'}", x.getItems());
+ }
+
+ //-----------------------------------------------------------------------------------------------------------------
+ // Schema
+ //-----------------------------------------------------------------------------------------------------------------
+
+ @RestResource
+ public static class SB {
+
+ @Query(name="Q", schema=@Schema(" type:'b' "))
+ public static class SB01 {}
+ @RestMethod(name=GET,path="/schemaValue")
+ public void sb01(SB01 q) {}
+
+ @Query("Q")
+ public static class SB02 {
+ public String f1;
+ }
+ @RestMethod(name=GET,path="/autoDetectBean")
+ public void sb02(SB02 q) {}
+
+ @Query("Q")
+ public static class SB03 extends LinkedList<String> {
+ private static final long serialVersionUID = 1L;
+ }
+ @RestMethod(name=GET,path="/autoDetectList")
+ public void sb03(SB03 q) {}
+
+ @Query("Q")
+ public static class SB04 {}
+ @RestMethod(name=GET,path="/autoDetectStringObject")
+ public void sb04(SB04 q) {}
}
+
@Test
- public void sa19e_Query_onPojo_schema5() throws Exception {
- ParameterInfo x = getSwagger(new SA()).getPaths().get("/schema5").get("get").getParameter("query", "Q");
- assertObjectEquals("{type:'string'}", x.getSchema());
+ public void sb01_Query_onPojo_schemaValue() throws Exception {
+ ParameterInfo x = getSwagger(new SB()).getPaths().get("/schemaValue").get("get").getParameter("query", "Q");
+ assertObjectEquals("{type:'b'}", x.getSchema());
}
@Test
- public void sa21b_Query_onPojo_default2() throws Exception {
- ParameterInfo x = getSwagger(new SA()).getPaths().get("/_default2").get("get").getParameter("query", "Q");
- assertEquals("a\nb", x.getDefault());
+ public void sb02_Query_onPojo_autoDetectBean() throws Exception {
+ ParameterInfo x = getSwagger(new SB()).getPaths().get("/autoDetectBean").get("get").getParameter("query", "Q");
+ assertObjectEquals("{type:'object',properties:{f1:{type:'string'}}}", x.getSchema());
}
@Test
- public void sa22b_Query_onPojo_enum2() throws Exception {
- ParameterInfo x = getSwagger(new SA()).getPaths().get("/_enum2").get("get").getParameter("query", "Q");
- assertObjectEquals("['a','b']", x.getEnum());
+ public void sb03_Query_onPojo_autoDetectList() throws Exception {
+ ParameterInfo x = getSwagger(new SB()).getPaths().get("/autoDetectList").get("get").getParameter("query", "Q");
+ assertObjectEquals("{type:'array',items:{type:'string'}}", x.getSchema());
}
@Test
- public void sa23b_Query_onPojo_items2() throws Exception {
- ParameterInfo x = getSwagger(new SA()).getPaths().get("/items2").get("get").getParameter("query", "Q");
- assertObjectEquals("{type:'b'}", x.getItems());
+ public void sb04_Query_onPojo_autoDetectStringObject() throws Exception {
+ ParameterInfo x = getSwagger(new SB()).getPaths().get("/autoDetectStringObject").get("get").getParameter("query", "Q");
+ assertObjectEquals("{type:'string'}", x.getSchema());
}
+
+ //-----------------------------------------------------------------------------------------------------------------
+ // Examples
+ //-----------------------------------------------------------------------------------------------------------------
+
+ @RestResource
+ public static class SC {
+
+ @Query(name="Q", example={"{f1:'a'}"})
+ public static class SC01 {
+ public String f1;
+ }
+ @RestMethod(name=GET,path="/example")
+ public void sc01(SC01 q) {}
+ }
+
@Test
- public void sa24b_Query_onPojo_example2() throws Exception {
- ParameterInfo x = getSwagger(new SA()).getPaths().get("/example2").get("get").getParameter("query", "Q");
+ public void sc01_Query_onPojo_example() throws Exception {
+ ParameterInfo x = getSwagger(new SC()).getPaths().get("/example").get("get").getParameter("query", "Q");
assertObjectEquals("{f1:'a'}", x.getExample());
}
@@ -434,13 +588,101 @@ public class QueryAnnotationTest {
// @Query on parameter
//=================================================================================================================
- @RestResource()
- public static class SB {
+ //-----------------------------------------------------------------------------------------------------------------
+ // Basic tests
+ //-----------------------------------------------------------------------------------------------------------------
+
+ @RestResource
+ public static class TA {
@RestMethod(name=GET,path="/basic")
- public void sb00(
+ public void ta01(
+ @Query(
+ name="Q",
+ description= {"a","b"},
+ required="true",
+ type="a",
+ format="a",
+ pattern="a",
+ collectionFormat="a",
+ maximum="1",
+ minimum="1",
+ multipleOf="1",
+ maxLength="1",
+ minLength="1",
+ maxItems="1",
+ minItems="1",
+ allowEmptyValue="true",
+ exclusiveMaximum="true",
+ exclusiveMinimum="true",
+ uniqueItems="true",
+ schema=@Schema(type="a"),
+ _default="a",
+ _enum="a,b",
+ items=@Items(type="a"),
+ example="a"
+ )
+ String q) {}
+
+ @RestMethod(name=GET,path="/api")
+ public void ta02(
@Query(
name="Q",
+ api={
+ "description: 'a\nb',",
+ "required:'true',",
+ "type:'a',",
+ "format:'a',",
+ "pattern:'a',",
+ "collectionFormat:'a',",
+ "maximum:'1',",
+ "minimum:'1',",
+ "multipleOf:'1',",
+ "maxLength:'1',",
+ "minLength:'1',",
+ "maxItems:'1',",
+ "minItems:'1',",
+ "allowEmptyValue:'true',",
+ "exclusiveMaximum:'true',",
+ "exclusiveMinimum:'true',",
+ "uniqueItems:'true',",
+ "schema:{type:'a'},",
+ "default:'a',",
+ "enum:'a, b',",
+ "items:{type:'a'},",
+ "example:'a'"
+ }
+ )
+ String q) {}
+
+ @RestMethod(name=GET,path="/mixed")
+ public void ta03(
+ @Query(
+ name="Q",
+ api={
+ "description: 'b\nc',",
+ "required:'false',",
+ "type:'b',",
+ "format:'b',",
+ "pattern:'b',",
+ "collectionFormat:'b',",
+ "maximum:'2',",
+ "minimum:'2',",
+ "multipleOf:'2',",
+ "maxLength:'2',",
+ "minLength:'2',",
+ "maxItems:'2',",
+ "minItems:'2',",
+ "allowEmptyValue:'false',",
+ "exclusiveMaximum:'false',",
+ "exclusiveMinimum:'false',",
+ "uniqueItems:'false',",
+ "schema:{type:'b'},",
+ "default:'b',",
+ "enum:'b, c',",
+ "items:{type:'b'},",
+ "example:'b'"
+ },
description= {"a","b"},
required="true",
type="a",
@@ -467,27 +709,48 @@ public class QueryAnnotationTest {
String q) {}
@RestMethod(name=GET,path="/value")
- public void sb02(@Query("Q") String q) {}
-
- @RestMethod(name=GET,path="/schema2")
- public void sb19b(@Query(name="Q", schema=@Schema( " type: 'b' ")) String q) {}
+ public void ta04(@Query("Q") String q) {}
- @RestMethod(name=GET,path="/_default2")
- public void sb20b(@Query(name="Q", _default={"a","b"}) String q) {}
+ @RestMethod(name=GET,path="/default")
+ public void ta05(@Query(name="Q", _default={"a","b"}) String q) {}
- @RestMethod(name=GET,path="/_enum2")
- public void sb21b(@Query(name="Q", _enum= {" ['a','b'] "}) String q) {}
+ @RestMethod(name=GET,path="/enum")
+ public void ta06(@Query(name="Q", _enum= {" ['a','b'] "}) String q) {}
- @RestMethod(name=GET,path="/items2")
- public void sb22b(@Query(name="Q", items=@Items(" type:'b' ")) String q) {}
+ @RestMethod(name=GET,path="/items")
+ public void ta07(@Query(name="Q", items=@Items(" type:'b' ")) String q) {}
+ }
- @RestMethod(name=GET,path="/example2")
- public void sb23b(@Query(name="Q", example={"a","b"}) String q) {}
+ @Test
+ public void ta01_Query_onParameter_basic() throws Exception {
+ ParameterInfo x = getSwagger(new TA()).getPaths().get("/basic").get("get").getParameter("query", "Q");
+ assertEquals("Q", x.getName());
+ assertEquals("a\nb", x.getDescription());
+ assertObjectEquals("true", x.getRequired());
+ assertEquals("a", x.getType());
+ assertEquals("a", x.getFormat());
+ assertEquals("a", x.getPattern());
+ assertEquals("a", x.getCollectionFormat());
+ assertObjectEquals("1", x.getMaximum());
+ assertObjectEquals("1", x.getMinimum());
+ assertObjectEquals("1", x.getMultipleOf());
+ assertObjectEquals("1", x.getMaxLength());
+ assertObjectEquals("1", x.getMinLength());
+ assertObjectEquals("1", x.getMaxItems());
+ assertObjectEquals("1", x.getMinItems());
+ assertObjectEquals("true", x.getAllowEmptyValue());
+ assertObjectEquals("true", x.getExclusiveMaximum());
+ assertObjectEquals("true", x.getExclusiveMinimum());
+ assertObjectEquals("true", x.getUniqueItems());
+ assertObjectEquals("{type:'a'}", x.getSchema());
+ assertEquals("a", x.getDefault());
+ assertObjectEquals("['a','b']", x.getEnum());
+ assertObjectEquals("{type:'a'}", x.getItems());
+ assertEquals("a", x.getExample());
}
-
@Test
- public void sb00_Query_onParameter_basic() throws Exception {
- ParameterInfo x = getSwagger(new SB()).getPaths().get("/basic").get("get").getParameter("query", "Q");
+ public void ta02_Query_onParameter_api() throws Exception {
+ ParameterInfo x = getSwagger(new TA()).getPaths().get("/api").get("get").getParameter("query", "Q");
assertEquals("Q", x.getName());
assertEquals("a\nb", x.getDescription());
assertObjectEquals("true", x.getRequired());
@@ -513,33 +776,84 @@ public class QueryAnnotationTest {
assertEquals("a", x.getExample());
}
@Test
- public void sb02_Query_onParameter_value() throws Exception {
- ParameterInfo x = getSwagger(new SB()).getPaths().get("/value").get("get").getParameter("query", "Q");
+ public void ta03_Query_onParameter_mixed() throws Exception {
+ ParameterInfo x = getSwagger(new TA()).getPaths().get("/mixed").get("get").getParameter("query", "Q");
assertEquals("Q", x.getName());
+ assertEquals("a\nb", x.getDescription());
+ assertObjectEquals("true", x.getRequired());
+ assertEquals("a", x.getType());
+ assertEquals("a", x.getFormat());
+ assertEquals("a", x.getPattern());
+ assertEquals("a", x.getCollectionFormat());
+ assertObjectEquals("1", x.getMaximum());
+ assertObjectEquals("1", x.getMinimum());
+ assertObjectEquals("1", x.getMultipleOf());
+ assertObjectEquals("1", x.getMaxLength());
+ assertObjectEquals("1", x.getMinLength());
+ assertObjectEquals("1", x.getMaxItems());
+ assertObjectEquals("1", x.getMinItems());
+ assertObjectEquals("true", x.getAllowEmptyValue());
+ assertObjectEquals("true", x.getExclusiveMaximum());
+ assertObjectEquals("true", x.getExclusiveMinimum());
+ assertObjectEquals("true", x.getUniqueItems());
+ assertObjectEquals("{type:'a'}", x.getSchema());
+ assertEquals("a", x.getDefault());
+ assertObjectEquals("['a','b']", x.getEnum());
+ assertObjectEquals("{type:'a'}", x.getItems());
+ assertEquals("a", x.getExample());
}
@Test
- public void sb19b_Query_onParameter_schema2() throws Exception {
- ParameterInfo x = getSwagger(new SB()).getPaths().get("/schema2").get("get").getParameter("query", "Q");
- assertObjectEquals("{type:'b'}", x.getSchema());
+ public void ta04_Query_onParameter_value() throws Exception {
+ ParameterInfo x = getSwagger(new TA()).getPaths().get("/value").get("get").getParameter("query", "Q");
+ assertEquals("Q", x.getName());
}
@Test
- public void sb20b_Query_onParameter__default2() throws Exception {
- ParameterInfo x = getSwagger(new SB()).getPaths().get("/_default2").get("get").getParameter("query", "Q");
+ public void ta05_Query_onParameter_default() throws Exception {
+ ParameterInfo x = getSwagger(new TA()).getPaths().get("/default").get("get").getParameter("query", "Q");
assertEquals("a\nb", x.getDefault());
}
@Test
- public void sb21b_Query_onParameter__enum2() throws Exception {
- ParameterInfo x = getSwagger(new SB()).getPaths().get("/_enum2").get("get").getParameter("query", "Q");
+ public void ta06_Query_onParameter_enum() throws Exception {
+ ParameterInfo x = getSwagger(new TA()).getPaths().get("/enum").get("get").getParameter("query", "Q");
assertObjectEquals("['a','b']", x.getEnum());
}
@Test
- public void sb22b_Query_onParameter_items2() throws Exception {
- ParameterInfo x = getSwagger(new SB()).getPaths().get("/items2").get("get").getParameter("query", "Q");
+ public void ta07_Query_onParameter_items() throws Exception {
+ ParameterInfo x = getSwagger(new TA()).getPaths().get("/items").get("get").getParameter("query", "Q");
assertObjectEquals("{type:'b'}", x.getItems());
}
+
+ //-----------------------------------------------------------------------------------------------------------------
+ // Schema
+ //-----------------------------------------------------------------------------------------------------------------
+
+ @RestResource
+ public static class TB {
+
+ @RestMethod(name=GET,path="/schemaValue")
+ public void tb01(@Query(name="Q", schema=@Schema( " type: 'b' ")) String q) {}
+ }
+
+ @Test
+ public void tb01_Query_onParameter_schemaValue() throws Exception {
+ ParameterInfo x = getSwagger(new TB()).getPaths().get("/schemaValue").get("get").getParameter("query", "Q");
+ assertObjectEquals("{type:'b'}", x.getSchema());
+ }
+
+ //-----------------------------------------------------------------------------------------------------------------
+ // Examples
+ //-----------------------------------------------------------------------------------------------------------------
+
+ @RestResource
+ public static class TC {
+
+ @RestMethod(name=GET,path="/example")
+ public void tc01(@Query(name="Q", example={"a","b"}) String q) {}
+ }
+
@Test
- public void sb23b_Query_onParameter_example2() throws Exception {
- ParameterInfo x = getSwagger(new SB()).getPaths().get("/example2").get("get").getParameter("query", "Q");
+ public void t01_Query_onParameter_example() throws Exception {
+ ParameterInfo x = getSwagger(new TC()).getPaths().get("/example").get("get").getParameter("query", "Q");
assertEquals("a\nb", x.getExample());
}
}
diff --git a/juneau-rest/juneau-rest-server/src/test/java/org/apache/juneau/rest/annotation/ResponseAnnotationTest.java b/juneau-rest/juneau-rest-server/src/test/java/org/apache/juneau/rest/annotation/ResponseAnnotationTest.java
index 1fbbe72..de505cc 100644
--- a/juneau-rest/juneau-rest-server/src/test/java/org/apache/juneau/rest/annotation/ResponseAnnotationTest.java
+++ b/juneau-rest/juneau-rest-server/src/test/java/org/apache/juneau/rest/annotation/ResponseAnnotationTest.java
@@ -46,7 +46,11 @@ public class ResponseAnnotationTest {
// @Response on POJO
//=================================================================================================================
- @RestResource()
+ //-----------------------------------------------------------------------------------------------------------------
+ // Basic tests
+ //-----------------------------------------------------------------------------------------------------------------
+
+ @RestResource
public static class SA {
@Response(
@@ -56,72 +60,60 @@ public class ResponseAnnotationTest {
example="'a'",
examples=" {foo:'a'} "
)
- public static class SA00 {}
-
- @RestMethod(name=GET,path="/basic")
- public void sa00(SA00 r) {}
-
- @Response(code=100)
public static class SA01 {}
-
- @RestMethod(name=GET,path="/code")
+ @RestMethod(name=GET,path="/basic")
public void sa01(SA01 r) {}
- @Response(code=100)
+ @Response(
+ api={
+ "description:'a\nb',",
+ "schema:{type:'a'},",
+ "headers:{foo:{type:'a'}},",
+ "example:'a',",
+ "examples:{foo:'a'}"
+ }
+ )
+
public static class SA02 {}
-
- @RestMethod(name=GET,path="/value")
+ @RestMethod(name=GET,path="/api")
public void sa02(SA02 r) {}
-
- @Response(schema=@Schema(" type:'b' "))
- public static class SA04b {}
- @RestMethod(name=GET,path="/schema2")
- public void sa04b(SA04b r) {}
-
- @Response
- public static class SA04c {
- public String f1;
- }
-
- @RestMethod(name=GET,path="/schema3")
- public void sa04c(SA04c b) {}
-
- @Response
- public static class SA04d extends LinkedList<String> {
- private static final long serialVersionUID = 1L;
- }
-
- @RestMethod(name=GET,path="/schema4")
- public void sa04d(SA04d b) {}
+ @Response(
+ api={
+ "description:'b',",
+ "schema:{type:'b'},",
+ "headers:{bar:{type:'b'}},",
+ "example:'b',",
+ "examples:{bar:'b'}"
+ },
+ description={"a","b"},
+ schema=@Schema(type="a"),
+ headers=@ResponseHeader(name="foo",type="a"),
+ example="'a'",
+ examples=" {foo:'a'} "
+ )
+ public static class SA03 {}
+ @RestMethod(name=GET,path="/mixed")
+ public void sa03(SA03 r) {}
- @Response
- public static class SA04e {}
+ @Response(code=100)
+ public static class SA04 {}
+ @RestMethod(name=GET,path="/code")
+ public void sa04(SA04 r) {}
- @RestMethod(name=GET,path="/schema5")
- public void sa04e(SA04e b) {}
+ @Response(100)
+ public static class SA05 {}
+ @RestMethod(name=GET,path="/value")
+ public void sa05(SA05 r) {}
@Response(headers=@ResponseHeader(name="foo",api=" type:'b' "))
- public static class SA05b {}
-
- @RestMethod(name=GET,path="/headers2")
- public void sa05b(SA05b r) {}
-
- @Response(example="{f1:'a'}")
- public static class SA06b {}
-
- @RestMethod(name=GET,path="/example2")
- public void sa06b(SA06b r) {}
-
- @Response(examples={" foo:'b' "})
- public static class SA07b {}
-
- @RestMethod(name=GET,path="/examples2")
- public void sa07b(SA07b r) {}
+ public static class SA06 {}
+ @RestMethod(name=GET,path="/headers")
+ public void sa06(SA06 r) {}
}
-
+
@Test
- public void sa00_Response_onPojo_basic() throws Exception {
+ public void sa01_Response_onPojo_basic() throws Exception {
ResponseInfo x = getSwagger(new SA()).getPaths().get("/basic").get("get").getResponse(200);
assertEquals("a\nb", x.getDescription());
assertObjectEquals("{type:'a'}", x.getSchema());
@@ -130,48 +122,118 @@ public class ResponseAnnotationTest {
assertObjectEquals("{foo:'a'}", x.getExamples());
}
@Test
- public void sa01_Response_onPojo_code() throws Exception {
+ public void sa02_Response_onPojo_api() throws Exception {
+ ResponseInfo x = getSwagger(new SA()).getPaths().get("/api").get("get").getResponse(200);
+ assertEquals("a\nb", x.getDescription());
+ assertObjectEquals("{type:'a'}", x.getSchema());
+ assertObjectEquals("{foo:{type:'a'}}", x.getHeaders());
+ assertObjectEquals("'a'", x.getExample());
+ assertObjectEquals("{foo:'a'}", x.getExamples());
+ }
+ @Test
+ public void sa03_Response_onPojo_mixed() throws Exception {
+ ResponseInfo x = getSwagger(new SA()).getPaths().get("/mixed").get("get").getResponse(200);
+ assertEquals("a\nb", x.getDescription());
+ assertObjectEquals("{type:'a'}", x.getSchema());
+ assertObjectEquals("{foo:{type:'a'}}", x.getHeaders());
+ assertObjectEquals("'a'", x.getExample());
+ assertObjectEquals("{foo:'a'}", x.getExamples());
+ }
+ @Test
+ public void sa04_Response_onPojo_code() throws Exception {
ResponseInfo x = getSwagger(new SA()).getPaths().get("/code").get("get").getResponse(100);
assertEquals("Continue", x.getDescription());
}
@Test
- public void sa02_Response_onPojo_value() throws Exception {
+ public void sa05_Response_onPojo_value() throws Exception {
ResponseInfo x = getSwagger(new SA()).getPaths().get("/value").get("get").getResponse(100);
assertEquals("Continue", x.getDescription());
}
@Test
- public void sa04b_Response_onPojo_schema2() throws Exception {
- ResponseInfo x = getSwagger(new SA()).getPaths().get("/schema2").get("get").getResponse(200);
+ public void sa06_Response_onPojo_headers() throws Exception {
+ ResponseInfo x = getSwagger(new SA()).getPaths().get("/headers").get("get").getResponse(200);
+ assertObjectEquals("{foo:{type:'b'}}", x.getHeaders());
+ }
+
+ //-----------------------------------------------------------------------------------------------------------------
+ // Schema
+ //-----------------------------------------------------------------------------------------------------------------
+
+ @RestResource
+ public static class SB {
+
+ @Response(schema=@Schema(" type:'b' "))
+ public static class SB01 {}
+ @RestMethod(name=GET,path="/schemaValue")
+ public void sb01(SB01 r) {}
+
+ @Response
+ public static class SB02 {
+ public String f1;
+ }
+ @RestMethod(name=GET,path="/autoDetectBean")
+ public void sb02(SB02 b) {}
+
+ @Response
+ public static class SB03 extends LinkedList<String> {
+ private static final long serialVersionUID = 1L;
+ }
+ @RestMethod(name=GET,path="/autoDetectList")
+ public void sb03(SB03 b) {}
+
+ @Response
+ public static class SB04 {}
+ @RestMethod(name=GET,path="/autoDetectStringObject")
+ public void sb04(SB04 b) {}
+ }
+
+ @Test
+ public void sb01_Response_onPojo_schemaValue() throws Exception {
+ ResponseInfo x = getSwagger(new SB()).getPaths().get("/schemaValue").get("get").getResponse(200);
assertObjectEquals("{type:'b'}", x.getSchema());
}
@Test
- public void sa04c_Response_onPojo_schema3() throws Exception {
- ResponseInfo x = getSwagger(new SA()).getPaths().get("/schema3").get("get").getResponse(200);
+ public void sb02_Response_onPojo_autoDetectBean() throws Exception {
+ ResponseInfo x = getSwagger(new SB()).getPaths().get("/autoDetectBean").get("get").getResponse(200);
assertObjectEquals("{type:'object',properties:{f1:{type:'string'}}}", x.getSchema());
}
@Test
- public void sa04d_Response_onPojo_schema4() throws Exception {
- ResponseInfo x = getSwagger(new SA()).getPaths().get("/schema4").get("get").getResponse(200);
+ public void sb03_Response_onPojo_autoDetectList() throws Exception {
+ ResponseInfo x = getSwagger(new SB()).getPaths().get("/autoDetectList").get("get").getResponse(200);
assertObjectEquals("{type:'array',items:{type:'string'}}", x.getSchema());
}
@Test
- public void sa04e_Response_onPojo_schema5() throws Exception {
- ResponseInfo x = getSwagger(new SA()).getPaths().get("/schema5").get("get").getResponse(200);
+ public void sb04_Response_onPojo_autoDetectStringObject() throws Exception {
+ ResponseInfo x = getSwagger(new SB()).getPaths().get("/autoDetectStringObject").get("get").getResponse(200);
assertObjectEquals("{type:'string'}", x.getSchema());
}
- @Test
- public void sa05b_Response_onPojo_headers2() throws Exception {
- ResponseInfo x = getSwagger(new SA()).getPaths().get("/headers2").get("get").getResponse(200);
- assertObjectEquals("{foo:{type:'b'}}", x.getHeaders());
+
+ //-----------------------------------------------------------------------------------------------------------------
+ // Examples
+ //-----------------------------------------------------------------------------------------------------------------
+
+ @RestResource
+ public static class SC {
+
+ @Response(example="{f1:'a'}")
+ public static class SC01 {}
+ @RestMethod(name=GET,path="/example")
+ public void sc01(SC01 r) {}
+
+ @Response(examples={" foo:'b' "})
+ public static class SC02 {}
+ @RestMethod(name=GET,path="/examples")
+ public void sc02(SC02 r) {}
}
+
@Test
- public void sa06b_Response_onPojo_example2() throws Exception {
- ResponseInfo x = getSwagger(new SA()).getPaths().get("/example2").get("get").getResponse(200);
+ public void sc01_Response_onPojo_example() throws Exception {
+ ResponseInfo x = getSwagger(new SC()).getPaths().get("/example").get("get").getResponse(200);
assertObjectEquals("{f1:'a'}", x.getExample());
}
@Test
- public void sa07b_Response_onPojo_examples2() throws Exception {
- ResponseInfo x = getSwagger(new SA()).getPaths().get("/examples2").get("get").getResponse(200);
+ public void sc02_Response_onPojo_examples() throws Exception {
+ ResponseInfo x = getSwagger(new SC()).getPaths().get("/examples").get("get").getResponse(200);
assertObjectEquals("{foo:'b'}", x.getExamples());
}
@@ -179,75 +241,83 @@ public class ResponseAnnotationTest {
// @Response on parameter
//=================================================================================================================
- @RestResource()
- public static class SB {
+ //-----------------------------------------------------------------------------------------------------------------
+ // Basic tests
+ //-----------------------------------------------------------------------------------------------------------------
- public static class SB00 {}
+ @RestResource
+ public static class TA {
+ public static class TA01 {}
@RestMethod(name=GET,path="/basic")
- public void sb00(
+ public void ta01(
@Response(
description={"a","b"},
schema=@Schema(type="a"),
headers=@ResponseHeader(name="foo",type="a"),
example=" 'a' ",
examples=" {foo:'a'} "
- ) SB00 r
+ ) TA01 r
) {}
- public static class SB01 {}
+ public static class TA02 {}
+ @RestMethod(name=GET,path="/api")
+ public void ta02(
+ @Response(
+ api={
+ "description:'a\nb',",
+ "schema:{type:'a'},",
+ "headers:{foo:{type:'a'}},",
+ "example:'a',",
+ "examples:{foo:'a'}"
+ }
+ ) TA02 r
+ ) {}
- @RestMethod(name=GET,path="/code")
- public void sb01(@Response(code=100) SB01 r) {}
+ public static class TA03 {}
+ @RestMethod(name=GET,path="/mixed")
+ public void ta03(
+ @Response(
+ api={
+ "description:'b',",
+ "schema:{type:'b'},",
+ "headers:{bar:{type:'b'}},",
+ "example:'b',",
+ "examples:{bar:'b'}"
+ },
+ description={"a","b"},
+ schema=@Schema(type="a"),
+ headers=@ResponseHeader(name="foo",type="a"),
+ example=" 'a' ",
+ examples=" {foo:'a'} "
+ ) TA03 r
+ ) {}
- public static class SB02 {}
+ public static class TA04 {}
+ @RestMethod(name=GET,path="/code")
+ public void ta04(@Response(code=100) TA04 r) {}
+ public static class TA05 {}
@RestMethod(name=GET,path="/value")
- public void sb02(@Response(code=100) SB02 r) {}
-
- public static class SB05b {}
-
- @RestMethod(name=GET,path="/schema2")
- public void sb05b(@Response(schema=@Schema(" type:'b' ")) SB05b r) {}
-
- public static class SB05c {
- public String f1;
- }
-
- @RestMethod(name=GET,path="/schema3")
- public void sb05c(@Response SB05c b) {}
-
- public static class SB05d extends LinkedList<String> {
- private static final long serialVersionUID = 1L;
- }
-
- @RestMethod(name=GET,path="/schema4")
- public void sb05d(@Response SB05d b) {}
-
- public static class SB05e {}
-
- @RestMethod(name=GET,path="/schema5")
- public void sb05e(@Response SB05e b) {}
-
- public static class SB08 {}
+ public void ta05(@Response(code=100) TA05 r) {}
- @RestMethod(name=GET,path="/headers2")
- public void sb08(@Response(headers=@ResponseHeader(name="foo",api=" type:'b' ")) SB08 r) {}
-
- public static class SB10 {}
-
- @RestMethod(name=GET,path="/example2")
- public void sb10(@Response(example=" {f1:'b'} ") SB10 r) {}
-
- public static class SB12 {}
+ public static class TA06 {}
+ @RestMethod(name=GET,path="/headers")
+ public void ta06(@Response(headers=@ResponseHeader(name="foo",api=" type:'b' ")) TA06 r) {}
+ }
- @RestMethod(name=GET,path="/examples2")
- public void sb12(@Response(examples={" foo:'b' "}) SB12 r) {}
+ @Test
+ public void ta01_Response_onParameter_basic() throws Exception {
+ ResponseInfo x = getSwagger(new TA()).getPaths().get("/basic").get("get").getResponse(200);
+ assertEquals("a\nb", x.getDescription());
+ assertObjectEquals("{type:'a'}", x.getSchema());
+ assertObjectEquals("{foo:{type:'a'}}", x.getHeaders());
+ assertObjectEquals("'a'", x.getExample());
+ assertObjectEquals("{foo:'a'}", x.getExamples());
}
-
@Test
- public void sb00_Response_onParameter_basic() throws Exception {
- ResponseInfo x = getSwagger(new SB()).getPaths().get("/basic").get("get").getResponse(200);
+ public void ta02_Response_onParameter_api() throws Exception {
+ ResponseInfo x = getSwagger(new TA()).getPaths().get("/api").get("get").getResponse(200);
assertEquals("a\nb", x.getDescription());
assertObjectEquals("{type:'a'}", x.getSchema());
assertObjectEquals("{foo:{type:'a'}}", x.getHeaders());
@@ -255,48 +325,103 @@ public class ResponseAnnotationTest {
assertObjectEquals("{foo:'a'}", x.getExamples());
}
@Test
- public void sb01_Response_onParameter_code() throws Exception {
- ResponseInfo x = getSwagger(new SB()).getPaths().get("/code").get("get").getResponse(100);
+ public void ta03_Response_onParameter_mixed() throws Exception {
+ ResponseInfo x = getSwagger(new TA()).getPaths().get("/mixed").get("get").getResponse(200);
+ assertEquals("a\nb", x.getDescription());
+ assertObjectEquals("{type:'a'}", x.getSchema());
+ assertObjectEquals("{foo:{type:'a'}}", x.getHeaders());
+ assertObjectEquals("'a'", x.getExample());
+ assertObjectEquals("{foo:'a'}", x.getExamples());
+ }
+ @Test
+ public void ta04_Response_onParameter_code() throws Exception {
+ ResponseInfo x = getSwagger(new TA()).getPaths().get("/code").get("get").getResponse(100);
assertEquals("Continue", x.getDescription());
}
@Test
- public void sb02_Response_onParameter_value() throws Exception {
- ResponseInfo x = getSwagger(new SB()).getPaths().get("/value").get("get").getResponse(100);
+ public void ta05_Response_onParameter_value() throws Exception {
+ ResponseInfo x = getSwagger(new TA()).getPaths().get("/value").get("get").getResponse(100);
assertEquals("Continue", x.getDescription());
}
@Test
- public void sb05b_Response_onParameter_schema2() throws Exception {
- ResponseInfo x = getSwagger(new SB()).getPaths().get("/schema2").get("get").getResponse(200);
+ public void ta06_Response_onParameter_headers() throws Exception {
+ ResponseInfo x = getSwagger(new TA()).getPaths().get("/headers").get("get").getResponse(200);
+ assertObjectEquals("{foo:{type:'b'}}", x.getHeaders());
+ }
+
+ //-----------------------------------------------------------------------------------------------------------------
+ // Schema
+ //-----------------------------------------------------------------------------------------------------------------
+
+ @RestResource
+ public static class TB {
+
+ public static class TB01 {}
+ @RestMethod(name=GET,path="/schemaValue")
+ public void tb01(@Response(schema=@Schema(" type:'b' ")) TB01 r) {}
+
+ public static class TB02 {
+ public String f1;
+ }
+ @RestMethod(name=GET,path="/autoDetectBean")
+ public void tb02(@Response TB02 b) {}
+
+ public static class TB03 extends LinkedList<String> {
+ private static final long serialVersionUID = 1L;
+ }
+ @RestMethod(name=GET,path="/autoDetectList")
+ public void tb03(@Response TB03 b) {}
+
+ public static class TB04 {}
+ @RestMethod(name=GET,path="/autoDetectStringObject")
+ public void tb04(@Response TB04 b) {}
+ }
+
+ @Test
+ public void tb01_Response_onParameter_schemaValue() throws Exception {
+ ResponseInfo x = getSwagger(new TB()).getPaths().get("/schemaValue").get("get").getResponse(200);
assertObjectEquals("{type:'b'}", x.getSchema());
}
@Test
- public void sb05c_Response_onParameter_schema3() throws Exception {
- ResponseInfo x = getSwagger(new SB()).getPaths().get("/schema3").get("get").getResponse(200);
+ public void tb02_Response_onParameter_autoDetectBean() throws Exception {
+ ResponseInfo x = getSwagger(new TB()).getPaths().get("/autoDetectBean").get("get").getResponse(200);
assertObjectEquals("{type:'object',properties:{f1:{type:'string'}}}", x.getSchema());
}
@Test
- public void sb05d_Response_onParameter_schema4() throws Exception {
- ResponseInfo x = getSwagger(new SB()).getPaths().get("/schema4").get("get").getResponse(200);
+ public void tb03_Response_onParameter_autoDetectList() throws Exception {
+ ResponseInfo x = getSwagger(new TB()).getPaths().get("/autoDetectList").get("get").getResponse(200);
assertObjectEquals("{type:'array',items:{type:'string'}}", x.getSchema());
}
@Test
- public void sb05e_Response_onParameter_schema5() throws Exception {
- ResponseInfo x = getSwagger(new SB()).getPaths().get("/schema5").get("get").getResponse(200);
+ public void tb04_Response_onParameter_autoDetectStringObject() throws Exception {
+ ResponseInfo x = getSwagger(new TB()).getPaths().get("/autoDetectStringObject").get("get").getResponse(200);
assertObjectEquals("{type:'string'}", x.getSchema());
}
- @Test
- public void sb08_Response_onParameter_headers2() throws Exception {
- ResponseInfo x = getSwagger(new SB()).getPaths().get("/headers2").get("get").getResponse(200);
- assertObjectEquals("{foo:{type:'b'}}", x.getHeaders());
+
+ //-----------------------------------------------------------------------------------------------------------------
+ // Examples
+ //-----------------------------------------------------------------------------------------------------------------
+
+ @RestResource
+ public static class TC {
+
+ public static class TC01 {}
+ @RestMethod(name=GET,path="/example")
+ public void tc01(@Response(example=" {f1:'b'} ") TC01 r) {}
+
+ public static class TC02 {}
+ @RestMethod(name=GET,path="/examples")
+ public void tc02(@Response(examples={" foo:'b' "}) TC02 r) {}
}
+
@Test
- public void sb10_Response_onParameter_example2() throws Exception {
- ResponseInfo x = getSwagger(new SB()).getPaths().get("/example2").get("get").getResponse(200);
+ public void tc01_Response_onParameter_example() throws Exception {
+ ResponseInfo x = getSwagger(new TC()).getPaths().get("/example").get("get").getResponse(200);
assertObjectEquals("{f1:'b'}", x.getExample());
}
@Test
- public void sb12_Response_onParameter_examples2() throws Exception {
- ResponseInfo x = getSwagger(new SB()).getPaths().get("/examples2").get("get").getResponse(200);
+ public void tc02_Response_onParameter_examples() throws Exception {
+ ResponseInfo x = getSwagger(new TC()).getPaths().get("/examples").get("get").getResponse(200);
assertObjectEquals("{foo:'b'}", x.getExamples());
}
@@ -304,9 +429,13 @@ public class ResponseAnnotationTest {
// @Response on throwable
//=================================================================================================================
- @RestResource()
+ //-----------------------------------------------------------------------------------------------------------------
+ // Basic tests
+ //-----------------------------------------------------------------------------------------------------------------
+
+ @RestResource
@SuppressWarnings({"unused"})
- public static class SC {
+ public static class UA {
@Response(
description= {"a","b"},
@@ -315,51 +444,60 @@ public class ResponseAnnotationTest {
example=" 'a' ",
examples=" {foo:'a'} "
)
- public static class SC00 extends Throwable {}
-
+ public static class UA01 extends Throwable {}
@RestMethod(name=GET,path="/basic")
- public void sc00() throws SC00 {}
+ public void ua01() throws UA01 {}
- @Response(code=100)
- public static class SC01 extends Throwable {}
+ @Response(
+ api={
+ "description:'a\nb',",
+ "schema:{type:'a'},",
+ "headers:{foo:{type:'a'}},",
+ "example:'a',",
+ "examples:{foo:'a'}"
+ }
+ )
+ public static class UA02 extends Throwable {}
+ @RestMethod(name=GET,path="/api")
+ public void ua02() throws UA02 {}
- @RestMethod(name=GET,path="/code")
- public void sc01() throws SC01 {}
+ @Response(
+ api={
+ "description:'b',",
+ "schema:{type:'b'},",
+ "headers:{bar:{type:'b'}},",
+ "example:'b',",
+ "examples:{bar:'b'}"
+ },
+ description= {"a","b"},
+ schema=@Schema(type="a"),
+ headers=@ResponseHeader(name="foo",type="a"),
+ example=" 'a' ",
+ examples=" {foo:'a'} "
+ )
+ public static class UA03 extends Throwable {}
+ @RestMethod(name=GET,path="/mixed")
+ public void ua03() throws UA03 {}
@Response(code=100)
- public static class SC02 extends Throwable {}
+ public static class UA04 extends Throwable {}
+ @RestMethod(name=GET,path="/code")
+ public void ua04() throws UA04 {}
+ @Response(code=100)
+ public static class UA05 extends Throwable {}
@RestMethod(name=GET,path="/value")
- public void sc02() throws SC02 {}
-
- @Response(schema=@Schema(" type:'b' "))
- public static class SC03 extends Throwable {}
-
- @RestMethod(name=GET,path="/schema1")
- public void sc03() throws SC03 {}
+ public void ua05() throws UA05 {}
@Response(headers=@ResponseHeader(name="foo", api=" {type:'b'} "))
- public static class SC04 extends Throwable {}
-
- @RestMethod(name=GET,path="/headers1")
- public void sc04() throws SC04 {}
-
- @Response(example={" {f1:'b'} "})
- public static class SC05 extends Throwable {}
-
- @RestMethod(name=GET,path="/example1")
- public void sc05() throws SC05 {}
-
- @Response(examples={" foo:'b' "})
- public static class SC06 extends Throwable {}
-
- @RestMethod(name=GET,path="/examples1")
- public void sc06() throws SC06 {}
+ public static class UA06 extends Throwable {}
+ @RestMethod(name=GET,path="/headers")
+ public void ua06() throws UA06 {}
}
@Test
- public void sc00_Response_onThrowable_basic() throws Exception {
- ResponseInfo x = getSwagger(new SC()).getPaths().get("/basic").get("get").getResponse(500);
+ public void ua01_Response_onThrowable_basic() throws Exception {
+ ResponseInfo x = getSwagger(new UA()).getPaths().get("/basic").get("get").getResponse(500);
assertEquals("a\nb", x.getDescription());
assertObjectEquals("{type:'a'}", x.getSchema());
assertObjectEquals("{foo:{type:'a'}}", x.getHeaders());
@@ -367,268 +505,86 @@ public class ResponseAnnotationTest {
assertObjectEquals("{foo:'a'}", x.getExamples());
}
@Test
- public void sc01_Response_onThrowable_code() throws Exception {
- ResponseInfo x = getSwagger(new SC()).getPaths().get("/code").get("get").getResponse(100);
- assertEquals("Continue", x.getDescription());
- }
- @Test
- public void sc02_Response_onThrowable_value() throws Exception {
- ResponseInfo x = getSwagger(new SC()).getPaths().get("/value").get("get").getResponse(100);
- assertEquals("Continue", x.getDescription());
+ public void ua02_Response_onThrowable_api() throws Exception {
+ ResponseInfo x = getSwagger(new UA()).getPaths().get("/api").get("get").getResponse(500);
+ assertEquals("a\nb", x.getDescription());
+ assertObjectEquals("{type:'a'}", x.getSchema());
+ assertObjectEquals("{foo:{type:'a'}}", x.getHeaders());
+ assertObjectEquals("'a'", x.getExample());
+ assertObjectEquals("{foo:'a'}", x.getExamples());
}
@Test
- public void sc03_Response_onThrowable_schema1() throws Exception {
- ResponseInfo x = getSwagger(new SC()).getPaths().get("/schema1").get("get").getResponse(500);
- assertObjectEquals("{type:'b'}", x.getSchema());
+ public void ua03_Response_onThrowable_mixed() throws Exception {
+ ResponseInfo x = getSwagger(new UA()).getPaths().get("/mixed").get("get").getResponse(500);
+ assertEquals("a\nb", x.getDescription());
+ assertObjectEquals("{type:'a'}", x.getSchema());
+ assertObjectEquals("{foo:{type:'a'}}", x.getHeaders());
+ assertObjectEquals("'a'", x.getExample());
+ assertObjectEquals("{foo:'a'}", x.getExamples());
}
@Test
- public void sc04_Response_onThrowable_headers1() throws Exception {
- ResponseInfo x = getSwagger(new SC()).getPaths().get("/headers1").get("get").getResponse(500);
- assertObjectEquals("{foo:{type:'b'}}", x.getHeaders());
+ public void ua04_Response_onThrowable_code() throws Exception {
+ ResponseInfo x = getSwagger(new UA()).getPaths().get("/code").get("get").getResponse(100);
+ assertEquals("Continue", x.getDescription());
}
@Test
- public void sc05_Response_onThrowable_example1() throws Exception {
- ResponseInfo x = getSwagger(new SC()).getPaths().get("/example1").get("get").getResponse(500);
- assertObjectEquals("{f1:'b'}", x.getExample());
+ public void ua05_Response_onThrowable_value() throws Exception {
+ ResponseInfo x = getSwagger(new UA()).getPaths().get("/value").get("get").getResponse(100);
+ assertEquals("Continue", x.getDescription());
}
@Test
- public void sc6_Response_onThrowable_examples1() throws Exception {
- ResponseInfo x = getSwagger(new SC()).getPaths().get("/examples1").get("get").getResponse(500);
- assertObjectEquals("{foo:'b'}", x.getExamples());
+ public void ua06_Response_onThrowable_headers1() throws Exception {
+ ResponseInfo x = getSwagger(new UA()).getPaths().get("/headers").get("get").getResponse(500);
+ assertObjectEquals("{foo:{type:'b'}}", x.getHeaders());
}
- //=================================================================================================================
- // @Responses on POJO
- //=================================================================================================================
-
- @RestResource()
- public static class SD {
-
- @Responses({
- @Response(code=100),
- @Response(code=101)
- })
- public static class SD01 {}
-
- @RestMethod(name=GET,path="/code")
- public void sd01(SD01 r) {}
-
- @Responses({
- @Response(code=100),
- @Response(code=101)
- })
- public static class SD02 {}
-
- @RestMethod(name=GET,path="/value")
- public void sd02(SD02 r) {}
-
- @Responses({
- @Response(code=100, description="a"),
- @Response(code=101, description={"a","b"})
- })
- public static class SD03 {}
-
- @RestMethod(name=GET,path="/description")
- public void sd03(SD03 r) {}
-
- @Responses({
- @Response(code=100, schema=@Schema(type="a")),
- @Response(code=101, schema=@Schema(" type:'b' "))
- })
- public static class SD04 {}
-
- @RestMethod(name=GET,path="/schema")
- public void sd04(SD04 r) {}
-
- @Responses({
- @Response(code=100, headers=@ResponseHeader(name="foo", type="a")),
- @Response(code=101, headers=@ResponseHeader(name="foo", api=" type:'b' "))
- })
- public static class SD05 {}
-
- @RestMethod(name=GET,path="/headers")
- public void sd05(SD05 r) {}
-
- @Responses({
- @Response(code=100, example="'a'"),
- @Response(code=101, example="{f1:'a'}")
- })
- public static class SD06 {}
-
- @RestMethod(name=GET,path="/example")
- public void sd06(SD06 r) {}
+ //-----------------------------------------------------------------------------------------------------------------
+ // Schema
+ //-----------------------------------------------------------------------------------------------------------------
- @Responses({
- @Response(code=100, examples=" {foo:'a'} "),
- @Response(code=101, examples={" foo:'b' "})
- })
- public static class SD07 {}
+ @RestResource
+ @SuppressWarnings({"unused"})
+ public static class UB {
- @RestMethod(name=GET,path="/examples")
- public void sd07(SD07 r) {}
- }
-
- @Test
- public void sd01_Responses_onPojo_code() throws Exception {
- Operation x = getSwagger(new SD()).getPaths().get("/code").get("get");
- assertEquals("Continue", x.getResponse(100).getDescription());
- assertEquals("Switching Protocols", x.getResponse(101).getDescription());
- }
- @Test
- public void sd02_Responses_onPojo_value() throws Exception {
- Operation x = getSwagger(new SD()).getPaths().get("/value").get("get");
- assertEquals("Continue", x.getResponse(100).getDescription());
- assertEquals("Switching Protocols", x.getResponse(101).getDescription());
- }
- @Test
- public void sd03_Responses_onPojo_description() throws Exception {
- Operation x = getSwagger(new SD()).getPaths().get("/description").get("get");
- assertEquals("a", x.getResponse(100).getDescription());
- assertEquals("a\nb", x.getResponse(101).getDescription());
- }
- @Test
- public void sd04_Responses_onPojo_schema() throws Exception {
- Operation x = getSwagger(new SD()).getPaths().get("/schema").get("get");
- assertObjectEquals("{type:'a'}", x.getResponse(100).getSchema());
- assertObjectEquals("{type:'b'}", x.getResponse(101).getSchema());
- }
- @Test
- public void sd05_Responses_onPojo_headers() throws Exception {
- Operation x = getSwagger(new SD()).getPaths().get("/headers").get("get");
- assertObjectEquals("{foo:{type:'a'}}", x.getResponse(100).getHeaders());
- assertObjectEquals("{foo:{type:'b'}}", x.getResponse(101).getHeaders());
- }
- @Test
- public void sd06_Responses_onPojo_example() throws Exception {
- Operation x = getSwagger(new SD()).getPaths().get("/example").get("get");
- assertObjectEquals("'a'", x.getResponse(100).getExample());
- assertObjectEquals("{f1:'a'}", x.getResponse(101).getExample());
+ @Response(schema=@Schema(" type:'b' "))
+ public static class UB01 extends Throwable {}
+ @RestMethod(name=GET,path="/schemaValue")
+ public void ub01() throws UB01 {}
}
+
@Test
- public void sd07_Responses_onPojo_examples() throws Exception {
- Operation x = getSwagger(new SD()).getPaths().get("/examples").get("get");
- assertObjectEquals("{foo:'a'}", x.getResponse(100).getExamples());
- assertObjectEquals("{foo:'b'}", x.getResponse(101).getExamples());
+ public void ub01_Response_onThrowable_schemaValue() throws Exception {
+ ResponseInfo x = getSwagger(new UB()).getPaths().get("/schemaValue").get("get").getResponse(500);
+ assertObjectEquals("{type:'b'}", x.getSchema());
}
-
- //=================================================================================================================
- // @Responses on parameter
- //=================================================================================================================
-
- @RestResource()
- public static class SE {
-
- public static class SE01 {}
-
- @RestMethod(name=GET,path="/code")
- public void se01(
- @Responses({
- @Response(code=100),
- @Response(code=101)
- })
- SE01 r) {}
-
- public static class SE02 {}
-
- @RestMethod(name=GET,path="/valse")
- public void se02(
- @Responses({
- @Response(code=100),
- @Response(code=101)
- })
- SE02 r) {}
-
- public static class SE03 {}
-
- @RestMethod(name=GET,path="/description")
- public void se03(
- @Responses({
- @Response(code=100, description="a"),
- @Response(code=101, description={"a","b"})
- })
- SE03 r) {}
-
- public static class SE04 {}
-
- @RestMethod(name=GET,path="/schema")
- public void se04(
- @Responses({
- @Response(code=100, schema=@Schema(type="a")),
- @Response(code=101, schema=@Schema(" type:'b' "))
- })
- SE04 r) {}
-
- public static class SE05 {}
-
- @RestMethod(name=GET,path="/headers")
- public void se05(
- @Responses({
- @Response(code=100, headers=@ResponseHeader(name="foo",type="a")),
- @Response(code=101, headers=@ResponseHeader(name="foo", api=" type:'b' "))
- })
- SE05 r) {}
- public static class SE06 {}
+ //-----------------------------------------------------------------------------------------------------------------
+ // Examples
+ //-----------------------------------------------------------------------------------------------------------------
+ @RestResource
+ @SuppressWarnings({"unused"})
+ public static class UC {
+
+ @Response(example={" {f1:'b'} "})
+ public static class UC01 extends Throwable {}
@RestMethod(name=GET,path="/example")
- public void se06(
- @Responses({
- @Response(code=100, example=" 'a' "),
- @Response(code=101, example=" {f1:'b'} ")
- })
- SE06 r) {}
-
- public static class SE07 {}
+ public void uc01() throws UC01 {}
+ @Response(examples={" foo:'b' "})
+ public static class UC02 extends Throwable {}
@RestMethod(name=GET,path="/examples")
- public void se07(
- @Responses({
- @Response(code=100, examples=" {foo:'a'} "),
- @Response(code=101, examples={" foo:'b' "})
- })
- SE07 r) {}
+ public void uc02() throws UC02 {}
}
@Test
- public void se01_Responses_onParameter_code() throws Exception {
- Operation x = getSwagger(new SE()).getPaths().get("/code").get("get");
- assertEquals("Continue", x.getResponse(100).getDescription());
- assertEquals("Switching Protocols", x.getResponse(101).getDescription());
- }
- @Test
- public void se02_Responses_onParameter_valse() throws Exception {
- Operation x = getSwagger(new SE()).getPaths().get("/valse").get("get");
- assertEquals("Continue", x.getResponse(100).getDescription());
- assertEquals("Switching Protocols", x.getResponse(101).getDescription());
- }
- @Test
- public void se03_Responses_onParameter_description() throws Exception {
- Operation x = getSwagger(new SE()).getPaths().get("/description").get("get");
- assertEquals("a", x.getResponse(100).getDescription());
- assertEquals("a\nb", x.getResponse(101).getDescription());
- }
- @Test
- public void se04_Responses_onParameter_schema() throws Exception {
- Operation x = getSwagger(new SE()).getPaths().get("/schema").get("get");
- assertObjectEquals("{type:'a'}", x.getResponse(100).getSchema());
- assertObjectEquals("{type:'b'}", x.getResponse(101).getSchema());
- }
- @Test
- public void se05_Responses_onParameter_headers() throws Exception {
- Operation x = getSwagger(new SE()).getPaths().get("/headers").get("get");
- assertObjectEquals("{foo:{type:'a'}}", x.getResponse(100).getHeaders());
- assertObjectEquals("{foo:{type:'b'}}", x.getResponse(101).getHeaders());
- }
- @Test
- public void se06_Responses_onParameter_example() throws Exception {
- Operation x = getSwagger(new SE()).getPaths().get("/example").get("get");
- assertObjectEquals("'a'", x.getResponse(100).getExample());
- assertObjectEquals("{f1:'b'}", x.getResponse(101).getExample());
+ public void uc01_Response_onThrowable_example() throws Exception {
+ ResponseInfo x = getSwagger(new UC()).getPaths().get("/example").get("get").getResponse(500);
+ assertObjectEquals("{f1:'b'}", x.getExample());
}
@Test
- public void se07_Responses_onParameter_examples() throws Exception {
- Operation x = getSwagger(new SE()).getPaths().get("/examples").get("get");
- assertObjectEquals("{foo:'a'}", x.getResponse(100).getExamples());
- assertObjectEquals("{foo:'b'}", x.getResponse(101).getExamples());
+ public void uc02_Response_onThrowable_examples() throws Exception {
+ ResponseInfo x = getSwagger(new UC()).getPaths().get("/examples").get("get").getResponse(500);
+ assertObjectEquals("{foo:'b'}", x.getExamples());
}
}
diff --git a/juneau-rest/juneau-rest-server/src/test/java/org/apache/juneau/rest/annotation/ResponseHeaderAnnotationTest.java b/juneau-rest/juneau-rest-server/src/test/java/org/apache/juneau/rest/annotation/ResponseHeaderAnnotationTest.java
index a7f04f1..8143188 100644
--- a/juneau-rest/juneau-rest-server/src/test/java/org/apache/juneau/rest/annotation/ResponseHeaderAnnotationTest.java
+++ b/juneau-rest/juneau-rest-server/src/test/java/org/apache/juneau/rest/annotation/ResponseHeaderAnnotationTest.java
@@ -46,7 +46,7 @@ public class ResponseHeaderAnnotationTest {
// @ResponseHeader on POJO
//=================================================================================================================
- @RestResource()
+ @RestResource
public static class SA {
@ResponseHeader(
@@ -70,68 +70,130 @@ public class ResponseHeaderAnnotationTest {
_enum=" a,b ",
example="'a'"
)
- public static class SA00 {}
-
+ public static class SA01 {}
@RestMethod(name=GET,path="/basic")
- public void sa00(SA00 h) {}
+ public void sa01(SA01 h) {}
+
+ @ResponseHeader(
+ name="H",
+ api={
+ "description:'a',",
+ "type:'a',",
+ "format:'a',",
+ "collectionFormat:'a',",
+ "maximum:'1',",
+ "minimum:'1',",
+ "multipleOf:'1',",
+ "maxLength:'1',",
+ "minLength:'1',",
+ "maxItems:'1',",
+ "minItems:'1',",
+ "exclusiveMaximum:'true',",
+ "exclusiveMinimum:'true',",
+ "uniqueItems:'true',",
+ "items:{type:'a'},",
+ "default:'a',",
+ "enum:' a,b ',",
+ "example:'a'"
+ }
+ )
+ public static class SA02 {}
+ @RestMethod(name=GET,path="/api")
+ public void sa02(SA02 h) {}
+
+ @ResponseHeader(
+ name="H",
+ api={
+ "description:'b',",
+ "type:'b',",
+ "format:'b',",
+ "collectionFormat:'b',",
+ "maximum:'2',",
+ "minimum:'2',",
+ "multipleOf:'2',",
+ "maxLength:'2',",
+ "minLength:'2',",
+ "maxItems:'2',",
+ "minItems:'2',",
+ "exclusiveMaximum:'false',",
+ "exclusiveMinimum:'false',",
+ "uniqueItems:'false',",
+ "items:{type:'b'},",
+ "default:'b',",
+ "enum:' b,c ',",
+ "example:'b'"
+ },
+ description="a",
+ type="a",
+ format="a",
+ collectionFormat="a",
+ maximum="1",
+ minimum="1",
+ multipleOf="1",
+ maxLength="1",
+ minLength="1",
+ maxItems="1",
+ minItems="1",
+ exclusiveMaximum="true",
+ exclusiveMinimum="true",
+ uniqueItems="true",
+ items=@Items(type="a"),
+ _default="'a'",
+ _enum=" a,b ",
+ example="'a'"
+ )
+ public static class SA03 {}
+ @RestMethod(name=GET,path="/mixed")
+ public void sa03(SA03 h) {}
@ResponseHeader(name="H", code=100)
- public static class SA01a {}
-
+ public static class SA04 {}
@RestMethod(name=GET,path="/code")
- public void sa01a(SA01a h) {}
+ public void sa04(SA04 h) {}
@ResponseHeader(name="H", codes={100,101})
- public static class SA01b {}
-
+ public static class SA05 {}
@RestMethod(name=GET,path="/codes")
- public void sa01b(SA01b h) {}
+ public void sa05(SA05 h) {}
@ResponseHeader(name="H", code=100,codes={101})
- public static class SA01c {}
-
+ public static class SA06 {}
@RestMethod(name=GET,path="/codeAndCodes")
- public void sa01c(SA01c h) {}
+ public void sa06(SA06 h) {}
@ResponseHeader(name="H", description="a")
- public static class SA01d {}
-
+ public static class SA07 {}
@RestMethod(name=GET,path="/nocode")
- public void sa01d(SA01d h) {}
+ public void sa07(SA07 h) {}
@ResponseHeader("H")
- public static class SA02 {}
-
+ public static class SA08 {}
@RestMethod(name=GET,path="/value")
- public void sa02(SA02 h) {}
+ public void sa08(SA08 h) {}
@ResponseHeader(name="H", items=@Items(" type:'b' "))
- public static class SA03 {}
-
+ public static class SA09 {}
@RestMethod(name=GET,path="/items1")
- public void sa03(SA03 h) {}
+ public void sa09(SA09 h) {}
@ResponseHeader(name="H", _default={" {f1:'b'} "})
- public static class SA04 {}
-
+ public static class SA10 {}
@RestMethod(name=GET,path="/default1")
- public void sa04(SA04 h) {}
+ public void sa10(SA10 h) {}
@ResponseHeader(name="H", _enum={" ['a','b'] "})
- public static class SA05 {}
-
+ public static class SA11 {}
@RestMethod(name=GET,path="/enum1")
- public void sa05(SA05 h) {}
+ public void sa11(SA11 h) {}
@ResponseHeader(name="H", example={" {f1:'b'} "})
- public static class SA06 {}
-
+ public static class SA12 {}
@RestMethod(name=GET,path="/example1")
- public void sa06(SA06 h) {}
+ public void sa12(SA12 h) {}
}
@Test
- public void sa00_ResponseHeader_onPojo_basic() throws Exception {
+ public void sa01_ResponseHeader_onPojo_basic() throws Exception {
HeaderInfo x = getSwagger(new SA()).getPaths().get("/basic").get("get").getResponse(200).getHeader("H");
assertEquals("a", x.getDescription());
assertEquals("a", x.getType());
@@ -153,49 +215,93 @@ public class ResponseHeaderAnnotationTest {
assertObjectEquals("'a'", x.getExample());
}
@Test
- public void sa01a_ResponseHeader_onPojo_code() throws Exception {
+ public void sa02_ResponseHeader_onPojo_api() throws Exception {
+ HeaderInfo x = getSwagger(new SA()).getPaths().get("/api").get("get").getResponse(200).getHeader("H");
+ assertEquals("a", x.getDescription());
+ assertEquals("a", x.getType());
+ assertEquals("a", x.getFormat());
+ assertEquals("a", x.getCollectionFormat());
+ assertObjectEquals("1", x.getMaximum());
+ assertObjectEquals("1", x.getMinimum());
+ assertObjectEquals("1", x.getMultipleOf());
+ assertObjectEquals("1", x.getMaxLength());
+ assertObjectEquals("1", x.getMinLength());
+ assertObjectEquals("1", x.getMaxItems());
+ assertObjectEquals("1", x.getMinItems());
+ assertObjectEquals("true", x.getExclusiveMaximum());
+ assertObjectEquals("true", x.getExclusiveMinimum());
+ assertObjectEquals("true", x.getUniqueItems());
+ assertObjectEquals("{type:'a'}", x.getItems());
+ assertObjectEquals("'a'", x.getDefault());
+ assertObjectEquals("['a','b']", x.getEnum());
+ assertObjectEquals("'a'", x.getExample());
+ }
+ @Test
+ public void sa03_ResponseHeader_onPojo_mixed() throws Exception {
+ HeaderInfo x = getSwagger(new SA()).getPaths().get("/mixed").get("get").getResponse(200).getHeader("H");
+ assertEquals("a", x.getDescription());
+ assertEquals("a", x.getType());
+ assertEquals("a", x.getFormat());
+ assertEquals("a", x.getCollectionFormat());
+ assertObjectEquals("1", x.getMaximum());
+ assertObjectEquals("1", x.getMinimum());
+ assertObjectEquals("1", x.getMultipleOf());
+ assertObjectEquals("1", x.getMaxLength());
+ assertObjectEquals("1", x.getMinLength());
+ assertObjectEquals("1", x.getMaxItems());
+ assertObjectEquals("1", x.getMinItems());
+ assertObjectEquals("true", x.getExclusiveMaximum());
+ assertObjectEquals("true", x.getExclusiveMinimum());
+ assertObjectEquals("true", x.getUniqueItems());
+ assertObjectEquals("{type:'a'}", x.getItems());
+ assertObjectEquals("'a'", x.getDefault());
+ assertObjectEquals("['a','b']", x.getEnum());
+ assertObjectEquals("'a'", x.getExample());
+ }
+ @Test
+ public void sa04_ResponseHeader_onPojo_code() throws Exception {
HeaderInfo x = getSwagger(new SA()).getPaths().get("/code").get("get").getResponse(100).getHeader("H");
assertNotNull(x);
}
@Test
- public void sa01b_ResponseHeader_onPojo_codes() throws Exception {
+ public void sa05_ResponseHeader_onPojo_codes() throws Exception {
Operation x = getSwagger(new SA()).getPaths().get("/codes").get("get");
assertNotNull(x.getResponse(100).getHeader("H"));
assertNotNull(x.getResponse(101).getHeader("H"));
}
@Test
- public void sa01c_ResponseHeader_onPojo_codeAndCodes() throws Exception {
+ public void sa06_ResponseHeader_onPojo_codeAndCodes() throws Exception {
Operation x = getSwagger(new SA()).getPaths().get("/codeAndCodes").get("get");
assertNotNull(x.getResponse(100).getHeader("H"));
assertNotNull(x.getResponse(101).getHeader("H"));
}
@Test
- public void sa01d_ResponseHeader_onPojo_nocode() throws Exception {
+ public void sa07_ResponseHeader_onPojo_nocode() throws Exception {
HeaderInfo x = getSwagger(new SA()).getPaths().get("/nocode").get("get").getResponse(200).getHeader("H");
assertEquals("a", x.getDescription());
}
@Test
- public void sa02_ResponseHeader_onPojo_value() throws Exception {
+ public void sa08_ResponseHeader_onPojo_value() throws Exception {
HeaderInfo x = getSwagger(new SA()).getPaths().get("/value").get("get").getResponse(200).getHeader("H");
assertNotNull(x);
}
@Test
- public void sa03_ResponseHeader_onPojo_items1() throws Exception {
+ public void sa09_ResponseHeader_onPojo_items1() throws Exception {
HeaderInfo x = getSwagger(new SA()).getPaths().get("/items1").get("get").getResponse(200).getHeader("H");
assertObjectEquals("{type:'b'}", x.getItems());
}
@Test
- public void sa04_ResponseHeader_onPojo_default1() throws Exception {
+ public void sa10_ResponseHeader_onPojo_default1() throws Exception {
HeaderInfo x = getSwagger(new SA()).getPaths().get("/default1").get("get").getResponse(200).getHeader("H");
assertObjectEquals("{f1:'b'}", x.getDefault());
}
@Test
- public void sa05_ResponseHeader_onPojo_enum1() throws Exception {
+ public void sa11_ResponseHeader_onPojo_enum1() throws Exception {
HeaderInfo x = getSwagger(new SA()).getPaths().get("/enum1").get("get").getResponse(200).getHeader("H");
assertObjectEquals("['a','b']", x.getEnum());
}
@Test
- public void sa06_ResponseHeader_onPojo_example1() throws Exception {
+ public void sa12_ResponseHeader_onPojo_example1() throws Exception {
HeaderInfo x = getSwagger(new SA()).getPaths().get("/example1").get("get").getResponse(200).getHeader("H");
assertObjectEquals("{f1:'b'}", x.getExample());
}
@@ -204,13 +310,12 @@ public class ResponseHeaderAnnotationTest {
// @ResponseHeader on parameter
//=================================================================================================================
- @RestResource()
+ @RestResource
public static class SB {
- public static class SB00 {}
-
+ public static class SB01 {}
@RestMethod(name=GET,path="/basic")
- public void sb00(
+ public void sb01(
@ResponseHeader(
name="H",
description="a",
@@ -231,56 +336,119 @@ public class ResponseHeaderAnnotationTest {
_default="'a'",
_enum=" a,b ",
example="'a'"
- ) SB00 h) {}
-
- public static class SB01a {}
+ ) SB01 h) {}
+ public static class SB02 {}
+ @RestMethod(name=GET,path="/api")
+ public void sb02(
+ @ResponseHeader(
+ name="H",
+ api={
+ "description:'a',",
+ "type:'a',",
+ "format:'a',",
+ "collectionFormat:'a',",
+ "maximum:'1',",
+ "minimum:'1',",
+ "multipleOf:'1',",
+ "maxLength:'1',",
+ "minLength:'1',",
+ "maxItems:'1',",
+ "minItems:'1',",
+ "exclusiveMaximum:'true',",
+ "exclusiveMinimum:'true',",
+ "uniqueItems:'true',",
+ "items:{type:'a'},",
+ "default:'a',",
+ "enum:' a,b ',",
+ "example:'a'"
+ }
+ ) SB02 h) {}
+
+ public static class SB03 {}
+ @RestMethod(name=GET,path="/mixed")
+ public void sb03(
+ @ResponseHeader(
+ name="H",
+ api={
+ "description:'b',",
+ "type:'b',",
+ "format:'b',",
+ "collectionFormat:'b',",
+ "maximum:'2',",
+ "minimum:'2',",
+ "multipleOf:'2',",
+ "maxLength:'2',",
+ "minLength:'2',",
+ "maxItems:'2',",
+ "minItems:'2',",
+ "exclusiveMaximum:'false',",
+ "exclusiveMinimum:'false',",
+ "uniqueItems:'false',",
+ "items:{type:'b'},",
+ "default:'b',",
+ "enum:' b,c ',",
+ "example:'b'"
+ },
+ description="a",
+ type="a",
+ format="a",
+ collectionFormat="a",
+ maximum="1",
+ minimum="1",
+ multipleOf="1",
+ maxLength="1",
+ minLength="1",
+ maxItems="1",
+ minItems="1",
+ exclusiveMaximum="true",
+ exclusiveMinimum="true",
+ uniqueItems="true",
+ items=@Items(type="a"),
+ _default="'a'",
+ _enum=" a,b ",
+ example="'a'"
+ ) SB03 h) {}
+
+ public static class SB04 {}
@RestMethod(name=GET,path="/code")
- public void sb01a(@ResponseHeader(name="H", code=100) SB01a h) {}
+ public void sb04(@ResponseHeader(name="H", code=100) SB04 h) {}
- public static class SB01b {}
-
+ public static class SB05 {}
@RestMethod(name=GET,path="/codes")
- public void sb01b(@ResponseHeader(name="H", codes={100,101}) SB01b h) {}
+ public void sb05(@ResponseHeader(name="H", codes={100,101}) SB05 h) {}
- public static class SB01c {}
-
+ public static class SB06 {}
@RestMethod(name=GET,path="/codeAndCodes")
- public void sb01c(@ResponseHeader(name="H", code=100,codes={101}) SB01c h) {}
+ public void sb06(@ResponseHeader(name="H", code=100,codes={101}) SB06 h) {}
- public static class SB01d {}
-
+ public static class SB07 {}
@RestMethod(name=GET,path="/nocode")
- public void sb01d(@ResponseHeader(name="H", description="a") SB01d h) {}
+ public void sb07(@ResponseHeader(name="H", description="a") SB07 h) {}
- public static class SB02 {}
-
+ public static class SB08 {}
@RestMethod(name=GET,path="/value")
- public void sb02(@ResponseHeader("H") SB02 h) {}
-
- public static class SB03 {}
+ public void sb08(@ResponseHeader("H") SB08 h) {}
+ public static class SB09 {}
@RestMethod(name=GET,path="/items1")
- public void sb03(@ResponseHeader(name="H", items=@Items(" type:'b' ")) SB03 h) {}
+ public void sb09(@ResponseHeader(name="H", items=@Items(" type:'b' ")) SB09 h) {}
- public static class SB04 {}
-
+ public static class SB10 {}
@RestMethod(name=GET,path="/default1")
- public void sb04(@ResponseHeader(name="H", _default={" {f1:'b'} "}) SB04 h) {}
+ public void sb10(@ResponseHeader(name="H", _default={" {f1:'b'} "}) SB10 h) {}
- public static class SB05 {}
-
+ public static class SB11 {}
@RestMethod(name=GET,path="/enum1")
- public void sb05(@ResponseHeader(name="H", _enum={" ['a','b'] "}) SB05 h) {}
+ public void sb11(@ResponseHeader(name="H", _enum={" ['a','b'] "}) SB11 h) {}
- public static class SB06 {}
-
+ public static class SB12 {}
@RestMethod(name=GET,path="/example1")
- public void sb06(@ResponseHeader(name="H", example={" {f1:'b'} "}) SB06 h) {}
+ public void sb12(@ResponseHeader(name="H", example={" {f1:'b'} "}) SB12 h) {}
}
@Test
- public void sb00_ResponseHeader_onPojo_basic() throws Exception {
+ public void sb01_ResponseHeader_onPojo_basic() throws Exception {
HeaderInfo x = getSwagger(new SB()).getPaths().get("/basic").get("get").getResponse(200).getHeader("H");
assertEquals("a", x.getDescription());
assertEquals("a", x.getType());
@@ -302,49 +470,93 @@ public class ResponseHeaderAnnotationTest {
assertObjectEquals("'a'", x.getExample());
}
@Test
- public void sb01a_ResponseHeader_onPojo_code() throws Exception {
+ public void sb02_ResponseHeader_onPojo_api() throws Exception {
+ HeaderInfo x = getSwagger(new SB()).getPaths().get("/api").get("get").getResponse(200).getHeader("H");
+ assertEquals("a", x.getDescription());
+ assertEquals("a", x.getType());
+ assertEquals("a", x.getFormat());
+ assertEquals("a", x.getCollectionFormat());
+ assertObjectEquals("1", x.getMaximum());
+ assertObjectEquals("1", x.getMinimum());
+ assertObjectEquals("1", x.getMultipleOf());
+ assertObjectEquals("1", x.getMaxLength());
+ assertObjectEquals("1", x.getMinLength());
+ assertObjectEquals("1", x.getMaxItems());
+ assertObjectEquals("1", x.getMinItems());
+ assertObjectEquals("true", x.getExclusiveMaximum());
+ assertObjectEquals("true", x.getExclusiveMinimum());
+ assertObjectEquals("true", x.getUniqueItems());
+ assertObjectEquals("{type:'a'}", x.getItems());
+ assertObjectEquals("'a'", x.getDefault());
+ assertObjectEquals("['a','b']", x.getEnum());
+ assertObjectEquals("'a'", x.getExample());
+ }
+ @Test
+ public void sb03_ResponseHeader_onPojo_mixed() throws Exception {
+ HeaderInfo x = getSwagger(new SB()).getPaths().get("/mixed").get("get").getResponse(200).getHeader("H");
+ assertEquals("a", x.getDescription());
+ assertEquals("a", x.getType());
+ assertEquals("a", x.getFormat());
+ assertEquals("a", x.getCollectionFormat());
+ assertObjectEquals("1", x.getMaximum());
+ assertObjectEquals("1", x.getMinimum());
+ assertObjectEquals("1", x.getMultipleOf());
+ assertObjectEquals("1", x.getMaxLength());
+ assertObjectEquals("1", x.getMinLength());
+ assertObjectEquals("1", x.getMaxItems());
+ assertObjectEquals("1", x.getMinItems());
+ assertObjectEquals("true", x.getExclusiveMaximum());
+ assertObjectEquals("true", x.getExclusiveMinimum());
+ assertObjectEquals("true", x.getUniqueItems());
+ assertObjectEquals("{type:'a'}", x.getItems());
+ assertObjectEquals("'a'", x.getDefault());
+ assertObjectEquals("['a','b']", x.getEnum());
+ assertObjectEquals("'a'", x.getExample());
+ }
+ @Test
+ public void sb04_ResponseHeader_onPojo_code() throws Exception {
HeaderInfo x = getSwagger(new SB()).getPaths().get("/code").get("get").getResponse(100).getHeader("H");
assertNotNull(x);
}
@Test
- public void sb01b_ResponseHeader_onPojo_codes() throws Exception {
+ public void sb05_ResponseHeader_onPojo_codes() throws Exception {
Operation x = getSwagger(new SB()).getPaths().get("/codes").get("get");
assertNotNull(x.getResponse(100).getHeader("H"));
assertNotNull(x.getResponse(101).getHeader("H"));
}
@Test
- public void sb01c_ResponseHeader_onPojo_codeAndCodes() throws Exception {
+ public void sb06_ResponseHeader_onPojo_codeAndCodes() throws Exception {
Operation x = getSwagger(new SB()).getPaths().get("/codeAndCodes").get("get");
assertNotNull(x.getResponse(100).getHeader("H"));
assertNotNull(x.getResponse(101).getHeader("H"));
}
@Test
- public void sb01d_ResponseHeader_onPojo_nocode() throws Exception {
+ public void sb07_ResponseHeader_onPojo_nocode() throws Exception {
HeaderInfo x = getSwagger(new SB()).getPaths().get("/nocode").get("get").getResponse(200).getHeader("H");
assertEquals("a", x.getDescription());
}
@Test
- public void sb02_ResponseHeader_onPojo_value() throws Exception {
+ public void sb08_ResponseHeader_onPojo_value() throws Exception {
HeaderInfo x = getSwagger(new SB()).getPaths().get("/value").get("get").getResponse(200).getHeader("H");
assertNotNull(x);
}
@Test
- public void sb03_ResponseHeader_onPojo_items1() throws Exception {
+ public void sb09_ResponseHeader_onPojo_items1() throws Exception {
HeaderInfo x = getSwagger(new SB()).getPaths().get("/items1").get("get").getResponse(200).getHeader("H");
assertObjectEquals("{type:'b'}", x.getItems());
}
@Test
- public void sb04_ResponseHeader_onPojo_default1() throws Exception {
+ public void sb10_ResponseHeader_onPojo_default1() throws Exception {
HeaderInfo x = getSwagger(new SB()).getPaths().get("/default1").get("get").getResponse(200).getHeader("H");
assertObjectEquals("{f1:'b'}", x.getDefault());
}
@Test
- public void sb05_ResponseHeader_onPojo_enum1() throws Exception {
+ public void sb11_ResponseHeader_onPojo_enum1() throws Exception {
HeaderInfo x = getSwagger(new SB()).getPaths().get("/enum1").get("get").getResponse(200).getHeader("H");
assertObjectEquals("['a','b']", x.getEnum());
}
@Test
- public void sb06_ResponseHeader_onPojo_example1() throws Exception {
+ public void sb12_ResponseHeader_onPojo_example1() throws Exception {
HeaderInfo x = getSwagger(new SB()).getPaths().get("/example1").get("get").getResponse(200).getHeader("H");
assertObjectEquals("{f1:'b'}", x.getExample());
}
diff --git a/juneau-rest/juneau-rest-server/src/test/java/org/apache/juneau/rest/annotation/ResponseStatusAnnotationTest.java b/juneau-rest/juneau-rest-server/src/test/java/org/apache/juneau/rest/annotation/ResponseStatusAnnotationTest.java
index ae75bbd..f9ec610 100644
--- a/juneau-rest/juneau-rest-server/src/test/java/org/apache/juneau/rest/annotation/ResponseStatusAnnotationTest.java
+++ b/juneau-rest/juneau-rest-server/src/test/java/org/apache/juneau/rest/annotation/ResponseStatusAnnotationTest.java
@@ -43,7 +43,7 @@ public class ResponseStatusAnnotationTest {
// @ResponseStatus on POJO
//=================================================================================================================
- @RestResource()
+ @RestResource
public static class SA {
@ResponseStatus({
@Status(code=100),
@@ -96,7 +96,7 @@ public class ResponseStatusAnnotationTest {
// @ResponseStatus on parameter
//=================================================================================================================
- @RestResource()
+ @RestResource
public static class SB {
public static class SB01 {}
diff --git a/juneau-rest/juneau-rest-server/src/test/java/org/apache/juneau/rest/annotation/ResponsesAnnotationTest.java b/juneau-rest/juneau-rest-server/src/test/java/org/apache/juneau/rest/annotation/ResponsesAnnotationTest.java
new file mode 100644
index 0000000..8ff4a04
--- /dev/null
+++ b/juneau-rest/juneau-rest-server/src/test/java/org/apache/juneau/rest/annotation/ResponsesAnnotationTest.java
@@ -0,0 +1,264 @@
+// ***************************************************************************************************************************
+// * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file *
+// * distributed with this work for additional information regarding copyright ownership. The ASF licenses this file *
+// * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance *
+// * with the License. You may obtain a copy of the License at *
+// * *
+// * http://www.apache.org/licenses/LICENSE-2.0 *
+// * *
+// * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an *
+// * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the *
+// * specific language governing permissions and limitations under the License. *
+// ***************************************************************************************************************************
+package org.apache.juneau.rest.annotation;
+
+import static org.apache.juneau.http.HttpMethodName.*;
+import static org.apache.juneau.testutils.TestUtils.*;
+import static org.junit.Assert.assertEquals;
+
+
+import org.apache.juneau.dto.swagger.*;
+import org.apache.juneau.rest.*;
+import org.apache.juneau.rest.mock.*;
+import org.junit.*;
+import org.junit.runners.*;
+
+/**
+ * Tests the @Responses annotation.
+ */
+@SuppressWarnings({"javadoc"})
+@FixMethodOrder(MethodSorters.NAME_ASCENDING)
+public class ResponsesAnnotationTest {
+
+ //=================================================================================================================
+ // Setup
+ //=================================================================================================================
+
+ private static Swagger getSwagger(Object resource) throws Exception {
+ RestContext rc = RestContext.create(resource).build();
+ RestRequest req = rc.getCallHandler().createRequest(new MockServletRequest());
+ RestInfoProvider ip = rc.getInfoProvider();
+ return ip.getSwagger(req);
+ }
+
+ //=================================================================================================================
+ // @Responses on POJO
+ //=================================================================================================================
+
+ @RestResource
+ public static class A {
+
+ @Responses({
+ @Response(code=100),
+ @Response(code=101)
+ })
+ public static class A01 {}
+ @RestMethod(name=GET,path="/code")
+ public void a01(A01 r) {}
+
+ @Responses({
+ @Response(code=100),
+ @Response(code=101)
+ })
+ public static class A02 {}
+ @RestMethod(name=GET,path="/value")
+ public void a02(A02 r) {}
+
+ @Responses({
+ @Response(code=100, description="a"),
+ @Response(code=101, description={"a","b"})
+ })
+ public static class A03 {}
+ @RestMethod(name=GET,path="/description")
+ public void a03(A03 r) {}
+
+ @Responses({
+ @Response(code=100, schema=@Schema(type="a")),
+ @Response(code=101, schema=@Schema(" type:'b' "))
+ })
+ public static class A04 {}
+ @RestMethod(name=GET,path="/schema")
+ public void a04(A04 r) {}
+
+ @Responses({
+ @Response(code=100, headers=@ResponseHeader(name="foo", type="a")),
+ @Response(code=101, headers=@ResponseHeader(name="foo", api=" type:'b' "))
+ })
+ public static class A05 {}
+ @RestMethod(name=GET,path="/headers")
+ public void a05(A05 r) {}
+
+ @Responses({
+ @Response(code=100, example="'a'"),
+ @Response(code=101, example="{f1:'a'}")
+ })
+ public static class A06 {}
+ @RestMethod(name=GET,path="/example")
+ public void a06(A06 r) {}
+
+ @Responses({
+ @Response(code=100, examples=" {foo:'a'} "),
+ @Response(code=101, examples={" foo:'b' "})
+ })
+ public static class A07 {}
+ @RestMethod(name=GET,path="/examples")
+ public void a07(A07 r) {}
+ }
+
+ @Test
+ public void a01_Responses_onPojo_code() throws Exception {
+ Operation x = getSwagger(new A()).getPaths().get("/code").get("get");
+ assertEquals("Continue", x.getResponse(100).getDescription());
+ assertEquals("Switching Protocols", x.getResponse(101).getDescription());
+ }
+ @Test
+ public void a02_Responses_onPojo_value() throws Exception {
+ Operation x = getSwagger(new A()).getPaths().get("/value").get("get");
+ assertEquals("Continue", x.getResponse(100).getDescription());
+ assertEquals("Switching Protocols", x.getResponse(101).getDescription());
+ }
+ @Test
+ public void a03_Responses_onPojo_description() throws Exception {
+ Operation x = getSwagger(new A()).getPaths().get("/description").get("get");
+ assertEquals("a", x.getResponse(100).getDescription());
+ assertEquals("a\nb", x.getResponse(101).getDescription());
+ }
+ @Test
+ public void a04_Responses_onPojo_schema() throws Exception {
+ Operation x = getSwagger(new A()).getPaths().get("/schema").get("get");
+ assertObjectEquals("{type:'a'}", x.getResponse(100).getSchema());
+ assertObjectEquals("{type:'b'}", x.getResponse(101).getSchema());
+ }
+ @Test
+ public void a05_Responses_onPojo_headers() throws Exception {
+ Operation x = getSwagger(new A()).getPaths().get("/headers").get("get");
+ assertObjectEquals("{foo:{type:'a'}}", x.getResponse(100).getHeaders());
+ assertObjectEquals("{foo:{type:'b'}}", x.getResponse(101).getHeaders());
+ }
+ @Test
+ public void a06_Responses_onPojo_example() throws Exception {
+ Operation x = getSwagger(new A()).getPaths().get("/example").get("get");
+ assertObjectEquals("'a'", x.getResponse(100).getExample());
+ assertObjectEquals("{f1:'a'}", x.getResponse(101).getExample());
+ }
+ @Test
+ public void a07_Responses_onPojo_examples() throws Exception {
+ Operation x = getSwagger(new A()).getPaths().get("/examples").get("get");
+ assertObjectEquals("{foo:'a'}", x.getResponse(100).getExamples());
+ assertObjectEquals("{foo:'b'}", x.getResponse(101).getExamples());
+ }
+
+ //=================================================================================================================
+ // @Responses on parameter
+ //=================================================================================================================
+
+ @RestResource
+ public static class B {
+
+ public static class B01 {}
+ @RestMethod(name=GET,path="/code")
+ public void b01(
+ @Responses({
+ @Response(code=100),
+ @Response(code=101)
+ })
+ B01 r) {}
+
+ public static class B02 {}
+ @RestMethod(name=GET,path="/value")
+ public void b02(
+ @Responses({
+ @Response(code=100),
+ @Response(code=101)
+ })
+ B02 r) {}
+
+ public static class B03 {}
+ @RestMethod(name=GET,path="/description")
+ public void b03(
+ @Responses({
+ @Response(code=100, description="a"),
+ @Response(code=101, description={"a","b"})
+ })
+ B03 r) {}
+
+ public static class B04 {}
+ @RestMethod(name=GET,path="/schema")
+ public void b04(
+ @Responses({
+ @Response(code=100, schema=@Schema(type="a")),
+ @Response(code=101, schema=@Schema(" type:'b' "))
+ })
+ B04 r) {}
+
+ public static class B05 {}
+ @RestMethod(name=GET,path="/headers")
+ public void b05(
+ @Responses({
+ @Response(code=100, headers=@ResponseHeader(name="foo",type="a")),
+ @Response(code=101, headers=@ResponseHeader(name="foo", api=" type:'b' "))
+ })
+ B05 r) {}
+
+ public static class B06 {}
+ @RestMethod(name=GET,path="/example")
+ public void b06(
+ @Responses({
+ @Response(code=100, example=" 'a' "),
+ @Response(code=101, example=" {f1:'b'} ")
+ })
+ B06 r) {}
+
+ public static class B07 {}
+ @RestMethod(name=GET,path="/examples")
+ public void b07(
+ @Responses({
+ @Response(code=100, examples=" {foo:'a'} "),
+ @Response(code=101, examples={" foo:'b' "})
+ })
+ B07 r) {}
+ }
+
+ @Test
+ public void b01_Responbs_onParameter_code() throws Exception {
+ Operation x = getSwagger(new B()).getPaths().get("/code").get("get");
+ assertEquals("Continue", x.getResponse(100).getDescription());
+ assertEquals("Switching Protocols", x.getResponse(101).getDescription());
+ }
+ @Test
+ public void b02_Responbs_onParameter_value() throws Exception {
+ Operation x = getSwagger(new B()).getPaths().get("/value").get("get");
+ assertEquals("Continue", x.getResponse(100).getDescription());
+ assertEquals("Switching Protocols", x.getResponse(101).getDescription());
+ }
+ @Test
+ public void b03_Responbs_onParameter_description() throws Exception {
+ Operation x = getSwagger(new B()).getPaths().get("/description").get("get");
+ assertEquals("a", x.getResponse(100).getDescription());
+ assertEquals("a\nb", x.getResponse(101).getDescription());
+ }
+ @Test
+ public void b04_Responbs_onParameter_schema() throws Exception {
+ Operation x = getSwagger(new B()).getPaths().get("/schema").get("get");
+ assertObjectEquals("{type:'a'}", x.getResponse(100).getSchema());
+ assertObjectEquals("{type:'b'}", x.getResponse(101).getSchema());
+ }
+ @Test
+ public void b05_Responbs_onParameter_headers() throws Exception {
+ Operation x = getSwagger(new B()).getPaths().get("/headers").get("get");
+ assertObjectEquals("{foo:{type:'a'}}", x.getResponse(100).getHeaders());
+ assertObjectEquals("{foo:{type:'b'}}", x.getResponse(101).getHeaders());
+ }
+ @Test
+ public void b06_Responbs_onParameter_example() throws Exception {
+ Operation x = getSwagger(new B()).getPaths().get("/example").get("get");
+ assertObjectEquals("'a'", x.getResponse(100).getExample());
+ assertObjectEquals("{f1:'b'}", x.getResponse(101).getExample());
+ }
+ @Test
+ public void b07_Responbs_onParameter_examples() throws Exception {
+ Operation x = getSwagger(new B()).getPaths().get("/examples").get("get");
+ assertObjectEquals("{foo:'a'}", x.getResponse(100).getExamples());
+ assertObjectEquals("{foo:'b'}", x.getResponse(101).getExamples());
+ }
+}
--
To stop receiving notification emails like this one, please contact
jamesbognar@apache.org.