swagger-core icon indicating copy to clipboard operation
swagger-core copied to clipboard

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

Open Jouramie opened this issue 1 year ago • 2 comments

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

Jouramie avatar Jun 12 '24 14:06 Jouramie

Added resolve(t, context, Collections.emptyIterator()) just before the handleUnwrapped(...) call (ModelResolver:710) to properly process @JsonUnwrapped in my project.

image001_resized

jayChrono avatar Sep 27 '24 13:09 jayChrono

I’m experiencing this issue too. I can’t believe it’s been open for so long without any help to resolve it.

ksmrp avatar Feb 08 '25 06:02 ksmrp