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 using the @GetMapping("/path/{para}") annotation to pass parameters, the generated HTML reports an error during interface debugging. #103

Closed
NeverKnowsTomorrow opened this issue Apr 11, 2021 · 5 comments
Labels
bug Something isn't working
Milestone

Comments

@NeverKnowsTomorrow
Copy link

NeverKnowsTomorrow commented Apr 11, 2021

Your Environment(您的使用环境)

  • smart-doc version:
  • plugin version (e.g. smart-doc-maven-plugin or smart-doc-gradle-plugin): 2.1.2
  • build tool version(maven or gradle): maven

Expected Behavior(您期望的结果)

Current Behavior(当前结果)

The generated HTML API documentation throws an error during interface debugging.

API response result:

{
    "timestamp": "2021-04-11T04:09:30.834+00:00",
    "status": 400,
    "error": "Bad Request",
    "trace": "org.springframework.web.method.annotation.MethodArgumentTypeMismatchException: Failed to convert value of type 'java.lang.String' to required type 'java.lang.Integer'; nested exception is java.lang.NumberFormatException: For input string: \"{rootCatId}\"\r\n\tat org.springframework.web.method.annotation.AbstractNamedValueMethodArgumentResolver.resolveArgument(AbstractNamedValueMethodArgumentResolver.java:133)\r\n\tat org.springframework.web.method.support.HandlerMethodArgumentResolverComposite.resolveArgument(HandlerMethodArgumentResolverComposite.java:121)\r\n\tat org.springframework.web.method.support.InvocableHandlerMethod.getMethodArgumentValues(InvocableHandlerMethod.java:167)\r\n\tat org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:134)\r\n\tat org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:105)\r\n\tat org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:879)\r\n\tat org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:793)\r\n\tat org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87)\r\n\tat org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1040)\r\n\tat org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:943)\r\n\tat org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006)\r\n\tat org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:898)\r\n\tat javax.servlet.http.HttpServlet.service(HttpServlet.java:634)\r\n\tat org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:883)\r\n\tat javax.servlet.http.HttpServlet.service(HttpServlet.java:741)\r\n\tat org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)\r\n\tat org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)\r\n\tat org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)\r\n\tat org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)\r\n\tat org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)\r\n\tat org.springframework.web.filter.CorsFilter.doFilterInternal(CorsFilter.java:92)\r\n\tat org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)\r\n\tat org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)\r\n\tat org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)\r\n\tat org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:100)\r\n\tat org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)\r\n\tat org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)\r\n\tat org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)\r\n\tat org.springframework.web.filter.FormContentFilter.doFilterInternal(FormContentFilter.java:93)\r\n\tat org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)\r\n\tat org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)\r\n\tat org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)\r\n\tat org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:201)\r\n\tat org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)\r\n\tat org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)\r\n\tat org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)\r\n\tat org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:202)\r\n\tat org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)\r\n\tat org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:541)\r\n\tat org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:139)\r\n\tat org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)\r\n\tat org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74)\r\n\tat org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343)\r\n\tat org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:373)\r\n\tat org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65)\r\n\tat org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:868)\r\n\tat org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1590)\r\n\tat org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)\r\n\tat java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)\r\n\tat java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)\r\n\tat org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)\r\n\tat java.base/java.lang.Thread.run(Thread.java:834)\r\nCaused by: java.lang.NumberFormatException: For input string: \"{rootCatId}\"\r\n\tat java.base/java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)\r\n\tat java.base/java.lang.Integer.parseInt(Integer.java:652)\r\n\tat java.base/java.lang.Integer.valueOf(Integer.java:983)\r\n\tat org.springframework.util.NumberUtils.parseNumber(NumberUtils.java:211)\r\n\tat org.springframework.beans.propertyeditors.CustomNumberEditor.setAsText(CustomNumberEditor.java:115)\r\n\tat org.springframework.beans.TypeConverterDelegate.doConvertTextValue(TypeConverterDelegate.java:429)\r\n\tat org.springframework.beans.TypeConverterDelegate.doConvertValue(TypeConverterDelegate.java:402)\r\n\tat org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:155)\r\n\tat org.springframework.beans.TypeConverterSupport.convertIfNecessary(TypeConverterSupport.java:73)\r\n\tat org.springframework.beans.TypeConverterSupport.convertIfNecessary(TypeConverterSupport.java:53)\r\n\tat org.springframework.validation.DataBinder.convertIfNecessary(DataBinder.java:693)\r\n\tat org.springframework.web.method.annotation.AbstractNamedValueMethodArgumentResolver.resolveArgument(AbstractNamedValueMethodArgumentResolver.java:125)\r\n\t... 51 more\r\n",
    "message": "Failed to convert value of type 'java.lang.String' to required type 'java.lang.Integer'; nested exception is java.lang.NumberFormatException: For input string: \"{rootCatId}\"",
    "path": "/index/subCat/%7BrootCatId%7D"
}

Possible Solution(bug解决建议)

Sure, here is the translation to English:

Steps to Reproduce (Bug Generation Steps, please try to provide test case code)

  1. In smart-doc.json, set the parameter "requestFieldToUnderline" to true.
  2. The Controller uses the annotation @GetMapping("/path/{para}" ) to pass parameters.
  3. Click on Send Request in the generated HTML interface documentation to request the interface.

Context (Description of how the bug affects you)

It has been verified that there is no problem when the parameter "requestFieldToUnderline" is set to false.

@NeverKnowsTomorrow NeverKnowsTomorrow added the bug Something isn't working label Apr 11, 2021
@shalousun
Copy link
Collaborator

shalousun commented Apr 11, 2021

@NeverKnowsTomorrow Does the requestFieldToUnderline require conversion for regular parameters?

@NeverKnowsTomorrow
Copy link
Author

NeverKnowsTomorrow commented Apr 11, 2021

@shalousun, I didn't quite understand your point. Could you please describe it in more detail?

@shalousun
Copy link
Collaborator

shalousun commented Apr 11, 2021

@NeverKnowsTomorrow, the question is whether simple types like String and Integer on the controller need to be converted to underscore format.

@hetylei
Copy link

hetylei commented Jan 14, 2022

@shalousun, does the test support path parameters?

For example:

/**
 * Log query test GET path parameter
 * @param testData Test path parameter
 * @return
 * Pagination query result object
 */
@GetMapping("/list/{testData}")
public TableDataInfo<SysOperLog> listTest(
        @PathVariable String testData)
{
    logger.info("pathVar:{}", testData);
    startPage();
    List<SysOperLog> list = operLogService.selectOperLogList(null);
    return getDataTable(list);
}

In the generated documentation test, there are no path parameters, that is, the parameters declared by PathVariable are ignored.

8.2. Log Query Test GET Path Parameter
URL: http://localhost:19201/operlog/list/{testData}

Type: GET

Author: ruoyi

Content-Type: application/x-www-form-urlencoded;charset=utf-8

Description: Log query test GET path parameter
                                                          <-- No Query-parameters generated here:
Response-fields:

I am using version 2.3.6.

<plugin>
                <groupId>com.github.shalousun</groupId>
                <artifactId>smart-doc-maven-plugin</artifactId>
                <version>2.3.6</version>
                <configuration>
                    <!--Specify the configuration file used for generating the document, the configuration file is placed in your own project-->
                    <configFile>./src/main/resources/smart-doc.json</configFile>
                    <!--Specify the project name-->
                    <projectName>Test</projectName>
                    <!--Smart-doc can automatically analyze the dependency tree to load the source code of third-party dependencies, if some framework dependency libraries cannot be loaded and cause errors, use excludes to exclude them-->
                    <excludes>
                        <!--Format: groupId:artifactId; refer to the following-->
                        <!--Regular expressions are also supported, such as: com.alibaba:.* -->
                        <exclude>com.alibaba:fastjson</exclude>
                    </excludes>
                    <!--The includes configuration is used to configure the loading of external dependency source code, after configuration, the plugin will load the external source code according to the configuration items instead of automatically loading all dependencies, so pay attention when using-->
                    <!--Smart-doc can automatically analyze the dependency tree and load all dependent source codes, in principle, it will affect the efficiency of document construction, so you can use includes to let the plugin load the components you configure-->
                    <includes>
                        <!--Format: groupId:artifactId; refer to the following-->
                        <!--Regular expressions are also supported, such as: com.alibaba:.* -->
                        <include>com.alibaba:fastjson</include>
                    </includes>
                </configuration>
                <executions>
                    <execution>
                        <!--If you do not need to start smart-doc when compiling, then comment out the phase-->
                        <phase>compile</phase>
                        <goals>
                            <!--Smart-doc provides goals such as html, openapi, markdown, etc., which can be configured as needed-->
                            <goal>html</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

The configuration file is as follows:

 {
  "serverUrl": "http://localhost:19201",
  "pathPrefix": "",
  "allInOne": true,
  "outPath": "./src/main/resources/static/doc",
  "createDebugPage": true,
  "style":"xt256",
  "projectName": "ruoyi-doc",
  "framework": "spring",
  "requestFieldToUnderline":true,
  "responseFieldToUnderline":true,
  "inlineEnum":true,
  "recursionLimit":7,
  "allInOneDocFileName":"index.html",
  "requestExample":"true",
  "responseExample":"true",
  "displayActualType":true,
  "ignoreRequestParams":[
    "org.springframework.ui.ModelMap"
  ],
  "requestParamsTable": true,
  "responseParamsTable": true
}

Because the test parameters are not listed in the editable request parameters, the path parameters in the test request are not replaced, so the request address directly becomes xxx/xxx/{paramter}, which will reproduce the problem encountered by the person who posted the question originally

@shalousun
Copy link
Collaborator

shalousun commented Feb 25, 2023

@NeverKnowsTomorrow @hetylei Path parameters are not converted; essentially, they are just placeholders.

@shalousun shalousun added this to the 2.6.5 milestone Feb 25, 2023
shalousun added a commit that referenced this issue Feb 25, 2023
@shalousun shalousun changed the title 使用 @GetMapping("/path/{para}" ) 形式的注解传参时,生成的 HTML 在接口调试时报错 When using the @GetMapping("/path/{para}") annotation to pass parameters, the generated HTML reports an error during interface debugging. Jul 3, 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