Skip to content
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

[BUG][Java][Spring] inheritance not working using java/spring generator with multi file opeanpi 3.1.0 spec #18686

Open
5 of 6 tasks
tonketonky opened this issue May 16, 2024 · 0 comments

Comments

@tonketonky
Copy link

tonketonky commented May 16, 2024

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

Composition instead of inheritance is generated when using java/spring generator with openap:i 3.1.0 declaration split into multiple files. With openapi: 3.0.2 it works fine.

openapi-generator version

openapi-generator-maven-plugin:7.5.0

OpenAPI declaration file content or url

openapi.yaml:

openapi: 3.1.0
info:
  title: multi-file-openapi
  version: 1.0.0
servers:
  - url: 'http://localhost:8080/rest'
paths:
  /dummy-path:
    get:
      operationId: getDummy
      responses:
        '200':
          description: Get dummy.
          content:
            application/json:
              schema:
                $ref: './child.yaml'

child.yaml:

title: Child
allOf:
  - $ref: './parent.yaml'
  - properties:
      propB:
        type: string

parent.yaml:

title: Parent
discriminator:
  propertyName: propA
properties:
  propA:
    type: string
required:
  - propA
Generation Details
<plugin>
    <groupId>org.openapitools</groupId>
    <artifactId>openapi-generator-maven-plugin</artifactId>
    <executions>
        <execution>
            <phase>generate-sources</phase>
            <goals>
                <goal>generate</goal>
            </goals>
            <configuration>
                <generatorName>spring</generatorName>
                <inputSpec>${project.basedir}/src/main/resources/openapi-multiple-files/openapi.yaml</inputSpec>
                <output>${project.basedir}</output>
                <generateApis>false</generateApis>
                <generateApiTests>false</generateApiTests>
                <generateApiDocumentation>false</generateApiDocumentation>
                <generateModelTests>false</generateModelTests>
                <generateModelDocumentation>false</generateModelDocumentation>
                <generateSupportingFiles>false</generateSupportingFiles>
                <configOptions>
                    <library>spring-boot</library>
                    <serializableModel>true</serializableModel>
                    <groupId>${project.groupId}</groupId>
                    <artifactId>${project.artifactId}</artifactId>
                    <version>${project.version}</version>
                    <useJakartaEe>true</useJakartaEe>
                </configOptions>
            </configuration>
        </execution>
    </executions>
</plugin>
Steps to reproduce
  1. Generate code using openapi-generator-maven-plugin:7.5.0 and provided openapi declaration file.
Actual behavior (with openapi: 3.1.0)

A single class Child with both propA and propB is generated:

package org.openapitools.model;

import java.net.URI;
import java.util.Objects;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonSubTypes;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import org.openapitools.jackson.nullable.JsonNullable;
import java.time.OffsetDateTime;
import javax.validation.Valid;
import javax.validation.constraints.*;
import io.swagger.v3.oas.annotations.media.Schema;


import java.util.*;
import javax.annotation.Generated;

/**
 * Child
 */


@Generated(value = "org.openapitools.codegen.languages.SpringCodegen", date = "2024-05-16T12:43:04.523358872Z[Etc/UTC]", comments = "Generator version: 7.6.0-SNAPSHOT")
public class Child {

  private String propA;

  private String propB;

  // generated constructor, getters, setters, etc.
}
Expected behavior (as it is with openapi: 3.0.2):

Two classes are generated:

  • Parent class with propA property
package org.openapitools.model;

import java.net.URI;
import java.util.Objects;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonSubTypes;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import com.fasterxml.jackson.annotation.JsonTypeName;
import org.openapitools.jackson.nullable.JsonNullable;
import java.time.OffsetDateTime;
import javax.validation.Valid;
import javax.validation.constraints.*;
import io.swagger.v3.oas.annotations.media.Schema;


import java.util.*;
import javax.annotation.Generated;

/**
 * Parent
 */

@JsonIgnoreProperties(
  value = "propA", // ignore manually set propA, it will be automatically generated by Jackson during serialization
  allowSetters = true // allows the propA to be set during deserialization
)
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "propA", visible = true)
@JsonSubTypes({
  @JsonSubTypes.Type(value = Child.class, name = "child")
})

@Generated(value = "org.openapitools.codegen.languages.SpringCodegen", date = "2024-05-16T13:05:57.171195852Z[Etc/UTC]", comments = "Generator version: 7.6.0-SNAPSHOT")
public class Parent {

  private String propA;

  // generated constructor, getters, setters, etc.
}
  • Child class with propB property, extending Parent class
package org.openapitools.model;

import java.net.URI;
import java.util.Objects;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonSubTypes;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import com.fasterxml.jackson.annotation.JsonTypeName;
import org.openapitools.model.Parent;
import org.openapitools.jackson.nullable.JsonNullable;
import java.time.OffsetDateTime;
import javax.validation.Valid;
import javax.validation.constraints.*;
import io.swagger.v3.oas.annotations.media.Schema;


import java.util.*;
import javax.annotation.Generated;

/**
 * Child
 */


@JsonTypeName("child")
@Generated(value = "org.openapitools.codegen.languages.SpringCodegen", date = "2024-05-16T13:05:57.171195852Z[Etc/UTC]", comments = "Generator version: 7.6.0-SNAPSHOT")
public class Child extends Parent {

  private String propB;

  // generated constructor, getters, setters, etc.
}
Related issues/PRs

N/A

Suggest a fix

N/A

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

1 participant