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.

Home Page:https://smart-doc-group.github.io/#/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to ignore a common header field on method

baboy opened this issue · comments

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

If configure requestHeaders in smart-doc.json like this:

...
"requestHeaders": [
    {
      "name": "x-region-code",
      "type": "string",
      "desc": "区域编码",
      "value": "",
      "required": true,
      "since": "-",
      "pathPatterns": "/api/**",
      "excludePathPatterns": "**/region/**"
    },...
]...

it will add "x-region-code" header to all of the requests, but some requests need to ignore this header. how should I do to achieve it?
Shall we add ignoreHeader comment annotation to fix this or if there is an another solution?

 /**
     * 获取eip类型
     * @ignoreHeader x-region-code
     */
    @RequestMapping(path = "/searchType", method = RequestMethod.GET)
    public HttpResponse<List<xxx>> searchType() {

@baboy In smart-doc, we fully reference the filtering method of spring filter for pathPatterns and excludePathPatterns. The main purpose of using pathPatterns and excludePathPatterns is to set the correct regular expressions. The priority of excludePathPatterns is higher than that of pathPatterns, and it is recommended to use them separately. The more accurate the regular expression, the better. In smart-doc, it is not recommended to add custom tags at will, and it is suggested to add them only when there are no other alternative methods. In your scenario, it is recommended to optimize the expression configuration of excludePathPatterns. In addition, both pathPatterns and excludePathPatterns support multiple expressions.

@baboy In smart-doc, we fully reference the filtering method of spring filter for pathPatterns and excludePathPatterns. The main purpose of using pathPatterns and excludePathPatterns is to set the correct regular expressions. The priority of excludePathPatterns is higher than that of pathPatterns, and it is recommended to use them separately. The more accurate the regular expression, the better. In smart-doc, it is not recommended to add custom tags at will, and it is suggested to add them only when there are no other alternative methods. In your scenario, it is recommended to optimize the expression configuration of excludePathPatterns. In addition, both pathPatterns and excludePathPatterns support multiple expressions.

I understand. but in my case,we defined the api paths with restful style, so the POST request path maybe as same as the GET request path, but sometimes they need different headers. So, both pathPatterns and excludePathPatterns can't solve the problem. if support the http method type configuration to filter out the request, the problem will be resolved.

Thank you very much!

This header can be intercepted in a Spring Boot application using an interceptor, and a similar effect could potentially be used to optimize smart-doc.