OpenAPITools / OpenAPITools/openapi-generator

[Java] Different interface name gets generated by using jaxrs-spec and jaxrs-cxf generators

Open
#2,889 0 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

I'm using 4.0.0 version with Maven plugin to generate Java code.

components:

  schemas:
    BaseRequest:
      type: object
      properties:
        sampleField:
          type: string

    Payment:
      type: object
      properties:
        paymentSampleField:
          type: string
    CreditTransferRequest:
      allOf:
        - $ref: '#/components/schemas/BaseRequest'
        - $ref: '#/components/schemas/Payment'

paths:
  /payment:
    post:
      tags:
        - payment-service
      operationId: postCreditTransfer
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CreditTransferRequest'
      responses:
        '200':
          description: ok

By using

<configuration>
  <generateModelTests>false</generateModelTests>
  <generateApiTests>false</generateApiTests>
  <generateSupportingFiles>false</generateSupportingFiles>
  <inputSpec>${project.build.directory}/classes/sample.yaml</inputSpec>
  <skipValidateSpec>true</skipValidateSpec>
  <generatorName>jaxrs-spec</generatorName>
  <output>${project.build.directory}/generated-sources</output>
  <configOptions>
    <sourceFolder>java</sourceFolder>
    <apiPackage>${api.package}</apiPackage>
    <modelPackage>${model.package}</modelPackage>
    <useGenericResponse>true</useGenericResponse>
    <useBeanValidation>false</useBeanValidation>
    <interfaceOnly>true</interfaceOnly>
    <serializableModel>true</serializableModel>
  </configOptions>
</configuration>

the interface generated is

...
public interface PaymentApi
...

By using

<configuration>
  <generateModelTests>false</generateModelTests>
  <generateApiTests>false</generateApiTests>
  <generateSupportingFiles>false</generateSupportingFiles>
  <inputSpec>${project.build.directory}/classes/sample.yaml</inputSpec>
  <skipValidateSpec>true</skipValidateSpec>
  <generatorName>jaxrs-cxf</generatorName>
  <output>${project.build.directory}/generated-sources</output>
  <configOptions>
    <sourceFolder>java</sourceFolder>
    <apiPackage>${api.package}</apiPackage>
    <modelPackage>${model.package}</modelPackage>
    <useGenericResponse>true</useGenericResponse>
    <useBeanValidation>false</useBeanValidation>
    <serializableModel>true</serializableModel>
  </configOptions>
</configuration>

the interface generated is

...
public interface PaymentServiceApi
...

I experimented a bit and found out that jaxrs-spec is using the path for generate the interface name.
This is different to jaxrs-cxf where the tags part is used.

I think this kind of incompatiblity makes hard to change between the 2 generators.
I suggest they should generate the interface name similar way or at least there should be an option with one could directly set a name.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by comparing interface-name generation in the jaxrs-spec and jaxrs-cxf generators using the supplied OpenAPI example, especially their treatment of the path and tags. Trace the relevant generator entry points and existing generator tests; done means both generators produce the same interface name or expose a documented naming option.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, openapi
Domain
api, devtools
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.