Skip to content

Schema Generic Type Issue of Generated Response #2433

@cloudlessa

Description

@cloudlessa

To Reproduce
Steps to reproduce the behavior:

  • Currently using spring boot 2.7.12 with Java 8
  • springdoc-openapi-ui version 1.7.0

No generic symbols are added to $ref in the schema of the generated response type::

"responses" : {
"200" : {
"description" : "OK",
"content" : {
"/" : {
"schema" : {
"$ref" : "#/components/schemas/AjaxResultUserEntity"
}
}
}
}
}

Can this return something like AjaxResult«UserEntity»? Like Springfox's response, it will add something like "« »" to form the response schema's 'AjaxResult«UserEntity»'

but I looked at the source code of springdoc, and there is a code in it:

image the method of nameForGenericType :

//This is directly splicing the parameters to the back.
generic.append(WordUtils.capitalize(argName))
Can add a generic symbol to distinguish the type?

Test Class

@Tag(name = "userManage")
@RestController
@RequestMapping("/test")
public class TestController {
    @Operation(summary = "getUser")
    @GetMapping("/getUser")
    public AjaxResult<UserEntity> getUser()
    {
        UserEntity user = new UserEntity(1, "test", "test", "xxxxx");
        return AjaxResult.success(user);
    }
}
//entityClass
@Schema(name = "UserEntity", description = "UserEntity")
class UserEntity
{
    @Schema(description = "userId")
    private Integer userId;

    @Schema(description = "username")
    private String username;

    @Schema(description = "password")
    private String password;

    @Schema(description = "mobile")
    private String mobile;
 
   public Integer getUserId()
    {
        return userId;
    }

    public void setUserId(Integer userId)
    {
        this.userId = userId;
    }

    public String getUsername()
    {
        return username;
    }

    public void setUsername(String username)
    {
        this.username = username;
    }

    public String getPassword()
    {
        return password;
    }

    public void setPassword(String password)
    {
        this.password = password;
    }

    public String getMobile()
    {
        return mobile;
    }

    public void setMobile(String mobile)
    {
        this.mobile = mobile;
    }
//ResponseClass
public class AjaxResult<T> {
    private int code;
    private String msg;
    private T data;
    private static <T> AjaxResult<T> restResult(int code, String msg, T data) {
        AjaxResult<T> apiResult = new AjaxResult<>();
        apiResult.setCode(code);
        apiResult.setData(data);
        apiResult.setMsg(msg);
        return apiResult;
    }
 public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }
image

This causes swagger-ui to return this type. It cannot be seen that this is a generic return type.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions