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: BasicRestInfoProvider refactor.
Date Thu, 02 Aug 2018 01:33:23 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 c9d65b5  BasicRestInfoProvider refactor.
c9d65b5 is described below

commit c9d65b5e77076239eca427114497c77c54558f33
Author: JamesBognar <jamesbognar@apache.org>
AuthorDate: Wed Aug 1 21:33:09 2018 -0400

    BasicRestInfoProvider refactor.
---
 .../apache/juneau/marshall/UrlEncodingTest.java    |  3 --
 .../apache/juneau/rest/BasicRestInfoProvider.java  | 51 ++++++++++++++++++----
 2 files changed, 42 insertions(+), 12 deletions(-)

diff --git a/juneau-core/juneau-core-test/src/test/java/org/apache/juneau/marshall/UrlEncodingTest.java
b/juneau-core/juneau-core-test/src/test/java/org/apache/juneau/marshall/UrlEncodingTest.java
index cb45239..88ca338 100644
--- a/juneau-core/juneau-core-test/src/test/java/org/apache/juneau/marshall/UrlEncodingTest.java
+++ b/juneau-core/juneau-core-test/src/test/java/org/apache/juneau/marshall/UrlEncodingTest.java
@@ -18,7 +18,6 @@ import static org.junit.Assert.assertEquals;
 import java.io.*;
 import java.util.*;
 
-import org.apache.juneau.*;
 import org.junit.*;
 
 public class UrlEncodingTest {
@@ -50,8 +49,6 @@ public class UrlEncodingTest {
 
 	@Test
 	public void read2() throws Exception {
-		ObjectMap om = new ObjectMap("{foo:'bar'}");
-		m.println(om);
 		Map<?,?> o = m.read("foo=bar", Map.class, String.class, String.class);
 		assertObjectEquals("{foo:'bar'}", o);
 	}
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 543146a..ec09f80 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
@@ -412,17 +412,15 @@ public class BasicRestInfoProvider implements RestInfoProvider {
 					if (in == BODY) {
 						for (Body a : getAnnotationsParentFirst(Body.class, mp.method, mp.index))
 							merge(param, a, vr, "ParameterInfo on class {0} method {1}", c, m);
-						if (! param.containsKey("schema"))
-							param.put("schema", getSchema(req, param.getObjectMap("schema", true), js, mp.getType()));
 
 					} else if (in == QUERY) {
 						for (Query a : getAnnotationsParentFirst(Query.class, mp.method, mp.index))
 							merge(param, a, vr, "ParameterInfo on class {0} method {1}", c, m);
-						if (! param.containsKey("schema"))
-							param.put("schema", getSchema(req, param.getObjectMap("schema", true), js, mp.getType()));
 
 					} else if (in == FORM_DATA) {
-						pi = HttpPartSchema.create(FormData.class, mp.method, mp.index).getApi();
+						for (FormData a : getAnnotationsParentFirst(FormData.class, mp.method, mp.index))
+							merge(param, a, vr, "ParameterInfo on class {0} method {1}", c, m);
+
 					} else if (in == HEADER) {
 						pi = HttpPartSchema.create(Header.class, mp.method, mp.index).getApi();
 					} else if (in == PATH) {
@@ -435,7 +433,7 @@ public class BasicRestInfoProvider implements RestInfoProvider {
 
 					// Common to all
 
-					if (in != BODY && in != QUERY) {
+					if (in != BODY && in != QUERY && in != FORM_DATA) {
 						param.appendSkipEmpty("description", resolve(vr, pi.getString("description")));
 						param.appendSkipEmpty("required", resolve(vr, pi.getString("required")));
 						param.appendSkipEmpty("type", resolve(vr, pi.getString("type")));
@@ -459,11 +457,11 @@ public class BasicRestInfoProvider implements RestInfoProvider {
 						param.appendSkipEmpty("x-example", resolve(vr, pi.getString("example")));
 						param.appendSkipEmpty("x-examples", parseMap(vr, pi.get("examples"), "ParameterInfo/examples
on class {0} method {1}", c, m));
 						param.appendSkipEmpty("items", parseMap(vr, pi.get("items"), "ParameterInfo/items on
class {0} method {1}", c, m));
-
-						// Technically Swagger doesn't support schema on non-body parameters, but we do.
-						param.appendSkipEmpty("schema", getSchema(req, param.getObjectMap("schema", true),
js, mp.getType()));
 					}
 
+					if (! param.containsKey("schema"))
+						param.put("schema", getSchema(req, param.getObjectMap("schema", true), js, mp.getType()));
+
 					if ((in == BODY || in == PATH) && ! param.containsKeyNotEmpty("required"))
 						param.put("required", true);
 
@@ -1447,6 +1445,41 @@ public class BasicRestInfoProvider implements RestInfoProvider {
 		}
 	}
 
+	private static ObjectMap merge(ObjectMap om, FormData a, VarResolverSession vr, String location,
Object...args) throws SwaggerException {
+		try {
+			if (empty(a))
+				return om;
+			om = newMap(om);
+			if (a.api().length > 0)
+				om.putAll(parseMap(vr, a.api()));
+			return om
+				.appendSkipFalse("allowEmptyValue", a.allowEmptyValue())
+				.appendSkipEmpty("collectionFormat", a.collectionFormat())
+				.appendSkipEmpty("default", joinnl(a._default()))
+				.appendSkipEmpty("description", resolve(vr, a.description()))
+				.appendSkipEmpty("enum", toSet(a._enum(), vr))
+				.appendSkipEmpty("x-example", resolve(vr, a.example()))
+				.appendSkipFalse("exclusiveMaximum", a.exclusiveMaximum())
+				.appendSkipFalse("exclusiveMinimum", a.exclusiveMinimum())
+				.appendSkipEmpty("format", a.format())
+				.appendSkipEmpty("items", merge(om.getObjectMap("items"), a.items(), vr))
+				.appendSkipEmpty("maximum", a.maximum())
+				.appendSkipMinusOne("maxItems", a.maxItems())
+				.appendSkipMinusOne("maxLength", a.maxLength())
+				.appendSkipEmpty("minimum", a.minimum())
+				.appendSkipMinusOne("minItems", a.minItems())
+				.appendSkipMinusOne("minLength", a.minLength())
+				.appendSkipEmpty("multipleOf", a.multipleOf())
+				.appendSkipEmpty("pattern", a.pattern())
+				.appendSkipFalse("required", a.required())
+				.appendSkipEmpty("type", a.type())
+				.appendSkipFalse("uniqueItems", a.uniqueItems())
+			;
+		} catch (ParseException e) {
+			throw new SwaggerException(e, "Malformed swagger JSON object encountered in " + location
+ ".", args);
+		}
+	}
+
 	private static ObjectMap merge(ObjectMap om, Schema a, VarResolverSession vr, String location,
Object...args) throws SwaggerException {
 		try {
 			if (empty(a))


Mime
View raw message