Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • O openapi-generator
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,476
    • Issues 3,476
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 402
    • Merge requests 402
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • OpenAPI Tools
  • openapi-generator
  • Issues
  • #517
Closed
Open
Issue created Jul 09, 2018 by Administrator@rootContributor

[Java][Jersey2] Java6 compatibility broken in ApiClient using diamond operator without generic type inference

Created by: jcohen-stingray

Description

ApiClient.mustache template for method invokeApi() uses return statements that do not conform to java 6 compatibility. Return statements should include generic type in method definition. Every other class generated with the java-jersey2 generator is java6 compatible with regards to diamond operators.

C:\dev\...\clientjava6\ApiClient.java:698: error: diamond operator is not supported in -source 1.6
        return new ApiResponse<>(statusCode, responseHeaders);
                               ^
  (use -source 7 or higher to enable diamond operator)
1 error
openapi-generator version

3.0.3

OpenAPI gradle task specification
openApiGenerate {
    inputSpec = swaggerInput.path
    outputDir = swaggerOutputDir.path
    generatorName = 'java'
    library = 'jersey2'
    invokerPackage = "com.stingray." + root_project_without_hyphen + ".$project.name".replaceAll(~/-/, "")
    modelPackage = "com.stingray." + root_project_without_hyphen + ".$project.name".replaceAll(~/-/, "") + ".model"
    apiPackage = "com.stingray." + root_project_without_hyphen + ".$project.name".replaceAll(~/-/, "") + ".api"
    generateApiTests = true
    generateApiDocumentation = false
    generateModelTests = true
    generateModelDocumentation = false
    additionalProperties = [
        'supportJava6' : 'true',
        'dateLibrary' : 'threetenbp',
        'sourceFolder'  : 'src/generated/java/',
    ]
}
Steps to reproduce
  1. Using the gradle plugin and any valid specification swagger yaml file, run the openApiGenerate task to generate a java client.
  2. In the build.gradle file, set the compileJava settings to java 1.6:
compileJava {
    sourceCompatibility = 1.6
    targetCompatibility = 1.6
}
  1. Run gradle build to see the compilation error.
Suggest a fix/enhancement

The file ApiClient.mustache, add generic type to the 3 return statements of the method invokeApi():

if (response.getStatus() == Status.NO_CONTENT.getStatusCode()) {
        return new ApiResponse<T>(statusCode, responseHeaders);
      } else if (response.getStatusInfo().getFamily() == Status.Family.SUCCESSFUL) {
        if (returnType == null)
          return new ApiResponse<T>(statusCode, responseHeaders);
        else
          return new ApiResponse<T>(statusCode, responseHeaders, deserialize(response, returnType));

Lines 712 through 717.

Assignee
Assign to
Time tracking