swagger-api / swagger-api/swagger-core

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

Open
#4,696 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

backlog
Dominant language
Java
Stars
7.5k
Forks
2.3k
Avg merge
18h 1m
Merged PRs (30d)
10

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the Java record example with @JsonUnwrapped and @Schema(implementation = ResourcePath.class), then inspect the generated openapi.yaml. Compare schema generation with and without implementation and verify that the completed result inlines resourceType and resourcePath under Car instead of emitting a resource $ref.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
api, backend-api-design
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.