Skip to content

[BUG][JAVA] generated class tries to extend instead of implement Serializable interface #16240

@PhraseTomasVich

Description

@PhraseTomasVich

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • 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

Following OpenAPI v3 YAML schema definition generates non-compilable code.

Generated class extends abstract class AbstractOpenApiSchema but then it also tries to extend (instead of implement) Serializable interface.

@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen", date = "2023-08-02T14:31:16.003353100")
public class ReferencesCondition extends AbstractOpenApiSchema, Serializable {
...
}
openapi-generator version

org.openapitools:openapi-generator-gradle-plugin:6.6.0
with Java 1.8

OpenAPI declaration file content or url
openapi: 3.0.1
info:
  title: Test
  version: 0.0.1
paths:
  /api/some_api:
    get:
      operationId: someApi
      responses:
        "200":
          description: OK
          content:
            '*/*':
              schema:
                $ref: '#/components/schemas/ReferencesCondition'
components:
  schemas:
    ReferencesCondition:
      type: object
      oneOf:
        - $ref: '#/components/schemas/JobCondition'
        - $ref: '#/components/schemas/TaskCondition'
    JobCondition:
      type: object
      properties:
        jobId:
          type: string
    TaskCondition:
      type: object
      properties:
        taskId:
          type: string
x-build-time: 2023-08-02T11:35:52.647Z
Generation Details
task buildSomeJavaClient(type: org.openapitools.generator.gradle.plugin.tasks.GenerateTask) {
    generatorName = "java"
    inputSpec = "$projectDir/src/main/resources/some.yaml".toString()
    outputDir = "$buildDir/generated/sources/some-client".toString()
    templateDir = "$projectDir/codegen/Java".toString()

    groupId = project.group
    id = "$project.name-some-client"
    version = project.version
    apiPackage = 'com.some.api'
    invokerPackage = 'com.some.api.invoker'
    modelPackage = 'com.some.api.model'
    skipOverwrite = false

    configOptions = [
            dateLibrary                             : 'java8',
            disallowAdditionalPropertiesIfNotPresent: 'false',
            serializableModel                       : 'true'
    ]
}
compileJava.dependsOn tasks.buildSomeJavaClient
sourceSets.main.java.srcDirs += "$buildDir/generated/sources/some-client/src/main/java"
Steps to reproduce

Generate the client, try to build with it.

Related issues/PRs
Suggest a fix

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions