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 52a3864 Swagger UI improvements.
52a3864 is described below
commit 52a3864ede759019b6d2cfa44b3752e1ca60b4a6
Author: JamesBognar <[email protected]>
AuthorDate: Wed Apr 4 20:56:42 2018 -0400
Swagger UI improvements.
---
.../juneau/json/JsonSchemaSerializerTest.java | 244 ++++++++++-----------
.../org/apache/juneau/dto/swagger/HeaderInfo.java | 17 +-
.../java/org/apache/juneau/dto/swagger/Items.java | 28 ++-
.../org/apache/juneau/dto/swagger/Operation.java | 21 --
.../apache/juneau/dto/swagger/ParameterInfo.java | 11 +-
.../apache/juneau/dto/swagger/ResponseInfo.java | 7 +-
.../org/apache/juneau/dto/swagger/SchemaInfo.java | 23 +-
.../org/apache/juneau/dto/swagger/Swagger.java | 23 --
.../apache/juneau/dto/swagger/SwaggerElement.java | 11 +-
.../apache/juneau/dto/swagger/ui/SwaggerUI.java | 31 +--
.../src/main/java/org/apache/juneau/BeanMap.java | 11 +-
.../src/main/java/org/apache/juneau/ClassMeta.java | 8 -
.../jsonschema/JsonSchemaSerializerSession.java | 19 +-
juneau-doc/src/main/javadoc/overview.html | 3 +
.../juneau/examples/rest/petstore/Order.java | 1 +
.../apache/juneau/examples/rest/petstore/Pet.java | 1 +
.../examples/rest/petstore/PetStoreResource.java | 119 +++++++---
.../apache/juneau/examples/rest/petstore/User.java | 11 +
.../apache/juneau/rest/BasicRestInfoProvider.java | 157 ++++++++-----
.../org/apache/juneau/rest/RestParamDefaults.java | 5 +
.../org/apache/juneau/rest/annotation/Body.java | 20 ++
.../apache/juneau/rest/annotation/FormData.java | 18 ++
.../org/apache/juneau/rest/annotation/Header.java | 19 ++
.../org/apache/juneau/rest/annotation/Path.java | 19 ++
.../org/apache/juneau/rest/annotation/Query.java | 18 ++
.../apache/juneau/rest/labels/NameDescription.java | 89 --------
.../juneau/rest/labels/ResourceDescription.java | 51 ++++-
27 files changed, 570 insertions(+), 415 deletions(-)
diff --git
a/juneau-core/juneau-core-test/src/test/java/org/apache/juneau/json/JsonSchemaSerializerTest.java
b/juneau-core/juneau-core-test/src/test/java/org/apache/juneau/json/JsonSchemaSerializerTest.java
index 639e224..1cfcd7d 100755
---
a/juneau-core/juneau-core-test/src/test/java/org/apache/juneau/json/JsonSchemaSerializerTest.java
+++
b/juneau-core/juneau-core-test/src/test/java/org/apache/juneau/json/JsonSchemaSerializerTest.java
@@ -419,7 +419,7 @@ public class JsonSchemaSerializerTest {
@Test
public void addExample_BEAN_exampleMethod() throws Exception {
JsonSchemaSerializerSession s =
JsonSchemaSerializer.DEFAULT_LAX.builder().addExamplesTo("bean").build().createSession();
-
assertObjectEquals("{type:'object',properties:{f1:{type:'string'}},example:{f1:'foobar'}}",
s.getSchema(SimpleBeanWithExampleMethod.class));
+
assertObjectEquals("{type:'object',properties:{f1:{type:'string'}},'x-example':{f1:'foobar'}}",
s.getSchema(SimpleBeanWithExampleMethod.class));
}
@Test
@@ -427,13 +427,13 @@ public class JsonSchemaSerializerTest {
SimpleBeanWithExampleMethod b = new
SimpleBeanWithExampleMethod();
b.f1 = "baz";
JsonSchemaSerializerSession s =
JsonSchemaSerializer.DEFAULT_LAX.builder().addExamplesTo("bean").example(SimpleBeanWithExampleMethod.class,
b).build().createSession();
-
assertObjectEquals("{type:'object',properties:{f1:{type:'string'}},example:{f1:'baz'}}",
s.getSchema(SimpleBeanWithExampleMethod.class));
+
assertObjectEquals("{type:'object',properties:{f1:{type:'string'}},'x-example':{f1:'baz'}}",
s.getSchema(SimpleBeanWithExampleMethod.class));
}
@Test
public void addExample_BEAN_exampleMethod_array2d() throws Exception {
JsonSchemaSerializerSession s =
JsonSchemaSerializer.DEFAULT_LAX.builder().addExamplesTo("bean").build().createSession();
-
assertObjectEquals("{type:'array',items:{type:'array',items:{type:'object',properties:{f1:{type:'string'}},example:{f1:'foobar'}}}}",
s.getSchema(SimpleBeanWithExampleMethod[][].class));
+
assertObjectEquals("{type:'array',items:{type:'array',items:{type:'object',properties:{f1:{type:'string'}},'x-example':{f1:'foobar'}}}}",
s.getSchema(SimpleBeanWithExampleMethod[][].class));
}
public static class SimpleBeanWithExampleMethod extends SimpleBean {
@@ -449,13 +449,13 @@ public class JsonSchemaSerializerTest {
@Test
public void addExample_BEAN_exampleField() throws Exception {
JsonSchemaSerializerSession s =
JsonSchemaSerializer.DEFAULT_LAX.builder().addExamplesTo("bean").build().createSession();
-
assertObjectEquals("{type:'object',properties:{f1:{type:'string'}},example:{f1:'foobar'}}",
s.getSchema(SimpleBeanWithExampleField.class));
+
assertObjectEquals("{type:'object',properties:{f1:{type:'string'}},'x-example':{f1:'foobar'}}",
s.getSchema(SimpleBeanWithExampleField.class));
}
@Test
public void addExample_BEAN_exampleField_array2d() throws Exception {
JsonSchemaSerializerSession s =
JsonSchemaSerializer.DEFAULT_LAX.builder().addExamplesTo("bean").build().createSession();
-
assertObjectEquals("{type:'array',items:{type:'array',items:{type:'object',properties:{f1:{type:'string'}},example:{f1:'foobar'}}}}",
s.getSchema(SimpleBeanWithExampleField[][].class));
+
assertObjectEquals("{type:'array',items:{type:'array',items:{type:'object',properties:{f1:{type:'string'}},'x-example':{f1:'foobar'}}}}",
s.getSchema(SimpleBeanWithExampleField[][].class));
}
public static class SimpleBeanWithExampleField extends SimpleBean {
@@ -473,13 +473,13 @@ public class JsonSchemaSerializerTest {
@Test
public void addExample_BEAN_exampleBeanAnnotation() throws Exception {
JsonSchemaSerializerSession s =
JsonSchemaSerializer.DEFAULT_LAX.builder().addExamplesTo("bean").build().createSession();
-
assertObjectEquals("{type:'object',properties:{f1:{type:'string'}},example:{f1:'foobar'}}",
s.getSchema(SimpleBeanWithExampleAnnotation.class));
+
assertObjectEquals("{type:'object',properties:{f1:{type:'string'}},'x-example':{f1:'foobar'}}",
s.getSchema(SimpleBeanWithExampleAnnotation.class));
}
@Test
public void addExample_BEAN_exampleBeanAnnotation_2darray() throws
Exception {
JsonSchemaSerializerSession s =
JsonSchemaSerializer.DEFAULT_LAX.builder().addExamplesTo("bean").build().createSession();
-
assertObjectEquals("{type:'array',items:{type:'array',items:{type:'object',properties:{f1:{type:'string'}},example:{f1:'foobar'}}}}",
s.getSchema(SimpleBeanWithExampleAnnotation[][].class));
+
assertObjectEquals("{type:'array',items:{type:'array',items:{type:'object',properties:{f1:{type:'string'}},'x-example':{f1:'foobar'}}}}",
s.getSchema(SimpleBeanWithExampleAnnotation[][].class));
}
@Example("{f1:'foobar'}")
@@ -490,7 +490,7 @@ public class JsonSchemaSerializerTest {
SimpleBean b = new SimpleBean();
b.f1 = "foobar";
JsonSchemaSerializerSession s =
JsonSchemaSerializer.DEFAULT_LAX.builder().addExamplesTo("bean").example(SimpleBean.class,
b).build().createSession();
-
assertObjectEquals("{type:'object',properties:{f1:{type:'string'}},example:{f1:'foobar'}}",
s.getSchema(SimpleBean.class));
+
assertObjectEquals("{type:'object',properties:{f1:{type:'string'}},'x-example':{f1:'foobar'}}",
s.getSchema(SimpleBean.class));
}
@Test
@@ -498,7 +498,7 @@ public class JsonSchemaSerializerTest {
SimpleBean b = new SimpleBean();
b.f1 = "foobar";
JsonSchemaSerializerSession s =
JsonSchemaSerializer.DEFAULT_LAX.builder().addExamplesTo("bean").example(SimpleBean.class,
b).build().createSession();
-
assertObjectEquals("{type:'array',items:{type:'array',items:{type:'object',properties:{f1:{type:'string'}},example:{f1:'foobar'}}}}",
s.getSchema(SimpleBean[][].class));
+
assertObjectEquals("{type:'array',items:{type:'array',items:{type:'object',properties:{f1:{type:'string'}},'x-example':{f1:'foobar'}}}}",
s.getSchema(SimpleBean[][].class));
}
//====================================================================================================
@@ -514,7 +514,7 @@ public class JsonSchemaSerializerTest {
@Test
public void addExample_MAP_exampleMethod() throws Exception {
JsonSchemaSerializerSession s =
JsonSchemaSerializer.DEFAULT_LAX.builder().addExamplesTo("map").build().createSession();
-
assertObjectEquals("{type:'object',additionalProperties:{type:'object',properties:{f1:{type:'string'}}},example:{'123':{f1:'foobar'}}}",
s.getSchema(BeanMapWithExampleMethod.class));
+
assertObjectEquals("{type:'object',additionalProperties:{type:'object',properties:{f1:{type:'string'}}},'x-example':{'123':{f1:'foobar'}}}",
s.getSchema(BeanMapWithExampleMethod.class));
}
@Test
@@ -522,7 +522,7 @@ public class JsonSchemaSerializerTest {
BeanMapWithExampleMethod b = new BeanMapWithExampleMethod();
b.put(456, SimpleBeanWithExampleMethod.example());
JsonSchemaSerializerSession s =
JsonSchemaSerializer.DEFAULT_LAX.builder().addExamplesTo("map").example(BeanMapWithExampleMethod.class,
b).build().createSession();
-
assertObjectEquals("{type:'object',additionalProperties:{type:'object',properties:{f1:{type:'string'}}},example:{'456':{f1:'foobar'}}}",
s.getSchema(BeanMapWithExampleMethod.class));
+
assertObjectEquals("{type:'object',additionalProperties:{type:'object',properties:{f1:{type:'string'}}},'x-example':{'456':{f1:'foobar'}}}",
s.getSchema(BeanMapWithExampleMethod.class));
}
@SuppressWarnings("serial")
@@ -539,13 +539,13 @@ public class JsonSchemaSerializerTest {
@Test
public void addExample_MAP_exampleField() throws Exception {
JsonSchemaSerializerSession s =
JsonSchemaSerializer.DEFAULT_LAX.builder().addExamplesTo("map").build().createSession();
-
assertObjectEquals("{type:'object',additionalProperties:{type:'object',properties:{f1:{type:'string'}}},example:{'123':{f1:'foobar'}}}",
s.getSchema(BeanMapWithExampleField.class));
+
assertObjectEquals("{type:'object',additionalProperties:{type:'object',properties:{f1:{type:'string'}}},'x-example':{'123':{f1:'foobar'}}}",
s.getSchema(BeanMapWithExampleField.class));
}
@Test
public void addExample_MAP_exampleField_array2d() throws Exception {
JsonSchemaSerializerSession s =
JsonSchemaSerializer.DEFAULT_LAX.builder().addExamplesTo("map").build().createSession();
-
assertObjectEquals("{type:'array',items:{type:'array',items:{type:'object',additionalProperties:{type:'object',properties:{f1:{type:'string'}}},example:{'123':{f1:'foobar'}}}}}",
s.getSchema(BeanMapWithExampleField[][].class));
+
assertObjectEquals("{type:'array',items:{type:'array',items:{type:'object',additionalProperties:{type:'object',properties:{f1:{type:'string'}}},'x-example':{'123':{f1:'foobar'}}}}}",
s.getSchema(BeanMapWithExampleField[][].class));
}
@SuppressWarnings("serial")
@@ -564,13 +564,13 @@ public class JsonSchemaSerializerTest {
@Test
public void addExample_MAP_exampleBeanAnnotation() throws Exception {
JsonSchemaSerializerSession s =
JsonSchemaSerializer.DEFAULT_LAX.builder().addExamplesTo("map").build().createSession();
-
assertObjectEquals("{type:'object',additionalProperties:{type:'object',properties:{f1:{type:'string'}}},example:{'123':{f1:'baz'}}}",
s.getSchema(BeanMapWithExampleAnnotation.class));
+
assertObjectEquals("{type:'object',additionalProperties:{type:'object',properties:{f1:{type:'string'}}},'x-example':{'123':{f1:'baz'}}}",
s.getSchema(BeanMapWithExampleAnnotation.class));
}
@Test
public void addExample_MAP_exampleBeanAnnotation_2darray() throws
Exception {
JsonSchemaSerializerSession s =
JsonSchemaSerializer.DEFAULT_LAX.builder().addExamplesTo("map").build().createSession();
-
assertObjectEquals("{type:'array',items:{type:'array',items:{type:'object',additionalProperties:{type:'object',properties:{f1:{type:'string'}}},example:{'123':{f1:'baz'}}}}}",
s.getSchema(BeanMapWithExampleAnnotation[][].class));
+
assertObjectEquals("{type:'array',items:{type:'array',items:{type:'object',additionalProperties:{type:'object',properties:{f1:{type:'string'}}},'x-example':{'123':{f1:'baz'}}}}}",
s.getSchema(BeanMapWithExampleAnnotation[][].class));
}
@SuppressWarnings("serial")
@@ -580,13 +580,13 @@ public class JsonSchemaSerializerTest {
@Test
public void addExample_MAP_exampleBeanProperty() throws Exception {
JsonSchemaSerializerSession s =
JsonSchemaSerializer.DEFAULT_LAX.builder().addExamplesTo("map").example(BeanMap.class,
BeanMapWithExampleMethod.example()).build().createSession();
-
assertObjectEquals("{type:'object',additionalProperties:{type:'object',properties:{f1:{type:'string'}}},example:{'123':{f1:'foobar'}}}",
s.getSchema(BeanMap.class));
+
assertObjectEquals("{type:'object',additionalProperties:{type:'object',properties:{f1:{type:'string'}}},'x-example':{'123':{f1:'foobar'}}}",
s.getSchema(BeanMap.class));
}
@Test
public void addExample_MAP_exampleBeanProperty_2darray() throws
Exception {
JsonSchemaSerializerSession s =
JsonSchemaSerializer.DEFAULT_LAX.builder().addExamplesTo("map").example(BeanMap.class,
BeanMapWithExampleMethod.example()).build().createSession();
-
assertObjectEquals("{type:'array',items:{type:'array',items:{type:'object',additionalProperties:{type:'object',properties:{f1:{type:'string'}}},example:{'123':{f1:'foobar'}}}}}",
s.getSchema(BeanMap[][].class));
+
assertObjectEquals("{type:'array',items:{type:'array',items:{type:'object',additionalProperties:{type:'object',properties:{f1:{type:'string'}}},'x-example':{'123':{f1:'foobar'}}}}}",
s.getSchema(BeanMap[][].class));
}
//====================================================================================================
@@ -602,7 +602,7 @@ public class JsonSchemaSerializerTest {
@Test
public void addExample_COLLECTION_exampleMethod() throws Exception {
JsonSchemaSerializerSession s =
JsonSchemaSerializer.DEFAULT_LAX.builder().addExamplesTo("collection").build().createSession();
-
assertObjectEquals("{type:'array',items:{type:'object',properties:{f1:{type:'string'}}},example:[{f1:'foobar'}]}",
s.getSchema(BeanListWithExampleMethod.class));
+
assertObjectEquals("{type:'array',items:{type:'object',properties:{f1:{type:'string'}}},'x-example':[{f1:'foobar'}]}",
s.getSchema(BeanListWithExampleMethod.class));
}
@Test
@@ -612,7 +612,7 @@ public class JsonSchemaSerializerTest {
sb.f1 = "baz";
b.add(sb);
JsonSchemaSerializerSession s =
JsonSchemaSerializer.DEFAULT_LAX.builder().addExamplesTo("collection").example(BeanListWithExampleMethod.class,
b).build().createSession();
-
assertObjectEquals("{type:'array',items:{type:'object',properties:{f1:{type:'string'}}},example:[{f1:'baz'}]}",
s.getSchema(BeanListWithExampleMethod.class));
+
assertObjectEquals("{type:'array',items:{type:'object',properties:{f1:{type:'string'}}},'x-example':[{f1:'baz'}]}",
s.getSchema(BeanListWithExampleMethod.class));
}
@SuppressWarnings("serial")
@@ -629,13 +629,13 @@ public class JsonSchemaSerializerTest {
@Test
public void addExample_COLLECTION_exampleField() throws Exception {
JsonSchemaSerializerSession s =
JsonSchemaSerializer.DEFAULT_LAX.builder().addExamplesTo("collection").build().createSession();
-
assertObjectEquals("{type:'array',items:{type:'object',properties:{f1:{type:'string'}}},example:[{f1:'foobar'}]}",
s.getSchema(BeanListWithExampleField.class));
+
assertObjectEquals("{type:'array',items:{type:'object',properties:{f1:{type:'string'}}},'x-example':[{f1:'foobar'}]}",
s.getSchema(BeanListWithExampleField.class));
}
@Test
public void addExample_ARRAY_exampleField_array2d() throws Exception {
JsonSchemaSerializerSession s =
JsonSchemaSerializer.DEFAULT_LAX.builder().addExamplesTo("array").build().createSession();
-
assertObjectEquals("{type:'array',items:{type:'array',items:{type:'array',items:{type:'object',properties:{f1:{type:'string'}}}}},example:[[[{f1:'foobar'}]]]}",
s.getSchema(BeanListWithExampleField[][].class));
+
assertObjectEquals("{type:'array',items:{type:'array',items:{type:'array',items:{type:'object',properties:{f1:{type:'string'}}}}},'x-example':[[[{f1:'foobar'}]]]}",
s.getSchema(BeanListWithExampleField[][].class));
}
@SuppressWarnings("serial")
@@ -654,13 +654,13 @@ public class JsonSchemaSerializerTest {
@Test
public void addExample_COLLECTION_exampleBeanAnnotation() throws
Exception {
JsonSchemaSerializerSession s =
JsonSchemaSerializer.DEFAULT_LAX.builder().addExamplesTo("collection").build().createSession();
-
assertObjectEquals("{type:'array',items:{type:'object',properties:{f1:{type:'string'}}},example:[{f1:'baz'}]}",
s.getSchema(BeanListWithExampleAnnotation.class));
+
assertObjectEquals("{type:'array',items:{type:'object',properties:{f1:{type:'string'}}},'x-example':[{f1:'baz'}]}",
s.getSchema(BeanListWithExampleAnnotation.class));
}
@Test
public void addExample_ARRAY_exampleBeanAnnotation_2darray() throws
Exception {
JsonSchemaSerializerSession s =
JsonSchemaSerializer.DEFAULT_LAX.builder().addExamplesTo("array").build().createSession();
-
assertObjectEquals("{type:'array',items:{type:'array',items:{type:'array',items:{type:'object',properties:{f1:{type:'string'}}}}},example:[[[{f1:'baz'}]]]}",
s.getSchema(BeanListWithExampleAnnotation[][].class));
+
assertObjectEquals("{type:'array',items:{type:'array',items:{type:'array',items:{type:'object',properties:{f1:{type:'string'}}}}},'x-example':[[[{f1:'baz'}]]]}",
s.getSchema(BeanListWithExampleAnnotation[][].class));
}
@SuppressWarnings("serial")
@@ -670,13 +670,13 @@ public class JsonSchemaSerializerTest {
@Test
public void addExample_COLLECTION_exampleBeanProperty() throws
Exception {
JsonSchemaSerializerSession s
=JsonSchemaSerializer.DEFAULT_LAX.builder().addExamplesTo("collection").example(BeanList.class,
BeanListWithExampleMethod.example()).build().createSession();
-
assertObjectEquals("{type:'array',items:{type:'object',properties:{f1:{type:'string'}}},example:[{f1:'foobar'}]}",
s.getSchema(BeanList.class));
+
assertObjectEquals("{type:'array',items:{type:'object',properties:{f1:{type:'string'}}},'x-example':[{f1:'foobar'}]}",
s.getSchema(BeanList.class));
}
@Test
public void addExample_ARRAY_exampleBeanProperty_2darray() throws
Exception {
JsonSchemaSerializerSession s =
JsonSchemaSerializer.DEFAULT_LAX.builder().addExamplesTo("array").example(BeanList.class,
BeanListWithExampleMethod.example()).build().createSession();
-
assertObjectEquals("{type:'array',items:{type:'array',items:{type:'array',items:{type:'object',properties:{f1:{type:'string'}}}}},example:[[[{f1:'foobar'}]]]}",
s.getSchema(BeanList[][].class));
+
assertObjectEquals("{type:'array',items:{type:'array',items:{type:'array',items:{type:'object',properties:{f1:{type:'string'}}}}},'x-example':[[[{f1:'foobar'}]]]}",
s.getSchema(BeanList[][].class));
}
//====================================================================================================
@@ -685,8 +685,8 @@ public class JsonSchemaSerializerTest {
@Test
public void addExample_BOOLEAN() throws Exception {
JsonSchemaSerializerSession s =
JsonSchemaSerializer.DEFAULT_LAX.builder().addExamplesTo("boolean").build().createSession();
- assertObjectEquals("{type:'boolean',example:true}",
s.getSchema(boolean.class));
- assertObjectEquals("{type:'boolean',example:true}",
s.getSchema(Boolean.class));
+ assertObjectEquals("{type:'boolean','x-example':true}",
s.getSchema(boolean.class));
+ assertObjectEquals("{type:'boolean','x-example':true}",
s.getSchema(Boolean.class));
}
@Test
@@ -695,15 +695,15 @@ public class JsonSchemaSerializerTest {
.example(boolean.class, false)
.example(Boolean.class, false)
.build().createSession();
- assertObjectEquals("{type:'boolean',example:false}",
s.getSchema(boolean.class));
- assertObjectEquals("{type:'boolean',example:false}",
s.getSchema(Boolean.class));
+ assertObjectEquals("{type:'boolean','x-example':false}",
s.getSchema(boolean.class));
+ assertObjectEquals("{type:'boolean','x-example':false}",
s.getSchema(Boolean.class));
}
@Test
public void addExample_BOOLEAN_2darray() throws Exception {
JsonSchemaSerializerSession s =
JsonSchemaSerializer.DEFAULT_LAX.builder().addExamplesTo("boolean").build().createSession();
-
assertObjectEquals("{type:'array',items:{type:'array',items:{type:'boolean',example:true}}}",
s.getSchema(boolean[][].class));
-
assertObjectEquals("{type:'array',items:{type:'array',items:{type:'boolean',example:true}}}",
s.getSchema(Boolean[][].class));
+
assertObjectEquals("{type:'array',items:{type:'array',items:{type:'boolean','x-example':true}}}",
s.getSchema(boolean[][].class));
+
assertObjectEquals("{type:'array',items:{type:'array',items:{type:'boolean','x-example':true}}}",
s.getSchema(Boolean[][].class));
}
//====================================================================================================
@@ -712,16 +712,16 @@ public class JsonSchemaSerializerTest {
@Test
public void addExample_NUMBER() throws Exception {
JsonSchemaSerializerSession s =
JsonSchemaSerializer.DEFAULT_LAX.builder().addExamplesTo("number").build().createSession();
- assertObjectEquals("{type:'integer',format:'int16',example:1}",
s.getSchema(short.class));
- assertObjectEquals("{type:'integer',format:'int16',example:1}",
s.getSchema(Short.class));
- assertObjectEquals("{type:'integer',format:'int32',example:1}",
s.getSchema(int.class));
- assertObjectEquals("{type:'integer',format:'int32',example:1}",
s.getSchema(Integer.class));
- assertObjectEquals("{type:'integer',format:'int64',example:1}",
s.getSchema(long.class));
- assertObjectEquals("{type:'integer',format:'int64',example:1}",
s.getSchema(Long.class));
-
assertObjectEquals("{type:'number',format:'float',example:1.0}",
s.getSchema(float.class));
-
assertObjectEquals("{type:'number',format:'float',example:1.0}",
s.getSchema(Float.class));
-
assertObjectEquals("{type:'number',format:'double',example:1.0}",
s.getSchema(double.class));
-
assertObjectEquals("{type:'number',format:'double',example:1.0}",
s.getSchema(Double.class));
+
assertObjectEquals("{type:'integer',format:'int16','x-example':1}",
s.getSchema(short.class));
+
assertObjectEquals("{type:'integer',format:'int16','x-example':1}",
s.getSchema(Short.class));
+
assertObjectEquals("{type:'integer',format:'int32','x-example':1}",
s.getSchema(int.class));
+
assertObjectEquals("{type:'integer',format:'int32','x-example':1}",
s.getSchema(Integer.class));
+
assertObjectEquals("{type:'integer',format:'int64','x-example':1}",
s.getSchema(long.class));
+
assertObjectEquals("{type:'integer',format:'int64','x-example':1}",
s.getSchema(Long.class));
+
assertObjectEquals("{type:'number',format:'float','x-example':1.0}",
s.getSchema(float.class));
+
assertObjectEquals("{type:'number',format:'float','x-example':1.0}",
s.getSchema(Float.class));
+
assertObjectEquals("{type:'number',format:'double','x-example':1.0}",
s.getSchema(double.class));
+
assertObjectEquals("{type:'number',format:'double','x-example':1.0}",
s.getSchema(Double.class));
}
@Test
@@ -738,31 +738,31 @@ public class JsonSchemaSerializerTest {
.example(double.class, 10d)
.example(Double.class, 11d)
.build().createSession();
- assertObjectEquals("{type:'integer',format:'int16',example:2}",
s.getSchema(short.class));
- assertObjectEquals("{type:'integer',format:'int16',example:3}",
s.getSchema(Short.class));
- assertObjectEquals("{type:'integer',format:'int32',example:4}",
s.getSchema(int.class));
- assertObjectEquals("{type:'integer',format:'int32',example:5}",
s.getSchema(Integer.class));
- assertObjectEquals("{type:'integer',format:'int64',example:6}",
s.getSchema(long.class));
- assertObjectEquals("{type:'integer',format:'int64',example:7}",
s.getSchema(Long.class));
-
assertObjectEquals("{type:'number',format:'float',example:8.0}",
s.getSchema(float.class));
-
assertObjectEquals("{type:'number',format:'float',example:9.0}",
s.getSchema(Float.class));
-
assertObjectEquals("{type:'number',format:'double',example:10.0}",
s.getSchema(double.class));
-
assertObjectEquals("{type:'number',format:'double',example:11.0}",
s.getSchema(Double.class));
+
assertObjectEquals("{type:'integer',format:'int16','x-example':2}",
s.getSchema(short.class));
+
assertObjectEquals("{type:'integer',format:'int16','x-example':3}",
s.getSchema(Short.class));
+
assertObjectEquals("{type:'integer',format:'int32','x-example':4}",
s.getSchema(int.class));
+
assertObjectEquals("{type:'integer',format:'int32','x-example':5}",
s.getSchema(Integer.class));
+
assertObjectEquals("{type:'integer',format:'int64','x-example':6}",
s.getSchema(long.class));
+
assertObjectEquals("{type:'integer',format:'int64','x-example':7}",
s.getSchema(Long.class));
+
assertObjectEquals("{type:'number',format:'float','x-example':8.0}",
s.getSchema(float.class));
+
assertObjectEquals("{type:'number',format:'float','x-example':9.0}",
s.getSchema(Float.class));
+
assertObjectEquals("{type:'number',format:'double','x-example':10.0}",
s.getSchema(double.class));
+
assertObjectEquals("{type:'number',format:'double','x-example':11.0}",
s.getSchema(Double.class));
}
@Test
public void addExample_NUMBER_2darray() throws Exception {
JsonSchemaSerializerSession s =
JsonSchemaSerializer.DEFAULT_LAX.builder().addExamplesTo("number").build().createSession();
-
assertObjectEquals("{type:'array',items:{type:'array',items:{type:'integer',format:'int16',example:1}}}",
s.getSchema(short[][].class));
-
assertObjectEquals("{type:'array',items:{type:'array',items:{type:'integer',format:'int16',example:1}}}",
s.getSchema(Short[][].class));
-
assertObjectEquals("{type:'array',items:{type:'array',items:{type:'integer',format:'int32',example:1}}}",
s.getSchema(int[][].class));
-
assertObjectEquals("{type:'array',items:{type:'array',items:{type:'integer',format:'int32',example:1}}}",
s.getSchema(Integer[][].class));
-
assertObjectEquals("{type:'array',items:{type:'array',items:{type:'integer',format:'int64',example:1}}}",
s.getSchema(long[][].class));
-
assertObjectEquals("{type:'array',items:{type:'array',items:{type:'integer',format:'int64',example:1}}}",
s.getSchema(Long[][].class));
-
assertObjectEquals("{type:'array',items:{type:'array',items:{type:'number',format:'float',example:1.0}}}",
s.getSchema(float[][].class));
-
assertObjectEquals("{type:'array',items:{type:'array',items:{type:'number',format:'float',example:1.0}}}",
s.getSchema(Float[][].class));
-
assertObjectEquals("{type:'array',items:{type:'array',items:{type:'number',format:'double',example:1.0}}}",
s.getSchema(double[][].class));
-
assertObjectEquals("{type:'array',items:{type:'array',items:{type:'number',format:'double',example:1.0}}}",
s.getSchema(Double[][].class));
+
assertObjectEquals("{type:'array',items:{type:'array',items:{type:'integer',format:'int16','x-example':1}}}",
s.getSchema(short[][].class));
+
assertObjectEquals("{type:'array',items:{type:'array',items:{type:'integer',format:'int16','x-example':1}}}",
s.getSchema(Short[][].class));
+
assertObjectEquals("{type:'array',items:{type:'array',items:{type:'integer',format:'int32','x-example':1}}}",
s.getSchema(int[][].class));
+
assertObjectEquals("{type:'array',items:{type:'array',items:{type:'integer',format:'int32','x-example':1}}}",
s.getSchema(Integer[][].class));
+
assertObjectEquals("{type:'array',items:{type:'array',items:{type:'integer',format:'int64','x-example':1}}}",
s.getSchema(long[][].class));
+
assertObjectEquals("{type:'array',items:{type:'array',items:{type:'integer',format:'int64','x-example':1}}}",
s.getSchema(Long[][].class));
+
assertObjectEquals("{type:'array',items:{type:'array',items:{type:'number',format:'float','x-example':1.0}}}",
s.getSchema(float[][].class));
+
assertObjectEquals("{type:'array',items:{type:'array',items:{type:'number',format:'float','x-example':1.0}}}",
s.getSchema(Float[][].class));
+
assertObjectEquals("{type:'array',items:{type:'array',items:{type:'number',format:'double','x-example':1.0}}}",
s.getSchema(double[][].class));
+
assertObjectEquals("{type:'array',items:{type:'array',items:{type:'number',format:'double','x-example':1.0}}}",
s.getSchema(Double[][].class));
}
//====================================================================================================
@@ -772,10 +772,10 @@ public class JsonSchemaSerializerTest {
@Test
public void addExample_STRING() throws Exception {
JsonSchemaSerializerSession s =
JsonSchemaSerializer.DEFAULT_LAX.builder().addExamplesTo("string").build().createSession();
- assertObjectEquals("{type:'string',example:'foo'}",
s.getSchema(String.class));
- assertObjectEquals("{type:'string',example:'foo'}",
s.getSchema(StringBuilder.class));
- assertObjectEquals("{type:'string',example:'a'}",
s.getSchema(Character.class));
- assertObjectEquals("{type:'string',example:'a'}",
s.getSchema(char.class));
+ assertObjectEquals("{type:'string','x-example':'foo'}",
s.getSchema(String.class));
+ assertObjectEquals("{type:'string','x-example':'foo'}",
s.getSchema(StringBuilder.class));
+ assertObjectEquals("{type:'string','x-example':'a'}",
s.getSchema(Character.class));
+ assertObjectEquals("{type:'string','x-example':'a'}",
s.getSchema(char.class));
}
@Test
@@ -786,19 +786,19 @@ public class JsonSchemaSerializerTest {
.example(Character.class, 'b')
.example(char.class, 'c')
.build().createSession();
- assertObjectEquals("{type:'string',example:'bar1'}",
s.getSchema(String.class));
- assertObjectEquals("{type:'string',example:'bar2'}",
s.getSchema(StringBuilder.class));
- assertObjectEquals("{type:'string',example:'b'}",
s.getSchema(Character.class));
- assertObjectEquals("{type:'string',example:'c'}",
s.getSchema(char.class));
+ assertObjectEquals("{type:'string','x-example':'bar1'}",
s.getSchema(String.class));
+ assertObjectEquals("{type:'string','x-example':'bar2'}",
s.getSchema(StringBuilder.class));
+ assertObjectEquals("{type:'string','x-example':'b'}",
s.getSchema(Character.class));
+ assertObjectEquals("{type:'string','x-example':'c'}",
s.getSchema(char.class));
}
@Test
public void addExample_STRING_2darray() throws Exception {
JsonSchemaSerializerSession s =
JsonSchemaSerializer.DEFAULT_LAX.builder().addExamplesTo("string").build().createSession();
-
assertObjectEquals("{type:'array',items:{type:'array',items:{type:'string',example:'foo'}}}",
s.getSchema(String[][].class));
-
assertObjectEquals("{type:'array',items:{type:'array',items:{type:'string',example:'foo'}}}",
s.getSchema(StringBuilder[][].class));
-
assertObjectEquals("{type:'array',items:{type:'array',items:{type:'string',example:'a'}}}",
s.getSchema(Character[][].class));
-
assertObjectEquals("{type:'array',items:{type:'array',items:{type:'string',example:'a'}}}",
s.getSchema(char[][].class));
+
assertObjectEquals("{type:'array',items:{type:'array',items:{type:'string','x-example':'foo'}}}",
s.getSchema(String[][].class));
+
assertObjectEquals("{type:'array',items:{type:'array',items:{type:'string','x-example':'foo'}}}",
s.getSchema(StringBuilder[][].class));
+
assertObjectEquals("{type:'array',items:{type:'array',items:{type:'string','x-example':'a'}}}",
s.getSchema(Character[][].class));
+
assertObjectEquals("{type:'array',items:{type:'array',items:{type:'string','x-example':'a'}}}",
s.getSchema(char[][].class));
}
@Test
@@ -809,10 +809,10 @@ public class JsonSchemaSerializerTest {
.example(Character.class, 'b')
.example(char.class, 'c')
.build().createSession();
-
assertObjectEquals("{type:'array',items:{type:'array',items:{type:'string',example:'bar1'}}}",
s.getSchema(String[][].class));
-
assertObjectEquals("{type:'array',items:{type:'array',items:{type:'string',example:'bar2'}}}",
s.getSchema(StringBuilder[][].class));
-
assertObjectEquals("{type:'array',items:{type:'array',items:{type:'string',example:'b'}}}",
s.getSchema(Character[][].class));
-
assertObjectEquals("{type:'array',items:{type:'array',items:{type:'string',example:'c'}}}",
s.getSchema(char[][].class));
+
assertObjectEquals("{type:'array',items:{type:'array',items:{type:'string','x-example':'bar1'}}}",
s.getSchema(String[][].class));
+
assertObjectEquals("{type:'array',items:{type:'array',items:{type:'string','x-example':'bar2'}}}",
s.getSchema(StringBuilder[][].class));
+
assertObjectEquals("{type:'array',items:{type:'array',items:{type:'string','x-example':'b'}}}",
s.getSchema(Character[][].class));
+
assertObjectEquals("{type:'array',items:{type:'array',items:{type:'string','x-example':'c'}}}",
s.getSchema(char[][].class));
}
//====================================================================================================
@@ -822,37 +822,37 @@ public class JsonSchemaSerializerTest {
@Test
public void addExample_ENUM() throws Exception {
JsonSchemaSerializerSession s =
JsonSchemaSerializer.DEFAULT_LAX.builder().addExamplesTo("enum").build().createSession();
-
assertObjectEquals("{type:'string','enum':['one','two','three'],example:'one'}",
s.getSchema(TestEnum.class));
+
assertObjectEquals("{type:'string','enum':['one','two','three'],'x-example':'one'}",
s.getSchema(TestEnum.class));
}
@Test
public void addExample_ENUM_wDefault() throws Exception {
JsonSchemaSerializerSession s =
JsonSchemaSerializer.DEFAULT_LAX.builder().addExamplesTo("enum").example(TestEnum.class,
TestEnum.TWO).build().createSession();
-
assertObjectEquals("{type:'string','enum':['one','two','three'],example:'two'}",
s.getSchema(TestEnum.class));
+
assertObjectEquals("{type:'string','enum':['one','two','three'],'x-example':'two'}",
s.getSchema(TestEnum.class));
}
@Test
public void addExample_ENUM_2darray() throws Exception {
JsonSchemaSerializerSession s =
JsonSchemaSerializer.DEFAULT_LAX.builder().addExamplesTo("enum").build().createSession();
-
assertObjectEquals("{type:'array',items:{type:'array',items:{type:'string','enum':['one','two','three'],example:'one'}}}",
s.getSchema(TestEnum[][].class));
+
assertObjectEquals("{type:'array',items:{type:'array',items:{type:'string','enum':['one','two','three'],'x-example':'one'}}}",
s.getSchema(TestEnum[][].class));
}
@Test
public void addExample_ENUM_useEnumNames() throws Exception {
JsonSchemaSerializerSession s =
JsonSchemaSerializer.DEFAULT_LAX.builder().useEnumNames().addExamplesTo("enum").build().createSession();
-
assertObjectEquals("{type:'string','enum':['ONE','TWO','THREE'],example:'ONE'}",
s.getSchema(TestEnum.class));
+
assertObjectEquals("{type:'string','enum':['ONE','TWO','THREE'],'x-example':'ONE'}",
s.getSchema(TestEnum.class));
}
@Test
public void addExample_ENUM_wDefault_useEnumNames() throws Exception {
JsonSchemaSerializerSession s =
JsonSchemaSerializer.DEFAULT_LAX.builder().useEnumNames().addExamplesTo("enum").example(TestEnum.class,
TestEnum.TWO).build().createSession();
-
assertObjectEquals("{type:'string','enum':['ONE','TWO','THREE'],example:'TWO'}",
s.getSchema(TestEnum.class));
+
assertObjectEquals("{type:'string','enum':['ONE','TWO','THREE'],'x-example':'TWO'}",
s.getSchema(TestEnum.class));
}
@Test
public void addExample_ENUM_2darray_useEnumNames() throws Exception {
JsonSchemaSerializerSession s =
JsonSchemaSerializer.DEFAULT_LAX.builder().useEnumNames().addExamplesTo("enum").build().createSession();
-
assertObjectEquals("{type:'array',items:{type:'array',items:{type:'string','enum':['ONE','TWO','THREE'],example:'ONE'}}}",
s.getSchema(TestEnum[][].class));
+
assertObjectEquals("{type:'array',items:{type:'array',items:{type:'string','enum':['ONE','TWO','THREE'],'x-example':'ONE'}}}",
s.getSchema(TestEnum[][].class));
}
//====================================================================================================
@@ -861,26 +861,26 @@ public class JsonSchemaSerializerTest {
@Test
public void addExample_ANY() throws Exception {
JsonSchemaSerializerSession s =
JsonSchemaSerializer.DEFAULT_LAX.builder().addExamplesTo("any").build().createSession();
-
assertObjectEquals("{type:'object',properties:{f1:{type:'string',example:'foo'}}}",
s.getSchema(SimpleBean.class));
-
assertObjectEquals("{type:'object',additionalProperties:{type:'object',properties:{f1:{type:'string'}}},example:{'123':{f1:'foobar'}}}",
s.getSchema(BeanMapWithExampleMethod.class));
-
assertObjectEquals("{type:'array',items:{type:'object',properties:{f1:{type:'string'}}},example:[{f1:'foobar'}]}",
s.getSchema(BeanListWithExampleMethod.class));
-
assertObjectEquals("{type:'array',items:{type:'array',items:{type:'array',items:{type:'object',properties:{f1:{type:'string'}}}}},example:[[[{f1:'foobar'}]]]}",
s.getSchema(BeanListWithExampleField[][].class));
- assertObjectEquals("{type:'boolean',example:true}",
s.getSchema(boolean.class));
- assertObjectEquals("{type:'integer',format:'int16',example:1}",
s.getSchema(short.class));
- assertObjectEquals("{type:'integer',format:'int16',example:1}",
s.getSchema(Short.class));
- assertObjectEquals("{type:'integer',format:'int32',example:1}",
s.getSchema(int.class));
- assertObjectEquals("{type:'integer',format:'int32',example:1}",
s.getSchema(Integer.class));
- assertObjectEquals("{type:'integer',format:'int64',example:1}",
s.getSchema(long.class));
- assertObjectEquals("{type:'integer',format:'int64',example:1}",
s.getSchema(Long.class));
-
assertObjectEquals("{type:'number',format:'float',example:1.0}",
s.getSchema(float.class));
-
assertObjectEquals("{type:'number',format:'float',example:1.0}",
s.getSchema(Float.class));
-
assertObjectEquals("{type:'number',format:'double',example:1.0}",
s.getSchema(double.class));
-
assertObjectEquals("{type:'number',format:'double',example:1.0}",
s.getSchema(Double.class));
- assertObjectEquals("{type:'string',example:'foo'}",
s.getSchema(String.class));
- assertObjectEquals("{type:'string',example:'foo'}",
s.getSchema(StringBuilder.class));
- assertObjectEquals("{type:'string',example:'a'}",
s.getSchema(Character.class));
- assertObjectEquals("{type:'string',example:'a'}",
s.getSchema(char.class));
-
assertObjectEquals("{type:'string','enum':['one','two','three'],example:'one'}",
s.getSchema(TestEnum.class));
+
assertObjectEquals("{type:'object',properties:{f1:{type:'string','x-example':'foo'}}}",
s.getSchema(SimpleBean.class));
+
assertObjectEquals("{type:'object',additionalProperties:{type:'object',properties:{f1:{type:'string'}}},'x-example':{'123':{f1:'foobar'}}}",
s.getSchema(BeanMapWithExampleMethod.class));
+
assertObjectEquals("{type:'array',items:{type:'object',properties:{f1:{type:'string'}}},'x-example':[{f1:'foobar'}]}",
s.getSchema(BeanListWithExampleMethod.class));
+
assertObjectEquals("{type:'array',items:{type:'array',items:{type:'array',items:{type:'object',properties:{f1:{type:'string'}}}}},'x-example':[[[{f1:'foobar'}]]]}",
s.getSchema(BeanListWithExampleField[][].class));
+ assertObjectEquals("{type:'boolean','x-example':true}",
s.getSchema(boolean.class));
+
assertObjectEquals("{type:'integer',format:'int16','x-example':1}",
s.getSchema(short.class));
+
assertObjectEquals("{type:'integer',format:'int16','x-example':1}",
s.getSchema(Short.class));
+
assertObjectEquals("{type:'integer',format:'int32','x-example':1}",
s.getSchema(int.class));
+
assertObjectEquals("{type:'integer',format:'int32','x-example':1}",
s.getSchema(Integer.class));
+
assertObjectEquals("{type:'integer',format:'int64','x-example':1}",
s.getSchema(long.class));
+
assertObjectEquals("{type:'integer',format:'int64','x-example':1}",
s.getSchema(Long.class));
+
assertObjectEquals("{type:'number',format:'float','x-example':1.0}",
s.getSchema(float.class));
+
assertObjectEquals("{type:'number',format:'float','x-example':1.0}",
s.getSchema(Float.class));
+
assertObjectEquals("{type:'number',format:'double','x-example':1.0}",
s.getSchema(double.class));
+
assertObjectEquals("{type:'number',format:'double','x-example':1.0}",
s.getSchema(Double.class));
+ assertObjectEquals("{type:'string','x-example':'foo'}",
s.getSchema(String.class));
+ assertObjectEquals("{type:'string','x-example':'foo'}",
s.getSchema(StringBuilder.class));
+ assertObjectEquals("{type:'string','x-example':'a'}",
s.getSchema(Character.class));
+ assertObjectEquals("{type:'string','x-example':'a'}",
s.getSchema(char.class));
+
assertObjectEquals("{type:'string','enum':['one','two','three'],'x-example':'one'}",
s.getSchema(TestEnum.class));
}
//====================================================================================================
@@ -906,13 +906,13 @@ public class JsonSchemaSerializerTest {
@Test
public void addDescription_MAP() throws Exception {
JsonSchemaSerializerSession s =
JsonSchemaSerializer.DEFAULT_LAX.builder().addDescriptionsTo("map").build().createSession();
-
assertObjectEquals("{type:'object',additionalProperties:{type:'object',properties:{f1:{type:'string'}}},description:'org.apache.juneau.json.JsonSchemaSerializerTest$BeanMap'}",
s.getSchema(BeanMap.class));
+
assertObjectEquals("{type:'object',additionalProperties:{type:'object',properties:{f1:{type:'string'}}},description:'org.apache.juneau.json.JsonSchemaSerializerTest$BeanMap<java.lang.Integer,org.apache.juneau.json.JsonSchemaSerializerTest$SimpleBean>'}",
s.getSchema(BeanMap.class));
}
@Test
public void addDescription_MAP_2darray() throws Exception {
JsonSchemaSerializerSession s =
JsonSchemaSerializer.DEFAULT_LAX.builder().addDescriptionsTo("map").build().createSession();
-
assertObjectEquals("{type:'array',items:{type:'array',items:{type:'object',additionalProperties:{type:'object',properties:{f1:{type:'string'}}},description:'org.apache.juneau.json.JsonSchemaSerializerTest$BeanMap'}}}",
s.getSchema(BeanMap[][].class));
+
assertObjectEquals("{type:'array',items:{type:'array',items:{type:'object',additionalProperties:{type:'object',properties:{f1:{type:'string'}}},description:'org.apache.juneau.json.JsonSchemaSerializerTest$BeanMap<java.lang.Integer,org.apache.juneau.json.JsonSchemaSerializerTest$SimpleBean>'}}}",
s.getSchema(BeanMap[][].class));
}
//====================================================================================================
@@ -922,19 +922,19 @@ public class JsonSchemaSerializerTest {
@Test
public void addDescription_COLLECTION() throws Exception {
JsonSchemaSerializerSession s =
JsonSchemaSerializer.DEFAULT_LAX.builder().addDescriptionsTo("collection").build().createSession();
-
assertObjectEquals("{type:'array',items:{type:'object',properties:{f1:{type:'string'}}},description:'org.apache.juneau.json.JsonSchemaSerializerTest$BeanList'}",
s.getSchema(BeanList.class));
+
assertObjectEquals("{type:'array',items:{type:'object',properties:{f1:{type:'string'}}},description:'org.apache.juneau.json.JsonSchemaSerializerTest$BeanList<org.apache.juneau.json.JsonSchemaSerializerTest$SimpleBean>'}",
s.getSchema(BeanList.class));
}
@Test
public void addDescription_COLLECTION_2darray() throws Exception {
JsonSchemaSerializerSession s =
JsonSchemaSerializer.DEFAULT_LAX.builder().addDescriptionsTo("collection").build().createSession();
-
assertObjectEquals("{type:'array',items:{type:'array',items:{type:'array',items:{type:'object',properties:{f1:{type:'string'}}},description:'org.apache.juneau.json.JsonSchemaSerializerTest$BeanList'}}}",
s.getSchema(BeanList[][].class));
+
assertObjectEquals("{type:'array',items:{type:'array',items:{type:'array',items:{type:'object',properties:{f1:{type:'string'}}},description:'org.apache.juneau.json.JsonSchemaSerializerTest$BeanList<org.apache.juneau.json.JsonSchemaSerializerTest$SimpleBean>'}}}",
s.getSchema(BeanList[][].class));
}
@Test
public void addDescription_ARRAY() throws Exception {
JsonSchemaSerializerSession s =
JsonSchemaSerializer.DEFAULT_LAX.builder().addDescriptionsTo("array").build().createSession();
-
assertObjectEquals("{type:'array',items:{type:'array',items:{type:'array',items:{type:'object',properties:{f1:{type:'string'}}}}},description:'org.apache.juneau.json.JsonSchemaSerializerTest$BeanList[][]'}",
s.getSchema(BeanList[][].class));
+
assertObjectEquals("{type:'array',items:{type:'array',items:{type:'array',items:{type:'object',properties:{f1:{type:'string'}}}}},description:'org.apache.juneau.json.JsonSchemaSerializerTest$BeanList<org.apache.juneau.json.JsonSchemaSerializerTest$SimpleBean>[][]'}",
s.getSchema(BeanList[][].class));
}
//====================================================================================================
@@ -1032,9 +1032,9 @@ public class JsonSchemaSerializerTest {
public void addDescription_ANY() throws Exception {
JsonSchemaSerializerSession s =
JsonSchemaSerializer.DEFAULT_LAX.builder().addDescriptionsTo("any").build().createSession();
assertObjectEquals("{type:'object',properties:{f1:{type:'string'}},description:'org.apache.juneau.json.JsonSchemaSerializerTest$SimpleBean'}",
s.getSchema(SimpleBean.class));
-
assertObjectEquals("{type:'object',additionalProperties:{type:'object',properties:{f1:{type:'string'}}},description:'org.apache.juneau.json.JsonSchemaSerializerTest$BeanMap'}",
s.getSchema(BeanMap.class));
-
assertObjectEquals("{type:'array',items:{type:'object',properties:{f1:{type:'string'}}},description:'org.apache.juneau.json.JsonSchemaSerializerTest$BeanList'}",
s.getSchema(BeanList.class));
-
assertObjectEquals("{type:'array',items:{type:'array',items:{type:'array',items:{type:'object',properties:{f1:{type:'string'}}}}},description:'org.apache.juneau.json.JsonSchemaSerializerTest$BeanList[][]'}",
s.getSchema(BeanList[][].class));
+
assertObjectEquals("{type:'object',additionalProperties:{type:'object',properties:{f1:{type:'string'}}},description:'org.apache.juneau.json.JsonSchemaSerializerTest$BeanMap<java.lang.Integer,org.apache.juneau.json.JsonSchemaSerializerTest$SimpleBean>'}",
s.getSchema(BeanMap.class));
+
assertObjectEquals("{type:'array',items:{type:'object',properties:{f1:{type:'string'}}},description:'org.apache.juneau.json.JsonSchemaSerializerTest$BeanList<org.apache.juneau.json.JsonSchemaSerializerTest$SimpleBean>'}",
s.getSchema(BeanList.class));
+
assertObjectEquals("{type:'array',items:{type:'array',items:{type:'array',items:{type:'object',properties:{f1:{type:'string'}}}}},description:'org.apache.juneau.json.JsonSchemaSerializerTest$BeanList<org.apache.juneau.json.JsonSchemaSerializerTest$SimpleBean>[][]'}",
s.getSchema(BeanList[][].class));
assertObjectEquals("{type:'boolean',description:'boolean'}",
s.getSchema(boolean.class));
assertObjectEquals("{type:'boolean',description:'java.lang.Boolean'}",
s.getSchema(Boolean.class));
assertObjectEquals("{type:'integer',format:'int16',description:'short'}",
s.getSchema(short.class));
@@ -1169,7 +1169,7 @@ public class JsonSchemaSerializerTest {
.addExamplesTo("collection,bean")
.build().createSession();
-
assertObjectEquals("{type:'array',items:{type:'object',properties:{f1:{type:'string'}},example:{}},example:[]}",
s.getSchema(BeanList.class));
+
assertObjectEquals("{type:'array',items:{type:'object',properties:{f1:{type:'string'}},'x-example':{}},'x-example':[]}",
s.getSchema(BeanList.class));
}
@Test
@@ -1180,7 +1180,7 @@ public class JsonSchemaSerializerTest {
.addExamplesTo("collection,bean")
.build().createSession();
-
assertObjectEquals("{type:'array',items:{type:'object',properties:{f1:{type:'string'}}},example:[]}",
s.getSchema(BeanList.class));
+
assertObjectEquals("{type:'array',items:{type:'object',properties:{f1:{type:'string'}}},'x-example':[]}",
s.getSchema(BeanList.class));
}
//====================================================================================================
@@ -1194,7 +1194,7 @@ public class JsonSchemaSerializerTest {
.addDescriptionsTo("collection,bean")
.build().createSession();
-
assertObjectEquals("{type:'array',items:{type:'object',properties:{f1:{type:'string'}},description:'org.apache.juneau.json.JsonSchemaSerializerTest$SimpleBean'},description:'org.apache.juneau.json.JsonSchemaSerializerTest$BeanList'}",
s.getSchema(BeanList.class));
+
assertObjectEquals("{type:'array',items:{type:'object',properties:{f1:{type:'string'}},description:'org.apache.juneau.json.JsonSchemaSerializerTest$SimpleBean'},description:'org.apache.juneau.json.JsonSchemaSerializerTest$BeanList<org.apache.juneau.json.JsonSchemaSerializerTest$SimpleBean>'}",
s.getSchema(BeanList.class));
}
@Test
@@ -1203,7 +1203,7 @@ public class JsonSchemaSerializerTest {
.addDescriptionsTo("collection,bean")
.build().createSession();
-
assertObjectEquals("{type:'array',items:{type:'object',properties:{f1:{type:'string'}}},description:'org.apache.juneau.json.JsonSchemaSerializerTest$BeanList'}",
s.getSchema(BeanList.class));
+
assertObjectEquals("{type:'array',items:{type:'object',properties:{f1:{type:'string'}}},description:'org.apache.juneau.json.JsonSchemaSerializerTest$BeanList<org.apache.juneau.json.JsonSchemaSerializerTest$SimpleBean>'}",
s.getSchema(BeanList.class));
}
//====================================================================================================
@@ -1229,7 +1229,7 @@ public class JsonSchemaSerializerTest {
@Test
public void jsonSchema_onclass() throws Exception {
JsonSchemaSerializerSession s =
JsonSchemaSerializer.DEFAULT_LAX.builder().build().createSession();
-
assertObjectEquals("{type:'foo',format:'bar',properties:{f1:{type:'integer',format:'int32'}},description:'baz',example:{f1:123}}",
s.getSchema(A1.class));
+
assertObjectEquals("{type:'foo',format:'bar',properties:{f1:{type:'integer',format:'int32'}},description:'baz','x-example':{f1:123}}",
s.getSchema(A1.class));
}
@JsonSchema(type="foo",format="bar",description="baz",example="{f1:123}")
@@ -1240,7 +1240,7 @@ public class JsonSchemaSerializerTest {
@Test
public void jsonSchema_onbeanfield() throws Exception {
JsonSchemaSerializerSession s =
JsonSchemaSerializer.DEFAULT_LAX.builder().build().createSession();
-
assertObjectEquals("{type:'object',properties:{f1:{type:'foo',format:'bar',description:'baz',example:123}}}",
s.getSchema(A2.class));
+
assertObjectEquals("{type:'object',properties:{f1:{type:'foo',format:'bar',description:'baz','x-example':123}}}",
s.getSchema(A2.class));
}
public static class A2 {
@@ -1251,7 +1251,7 @@ public class JsonSchemaSerializerTest {
@Test
public void jsonSchema_onbeangetter() throws Exception {
JsonSchemaSerializerSession s =
JsonSchemaSerializer.DEFAULT_LAX.builder().build().createSession();
-
assertObjectEquals("{type:'object',properties:{f1:{type:'foo',format:'bar',description:'baz',example:123}}}",
s.getSchema(A3.class));
+
assertObjectEquals("{type:'object',properties:{f1:{type:'foo',format:'bar',description:'baz','x-example':123}}}",
s.getSchema(A3.class));
}
public static class A3 {
@@ -1264,7 +1264,7 @@ public class JsonSchemaSerializerTest {
public void jsonSchema_onbeansetter() throws Exception {
JsonSchemaSerializerSession s =
JsonSchemaSerializer.DEFAULT_LAX.builder().build().createSession();
-
assertObjectEquals("{type:'object',properties:{f1:{type:'foo',format:'bar',description:'baz',example:123}}}",
s.getSchema(A4.class));
+
assertObjectEquals("{type:'object',properties:{f1:{type:'foo',format:'bar',description:'baz','x-example':123}}}",
s.getSchema(A4.class));
}
public static class A4 {
@@ -1285,9 +1285,9 @@ public class JsonSchemaSerializerTest {
JsonSchemaSerializerSession s =
JsonSchemaSerializer.DEFAULT_LAX.builder()
.pojoSwaps(SwapWithAnnotation.class)
.build().createSession();
-
assertObjectEquals("{type:'foo',format:'bar',description:'baz',example:123}",
s.getSchema(SimpleBean.class));
-
assertObjectEquals("{type:'array',items:{type:'foo',format:'bar',description:'baz',example:123}}",
s.getSchema(BeanList.class));
-
assertObjectEquals("{type:'array',items:{type:'array',items:{type:'foo',format:'bar',description:'baz',example:123}}}",
s.getSchema(SimpleBean[][].class));
+
assertObjectEquals("{type:'foo',format:'bar',description:'baz','x-example':123}",
s.getSchema(SimpleBean.class));
+
assertObjectEquals("{type:'array',items:{type:'foo',format:'bar',description:'baz','x-example':123}}",
s.getSchema(BeanList.class));
+
assertObjectEquals("{type:'array',items:{type:'array',items:{type:'foo',format:'bar',description:'baz','x-example':123}}}",
s.getSchema(SimpleBean[][].class));
}
@JsonSchema(type="foo",format="bar",description="baz",example="123")
diff --git
a/juneau-core/juneau-dto/src/main/java/org/apache/juneau/dto/swagger/HeaderInfo.java
b/juneau-core/juneau-dto/src/main/java/org/apache/juneau/dto/swagger/HeaderInfo.java
index 242a58c..98bd49c 100644
---
a/juneau-core/juneau-dto/src/main/java/org/apache/juneau/dto/swagger/HeaderInfo.java
+++
b/juneau-core/juneau-dto/src/main/java/org/apache/juneau/dto/swagger/HeaderInfo.java
@@ -1141,17 +1141,24 @@ public class HeaderInfo extends SwaggerElement {
* Resolves any <js>"$ref"</js> attributes in this element.
*
* @param swagger The swagger document containing the definitions.
+ * @param refStack Keeps track of previously-visited references so that
we don't cause recursive loops.
* @return
* This object with references resolved.
* <br>May or may not be the same object.
*/
- public HeaderInfo resolveRefs(Swagger swagger) {
-
- if (ref != null)
- return swagger.findRef(ref, HeaderInfo.class);
+ public HeaderInfo resolveRefs(Swagger swagger, Deque<String> refStack) {
+ if (ref != null) {
+ if (refStack.contains(ref) || refStack.size() > 2)
+ return this;
+ refStack.addLast(ref);
+ HeaderInfo r = swagger.findRef(ref,
HeaderInfo.class).resolveRefs(swagger, refStack);
+ refStack.removeLast();
+ return r;
+ }
+
if (items != null)
- items = items.resolveRefs(swagger);
+ items = items.resolveRefs(swagger, refStack);
return this;
}
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 56c7b5b..35c63bf 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
@@ -96,7 +96,6 @@ public class Items extends SwaggerElement {
this.format = copyFrom.format;
this.collectionFormat = copyFrom.collectionFormat;
this.pattern = copyFrom.pattern;
- this.ref = copyFrom.ref;
this.maximum = copyFrom.maximum;
this.minimum = copyFrom.minimum;
this.multipleOf = copyFrom.multipleOf;
@@ -110,6 +109,7 @@ public class Items extends SwaggerElement {
this.items = copyFrom.items == null ? null :
copyFrom.items.copy();
this._default = copyFrom._default;
this._enum = newList(copyFrom._enum);
+ this.ref = copyFrom.ref;
}
/**
@@ -1039,7 +1039,6 @@ public class Items extends SwaggerElement {
case "format": return toType(getFormat(), type);
case "items": return toType(getItems(), type);
case "collectionFormat": return
toType(getCollectionFormat(), type);
- case "$ref": return toType(getRef(), type);
case "default": return toType(getDefault(), type);
case "maximum": return toType(getMaximum(), type);
case "exclusiveMaximum": return
toType(getExclusiveMaximum(), type);
@@ -1053,6 +1052,7 @@ public class Items extends SwaggerElement {
case "uniqueItems": return toType(getUniqueItems(),
type);
case "enum": return toType(getEnum(), type);
case "multipleOf": return toType(getMultipleOf(), type);
+ case "$ref": return toType(getRef(), type);
default: return super.get(property, type);
}
}
@@ -1066,7 +1066,6 @@ public class Items extends SwaggerElement {
case "format": return format(value);
case "items": return items(value);
case "collectionFormat": return collectionFormat(value);
- case "$ref": return ref(value);
case "default": return _default(value);
case "maximum": return maximum(value);
case "exclusiveMaximum": return exclusiveMaximum(value);
@@ -1080,6 +1079,7 @@ public class Items extends SwaggerElement {
case "uniqueItems": return uniqueItems(value);
case "enum": return setEnum(null)._enum(value);
case "multipleOf": return multipleOf(value);
+ case "$ref": return ref(value);
default:
super.set(property, value);
return this;
@@ -1093,7 +1093,6 @@ public class Items extends SwaggerElement {
.appendIf(format != null, "format")
.appendIf(items != null, "items")
.appendIf(collectionFormat != null, "collectionFormat")
- .appendIf(ref != null, "$ref")
.appendIf(_default != null, "default")
.appendIf(maximum != null, "maximum")
.appendIf(exclusiveMaximum != null, "exclusiveMaximum")
@@ -1106,7 +1105,8 @@ public class Items extends SwaggerElement {
.appendIf(minItems != null, "minItems")
.appendIf(uniqueItems != null, "uniqueItems")
.appendIf(_enum != null, "enum")
- .appendIf(multipleOf != null, "multipleOf");
+ .appendIf(multipleOf != null, "multipleOf")
+ .appendIf(ref != null, "$ref");
return new MultiSet<>(s, super.keySet());
}
@@ -1114,19 +1114,27 @@ public class Items extends SwaggerElement {
* Resolves any <js>"$ref"</js> attributes in this element.
*
* @param swagger The swagger document containing the definitions.
+ * @param refStack Keeps track of previously-visited references so that
we don't cause recursive loops.
* @return
* This object with references resolved.
* <br>May or may not be the same object.
*/
- public Items resolveRefs(Swagger swagger) {
+ public Items resolveRefs(Swagger swagger, Deque<String> refStack) {
- if (ref != null)
- return swagger.findRef(ref, Items.class);
+ if (ref != null) {
+ if (refStack.contains(ref) || refStack.size() > 2)
+ return this;
+ refStack.addLast(ref);
+ Items r = swagger.findRef(ref,
Items.class).resolveRefs(swagger, refStack);
+ refStack.removeLast();
+ return r;
+ }
if (items != null)
- items = items.resolveRefs(swagger);
+ items = items.resolveRefs(swagger, refStack);
+
+ set("example", null);
return this;
}
-
}
diff --git
a/juneau-core/juneau-dto/src/main/java/org/apache/juneau/dto/swagger/Operation.java
b/juneau-core/juneau-dto/src/main/java/org/apache/juneau/dto/swagger/Operation.java
index e5df4c2..1affb33 100644
---
a/juneau-core/juneau-dto/src/main/java/org/apache/juneau/dto/swagger/Operation.java
+++
b/juneau-core/juneau-dto/src/main/java/org/apache/juneau/dto/swagger/Operation.java
@@ -1171,25 +1171,4 @@ public class Operation extends SwaggerElement {
.appendIf(security != null, "security");
return new MultiSet<>(s, super.keySet());
}
-
- /**
- * Resolves any <js>"$ref"</js> attributes in this element.
- *
- * @param swagger The swagger document containing the definitions.
- * @return
- * This object with references resolved.
- * <br>May or may not be the same object.
- */
- public Operation resolveRefs(Swagger swagger) {
-
- if (parameters != null)
- for (ListIterator<ParameterInfo> i =
parameters.listIterator(); i.hasNext();)
- i.set(i.next().resolveRefs(swagger));
-
- if (responses != null)
- for (Map.Entry<String,ResponseInfo> e :
responses.entrySet())
- e.setValue(e.getValue().resolveRefs(swagger));
-
- return this;
- }
}
diff --git
a/juneau-core/juneau-dto/src/main/java/org/apache/juneau/dto/swagger/ParameterInfo.java
b/juneau-core/juneau-dto/src/main/java/org/apache/juneau/dto/swagger/ParameterInfo.java
index b1fe506..3be783a 100644
---
a/juneau-core/juneau-dto/src/main/java/org/apache/juneau/dto/swagger/ParameterInfo.java
+++
b/juneau-core/juneau-dto/src/main/java/org/apache/juneau/dto/swagger/ParameterInfo.java
@@ -1507,7 +1507,7 @@ public class ParameterInfo extends SwaggerElement {
case "uniqueItems": return toType(getUniqueItems(),
type);
case "enum": return toType(getEnum(), type);
case "multipleOf": return toType(getMultipleOf(), type);
- case "examples": return toType(getExamples(), type);
+ case "x-examples": return toType(getExamples(), type);
default: return super.get(property, type);
}
}
@@ -1573,7 +1573,7 @@ public class ParameterInfo extends SwaggerElement {
.appendIf(uniqueItems != null, "uniqueItems")
.appendIf(_enum != null, "enum")
.appendIf(multipleOf != null, "multipleOf")
- .appendIf(examples != null, "examples");
+ .appendIf(examples != null, "x-examples");
return new MultiSet<>(s, super.keySet());
}
@@ -1581,17 +1581,18 @@ public class ParameterInfo extends SwaggerElement {
* Resolves any <js>"$ref"</js> attributes in this element.
*
* @param swagger The swagger document containing the definitions.
+ * @param refStack Keeps track of previously-visited references so that
we don't cause recursive loops.
* @return
* This object with references resolved.
* <br>May or may not be the same object.
*/
- public ParameterInfo resolveRefs(Swagger swagger) {
+ public ParameterInfo resolveRefs(Swagger swagger, Deque<String>
refStack) {
if (schema != null)
- schema = schema.resolveRefs(swagger);
+ schema = schema.resolveRefs(swagger, refStack);
if (items != null)
- items = items.resolveRefs(swagger);
+ items = items.resolveRefs(swagger, refStack);
return this;
}
diff --git
a/juneau-core/juneau-dto/src/main/java/org/apache/juneau/dto/swagger/ResponseInfo.java
b/juneau-core/juneau-dto/src/main/java/org/apache/juneau/dto/swagger/ResponseInfo.java
index afec0ce..6923368 100644
---
a/juneau-core/juneau-dto/src/main/java/org/apache/juneau/dto/swagger/ResponseInfo.java
+++
b/juneau-core/juneau-dto/src/main/java/org/apache/juneau/dto/swagger/ResponseInfo.java
@@ -440,18 +440,19 @@ public class ResponseInfo extends SwaggerElement {
* Resolves any <js>"$ref"</js> attributes in this element.
*
* @param swagger The swagger document containing the definitions.
+ * @param refStack Keeps track of previously-visited references so that
we don't cause recursive loops.
* @return
* This object with references resolved.
* <br>May or may not be the same object.
*/
- public ResponseInfo resolveRefs(Swagger swagger) {
+ public ResponseInfo resolveRefs(Swagger swagger, Deque<String>
refStack) {
if (schema != null)
- schema = schema.resolveRefs(swagger);
+ schema = schema.resolveRefs(swagger, refStack);
if (headers != null)
for (Map.Entry<String,HeaderInfo> e :
headers.entrySet())
- e.setValue(e.getValue().resolveRefs(swagger));
+ e.setValue(e.getValue().resolveRefs(swagger,
refStack));
return this;
}
diff --git
a/juneau-core/juneau-dto/src/main/java/org/apache/juneau/dto/swagger/SchemaInfo.java
b/juneau-core/juneau-dto/src/main/java/org/apache/juneau/dto/swagger/SchemaInfo.java
index ca5260f..4ec8abb 100644
---
a/juneau-core/juneau-dto/src/main/java/org/apache/juneau/dto/swagger/SchemaInfo.java
+++
b/juneau-core/juneau-dto/src/main/java/org/apache/juneau/dto/swagger/SchemaInfo.java
@@ -1509,24 +1509,33 @@ public class SchemaInfo extends SwaggerElement {
* Resolves any <js>"$ref"</js> attributes in this element.
*
* @param swagger The swagger document containing the definitions.
+ * @param refStack Keeps track of previously-visited references so that
we don't cause recursive loops.
* @return
* This object with references resolved.
* <br>May or may not be the same object.
*/
- public SchemaInfo resolveRefs(Swagger swagger) {
-
- if (ref != null)
- return swagger.findRef(ref, SchemaInfo.class);
+ public SchemaInfo resolveRefs(Swagger swagger, Deque<String> refStack) {
+ if (ref != null) {
+ if (refStack.contains(ref) || refStack.size() > 2)
+ return this;
+ refStack.addLast(ref);
+ SchemaInfo r = swagger.findRef(ref,
SchemaInfo.class).resolveRefs(swagger, refStack);
+ refStack.removeLast();
+ return r;
+ }
+
if (items != null)
- items = items.resolveRefs(swagger);
+ items = items.resolveRefs(swagger, refStack);
if (properties != null)
for (Map.Entry<String,SchemaInfo> e :
properties.entrySet())
- e.setValue(e.getValue().resolveRefs(swagger));
+ e.setValue(e.getValue().resolveRefs(swagger,
refStack));
if (additionalProperties != null)
- additionalProperties =
additionalProperties.resolveRefs(swagger);
+ additionalProperties =
additionalProperties.resolveRefs(swagger, refStack);
+
+ this.example = null;
return this;
}
diff --git
a/juneau-core/juneau-dto/src/main/java/org/apache/juneau/dto/swagger/Swagger.java
b/juneau-core/juneau-dto/src/main/java/org/apache/juneau/dto/swagger/Swagger.java
index c498e44..27afa97 100644
---
a/juneau-core/juneau-dto/src/main/java/org/apache/juneau/dto/swagger/Swagger.java
+++
b/juneau-core/juneau-dto/src/main/java/org/apache/juneau/dto/swagger/Swagger.java
@@ -1365,27 +1365,4 @@ public class Swagger extends SwaggerElement {
throw new BeanRuntimeException("Reference ''{0}'' could
not be converted to type ''{1}''.", ref, c.getName()).initCause(e);
}
}
-
- /**
- * Resolves any <js>"$ref"</js> attributes in this document.
- *
- * @return This object (for method chaining).
- */
- public Swagger resolveRefs() {
-
- if (parameters != null)
- for (Map.Entry<String,ParameterInfo> e :
parameters.entrySet())
- e.setValue(e.getValue().resolveRefs(this));
-
- if (responses != null)
- for (Map.Entry<String,ResponseInfo> e :
responses.entrySet())
- e.setValue(e.getValue().resolveRefs(this));
-
- if (paths != null)
- for (Map.Entry<String,Map<String,Operation>> e :
paths.entrySet())
- for (Map.Entry<String,Operation> e2 :
e.getValue().entrySet())
-
e2.setValue(e2.getValue().resolveRefs(this));
-
- return this;
- }
}
diff --git
a/juneau-core/juneau-dto/src/main/java/org/apache/juneau/dto/swagger/SwaggerElement.java
b/juneau-core/juneau-dto/src/main/java/org/apache/juneau/dto/swagger/SwaggerElement.java
index 8fa663d..b5aef00 100644
---
a/juneau-core/juneau-dto/src/main/java/org/apache/juneau/dto/swagger/SwaggerElement.java
+++
b/juneau-core/juneau-dto/src/main/java/org/apache/juneau/dto/swagger/SwaggerElement.java
@@ -89,8 +89,8 @@ public abstract class SwaggerElement {
*/
@BeanProperty("*")
public Map<String,Object> getExtraProperties() {
- if (extra == null)
- extra = new LinkedHashMap<>();
+ if (extra == null || extra.isEmpty())
+ return null;
return extra;
}
@@ -109,7 +109,7 @@ public abstract class SwaggerElement {
return null;
switch (property) {
case "strict": return toType(isStrict(), type);
- default: return
toType(getExtraProperties().get(property), type);
+ default: return extra == null ? null :
toType(getExtraProperties().get(property), type);
}
};
@@ -123,13 +123,16 @@ public abstract class SwaggerElement {
* @param value The new value for the property.
* @return This object (for method chaining).
*/
+ @BeanProperty("*")
public SwaggerElement set(String property, Object value) {
if (property == null)
return this;
switch (property) {
case "strict": return strict(value);
default:
- getExtraProperties().put(property, value);
+ if (extra == null)
+ extra = new LinkedHashMap<>();
+ extra.put(property, value);
return this;
}
}
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 da757f1..af8c9fc 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
@@ -14,6 +14,7 @@ package org.apache.juneau.dto.swagger.ui;
import static org.apache.juneau.dto.html5.HtmlBuilder.*;
+import java.util.*;
import java.util.Map;
import org.apache.juneau.*;
@@ -39,7 +40,7 @@ public class SwaggerUI extends PojoSwap<Swagger,Div> {
@Override
public Div swap(BeanSession session, Swagger s) throws Exception {
- s = s.copy().resolveRefs();
+ s = s.copy();
Div outer = div(
style(RESOURCES.getString("SwaggerUI.css")),
@@ -178,7 +179,7 @@ public class SwaggerUI extends PojoSwap<Swagger,Div> {
Td parameterValue = td(
div(pi.getDescription())._class("description"),
- examples(pi.getSchema(),
pi.getExamples())
+ examples(s, pi.getSchema(),
pi.getExamples())
)._class("parameter-value");
parameters.child(tr(parameterKey,
parameterValue));
@@ -200,7 +201,7 @@ public class SwaggerUI extends PojoSwap<Swagger,Div> {
Td codeValue = td(
div(ri.getDescription())._class("description"),
- examples(ri.getSchema(),
ri.getExamples()),
+ examples(s, ri.getSchema(),
ri.getExamples()),
headers(s, ri)
)._class("response-value");
@@ -237,21 +238,25 @@ public class SwaggerUI extends PojoSwap<Swagger,Div> {
return headers;
}
- private Div examples(SchemaInfo si, Map<String,?> examples) {
- if (examples == null || si == null)
+ private Div examples(Swagger swagger, SchemaInfo si, Map<String,?>
examples) {
+ if (si == null && examples == null)
return null;
Select select =
(Select)select().onchange("selectExample(this)")._class("example-select");
- select.child(option("model","model"));
Div div = div(select)._class("examples");
- div.child(div(si.copy().setExample(null))._class("model
active").attr("data-name", "model"));
-
- for (Map.Entry<String,?> e : examples.entrySet()) {
- String name = e.getKey();
- String value = e.getValue().toString();
- select.child(option(name, name));
- div.child(div(value.replaceAll("\\n",
"\n"))._class("example").attr("data-name", name));
+ if (si != null) {
+ select.child(option("model","model"));
+ div.child(div(si.copy().resolveRefs(swagger, new
ArrayDeque<String>()))._class("model active").attr("data-name", "model"));
+ }
+
+ if (examples != null) {
+ for (Map.Entry<String,?> e : examples.entrySet()) {
+ String name = e.getKey();
+ String value = e.getValue().toString();
+ select.child(option(name, name));
+ div.child(div(value.replaceAll("\\n",
"\n"))._class("example").attr("data-name", name));
+ }
}
return div;
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/BeanMap.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/BeanMap.java
index 9e92f9e..810effd 100644
--- a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/BeanMap.java
+++ b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/BeanMap.java
@@ -453,10 +453,13 @@ public class BeanMap<T> extends
AbstractMap<String,Object> implements Delegate<T
if (bpm.canRead()) {
try {
if (bpm.isDyna()) {
- for (String pName :
bpm.getDynaMap(bean).keySet()) {
- Object val =
bpm.get(this, pName);
- if (val != null || !
ignoreNulls)
- l.add(new
BeanPropertyValue(bpm, pName, val, null));
+ Map<String,Object> dynaMap =
bpm.getDynaMap(bean);
+ if (dynaMap != null) {
+ for (String pName :
bpm.getDynaMap(bean).keySet()) {
+ Object val =
bpm.get(this, pName);
+ if (val != null
|| ! ignoreNulls)
+
l.add(new BeanPropertyValue(bpm, pName, val, null));
+ }
}
} else {
Object val = bpm.get(this,
null);
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/ClassMeta.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/ClassMeta.java
index 02427e4..45c6800 100644
--- a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/ClassMeta.java
+++ b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/ClassMeta.java
@@ -1941,14 +1941,6 @@ public final class ClassMeta<T> implements Type {
return
sb.append(BeanMap.class.getName()).append('<').append(n).append('>');
if (cc == COLLECTION)
return sb.append(n).append(elementType.isObject() ? ""
: "<"+elementType.toString(simple)+">");
- if (cc == OTHER && beanMeta == null) {
- if (simple)
- return sb.append(n);
-
sb.append("OTHER-").append(n).append(",notABeanReason=").append(notABeanReason);
- if (initException != null)
-
sb.append(",initException=").append(initException);
- return sb;
- }
return sb.append(n);
}
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/jsonschema/JsonSchemaSerializerSession.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/jsonschema/JsonSchemaSerializerSession.java
index af574af..e078030 100644
---
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/jsonschema/JsonSchemaSerializerSession.java
+++
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/jsonschema/JsonSchemaSerializerSession.java
@@ -62,7 +62,7 @@ public class JsonSchemaSerializerSession extends
JsonSerializerSession {
defaultSchemas = getProperty(JSONSCHEMA_defaultSchemas,
Map.class, ctx.defaultSchemas);
addExamplesTo = hasProperty(JSONSCHEMA_addExamplesTo) ?
TypeCategory.parse(getProperty(JSONSCHEMA_addExamplesTo, String.class)) :
ctx.addExamplesTo;
addDescriptionsTo = hasProperty(JSONSCHEMA_addDescriptionsTo) ?
TypeCategory.parse(getProperty(JSONSCHEMA_addDescriptionsTo, String.class)) :
ctx.addDescriptionsTo;
- defs = useBeanDefs ? new LinkedHashMap<String,ObjectMap>() :
null;
+ defs = useBeanDefs ? new TreeMap<String,ObjectMap>() : null;
}
@Override /* SerializerSession */
@@ -108,6 +108,7 @@ public class JsonSchemaSerializerSession extends
JsonSerializerSession {
aType = push(attrName, eType, null);
sType = eType.getSerializedClassMeta(this);
+
String type = null, format = null;
Object example = null, description = null;
@@ -118,8 +119,8 @@ public class JsonSchemaSerializerSession extends
JsonSerializerSession {
// If we previously encountered this bean in a
collection/array, then it may not have
// the example and description associated with it, so
add it now.
- if (! schema.containsKey("example"))
- schema.appendIf(true, true, true, "example",
getExample(sType, BEAN, exampleAdded));
+ if (! schema.containsKey("x-example"))
+ schema.appendIf(true, true, true, "x-example",
getExample(sType, BEAN, exampleAdded));
if (! schema.containsKey("description"))
schema.appendIf(true, true, true,
"description", getDescription(sType, BEAN, exampleAdded));
@@ -178,6 +179,10 @@ public class JsonSchemaSerializerSession extends
JsonSerializerSession {
} else if (sType.isCharSequence() || sType.isChar()) {
tc = STRING;
type = "string";
+ } else if (sType.isUri()) {
+ tc = STRING;
+ type = "string";
+ format = "uri";
}
// Add info from @JsonSchema on bean property.
@@ -237,14 +242,14 @@ public class JsonSchemaSerializerSession extends
JsonSerializerSession {
// Add info from @JsonSchema on bean property.
if (jsbpm != null) {
out.appendIf(false, true, true, "description",
jsbpm.getDescription());
- out.appendIf(false, true, true, "example",
jsbpm.getExample());
+ out.appendIf(false, true, true, "x-example",
jsbpm.getExample());
}
out.appendIf(false, true, true, "description",
jscm.getDescription());
- out.appendIf(false, true, true, "example", jscm.getExample());
+ out.appendIf(false, true, true, "x-example", jscm.getExample());
out.appendIf(false, true, true, "description", description);
- out.appendIf(false, true, true, "example", example);
+ out.appendIf(false, true, true, "x-example", example);
if (ds != null)
out.appendAll(ds);
@@ -279,7 +284,7 @@ public class JsonSchemaSerializerSession extends
JsonSerializerSession {
private Object getDescription(ClassMeta<?> sType, TypeCategory t,
boolean descriptionAdded) {
boolean canAdd = allowNestedDescriptions || ! descriptionAdded;
if (canAdd && (addDescriptionsTo.contains(t) ||
addDescriptionsTo.contains(ANY)))
- return sType.getReadableName();
+ return sType.toString();
return null;
}
diff --git a/juneau-doc/src/main/javadoc/overview.html
b/juneau-doc/src/main/javadoc/overview.html
index 9f3e1fc..087ee05 100644
--- a/juneau-doc/src/main/javadoc/overview.html
+++ b/juneau-doc/src/main/javadoc/overview.html
@@ -21341,6 +21341,9 @@
<ul>
<li>New {@link
org.apache.juneau.jsonschema.annotation.JsonSchema @JsonSchema} annotation.
</ul>
+ <li>
+ Fixed <code>NullPointerException</code> when
serializing beans with a dyna-property (i.e.
<code><ja>@Bean</ja>(<js>"*"</js>)</code>)
+ which returns a <jk>null</jk> value.
</ul>
<h5 class='topic w800'>juneau-dto</h5>
diff --git
a/juneau-examples/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/petstore/Order.java
b/juneau-examples/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/petstore/Order.java
index 724ce07..1ecaf39 100644
---
a/juneau-examples/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/petstore/Order.java
+++
b/juneau-examples/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/petstore/Order.java
@@ -15,6 +15,7 @@ package org.apache.juneau.examples.rest.petstore;
import org.apache.juneau.annotation.*;
@Bean(fluentSetters=true)
+@Example("{id:123,petId:456,quantity:100,shipDate:'2012-12-21',status:'APPROVED'}")
public class Order {
private long id, petId;
private int quantity;
diff --git
a/juneau-examples/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/petstore/Pet.java
b/juneau-examples/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/petstore/Pet.java
index c883e96..4817903 100644
---
a/juneau-examples/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/petstore/Pet.java
+++
b/juneau-examples/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/petstore/Pet.java
@@ -29,6 +29,7 @@ public class Pet {
private List<Tag> tags;
private PetStatus status;
+ // This shows an example generated from a static method.
@Example
public static Pet example() {
return new Pet()
diff --git
a/juneau-examples/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/petstore/PetStoreResource.java
b/juneau-examples/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/petstore/PetStoreResource.java
index 68ee990..16658f7 100644
---
a/juneau-examples/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/petstore/PetStoreResource.java
+++
b/juneau-examples/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/petstore/PetStoreResource.java
@@ -89,7 +89,7 @@ public class PetStoreResource extends BasicRestServletJena {
"security:[ { api_key:[] } ]"
}
)
- public Pet getPet(@Path(description="ID of pet to return") long petId)
throws IdNotFoundException {
+ public Pet getPet(@Path(description="ID of pet to return",
example="123") long petId) throws IdNotFoundException {
return db.getPet(petId);
}
@@ -100,10 +100,13 @@ public class PetStoreResource extends
BasicRestServletJena {
swagger={
"tags:['pet'],",
"security:[ { petstore_auth:['write:pets','read:pets']
} ],",
- "responses: { 200: { description: 'OK', schema:{
type:'string' } } }"
+ "responses: { 200: { 'x-example':'OK' } }"
}
)
- public String addPet(@Body(description="Pet object that needs to be
added to the store") Pet pet) throws IdConflictException {
+ public String addPet(
+ @Body(description="Pet object that needs to be added to
the store") Pet pet
+ ) throws IdConflictException {
+
db.add(pet);
return "OK";
}
@@ -115,7 +118,7 @@ public class PetStoreResource extends BasicRestServletJena {
swagger={
"tags:['pet'],",
"security:[ { petstore_auth: ['write:pets','read:pets']
} ],",
- "responses: { 200: { description: 'OK', schema:{
type:'string' } } }"
+ "responses: { 200: { 'x-example':'OK' } }"
}
)
public String updatePet(@Body(description="Pet object that needs to be
added to the store") Pet pet) throws IdNotFoundException {
@@ -133,7 +136,16 @@ public class PetStoreResource extends BasicRestServletJena
{
"security:[{ petstore_auth:[ 'write:pets','read:pets' ]
} ]"
}
)
- public Collection<Pet> findPetsByStatus(@Query(name="status",
description="Status values that need to be considered for filter",
required="true") PetStatus[] status) {
+ public Collection<Pet> findPetsByStatus(
+ @Query(
+ name="status",
+ description="Status values that need to be
considered for filter",
+ required="true",
+ example="['AVAILABLE','PENDING']"
+ )
+ PetStatus[] status
+ ) {
+
return db.getPetsByStatus(status);
}
@@ -148,7 +160,16 @@ public class PetStoreResource extends BasicRestServletJena
{
}
)
@Deprecated
- public Collection<Pet> findPetsByTags(@Query(name="tags",
description="Tags to filter by", required="true") String[] tags) throws
InvalidTagException {
+ public Collection<Pet> findPetsByTags(
+ @Query(
+ name="tags",
+ description="Tags to filter by",
+ required="true",
+ example="['tag1','tag2']"
+ )
+ String[] tags
+ ) throws InvalidTagException {
+
return db.getPetsByTags(tags);
}
@@ -159,14 +180,15 @@ public class PetStoreResource extends
BasicRestServletJena {
swagger={
"tags:[ 'pet' ],",
"security:[ { petstore_auth:[ 'write:pets', 'read:pets'
] } ],",
- "responses: { 200: { description: 'OK', schema:{
type:'string' } } }"
+ "responses: { 200: { 'x-example':'OK' } }"
}
)
public String updatePetForm(
- @Path(description="ID of pet that needs to be updated")
long petId,
- @FormData(name="name", description="Updated name of the
pet") String name,
- @FormData(name="status", description="Updated status of
the pet") PetStatus status
+ @Path(description="ID of pet that needs to be updated",
example="123") long petId,
+ @FormData(name="name", description="Updated name of the
pet", example="'Scruffy'") String name,
+ @FormData(name="status", description="Updated status of
the pet", example="'AVAILABLE'") PetStatus status
) throws IdNotFoundException {
+
Pet pet = db.getPet(petId);
pet.name(name);
pet.status(status);
@@ -181,12 +203,12 @@ public class PetStoreResource extends
BasicRestServletJena {
swagger={
"tags:[ 'pet' ],",
"security:[ { petstore_auth:[ 'write:pets','read:pets'
] } ],",
- "responses: { 200: { description: 'OK', schema:{
type:'string' } } }"
+ "responses: { 200: { 'x-example':'OK' } }"
}
)
public String deletePet(
- @Header("api_key") String apiKey,
- @Path(description="Pet id to delete") long petId
+ @Header(name="api_key", example="foobar") String
apiKey,
+ @Path(description="Pet id to delete", example="123")
long petId
) throws IdNotFoundException {
db.removePet(petId);
return "OK";
@@ -199,12 +221,12 @@ public class PetStoreResource extends
BasicRestServletJena {
swagger={
"tags:[ 'pet' ],",
"security:[ { petstore_auth:[ 'write:pets','read:pets'
] } ],",
- "responses: { 200: { description: 'OK', schema:{
type:'string' } } }"
+ "responses: { 200: { 'x-example':'OK' } }"
}
)
public String uploadImage(
- @Path(description="ID of pet to update") long petId,
- @FormData(name="additionalMetadata",
description="Additional data to pass to server") String additionalMetadata,
+ @Path(description="ID of pet to update", example="123")
long petId,
+ @FormData(name="additionalMetadata",
description="Additional data to pass to server", example="Foobar") String
additionalMetadata,
@FormData(name="file", description="file to upload",
required="true", type="file") byte[] file
) {
return "OK";
@@ -236,8 +258,15 @@ public class PetStoreResource extends BasicRestServletJena
{
}
)
public Order getOrder(
- @Path(description="ID of order to fetch",
maximum="10.0", minimum="1.0") long orderId
+ @Path(
+ description="ID of order to fetch",
+ maximum="10",
+ minimum="1",
+ example="5"
+ )
+ long orderId
) throws InvalidIdException, IdNotFoundException {
+
if (orderId < 0 || orderId > 10)
throw new InvalidIdException();
return db.getOrder(orderId);
@@ -251,7 +280,14 @@ public class PetStoreResource extends BasicRestServletJena
{
"tags:[ 'store' ]"
}
)
- public Order placeOrder(@Body(description="Order placed for purchasing
the pet") Order order) throws IdConflictException {
+ public Order placeOrder(
+ @Body(
+ description="Order placed for purchasing the
pet",
+ example="{petId:456,quantity:100}"
+ )
+ Order order
+ ) throws IdConflictException {
+
return db.add(order);
}
@@ -262,12 +298,18 @@ public class PetStoreResource extends
BasicRestServletJena {
description="For valid response try integer IDs with positive
integer value. Negative or non-integer values will generate API errors.",
swagger={
"tags:[ 'store' ],",
- "responses: { 200: { description: 'OK', schema:{
type:'string' } } }"
+ "responses: { 200: { 'x-example':'OK' } }"
}
)
public String deletePurchaseOrder(
- @Path(description="ID of the order that needs to be
deleted", minimum="1.0") long orderId
+ @Path(
+ description="ID of the order that needs to be
deleted",
+ minimum="1",
+ example="5"
+ )
+ long orderId
) throws InvalidIdException, IdNotFoundException {
+
if (orderId < 0)
throw new InvalidIdException();
db.removeOrder(orderId);
@@ -282,7 +324,7 @@ public class PetStoreResource extends BasicRestServletJena {
swagger={
"tags:[ 'store' ],",
"responses:{",
- "200:{ description:'successful operation',
schema:{ type:'object', additionalProperties:{ type:'integer', format:'int32' }
} }",
+ "200:{ 'x-example':{AVAILABLE:123} }",
"},",
"security:[ { api_key:[] } ]"
}
@@ -326,7 +368,7 @@ public class PetStoreResource extends BasicRestServletJena {
description="This can only be done by the logged in user.",
swagger={
"tags:[ 'user' ],",
- "responses: { 200: { description: 'OK', schema:{
type:'string' } } }"
+ "responses: { 200: { 'x-example':'OK' } }"
}
)
public String createUser(@Body(description="Created user object") User
user) throws InvalidUsernameException, IdConflictException {
@@ -340,7 +382,7 @@ public class PetStoreResource extends BasicRestServletJena {
summary="Creates list of users with given input array",
swagger={
"tags:[ 'user' ],",
- "responses: { 200: { description: 'OK', schema:{
type:'string' } } }"
+ "responses: { 200: { 'x-example':'OK' } }"
}
)
public String createUsers(@Body(description="List of user objects")
User[] users) throws InvalidUsernameException, IdConflictException {
@@ -356,7 +398,7 @@ public class PetStoreResource extends BasicRestServletJena {
description="This can only be done by the logged in user.",
swagger={
"tags:[ 'user' ],",
- "responses: { 200: { description: 'OK', schema:{
type:'string' } } }"
+ "responses: { 200: { 'x-example':'OK' } }"
}
)
public String updateUser(
@@ -376,7 +418,7 @@ public class PetStoreResource extends BasicRestServletJena {
description="This can only be done by the logged in user.",
swagger={
"tags:[ 'user' ],",
- "responses: { 200: { description: 'OK', schema:{
type:'string' } } }"
+ "responses: { 200: { 'x-example':'OK' } }"
}
)
public String deleteUser(@Path(description="The name that needs to be
deleted") String username) throws InvalidUsernameException, IdNotFoundException
{
@@ -393,23 +435,38 @@ public class PetStoreResource extends
BasicRestServletJena {
"tags:[ 'user' ],",
"responses:{",
"200:{",
- "description: 'OK', schema:{
type:'string' },",
+ "'x-example':'OK',",
+ "schema:{ type:'string' },",
"headers:{",
- "X-Rate-Limit:{ type:'integer',
format:'int32', description:'calls per hour allowed by the user' },",
- "X-Expires-After:{
type:'string', format:'date-time', description:'date in UTC when token expires'
}",
+ "X-Rate-Limit:{ type:'integer',
format:'int32', description:'calls per hour allowed by the user',
'x-example':123},",
+ "X-Expires-After:{
type:'string', format:'date-time', description:'date in UTC when token
expires', 'x-example':'2012-10-21'}",
"}",
"}",
"}"
}
)
public String login(
- @Query(name="username", description="The username for
login", required="true") String username,
- @Query(name="password", description="The password for
login in clear text", required="true") String password,
+ @Query(
+ name="username",
+ description="The username for login",
+ required="true",
+ example="myuser"
+ )
+ String username,
+ @Query(
+ name="password",
+ description="The password for login in clear
text",
+ required="true",
+ example="abc123"
+ )
+ String password,
RestRequest req,
RestResponse res
) throws LoginException {
+
if (! db.isValid(username, password))
throw new LoginException();
+
Date d = new Date(System.currentTimeMillis() + 30 * 60 * 1000);
req.getSession().setAttribute("login-expires", d);
res.setHeader("X-Rate-Limit", "1000");
@@ -423,7 +480,7 @@ public class PetStoreResource extends BasicRestServletJena {
summary="Logs out current logged in user session",
swagger={
"tags:[ 'user' ],",
- "responses: { 200: { description: 'OK', schema:{
type:'string' } } }"
+ "responses: { 200: { 'x-example':'OK' } }"
}
)
public String logout(RestRequest req) {
diff --git
a/juneau-examples/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/petstore/User.java
b/juneau-examples/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/petstore/User.java
index d6978cc..9722010 100644
---
a/juneau-examples/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/petstore/User.java
+++
b/juneau-examples/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/petstore/User.java
@@ -20,6 +20,17 @@ public class User {
private String username, firstName, lastName, email, password, phone;
private int userStatus;
+ // This shows an example provided as a static field.
+ @Example
+ public static User EXAMPLE = new User()
+ .username("billy")
+ .firstName("Billy")
+ .lastName("Bob")
+ .email("[email protected]")
+ .id(123)
+ .userStatus(1)
+ .phone("111-222-3333");
+
public long getId() {
return id;
}
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 f907702..1788f15 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
@@ -334,49 +334,51 @@ public class BasicRestInfoProvider implements
RestInfoProvider {
if (in != BODY)
param.append("name", mp.name);
- ObjectMap pm = mp.getMetaData();
- if (pm.containsKeyNotEmpty("required"))
- param.put("required",
vr.resolve(pm.getString("required")));
- if (pm.containsKeyNotEmpty("description"))
- param.put("description",
vr.resolve(pm.getString("description")));
- if (pm.containsKeyNotEmpty("type"))
- param.put("type",
vr.resolve(pm.getString("type")));
- if (pm.containsKeyNotEmpty("format"))
- param.put("format",
vr.resolve(pm.getString("format")));
- if (pm.containsKeyNotEmpty("pattern"))
- param.put("pattern",
vr.resolve(pm.getString("pattern")));
- if (pm.containsKeyNotEmpty("collectionFormat"))
- param.put("collectionFormat",
vr.resolve(pm.getString("collectionFormat")));
- if (pm.containsKeyNotEmpty("maximum"))
- param.put("maximum",
vr.resolve(pm.getString("maximum")));
- if (pm.containsKeyNotEmpty("minimum"))
- param.put("minimum",
vr.resolve(pm.getString("minimum")));
- if (pm.containsKeyNotEmpty("multipleOf"))
- param.put("multipleOf",
vr.resolve(pm.getString("multipleOf")));
- if (pm.containsKeyNotEmpty("maxLength"))
- param.put("maxLength",
vr.resolve(pm.getString("maxLength")));
- if (pm.containsKeyNotEmpty("minLength"))
- param.put("minLength",
vr.resolve(pm.getString("minLength")));
- if (pm.containsKeyNotEmpty("maxItems"))
- param.put("maxItems",
vr.resolve(pm.getString("maxItems")));
- if (pm.containsKeyNotEmpty("minItems"))
- param.put("minItems",
vr.resolve(pm.getString("minItems")));
- if (pm.containsKeyNotEmpty("allowEmptyVals"))
- param.put("allowEmptyVals",
vr.resolve(pm.getString("allowEmptyVals")));
- if (pm.containsKeyNotEmpty("exclusiveMaximum"))
- param.put("exclusiveMaximum",
vr.resolve(pm.getString("exclusiveMaximum")));
- if (pm.containsKeyNotEmpty("exclusiveMimimum"))
- param.put("exclusiveMimimum",
vr.resolve(pm.getString("exclusiveMimimum")));
- if (pm.containsKeyNotEmpty("uniqueItems"))
- param.put("uniqueItems",
vr.resolve(pm.getString("uniqueItems")));
- if (pm.containsKeyNotEmpty("schema"))
- param.put("schema", new
ObjectMap(vr.resolve(pm.getString("schema"))));
- if (pm.containsKeyNotEmpty("default"))
- param.put("default",
JsonParser.DEFAULT.parse(vr.resolve(pm.getString("default")), Object.class));
- if (pm.containsKeyNotEmpty("enum"))
- param.put("enum", new
ObjectList(vr.resolve(pm.getString("enum"))));
- if (pm.containsKeyNotEmpty("items"))
- param.put("items", new
ObjectMap(vr.resolve(pm.getString("items"))));
+ ObjectMap pi = mp.getMetaData();
+ if (pi.containsKeyNotEmpty("required"))
+ param.put("required",
vr.resolve(pi.getString("required")));
+ if (pi.containsKeyNotEmpty("description"))
+ param.put("description",
vr.resolve(pi.getString("description")));
+ if (pi.containsKeyNotEmpty("type"))
+ param.put("type",
vr.resolve(pi.getString("type")));
+ if (pi.containsKeyNotEmpty("format"))
+ param.put("format",
vr.resolve(pi.getString("format")));
+ if (pi.containsKeyNotEmpty("pattern"))
+ param.put("pattern",
vr.resolve(pi.getString("pattern")));
+ if (pi.containsKeyNotEmpty("collectionFormat"))
+ param.put("collectionFormat",
vr.resolve(pi.getString("collectionFormat")));
+ if (pi.containsKeyNotEmpty("maximum"))
+ param.put("maximum",
vr.resolve(pi.getString("maximum")));
+ if (pi.containsKeyNotEmpty("minimum"))
+ param.put("minimum",
vr.resolve(pi.getString("minimum")));
+ if (pi.containsKeyNotEmpty("multipleOf"))
+ param.put("multipleOf",
vr.resolve(pi.getString("multipleOf")));
+ if (pi.containsKeyNotEmpty("maxLength"))
+ param.put("maxLength",
vr.resolve(pi.getString("maxLength")));
+ if (pi.containsKeyNotEmpty("minLength"))
+ param.put("minLength",
vr.resolve(pi.getString("minLength")));
+ if (pi.containsKeyNotEmpty("maxItems"))
+ param.put("maxItems",
vr.resolve(pi.getString("maxItems")));
+ if (pi.containsKeyNotEmpty("minItems"))
+ param.put("minItems",
vr.resolve(pi.getString("minItems")));
+ if (pi.containsKeyNotEmpty("allowEmptyVals"))
+ param.put("allowEmptyVals",
vr.resolve(pi.getString("allowEmptyVals")));
+ if (pi.containsKeyNotEmpty("exclusiveMaximum"))
+ param.put("exclusiveMaximum",
vr.resolve(pi.getString("exclusiveMaximum")));
+ if (pi.containsKeyNotEmpty("exclusiveMimimum"))
+ param.put("exclusiveMimimum",
vr.resolve(pi.getString("exclusiveMimimum")));
+ if (pi.containsKeyNotEmpty("uniqueItems"))
+ param.put("uniqueItems",
vr.resolve(pi.getString("uniqueItems")));
+ if (pi.containsKeyNotEmpty("schema"))
+ param.put("schema", new
ObjectMap(vr.resolve(pi.getString("schema"))));
+ if (pi.containsKeyNotEmpty("default"))
+ param.put("default",
JsonParser.DEFAULT.parse(vr.resolve(pi.getString("default")), Object.class));
+ if (pi.containsKeyNotEmpty("enum"))
+ param.put("enum", new
ObjectList(vr.resolve(pi.getString("enum"))));
+ if (pi.containsKeyNotEmpty("items"))
+ param.put("items", new
ObjectMap(vr.resolve(pi.getString("items"))));
+ if (pi.containsKeyNotEmpty("example"))
+ param.put("x-example",
parse(vr.resolve(pi.getString("example"))));
if ((in == BODY || in == PATH) && !
param.containsKeyNotEmpty("required"))
param.put("required", true);
@@ -411,14 +413,23 @@ public class BasicRestInfoProvider implements
RestInfoProvider {
}
}
- if (! responses.containsKey("200"))
- responses.put("200", new
ObjectMap().append("description", "Success"));
-
ObjectMap okResponse = responses.getObjectMap("200");
+ if (okResponse == null)
+ okResponse = new ObjectMap();
okResponse.put("schema", getSchema(req,
okResponse.getObjectMap("schema", true), js, m.getGenericReturnType()));
addXExamples(req, sm, okResponse, "ok", js,
m.getGenericReturnType());
+ responses.put("200", okResponse);
+
+ // Add default response descriptions.
+ for (Map.Entry<String,Object> e : responses.entrySet())
{
+ String key = e.getKey();
+ Object val = e.getValue();
+ if (StringUtils.isDecimal(key) && val
instanceof ObjectMap)
+
responses.getObjectMap(key).appendIf(false, true, true, "description",
RestUtils.getHttpResponseText(Integer.parseInt(key)));
+ }
+
if (responses.isEmpty())
op.remove("responses");
else
@@ -437,7 +448,8 @@ public class BasicRestInfoProvider implements
RestInfoProvider {
}
}
- definitions.putAll(js.getBeanDefs());
+ for (Map.Entry<String,ObjectMap> e :
js.getBeanDefs().entrySet())
+ definitions.put(e.getKey(),
fixSwaggerExtensions(e.getValue()));
if (definitions.isEmpty())
omSwagger.remove("definitions");
@@ -458,6 +470,13 @@ public class BasicRestInfoProvider implements
RestInfoProvider {
return swagger;
}
+ private Object parse(String s) throws ParseException {
+ char c1 = StringUtils.firstNonWhitespaceChar(s), c2 =
StringUtils.lastNonWhitespaceChar(s);
+ if (c1 == '{' && c2 == '}' || c1 == '[' && c2 == ']' || c1 ==
'\'' && c2 == '\'')
+ return JsonParser.DEFAULT.parse(s, Object.class);
+ return s;
+ }
+
private ObjectMap getSchema(RestRequest req, ObjectMap schema,
JsonSchemaSerializerSession js, Type type) throws Exception {
BeanSession bs = req.getBeanSession();
ClassMeta<?> cm = bs.getClassMeta(type);
@@ -465,19 +484,31 @@ public class BasicRestInfoProvider implements
RestInfoProvider {
if (schema.containsKey("type") || schema.containsKey("$ref"))
return schema;
- schema.putAll(js.getSchema(cm));
-
- return schema;
+ return fixSwaggerExtensions(schema.appendAll(js.getSchema(cm)));
}
+ /**
+ * Replaces non-standard JSON-Schema attributes with standard Swagger
attributes.
+ */
+ private ObjectMap fixSwaggerExtensions(ObjectMap om) {
+ om.appendSkipNull("discriminator",
om.remove("x-discriminator"));
+ om.appendSkipNull("readOnly", om.remove("x-readOnly"));
+ om.appendSkipNull("xml", om.remove("x-xml"));
+ om.appendSkipNull("externalDocs", om.remove("x-externalDocs"));
+ om.appendSkipNull("example", om.remove("x-example"));
+ return om;
+ }
- private void addXExamples(RestRequest req, RestJavaMethod sm, ObjectMap
m, String in, JsonSchemaSerializerSession js, Type type) throws Exception {
+ private void addXExamples(RestRequest req, RestJavaMethod sm, ObjectMap
piri, String in, JsonSchemaSerializerSession js, Type type) throws Exception {
- ObjectMap schema = resolve(js, m.getObjectMap("schema"));
- if (schema == null)
- return;
+ Object example = piri.get("x-example");
+
+ if (example == null) {
+ ObjectMap schema = resolve(js,
piri.getObjectMap("schema"));
+ if (schema != null)
+ example = schema.get("x-example");
+ }
- Object example = schema.get("example", Object.class);
if (example == null)
return;
@@ -487,7 +518,7 @@ public class BasicRestInfoProvider implements
RestInfoProvider {
String examplesKey = isOk ? "examples" : "x-examples"; //
Parameters don't have an examples attribute.
- ObjectMap examples = schema.getObjectMap(examplesKey);
+ ObjectMap examples = piri.getObjectMap(examplesKey);
if (examples == null)
examples = new ObjectMap();
@@ -506,11 +537,21 @@ public class BasicRestInfoProvider implements
RestInfoProvider {
}
}
} else {
- examples.put("example",
req.getPartSerializer().serialize(HttpPartType.valueOf(in.toUpperCase()),
example));
+ String paramName = piri.getString("name");
+ String s =
req.getPartSerializer().serialize(HttpPartType.valueOf(in.toUpperCase()),
example);
+ if ("query".equals(in))
+ s = "?" + paramName + "=" + s;
+ else if ("formData".equals(in))
+ s = paramName + "=" + s;
+ else if ("header".equals(in))
+ s = paramName + ": " + s;
+ else if ("path".equals(in))
+ s =
sm.getPathPattern().replace("{"+paramName+"}", s);
+ examples.put("example", s);
}
if (! examples.isEmpty())
- m.put(examplesKey, examples);
+ piri.put(examplesKey, examples);
}
private ObjectMap resolve(JsonSchemaSerializerSession js, ObjectMap m) {
diff --git
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestParamDefaults.java
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestParamDefaults.java
index c960cd4..f59cfb8 100644
---
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestParamDefaults.java
+++
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestParamDefaults.java
@@ -570,6 +570,7 @@ class RestParamDefaults {
.appendSkipEmpty("exclusiveMimimum",
a.exclusiveMimimum())
.appendSkipEmpty("schema", a.schema())
.appendSkipEmpty("enum", a._enum())
+ .appendSkipEmpty("example", a.example())
;
}
}
@@ -610,6 +611,7 @@ class RestParamDefaults {
.appendSkipEmpty("default", a._default())
.appendSkipEmpty("enum", a._enum())
.appendSkipEmpty("items", a.items())
+ .appendSkipEmpty("example", a.example())
;
}
}
@@ -652,6 +654,7 @@ class RestParamDefaults {
.appendSkipEmpty("default", a._default())
.appendSkipEmpty("enum", a._enum())
.appendSkipEmpty("items", a.items())
+ .appendSkipEmpty("example", a.example())
;
}
}
@@ -714,6 +717,7 @@ class RestParamDefaults {
.appendSkipEmpty("default", a._default())
.appendSkipEmpty("enum", a._enum())
.appendSkipEmpty("items", a.items())
+ .appendSkipEmpty("example", a.example())
;
}
}
@@ -762,6 +766,7 @@ class RestParamDefaults {
.appendSkipEmpty("default", a._default())
.appendSkipEmpty("enum", a._enum())
.appendSkipEmpty("items", a.items())
+ .appendSkipEmpty("example", a.example())
;
}
diff --git
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/annotation/Body.java
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/annotation/Body.java
index 4b79903..d3187ff 100644
---
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/annotation/Body.java
+++
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/annotation/Body.java
@@ -18,6 +18,8 @@ import static java.lang.annotation.RetentionPolicy.*;
import java.io.*;
import java.lang.annotation.*;
+import org.apache.juneau.rest.*;
+
/**
* Annotation that can be applied to a parameter of a {@link RestMethod
@RestMethod} annotated method to identify it as the HTTP
* request body converted to a POJO.
@@ -369,4 +371,22 @@ public @interface Body {
* </ul>
*/
String items() default "";
+
+ /**
+ * Defines the swagger value
<code>/paths/{path}/{method}/parameters/#/x-example</code>.
+ *
+ * <p>
+ * This attribute defines a JSON representation of the body value that
is used by {@link BasicRestInfoProvider} to construct
+ * media-type-based examples of the body of the request.
+ *
+ * <h5 class='section'>Notes:</h5>
+ * <ul class='spaced-list'>
+ * <li>
+ * The format of the value is a JSON object or plain-text
string.
+ * <li>
+ * Supports <a class="doclink"
href="../../../../../overview-summary.html#DefaultRestSvlVariables">initialization-time
and request-time variables</a>
+ * (e.g. <js>"$L{my.localized.variable}"</js>).
+ * </ul>
+ */
+ String example() default "";
}
diff --git
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/annotation/FormData.java
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/annotation/FormData.java
index 5dbf0c3..d9c1bfa 100644
---
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/annotation/FormData.java
+++
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/annotation/FormData.java
@@ -415,4 +415,22 @@ public @interface FormData {
* </ul>
*/
String items() default "";
+
+ /**
+ * Defines the swagger value
<code>/paths/{path}/{method}/parameters/#/x-example</code>.
+ *
+ * <p>
+ * This attribute defines a JSON representation of the value that is
used by {@link BasicRestInfoProvider} to construct
+ * an example of the form data entry.
+ *
+ * <h5 class='section'>Notes:</h5>
+ * <ul class='spaced-list'>
+ * <li>
+ * The format of the value is a JSON object or plain-text
string.
+ * <li>
+ * Supports <a class="doclink"
href="../../../../../overview-summary.html#DefaultRestSvlVariables">initialization-time
and request-time variables</a>
+ * (e.g. <js>"$L{my.localized.variable}"</js>).
+ * </ul>
+ */
+ String example() default "";
}
diff --git
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/annotation/Header.java
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/annotation/Header.java
index a25019c..01ad591 100644
---
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/annotation/Header.java
+++
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/annotation/Header.java
@@ -18,6 +18,7 @@ import static java.lang.annotation.RetentionPolicy.*;
import java.lang.annotation.*;
import org.apache.juneau.httppart.*;
+import org.apache.juneau.rest.*;
/**
* Annotation that can be applied to a parameter of a {@link RestMethod
@RestMethod} annotated method to identify it as a HTTP
@@ -387,4 +388,22 @@ public @interface Header {
* </ul>
*/
String items() default "";
+
+ /**
+ * Defines the swagger value
<code>/paths/{path}/{method}/parameters/#/x-example</code>.
+ *
+ * <p>
+ * This attribute defines a JSON representation of the value that is
used by {@link BasicRestInfoProvider} to construct
+ * an example of the header entry.
+ *
+ * <h5 class='section'>Notes:</h5>
+ * <ul class='spaced-list'>
+ * <li>
+ * The format of the value is a JSON object or plain-text
string.
+ * <li>
+ * Supports <a class="doclink"
href="../../../../../overview-summary.html#DefaultRestSvlVariables">initialization-time
and request-time variables</a>
+ * (e.g. <js>"$L{my.localized.variable}"</js>).
+ * </ul>
+ */
+ String example() default "";
}
diff --git
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/annotation/Path.java
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/annotation/Path.java
index 690ab29..fa30b8e 100644
---
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/annotation/Path.java
+++
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/annotation/Path.java
@@ -18,6 +18,7 @@ import static java.lang.annotation.RetentionPolicy.*;
import java.lang.annotation.*;
import org.apache.juneau.httppart.*;
+import org.apache.juneau.rest.*;
/**
* Annotation that can be applied to a parameter of a {@link RestMethod
@RestMethod} annotated method to identify it as a variable
@@ -307,4 +308,22 @@ public @interface Path {
* </ul>
*/
String _enum() default "";
+
+ /**
+ * Defines the swagger value
<code>/paths/{path}/{method}/parameters/#/x-example</code>.
+ *
+ * <p>
+ * This attribute defines a JSON representation of the value that is
used by {@link BasicRestInfoProvider} to construct
+ * an example of the path.
+ *
+ * <h5 class='section'>Notes:</h5>
+ * <ul class='spaced-list'>
+ * <li>
+ * The format of the value is a JSON object or plain-text
string.
+ * <li>
+ * Supports <a class="doclink"
href="../../../../../overview-summary.html#DefaultRestSvlVariables">initialization-time
and request-time variables</a>
+ * (e.g. <js>"$L{my.localized.variable}"</js>).
+ * </ul>
+ */
+ String example() default "";
}
diff --git
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/annotation/Query.java
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/annotation/Query.java
index 6fe9d1d..c3c60e7 100644
---
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/annotation/Query.java
+++
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/annotation/Query.java
@@ -411,4 +411,22 @@ public @interface Query {
* </ul>
*/
String items() default "";
+
+ /**
+ * Defines the swagger value
<code>/paths/{path}/{method}/parameters/#/x-example</code>.
+ *
+ * <p>
+ * This attribute defines a JSON representation of the value that is
used by {@link BasicRestInfoProvider} to construct
+ * an example of the query entry.
+ *
+ * <h5 class='section'>Notes:</h5>
+ * <ul class='spaced-list'>
+ * <li>
+ * The format of the value is a JSON object or plain-text
string.
+ * <li>
+ * Supports <a class="doclink"
href="../../../../../overview-summary.html#DefaultRestSvlVariables">initialization-time
and request-time variables</a>
+ * (e.g. <js>"$L{my.localized.variable}"</js>).
+ * </ul>
+ */
+ String example() default "";
}
diff --git
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/labels/NameDescription.java
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/labels/NameDescription.java
deleted file mode 100644
index b0e120a..0000000
---
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/labels/NameDescription.java
+++ /dev/null
@@ -1,89 +0,0 @@
-//
***************************************************************************************************************************
-// * Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file *
-// * distributed with this work for additional information regarding copyright
ownership. The ASF licenses this file *
-// * to you under the Apache License, Version 2.0 (the "License"); you may not
use this file except in compliance *
-// * with the License. You may obtain a copy of the License at
*
-// *
*
-// * http://www.apache.org/licenses/LICENSE-2.0
*
-// *
*
-// * Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an *
-// * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
express or implied. See the License for the *
-// * specific language governing permissions and limitations under the
License. *
-//
***************************************************************************************************************************
-package org.apache.juneau.rest.labels;
-
-import org.apache.juneau.annotation.*;
-
-/**
- * Simple bean with {@code name} and {@code description} properties.
- *
- * <p>
- * Primarily used for constructing tables with name/description columns on
REST OPTIONS requests.
- *
- * <h5 class='section'>See Also:</h5>
- * <ul>
- * <li class='link'><a class="doclink"
href="../../../../../overview-summary.html#juneau-rest-server.PredefinedLabelBeans">Overview
> juneau-rest-server > Predefined Label Beans</a>
- * </ul>
- */
-@Bean(properties="name,description")
-public class NameDescription {
-
- private Object name;
- private Object description;
-
- /** No-arg constructor. Used for JUnit testing of OPTIONS pages. */
- public NameDescription() {}
-
- /**
- * Constructor.
- *
- * @param name A name.
- * @param description A description.
- */
- public NameDescription(Object name, Object description) {
- this.name = name;
- this.description = description;
- }
-
- /**
- * Returns the name field on this label.
- *
- * @return The name.
- */
- public Object getName() {
- return name;
- }
-
- /**
- * Sets the name field on this label to a new value.
- *
- * @param name The new name.
- * @return This object (for method chaining).
- */
- @BeanProperty
- public NameDescription name(Object name) {
- this.name = name;
- return this;
- }
-
- /**
- * Returns the description field on this label.
- *
- * @return The description.
- */
- public Object getDescription() {
- return description;
- }
-
- /**
- * Sets the description field on this label to a new value.
- *
- * @param description The new description.
- * @return This object (for method chaining).
- */
- @BeanProperty
- public NameDescription description(Object description) {
- this.description = description;
- return this;
- }
-}
diff --git
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/labels/ResourceDescription.java
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/labels/ResourceDescription.java
index e496edd..68376b0 100644
---
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/labels/ResourceDescription.java
+++
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/labels/ResourceDescription.java
@@ -12,6 +12,7 @@
//
***************************************************************************************************************************
package org.apache.juneau.rest.labels;
+import org.apache.juneau.annotation.*;
import org.apache.juneau.html.annotation.*;
/**
@@ -27,7 +28,10 @@ import org.apache.juneau.html.annotation.*;
* <li class='link'><a class="doclink"
href="../../../../../overview-summary.html#juneau-rest-server.PredefinedLabelBeans">Overview
> juneau-rest-server > Predefined Label Beans</a>
* </ul>
*/
-public final class ResourceDescription extends NameDescription implements
Comparable<ResourceDescription> {
+@Bean(properties="name,description", fluentSetters=true)
+public final class ResourceDescription implements
Comparable<ResourceDescription> {
+
+ private String name, description;
/**
* Constructor.
@@ -36,18 +40,55 @@ public final class ResourceDescription extends
NameDescription implements Compar
* @param description The description of the child resource.
*/
public ResourceDescription(String name, String description) {
- super(name, description);
+ this.name = name;
+ this.description = description;
}
/** No-arg constructor. Used for JUnit testing of OPTIONS pages. */
public ResourceDescription() {}
- @Override /* NameDescription */
+ /**
+ * Returns the name field on this label.
+ *
+ * @return The name.
+ */
@Html(link="servlet:/{name}")
- public Object getName() {
- return super.getName();
+ public String getName() {
+ return name;
+ }
+
+ /**
+ * Sets the name field on this label to a new value.
+ *
+ * @param name The new name.
+ * @return This object (for method chaining).
+ */
+ public ResourceDescription name(String name) {
+ this.name = name;
+ return this;
}
+ /**
+ * Returns the description field on this label.
+ *
+ * @return The description.
+ */
+ public String getDescription() {
+ return description;
+ }
+
+ /**
+ * Sets the description field on this label to a new value.
+ *
+ * @param description The new description.
+ * @return This object (for method chaining).
+ */
+ public ResourceDescription description(String description) {
+ this.description = description;
+ return this;
+ }
+
+
@Override /* Comparable */
public int compareTo(ResourceDescription o) {
return getName().toString().compareTo(o.getName().toString());
--
To stop receiving notification emails like this one, please contact
[email protected].