OpenAPITools / openapi-generator

OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec (v2, v3)
https://openapi-generator.tech
Apache License 2.0
21.49k stars 6.5k forks source link

[BUG][JAVA] Compilation error: element value must be a constant expression #2540

Open benoitheinrich opened 5 years ago

benoitheinrich commented 5 years ago

Bug Report Checklist

In version 3.3.3 that same spec was working and was generating:

@RequestParam(value = "username", required = true, defaultValue="null")
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: benoit.heinrich@gmail.com
  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

Zomzog commented 5 years ago

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

benoitheinrich commented 5 years ago

Do you know when the 4.0.0 is supposed to be released ?

karismann commented 5 years ago

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)

bsakari commented 4 months ago

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)