Skip to content

Commit

Permalink
better type check for additoinal properties before casting (#18212)
Browse files Browse the repository at this point in the history
  • Loading branch information
wing328 authored Mar 23, 2024
1 parent 4ca8f9c commit 420e49f
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -277,8 +277,11 @@ public String getTypeDeclaration(Schema p) {
Schema inner = ap.getItems();
return "[" + getTypeDeclaration(inner) + "]";
} else if (ModelUtils.isMapSchema(p)) {
Schema inner = (Schema) p.getAdditionalProperties();
return getTypeDeclaration(inner);
Object ap = p.getAdditionalProperties();
// additionalProperties is either a Schema or a Boolean
if (ap instanceof Schema) {
return getTypeDeclaration((Schema) ap);
}
}

// Not using the supertype invocation, because we want to UpperCamelize
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,10 +171,10 @@ public String getTypeDeclaration(Schema p) {

return "(s/coll-of " + getTypeDeclaration(inner) + ")";
} else if (ModelUtils.isMapSchema(p)) {
Object additionalProperties = p.getAdditionalProperties();
Object ap = p.getAdditionalProperties();
// additionalProperties is either a Schema or a Boolean
if (additionalProperties instanceof Schema) {
Schema inner = (Schema) additionalProperties;
if (ap instanceof Schema) {
Schema inner = (Schema) ap;
return "(s/map-of string? " + getTypeDeclaration(inner) + ")";
}
return "(s/map-of string? s/any?)";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,10 @@ public String getTypeDeclaration(Schema p) {
// return "[" + getTypeDeclaration(inner) + "]";
return getTypeDeclaration(inner);
} else if (ModelUtils.isMapSchema(p)) {
Schema inner = (Schema) p.getAdditionalProperties();

return getTypeDeclaration(inner);
Object ap = p.getAdditionalProperties();
if (ap instanceof Schema) {
return getTypeDeclaration((Schema) ap);
}
}

// IMPORTANT NOTE Not using the supertype invocation, because we want to UpperCamelize the type:
Expand Down

0 comments on commit 420e49f

Please sign in to comment.