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
  • #5324
Closed
Open
Issue created Feb 14, 2020 by Administrator@rootContributor5 of 6 checklist items completed5/6 checklist items

[BUG][Java] Generated API class has wrong dataType and does not compile

Created by: sebastien-rosset

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • What's the version of OpenAPI Generator used?
  • Have you search for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Bounty to sponsor the fix (example)
Description

Using OpenAPI v3 document to generate a client-side Java SDK with the default library (okhttp-gson). The generated classes under the "api" directory cause a compilation failure.

For example, a generated API Java class api/SyslogApi.java has the following createSyslogPolicyCall() method. The requestBody argument is a templatized PolicyAbstractPolicy<String, Object>.

  public okhttp3.Call
  createSyslogPolicyCall(PolicyAbstractPolicy<String, Object> requestBody,
                         final ApiCallback _callback) throws ApiException {
    Object localVarPostBody = requestBody;

However, the generated model/PolicyAbstractPolicy.java class is not a generic, hence the compilation fails. There are two problems:

  1. The argument uses a generic
  2. The argument type is the parent class

I was expecting the generated method signature to be something like:

public okhttp3.Call createSyslogPolicyCall(SyslogPolicy syslogPolicy, final ApiCallback _callback)

The mustache templates that are used to generate these classes are:

  1. API: Java/libraries/native/api.mustache
  2. Model: modules/openapi-generator/src/main/resources/Java/pojo.mustache

It looks like the problem is the value of dataType in the API template does not match the class name of the POJO

{{{dataType}}} {{paramName}}

I am using the default Java library, which is okhttp-gson.

openapi-generator version

master February 14th 2020

OpenAPI declaration file content or url

Operations:

  /syslog/Policies:
    post:
      tags:
      - syslog
      summary: Create a 'syslog.Policy' resource.
      operationId: CreateSyslogPolicy
      requestBody:
        description: The 'syslog.Policy' resource to create.
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/syslog.Policy'
      responses:
        '200':
          description: The 'syslog.Policy'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/syslog.Policy'

Schema:

    mo.BaseMo:
      type: object
      discriminator:
        propertyName: objectType
      required:
      - objectType
      properties:
        objectType:
          type: string

    policy.AbstractPolicy:
      allOf:
      - $ref: '#/components/schemas/mo.BaseMo'
      - type: object
        required:
        - objectType
        properties:
          description:
            type: string

    syslog.Policy:
      additionalProperties: {}
      allOf:
      - $ref: '#/components/schemas/policy.AbstractPolicy'
      - type: object
        required:
        - objectType
        properties:
          localClients:
            type: array
            items:
              type: string
Command line used for generation
Steps to reproduce

Edit modules/openapi-generator/src/test/resources/3_0/petstore-with-fake-endpoints-models-for-testing.yaml and add the YAML snippets listed in this issue.

Invoke bin/java-petstore-native.sh


Run mvn package in sample directory.

Open samples/......./openapitools/client/api/SyslogApi.java in file editor.

Related issues/PRs
Suggest a fix
Assignee
Assign to
Time tracking