Skip to content

[BUG] array schemas with single non-object allOf entry aren't resolved #23837

@RomiRand

Description

@RomiRand
Description

When an array schema contains an allOf definition with just a single element (that is not an object), it is not resolved, even though this can safely be unwrapped. This leads to type resolution errors in generated code. Other composed schemas such as oneOf are handled correctly.

openapi-generator version

v7.22.0

OpenAPI declaration file content or url
openapi: 3.0.0
info:
  title: Test
  version: 1.0.0
paths: {}
components:
  schemas:
    Data:
      type: object
      properties:
        outer:
          type: array
          items:
            allOf:
              - type: array
                items:
                  type: string
Generation Details

It happens with all generated outputs, many languages can't compile the generated code. E.g. go:

// Data struct for Data
type Data struct {
	Outer []Array `json:"outer,omitempty"`
}
Steps to reproduce

run openapi-generator with:
openapi-generator generate -i modules/openapi-generator/src/test/resources/3_0/array_allof_single_type.yaml -o out/ -g <anything>

Related issues/PRs

#23838

Suggest a fix

Basically needs analog handling to the object case:

} else if (ModelUtils.isComposedSchema(prop)) {
if (prop.getAllOf() != null && prop.getAllOf().size() == 1 &&
!(((Schema) prop.getAllOf().get(0)).getType() == null ||
"object".equals(((Schema) prop.getAllOf().get(0)).getType()))) {
// allOf with only 1 type (non-model)
LOGGER.info("allOf schema used by the property `{}` replaced by its only item (a type)", propName);
props.put(propName, (Schema) prop.getAllOf().get(0));
}

I'll open a PR

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions