juneau-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jamesbog...@apache.org
Subject [juneau] branch master updated: SwaggerUI fixes.
Date Sat, 15 Sep 2018 13:08:56 GMT
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 736fbf9  SwaggerUI fixes.
736fbf9 is described below

commit 736fbf9d9674d689eea2373bccf3d1d120766c8a
Author: JamesBognar <jamesbognar@apache.org>
AuthorDate: Sat Sep 15 09:08:43 2018 -0400

    SwaggerUI fixes.
---
 .../java/org/apache/juneau/dto/swagger/Items.java  | 11 +++----
 .../apache/juneau/dto/swagger/ui/SwaggerUI.java    |  6 ++++
 .../org/apache/juneau/rest/SwaggerGenerator.java   | 34 ++++++++++++++--------
 3 files changed, 34 insertions(+), 17 deletions(-)

diff --git a/juneau-core/juneau-dto/src/main/java/org/apache/juneau/dto/swagger/Items.java
b/juneau-core/juneau-dto/src/main/java/org/apache/juneau/dto/swagger/Items.java
index dae9b69..fca4f32 100644
--- a/juneau-core/juneau-dto/src/main/java/org/apache/juneau/dto/swagger/Items.java
+++ b/juneau-core/juneau-dto/src/main/java/org/apache/juneau/dto/swagger/Items.java
@@ -1159,12 +1159,13 @@ public class Items extends SwaggerElement {
 	private Object resolveRefs(Object o, Swagger swagger, Deque<String> refStack, int
maxDepth) {
 		if (o instanceof ObjectMap) {
 			ObjectMap om = (ObjectMap)o;
-			String ref = om.getString("$ref");
-			if (ref != null) {
-				if (refStack.contains(ref) || refStack.size() >= maxDepth)
+			Object ref = om.get("$ref");
+			if (ref instanceof CharSequence) {
+				String sref = ref.toString();
+				if (refStack.contains(sref) || refStack.size() >= maxDepth)
 					return o;
-				refStack.addLast(ref);
-				Object o2 = swagger.findRef(ref, Object.class);
+				refStack.addLast(sref);
+				Object o2 = swagger.findRef(sref, Object.class);
 				o2 = resolveRefs(o2, swagger, refStack, maxDepth);
 				refStack.removeLast();
 				return o2;
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 f39a423..3c7cbfe 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
@@ -326,6 +326,9 @@ public class SwaggerUI extends PojoSwap<Swagger,Div> {
 			for (Map.Entry<String,?> e : examples.entrySet())
 				m.put(e.getKey(), e.getValue());
 
+		if (m.isEmpty())
+			return null;
+
 		return examplesDiv(m);
 	}
 
@@ -343,6 +346,9 @@ public class SwaggerUI extends PojoSwap<Swagger,Div> {
 			for (Map.Entry<String,?> e : examples.entrySet())
 				m.put(e.getKey(), e.getValue());
 
+		if (m.isEmpty())
+			return null;
+
 		return examplesDiv(m);
 	}
 
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 e6d20d5..30b8fc0 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
@@ -328,9 +328,9 @@ final class SwaggerGenerator {
 						param.append("name", mp.name);
 
 					if (in == BODY)
-						param.put("schema", getSchema(param.getObjectMap("schema", false), mp.getType()));
+						param.appendSkipEmpty("schema", getSchema(param.getObjectMap("schema"), mp.getType()));
 					else
-						mergePartSchema(param, getSchema(param.getObjectMap("schema", false), mp.getType()));
+						mergePartSchema(param, getSchema(param.getObjectMap("schema"), mp.getType()));
 
 					try {
 						if (mp.method != null) {
@@ -392,12 +392,12 @@ final class SwaggerGenerator {
 				for (String code : responses.keySet()) {
 					ObjectMap om = responses.getObjectMap(code);
 					if (! om.containsKey("schema"))
-						om.appendSkipEmpty("schema", getSchema(om.getObjectMap("schema", true), m.getGenericReturnType()));
+						om.appendSkipEmpty("schema", getSchema(om.getObjectMap("schema"), m.getGenericReturnType()));
 				}
 			} else if (m.getGenericReturnType() != void.class) {
 				ObjectMap om = responses.getObjectMap("200", true);
 				if (! om.containsKey("schema"))
-					om.appendSkipEmpty("schema", getSchema(om.getObjectMap("schema", true), m.getGenericReturnType()));
+					om.appendSkipEmpty("schema", getSchema(om.getObjectMap("schema"), m.getGenericReturnType()));
 				addBodyExamples(sm, om, true, m.getGenericReturnType());
 			}
 
@@ -426,7 +426,7 @@ final class SwaggerGenerator {
 						for (String code : responses.keySet()) {
 							ObjectMap om = responses.getObjectMap(code);
 							if (! om.containsKey("schema"))
-								om.appendSkipEmpty("schema", getSchema(om.getObjectMap("schema", true), type));
+								om.appendSkipEmpty("schema", getSchema(om.getObjectMap("schema"), type));
 						}
 					}
 				}
@@ -655,7 +655,7 @@ final class SwaggerGenerator {
 		ObjectMap om = newMap(new ObjectMap(), a.value(), location, locationArgs);
 		om.appendSkipEmpty("description", resolve(joinnl(a.description())));
 		om.appendSkipEmpty("url", resolve(a.url()));
-		return om.isEmpty() ? null : om;
+		return nullIfEmpty(om);
 	}
 
 	private ObjectMap toMap(Contact a, String location, Object...locationArgs) throws ParseException
{
@@ -665,7 +665,7 @@ final class SwaggerGenerator {
 		om.appendSkipEmpty("name", resolve(a.name()));
 		om.appendSkipEmpty("url", resolve(a.url()));
 		om.appendSkipEmpty("email", resolve(a.email()));
-		return om.isEmpty() ? null : om;
+		return nullIfEmpty(om);
 	}
 
 	private ObjectMap toMap(License a, String location, Object...locationArgs) throws ParseException
{
@@ -674,7 +674,7 @@ final class SwaggerGenerator {
 		ObjectMap om = newMap(new ObjectMap(), a.value(), location, locationArgs);
 		om.appendSkipEmpty("name", resolve(a.name()));
 		om.appendSkipEmpty("url", resolve(a.url()));
-		return om.isEmpty() ? null : om;
+		return nullIfEmpty(om);
 	}
 
 	private ObjectMap toMap(Tag a, String location, Object...locationArgs) throws ParseException
{
@@ -682,7 +682,7 @@ final class SwaggerGenerator {
 		om.appendSkipEmpty("name", resolve(a.name()));
 		om.appendSkipEmpty("description", resolve(joinnl(a.description())));
 		om.appendSkipNull("externalDocs", merge(om.getObjectMap("externalDocs"), toMap(a.externalDocs(),
location, locationArgs)));
-		return om.isEmpty() ? null : om;
+		return nullIfEmpty(om);
 	}
 
 	private ObjectList toList(Tag[] aa, String location, Object...locationArgs) throws ParseException
{
@@ -691,7 +691,7 @@ final class SwaggerGenerator {
 		ObjectList ol = new ObjectList();
 		for (Tag a : aa)
 			ol.add(toMap(a, location, locationArgs));
-		return ol.isEmpty() ? null : ol;
+		return nullIfEmpty(ol);
 	}
 
 	private ObjectMap getSchema(ObjectMap schema, Type type) throws Exception {
@@ -706,7 +706,9 @@ final class SwaggerGenerator {
 		if (schema.containsKey("type") || schema.containsKey("$ref"))
 			return schema;
 
-		return fixSwaggerExtensions(schema.appendAll(js.getSchema(cm)));
+		ObjectMap om = fixSwaggerExtensions(schema.appendAll(js.getSchema(cm)));
+		
+		return nullIfEmpty(om);
 	}
 
 	/**
@@ -718,7 +720,7 @@ final class SwaggerGenerator {
 		om.appendSkipNull("xml", om.remove("x-xml"));
 		om.appendSkipNull("externalDocs", om.remove("x-externalDocs"));
 		om.appendSkipNull("example", om.remove("x-example"));
-		return om;
+		return nullIfEmpty(om);
 	}
 
 	private void addBodyExamples(RestJavaMethod sm, ObjectMap piri, boolean response, Type type)
throws Exception {
@@ -1219,4 +1221,12 @@ final class SwaggerGenerator {
 			codes.add(def);
 		return codes;
 	}
+
+	private static ObjectMap nullIfEmpty(ObjectMap m) {
+		return (m == null || m.isEmpty() ? null : m);
+	}
+
+	private static ObjectList nullIfEmpty(ObjectList l) {
+		return (l == null || l.isEmpty() ? null : l);
+	}
 }


Mime
View raw message