Skip to content

[BUG] OpenAPI Generator fails to generate array models #7802

Open
@segevfiner

Description

@segevfiner

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description

OpenAPI generator fails to generate array models. It complains with:

[main] INFO  o.o.codegen.DefaultGenerator - Model {} not generated since it's an alias to array (without property) and `generateAliasAsModel` is set to false (default)
openapi-generator version

v4.3.1

And also tried latest master using Docker 07c23f4.

OpenAPI declaration file content or url
openapi: '3.0.3'

info:
  title: Test
  version: 0.1.0

paths: {}

components:
  schemas:
    Test:
      type: array
      items:
        type: object
        properties:
          foo:
            type: string
Generation Details
docker run --rm \                                
  -v ${PWD}:/local openapitools/openapi-generator-cli generate \    
  -i /local/openapi.yaml \ 
  -g go \
  -o /local/out/go
Steps to reproduce
  1. Generate a client for any language using the provided schema. Note that the array model is not generated with the log message from this bug's description.
Related issues/PRs
Suggest a fix

The following code is erroneous. An array has items not properties (Even required by the OpenAPI spec). You might need to cast Schema to ArraySchema to get access to items or something like that.

if (!ModelUtils.isGenerateAliasAsModel(schema) && (schema.getProperties() == null || schema.getProperties().isEmpty())) {
// schema without property, i.e. alias to array
LOGGER.info("Model {} not generated since it's an alias to array (without property) and `generateAliasAsModel` is set to false (default)", name);
continue;

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions