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

Nested generics seem to have some issues with support. #575

Closed
HengCC opened this issue Aug 21, 2023 · 6 comments
Closed

Nested generics seem to have some issues with support. #575

HengCC opened this issue Aug 21, 2023 · 6 comments
Labels
bug Something isn't working
Milestone

Comments

@HengCC
Copy link

HengCC commented Aug 21, 2023

The configuration is as follows:

<plugins>
    <plugin>
        <groupId>com.github.shalousun</groupId>
        <artifactId>smart-doc-maven-plugin</artifactId>
        <version>2.7.4</version>
        <configuration>
            <!-- Specifies the configuration file used to generate the documentation, placed within the project -->
            <configFile>smart-doc.json</configFile>
            <!-- Specifies the project name; it's recommended to use dynamic parameters like ${project.description} -->
            <!-- If smart-doc.json and this setting do not specify a projectName, starting from version 2.3.4, the plugin automatically uses the projectName from pom.xml -->
            <projectName>${project.description}</projectName>
            <!-- smart-doc realizes automatic analysis of the dependency tree to load source code from third-party dependencies; if some framework libraries can't be loaded causing errors, exclude them here -->
            <excludes>
                <!-- Format is groupId:artifactId; see example below -->
                <!-- Regex is also supported, e.g., com.alibaba:.* -->
                <!--<exclude>com.alibaba:fastjson</exclude>-->
            </excludes>
            <!-- The includes configuration is used to configure loading of external dependency source code; after configuration, the plugin will load the specified components instead of automatically loading all, so caution is needed when using -->
            <!-- smart-doc can automatically analyze the dependency tree to load all dependent source code, which may affect documentation build efficiency; thus, you can use includes to make the plugin load your configured components -->
            <includes>
                <!-- Format is groupId:artifactId; see example -->
                <!-- Regex is also supported, e.g., com.alibaba:.* -->
                <!-- If includes are configured and JPA pagination is used, include the source code package used -->
                <include>org.springframework.data:spring-data-commons.*</include>
                <include>com.fasterxml.jackson:.*</include>
            </includes>
        </configuration>
        <executions>
            <!-- Uncomment the phase if smart-doc does not need to start during compilation -->
            <execution>
                <phase>compile</phase>
                <goals>
                    <!-- smart-doc provides goals such as html, openapi, markdown, etc., which can be configured as needed -->
                    <goal>markdown</goal>
                </goals>
            </execution>
        </executions>
    </plugin>
</plugins>

The JSON configuration is:

{
  "outPath": "./doc",
  "requestFieldToUnderline": false,
  "responseFieldToUnderline": false,
  "allInOne": "false",
  "coverOld": true,
  "displayActualType": true
}

The Controller is defined as:

@GetMapping(value = "/page")
public ResultDTO<Page<ContractDeductDTO>> page(@RequestParam String type, Pageable pageable) {
    return ResultDTO.success(demoService.page(type, pageable));
}

The ResultDTO is structured as:

@NoArgsConstructor
@AllArgsConstructor
@Builder
public class ResultDTO<T> {
    @Builder.Default
    @ApiModelProperty(required = true)
    private Boolean success = true;

    private T data;

    private String message;

    @Builder.Default
    private String code = Constants.CODE_SUCCESS;

    public static <T> ResultDTO<T> success(T data) {
        return ResultDTO.<T>builder().success(true).data(data).build();
    }
}

The generated documentation, however, fails to automatically generate fields and comments for generic DTOs.
image

@HengCC HengCC added the bug Something isn't working label Aug 21, 2023
@shalousun
Copy link
Collaborator

shalousun commented Aug 21, 2023

@HengCC 可以升级2.7.5看下,最好提供下你的page类

@HengCC
Copy link
Author

HengCC commented Aug 21, 2023

Page是JPA的. 默认长这样. 没更改过, 我先试试2.7.5
image


2.7.5运行后还是一样的结果.

@abing22333
Copy link
Contributor

abing22333 commented Aug 21, 2023

初步判断是QDox无法解析出接口中方法返回值的泛型。

@HengCC
Copy link
Author

HengCC commented Aug 22, 2023

@abing22333 换成PageImpl实现类也是一样的.

@abing22333
Copy link
Contributor

@HengCC 是你的配置有问题。没有引入源码,导致解析不出泛型。

  <includes>
      <!--格式为:groupId:artifactId;参考如下-->
      <!--也可以支持正则式如:com.alibaba:.* -->
      <!-- 如果配置了includes的情况下, 使用了jpa的分页需要include所使用的源码包 -->
      <include>org.springframework.data:spring-data-commons.*</include>
      <include>com.fasterxml.jackson:.*</include>
  </includes>

你include了 spring-data-commmons 依赖,还需要显示定义一次。smart-doc不会自动解析依赖中的依赖。

    <dependency>
      <groupId>org.springframework.data</groupId>
      <artifactId>spring-data-commons</artifactId>
    </dependency>

@HengCC
Copy link
Author

HengCC commented Aug 22, 2023

原来还必须在显示的指定依赖在pom中. 加了这个依赖后确实生成出来就没问题了. .thks~

@HengCC HengCC closed this as completed Aug 22, 2023
@shalousun shalousun added this to the 2.7.6 milestone Sep 2, 2023
@shalousun shalousun changed the title 嵌套泛型似乎支持有问题 Nested generics seem to have some issues with support. May 22, 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

3 participants