swagger-api / swagger-core

Examples and server integrations for generating the Swagger API Specification, which enables easy access to your REST API
http://swagger.io
Apache License 2.0
7.36k stars 2.17k forks source link

Using @JsonUnwrapped with @Schema(implementation = Something) does not unwrap #4696

Open Jouramie opened 2 weeks ago

Jouramie commented 2 weeks ago

Hi, I have an object like

public record Car(String model, @JsonUnwrapped @Schema(implementation=ResourcePath.class) Resource resource, boolean selected) {
}

public abstract class Resource {
}

public abstract class ResourcePath extend Resource {

  public String resourcePath;

  public String resourceType;

}

Resource is an abstract class, and does not contain all the fields present in ResourcePath. However, Jackson picks up all the fields and still unwrap them with @JsonUnwrapped.

The moment I specify an implementation in @Schema, resource stop being unwrapped in the openapi.yaml.

Expected

 Car:
  type: object
  properties:
    model:
      type: string
    resourceType:
      type: string
    resourcePath:
      type: string
    selected:
      type: boolean

Result

ResourcePath:
  type: object
  properties:
    resourceType:
      type: string
    resourcePath:
      type: string

Car:
  type: object
  properties:
    model:
      type: string
    resource:
      $ref: "#/components/schemas/ResourcePath"
    selected:
      type: boolean