TongchengOpenSource / smart-doc

Smart-doc is a java restful api document generation tool. Smart-doc is based on interface source code analysis to generate interface documentation, completely zero-injection.
https://smart-doc-group.github.io/#/
Apache License 2.0
1.42k stars 278 forks source link

Under JDK 17, generating SSE long-connection interfaces results in an error. #615

Closed 129duckflew closed 1 year ago

129duckflew commented 1 year ago

Your Environment(您的使用环境)

JDK17,SpringBoot 2.5.3

Expected Behavior(您期望的结果)

Normally parse the SSE interface and generate documentation. 正常解析SSE 接口并且生成文档

Current Behavior(当前结果)

[ERROR] 
java.lang.reflect.InaccessibleObjectException: Unable to make field private transient java.lang.Object java.lang.Throwable.backtrace accessible: module java.base does not "opens java.lang" to unnamed module @176b4e21
    at java.lang.reflect.AccessibleObject.checkCanSetAccessible (AccessibleObject.java:354)
    at java.lang.reflect.AccessibleObject.checkCanSetAccessible (AccessibleObject.java:297)
    at java.lang.reflect.Field.checkCanSetAccessible (Field.java:178)
    at java.lang.reflect.Field.setAccessible (Field.java:172)
    at com.power.doc.utils.JavaClassUtil.getFieldGenericType (JavaClassUtil.java:783)
    at com.power.doc.utils.JavaClassUtil.getFields (JavaClassUtil.java:241)
    at com.power.doc.utils.JavaClassUtil.getFields (JavaClassUtil.java:66)
    at com.power.doc.builder.ProjectDocConfigBuilder.getClassByName (ProjectDocConfigBuilder.java:156)
    at com.power.doc.helper.JsonBuildHelper.buildJson (JsonBuildHelper.java:166)
    at com.power.doc.helper.JsonBuildHelper.buildJson (JsonBuildHelper.java:442)
    at com.power.doc.helper.JsonBuildHelper.buildReturnJson (JsonBuildHelper.java:123)
    at com.power.doc.template.IRestDocTemplate.buildEntryPointMethod (IRestDocTemplate.java:441)
    at com.power.doc.template.IRestDocTemplate.processApiData (IRestDocTemplate.java:66)
    at com.power.doc.template.SpringBootDocBuildTemplate.getApiData (SpringBootDocBuildTemplate.java:54)
    at com.power.doc.builder.HtmlApiDocBuilder.buildApiDoc (HtmlApiDocBuilder.java:89)
    at com.smartdoc.mojo.HtmlMojo.executeMojo (HtmlMojo.java:48)
    at com.smartdoc.mojo.BaseDocsGeneratorMojo.execute (BaseDocsGeneratorMojo.java:165)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:126)
    at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute2 (MojoExecutor.java:328)
    at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute (MojoExecutor.java:316)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:212)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:174)
    at org.apache.maven.lifecycle.internal.MojoExecutor.access$000 (MojoExecutor.java:75)
    at org.apache.maven.lifecycle.internal.MojoExecutor$1.run (MojoExecutor.java:162)
    at org.apache.maven.plugin.DefaultMojosExecutionStrategy.execute (DefaultMojosExecutionStrategy.java:39)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:159)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:105)

Possible Solution(bug解决建议)

Steps to Reproduce (Bug产生步骤,请尽量提供用例代码)

  1. Introduce the Spring Boot Web Starter
  2. Write a controller to handle SSE requests

    /**
    * 长连接接口
    */
    @RestController
    @RequestMapping("/sse")
    @Slf4j
    public class SSEController {
    
    public static Map<Integer,SseEmitter> sseMap=new ConcurrentHashMap<>();
    
    /**
     * 获取报警状态的长连接
     * @apiNote 超时时间一小时,结束后SSE会自动重新连接
     */
    @GetMapping("/notify")
    public SseEmitter alarm(String userId) throws IOException {
        SseEmitter sse = sseMap.get(userId);
        if (sse==null){
            sse=new SseEmitter(3600_000L);
            sse.onTimeout(()->{
                sseMap.remove(userId);
            });
            sse.onCompletion(()->{
                log.info("alarm sse complete! userId={}",userId);
            });
            sseMap.put(userId,sse);
        }
        return sse;
    }
    }
  3. smart-doc configuration
    {
    "outPath": "src/main/resources/static/doc",
    "allInOne": true,
    "serverUrl": "http://127.0.0.1:8090",
    "createDebugPage": true,
    "style": "xt256",
    "requestHeaders": [{
    "name": "satoken",
    "type": "string",
    "desc": "登录返回的Token",
    "value":"ba3b16108ac349bf8af21cb12ef897d0",
    "required": true,
    "pathPatterns": "/**",
    "excludePathPatterns":"/login"
    }]
    }
  4. maven configuration
    <build>
    <pluginManagement>
      <plugins>
        <plugin>
          <groupId>com.github.shalousun</groupId>
          <artifactId>smart-doc-maven-plugin</artifactId>
          <version>2.7.7</version>
          <configuration>
            <!--指定生成文档的使用的配置文件-->
            <configFile>${basedir}/src/main/resources/smart-doc.json</configFile>
            <!--指定项目名称-->
            <projectName>test</projectName>
          </configuration>
          <executions>
            <execution>
              <phase>compile</phase>
              <goals>
                <goal>html</goal>
              </goals>
            </execution>
          </executions>
        </plugin>
        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-compiler-plugin</artifactId>
          <version>3.11.0</version>
          <configuration>
            <source>17</source>
            <target>17</target>
          </configuration>
        </plugin>
      </plugins>
    </pluginManagement>
    </build>
  5. mvn install -DskipTests

Context(Bug影响描述)

Failed to generate the documentation.

abing22333 commented 1 year ago

In the process of solving and fixing.

abing22333 commented 1 year ago

619