Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add 'title' attribute during deserialization of non-primitive properties #1599

Merged
merged 1 commit into from
Mar 5, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -168,21 +168,25 @@ public Xml getXml(JsonNode node) {

Property propertyFromNode(JsonNode node) {
final String type = getString(node, PropertyBuilder.PropertyId.TYPE);
final String title = getString(node, PropertyBuilder.PropertyId.TITLE);
final String format = getString(node, PropertyBuilder.PropertyId.FORMAT);
final Xml xml = getXml(node);

String description = getString(node, PropertyBuilder.PropertyId.DESCRIPTION);
JsonNode detailNode = node.get("$ref");
if (detailNode != null) {
return new RefProperty(detailNode.asText()).description(description);
return new RefProperty(detailNode.asText())
.description(description)
.title(title);
}

if (ObjectProperty.isType(type) || node.get("properties") != null) {
detailNode = node.get("additionalProperties");
if (detailNode != null && detailNode.getNodeType().equals(JsonNodeType.OBJECT)) {
Property items = propertyFromNode(detailNode);
if (items != null) {
MapProperty mapProperty = new MapProperty(items).description(description);
MapProperty mapProperty = new MapProperty(items)
.description(description)
.title(title);
mapProperty.setVendorExtensionMap(getVendorExtensions(node));
return mapProperty;
}
Expand All @@ -209,7 +213,9 @@ Property propertyFromNode(JsonNode node) {
}

if("array".equals(detailNodeType)) {
ArrayProperty ap = new ArrayProperty().description(description);
ArrayProperty ap = new ArrayProperty()
.description(description)
.title(title);
ap.setDescription(description);

if(properties.keySet().size() == 1) {
Expand All @@ -219,7 +225,9 @@ Property propertyFromNode(JsonNode node) {
ap.setVendorExtensionMap(getVendorExtensions(node));
return ap;
}
ObjectProperty objectProperty = new ObjectProperty(properties).description(description);
ObjectProperty objectProperty = new ObjectProperty(properties)
.description(description)
.title(title);
objectProperty.setVendorExtensionMap(getVendorExtensions(node));

List<String> required = getRequired(node, PropertyBuilder.PropertyId.REQUIRED);
Expand All @@ -232,7 +240,10 @@ Property propertyFromNode(JsonNode node) {
detailNode = node.get("items");
if (detailNode != null) {
Property subProperty = propertyFromNode(detailNode);
ArrayProperty arrayProperty = new ArrayProperty().items(subProperty).description(description);
ArrayProperty arrayProperty = new ArrayProperty()
.items(subProperty)
.description(description)
.title(title);
arrayProperty.setVendorExtensionMap(getVendorExtensions(node));
return arrayProperty;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public void testCompositionTest() throws IOException {
public void testObjectProperty() throws IOException {
final String json = "{\n" +
" \"type\":\"object\",\n" +
" \"title\":\"objectProperty\",\n" +
" \"description\":\"top level object\",\n" +
" \"properties\":{\n" +
" \"property1\":{\n" +
Expand All @@ -54,7 +55,8 @@ public void testObjectProperty() throws IOException {
"}";
final Property result = m.readValue(json, Property.class);
assertTrue(result instanceof ObjectProperty);
assertEquals(((ObjectProperty) result).getProperties().size(), 3);
assertEquals(3, ((ObjectProperty) result).getProperties().size());
assertEquals("objectProperty", ((ObjectProperty) result).getTitle());

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ public ArrayProperty description(String description) {
return this;
}

public ArrayProperty title(String title) {
this.setTitle(title);
return this;
}

public ArrayProperty items(Property items) {
setItems(items);
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ public MapProperty description(String description) {
return this;
}

public MapProperty title(String title) {
this.setTitle(title);
return this;
}

public MapProperty vendorExtension(String key, Object obj) {
this.setVendorExtension(key, obj);
return this;
Expand Down