Skip to content

[BUG] [JAVA] Property "useOneOfInterfaces" seems to be ignored during generation since version v7.13 #21234

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
5 of 6 tasks
neffets74 opened this issue May 7, 2025 · 4 comments

Comments

@neffets74
Copy link

neffets74 commented May 7, 2025

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description

In my specification I have a "oneOf" relation between two components, a interface ExINterface and a class ExObject1 implementing this interface (see specification snippet below).

When generating the code out of the specification with plugin version 7.12.0 I get the expected result:

public class ExObject1 implements ExInterface

But when generating the code with plugin version 7.13.0, the generated class does not implement the interface:

public class ExObject1

The interface class itself is not even generated.

openapi-generator version

v7.13.0

OpenAPI declaration file content or url
openapi: 3.0.3
info:
    title: Example API
    description: This is an example API specification serving as error reproducer
    version: 1.0.0
paths:
  /example:
    get:
      summary: Example endpoint
      description: This is an example endpoint
      operationId: getExample
      parameters:
        - name: exampleParam
          in: query
          required: true
          description: An example query parameter
          schema:
            type: string
      responses:
        '200':
          description: Successful response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ExInterface'
components:
  schemas:
    ExInterface:
      oneOf:
        - $ref: '#/components/schemas/ExObject1'
    ExObject1:
      type: object
      properties:
        name:
          type: string
          description: The name of the object
Generation Details

Using the following code gen options:

{
  "generatorName": "java",
  "library": "google-api-client",

  "sourceFolder": ".",
  "basePackage": "sk.example.base",
  "configPackage": "sk.example.config",
  "modelPackage": "sk.example.model",
  "apiPackage": "sk.example.client",

  "disallowAdditionalPropertiesIfNotPresent": true,
  "interfaceOnly": true,
  "legacyDiscriminatorBehavior": false,
  "openApiNullable": false,
  "useBeanValidation": true,
  "useEnumCaseInsensitive": true,
  "useJakartaEe": true,
  "useOneOfInterfaces": true,
  "useOptional": false
}
Steps to reproduce

Calling "./gradlew openapiGenerate" and reviewing the generated class "ExObject1".

Related issues/PRs
Suggest a fix
@Mattias-Sehlstedt
Copy link
Contributor

Hi,

This is tied to my fix here #21043. It fixed so that the generator normalization is now working as advertised. If it is of interest to get an interface for a oneOf with a single subSchema, then I would investigate turning off the SIMPLIFY_ONEOF_ANYOF normalization.

@neffets74
Copy link
Author

Thank you for clarification.
Unfortunately, it seems not to be straight forward, to disable the normalization when using the openapi-generator-gradle-plugin.
At least I could not find an according configuration option.

@Mattias-Sehlstedt
Copy link
Contributor

Mattias-Sehlstedt commented May 8, 2025

The settings are documented here, and the plugin usage here. When I have used their suggested structure

Image
It works as expected and it affects the normalizer's behavior.

E.g., something similar to:

openapiNormalizer.set([
  DISABLE_ALL: "true"
])

in your gradle task.

@neffets74
Copy link
Author

Great, it works now as expected. Thank you. I will close the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants