swagger-api / swagger-api/swagger-core
Using @JsonUnwrapped with @Schema(implementation = Something) does not unwrap
Nobody has claimed this yet.
- 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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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