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 92cf198  Swagger UI enhancements.
92cf198 is described below

commit 92cf198583d6bed40f2028a4c6d40d9b257834d0
Author: JamesBognar <jamesbog...@apache.org>
AuthorDate: Sun Apr 8 20:35:09 2018 -0400

    Swagger UI enhancements.
---
 .../apache/juneau/dto/swagger/ui/SwaggerUI.java    |  9 ++++--
 .../examples/rest/MethodExampleResource.java       | 36 ++++++++++++----------
 .../microservice/resources/ConfigResource.java     |  4 +--
 .../apache/juneau/rest/BasicRestInfoProvider.java  |  6 ++--
 .../apache/juneau/rest/annotation/RestMethod.java  |  2 +-
 5 files changed, 33 insertions(+), 24 deletions(-)

diff --git 
a/juneau-core/juneau-dto/src/main/java/org/apache/juneau/dto/swagger/ui/SwaggerUI.java
 
b/juneau-core/juneau-dto/src/main/java/org/apache/juneau/dto/swagger/ui/SwaggerUI.java
index 5697d16..4a08001 100644
--- 
a/juneau-core/juneau-dto/src/main/java/org/apache/juneau/dto/swagger/ui/SwaggerUI.java
+++ 
b/juneau-core/juneau-dto/src/main/java/org/apache/juneau/dto/swagger/ui/SwaggerUI.java
@@ -68,6 +68,8 @@ public class SwaggerUI extends PojoSwap<Swagger,Div> {
        
        static final ClasspathResourceManager RESOURCES = new 
ClasspathResourceManager(SwaggerUI.class);
        
+       private static final Set<String> STANDARD_METHODS = new 
ASet<String>().appendAll("get", "put", "post", "delete", "options");
+       
        @Override
        public MediaType[] forMediaTypes() {
                return new MediaType[] {MediaType.HTML};
@@ -193,9 +195,12 @@ public class SwaggerUI extends PojoSwap<Swagger,Div> {
        }
        
        private Div opBlock(Session s, String path, String opName, Operation 
op) {
-               String opNameLc = op.isDeprecated() ? "deprecated" : 
opName.toLowerCase();
                
-               return div()._class("op-block op-block-closed " + 
opNameLc).children(
+               String opClass = op.isDeprecated() ? "deprecated" : 
opName.toLowerCase();
+               if (! STANDARD_METHODS.contains(opClass))
+                       opClass = "other";
+               
+               return div()._class("op-block op-block-closed " + 
opClass).children(
                        opBlockSummary(path, opName, op),
                        div(tableContainer(s, op))._class("op-block-contents")
                );
diff --git 
a/juneau-examples/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/MethodExampleResource.java
 
b/juneau-examples/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/MethodExampleResource.java
index bcfa53b..ecbcb63 100644
--- 
a/juneau-examples/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/MethodExampleResource.java
+++ 
b/juneau-examples/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/MethodExampleResource.java
@@ -49,7 +49,7 @@ public class MethodExampleResource extends BasicRestServlet {
        private static final String SAMPLE_UUID_STRING = 
"aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee";
 
        /** Example GET request that redirects to our example method */
-       @RestMethod(name=GET, path="/")
+       @RestMethod(name=GET, path="/", summary="Top-level page")
        public ResourceDescription[] doExample() throws Exception {
                return new ResourceDescription[] {
                        new ResourceDescription(
@@ -67,11 +67,11 @@ public class MethodExampleResource extends BasicRestServlet 
{
                };
        }
 
-       /**
-        * Methodology #1 - GET request using annotated attributes.
-        * This approach uses annotated parameters for retrieving input.
-        */
-       @RestMethod(name=GET, path="/example1/{p1}/{p2}/{p3}/*")
+       @RestMethod(
+               name=GET, path="/example1/{p1}/{p2}/{p3}/*", 
+               summary="GET request using annotated attributes",
+               description="This approach uses annotated parameters for 
retrieving input."
+       )
        public Map<String,Object> example1(
                        @Method String method,                  // HTTP method.
                        @Path String p1,                        // Path 
variables.
@@ -101,11 +101,11 @@ public class MethodExampleResource extends 
BasicRestServlet {
                        .append("header-doNotTrack", doNotTrack);
        }
 
-       /**
-        * Methodology #2 - GET request using methods on RestRequest and 
RestResponse.
-        * This approach uses low-level request/response objects to perform the 
same as above.
-        */
-       @RestMethod(name=GET, path="/example2/{p1}/{p2}/{p3}/*")
+       @RestMethod(
+               name=GET, path="/example2/{p1}/{p2}/{p3}/*", 
+               summary="GET request using methods on RestRequest and 
RestResponse",
+               description="This approach uses low-level request/response 
objects to perform the same as above."
+       )
        public void example2(
                        RestRequest req,          // A direct subclass of 
HttpServletRequest.
                        RestResponse res          // A direct subclass of 
HttpServletResponse.
@@ -150,12 +150,14 @@ public class MethodExampleResource extends 
BasicRestServlet {
                res.setOutput(m);  // Use setOutput(Object) just to be 
different.
        }
 
-       /**
-        * Methodology #3 - GET request using special objects.
-        * This approach uses intermediate-level APIs.
-        * The framework recognizes the parameter types and knows how to 
resolve them.
-        */
-       @RestMethod(name=GET, path="/example3/{p1}/{p2}/{p3}/*")
+       @RestMethod(
+               name=GET, path="/example3/{p1}/{p2}/{p3}/*", 
+               summary="GET request using special objects",
+               description={
+                       "This approach uses intermediate-level APIs.\n",
+                       "The framework recognizes the parameter types and knows 
how to resolve them."
+               }
+       )
        public Map<String,Object> example3(
                HttpMethod method,           // HTTP method.
                RequestPathMatch path,       // Path variables.
diff --git 
a/juneau-microservice/juneau-microservice-server/src/main/java/org/apache/juneau/microservice/resources/ConfigResource.java
 
b/juneau-microservice/juneau-microservice-server/src/main/java/org/apache/juneau/microservice/resources/ConfigResource.java
index 83214d1..f9967f7 100755
--- 
a/juneau-microservice/juneau-microservice-server/src/main/java/org/apache/juneau/microservice/resources/ConfigResource.java
+++ 
b/juneau-microservice/juneau-microservice-server/src/main/java/org/apache/juneau/microservice/resources/ConfigResource.java
@@ -190,8 +190,8 @@ public class ConfigResource extends BasicRestServlet {
                description="Add or overwrite a config file entry.",
                swagger={
                        "parameters:[",
-                               "{name:'section',in:'path',description:'Section 
name.'}",
-                               "{name:'key',in:'path',description:'Entry 
name.'}",
+                               "{name:'section',in:'path',description:'Section 
name.'},",
+                               "{name:'key',in:'path',description:'Entry 
name.'},",
                                "{in:'body',description:'New value as a 
string.'}",
                        "]"
                }
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 719392e..34a05fa 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
@@ -299,7 +299,7 @@ public class BasicRestInfoProvider implements 
RestInfoProvider {
                        if (s != null)
                                op.put("summary", vr.resolve(s));
 
-                       s = rm.description();
+                       s = join(rm.description(), "");
                        if (s.isEmpty())
                                s = mb.findFirstString(locale, mn + 
".description");
                        if (s != null)
@@ -507,6 +507,8 @@ public class BasicRestInfoProvider implements 
RestInfoProvider {
                
                if (definitions.isEmpty())
                        omSwagger.remove("definitions");                
+               if (externalDocs.isEmpty())
+                       omSwagger.remove("externalDocs");
                if (tagMap.isEmpty())
                        omSwagger.remove("tags");
                
@@ -771,7 +773,7 @@ public class BasicRestInfoProvider implements 
RestInfoProvider {
        public String getMethodDescription(Method method, RestRequest req) 
throws Exception {
                VarResolverSession vr = req.getVarResolverSession();
                
-               String s = method.getAnnotation(RestMethod.class).description();
+               String s = 
join(method.getAnnotation(RestMethod.class).description(), "");
                if (s.isEmpty()) {
                        Operation o = getSwaggerOperation(method, req);
                        if (o != null)
diff --git 
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/annotation/RestMethod.java
 
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/annotation/RestMethod.java
index 1461deb..6d34b0c 100644
--- 
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/annotation/RestMethod.java
+++ 
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/annotation/RestMethod.java
@@ -369,7 +369,7 @@ public @interface RestMethod {
         *      <li class='jm'>{@link 
RestInfoProvider#getDescription(RestRequest)}
         * </ul>
         */
-       String description() default "";
+       String[] description() default {};
 
        /**
         * Compression encoders. 

-- 
To stop receiving notification emails like this one, please contact
jamesbog...@apache.org.

Reply via email to