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

feat: support declared type as array for jsonSchema #1590

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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 @@ -32,6 +32,9 @@
import com.sun.codemodel.JVar;
import org.apache.commons.lang.StringUtils;

import java.util.Iterator;
import java.util.stream.StreamSupport;

/**
* Applies the schema rules that represent a property definition.
*
Expand Down Expand Up @@ -221,11 +224,25 @@ private JsonNode resolveRefs(JsonNode node, Schema parent) {
}

private boolean isObject(JsonNode node) {
return node.path("type").asText().equals("object");
return checkType(node, "object");
}

private boolean isArray(JsonNode node) {
return node.path("type").asText().equals("array");
return checkType(node, "array");
}

private boolean checkType(JsonNode node, String type) {
return checkSimpleType(node, type) || checkArrayOfTypes(node, type);
}

private static boolean checkArrayOfTypes(JsonNode node, String type) {
return StreamSupport.stream(node.path("type").spliterator(), false)
.map(JsonNode::asText)
.anyMatch(type::equals);
}

private static boolean checkSimpleType(JsonNode node, String type) {
return node.path("type").asText().equals(type);
}

private JType getReturnType(final JDefinedClass c, final JFieldVar field, final boolean required, final boolean usesOptional) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
}
},
"refarray" : {
"type": "array",
"type": [ "array" ],
"items": {
"$ref": "#definitions/product"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"type": "string"
},
"objectfield" : {
"type": "object",
"type": [ "object" ] ,
"properties": {
"childprimitivefield" : {
"type": "string",
Expand Down