swagger-api / swagger-api/swagger-core
Swagger does not serializes Generic Objects in API response completely.
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 7.5k
- Forks
- 2.3k
- Avg merge
- 18h 1m
- Merged PRs (30d)
- 10
Description
We have over 200 APIs on Jersey (Non-Spring tech stack). We have integrated swagger and are now writing annotations.
The entities/pojos returned by our APIs are all wrapped inside a common structure using Generics.
public ApiCallResponse<User> users(){...}
public ApiCallResponse<Address> addresses {...}
public ApiCallResponse<Liability> addresses {...}
The swagger auto scan only detects ApiCallResponse object. It does not serializes User, Address or Liability for serialization.
I am working around this by creating separate classes for each of them as follows.
@Schema
public class ApiCallResponseUser extends ApiCallResponse<User> {
}
@Schema
public class ApiCallResponseAddress extends ApiCallResponse<Address> {
}
@Schema
public class ApiCallResponseAddress extends ApiCallResponse<Liability> {
}
and use them as follows
@ApiResponse(
responseCode = "200",
description = " Blah.",
content = @Content(mediaType = "application/json",
schema = @Schema(
name = "Blah",
implementation = ApiCallResponseUser.class
)
)
),
It would be really nice, if swagger while auto scanning, auto creates those classes internally and includes them in the generated json.
This will save me from creating so many classes and configuring them to exclude from code coverage.
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 Jersey API responses using the generic ApiCallResponse, ApiCallResponse
, and ApiCallResponse examples from the issue. Trace the Swagger auto-scan behavior and verify that the generated JSON includes schemas for each generic type without requiring wrapper classes such as ApiCallResponseUser.Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- api, backend
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100