Skip to content

[BUG][JAVA][MAVEN] Array aliases generate uncompilable Java code with generateAliasAsModel=true #23988

@adamszeibert

Description

@adamszeibert

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator?
  • 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

I have a schema called Item, I have array of Item properties in many schemas so I made an ItemArray alias to make my property definition shorter. I have generateAliasAsModel=true because I have other schema aliases. The generated Java code is
private ItemArray itemArray = new ArrayList<>();

which obviously does not compile. The correct code in this case should be
private List<Item> itemArray = new ArrayList<>();

openapi-generator version

7.23.0

OpenAPI declaration file content or url
openapi: 3.0.1
info:
  title: Test
  version: 0.0.1
paths: {}

components:
  schemas:
    Item:
      type: object
      properties:
        property:
          type: string
    ItemArray:
      type: array
      items:
        $ref: '#/components/schemas/Item'
    MyObject:
      type: object
      properties:
        id:
          type: string
          format: uuid
        itemArray:
          $ref: '#/components/schemas/ItemArray'
Generation Details

config from pom.xml

<generateSupportingFiles>false</generateSupportingFiles>
<generatorName>spring</generatorName>
<strictSpec>true</strictSpec>
<generateApiTests>false</generateApiTests>
<generateModelTests>false</generateModelTests>
<generateAliasAsModel>true</generateAliasAsModel>
<configOptions>
    <legacyDiscriminatorBehavior>true</legacyDiscriminatorBehavior>
    <library>spring-boot</library>
    <oas3>true</oas3>
    <useSpringController>true</useSpringController>
    <useSpringBoot3>true</useSpringBoot3>
    <useSpringfox>false</useSpringfox>
    <interfaceOnly>true</interfaceOnly>
    <skipDefaultInterface>true</skipDefaultInterface>
    <useBeanValidation>true</useBeanValidation>
    <useEnumCaseInsensitive>false</useEnumCaseInsensitive>
    <useClassLevelBeanValidation>false</useClassLevelBeanValidation>
    <serializableModel>true</serializableModel>
    <useTags>true</useTags>
    <javaNative>21</javaNative>
    <useOptional>false</useOptional>
    <hideGenerationTimestamp>true</hideGenerationTimestamp>
    <dateLibrary>java8</dateLibrary>
    <bigDecimalAsString>true</bigDecimalAsString>
    <generateApiUtil>false</generateApiUtil>
    <openApiNormalizer>RULE_1=true</openApiNormalizer>
    <apiPackage>com.test.api</apiPackage>
    <modelPackage>com.test.model</modelPackage>
</configOptions>
Steps to reproduce

The generated Java code is always wrong.

Related issues/PRs
Suggest a fix

The generated Java code should be
private List<Item> itemArray = new ArrayList<>();
instead of
private ItemArray itemArray = new ArrayList<>();

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