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 92f245d  Swagger UI support.
92f245d is described below

commit 92f245d3eae2f2f97dc3173d6f07cf31581e5dd2
Author: JamesBognar <[email protected]>
AuthorDate: Sun Mar 18 17:08:51 2018 -0400

    Swagger UI support.
---
 .../apache/juneau/dto/swagger/ui/SwaggerUI.java    | 61 +++++++++++-----------
 .../org/apache/juneau/dto/swagger/ui/SwaggerUI.css | 31 +++++------
 .../juneau/examples/rest/files/petstore.json       |  3 --
 3 files changed, 46 insertions(+), 49 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 0361031..b3b110a 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
@@ -43,6 +43,9 @@ public class SwaggerUI extends PojoSwap<Swagger,Div> {
                        script("text/javascript", RM.getString("SwaggerUI.js"))
                );
                
+               // Operations without tags are rendered first.
+               outer.child(div()._class("tag-block 
tag-block-open").children(tagBlockContents(s, null)));
+
                for (Tag t : s.getTags()) {
                        Div tagBlock = div()._class("tag-block 
tag-block-open").children(
                                tagBlockSummary(t),
@@ -54,17 +57,20 @@ public class SwaggerUI extends PojoSwap<Swagger,Div> {
                return outer;
        }
        
-       private Div tagBlockSummary(Tag t) {
+       // Creates the "pet  Everything about your Pets  ext-link" header.
+       private HtmlElement tagBlockSummary(Tag t) {
                ExternalDocumentation ed = t.getExternalDocs();
                String edd = ed == null ? null : ed.getDescription();
+               Object extDocText = ed == null ? null : (edd != null ? edd : 
ed.getUrl());
                
-               return (Div)div()._class("tag-block-summary").children(
+               return div()._class("tag-block-summary").children(
                        span(t.getName())._class("name"),
                        span(t.getDescription())._class("description"),
-                       ed == null ? null : span(a(ed.getUrl(), edd == null ? 
ed.getUrl() : edd))._class("extdocs")
+                       ed == null ? null : span(a(ed.getUrl(), 
extDocText))._class("extdocs")
                ).onclick("toggleTagBlock(this)");
        }
        
+       // Creates the contents under the "pet  Everything about your Pets  
ext-link" header.
        private Div tagBlockContents(Swagger s, Tag t) {
                Div tagBlockContents = div()._class("tag-block-contents");
                
@@ -73,10 +79,11 @@ public class SwaggerUI extends PojoSwap<Swagger,Div> {
                        for (Map.Entry<String,Operation> e2 : 
e.getValue().entrySet()) {
                                String opName = e2.getKey();
                                Operation op = e2.getValue();
-                               if (op.hasTag(t.getName())) 
+                               if ((t == null && op.hasNoTags()) || (t != null 
&& op.hasTag(t.getName())))
                                        tagBlockContents.child(opBlock(s, path, 
opName, op));
                        }
                }
+               
                return tagBlockContents;
        }
        
@@ -89,17 +96,23 @@ public class SwaggerUI extends PojoSwap<Swagger,Div> {
                );
        }
 
+       private HtmlElement opBlockSummary(String path, String opName, 
Operation op) {
+               return div()._class("op-block-summary").children(
+                       span(opName.toUpperCase())._class("method-button"),
+                       span(path)._class("path"),
+                       span(op.getSummary())._class("summary")
+               ).onclick("toggleOpBlock(this)");
+       }
+
        private Div tableContainer(Swagger s, Operation op) {
                Div tableContainer = div()._class("table-container");
                
-               String description = op.getDescription();
-               if (! StringUtils.isEmpty(description)) 
-                       
tableContainer.child(div(description)._class("op-block-description"));
+               String d = op.getDescription();
+               if (! StringUtils.isEmpty(d)) 
+                       
tableContainer.child(div(d)._class("op-block-description"));
                        
                if (op.hasParameters()) {
-                       tableContainer.child(
-                               
div(h4("Parameters")._class("title"))._class("op-block-section-header")
-                       );
+                       
tableContainer.child(div(h4("Parameters")._class("title"))._class("op-block-section-header"));
                        
                        Table parameters = 
table(tr(th("Name")._class("parameter-key"), 
th("Description")._class("parameter-key")))._class("parameters");
                        
@@ -113,9 +126,7 @@ public class SwaggerUI extends PojoSwap<Swagger,Div> {
                                )._class("parameter-key");
                                
                                Td parameterValue = td(
-                                       div(
-                                               pi.getDescription()
-                                       )._class("description"),
+                                       
div(pi.getDescription())._class("description"),
                                        examples(s, pi)
                                )._class("parameter-value");
                                
@@ -126,9 +137,7 @@ public class SwaggerUI extends PojoSwap<Swagger,Div> {
                }
                
                if (op.hasResponses()) {
-                       tableContainer.child(
-                               
div(h4("Responses")._class("title"))._class("op-block-section-header")
-                       );
+                       
tableContainer.child(div(h4("Responses")._class("title"))._class("op-block-section-header"));
                        
                        Table responses = 
table(tr(th("Code")._class("response-key"), 
th("Description")._class("response-key")))._class("responses");
                        tableContainer.child(responses);
@@ -139,9 +148,7 @@ public class SwaggerUI extends PojoSwap<Swagger,Div> {
                                Td code = 
td(e3.getKey())._class("response-key");
 
                                Td codeValue = td(
-                                       div(
-                                               ri.getDescription()
-                                       )._class("description"),
+                                       
div(ri.getDescription())._class("description"),
                                        examples(s, ri),
                                        headers(s, ri)
                                )._class("response-value");
@@ -153,13 +160,11 @@ public class SwaggerUI extends PojoSwap<Swagger,Div> {
                return tableContainer;
        }
        
-       private Object headers(Swagger s, ResponseInfo ri) {
+       private Div headers(Swagger s, ResponseInfo ri) {
                if (! ri.hasHeaders())
                        return null;
                
-               Table sectionTable = table(
-                       tr(th("Name"),th("Description"),th("Type"))
-               )._class("section-table");
+               Table sectionTable = 
table(tr(th("Name"),th("Description"),th("Type")))._class("section-table");
                
                Div headers = div(
                        div("Headers:")._class("section-name"),
@@ -189,6 +194,7 @@ public class SwaggerUI extends PojoSwap<Swagger,Div> {
                return examples(s, ri.getSchema());
        }
        
+       // If SchemaInfo is a "$ref", resolve it, otherwise a no-op.
        private SchemaInfo resolve(Swagger s, SchemaInfo si) {
                String ref = si.getRef();
                if (ref != null) 
@@ -223,6 +229,7 @@ public class SwaggerUI extends PojoSwap<Swagger,Div> {
                return div;
        }
        
+       // Generates the model contents.
        @SuppressWarnings("rawtypes")
        private ObjectMap getSchemaModel(Swagger s, SchemaInfo si) {
 
@@ -253,12 +260,4 @@ public class SwaggerUI extends PojoSwap<Swagger,Div> {
                
                return m;
        }
-
-       private Div opBlockSummary(String path, String opName, Operation op) {
-               return (Div)div()._class("op-block-summary").children(
-                       span(opName.toUpperCase())._class("method-button"),
-                       span(path)._class("path"),
-                       span(op.getSummary())._class("summary")
-               ).onclick("toggleOpBlock(this)");
-       }
 }
diff --git 
a/juneau-core/juneau-dto/src/main/resources/org/apache/juneau/dto/swagger/ui/SwaggerUI.css
 
b/juneau-core/juneau-dto/src/main/resources/org/apache/juneau/dto/swagger/ui/SwaggerUI.css
index 47083fd..e1b0b17 100644
--- 
a/juneau-core/juneau-dto/src/main/resources/org/apache/juneau/dto/swagger/ui/SwaggerUI.css
+++ 
b/juneau-core/juneau-dto/src/main/resources/org/apache/juneau/dto/swagger/ui/SwaggerUI.css
@@ -25,7 +25,6 @@
     text-align: center;
     border-radius: 3px;
     text-shadow: 0 1px 0 rgba(0,0,0,.1);
-    font-family: sans-serif;
     color: #fff;
 }
 .get .method-button        { background: rgb(97,175,254); }
@@ -41,17 +40,19 @@
  - Encapsulates one or more op-blocks.
  
----------------------------------------------------------------------------------------------------------*/
 
+.tag-block {
+       min-width: 800px;
+}
+
 .tag-block-summary {
        margin: 10px 0px;
        padding: 10px 0px;
-       font-family: sans-serif;        
     align-items: center;
     cursor: pointer;
        border-bottom: 1px solid rgba(59,65,81,.2);
        user-select: none;
 }
 .tag-block-summary .name {
-       font-family: sans-serif;
        font-size: 22px;
        padding: 0px 20px;
 }
@@ -75,7 +76,6 @@
 
 .op-block {
        margin-bottom: 10px;
-       font-family: sans-serif;        
     align-items: center;
     border-radius: 4px;
 }
@@ -106,13 +106,11 @@
 .op-block.deprecated .op-block-summary .description { color: #8f9199 }
 
 .op-block-summary .summary {
-    font-family: sans-serif;
     font-size: 14px;
     padding: 10px;
 }
 
 .op-block-description {
-    font-family: sans-serif;
     font-size: 14px;
     padding: 10px;
 }
@@ -130,12 +128,10 @@
        padding: 8px 20px;
     background: hsla(0,0%,100%,.2);
     box-shadow: 0 1px 2px rgba(0,0,0,.1);
-    font-family: sans-serif;
 }
 
 .op-block-section-header .title {
     font-size: 14px;
-       font-family: sans-serif;
     margin: 0px;
 }
 
@@ -157,7 +153,15 @@ th.parameter-key, th.response-key {
     text-align: left;
        border: none;
     border-bottom: 1px solid rgba(59,65,81,.2);
-    font-family: sans-serif;
+       background-color: inherit;
+}
+
+td.parameter-key, td.response-key {
+       font-size: 12px;
+    padding: 10px;
+    text-align: left;
+       border: none;
+    border-bottom: 1px solid rgba(59,65,81,.2);
        background-color: inherit;
 }
 
@@ -181,7 +185,6 @@ td.parameter-value, td.response-value {
 
 .parameter-key .name {
        font-size: 16px;
-    font-family: sans-serif;
 }
 
 .parameter-key .name.required {
@@ -207,7 +210,6 @@ td.parameter-value, td.response-value {
 }
 
 .op-block-contents .tab li {
-    font-family: sans-serif;
     font-weight: bold;
     opacity: 0.5;
     font-size: 12px;
@@ -243,6 +245,9 @@ td.parameter-value, td.response-value {
     font-weight: 400;
     color: #fff;
        display: none;
+       max-width: 800px;
+       max-height: 800px;
+       text-overflow: auto;
 }
 
 .op-block-contents .example.active {
@@ -271,7 +276,6 @@ td.parameter-value, td.response-value {
     font-weight: bold;
     padding: 5px 0;
     text-align: left;
-    font-family: sans-serif;
 }
 
 .headers .name {
@@ -300,8 +304,6 @@ div.headers {
     font-weight: bold;
     padding: 5px 0;
     text-align: left;
-    font-family: sans-serif;
-       
 }
 
 .section-table {
@@ -313,4 +315,3 @@ div.headers {
        text-align: left;
     border-bottom: 1px solid rgba(59,65,81,.2);
 }
-
diff --git 
a/juneau-examples/juneau-examples-rest/src/main/resources/org/apache/juneau/examples/rest/files/petstore.json
 
b/juneau-examples/juneau-examples-rest/src/main/resources/org/apache/juneau/examples/rest/files/petstore.json
index 50c2ecc..0c52155 100644
--- 
a/juneau-examples/juneau-examples-rest/src/main/resources/org/apache/juneau/examples/rest/files/petstore.json
+++ 
b/juneau-examples/juneau-examples-rest/src/main/resources/org/apache/juneau/examples/rest/files/petstore.json
@@ -144,9 +144,6 @@
                },
                "/pet/findByStatus": {
                        "get": {
-                               "tags": [
-                                       "pet"
-                               ],
                                "summary": "Finds Pets by status",
                                "description": "Multiple status values can be 
provided with comma separated strings",
                                "operationId": "findPetsByStatus",

-- 
To stop receiving notification emails like this one, please contact
[email protected].

Reply via email to