Skip to content

Wrong schema mapping with super class #310

Closed
@rodrigoords

Description

@rodrigoords

When I have a class that extends from a superclass the springdoc open api don't create swagger ui correctly, it only maps the superclass attributes.

example:
super class:

@MappedSuperclass
@EntityListeners(AuditingEntityListener.class)
public abstract class BaseModel implements Persistable<Long> {

  @Override
  public abstract Long getId();

  public abstract void setId(Long id);

  @Column(name = "created_date")
  @CreatedDate
  @JsonSerialize(using = ToStringSerializer.class)
  private LocalDateTime createdDate;

  @Column(name = "last_modified_date")
  @LastModifiedDate
  @JsonSerialize(using = ToStringSerializer.class)
  private LocalDateTime lastModifiedDate;

  @Override
  @JsonIgnore
  public boolean isNew() {
    return Objects.isNull(this.getId());
  }

  public LocalDateTime getCreatedDate() {
    return createdDate;
  }

  public void setCreatedDate(LocalDateTime createdDate) {
    this.createdDate = createdDate;
  }

  public LocalDateTime getLastModifiedDate() {
    return lastModifiedDate;
  }

  public void setLastModifiedDate(LocalDateTime lastModifiedDate) {
    this.lastModifiedDate = lastModifiedDate;
  }
}

Child class:

@Table(name = "companies")
@Entity
@AllArgsConstructor
@NoArgsConstructor
@Builder
@Data
public class Company extends BaseModel {

  @Id
  @GeneratedValue(strategy = GenerationType.IDENTITY)
  private Long id;

  @Column
  private String name;

  @NotNull
  @OneToOne(cascade = CascadeType.ALL)
  @JoinColumn(name = "address_id")
  private Address address;

  @Column
  private String cnpj;
}

Result on /v3/api-docs, all schemas are referencing to baseModel

"/companies": {
    "get": {
        "tags": [
            "company-controller"
        ],
        "operationId": "findPages_1",
        "parameters": [
            {
                "name": "pageable",
                "in": "query",
                "required": true,
                "schema": {
                    "required": [
                        "page",
                        "size"
                    ],
                    "type": "object",
                    "properties": {
                        "page": {
                            "minimum": 0,
                            "type": "integer",
                            "format": "int32"
                        },
                        "size": {
                            "maximum": 2000,
                            "minimum": 1,
                            "type": "integer",
                            "format": "int32"
                        },
                        "sort": {
                            "type": "array",
                            "items": {
                                "type": "string"
                            }
                        }
                    }
                }
            }
        ],
        "responses": {
            "200": {
                "description": "default response",
                "content": {
                    "*/*": {
                        "schema": {
                            "$ref": "#/components/schemas/PageBaseModel"
                        }
                    }
                }
            }
        }
    },
    "post": {
        "tags": [
            "company-controller"
        ],
        "operationId": "save_1",
        "requestBody": {
            "content": {
                "application/json": {
                    "schema": {
                        "$ref": "#/components/schemas/BaseModel"
                    }
                }
            }
        },
        "responses": {
            "201": {
                "description": "default response",
                "content": {
                    "*/*": {
                        "schema": {
                            "$ref": "#/components/schemas/BaseModel"
                        }
                    }
                }
            }
        }
    }
}

Schemas:
Company does not list as a schema.

version:

<dependency>
    <groupId>org.springdoc</groupId>
    <artifactId>springdoc-openapi-ui</artifactId>
    <version>1.2.21</version>
</dependency>

<dependency>
    <groupId>org.springdoc</groupId>
    <artifactId>springdoc-openapi-security</artifactId>
    <version>1.2.21</version>
</dependency>

<dependency>
    <groupId>org.springdoc</groupId>
    <artifactId>springdoc-openapi-data-rest</artifactId>
    <version>1.2.21</version>
</dependency>

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions