Skip to content

Commit

Permalink
Make the array items optional (OpenAPITools#6132)
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastien-rosset authored and michaelpro1 committed May 7, 2020
1 parent 09bad34 commit ea7f5e5
Showing 1 changed file with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,20 @@ public String getTypeDeclaration(Schema p) {
if (ModelUtils.isArraySchema(p)) {
ArraySchema ap = (ArraySchema) p;
Schema inner = ap.getItems();
return "[]" + getTypeDeclaration(ModelUtils.unaliasSchema(this.openAPI, inner));
// In OAS 3.0.x, the array "items" attribute is required.
// In OAS >= 3.1, the array "items" attribute is optional such that the OAS
// specification is aligned with the JSON schema specification.
// When "items" is not specified, the elements of the array may be anything at all.
if (inner != null) {
inner = ModelUtils.unaliasSchema(this.openAPI, inner);
}
String typDecl;
if (inner != null) {
typDecl = getTypeDeclaration(inner);
} else {
typDecl = "interface{}";
}
return "[]" + typDecl;
} else if (ModelUtils.isMapSchema(p)) {
Schema inner = ModelUtils.getAdditionalProperties(p);
return getSchemaType(p) + "[string]" + getTypeDeclaration(ModelUtils.unaliasSchema(this.openAPI, inner));
Expand Down

0 comments on commit ea7f5e5

Please sign in to comment.