Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When the interface returns a List structure and uses responseBodyAdvice to configure a unified return structure, the document output type is 'array'. #641

Closed
hellomsg opened this issue Oct 20, 2023 · 5 comments
Labels
bug Something isn't working
Milestone

Comments

@hellomsg
Copy link

hellomsg commented Oct 20, 2023

When the interface returns a List structure and uses responseBodyAdvice to configure a unified return structure, the document output type is 'array'.

Your Environment

  • Include as many relevant details about the environment where you experienced the bug.

  • smart-doc version: 2.7.7

  • plugin version (e.g., smart-doc-maven-plugin or smart-doc-gradle-plugin): 2.7.7

  • build tool version (maven or gradle): 3.8.6

  • jdk version: 1.8.0_381

Expected Behavior

If you're describing a bug, tell us what should happen.
If you're suggesting a change/improvement, tell us how it should work.

Current Behavior

If describing a bug, tell us what happens instead of the expected behavior.
If suggesting a change/improvement, explain the difference from current behavior.

In the JSON document generated by smart-doc:swagger, when the interface returns a List, "type": "array". I have configured a unified return structure using responseBodyAdvice, expecting the type to be an object.

Configuration:

"responseBodyAdvice": {
    "className": "com.common.api.CommonResult"
}

Unified return definition:

public class CommonResult<T> {
    /**
     * Status code
     */
    private long code;
    /**
     * Prompt message
     */
    private String message;
    /**
     * Return data
     */
    private T data;
    /**
     * Is successful
     */
    private Boolean success;
}

Interface definition:

/**
 * Get country/region list
 * @return
 */
@GetMapping
public List<Country> list() {
    return countryService.selectAll();
}

Generated swagger document:

"/api/public/countries": {
    "get": {
        "summary": "Get country/region list",
        "deprecated": false,
        "description": "Get country/region list",
        "tags": [
            "Country/Region"
        ],
        "responses": {
            "200": {
                "schema": {
                    "type": "array",
                    "items": {
                        "$ref": "#/definitions/CommonResultListCountry_response"
                    }
                },
                "description": "OK"
            }
        },
        "operationId": "apipubliccountries",
        "parameters": []
    }
},
...
"CommonResultListCountry_response": {
    "properties": {
        "code": {
            "format": "int64",
            "description": "Status code",
            "type": "number",
            "example": "0"
        },
        "message": {
            "format": "string",
            "description": "Prompt message",
            "type": "string",
            "example": ""
        },
        "data": {
            "description": "Return data",
            "type": "array",
            "items": {
                "$ref": "#/definitions/Country_response"
            }
        },
        "success": {
            "format": "boolean",
            "description": "Is successful",
            "type": "boolean",
            "example": "true"
        }
    }
}

Possible Solution

Not obligatory, but suggest a fix/reason for the bug, or ideas on how to implement the addition or change.

Steps to Reproduce

Provide a link to a live example, or an unambiguous set of steps to reproduce this bug. Include code to reproduce if relevant.

@hellomsg hellomsg added the bug Something isn't working label Oct 20, 2023
@shalousun
Copy link
Collaborator

shalousun commented Oct 20, 2023

@hellomsg If interested, you can refer to community co-construction, or help me register users, so that the community can better promote.
如果感兴趣,可以参考社区共建,也可以帮我登记下用户,方便社区更好的推广#12

@hellomsg
Copy link
Author

hellomsg commented Oct 20, 2023

#599
This should be the same issue; let's wait for the 3.0.0 version to go live and then check if it has been fixed.
跟这个应该是一个问题,带3.0.0版上线再看看有没有修复

@hellomsg
Copy link
Author

hellomsg commented Oct 20, 2023

@hellomsg If interested, you can refer to community co-construction, or help me register users, so that the community can better promote.
如果感兴趣,可以参考社区共建,也可以帮我登记下用户,方便社区更好的推广#12

@shalousun 3.0.0
This should be the same issue; let's wait for the 3.0.0 version to go live and then check if it has been fixed.
发布到仓库了吗?只能搜到 com.ly.smart-doc 的。com.github.shalousun 还是 2.7.7

@shalousun
Copy link
Collaborator

shalousun commented Oct 20, 2023

@hellomsg If interested, you can refer to community co-construction, or help me register users, so that the community can better promote.
如果感兴趣,可以参考社区共建,也可以帮我登记下用户,方便社区更好的推广#12

@shalousun This should be the same issue; let's wait for the 3.0.0 version to go live and then check if it has been fixed.
3.0.0 发布到仓库了吗?只能搜到 com.ly.smart-doc 的。com.github.shalousun 还是 2.7.7

The community's group ID has changed.
社区groupId变了

@hellomsg
Copy link
Author

hellomsg commented Oct 20, 2023

This bug has been fixed in version 3.0.0.
这个 bug 3.0.0 修复了。

@shalousun shalousun added this to the 3.0.0 milestone Dec 17, 2023
@shalousun shalousun changed the title 当接口返回List结构,并使用responseBodyAdvice配置统一返回结构时,文档输出类型为array When the interface returns a List structure and uses responseBodyAdvice to configure a unified return structure, the document output type is 'array'. Jun 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants