[BUG][JAVA] Compilation error: element value must be a constant expression
Bug Report Checklist
-
[ ] Have you provided a full/minimal spec to reproduce the issue? yes
-
[ ] Have you validated the input using an OpenAPI validator (example)? yes
-
[ ] What's the version of OpenAPI Generator used? 3.3.4
-
[ ] Have you search for related issues/PRs? yes
-
[ ] What's the actual output vs expected output? The generated java code is:
@RequestParam(value = "username", required = true, defaultValue=null)
And that code doesn't compile due to:
StuffApi.java:[53,123] element value must be a constant expression
In version 3.3.3 that same spec was working and was generating:
@RequestParam(value = "username", required = true, defaultValue="null")
- [ ] [Optional] Bounty to sponsor the fix (example) no
Description
When migrating from openapi-generator-maven-plugin 3.3.3 to 3.3.4 the generated code doesn't compile anymore.
openapi-generator version
I'm using version 3.3.4 of openapi-generator.
OpenAPI declaration file content or url
openapi: 3.0.2
info:
title: Smple API
contact:
name: Benoit Heinrich
email: [email protected]
version: 1.0.0
paths:
/stuff:
description: Manage stuff
get:
summary: Get some stuff
operationId: getStuff
parameters:
- in: query
name: username
required: true
schema:
$ref: '#/components/schemas/Username'
- in: query
name: filename
allowReserved: true
required: false
schema:
$ref: '#/components/schemas/Filename'
responses:
200:
description: worked
content:
application/json:
schema:
$ref: '#/components/schemas/WorkedOperationStatus'
example:
status: 'success'
message: 'It worked'
comment: 'the work to be done is done!'
components:
schemas:
Workload:
type: object
required:
- comment
properties:
comment:
$ref: '#/components/schemas/Comment'
Comment:
description: A user comment
type: string
minLength: 1
maxLength: 1000
example:
Some comment from user
WorkedOperationStatus:
type: object
required:
- status
- message
properties:
status:
type: string
enum:
- error
- success
message:
type: string
comment:
$ref: '#/components/schemas/Comment'
example:
status: 'error'
message: 'Unknown work type'
comment: 'the work to be done is done!'
Username:
description: The name of the user doing the action.
type: string
minLength: 1
maxLength: 60
example:
John
Filename:
description: The name of a configuration file.
type: string
pattern: '^[a-zA-Z0-9_-]+\.(csv|groovy)$'
example:
04_a_DOCUMENTS.csv
Command line used for generation
This happens using openapi-generator-maven-plugin, here is the plugin configuration:
<plugin>
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>${project.basedir.parent}/api/src/main/resources/spec.yaml</inputSpec>
<generatorName>spring</generatorName>
<library>spring-boot</library>
<validateSpec>true</validateSpec>
<generateSupportingFiles>false</generateSupportingFiles>
<apiPackage>com.bh.sample</apiPackage>
<modelPackage>com.bh.sample</modelPackage>
<generateModels>false</generateModels>
<withXml>true</withXml>
<configOptions>
<hideGenerationTimestamp>true</hideGenerationTimestamp>
<delegatePattern>true</delegatePattern>
<useBeanValidation>true</useBeanValidation>
<java8>true</java8>
<reactive>false</reactive>
</configOptions>
</configuration>
</execution>
</executions>
</plugin>
Steps to reproduce
A sample project is available here: https://github.com/benoitheinrich/spring-cloud-contract-long-text
Run mvn clean install
Reproduced in 3.3.4 but not in 4.0.0, looks like it has been fixed.
3.3.3 generate "null", 3.3.4 generate null
Do you know when the 4.0.0 is supposed to be released ?
Do you know when the 4.0.0 is supposed to be released ?
mid May to align with the project's anniversary (https://github.com/OpenAPITools/openapi-generator/milestone/4)
How can I solve this?
app/build/tmp/kapt3/stubs/debug/com/.../.../domain/model/ProductItem.java:4: error: element value must be a constant expression @androidx.room.Entity(tableName = null)