Skip to content

Commit

Permalink
Improve handling of union type in parameter schema (close #64)
Browse files Browse the repository at this point in the history
Signed-off-by: Ben Sherman <[email protected]>
  • Loading branch information
bentsherman committed Nov 21, 2024
1 parent 0743fc4 commit 01d9722
Showing 1 changed file with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,8 @@ private void declareParameters() {
var attrs = asMap(entry.getValue()).orElse(null);
if( attrs == null )
continue;
var type = getTypeClassFromString((String) attrs.get("type"));
var description = (String) attrs.get("description");
var type = getTypeClassFromString(asString(attrs.get("type")));
var description = asString(attrs.get("description"));
var fn = new FieldNode(name, Modifier.PUBLIC, type, cn, null);
fn.setHasNoRealSourcePosition(true);
fn.setDeclaringClass(cn);
Expand Down Expand Up @@ -160,6 +160,12 @@ private static Optional<Map> asMap(Object value) {
: Optional.empty();
}

private static String asString(Object value) {
return value instanceof String
? (String) value
: null;
}

private ClassNode getTypeClassFromString(String type) {
if( "boolean".equals(type) )
return ClassHelper.boolean_TYPE;
Expand Down

0 comments on commit 01d9722

Please sign in to comment.