-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Description
When an API returns a generic response type swagger-core:
- The swagger-core generated object name is not linked to the API definition response.
- Does not provide a means to customize the name of the returned object.
Example:
ResponseBody<List> getTeamMemberNames(Long teamId);
Swagger-core generates:
schema object: ResponseBodyListString (not a name we would want to expose)
"ResponseBodyListString" : {
"type" : "object",
"properties" : {
"data" : {
"type" : "array",
"items" : {
"type" : "string"
}
}
}
},
API definition:
"/team/membernames" : {
"get" : {
"operationId" : "getTeamMemberNames",
"parameters" : [ {
"name" : "teamId",
"in" : "path",
"required" : true,
"schema" : {
"type" : "integer",
"format" : "int64"
}
} ],
"responses" : {
"200" : {
"description" : "OK",
"content" : {
"application/json" : {
"schema" : {
"$ref" : "#/components/schemas/ResponseBody"
}
}
}
},
}
}
},
You can see above, that the API definition response returns "ResponseBody" the name of the generic class. Rather than the generated ResponseBodyListString object.
Current workaround: We define a custom "doc" class and use that in the Operation annotation.
This requires the doc class and the actual implementation are kept in-sync.
@Operation(summary = "Gets team member names",
description = "Gets list of team member names.",
responses = {
@ApiResponse(responseCode = "200", description = "OK",
content = @Content(schema = @Schema(implementation = TeamMemberNamesResponse.class))),
})