Skip to content

Commit ea7f5e5

Browse files
sebastien-rossetmichaelpro1
authored andcommitted
Make the array items optional (OpenAPITools#6132)
1 parent 09bad34 commit ea7f5e5

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractGoCodegen.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,20 @@ public String getTypeDeclaration(Schema p) {
328328
if (ModelUtils.isArraySchema(p)) {
329329
ArraySchema ap = (ArraySchema) p;
330330
Schema inner = ap.getItems();
331-
return "[]" + getTypeDeclaration(ModelUtils.unaliasSchema(this.openAPI, inner));
331+
// In OAS 3.0.x, the array "items" attribute is required.
332+
// In OAS >= 3.1, the array "items" attribute is optional such that the OAS
333+
// specification is aligned with the JSON schema specification.
334+
// When "items" is not specified, the elements of the array may be anything at all.
335+
if (inner != null) {
336+
inner = ModelUtils.unaliasSchema(this.openAPI, inner);
337+
}
338+
String typDecl;
339+
if (inner != null) {
340+
typDecl = getTypeDeclaration(inner);
341+
} else {
342+
typDecl = "interface{}";
343+
}
344+
return "[]" + typDecl;
332345
} else if (ModelUtils.isMapSchema(p)) {
333346
Schema inner = ModelUtils.getAdditionalProperties(p);
334347
return getSchemaType(p) + "[string]" + getTypeDeclaration(ModelUtils.unaliasSchema(this.openAPI, inner));

0 commit comments

Comments
 (0)