Bug Report Checklist
Description
When I define a default value for a nested array structure the resulting Java code can not be compiled. I attached a specification, that reproduces the issue.
openapi-generator version
7.14
OpenAPI declaration file content or url
openapi: 3.0.4
info:
title: Title
description: Title
version: 1.0.0
servers:
- url: 'https'
paths: {}
components:
schemas:
Example:
type: object
properties:
nestedArray:
type: array
items:
type: array
items:
type: string
default:
[
[ "h1", "Header 1" ],
[ "h2", "Header 2" ],
[ "h3", "Header 3" ],
[ "h4", "Header 4" ]
]
Generation Details
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<version>${openapi-generator-version}</version>
<configuration>
<configOptions>
<library>resttemplate</library>
</configOptions>
<generateApis>false</generateApis>
<generateApiDocumentation>false</generateApiDocumentation>
<generateApiTests>false</generateApiTests>
<generateModels>true</generateModels>
<generateModelDocumentation>false</generateModelDocumentation>
<generateModelTests>false</generateModelTests>
<generatorName>java</generatorName>
<generateSupportingFiles>false</generateSupportingFiles>
</configuration>
Steps to reproduce
Generate the Java class with my OpenApi above and try to compile the resulting class.
The issue should look like this: private List<List<String>> nestedArray = new ArrayList<>(Arrays.asList(, , ,,));
Suggest a fix
I traced the issue down to this part of the AbstractJavaCodegen.toArrayDefaultValue()
The problem is that element.asText() receives an ArrayNode, that will return as empty string for every element.
I have played around with a patch, that recursively walks further down the defaults, but its only a rough draft. I you are interested I can share that.
Bug Report Checklist
Description
When I define a default value for a nested array structure the resulting Java code can not be compiled. I attached a specification, that reproduces the issue.
openapi-generator version
7.14
OpenAPI declaration file content or url
Generation Details
Steps to reproduce
Generate the Java class with my OpenApi above and try to compile the resulting class.
The issue should look like this:
private List<List<String>> nestedArray = new ArrayList<>(Arrays.asList(, , ,,));Suggest a fix
I traced the issue down to this part of the AbstractJavaCodegen.toArrayDefaultValue()
The problem is that
element.asText()receives an ArrayNode, that will return as empty string for every element.I have played around with a patch, that recursively walks further down the defaults, but its only a rough draft. I you are interested I can share that.