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/09/19 15:04:04 UTC
[juneau] branch master updated: Examples not being added for
@Response-annotated methods.
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 f6b4a45 Examples not being added for @Response-annotated methods.
f6b4a45 is described below
commit f6b4a45424714d4bc0f82277c7e3e636cb3dc900
Author: JamesBognar <ja...@apache.org>
AuthorDate: Wed Sep 19 11:03:50 2018 -0400
Examples not being added for @Response-annotated methods.
---
.../examples/rest/SystemPropertiesResource.java | 59 +++++++++++++++-------
.../org/apache/juneau/rest/SwaggerGenerator.java | 1 +
.../juneau/rest/BasicRestInfoProviderTest.java | 24 ++++++---
.../rest/annotation/ResponseAnnotationTest.java | 20 ++++++--
4 files changed, 76 insertions(+), 28 deletions(-)
diff --git a/juneau-examples/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/SystemPropertiesResource.java b/juneau-examples/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/SystemPropertiesResource.java
index 300df4e..8517f25 100644
--- a/juneau-examples/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/SystemPropertiesResource.java
+++ b/juneau-examples/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/SystemPropertiesResource.java
@@ -14,6 +14,7 @@ package org.apache.juneau.examples.rest;
import static org.apache.juneau.dto.html5.HtmlBuilder.*;
import static org.apache.juneau.http.HttpMethodName.*;
+import static org.apache.juneau.serializer.WriterSerializer.*;
import java.util.*;
import java.util.Map;
@@ -77,6 +78,7 @@ import org.apache.juneau.rest.widget.*;
// Properties that get applied to all serializers and parsers.
properties={
// Use single quotes.
+ @Property(name=WSERIALIZER_quoteChar, value="'")
},
// Support GZIP encoding on Accept-Encoding header.
@@ -97,14 +99,21 @@ public class SystemPropertiesResource extends BasicRestServlet {
summary="Show all system properties",
description="Returns all system properties defined in the JVM.",
swagger=@MethodSwagger(
- responses={
- "200: {description:'Returns a map of key/value pairs.', x-example:{key1:'val1',key2:'val2'}}"
- }
+ // Additional swagger...
)
)
@SuppressWarnings({"rawtypes", "unchecked"})
+ @Response(
+ description="Returns a map of key/value pairs.",
+ example="{key1:'val1',key2:'val2'}"
+ )
public Map get(
- @Query(name="sort", description="Sort results alphabetically", _default="false", example="true") boolean sort
+ @Query(
+ name="sort",
+ description="Sort results alphabetically",
+ _default="false",
+ example="true"
+ ) boolean sort
) throws NotAcceptable {
if (sort)
@@ -117,13 +126,18 @@ public class SystemPropertiesResource extends BasicRestServlet {
summary="Get system property",
description="Returns the value of the specified system property.",
swagger=@MethodSwagger(
- responses={
- "200: {description:'The system property value, or null if not found'}"
- }
+ // Additional method-level swagger info here.
)
)
+ @Response(
+ description="The system property value, or null if not found."
+ )
public String getSystemProperty(
- @Path(name="propertyName", description="The system property name.", example="PATH") String propertyName
+ @Path(
+ name="propertyName",
+ description="The system property name.",
+ example="PATH"
+ ) String propertyName
) throws NotAcceptable {
return System.getProperty(propertyName);
@@ -136,12 +150,17 @@ public class SystemPropertiesResource extends BasicRestServlet {
guards=AdminGuard.class
)
public SeeOtherRoot setSystemProperty(
- @Path(name="propertyName", description="The system property name") String propertyName,
- @Body(description="The new system property value") String value
+ @Path(
+ name="propertyName",
+ description="The system property name"
+ ) String propertyName,
+ @Body(
+ description="The new system property value"
+ ) String value
) throws UserNotAdminException, NotAcceptable, UnsupportedMediaType {
System.setProperty(propertyName, value);
- return SeeOtherRoot.INSTANCE;
+ return SeeOtherRoot.INSTANCE; // Do a 303 redirect to the servlet root.
}
@RestMethod(
@@ -150,11 +169,14 @@ public class SystemPropertiesResource extends BasicRestServlet {
guards=AdminGuard.class
)
public SeeOtherRoot post(
- @Body(description="The new system property values", example="{key1:'val1',key2:123}") java.util.Properties newProperties
+ @Body(
+ description="The new system property values",
+ example="{key1:'val1',key2:123}"
+ ) java.util.Properties newProperties
) throws UserNotAdminException, NotAcceptable, UnsupportedMediaType {
System.setProperties(newProperties);
- return SeeOtherRoot.INSTANCE;
+ return SeeOtherRoot.INSTANCE; // Do a 303 redirect to the servlet root.
}
@RestMethod(
@@ -164,11 +186,15 @@ public class SystemPropertiesResource extends BasicRestServlet {
guards=AdminGuard.class
)
public SeeOtherRoot deleteSystemProperty(
- @Path(name="propertyName", description="The system property name", example="PATH") String propertyName
+ @Path(
+ name="propertyName",
+ description="The system property name",
+ example="PATH"
+ ) String propertyName
) throws UserNotAdminException, NotAcceptable {
System.clearProperty(propertyName);
- return SeeOtherRoot.INSTANCE;
+ return SeeOtherRoot.INSTANCE; // Do a 303 redirect to the servlet root.
}
@RestMethod(
@@ -211,7 +237,7 @@ public class SystemPropertiesResource extends BasicRestServlet {
) throws UserNotAdminException, NotAcceptable, UnsupportedMediaType {
System.setProperty(name, value);
- return SeeOtherRoot.INSTANCE;
+ return SeeOtherRoot.INSTANCE; // Do a 303 redirect to the servlet root.
}
@@ -227,5 +253,4 @@ public class SystemPropertiesResource extends BasicRestServlet {
super("User is not an administrator");
}
}
-
}
\ No newline at end of file
diff --git a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/SwaggerGenerator.java b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/SwaggerGenerator.java
index 09511bc..aa1b5e9 100644
--- a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/SwaggerGenerator.java
+++ b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/SwaggerGenerator.java
@@ -406,6 +406,7 @@ final class SwaggerGenerator {
merge(om, a);
if (! om.containsKey("schema"))
om.appendSkipEmpty("schema", getSchema(om.getObjectMap("schema"), m.getGenericReturnType()));
+ addBodyExamples(sm, om, true, m.getGenericReturnType());
}
}
if (hasAnnotation(Response.class, m.getReturnType())) {
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 7a00d01..23e0aa1 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
@@ -1793,7 +1793,9 @@ public class BasicRestInfoProviderTest {
public OA01x doFoo() { return null;}
}
@Response(code=100)
- public static class OA01x {}
+ public static class OA01x {
+ public String foo;
+ }
@Test
public void oa01a_responses_100_description_default() throws Exception {
@@ -1893,7 +1895,9 @@ public class BasicRestInfoProviderTest {
public OB01x doFoo() {return null;}
}
@Response(code=100)
- public static class OB01x {}
+ public static class OB01x {
+ public String foo;
+ }
@Test
public void ob01a_responses_100_headers_default() throws Exception {
@@ -1997,7 +2001,9 @@ public class BasicRestInfoProviderTest {
public OC01x doFoo() {return null;}
}
@Response(code=100)
- public static class OC01x {}
+ public static class OC01x {
+ public String foo;
+ }
@Test
public void oc01a_responses_100_example_default() throws Exception {
@@ -2045,7 +2051,9 @@ public class BasicRestInfoProviderTest {
public OC04x doFoo() {return null;}
}
@Response(code=100,example="{foo:'d'}")
- public static class OC04x {}
+ public static class OC04x {
+ public String foo;
+ }
@Test
public void oc04a_response_100_example_swaggerOnAnnotation() throws Exception {
@@ -2069,7 +2077,9 @@ public class BasicRestInfoProviderTest {
public OC05x doFoo() {return null;}
}
@Response(code=100,example="{foo:'$L{foo}'}")
- public static class OC05x {}
+ public static class OC05x {
+ public String foo;
+ }
@Test
public void oc05a_response_100_example_swaggerOnAnnotation_localized() throws Exception {
@@ -2097,7 +2107,9 @@ public class BasicRestInfoProviderTest {
public OD01x doFoo() {return null;}
}
@Response(code=100)
- public static class OD01x {}
+ public static class OD01x {
+ public String foo;
+ }
@Test
public void od01a_responses_100_examples_default() throws Exception {
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 bd9bd43..a2bf70f 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
@@ -489,7 +489,9 @@ public class ResponseAnnotationTest {
example="'a'",
examples=" {foo:'a'} "
)
- public static class SA01 {}
+ public static class SA01 {
+ public SA01(String x){}
+ }
@RestMethod
public void sa01a(Value<SA01> r) {}
@RestMethod
@@ -504,7 +506,9 @@ public class ResponseAnnotationTest {
"examples:{foo:'a'}"
}
)
- public static class SA02 {}
+ public static class SA02 {
+ public SA02(String x){}
+ }
@RestMethod
public void sa02a(Value<SA02> r) {}
@RestMethod
@@ -524,7 +528,9 @@ public class ResponseAnnotationTest {
example="'a'",
examples=" {foo:'a'} "
)
- public static class SA03 {}
+ public static class SA03 {
+ public SA03(String x){}
+ }
@RestMethod
public void sa03a(Value<SA03> r) {}
@RestMethod
@@ -730,14 +736,18 @@ public class ResponseAnnotationTest {
public static class SC {
@Response(example="{f1:'a'}")
- public static class SC01 {}
+ public static class SC01 {
+ public String f1;
+ }
@RestMethod
public void sc01a(Value<SC01> r) {}
@RestMethod
public SC01 sc01b() {return null;}
@Response(examples={" foo:'b' "})
- public static class SC02 {}
+ public static class SC02 {
+ public SC02(String x){}
+ }
@RestMethod
public void sc02a(Value<SC02> r) {}
@RestMethod