[
  {
    "path": ".gitignore",
    "content": ".idea\n/*.iml\ntarget/\n"
  },
  {
    "path": "LICENSE",
    "content": "                                 Apache License\n                           Version 2.0, January 2004\n                        http://www.apache.org/licenses/\n\n   TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION\n\n   1. Definitions.\n\n      \"License\" shall mean the terms and conditions for use, reproduction,\n      and distribution as defined by Sections 1 through 9 of this document.\n\n      \"Licensor\" shall mean the copyright owner or entity authorized by\n      the copyright owner that is granting the License.\n\n      \"Legal Entity\" shall mean the union of the acting entity and all\n      other entities that control, are controlled by, or are under common\n      control with that entity. For the purposes of this definition,\n      \"control\" means (i) the power, direct or indirect, to cause the\n      direction or management of such entity, whether by contract or\n      otherwise, or (ii) ownership of fifty percent (50%) or more of the\n      outstanding shares, or (iii) beneficial ownership of such entity.\n\n      \"You\" (or \"Your\") shall mean an individual or Legal Entity\n      exercising permissions granted by this License.\n\n      \"Source\" form shall mean the preferred form for making modifications,\n      including but not limited to software source code, documentation\n      source, and configuration files.\n\n      \"Object\" form shall mean any form resulting from mechanical\n      transformation or translation of a Source form, including but\n      not limited to compiled object code, generated documentation,\n      and conversions to other media types.\n\n      \"Work\" shall mean the work of authorship, whether in Source or\n      Object form, made available under the License, as indicated by a\n      copyright notice that is included in or attached to the work\n      (an example is provided in the Appendix below).\n\n      \"Derivative Works\" shall mean any work, whether in Source or Object\n      form, that is based on (or derived from) the Work and for which the\n      editorial revisions, annotations, elaborations, or other modifications\n      represent, as a whole, an original work of authorship. For the purposes\n      of this License, Derivative Works shall not include works that remain\n      separable from, or merely link (or bind by name) to the interfaces of,\n      the Work and Derivative Works thereof.\n\n      \"Contribution\" shall mean any work of authorship, including\n      the original version of the Work and any modifications or additions\n      to that Work or Derivative Works thereof, that is intentionally\n      submitted to Licensor for inclusion in the Work by the copyright owner\n      or by an individual or Legal Entity authorized to submit on behalf of\n      the copyright owner. For the purposes of this definition, \"submitted\"\n      means any form of electronic, verbal, or written communication sent\n      to the Licensor or its representatives, including but not limited to\n      communication on electronic mailing lists, source code control systems,\n      and issue tracking systems that are managed by, or on behalf of, the\n      Licensor for the purpose of discussing and improving the Work, but\n      excluding communication that is conspicuously marked or otherwise\n      designated in writing by the copyright owner as \"Not a Contribution.\"\n\n      \"Contributor\" shall mean Licensor and any individual or Legal Entity\n      on behalf of whom a Contribution has been received by Licensor and\n      subsequently incorporated within the Work.\n\n   2. Grant of Copyright License. Subject to the terms and conditions of\n      this License, each Contributor hereby grants to You a perpetual,\n      worldwide, non-exclusive, no-charge, royalty-free, irrevocable\n      copyright license to reproduce, prepare Derivative Works of,\n      publicly display, publicly perform, sublicense, and distribute the\n      Work and such Derivative Works in Source or Object form.\n\n   3. Grant of Patent License. Subject to the terms and conditions of\n      this License, each Contributor hereby grants to You a perpetual,\n      worldwide, non-exclusive, no-charge, royalty-free, irrevocable\n      (except as stated in this section) patent license to make, have made,\n      use, offer to sell, sell, import, and otherwise transfer the Work,\n      where such license applies only to those patent claims licensable\n      by such Contributor that are necessarily infringed by their\n      Contribution(s) alone or by combination of their Contribution(s)\n      with the Work to which such Contribution(s) was submitted. If You\n      institute patent litigation against any entity (including a\n      cross-claim or counterclaim in a lawsuit) alleging that the Work\n      or a Contribution incorporated within the Work constitutes direct\n      or contributory patent infringement, then any patent licenses\n      granted to You under this License for that Work shall terminate\n      as of the date such litigation is filed.\n\n   4. Redistribution. You may reproduce and distribute copies of the\n      Work or Derivative Works thereof in any medium, with or without\n      modifications, and in Source or Object form, provided that You\n      meet the following conditions:\n\n      (a) You must give any other recipients of the Work or\n          Derivative Works a copy of this License; and\n\n      (b) You must cause any modified files to carry prominent notices\n          stating that You changed the files; and\n\n      (c) You must retain, in the Source form of any Derivative Works\n          that You distribute, all copyright, patent, trademark, and\n          attribution notices from the Source form of the Work,\n          excluding those notices that do not pertain to any part of\n          the Derivative Works; and\n\n      (d) If the Work includes a \"NOTICE\" text file as part of its\n          distribution, then any Derivative Works that You distribute must\n          include a readable copy of the attribution notices contained\n          within such NOTICE file, excluding those notices that do not\n          pertain to any part of the Derivative Works, in at least one\n          of the following places: within a NOTICE text file distributed\n          as part of the Derivative Works; within the Source form or\n          documentation, if provided along with the Derivative Works; or,\n          within a display generated by the Derivative Works, if and\n          wherever such third-party notices normally appear. The contents\n          of the NOTICE file are for informational purposes only and\n          do not modify the License. You may add Your own attribution\n          notices within Derivative Works that You distribute, alongside\n          or as an addendum to the NOTICE text from the Work, provided\n          that such additional attribution notices cannot be construed\n          as modifying the License.\n\n      You may add Your own copyright statement to Your modifications and\n      may provide additional or different license terms and conditions\n      for use, reproduction, or distribution of Your modifications, or\n      for any such Derivative Works as a whole, provided Your use,\n      reproduction, and distribution of the Work otherwise complies with\n      the conditions stated in this License.\n\n   5. Submission of Contributions. Unless You explicitly state otherwise,\n      any Contribution intentionally submitted for inclusion in the Work\n      by You to the Licensor shall be under the terms and conditions of\n      this License, without any additional terms or conditions.\n      Notwithstanding the above, nothing herein shall supersede or modify\n      the terms of any separate license agreement you may have executed\n      with Licensor regarding such Contributions.\n\n   6. Trademarks. This License does not grant permission to use the trade\n      names, trademarks, service marks, or product names of the Licensor,\n      except as required for reasonable and customary use in describing the\n      origin of the Work and reproducing the content of the NOTICE file.\n\n   7. Disclaimer of Warranty. Unless required by applicable law or\n      agreed to in writing, Licensor provides the Work (and each\n      Contributor provides its Contributions) on an \"AS IS\" BASIS,\n      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or\n      implied, including, without limitation, any warranties or conditions\n      of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A\n      PARTICULAR PURPOSE. You are solely responsible for determining the\n      appropriateness of using or redistributing the Work and assume any\n      risks associated with Your exercise of permissions under this License.\n\n   8. Limitation of Liability. In no event and under no legal theory,\n      whether in tort (including negligence), contract, or otherwise,\n      unless required by applicable law (such as deliberate and grossly\n      negligent acts) or agreed to in writing, shall any Contributor be\n      liable to You for damages, including any direct, indirect, special,\n      incidental, or consequential damages of any character arising as a\n      result of this License or out of the use or inability to use the\n      Work (including but not limited to damages for loss of goodwill,\n      work stoppage, computer failure or malfunction, or any and all\n      other commercial damages or losses), even if such Contributor\n      has been advised of the possibility of such damages.\n\n   9. Accepting Warranty or Additional Liability. While redistributing\n      the Work or Derivative Works thereof, You may choose to offer,\n      and charge a fee for, acceptance of support, warranty, indemnity,\n      or other liability obligations and/or rights consistent with this\n      License. However, in accepting such obligations, You may act only\n      on Your own behalf and on Your sole responsibility, not on behalf\n      of any other Contributor, and only if You agree to indemnify,\n      defend, and hold each Contributor harmless for any liability\n      incurred by, or claims asserted against, such Contributor by reason\n      of your accepting any such warranty or additional liability.\n\n   END OF TERMS AND CONDITIONS\n\n   APPENDIX: How to apply the Apache License to your work.\n\n      To apply the Apache License to your work, attach the following\n      boilerplate notice, with the fields enclosed by brackets \"[]\"\n      replaced with your own identifying information. (Don't include\n      the brackets!)  The text should be enclosed in the appropriate\n      comment syntax for the file format. We also recommend that a\n      file or class name and description of purpose be included on the\n      same \"printed page\" as the copyright notice for easier\n      identification within third-party archives.\n\n   Copyright [yyyy] [name of copyright owner]\n\n   Licensed under the Apache License, Version 2.0 (the \"License\");\n   you may not use this file except in compliance with the License.\n   You may obtain a copy of the License at\n\n       http://www.apache.org/licenses/LICENSE-2.0\n\n   Unless required by applicable law or agreed to in writing, software\n   distributed under the License is distributed on an \"AS IS\" BASIS,\n   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n   See the License for the specific language governing permissions and\n   limitations under the License.\n"
  },
  {
    "path": "README.md",
    "content": "### 使用步骤（Google Chrome）\n1. 启动工程，访问地址： http://127.0.0.1:8080/swagger-ui.html\n2. swagger2Word 提供了多种方式生成 word 文档，可以通过 swagger json 的资源地址，例如：https://petstore.swagger.io/v2/swagger.json ；可以通过上传 json 文件；甚至可以直接输入 json 字符串。  \n![Image text](https://github.com/JMCuixy/swagger2word/blob/master/swagger2word.jpg)\n3. 生成的 WORD 示例：  \n![Image text](https://github.com/JMCuixy/swagger2word/blob/master/demo_word.jpg)\n\n<br>\n<br>\n<br>\n<p>--------------版本迭代历程，感谢各位小伙伴的支持--------------</p>\n\n#### 版本： SwaggerToWord 1.0 （2018-01-18）\n1. 一个Swagger API 文档转 Word 文档的工具项目 \n2. 项目想法和说明可以参考：[http://www.cnblogs.com/jmcui/p/8298823.html](http://www.cnblogs.com/jmcui/p/8298823.html)\n\n#### 版本：SwaggerToWord 1.1 (2018-02-11)\n1. 替换 HttpClient 工具类以适配更多的Restful服务。\n2. 把 json 示例文件替换成官方的示例文件。\n3. 更改写死的模板。让生成的 word 的内容都从 Swagger api 中来。\n\n#### 版本：SwaggerToWord 1.2 (2018-06-21)\n1. 引入了 Spring 的 RestTemplate 取代 HttpClients 以支持更多的 Restful 请求。\n2. 命名规范以及增加异常处理，对于无法处理的HTTP请求返回空字符串。\n3. 修改之前导入data.josn的方式，变成 restTemplate.getForObject(\"SwaggerJson的url地址\",Map.class) 的动态获取方式。\n\n#### 版本：SwaggerToWord 1.3 (2019-06-12)\n1. Spring 框架向 SpringBoot 升级。\n2. thymeleaf 取代 jsp模板。\n\n#### 版本：SwaggerToWord 1.4 (2019-08-02)\n1. 取消 HttpClient 的请求方式去获得返回值，改由从 Swagger Json 文件中直接读取  \n2. 针对 application/json 请求方式的入参做渲染     \n3. 对于文字过多导致 HTML table 变形做适配   \n4. 真诚感谢 [fpzhan](https://github.com/fpzhan)  的代码贡献。\n\n##### 版本: SwaggerToWord 1.4.1 (2019-09-25)\n1. 修复当请求参数为@RequestBody 时，参数类型显示不正确问题。\n2. 新增直接从请求路径中获取 Swagger JSON,多项目下API文档生成。\n3. 解决中文乱码问题。\n4. 真诚感谢 [NealLemon](https://github.com/NealLemon) 的代码贡献。\n\n\n##### 版本: SwaggerToWord 1.4.2 (2019-10-11)\n1. 增加一键下载doc文件文件的方式。\n2. 真诚感谢 [benwudan](https://github.com/benwudan) 的想法和代码贡献。\n\n#### 版本：SwaggerToWord 1.5 (2019-12-18)\n1. 代码梳理和页面美化。\n4. 真诚感谢 [kevin4j](https://github.com/kevin4j)  的代码贡献。\n"
  },
  {
    "path": "pom.xml",
    "content": "<project xmlns=\"http://maven.apache.org/POM/4.0.0\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n         xsi:schemaLocation=\"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd\">\n    <modelVersion>4.0.0</modelVersion>\n    <groupId>org.word</groupId>\n    <artifactId>Swagger2Word</artifactId>\n\n    <packaging>jar</packaging>\n    <version>1.5.0-SNAPSHOT</version>\n    <name>swagger2word</name>\n\n\n    <parent>\n        <groupId>org.springframework.boot</groupId>\n        <artifactId>spring-boot-starter-parent</artifactId>\n        <version>2.0.5.RELEASE</version>\n    </parent>\n\n    <properties>\n        <skipTests>true</skipTests>\n        <java.version>1.8</java.version>\n        <springfox-version>2.6.1</springfox-version>\n    </properties>\n\n    <dependencies>\n        <dependency>\n            <groupId>org.springframework.boot</groupId>\n            <artifactId>spring-boot-starter-web</artifactId>\n        </dependency>\n        <!-- thymeleaf -->\n        <dependency>\n            <groupId>org.springframework.boot</groupId>\n            <artifactId>spring-boot-starter-thymeleaf</artifactId>\n        </dependency>\n\n        <!--lombok-->\n        <dependency>\n            <groupId>org.projectlombok</groupId>\n            <artifactId>lombok</artifactId>\n        </dependency>\n        <dependency>\n            <groupId>org.apache.commons</groupId>\n            <artifactId>commons-lang3</artifactId>\n        </dependency>\n        <dependency>\n            <groupId>org.apache.httpcomponents</groupId>\n            <artifactId>httpclient</artifactId>\n        </dependency>\n        <dependency>\n            <groupId>io.springfox</groupId>\n            <artifactId>springfox-swagger2</artifactId>\n            <version>${springfox-version}</version>\n        </dependency>\n        <dependency>\n            <groupId>io.springfox</groupId>\n            <artifactId>springfox-swagger-ui</artifactId>\n            <version>${springfox-version}</version>\n        </dependency>\n        <dependency>\n            <groupId>joda-time</groupId>\n            <artifactId>joda-time</artifactId>\n        </dependency>\n    </dependencies>\n    <build>\n        <finalName>Swagger2Word</finalName>\n        <plugins>\n            <plugin>\n                <groupId>org.apache.maven.plugins</groupId>\n                <artifactId>maven-compiler-plugin</artifactId>\n                <version>3.3</version>\n                <configuration>\n                    <source>1.8</source>\n                    <target>1.8</target>\n                    <encoding>utf-8</encoding>\n                </configuration>\n            </plugin>\n            <plugin>\n                <groupId>org.apache.maven.plugins</groupId>\n                <artifactId>maven-resources-plugin</artifactId>\n                <version>2.6</version>\n                <configuration>\n                    <delimiters>\n                        <delimiter>${*}</delimiter>\n                        <delimiter>@</delimiter>\n                    </delimiters>\n                    <useDefaultDelimiters>false</useDefaultDelimiters>\n                </configuration>\n            </plugin>\n            <plugin>\n                <groupId>org.springframework.boot</groupId>\n                <artifactId>spring-boot-maven-plugin</artifactId>\n                <version>2.0.1.RELEASE</version>\n                <executions>\n                    <execution>\n                        <phase>package</phase>\n                        <!--可以把依赖的包都打包到生成的Jar包中-->\n                        <goals>\n                            <goal>repackage</goal>\n                        </goals>\n                        <!--可以生成不含依赖包的不可执行Jar包-->\n                        <configuration>\n                            <classifier>exec</classifier>\n                        </configuration>\n                    </execution>\n                </executions>\n            </plugin>\n\t\t  \t<plugin>\n\t\t  \t\t<groupId>org.springframework.boot</groupId>\n\t\t \t\t<artifactId>spring-boot-maven-plugin</artifactId>\n\t\t  \t</plugin>\n        </plugins>\n    </build>\n</project>\n"
  },
  {
    "path": "src/main/java/org/word/Application.java",
    "content": "package org.word;\n\nimport org.springframework.boot.SpringApplication;\nimport org.springframework.boot.autoconfigure.SpringBootApplication;\nimport springfox.documentation.swagger2.annotations.EnableSwagger2;\n\n/**\n * @author cuixiuyin\n * @description\n * @date: 2018/12/19 21:32\n */\n@SpringBootApplication\n@EnableSwagger2\npublic class Application {\n\n    public static void main(String[] args) {\n        SpringApplication.run(Application.class, args);\n    }\n}\n"
  },
  {
    "path": "src/main/java/org/word/config/JavaConfig.java",
    "content": "package org.word.config;\n\nimport org.apache.http.conn.ssl.SSLConnectionSocketFactory;\nimport org.apache.http.conn.ssl.TrustStrategy;\nimport org.apache.http.impl.client.CloseableHttpClient;\nimport org.apache.http.impl.client.HttpClients;\nimport org.springframework.context.annotation.Bean;\nimport org.springframework.context.annotation.Configuration;\nimport org.springframework.http.client.HttpComponentsClientHttpRequestFactory;\nimport org.springframework.http.converter.StringHttpMessageConverter;\nimport org.springframework.web.client.RestTemplate;\n\nimport javax.net.ssl.SSLContext;\nimport java.nio.charset.StandardCharsets;\nimport java.security.KeyManagementException;\nimport java.security.KeyStoreException;\nimport java.security.NoSuchAlgorithmException;\nimport java.security.cert.X509Certificate;\n\n/**\n * Created by XiuYin.Cui on 2018/6/21.\n */\n@Configuration\npublic class JavaConfig {\n\n    @Bean\n    public RestTemplate restTemplate() throws KeyStoreException, NoSuchAlgorithmException, KeyManagementException {\n        TrustStrategy acceptingTrustStrategy = (X509Certificate[] chain, String authType) -> true;\n        SSLContext sslContext = org.apache.http.ssl.SSLContexts.custom()\n                .loadTrustMaterial(null, acceptingTrustStrategy)\n                .build();\n        SSLConnectionSocketFactory csf = new SSLConnectionSocketFactory(sslContext);\n        CloseableHttpClient httpClient = HttpClients.custom()\n                .setSSLSocketFactory(csf)\n                .build();\n        HttpComponentsClientHttpRequestFactory requestFactory =\n                new HttpComponentsClientHttpRequestFactory();\n        requestFactory.setHttpClient(httpClient);\n\n        //60s\n        requestFactory.setConnectTimeout(60 * 1000);\n        requestFactory.setReadTimeout(60 * 1000);\n        RestTemplate restTemplate = new RestTemplate(requestFactory);\n        restTemplate.getMessageConverters().set(1, new StringHttpMessageConverter(StandardCharsets.UTF_8));\n        return restTemplate;\n    }\n}\n"
  },
  {
    "path": "src/main/java/org/word/config/SwaggerDocumentationConfig.java",
    "content": "package org.word.config;\n\nimport org.springframework.context.annotation.Bean;\nimport org.springframework.context.annotation.Configuration;\nimport springfox.documentation.builders.ApiInfoBuilder;\nimport springfox.documentation.builders.RequestHandlerSelectors;\nimport springfox.documentation.service.ApiInfo;\nimport springfox.documentation.service.ApiKey;\nimport springfox.documentation.service.Contact;\nimport springfox.documentation.spi.DocumentationType;\nimport springfox.documentation.spring.web.plugins.Docket;\n\nimport java.util.Collections;\nimport java.util.List;\n\n/*\n * added by dongxl6\n * enable swagger-ui\n */\n@Configuration\npublic class SwaggerDocumentationConfig {\n\n    ApiInfo apiInfo() {\n        return new ApiInfoBuilder()\n            .title(\"Swagger to Word\")\n            .description(\"a tool for converting swagger json to word\")\n            .license(\"Apache 2.0\")\n            .licenseUrl(\"http://www.apache.org/licenses/LICENSE-2.0.html\")\n            .termsOfServiceUrl(\"\")\n            .version(\"0.0.1\")\n            .contact(new Contact(\"\",\"\", \"15980292662@163.com\"))\n            .build();\n    }\n\n    @Bean\n    public Docket customImplementation(){\n        return new Docket(DocumentationType.SWAGGER_2)\n                .select()\n                    .apis(RequestHandlerSelectors.basePackage(\"org.word.controller\"))\n                    .build()\n                .directModelSubstitute(org.joda.time.LocalDate.class, java.sql.Date.class)\n                .directModelSubstitute(org.joda.time.DateTime.class, java.util.Date.class)\n                .apiInfo(apiInfo());\n    }\n\n}\n"
  },
  {
    "path": "src/main/java/org/word/controller/IndexController.java",
    "content": "package org.word.controller;\n\n\nimport io.swagger.annotations.ApiOperation;\nimport io.swagger.annotations.ApiResponse;\nimport io.swagger.annotations.ApiResponses;\nimport org.springframework.core.io.Resource;\nimport org.springframework.stereotype.Controller;\nimport org.springframework.web.bind.annotation.RequestMapping;\nimport org.springframework.web.bind.annotation.RequestMethod;\nimport springfox.documentation.annotations.ApiIgnore;\n\nimport javax.servlet.http.HttpServletRequest;\n\n/**\n * @author xiuyin.cui\n * @Description\n * @date 2019/3/22 10:52\n */\n@Controller\npublic class IndexController {\n    @ApiIgnore\n    @RequestMapping(value = \"/\")\n    public String index(HttpServletRequest request) {\n        return \"redirect:swagger-ui.html\";\n    }\n}\n"
  },
  {
    "path": "src/main/java/org/word/controller/OpenApiWordController.java",
    "content": "package org.word.controller;\n\nimport io.swagger.annotations.Api;\nimport io.swagger.annotations.ApiOperation;\nimport io.swagger.annotations.ApiParam;\nimport io.swagger.annotations.ApiResponse;\nimport io.swagger.annotations.ApiResponses;\nimport org.apache.commons.lang3.StringUtils;\nimport org.springframework.beans.factory.annotation.Autowired;\nimport org.springframework.beans.factory.annotation.Value;\nimport org.springframework.stereotype.Controller;\nimport org.springframework.ui.Model;\nimport org.springframework.web.bind.annotation.RequestMapping;\nimport org.springframework.web.bind.annotation.RequestMethod;\nimport org.springframework.web.bind.annotation.RequestPart;\nimport org.springframework.web.multipart.MultipartFile;\nimport org.thymeleaf.context.Context;\nimport org.thymeleaf.spring5.SpringTemplateEngine;\nimport org.word.service.OpenApiWordService;\n\nimport javax.servlet.http.HttpServletResponse;\nimport javax.validation.Valid;\nimport java.io.BufferedOutputStream;\nimport java.io.IOException;\nimport java.net.URLEncoder;\nimport java.util.Map;\n\n@Controller\n@Api(tags = \"OpenAPI\")\npublic class OpenApiWordController {\n\n    @Value(\"${swagger.url}\")\n    private String swaggerUrl;\n\n    @Autowired\n    private OpenApiWordService openApiWordService;\n    @Autowired\n    private SpringTemplateEngine springTemplateEngine;\n\n    private String fileName;\n\n    /**\n     * 将 swagger json文件转换成 word文档并下载\n     *\n     * @param model\n     * @param jsonFile 需要转换成 word 文档的swagger json文件\n     * @param response\n     * @return\n     * @throws Exception\n     */\n    @ApiOperation(value = \"将 swagger json文件转换成 word文档并下载\", notes = \"\", tags = {\"Word\"})\n    @ApiResponses(value = {@ApiResponse(code = 200, message = \"请求成功。\")})\n    @RequestMapping(value = \"/OpenApiFileToWord\", method = {RequestMethod.POST})\n    public void getWord(Model model, @ApiParam(\"swagger json file\") @Valid @RequestPart(\"jsonFile\") MultipartFile jsonFile, HttpServletResponse response) throws Exception {\n        generateModelData(model, jsonFile);\n        writeContentToResponse(model, response);\n    }\n\n    private void generateModelData(Model model, MultipartFile jsonFile) throws IOException {\n        Map<String, Object> result = openApiWordService.tableList(jsonFile);\n        fileName = jsonFile.getOriginalFilename();\n\n        if (fileName != null) {\n            fileName = fileName.replaceAll(\".json\", \"\");\n        } else {\n            fileName = \"toWord\";\n        }\n\n        model.addAttribute(\"url\", \"http://\");\n        model.addAttribute(\"download\", 0);\n        model.addAllAttributes(result);\n    }\n\n    private void generateModelData(Model model, String url, Integer download) {\n        url = StringUtils.defaultIfBlank(url, swaggerUrl);\n        Map<String, Object> result = openApiWordService.tableList(url);\n        model.addAttribute(\"url\", url);\n        model.addAttribute(\"download\", download);\n        model.addAllAttributes(result);\n    }\n\n    private void writeContentToResponse(Model model, HttpServletResponse response) {\n        Context context = new Context();\n        context.setVariables(model.asMap());\n        String content = springTemplateEngine.process(\"word\", context);\n        response.setContentType(\"application/octet-stream;charset=utf-8\");\n        response.setCharacterEncoding(\"utf-8\");\n        try (BufferedOutputStream bos = new BufferedOutputStream(response.getOutputStream())) {\n            response.setHeader(\"Content-disposition\", \"attachment;filename=\" + URLEncoder.encode(fileName + \".doc\", \"utf-8\"));\n            byte[] bytes = content.getBytes();\n            bos.write(bytes, 0, bytes.length);\n            bos.flush();\n        } catch (IOException e) {\n            e.printStackTrace();\n        }\n    }\n}"
  },
  {
    "path": "src/main/java/org/word/controller/WordController.java",
    "content": "package org.word.controller;\n\nimport io.swagger.annotations.*;\nimport lombok.extern.slf4j.Slf4j;\nimport org.apache.commons.lang3.StringUtils;\nimport org.springframework.beans.factory.annotation.Autowired;\nimport org.springframework.beans.factory.annotation.Value;\nimport org.springframework.stereotype.Controller;\nimport org.springframework.ui.Model;\nimport org.springframework.web.bind.annotation.RequestMapping;\nimport org.springframework.web.bind.annotation.RequestMethod;\nimport org.springframework.web.bind.annotation.RequestParam;\nimport org.springframework.web.bind.annotation.RequestPart;\nimport org.springframework.web.multipart.MultipartFile;\nimport org.thymeleaf.context.Context;\nimport org.thymeleaf.spring5.SpringTemplateEngine;\nimport org.word.service.WordService;\n\nimport javax.servlet.http.HttpServletResponse;\nimport javax.validation.Valid;\nimport java.io.*;\nimport java.net.URLEncoder;\nimport java.util.Locale;\nimport java.util.Map;\n\n/**\n * Created by XiuYin.Cui on 2018/1/11.\n */\n@Controller\n@Api(tags = \"the toWord API\")\n@Slf4j\npublic class WordController {\n\n    @Value(\"${swagger.url}\")\n    private String swaggerUrl;\n\n    @Autowired\n    private WordService tableService;\n    @Autowired\n    private SpringTemplateEngine springTemplateEngine;\n\n    private String fileName = \"toWord\";\n\n    /**\n     * 将 swagger 文档转换成 html 文档，可通过在网页上右键另存为 xxx.doc 的方式转换为 word 文档\n     *\n     * @param model\n     * @param url   需要转换成 word 文档的资源地址\n     * @return\n     */\n    @Deprecated\n    @ApiOperation(value = \"将 swagger 文档转换成 html 文档，可通过在网页上右键另存为 xxx.doc 的方式转换为 word 文档\", response = String.class, tags = {\"Word\"})\n    @ApiResponses(value = {@ApiResponse(code = 200, message = \"请求成功。\", response = String.class)})\n    @RequestMapping(value = \"/toWord\", method = {RequestMethod.GET})\n    public String getWord(Model model,\n                          @ApiParam(value = \"资源地址\", required = false) @RequestParam(value = \"url\", required = false) String url,\n                          @ApiParam(value = \"是否下载\", required = false) @RequestParam(value = \"download\", required = false, defaultValue = \"1\") Integer download) {\n        generateModelData(model, url, download);\n\n        // Is there a localized template available ?\n        Locale currentLocale = Locale.getDefault();\n        String localizedTemplate = \"word-\" + currentLocale.getLanguage() + \"_\" + currentLocale.getCountry();\n        String fileName = \"/templates/\" + localizedTemplate + \".html\";\n\n        if (getClass().getResourceAsStream(fileName) != null) {\n            log.info(fileName + \" resource found\");\n            return localizedTemplate;\n        } else {\n            log.info(fileName + \" resource not found, using default\");\n        }\n        return \"word\";\n    }\n\n    private void generateModelData(Model model, String url, Integer download) {\n        url = StringUtils.defaultIfBlank(url, swaggerUrl);\n        Map<String, Object> result = tableService.tableList(url);\n        model.addAttribute(\"url\", url);\n        model.addAttribute(\"download\", download);\n        model.addAllAttributes(result);\n    }\n\n    /**\n     * 将 swagger 文档一键下载为 doc 文档\n     *\n     * @param model\n     * @param url      需要转换成 word 文档的资源地址\n     * @param response\n     */\n    @ApiOperation(value = \"将 swagger 文档一键下载为 doc 文档\", notes = \"\", tags = {\"Word\"})\n    @ApiResponses(value = {@ApiResponse(code = 200, message = \"请求成功。\")})\n    @RequestMapping(value = \"/downloadWord\", method = {RequestMethod.GET})\n    public void word(Model model, @ApiParam(value = \"资源地址\", required = false) @RequestParam(required = false) String url, HttpServletResponse response) {\n        generateModelData(model, url, 0);\n        writeContentToResponse(model, response);\n    }\n\n    private void writeContentToResponse(Model model, HttpServletResponse response) {\n        Context context = new Context();\n        context.setVariables(model.asMap());\n        String content = springTemplateEngine.process(\"word\", context);\n        response.setContentType(\"application/octet-stream;charset=utf-8\");\n        response.setCharacterEncoding(\"utf-8\");\n        try (BufferedOutputStream bos = new BufferedOutputStream(response.getOutputStream())) {\n            response.setHeader(\"Content-disposition\", \"attachment;filename=\" + URLEncoder.encode(fileName + \".doc\", \"utf-8\"));\n            byte[] bytes = content.getBytes();\n            bos.write(bytes, 0, bytes.length);\n            bos.flush();\n        } catch (IOException e) {\n            e.printStackTrace();\n        }\n    }\n\n    /**\n     * 将 swagger json文件转换成 word文档并下载\n     *\n     * @param model\n     * @param jsonFile 需要转换成 word 文档的swagger json文件\n     * @param response\n     * @return\n     */\n    @ApiOperation(value = \"将 swagger json文件转换成 word文档并下载\", notes = \"\", tags = {\"Word\"})\n    @ApiResponses(value = {@ApiResponse(code = 200, message = \"请求成功。\")})\n    @RequestMapping(value = \"/fileToWord\", method = {RequestMethod.POST})\n    public void getWord(Model model, @ApiParam(\"swagger json file\") @Valid @RequestPart(\"jsonFile\") MultipartFile jsonFile, HttpServletResponse response) {\n        generateModelData(model, jsonFile);\n        writeContentToResponse(model, response);\n    }\n\n    /**\n     * 将 swagger json字符串转换成 word文档并下载\n     *\n     * @param model\n     * @param jsonStr  需要转换成 word 文档的swagger json字符串\n     * @param response\n     * @return\n     */\n    @ApiOperation(value = \"将 swagger json字符串转换成 word文档并下载\", notes = \"\", tags = {\"Word\"})\n    @ApiResponses(value = {@ApiResponse(code = 200, message = \"请求成功。\")})\n    @RequestMapping(value = \"/strToWord\", method = {RequestMethod.POST})\n    public void getWord(Model model, @ApiParam(\"swagger json string\") @Valid @RequestParam(\"jsonStr\") String jsonStr, HttpServletResponse response) {\n        generateModelData(model, jsonStr);\n        writeContentToResponse(model, response);\n    }\n\n    private void generateModelData(Model model, String jsonStr) {\n        Map<String, Object> result = tableService.tableListFromString(jsonStr);\n        model.addAttribute(\"url\", \"http://\");\n        model.addAttribute(\"download\", 0);\n        model.addAllAttributes(result);\n    }\n\n    private void generateModelData(Model model, MultipartFile jsonFile) {\n        Map<String, Object> result = tableService.tableList(jsonFile);\n        fileName = jsonFile.getOriginalFilename();\n\n        if (fileName != null) {\n            fileName = fileName.replaceAll(\".json\", \"\");\n        } else {\n            fileName = \"toWord\";\n        }\n\n        model.addAttribute(\"url\", \"http://\");\n        model.addAttribute(\"download\", 0);\n        model.addAllAttributes(result);\n    }\n}\n"
  },
  {
    "path": "src/main/java/org/word/model/ModelAttr.java",
    "content": "package org.word.model;\n\nimport lombok.Data;\nimport org.apache.commons.lang3.StringUtils;\n\nimport java.io.Serializable;\nimport java.util.ArrayList;\nimport java.util.List;\n\n/**\n * 返回属性\n *\n * @author kevin\n */\n@Data\npublic class ModelAttr implements Serializable {\n\n    public String getClassName() {\n\t\treturn className;\n\t}\n\n\tpublic void setClassName(String className) {\n\t\tthis.className = className;\n\t}\n\n\tpublic String getName() {\n\t\treturn name;\n\t}\n\n\tpublic void setName(String name) {\n\t\tthis.name = name;\n\t}\n\n\tpublic String getType() {\n\t\treturn type;\n\t}\n\n\tpublic void setType(String type) {\n\t\tthis.type = type;\n\t}\n\n\tpublic Boolean getRequire() {\n\t\treturn require;\n\t}\n\n\tpublic void setRequire(Boolean require) {\n\t\tthis.require = require;\n\t}\n\n\tpublic String getDescription() {\n\t\treturn description;\n\t}\n\n\tpublic void setDescription(String description) {\n\t\tthis.description = description;\n\t}\n\n\tpublic List<ModelAttr> getProperties() {\n\t\treturn properties;\n\t}\n\n\tpublic void setProperties(List<ModelAttr> properties) {\n\t\tthis.properties = properties;\n\t}\n\n\tpublic boolean isCompleted() {\n\t\treturn isCompleted;\n\t}\n\n\tpublic void setCompleted(boolean isCompleted) {\n\t\tthis.isCompleted = isCompleted;\n\t}\n\n\tpublic static long getSerialversionuid() {\n\t\treturn serialVersionUID;\n\t}\n\n\tprivate static final long serialVersionUID = -4074067438450613643L;\n\n    /**\n     * 类名\n     */\n    private String className = StringUtils.EMPTY;\n    /**\n     * 属性名\n     */\n    private String name = StringUtils.EMPTY;\n    /**\n     * 类型\n     */\n    private String type = StringUtils.EMPTY;\n    /**\n     * 是否必填\n     */\n    private Boolean require = false;\n    /**\n     * 属性描述\n     */\n    private String description;\n    /**\n     * 嵌套属性列表\n     */\n    private List<ModelAttr> properties = new ArrayList<>();\n\n    /**\n     * 是否加载完成，避免循环引用\n     */\n    private boolean isCompleted = false;\n}\n"
  },
  {
    "path": "src/main/java/org/word/model/Request.java",
    "content": "package org.word.model;\n\nimport java.io.Serializable;\n\nimport lombok.Data;\n\n/**\n * Created by XiuYin.Cui on 2018/1/11.\n */\n@Data\npublic class Request implements Serializable{\n\n    public String getName() {\n\t\treturn name;\n\t}\n\n\tpublic void setName(String name) {\n\t\tthis.name = name;\n\t}\n\n\tpublic String getType() {\n\t\treturn type;\n\t}\n\n\tpublic void setType(String type) {\n\t\tthis.type = type;\n\t}\n\n\tpublic String getParamType() {\n\t\treturn paramType;\n\t}\n\n\tpublic void setParamType(String paramType) {\n\t\tthis.paramType = paramType;\n\t}\n\n\tpublic Boolean getRequire() {\n\t\treturn require;\n\t}\n\n\tpublic void setRequire(Boolean require) {\n\t\tthis.require = require;\n\t}\n\n\tpublic String getRemark() {\n\t\treturn remark;\n\t}\n\n\tpublic void setRemark(String remark) {\n\t\tthis.remark = remark;\n\t}\n\n\tpublic ModelAttr getModelAttr() {\n\t\treturn modelAttr;\n\t}\n\n\tpublic void setModelAttr(ModelAttr modelAttr) {\n\t\tthis.modelAttr = modelAttr;\n\t}\n\n\t/**\n     * 参数名\n     */\n    private String name;\n\n    /**\n     * 数据类型\n     */\n    private String type;\n\n    /**\n     * 参数类型\n     */\n    private String paramType;\n\n    /**\n     * 是否必填\n     */\n    private Boolean require;\n\n    /**\n     * 说明\n     */\n    private String remark;\n\n    /**\n     * 复杂对象引用\n     */\n    private ModelAttr modelAttr;\n}\n"
  },
  {
    "path": "src/main/java/org/word/model/Response.java",
    "content": "package org.word.model;\n\nimport java.io.Serializable;\n\nimport lombok.Data;\n\n/**\n * Created by XiuYin.Cui on 2018/1/11.\n */\n@Data\npublic class Response implements Serializable{\n\n    public String getDescription() {\n\t\treturn description;\n\t}\n\n\tpublic void setDescription(String description) {\n\t\tthis.description = description;\n\t}\n\n\tpublic String getName() {\n\t\treturn name;\n\t}\n\n\tpublic void setName(String name) {\n\t\tthis.name = name;\n\t}\n\n\tpublic String getRemark() {\n\t\treturn remark;\n\t}\n\n\tpublic void setRemark(String remark) {\n\t\tthis.remark = remark;\n\t}\n\n\t/**\n     * 返回参数\n     */\n    private String description;\n\n    /**\n     * 参数名\n     */\n    private String name;\n\n    /**\n     * 备注\n     */\n    private String remark;\n}\n"
  },
  {
    "path": "src/main/java/org/word/model/Table.java",
    "content": "package org.word.model;\n\nimport lombok.Data;\n\nimport java.util.List;\n\n/**\n * Created by XiuYin.Cui on 2018/1/11.\n */\n@Data\npublic class Table {\n\n    public String getTitle() {\n\t\treturn title;\n\t}\n\n\tpublic void setTitle(String title) {\n\t\tthis.title = title;\n\t}\n\n\tpublic String getTag() {\n\t\treturn tag;\n\t}\n\n\tpublic void setTag(String tag) {\n\t\tthis.tag = tag;\n\t}\n\n\tpublic String getUrl() {\n\t\treturn url;\n\t}\n\n\tpublic void setUrl(String url) {\n\t\tthis.url = url;\n\t}\n\n\tpublic String getDescription() {\n\t\treturn description;\n\t}\n\n\tpublic void setDescription(String description) {\n\t\tthis.description = description;\n\t}\n\n\tpublic String getRequestForm() {\n\t\treturn requestForm;\n\t}\n\n\tpublic void setRequestForm(String requestForm) {\n\t\tthis.requestForm = requestForm;\n\t}\n\n\tpublic String getResponseForm() {\n\t\treturn responseForm;\n\t}\n\n\tpublic void setResponseForm(String responseForm) {\n\t\tthis.responseForm = responseForm;\n\t}\n\n\tpublic String getRequestType() {\n\t\treturn requestType;\n\t}\n\n\tpublic void setRequestType(String requestType) {\n\t\tthis.requestType = requestType;\n\t}\n\n\tpublic List<Request> getRequestList() {\n\t\treturn requestList;\n\t}\n\n\tpublic void setRequestList(List<Request> requestList) {\n\t\tthis.requestList = requestList;\n\t}\n\n\tpublic List<Response> getResponseList() {\n\t\treturn responseList;\n\t}\n\n\tpublic void setResponseList(List<Response> responseList) {\n\t\tthis.responseList = responseList;\n\t}\n\n\tpublic String getRequestParam() {\n\t\treturn requestParam;\n\t}\n\n\tpublic void setRequestParam(String requestParam) {\n\t\tthis.requestParam = requestParam;\n\t}\n\n\tpublic String getResponseParam() {\n\t\treturn responseParam;\n\t}\n\n\tpublic void setResponseParam(String responseParam) {\n\t\tthis.responseParam = responseParam;\n\t}\n\n\tpublic ModelAttr getModelAttr() {\n\t\treturn modelAttr;\n\t}\n\n\tpublic void setModelAttr(ModelAttr modelAttr) {\n\t\tthis.modelAttr = modelAttr;\n\t}\n\n\t/**\n     * 大标题\n     */\n    private String title;\n    /**\n     * 小标题\n     */\n    private String tag;\n    /**\n     * url\n     */\n    private String url;\n\n    /**\n     * 描述\n     */\n    private String description;\n\n    /**\n     * 请求参数格式\n     */\n    private String requestForm;\n\n    /**\n     * 响应参数格式\n     */\n    private String responseForm;\n\n    /**\n     * 请求方式\n     */\n    private String requestType;\n\n    /**\n     * 请求体\n     */\n    private List<Request> requestList;\n\n    /**\n     * 返回体\n     */\n    private List<Response> responseList;\n\n    /**\n     * 请求参数\n     */\n    private String requestParam;\n\n    /**\n     * 返回参数\n     */\n    private String responseParam;\n\n    /**\n     * 返回属性列表\n     */\n    private ModelAttr modelAttr = new ModelAttr();\n}\n"
  },
  {
    "path": "src/main/java/org/word/service/OpenApiWordService.java",
    "content": "package org.word.service;\n\nimport org.springframework.web.multipart.MultipartFile;\n\nimport java.io.IOException;\nimport java.util.Map;\n\n/**\n * Created by XiuYin.Cui on 2018/1/12.\n */\npublic interface OpenApiWordService {\n\n    Map<String,Object> tableList(String swaggerUrl);\n\n    Map<String, Object> tableListFromString(String jsonStr) throws IOException;\n\n    Map<String, Object> tableList(MultipartFile jsonFile) throws IOException;\n}"
  },
  {
    "path": "src/main/java/org/word/service/WordService.java",
    "content": "package org.word.service;\n\nimport org.springframework.web.multipart.MultipartFile;\n\nimport java.util.Map;\n\n/**\n * Created by XiuYin.Cui on 2018/1/12.\n */\npublic interface WordService {\n\n    Map<String,Object> tableList(String swaggerUrl);\n\n    Map<String, Object> tableListFromString(String jsonStr);\n\n    Map<String, Object> tableList(MultipartFile jsonFile);\n}\n"
  },
  {
    "path": "src/main/java/org/word/service/impl/OpenApiWordServiceImpl.java",
    "content": "package org.word.service.impl;\n\nimport com.fasterxml.jackson.core.JsonProcessingException;\nimport lombok.extern.slf4j.Slf4j;\nimport org.apache.commons.lang3.StringUtils;\nimport org.springframework.beans.factory.annotation.Autowired;\nimport org.springframework.stereotype.Service;\nimport org.springframework.util.CollectionUtils;\nimport org.springframework.web.client.RestTemplate;\nimport org.springframework.web.multipart.MultipartFile;\nimport org.word.model.ModelAttr;\nimport org.word.model.Request;\nimport org.word.model.Response;\nimport org.word.model.Table;\nimport org.word.service.OpenApiWordService;\nimport org.word.utils.JsonUtils;\nimport org.word.utils.RequestUtils;\nimport org.word.utils.ResponseUtils;\n\nimport java.io.IOException;\nimport java.io.PrintWriter;\nimport java.io.StringWriter;\nimport java.util.ArrayList;\nimport java.util.HashMap;\nimport java.util.Iterator;\nimport java.util.LinkedHashMap;\nimport java.util.List;\nimport java.util.Map;\nimport java.util.Map.Entry;\nimport java.util.Set;\nimport java.util.TreeMap;\nimport java.util.stream.Collectors;\n\n/**\n * @Author XiuYin.Cui\n * @Date 2018/1/12\n **/\n@SuppressWarnings({\"unchecked\", \"rawtypes\"})\n@Slf4j\n@Service\npublic class OpenApiWordServiceImpl implements OpenApiWordService {\n\n    @Autowired\n    private RestTemplate restTemplate;\n\n    @Override\n    public Map<String, Object> tableList(String swaggerUrl) {\n        Map<String, Object> resultMap = new HashMap<>();\n        try {\n            String jsonStr = restTemplate.getForObject(swaggerUrl, String.class);\n            resultMap = tableListFromString(jsonStr);\n            // log.debug(JsonUtils.writeJsonStr(resultMap));\n        } catch (Exception e) {\n            log.error(\"parse error\", e);\n        }\n        return resultMap;\n    }\n\n    @Override\n    public Map<String, Object> tableListFromString(String jsonStr) throws IOException {\n        Map<String, Object> resultMap = new HashMap<>();\n        List<Table> result = new ArrayList<>();\n        try {\n            Map<String, Object> map = getResultFromString(result, jsonStr);\n            Map<String, List<Table>> tableMap = result.stream().parallel().collect(Collectors.groupingBy(Table::getTitle));\n            resultMap.put(\"tableMap\", new TreeMap<>(tableMap));\n            resultMap.put(\"info\", map.get(\"info\"));\n\n            // log.debug(JsonUtils.writeJsonStr(resultMap));\n        } catch (Exception e) {\n            log.error(\"parse error\", e);\n        \tthrow e;\n        }\n        return resultMap;\n    }\n\n\t@Override\n    public Map<String, Object> tableList(MultipartFile jsonFile) throws IOException {\n        Map<String, Object> resultMap = new HashMap<>();\n        try {\n            String jsonStr = new String(jsonFile.getBytes());\n            resultMap = tableListFromString(jsonStr);\n            // log.debug(JsonUtils.writeJsonStr(resultMap));\n        } catch (Exception e) {\n            log.error(\"parse error\", e);\n        \tthrow e;\n        }\n        return resultMap;\n    }\n\n    private Map<String, Object> getResultFromString(List<Table> result, String jsonStr) throws IOException {\n        // convert JSON string to Map\n        Map<String, Object> map = JsonUtils.readValue(jsonStr, HashMap.class);\n\n        //解析model\n        Map<String, ModelAttr> definitinMap = parseComponents(map);\n\n        //解析paths\n        Map<String, Map<String, Object>> paths = (Map<String, Map<String, Object>>) map.get(\"paths\");\n\n        //获取全局请求参数格式作为默认请求参数格式\n        List<String> defaultConsumes = (List) map.get(\"consumes\");\n\n        //获取全局响应参数格式作为默认响应参数格式\n        List<String> defaultProduces = (List) map.get(\"produces\");\n\n        if (paths != null) {\n\n            Iterator<Entry<String, Map<String, Object>>> it = paths.entrySet().iterator();\n            while (it.hasNext()) {\n                Entry<String, Map<String, Object>> path = it.next();\n\n                // 0. 获取该路由下所有请求方式的公共参数\n                Map<String, Object> methods = (Map<String, Object>) path.getValue();\n                List<LinkedHashMap> commonParameters = (ArrayList) methods.get(\"parameters\");\n\n                Iterator<Entry<String, Object>> it2 = path.getValue().entrySet().iterator();\n                // 1.请求路径\n                String url = path.getKey();\n                String requestType = null;\n                while (it2.hasNext()) {\n                \ttry {\n                \t\tEntry<String, Object> request = it2.next();\n\n                \t\t// 2.请求方式，类似为 get,post,delete,put 这样\n                \t\trequestType = request.getKey();\n\n                \t\tif (\"parameters\".equals(requestType)) {\n                \t\t\tcontinue;\n                \t\t}\n\n                \t\tMap<String, Object> content = (Map<String, Object>) request.getValue();\n\n                \t\t// 4. 大标题（类说明）\n                \t\tString title = String.valueOf(((List) content.get(\"tags\")).get(0));\n\n                \t\t// 5.小标题 （方法说明）\n                \t\tString tag = String.valueOf(content.get(\"operationId\"));\n\n                \t\t// 6.接口描述\n                \t\tObject descObj = content.get(\"description\");\n                \t\tString description = descObj == null ? \"\" : descObj.toString();\n\n                \t\t// 7. 请求体\n                \t\tList<LinkedHashMap> parameters = (ArrayList) content.get(\"parameters\");\n\n                \t\tif (!CollectionUtils.isEmpty(parameters)) {\n                \t\t\tif (commonParameters != null) {\n                \t\t\t\tparameters.addAll(commonParameters);\n                \t\t\t}\n                \t\t} else {\n                \t\t\tif (commonParameters != null) {\n                \t\t\t\tparameters = commonParameters;\n                \t\t\t}\n                \t\t}\n\n                \t\t// 8.返回体\n                \t\tMap<String, Object> responses = (LinkedHashMap) content.get(\"responses\");\n\n                \t\t// 9.请求参数格式，类似于 multipart/form-data\n                \t\tList<String> requestParamsFormates = getRequestParamsFormate(content);\n                \t\tString requestForm = StringUtils.join(requestParamsFormates, \",\");\n\n                \t\t// 取出来状态是200时的返回值\n                \t\tMap<String, Object> obj = (Map<String, Object>) responses.get(\"200\");\n                \t\tMap<String, Object> requestBody = (Map<String, Object>) content.get(\"requestBody\");\n\n                \t\t// 10.返回参数格式，类似于 application/json\n                \t\tList<String> responseParamsFormates = getResponseParamsFormate(obj);\n                \t\tString responseForm = StringUtils.join(responseParamsFormates, \",\");\n\n                \t\t//封装Table\n                \t\tTable table = new Table();\n\n                \t\ttable.setTitle(title);\n                \t\ttable.setUrl(url);\n                \t\ttable.setTag(tag);\n                \t\ttable.setDescription(description);\n                \t\ttable.setRequestForm(requestForm);\n                \t\ttable.setResponseForm(responseForm);\n                \t\ttable.setRequestType(requestType);\n                \t\ttable.setRequestList(processRequestList(parameters, requestBody, definitinMap));\n\n                \t\ttable.setResponseList(processResponseCodeList(responses, definitinMap));\n                \t\tif (obj != null && obj.get(\"content\") != null) {\n                \t\t\ttable.setModelAttr(processResponseModelAttrs(obj, definitinMap));\n                \t\t}\n\n                \t\t//示例\n                \t\ttable.setRequestParam(processRequestParam(table.getRequestList()));\n                \t\ttable.setResponseParam(processResponseParam1(obj, definitinMap));\n\n                \t\tresult.add(table);\n                \t} catch (Exception e) {\n                \t\tStringWriter sw = new StringWriter();\n                \t\tPrintWriter pw = new PrintWriter(sw);\n                \t\te.printStackTrace(pw);\n                \t\tthrow new JsonProcessingException(url + \"接口格式不正确: \" + requestType + \"请求 \" + e.getMessage()) {};\n                \t}\n                }\n            }\n        }\n        return map;\n    }\n\n    /**\n     * 请求参数格式， 类似于 multipart/form-data\n     */\n    private List<String> getRequestParamsFormate(Map<String, Object> obj) {\n        Map<String, Object> requestBody = (LinkedHashMap) obj.get(\"requestBody\");\n        List<String> requestTypes = new ArrayList();\n        if (requestBody != null) {\n            Map<String, Map> content = (LinkedHashMap) requestBody.get(\"content\");\n            Set keys = content.keySet();\n            return new ArrayList<String>(keys);\n        }\n        return requestTypes;\n    }\n\n    /**\n     * 返回参数格式，类似于 application/json\n     * @throws Exception\n     */\n    private List<String> getResponseParamsFormate(Map<String, Object> responseObj) {\n        Map<String, Map> content = (LinkedHashMap) responseObj.get(\"content\");\n        List<String> responseTypes = new ArrayList();\n        if (content != null) {\n            Set keys = content.keySet();\n            return new ArrayList<String>(keys);\n        }\n        return responseTypes;\n    }\n\n    /**\n     * 处理请求参数列表\n     *\n     * @param parameters\n     * @param definitinMap\n     * @return\n     * @throws JsonProcessingException\n     */\n    private List<Request> processRequestList(List<LinkedHashMap> parameters, Map<String, Object> requestBody, Map<String, ModelAttr> definitinMap) throws JsonProcessingException {\n        List<Request> requestList = new ArrayList<>();\n        if (!CollectionUtils.isEmpty(parameters)) {\n            for (Map<String, Object> param : parameters) {\n                Object in = param.get(\"in\");\n                Request request = new Request();\n                request.setName(String.valueOf(param.get(\"name\")));\n\n                Map<String, String> schema1 = (Map) param.get(\"schema\");\n\n                request.setType(schema1 == null ? \" \" : schema1.get(\"type\").toString());\n                // request.setType(param.get(\"type\") == null ? \"object\" : param.get(\"type\").toString());\n                if (param.get(\"format\") != null) {\n                    request.setType(request.getType() + \"(\" + param.get(\"format\") + \")\");\n                }\n                request.setParamType(String.valueOf(in));\n                // 考虑对象参数类型\n                if (in != null && \"body\".equals(in)) {\n                    Map<String, Object> schema = (Map) param.get(\"schema\");\n                    Object ref = schema.get(\"$ref\");\n                    // 数组情况另外处理\n                    if (schema.get(\"type\") != null && \"array\".equals(schema.get(\"type\"))) {\n                        ref = ((Map) schema.get(\"items\")).get(\"$ref\");\n                        request.setType(\"array\");\n                    }\n                    if (ref != null) {\n                        request.setType(request.getType() + \":\" + ref.toString().replaceAll(\"#/definitions/\", \"\"));\n                        request.setModelAttr(definitinMap.get(ref));\n                    }\n                }\n                // 是否必填\n                request.setRequire(false);\n                if (param.get(\"required\") != null) {\n                    request.setRequire((Boolean) param.get(\"required\"));\n                }\n                // 参数说明\n                request.setRemark(String.valueOf(param.get(\"description\")));\n                requestList.add(request);\n            }\n        }\n\n        if (requestBody != null) {\n            Map<String, Map> content = (LinkedHashMap) requestBody.get(\"content\");\n\n            try {\n            \tRequestUtils.validateRequestKey(content);\n            } catch(Exception e) {\n            \tthrow new JsonProcessingException(\"requestybody 字段 \" + e.getMessage()) {};\n            }\n\n            Iterator<Map.Entry<String, Map>> applications = content.entrySet().iterator();\n            while (applications.hasNext()) {\n                Map.Entry<String, Map> application = applications.next();\n\n                if (application.getValue() != null) {\n                    Request request = new Request();\n\n                    Map<String, Object> schema = (Map<String, Object>) application.getValue().get(\"schema\");\n                    request.setName(\" \");\n                    request.setType(schema == null ? \" \" : schema.get(\"type\").toString());\n                    request.setParamType(\"body\");\n\n                    Object ref = schema.get(\"$ref\");\n\n                    if (schema.get(\"type\") != null && \"array\".equals(schema.get(\"type\"))) {\n                        ref = ((Map) schema.get(\"items\")).get(\"$ref\");\n                        request.setType(\"array\");\n                    }\n                    if (ref != null) {\n                        // request.setType(request.getType() + \":\" + ref.toString().replaceAll(\"#/definitions/\", \"\"));\n                        request.setType(\"object\");\n                        request.setModelAttr(definitinMap.get(ref));\n                    }\n                    if (schema.get(\"properties\") != null) {\n                        ArrayList<String> requiredArr = new ArrayList<String>();\n                        if (schema.get(\"required\") != null) {\n                            requiredArr = (ArrayList<String>) schema.get(\"required\");\n                        }\n                        request.setModelAttr(getRequestSchemaModelAttr(schema, requiredArr));\n                    }\n\n                    // 是否必填\n                    request.setRequire(true);\n\n                    // 参数说明\n                    requestList.add(request);\n                }\n            }\n        }\n        return requestList;\n    }\n\n\n    /**\n     * 处理返回码列表\n     *\n     * @param responses 全部状态码返回对象\n     * @return\n     */\n    private List<Response> processResponseCodeList(Map<String, Object> responses,  Map<String, ModelAttr> definitinMap ) throws JsonProcessingException  {\n        List<Response> responseList = new ArrayList<>();\n        Iterator<Map.Entry<String, Object>> resIt = responses.entrySet().iterator();\n        while (resIt.hasNext()) {\n            Map.Entry<String, Object> entry = resIt.next();\n            Response response = new Response();\n            // 状态码 200 201 401 403 404 这样\n            response.setName(entry.getKey());\n            LinkedHashMap<String, Object> statusCodeInfo = (LinkedHashMap) entry.getValue();\n            response.setDescription(String.valueOf(statusCodeInfo.get(\"description\")));\n\n            Map<String, Map> content = (Map) statusCodeInfo.get(\"content\");\n\n            if (content != null) {\n            \ttry {\n            \t\tResponseUtils.validateResponseKey(content);\n            \t} catch(Exception e) {\n            \t\tthrow new JsonProcessingException(\"response字段 \" + entry.getKey() + \"字段 \" + e.getMessage()) {};\n            \t}\n                // responses内容application多个遍历处理\n                Iterator<Map.Entry<String, Map>> applications = content.entrySet().iterator();\n\n                while (applications.hasNext()) {\n                    Map.Entry<String, Map> application = applications.next();\n\n                    if (application.getValue() != null) {\n                        Object schema = application.getValue().get(\"schema\");\n                        if (schema != null) {\n                            Object originalRef = ((LinkedHashMap) schema).get(\"originalRef\");\n                            response.setRemark(originalRef == null ? \"\" : originalRef.toString());\n                        }\n                        responseList.add(response);\n                    }\n                }\n            } else {\n                String ref = String.valueOf(statusCodeInfo.get(\"$ref\"));\n\n                if (ref != \"\") {\n                    ModelAttr modelAttr = definitinMap.get(ref);\n                    response.setDescription(modelAttr.getDescription());\n                }\n\n                responseList.add(response);\n            }\n        }\n        return responseList;\n    }\n\n    /**\n     * 处理返回属性列表\n     *\n     * @param responseObj\n     * @param definitinMap\n     * @return\n     */\n    private ModelAttr processResponseModelAttrs(Map<String, Object> responseObj, Map<String, ModelAttr> definitinMap) {\n        Map<String, Map> content = (Map) responseObj.get(\"content\");\n        //其他类型\n        ModelAttr modelAttr = new ModelAttr();\n\n        Iterator<Map.Entry<String, Map>> applications = content.entrySet().iterator();\n\n        while (applications.hasNext()) {\n            Map.Entry<String, Map> application = applications.next();\n\n            if (application.getValue() != null) {\n\n                Map<String, Object> schema = (Map<String, Object>) application.getValue().get(\"schema\");\n                String type = (String) schema.get(\"type\");\n                String ref = null;\n                //数组\n                if (\"array\".equals(type)) {\n                    Map<String, Object> items = (Map<String, Object>) schema.get(\"items\");\n                    if (items != null && items.get(\"$ref\") != null) {\n                        ref = (String) items.get(\"$ref\");\n                    }\n                }\n                //对象\n                if (schema.get(\"$ref\") != null) {\n                    ref = (String) schema.get(\"$ref\");\n                }\n\n                //其他类型\n                modelAttr.setType(StringUtils.defaultIfBlank(type, StringUtils.EMPTY));\n\n                if (StringUtils.isNotBlank(ref) && definitinMap.get(ref) != null) {\n                    modelAttr = definitinMap.get(ref);\n                }\n\n                // 未使用ref方式 使用properties方式\n                if (schema.get(\"properties\") != null) {\n                    modelAttr = getSchemaModelAttr(schema);\n                }\n            }\n        }\n        return modelAttr;\n    }\n\n    /**\n     * 解析components\n     *\n     * @param map\n     * @return\n     */\n    private Map<String, ModelAttr> parseComponents(Map<String, Object> map) {\n        Map<String, Object> definitions = (Map<String, Object>) map.get(\"components\");\n        Map<String, ModelAttr> definitinMap = new HashMap<>(256);\n        if (definitions != null) {\n            Iterator<String> modelNameIt = definitions.keySet().iterator();\n            /**\n             \"components\": {\n             \"requestBodies\": {},\n             \"schemas\": {}\n             }\n             */\n            while (modelNameIt.hasNext()) {\n                String modeName = modelNameIt.next();\n                /**\n                 \"schemas\": {\n                 \"cat\":{},\n                 \"dog\":{},\n                 }\n                 */\n                Map<String, Map<String, Object>> modeContent = (Map<String, Map<String, Object>>) definitions.get(modeName);\n\n                if (modeContent != null) {\n                    Iterator<String> modeContentIt = modeContent.keySet().iterator();\n\n                    while (modeContentIt.hasNext()) {\n                        String componentsGrandChildName = modeContentIt.next();\n\n                        getAndPutModelAttr(modeContent, definitinMap, modeName, componentsGrandChildName);\n                    }\n                }\n            }\n        }\n        return definitinMap;\n    }\n\n    /**\n     * 递归生成ModelAttr\n     * 对$ref类型设置具体属性\n     */\n    private ModelAttr getAndPutModelAttr(Map<String, Map<String, Object>> swaggerMap, Map<String, ModelAttr> resMap, String parentName, String modeName) {\n        ModelAttr modeAttr;\n        if ((modeAttr = resMap.get(\"#/components/\" + parentName + \"/\" + modeName)) == null) {\n            modeAttr = new ModelAttr();\n            resMap.put(\"#/components/\" + parentName + \"/\" + modeName, modeAttr);\n        } else if (resMap.get(\"#/components/\" + parentName + \"/\" + modeName) != null) {\n            return resMap.get(\"#/components/\" + parentName + \"/\" + modeName);\n        }\n        Map<String, Object> modeProperties = (Map<String, Object>) swaggerMap.get(modeName).get(\"properties\");\n        List<ModelAttr> attrList = new ArrayList<>();\n        // 获取required字段，遍历properties添加是否必填属性\n        ArrayList modeRequired = (ArrayList) swaggerMap.get(modeName).get(\"required\");\n\n        if (modeProperties != null) {\n            Iterator<Entry<String, Object>> mIt = modeProperties.entrySet().iterator();\n\n            //解析属性\n            while (mIt.hasNext()) {\n                Entry<String, Object> mEntry = mIt.next();\n                Map<String, Object> attrInfoMap = (Map<String, Object>) mEntry.getValue();\n                ModelAttr child = new ModelAttr();\n                child.setName(mEntry.getKey());\n                child.setType((String) attrInfoMap.get(\"type\"));\n                if (attrInfoMap.get(\"format\") != null) {\n                    child.setType(child.getType() + \"(\" + attrInfoMap.get(\"format\") + \")\");\n                }\n                child.setType(StringUtils.defaultIfBlank(child.getType(), \"object\"));\n\n                Object ref = attrInfoMap.get(\"$ref\");\n                Object items = attrInfoMap.get(\"items\");\n                if (ref != null || (items != null && (ref = ((Map) items).get(\"$ref\")) != null)) {\n                    String refName = ref.toString();\n                    //截取 #/components/ 后面的\n                    String clsName = refName.substring(21);\n                    ModelAttr refModel = getAndPutModelAttr(swaggerMap, resMap, parentName, clsName);\n                    if (refModel != null) {\n                        child.setProperties(refModel.getProperties());\n                    }\n                    child.setType(child.getType() + \":\" + clsName);\n                }\n                child.setDescription((String) attrInfoMap.get(\"description\"));\n\n                child.setRequire(false);\n                if (modeRequired != null && modeRequired.contains(mEntry.getKey())) {\n                    child.setRequire(true);\n                }\n\n                attrList.add(child);\n            }\n        }\n\n        Object title = swaggerMap.get(modeName).get(\"title\");\n        Object description = swaggerMap.get(modeName).get(\"description\");\n        modeAttr.setClassName(title == null ? \"\" : title.toString());\n        modeAttr.setDescription(description == null ? \"\" : description.toString());\n        modeAttr.setProperties(attrList);\n        return modeAttr;\n    }\n\n    /**\n     * 递归生成ModelAttr\n     * 处理schema对象\n     * 处理requestBody直接返回属性值情况\n     */\n    private ModelAttr getRequestSchemaModelAttr(Map<String, Object> schemaMap, ArrayList requiredArr) {\n        ModelAttr modeAttr = new ModelAttr();\n        Map<String, Object> modeProperties = (Map<String, Object>) schemaMap.get(\"properties\");\n\n        if (\"array\".equals(schemaMap.get(\"type\"))) {\n            Map items = (Map<String, Object>) schemaMap.get(\"items\");\n\n            if (items != null) {\n                modeProperties = (Map<String, Object>) items.get(\"properties\");\n            }\n        }\n\n        if (modeProperties == null) {\n            return null;\n        }\n        Iterator<Entry<String, Object>> mIt = modeProperties.entrySet().iterator();\n\n        List<ModelAttr> attrList = new ArrayList<>();\n        //解析属性\n        while (mIt.hasNext()) {\n            Entry<String, Object> mEntry = mIt.next();\n            Map<String, Object> attrInfoMap = (Map<String, Object>) mEntry.getValue();\n            ModelAttr child = new ModelAttr();\n            child.setName(mEntry.getKey());\n            child.setType((String) attrInfoMap.get(\"type\"));\n            if (attrInfoMap.get(\"format\") != null) {\n                child.setType(child.getType() + \"(\" + attrInfoMap.get(\"format\") + \")\");\n            }\n            child.setType(StringUtils.defaultIfBlank(child.getType(), \"object\"));\n\n            Object properties = attrInfoMap.get(\"properties\");\n            Object ref = attrInfoMap.get(\"$ref\");\n            Object items = attrInfoMap.get(\"items\");\n            if (properties != null || (items != null)) {\n                ArrayList<String> childRequiredArr = new ArrayList<String>();\n                if (attrInfoMap.get(\"required\") != null) {\n                    childRequiredArr = (ArrayList<String>) attrInfoMap.get(\"required\");\n                }\n                ModelAttr refModel = getRequestSchemaModelAttr(attrInfoMap, childRequiredArr);\n                if (refModel != null) {\n                    child.setProperties(refModel.getProperties());\n                }\n                child.setType((String) attrInfoMap.get(\"type\"));\n            }\n            child.setRequire(true);\n            if (!requiredArr.contains(mEntry.getKey())) {\n                child.setRequire(false);\n            }\n            child.setDescription((String) attrInfoMap.get(\"description\"));\n            attrList.add(child);\n        }\n        modeAttr.setClassName(\"\");\n        modeAttr.setDescription(\"\");\n        modeAttr.setProperties(attrList);\n        return modeAttr;\n    }\n\n    /**\n     * 递归生成ModelAttr\n     * 处理schema对象\n     * 处理responseData直接返回属性值情况\n     */\n    private ModelAttr getSchemaModelAttr(Map<String, Object> schemaMap) {\n        ModelAttr modeAttr = new ModelAttr();\n        Map<String, Object> modeProperties = (Map<String, Object>) schemaMap.get(\"properties\");\n\n        if (\"array\".equals(schemaMap.get(\"type\"))) {\n            Map items = (Map<String, Object>) schemaMap.get(\"items\");\n\n            if (items != null) {\n                modeProperties = (Map<String, Object>) items.get(\"properties\");\n            }\n        }\n\n        if (modeProperties == null) {\n            return null;\n        }\n        Iterator<Entry<String, Object>> mIt = modeProperties.entrySet().iterator();\n\n        List<ModelAttr> attrList = new ArrayList<>();\n        //解析属性\n        while (mIt.hasNext()) {\n            Entry<String, Object> mEntry = mIt.next();\n            Map<String, Object> attrInfoMap = (Map<String, Object>) mEntry.getValue();\n            ModelAttr child = new ModelAttr();\n            child.setName(mEntry.getKey());\n\n            child.setType((String) attrInfoMap.get(\"type\"));\n            if (attrInfoMap.get(\"format\") != null) {\n                child.setType(child.getType() + \"(\" + attrInfoMap.get(\"format\") + \")\");\n            }\n            child.setType(StringUtils.defaultIfBlank(child.getType(), \"object\"));\n\n            Object properties = attrInfoMap.get(\"properties\");\n            Object ref = attrInfoMap.get(\"$ref\");\n            Object items = attrInfoMap.get(\"items\");\n            if (properties != null || (items != null)) {\n                ModelAttr refModel = getSchemaModelAttr(attrInfoMap);\n                if (refModel != null) {\n                    child.setProperties(refModel.getProperties());\n                }\n                child.setType((String) attrInfoMap.get(\"type\"));\n            }\n            child.setDescription((String) attrInfoMap.get(\"description\"));\n            attrList.add(child);\n        }\n        modeAttr.setClassName(\"\");\n        modeAttr.setDescription(\"\");\n        modeAttr.setProperties(attrList);\n        return modeAttr;\n    }\n\n    /**\n     * 处理返回值\n     *\n     * @param responseObj\n     * @return\n     */\n    private String processResponseParam(Map<String, Object> responseObj, Map<String, ModelAttr> definitinMap) throws JsonProcessingException {\n        Map<String, Map> content = (Map) responseObj.get(\"content\");\n        if (content != null) {\n            Iterator<Map.Entry<String, Map>> applications = content.entrySet().iterator();\n            while (applications.hasNext()) {\n                Map.Entry<String, Map> application = applications.next();\n\n                if (application.getValue() != null) {\n                    Map<String, Object> applicationContent = (Map<String, Object>) application.getValue();\n                    if (applicationContent != null) {\n                        Map<String, Object> schema = (Map<String, Object>) applicationContent.get(\"schema\");\n                        String type = (String) schema.get(\"type\");\n                        String ref = null;\n                        // 数组\n                        if (\"array\".equals(type)) {\n                            Map<String, Object> items = (Map<String, Object>) schema.get(\"items\");\n                            if (items != null && items.get(\"$ref\") != null) {\n                                ref = (String) items.get(\"$ref\");\n                            }\n                        }\n                        // 对象ref\n                        if (schema.get(\"$ref\") != null) {\n                            ref = (String) schema.get(\"$ref\");\n                        }\n                        if (StringUtils.isNotEmpty(ref)) {\n                            ModelAttr modelAttr = definitinMap.get(ref);\n                            if (modelAttr != null && !CollectionUtils.isEmpty(modelAttr.getProperties())) {\n                                Map<String, Object> responseMap = new HashMap<>(8);\n                                for (ModelAttr subModelAttr : modelAttr.getProperties()) {\n                                    responseMap.put(subModelAttr.getName(), getValue(subModelAttr.getType(), subModelAttr));\n                                }\n                                return JsonUtils.writeJsonStr(responseMap);\n                            }\n                        }\n                        if (schema.get(\"properties\") != null) {\n                            ModelAttr modelAttr = getSchemaModelAttr(schema);\n                            if (modelAttr != null) {\n                                Map<String, Object> responseMap = new HashMap<>(8);\n                                for (ModelAttr subModelAttr : modelAttr.getProperties()) {\n                                    responseMap.put(subModelAttr.getName(), getValue(subModelAttr.getType(), subModelAttr));\n                                }\n                                return JsonUtils.writeJsonStr(responseMap);\n                            }\n                        }\n                    }\n                }\n            }\n        }\n        return StringUtils.EMPTY;\n    }\n\n    private String processResponseParam1(Map<String, Object> responseObj, Map<String, ModelAttr> definitinMap) throws JsonProcessingException {\n        Map<String, Map> content = (Map) responseObj.get(\"content\");\n        // if (responseObj != null && content.get(\"application/json\") != null) {\n        if (content != null) {\n            Iterator<Map.Entry<String, Map>> applications = content.entrySet().iterator();\n            while (applications.hasNext()) {\n                Map.Entry<String, Map> application = applications.next();\n\n                if (application.getValue() != null) {\n                    Map<String, Map<String, Map>> applicationContent = (Map<String, Map<String, Map>>) application.getValue();\n                    if (applicationContent != null) {\n                        Map<String, Map> examples = (Map<String, Map>) applicationContent.get(\"examples\");\n\n                        if (examples != null) {\n                            Map<String, Object> responseData = examples.get(\"response\");\n\n                            if (responseData != null) {\n                                Object value = responseData.get(\"value\");\n                                return JsonUtils.writeJsonStr(value);\n                            }\n                        } else {\n                            return \"\";\n                        }\n\n                    }\n                }\n            }\n        }\n        return StringUtils.EMPTY;\n    }\n\n    /**\n     * 封装请求体\n     *\n     * @param list\n     * @return\n     */\n    private String processRequestParam(List<Request> list) throws IOException {\n        Map<String, Object> headerMap = new LinkedHashMap<>();\n        Map<String, Object> queryMap = new LinkedHashMap<>();\n        Map<String, Object> jsonMap = new LinkedHashMap<>();\n        if (list != null && list.size() > 0) {\n            for (Request request : list) {\n                String name = request.getName();\n                String paramType = request.getParamType();\n                Object value = getValue(request.getType(), request.getModelAttr());\n                switch (paramType) {\n                    case \"header\":\n                        headerMap.put(name, value);\n                        break;\n                    case \"query\":\n                        queryMap.put(name, value);\n                        break;\n                    case \"path\":\n                        queryMap.put(name, value);\n                        break;\n                    case \"body\":\n                        //TODO 根据content-type序列化成不同格式，目前只用了json\n                        jsonMap.put(name, value);\n                        break;\n                    default:\n                        break;\n\n                }\n            }\n        }\n        String res = \"\";\n        if (!queryMap.isEmpty()) {\n            res += getUrlParamsByMap(queryMap);\n        }\n        if (!headerMap.isEmpty()) {\n            res += \" \" + getHeaderByMap(headerMap);\n        }\n        if (!jsonMap.isEmpty()) {\n            if (jsonMap.size() == 1) {\n                for (Entry<String, Object> entry : jsonMap.entrySet()) {\n                    res += \" '\" + JsonUtils.writeJsonStr(entry.getValue()) + \"'\";\n                }\n            } else {\n                res += \" '\" + JsonUtils.writeJsonStr(jsonMap) + \"'\";\n            }\n        }\n        return res;\n    }\n\n    /**\n     * 例子中，字段的默认值\n     *\n     * @param type      类型\n     * @param modelAttr 引用的类型\n     * @return\n     */\n    private Object getValue(String type, ModelAttr modelAttr) {\n        int pos;\n        if ((pos = type.indexOf(\":\")) != -1) {\n            type = type.substring(0, pos);\n        }\n        switch (type) {\n            case \"string\":\n                return \"string\";\n            case \"string(date-time)\":\n                return \"2020/01/01 00:00:00\";\n            case \"integer\":\n            case \"integer(int64)\":\n            case \"integer(int32)\":\n                return 0;\n            case \"number\":\n                return 0.0;\n            case \"boolean\":\n                return true;\n            case \"file\":\n                return \"(binary)\";\n            case \"array\":\n                List list = new ArrayList();\n                Map<String, Object> map = new LinkedHashMap<>();\n                if (modelAttr != null && !CollectionUtils.isEmpty(modelAttr.getProperties())) {\n                    for (ModelAttr subModelAttr : modelAttr.getProperties()) {\n                        map.put(subModelAttr.getName(), getValue(subModelAttr.getType(), subModelAttr));\n                    }\n                }\n                list.add(map);\n                return list;\n            case \"object\":\n                map = new LinkedHashMap<>();\n                if (modelAttr != null && !CollectionUtils.isEmpty(modelAttr.getProperties())) {\n                    for (ModelAttr subModelAttr : modelAttr.getProperties()) {\n                        map.put(subModelAttr.getName(), getValue(subModelAttr.getType(), subModelAttr));\n                    }\n                }\n                return map;\n            default:\n                return null;\n        }\n    }\n\n    /**\n     * 将map转换成url\n     */\n    public static String getUrlParamsByMap(Map<String, Object> map) {\n        if (map == null || map.isEmpty()) {\n            return \"\";\n        }\n        StringBuffer sb = new StringBuffer();\n        for (Map.Entry<String, Object> entry : map.entrySet()) {\n            sb.append(entry.getKey() + \"=\" + entry.getValue());\n            sb.append(\"&\");\n        }\n        String s = sb.toString();\n        if (s.endsWith(\"&\")) {\n            s = StringUtils.substringBeforeLast(s, \"&\");\n        }\n        return s;\n    }\n\n    /**\n     * 将map转换成header\n     */\n    public static String getHeaderByMap(Map<String, Object> map) {\n        if (map == null || map.isEmpty()) {\n            return \"\";\n        }\n        StringBuffer sb = new StringBuffer();\n        for (Map.Entry<String, Object> entry : map.entrySet()) {\n            sb.append(\"--header '\");\n            sb.append(entry.getKey() + \":\" + entry.getValue());\n            sb.append(\"'\");\n        }\n        return sb.toString();\n    }\n}"
  },
  {
    "path": "src/main/java/org/word/service/impl/WordServiceImpl.java",
    "content": "package org.word.service.impl;\n\nimport com.fasterxml.jackson.core.JsonProcessingException;\nimport lombok.extern.slf4j.Slf4j;\nimport org.apache.commons.lang3.StringUtils;\nimport org.springframework.beans.factory.annotation.Autowired;\nimport org.springframework.stereotype.Service;\nimport org.springframework.util.CollectionUtils;\nimport org.springframework.web.client.RestTemplate;\nimport org.springframework.web.multipart.MultipartFile;\nimport org.word.model.ModelAttr;\nimport org.word.model.Request;\nimport org.word.model.Response;\nimport org.word.model.Table;\nimport org.word.service.WordService;\nimport org.word.utils.JsonUtils;\n\nimport java.io.IOException;\nimport java.util.*;\nimport java.util.Map.Entry;\nimport java.util.stream.Collectors;\n\n/**\n * @Author XiuYin.Cui\n * @Date 2018/1/12\n **/\n@SuppressWarnings({\"unchecked\", \"rawtypes\"})\n@Slf4j\n@Service\npublic class WordServiceImpl implements WordService {\n\n    @Autowired\n    private RestTemplate restTemplate;\n\n    @Override\n    public Map<String, Object> tableList(String swaggerUrl) {\n        Map<String, Object> resultMap = new HashMap<>();\n        try {\n            String jsonStr = restTemplate.getForObject(swaggerUrl, String.class);\n            resultMap = tableListFromString(jsonStr);\n            log.debug(JsonUtils.writeJsonStr(resultMap));\n        } catch (Exception e) {\n            log.error(\"parse error\", e);\n        }\n        return resultMap;\n    }\n\n    @Override\n    public Map<String, Object> tableListFromString(String jsonStr) {\n        Map<String, Object> resultMap = new HashMap<>();\n        List<Table> result = new ArrayList<>();\n        try {\n            Map<String, Object> map = getResultFromString(result, jsonStr);\n            Map<String, List<Table>> tableMap = result.stream().parallel().collect(Collectors.groupingBy(Table::getTitle));\n            resultMap.put(\"tableMap\", new TreeMap<>(tableMap));\n            resultMap.put(\"info\", map.get(\"info\"));\n\n            log.debug(JsonUtils.writeJsonStr(resultMap));\n        } catch (Exception e) {\n            log.error(\"parse error\", e);\n        }\n        return resultMap;\n    }\n\n    @Override\n    public Map<String, Object> tableList(MultipartFile jsonFile) {\n        Map<String, Object> resultMap = new HashMap<>();\n        List<Table> result = new ArrayList<>();\n        try {\n            String jsonStr = new String(jsonFile.getBytes());\n            resultMap = tableListFromString(jsonStr);\n            log.debug(JsonUtils.writeJsonStr(resultMap));\n        } catch (Exception e) {\n            log.error(\"parse error\", e);\n        }\n        return resultMap;\n    }\n\n    // 处理方案一： 同一路由下所有请求方式合并为一个表格\n    private Map<String, Object> getResultFromString(List<Table> result, String jsonStr) throws IOException {\n        // convert JSON string to Map\n        Map<String, Object> map = JsonUtils.readValue(jsonStr, HashMap.class);\n\n        //解析model\n        Map<String, ModelAttr> definitinMap = parseDefinitions(map);\n\n        //解析paths\n        Map<String, Map<String, Object>> paths = (Map<String, Map<String, Object>>) map.get(\"paths\");\n        if (paths != null) {\n            Iterator<Entry<String, Map<String, Object>>> it = paths.entrySet().iterator();\n            while (it.hasNext()) {\n                Entry<String, Map<String, Object>> path = it.next();\n\n                Iterator<Entry<String, Object>> it2 = path.getValue().entrySet().iterator();\n                // 1.请求路径\n                String url = path.getKey();\n\n                // 2. 循环解析每个子节点，适应同一个路径几种请求方式的场景\n                while (it2.hasNext()) {\n                    Entry<String, Object> request = it2.next();\n\n                    // 2. 请求方式，类似为 get,post,delete,put 这样\n                    String requestType = request.getKey();\n\n                    Map<String, Object> content = (Map<String, Object>) request.getValue();\n\n                    // 4. 大标题（类说明）\n                    String title = String.valueOf(((List) content.get(\"tags\")).get(0));\n\n                    // 5.小标题 （方法说明）\n                    String tag = String.valueOf(content.get(\"summary\"));\n\n                    // 6.接口描述\n                    String description = String.valueOf(content.get(\"summary\"));\n\n                    // 7.请求参数格式，类似于 multipart/form-data\n                    String requestForm = \"\";\n                    List<String> consumes = (List) content.get(\"consumes\");\n                    if (consumes != null && consumes.size() > 0) {\n                        requestForm = StringUtils.join(consumes, \",\");\n                    }\n\n                    // 8.返回参数格式，类似于 application/json\n                    String responseForm = \"\";\n                    List<String> produces = (List) content.get(\"produces\");\n                    if (produces != null && produces.size() > 0) {\n                        responseForm = StringUtils.join(produces, \",\");\n                    }\n\n                    // 9. 请求体\n                    List<LinkedHashMap> parameters = (ArrayList) content.get(\"parameters\");\n\n                    // 10.返回体\n                    Map<String, Object> responses = (LinkedHashMap) content.get(\"responses\");\n\n                    //封装Table\n                    Table table = new Table();\n\n                    table.setTitle(title);\n                    table.setUrl(url);\n                    table.setTag(tag);\n                    table.setDescription(description);\n                    table.setRequestForm(requestForm);\n                    table.setResponseForm(responseForm);\n                    table.setRequestType(requestType);\n                    table.setRequestList(processRequestList(parameters, definitinMap));\n                    table.setResponseList(processResponseCodeList(responses));\n\n                    // 取出来状态是200时的返回值\n                    Map<String, Object> obj = (Map<String, Object>) responses.get(\"200\");\n                    if (obj != null && obj.get(\"schema\") != null) {\n                        table.setModelAttr(processResponseModelAttrs(obj, definitinMap));\n                    }\n\n                    //示例\n                    table.setRequestParam(processRequestParam(table.getRequestList()));\n                    table.setResponseParam(processResponseParam(obj, definitinMap));\n\n                    result.add(table);\n                }\n            }\n        }\n        return map;\n    }\n\n    //  处理方案二： 新增： 同一路由下所有请求方式单独为一个表格\n    /*private Map<String, Object> getResultFromString(List<Table> result, String jsonStr) throws IOException {\n        // convert JSON string to Map\n        Map<String, Object> map = JsonUtils.readValue(jsonStr, HashMap.class);\n\n        //解析model\n        Map<String, ModelAttr> definitinMap = parseDefinitions(map);\n\n        //解析paths\n        Map<String, Map<String, Object>> paths = (Map<String, Map<String, Object>>) map.get(\"paths\");\n\n        //获取全局请求参数格式作为默认请求参数格式\n        List<String> defaultConsumes = (List) map.get(\"consumes\");\n\n        //获取全局响应参数格式作为默认响应参数格式\n        List<String> defaultProduces = (List) map.get(\"produces\");\n\n        if (paths != null) {\n\n            Iterator<Entry<String, Map<String, Object>>> it = paths.entrySet().iterator();\n            while (it.hasNext()) {\n                Entry<String, Map<String, Object>> path = it.next();\n\n                // 0. 获取该路由下所有请求方式的公共参数\n                Map<String, Object> methods = (Map<String, Object>) path.getValue();\n                List<LinkedHashMap> commonParameters = (ArrayList) methods.get(\"parameters\");\n\n                Iterator<Entry<String, Object>> it2 = path.getValue().entrySet().iterator();\n                // 1.请求路径\n                String url = path.getKey();\n\n                while (it2.hasNext()) {\n                    Entry<String, Object> request = it2.next();\n\n                    // 2.请求方式，类似为 get,post,delete,put 这样\n                    String requestType = request.getKey();\n\n                    if (\"parameters\".equals(requestType)) {\n                        continue;\n                    }\n\n                    Map<String, Object> content = (Map<String, Object>) request.getValue();\n\n                    // 4. 大标题（类说明）\n                    String title = String.valueOf(((List) content.get(\"tags\")).get(0));\n\n                    // 5.小标题 （方法说明）\n                    String tag = String.valueOf(content.get(\"operationId\"));\n\n                    // 6.接口描述\n                    String description = String.valueOf(content.get(\"description\"));\n\n                    // 7.请求参数格式，类似于 multipart/form-data\n                    String requestForm = \"\";\n                    List<String> consumes = (List) content.get(\"consumes\");\n                    if (consumes != null && consumes.size() > 0) {\n                        requestForm = StringUtils.join(consumes, \",\");\n                    } else {\n                        requestForm = StringUtils.join(defaultConsumes, \",\");\n                    }\n\n                    // 8.返回参数格式，类似于 application/json\n                    String responseForm = \"\";\n                    List<String> produces = (List) content.get(\"produces\");\n                    if (produces != null && produces.size() > 0) {\n                        responseForm = StringUtils.join(produces, \",\");\n                    } else {\n                        responseForm = StringUtils.join(defaultProduces, \",\");\n                    }\n\n                    // 9. 请求体\n                    List<LinkedHashMap> parameters = (ArrayList) content.get(\"parameters\");\n\n                    if (!CollectionUtils.isEmpty(parameters)) {\n                        if (commonParameters != null) {\n                            parameters.addAll(commonParameters);\n                        }\n                    } else {\n                        if (commonParameters != null) {\n                            parameters = commonParameters;\n                        }\n                    }\n\n                    // 10.返回体\n                    Map<String, Object> responses = (LinkedHashMap) content.get(\"responses\");\n\n                    //封装Table\n                    Table table = new Table();\n\n                    table.setTitle(title);\n                    table.setUrl(url);\n                    table.setTag(tag);\n                    table.setDescription(description);\n                    table.setRequestForm(requestForm);\n                    table.setResponseForm(responseForm);\n                    table.setRequestType(requestType);\n                    table.setRequestList(processRequestList(parameters, definitinMap));\n                    table.setResponseList(processResponseCodeList(responses));\n\n                    // 取出来状态是200时的返回值\n                    Map<String, Object> obj = (Map<String, Object>) responses.get(\"200\");\n                    if (obj != null && obj.get(\"schema\") != null) {\n                        table.setModelAttr(processResponseModelAttrs(obj, definitinMap));\n                    }\n\n                    //示例\n                    table.setRequestParam(processRequestParam(table.getRequestList()));\n                    table.setResponseParam(processResponseParam(obj, definitinMap));\n\n                    result.add(table);\n                }\n            }\n        }\n        return map;\n    }*/\n\n    /**\n     * 处理请求参数列表\n     *\n     * @param parameters\n     * @param definitinMap\n     * @return\n     */\n    private List<Request> processRequestList(List<LinkedHashMap> parameters, Map<String, ModelAttr> definitinMap) {\n        List<Request> requestList = new ArrayList<>();\n        if (!CollectionUtils.isEmpty(parameters)) {\n            for (Map<String, Object> param : parameters) {\n                Object in = param.get(\"in\");\n                Request request = new Request();\n                request.setName(String.valueOf(param.get(\"name\")));\n                request.setType(param.get(\"type\") == null ? \"object\" : param.get(\"type\").toString());\n                if (param.get(\"format\") != null) {\n                    request.setType(request.getType() + \"(\" + param.get(\"format\") + \")\");\n                }\n                request.setParamType(String.valueOf(in));\n                // 考虑对象参数类型\n                if (in != null && \"body\".equals(in)) {\n                    request.setType(String.valueOf(in));\n                    Map<String, Object> schema = (Map) param.get(\"schema\");\n                    Object ref = schema.get(\"$ref\");\n                    // 数组情况另外处理\n                    if (schema.get(\"type\") != null && \"array\".equals(schema.get(\"type\"))) {\n                        ref = ((Map) schema.get(\"items\")).get(\"$ref\");\n                        request.setType(\"array\");\n                    }\n                    if (ref != null) {\n                        request.setType(request.getType() + \":\" + ref.toString().replaceAll(\"#/definitions/\", \"\"));\n                        request.setModelAttr(definitinMap.get(ref));\n                    }\n                }\n                // 是否必填\n                request.setRequire(false);\n                if (param.get(\"required\") != null) {\n                    request.setRequire((Boolean) param.get(\"required\"));\n                }\n                // 参数说明\n                request.setRemark(String.valueOf(param.get(\"description\")));\n                requestList.add(request);\n            }\n        }\n        return requestList;\n    }\n\n\n    /**\n     * 处理返回码列表\n     *\n     * @param responses 全部状态码返回对象\n     * @return\n     */\n    private List<Response> processResponseCodeList(Map<String, Object> responses) {\n        List<Response> responseList = new ArrayList<>();\n        Iterator<Map.Entry<String, Object>> resIt = responses.entrySet().iterator();\n        while (resIt.hasNext()) {\n            Map.Entry<String, Object> entry = resIt.next();\n            Response response = new Response();\n            // 状态码 200 201 401 403 404 这样\n            response.setName(entry.getKey());\n            LinkedHashMap<String, Object> statusCodeInfo = (LinkedHashMap) entry.getValue();\n            response.setDescription(String.valueOf(statusCodeInfo.get(\"description\")));\n            Object schema = statusCodeInfo.get(\"schema\");\n            if (schema != null) {\n                Object originalRef = ((LinkedHashMap) schema).get(\"originalRef\");\n                response.setRemark(originalRef == null ? \"\" : originalRef.toString());\n            }\n            responseList.add(response);\n        }\n        return responseList;\n    }\n\n    /**\n     * 处理返回属性列表\n     *\n     * @param responseObj\n     * @param definitinMap\n     * @return\n     */\n    private ModelAttr processResponseModelAttrs(Map<String, Object> responseObj, Map<String, ModelAttr> definitinMap) {\n        Map<String, Object> schema = (Map<String, Object>) responseObj.get(\"schema\");\n        String type = (String) schema.get(\"type\");\n        String ref = null;\n        //数组\n        if (\"array\".equals(type)) {\n            Map<String, Object> items = (Map<String, Object>) schema.get(\"items\");\n            if (items != null && items.get(\"$ref\") != null) {\n                ref = (String) items.get(\"$ref\");\n            }\n        }\n        //对象\n        if (schema.get(\"$ref\") != null) {\n            ref = (String) schema.get(\"$ref\");\n        }\n\n        //其他类型\n        ModelAttr modelAttr = new ModelAttr();\n        modelAttr.setType(StringUtils.defaultIfBlank(type, StringUtils.EMPTY));\n\n        if (StringUtils.isNotBlank(ref) && definitinMap.get(ref) != null) {\n            modelAttr = definitinMap.get(ref);\n        }\n        return modelAttr;\n    }\n\n    /**\n     * 解析Definition\n     *\n     * @param map\n     * @return\n     */\n    private Map<String, ModelAttr> parseDefinitions(Map<String, Object> map) {\n        Map<String, Map<String, Object>> definitions = (Map<String, Map<String, Object>>) map.get(\"definitions\");\n        Map<String, ModelAttr> definitinMap = new HashMap<>(256);\n        if (definitions != null) {\n            Iterator<String> modelNameIt = definitions.keySet().iterator();\n            while (modelNameIt.hasNext()) {\n                String modeName = modelNameIt.next();\n                getAndPutModelAttr(definitions, definitinMap, modeName);\n            }\n        }\n        return definitinMap;\n    }\n\n    /**\n     * 递归生成ModelAttr\n     * 对$ref类型设置具体属性\n     */\n    private ModelAttr getAndPutModelAttr(Map<String, Map<String, Object>> swaggerMap, Map<String, ModelAttr> resMap, String modeName) {\n        ModelAttr modeAttr;\n        if ((modeAttr = resMap.get(\"#/definitions/\" + modeName)) == null) {\n            modeAttr = new ModelAttr();\n            resMap.put(\"#/definitions/\" + modeName, modeAttr);\n        } else if (modeAttr.isCompleted()) {\n            return resMap.get(\"#/definitions/\" + modeName);\n        }\n        Map<String, Object> modeProperties = (Map<String, Object>) swaggerMap.get(modeName).get(\"properties\");\n        if (modeProperties == null) {\n            return null;\n        }\n\n        List<ModelAttr> attrList = getModelAttrs(swaggerMap, resMap, modeAttr, modeProperties);\n        List allOf = (List) swaggerMap.get(modeName).get(\"allOf\");\n        if (allOf != null) {\n            for (int i = 0; i < allOf.size(); i++) {\n                Map c = (Map) allOf.get(i);\n                if (c.get(\"$ref\") != null) {\n                    String refName = c.get(\"$ref\").toString();\n                    //截取 #/definitions/ 后面的\n                    String clsName = refName.substring(14);\n                    Map<String, Object> modeProperties1 = (Map<String, Object>) swaggerMap.get(clsName).get(\"properties\");\n                    List<ModelAttr> attrList1 = getModelAttrs(swaggerMap, resMap, modeAttr, modeProperties1);\n                    if (attrList1 != null && attrList != null) {\n                        attrList.addAll(attrList1);\n                    } else if (attrList == null && attrList1 != null) {\n                        attrList = attrList1;\n                    }\n                }\n            }\n        }\n\n        Object title = swaggerMap.get(modeName).get(\"title\");\n        Object description = swaggerMap.get(modeName).get(\"description\");\n        modeAttr.setClassName(title == null ? \"\" : title.toString());\n        modeAttr.setDescription(description == null ? \"\" : description.toString());\n        modeAttr.setProperties(attrList);\n        Object required = swaggerMap.get(modeName).get(\"required\");\n        if (Objects.nonNull(required)) {\n            if ((required instanceof List) && !CollectionUtils.isEmpty(attrList)) {\n                List requiredList = (List) required;\n                attrList.stream().filter(m -> requiredList.contains(m.getName())).forEach(m -> m.setRequire(true));\n            } else if (required instanceof Boolean) {\n                modeAttr.setRequire(Boolean.parseBoolean(required.toString()));\n            }\n        }\n        return modeAttr;\n    }\n\n    private List<ModelAttr> getModelAttrs(Map<String, Map<String, Object>> swaggerMap, Map<String, ModelAttr> resMap, ModelAttr modeAttr, Map<String, Object> modeProperties) {\n        Iterator<Entry<String, Object>> mIt = modeProperties.entrySet().iterator();\n\n        List<ModelAttr> attrList = new ArrayList<>();\n\n        //解析属性\n        while (mIt.hasNext()) {\n            Entry<String, Object> mEntry = mIt.next();\n            Map<String, Object> attrInfoMap = (Map<String, Object>) mEntry.getValue();\n            ModelAttr child = new ModelAttr();\n            child.setName(mEntry.getKey());\n            child.setType((String) attrInfoMap.get(\"type\"));\n            if (attrInfoMap.get(\"format\") != null) {\n                child.setType(child.getType() + \"(\" + attrInfoMap.get(\"format\") + \")\");\n            }\n            child.setType(StringUtils.defaultIfBlank(child.getType(), \"object\"));\n\n            Object ref = attrInfoMap.get(\"$ref\");\n            Object items = attrInfoMap.get(\"items\");\n            if (ref != null || (items != null && (ref = ((Map) items).get(\"$ref\")) != null)) {\n                String refName = ref.toString();\n                //截取 #/definitions/ 后面的\n                String clsName = refName.substring(14);\n                modeAttr.setCompleted(true);\n                ModelAttr refModel = getAndPutModelAttr(swaggerMap, resMap, clsName);\n                if (refModel != null) {\n                    child.setProperties(refModel.getProperties());\n                }\n                child.setType(child.getType() + \":\" + clsName);\n            }\n            child.setDescription((String) attrInfoMap.get(\"description\"));\n            attrList.add(child);\n        }\n        return attrList;\n    }\n\n    /**\n     * 处理返回值\n     *\n     * @param responseObj\n     * @return\n     */\n    private String processResponseParam(Map<String, Object> responseObj, Map<String, ModelAttr> definitinMap) throws JsonProcessingException {\n        if (responseObj != null && responseObj.get(\"schema\") != null) {\n            Map<String, Object> schema = (Map<String, Object>) responseObj.get(\"schema\");\n            String type = (String) schema.get(\"type\");\n            String ref = null;\n            // 数组\n            if (\"array\".equals(type)) {\n                Map<String, Object> items = (Map<String, Object>) schema.get(\"items\");\n                if (items != null && items.get(\"$ref\") != null) {\n                    ref = (String) items.get(\"$ref\");\n                }\n            }\n            // 对象\n            if (schema.get(\"$ref\") != null) {\n                ref = (String) schema.get(\"$ref\");\n            }\n            if (StringUtils.isNotEmpty(ref)) {\n                ModelAttr modelAttr = definitinMap.get(ref);\n                if (modelAttr != null && !CollectionUtils.isEmpty(modelAttr.getProperties())) {\n                    Map<String, Object> responseMap = new HashMap<>(8);\n                    for (ModelAttr subModelAttr : modelAttr.getProperties()) {\n                        responseMap.put(subModelAttr.getName(), getValue(subModelAttr.getType(), subModelAttr));\n                    }\n                    return JsonUtils.writeJsonStr(responseMap);\n                }\n            }\n        }\n        return StringUtils.EMPTY;\n    }\n\n    /**\n     * 封装请求体\n     *\n     * @param list\n     * @return\n     */\n    private String processRequestParam(List<Request> list) throws IOException {\n        Map<String, Object> headerMap = new LinkedHashMap<>();\n        Map<String, Object> queryMap = new LinkedHashMap<>();\n        Map<String, Object> jsonMap = new LinkedHashMap<>();\n        if (list != null && list.size() > 0) {\n            for (Request request : list) {\n                String name = request.getName();\n                String paramType = request.getParamType();\n                Object value = getValue(request.getType(), request.getModelAttr());\n                switch (paramType) {\n                    case \"header\":\n                        headerMap.put(name, value);\n                        break;\n                    case \"query\":\n                        queryMap.put(name, value);\n                        break;\n                    case \"body\":\n                        //TODO 根据content-type序列化成不同格式，目前只用了json\n                        jsonMap.put(name, value);\n                        break;\n                    default:\n                        break;\n\n                }\n            }\n        }\n        String res = \"\";\n        if (!queryMap.isEmpty()) {\n            res += getUrlParamsByMap(queryMap);\n        }\n        if (!headerMap.isEmpty()) {\n            res += \" \" + getHeaderByMap(headerMap);\n        }\n        if (!jsonMap.isEmpty()) {\n            if (jsonMap.size() == 1) {\n                for (Entry<String, Object> entry : jsonMap.entrySet()) {\n                    res += \" -d '\" + JsonUtils.writeJsonStr(entry.getValue()) + \"'\";\n                }\n            } else {\n                res += \" -d '\" + JsonUtils.writeJsonStr(jsonMap) + \"'\";\n            }\n        }\n        return res;\n    }\n\n    /**\n     * 例子中，字段的默认值\n     *\n     * @param type      类型\n     * @param modelAttr 引用的类型\n     * @return\n     */\n    private Object getValue(String type, ModelAttr modelAttr) {\n        int pos;\n        if ((pos = type.indexOf(\":\")) != -1) {\n            type = type.substring(0, pos);\n        }\n        switch (type) {\n            case \"string\":\n                return \"string\";\n            case \"string(date-time)\":\n                return \"2020/01/01 00:00:00\";\n            case \"integer\":\n            case \"integer(int64)\":\n            case \"integer(int32)\":\n                return 0;\n            case \"number\":\n                return 0.0;\n            case \"boolean\":\n                return true;\n            case \"file\":\n                return \"(binary)\";\n            case \"array\":\n                List list = new ArrayList();\n                Map<String, Object> map = new LinkedHashMap<>();\n                if (modelAttr != null && !CollectionUtils.isEmpty(modelAttr.getProperties())) {\n                    for (ModelAttr subModelAttr : modelAttr.getProperties()) {\n                        map.put(subModelAttr.getName(), getValue(subModelAttr.getType(), subModelAttr));\n                    }\n                }\n                list.add(map);\n                return list;\n            case \"object\":\n                map = new LinkedHashMap<>();\n                if (modelAttr != null && !CollectionUtils.isEmpty(modelAttr.getProperties())) {\n                    for (ModelAttr subModelAttr : modelAttr.getProperties()) {\n                        map.put(subModelAttr.getName(), getValue(subModelAttr.getType(), subModelAttr));\n                    }\n                }\n                return map;\n            default:\n                return null;\n        }\n    }\n\n    /**\n     * 将map转换成url\n     */\n    public static String getUrlParamsByMap(Map<String, Object> map) {\n        if (CollectionUtils.isEmpty(map)) {\n            return \"\";\n        }\n        StringBuilder sBuilder = new StringBuilder();\n        for (Map.Entry<String, Object> entry : map.entrySet()) {\n            sBuilder.append(entry.getKey() + \"=\" + entry.getValue());\n            sBuilder.append(\"&\");\n        }\n        String s = sBuilder.toString();\n        if (s.endsWith(\"&\")) {\n            s = StringUtils.substringBeforeLast(s, \"&\");\n        }\n        return s;\n    }\n\n    /**\n     * 将map转换成header\n     */\n    public static String getHeaderByMap(Map<String, Object> map) {\n        if (CollectionUtils.isEmpty(map)) {\n            return \"\";\n        }\n        StringBuilder sBuilder = new StringBuilder();\n        for (Map.Entry<String, Object> entry : map.entrySet()) {\n            sBuilder.append(\"--header '\");\n            sBuilder.append(entry.getKey() + \":\" + entry.getValue());\n            sBuilder.append(\"'\");\n        }\n        return sBuilder.toString();\n    }\n}\n"
  },
  {
    "path": "src/main/java/org/word/utils/JsonUtils.java",
    "content": "package org.word.utils;\n\nimport com.fasterxml.jackson.annotation.JsonInclude;\nimport com.fasterxml.jackson.core.JsonParser;\nimport com.fasterxml.jackson.core.JsonProcessingException;\nimport com.fasterxml.jackson.databind.DeserializationFeature;\nimport com.fasterxml.jackson.databind.JavaType;\nimport com.fasterxml.jackson.databind.JsonNode;\nimport com.fasterxml.jackson.databind.ObjectMapper;\nimport com.fasterxml.jackson.databind.node.ArrayNode;\nimport com.fasterxml.jackson.databind.node.ObjectNode;\n\nimport java.io.IOException;\nimport java.util.List;\n\n/**\n * @author cuixiuyin\n * @Date: 2018/11/05\n */\n\npublic class JsonUtils {\n\n    private static ObjectMapper objectMapper = new ObjectMapper();\n\n    static {\n        objectMapper.setSerializationInclusion(JsonInclude.Include.ALWAYS);\n        objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);\n        objectMapper.configure(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES, true);\n        objectMapper.configure(JsonParser.Feature.ALLOW_UNQUOTED_CONTROL_CHARS, true);\n        objectMapper.configure(JsonParser.Feature.ALLOW_SINGLE_QUOTES, true);\n    }\n\n    public static <T> T readValue(String jsonStr, Class<T> clazz) throws IOException {\n        return objectMapper.readValue(jsonStr, clazz);\n    }\n\n    public static <T> List<T> readListValue(String jsonStr, Class<T> clazz) throws IOException {\n        JavaType javaType = objectMapper.getTypeFactory().constructParametricType(List.class, clazz);\n        return objectMapper.readValue(jsonStr, javaType);\n    }\n\n    public static ArrayNode readArray(String jsonStr) throws IOException {\n        JsonNode node = objectMapper.readTree(jsonStr);\n        if (node.isArray()) {\n            return (ArrayNode) node;\n        }\n        return null;\n    }\n\n    public static JsonNode readNode(String jsonStr) throws IOException {\n        return objectMapper.readTree(jsonStr);\n    }\n\n    public static String writeJsonStr(Object obj) throws JsonProcessingException {\n        return objectMapper.writeValueAsString(obj);\n    }\n\n    public static ObjectNode createObjectNode() {\n        return objectMapper.createObjectNode();\n    }\n\n    public static ArrayNode createArrayNode() {\n        return objectMapper.createArrayNode();\n    }\n\n}\n"
  },
  {
    "path": "src/main/java/org/word/utils/MenuUtils.java",
    "content": "package org.word.utils;\n\n/**\n * @author : cuixiuyin\n * @date : 2019/8/31\n */\npublic class MenuUtils {\n\n    public static Integer count = 0;\n    public static String menuStr = \"null\";\n\n    public static boolean isMenu(String tags) {\n        if (menuStr.equals(tags)) {\n            count++;\n        } else {\n            menuStr = tags;\n            count = 0;\n        }\n        if (count == 0) {\n            return true;\n        } else {\n            return false;\n        }\n    }\n}\n"
  },
  {
    "path": "src/main/java/org/word/utils/ModelAttrUtils.java",
    "content": "package org.word.utils;\n\nimport java.util.ArrayList;\nimport java.util.Iterator;\nimport java.util.List;\nimport java.util.Map;\nimport java.util.Map.Entry;\n\nimport org.apache.commons.lang3.StringUtils;\nimport org.word.model.ModelAttr;\n\n/**\n * @author ivenhan\n * @Date: 2020/10/15\n */\n\npublic class ModelAttrUtils {\n\n\t// 封装schema - properties下某个具体property对象\n    public static ModelAttr propertyModelAttr(Map<String, Map<String, Object>> property) {\n    \tModelAttr modeAttr = new ModelAttr();\n\n        Map<String, Object> modeProperties = (Map<String, Object>) property.get(\"properties\");\n        ArrayList modeRequired = (ArrayList) property.get(\"required\");\n        List<ModelAttr> attrList = new ArrayList<>();\n\n    \tif (modeProperties != null) {\n        \tIterator<Entry<String, Object>> mIt = modeProperties.entrySet().iterator();\n\n            //解析属性\n            while (mIt.hasNext()) {\n                Entry<String, Object> mEntry = mIt.next();\n                Map<String, Object> attrInfoMap = (Map<String, Object>) mEntry.getValue();\n                ModelAttr child = new ModelAttr();\n                child.setName(mEntry.getKey());\n                child.setType((String) attrInfoMap.get(\"type\"));\n                if (attrInfoMap.get(\"format\") != null) {\n                    child.setType(child.getType() + \"(\" + attrInfoMap.get(\"format\") + \")\");\n                }\n                child.setType(StringUtils.defaultIfBlank(child.getType(), \"object\"));\n\n                Object ref = attrInfoMap.get(\"$ref\");\n                Object items = attrInfoMap.get(\"items\");\n\n                if (items != null && ((Map) items).get(\"$ref\") == null) {\n            \t\tModelAttr refModel = propertyModelAttr((Map<String, Map<String, Object>>)items);\n\t\t\t\t\tif (refModel != null) {\n\t\t\t\t\t    child.setProperties(refModel.getProperties());\n\t\t\t\t\t}\n\t\t\t\t\tchild.setType(child.getType());\n                }\n\n                child.setDescription((String) attrInfoMap.get(\"description\"));\n\n                child.setRequire(false);\n                if (modeRequired != null && modeRequired.contains(mEntry.getKey())) {\n                    child.setRequire(true);\n                }\n\n                attrList.add(child);\n            }\n        }\n\n        Object title = property.get(\"title\");\n        Object description = property.get(\"description\");\n        modeAttr.setClassName(title == null ? \"\" : title.toString());\n        modeAttr.setDescription(description == null ? \"\" : description.toString());\n        modeAttr.setProperties(attrList);\n        return modeAttr;\n    }\n}"
  },
  {
    "path": "src/main/java/org/word/utils/RequestUtils.java",
    "content": "package org.word.utils;\n\nimport java.util.ArrayList;\nimport java.util.LinkedHashMap;\nimport java.util.Map;\nimport java.util.Map.Entry;\nimport java.util.Set;\n\nimport com.fasterxml.jackson.core.JsonProcessingException;\n\n\n/**\n * @author : ivenhan\n * @date : 2020/10/16\n */\npublic class RequestUtils {\n\n    public static void validateRequestKey(Map<String, Map> content) throws JsonProcessingException {\n\t\tMap<String, Map> applicationJSON = content.get(\"application/json\");\n        if (applicationJSON == null) {\n        \tthrow new JsonProcessingException(\"content字段 缺少 application/json 字段\") {};\n        }\n\n        Map<String, Map> schema = applicationJSON.get(\"schema\");\n        if (schema == null) {\n        \tthrow new JsonProcessingException(\"content字段 application/json 缺少 schema 字段\") {};\n        }\n\n        if (schema.get(\"type\") == null) {\n        \tthrow new JsonProcessingException(\"content字段 application/json 字段 schema 字段 缺少 type字段\") {};\n        }\n    }\n}"
  },
  {
    "path": "src/main/java/org/word/utils/ResponseUtils.java",
    "content": "package org.word.utils;\n\nimport java.util.ArrayList;\nimport java.util.LinkedHashMap;\nimport java.util.Map;\nimport java.util.Map.Entry;\nimport java.util.Set;\n\nimport com.fasterxml.jackson.core.JsonProcessingException;\n\n/**\n * @author : ivenhan\n * @date : 2020/10/16\n */\npublic class ResponseUtils {\n\n    public static void validateResponseKey(Map<String, Map> content) throws JsonProcessingException {\n\t\tMap<String, Map> applicationJSON = content.get(\"application/json\");\n        if (applicationJSON == null) {\n        \tthrow new JsonProcessingException(\"content 字段缺少 application/json 字段\") {};\n        }\n\n        Map<String, Map> schema = applicationJSON.get(\"schema\");\n        if (schema == null) {\n        \tthrow new JsonProcessingException(\"content 字段 application/json 字段 缺少 schema 字段\") {};\n        }\n\n        if (schema.get(\"type\") == null) {\n        \tthrow new JsonProcessingException(\"content 字段 application/json 字段 schema 字段 缺少 type字段\") {};\n        }\n\n        Map items = schema.get(\"items\");\n        Map properties = schema.get(\"properties\");\n        if (items == null && properties == null) {\n        \tthrow new JsonProcessingException(\"content 字段 application/json 字段 schema 字段 缺少  properties 或者 items 字段\") {};\n        }\n\n\n        Set<Entry<String, Map>> contentValues = content.entrySet();\n\n        int size = contentValues.size();\n        if ((applicationJSON.get(\"examples\") != null && size > 2) || (applicationJSON.get(\"examples\") == null && size > 1) ) {\n        \tthrow new JsonProcessingException(\"content 字段存在除 application/json 或者 examples 字段之外的其他字段\") {};\n        }\n    }\n}"
  },
  {
    "path": "src/main/resources/application.yml",
    "content": "server:\n  port: 8080\n  tomcat:\n    max-threads: 800\n    uri-encoding: UTF-8\n\nspring:\n  application:\n    name: swagger2word\n  thymeleaf:\n    prefix: classpath:/templates/\n    suffix: .html\n    cache: false\n    servlet:\n      content-type: text/html\n    enabled: true\n    encoding: UTF-8\n    mode: HTML5\n  servlet:\n    multipart:\n      enabled: true\n      max-file-size: 50MB\n      max-request-size: 50MB\n# Swagger json url address\n# etc. https://petstore.swagger.io/\nswagger.url: https://petstore.swagger.io/v2/swagger.json\n\n\n\n\n\n\n\n"
  },
  {
    "path": "src/main/resources/logback.xml",
    "content": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<configuration>\n    <include resource=\"org/springframework/boot/logging/logback/defaults.xml\"/>\n\n    <appender name=\"CONSOLE\" class=\"ch.qos.logback.core.ConsoleAppender\">\n        <encoder>\n            <pattern>${CONSOLE_LOG_PATTERN}</pattern>\n            <charset>utf8</charset>\n        </encoder>\n    </appender>\n\n    <root level=\"INFO\">\n        <appender-ref ref=\"CONSOLE\"/>\n    </root>\n\n</configuration>"
  },
  {
    "path": "src/main/resources/templates/index.html",
    "content": "<!DOCTYPE html>\n<html>\n<body>\n<h2>Hello Swagger2word !</h2>\n</body>\n</html>\n"
  },
  {
    "path": "src/main/resources/templates/word-en_US.html",
    "content": "<!-- 2020/12/11 - Olivier Bretteville\n    English locale\n-->\n<!DOCTYPE html>\n<html xmlns:th=\"http://www.thymeleaf.org\">\n<head>\n    <meta http-equiv=\"Content-Type\" content=\"application/msword; charset=utf-8\"/>\n    <title>toWord</title>\n        <style type=\"text/css\">\n        .bg {\n            font-family: \"Verdana\", sans-serif;\n            font-size: 14.5px;\n            font-weight: bold;\n            color: #fff;\n            background-color: #00A6D9;\n        }\n\n        table {\n            border-width: 1px;\n            border-style: solid;\n            border-color: black;\n            table-layout: fixed;\n        }\n\n        tr {\n            height: 32px;\n            font-size: 12px;\n        }\n\n        td {\n            padding-left: 10px;\n            border-width: 1px;\n            border-style: solid;\n            border-color: black;\n            height: 32px;\n            overflow: hidden;\n            word-break: break-all;\n            word-wrap: break-word;\n            font-size: 14.5px;\n        }\n\n        .bg td {\n            font-size: 14.5px;\n        }\n\n        tr td {\n            font-size: 14.5px;\n        }\n\n        .specialHeight {\n            height: 40px;\n        }\n\n        .first_title {\n            height: 60px;\n            line-height: 60px;\n            margin: 0;\n            font-weight: bold;\n            font-size: 21px;\n        }\n\n        .second_title {\n            height: 40px;\n            line-height: 40px;\n            margin: 0;\n            font-size: 18.5px;\n        }\n\n        .doc_title {\n            font-size: 42.5px;\n            text-align: center;\n        }\n\n        .download_btn {\n            float: right;\n        }\n\n        body {\n            font-family: Sans-serif;\n        }\n    </style>\n</head>\n\n<body>\n<div style=\"width:1000px; margin: 0 auto\">\n    <div>\n        <p class=\"doc_title\" th:text=\"${info.title +'（'+ info.version +'）'}\"></p>\n        <a class=\"download_btn\" th:if=\"${download == 1}\" th:href=\"${'/downloadWord?url='+ url}\">Download</a>\n        <br>\n    </div>\n    <div th:each=\"tableMap:${tableMap}\" style=\"margin-bottom:20px;\">\n        <!--这个是类的说明-->\n        <h4 class=\"first_title\" th:text=\"${tableMap.key}\"></h4>\n        <div th:each=\"table,tableStat:${tableMap.value}\">\n\n            <!--这个是每个请求的说明，方便生成文档后进行整理-->\n            <h5 class=\"second_title\" th:text=\"${tableStat.count} + '）' + ${table.tag}\"></h5>\n\n            <table border=\"1\" cellspacing=\"0\" cellpadding=\"0\" width=\"100%\">\n                <tr class=\"bg\">\n                    <td colspan=\"8\" th:text=\"${table.tag}\"></td>\n                </tr>\n                <tr>\n                    <td colspan=\"2\" width=\"25%\">Description de l'interface</td>\n                    <td colspan=\"6\" th:text=\"${table.description}\"></td>\n                </tr>\n                <tr>\n                    <td colspan=\"2\">URL</td>\n                    <td colspan=\"6\" th:text=\"${table.url}\"></td>\n                </tr>\n                <tr>\n                    <td colspan=\"2\">HTTP verb</td>\n                    <td colspan=\"6\" th:text=\"${table.requestType}\"></td>\n                </tr>\n                <tr>\n                    <td colspan=\"2\">Content type</td>\n                    <td colspan=\"6\" th:text=\"${table.requestForm}\"></td>\n                </tr>\n                <tr>\n                    <td colspan=\"2\">Response type</td>\n                    <td colspan=\"6\" th:text=\"${table.responseForm}\"></td>\n                </tr>\n\n                <tr class=\"bg\">\n                    <td colspan=\"2\">Parameter name</td>\n                    <td colspan=\"2\">Type</td>\n                    <td colspan=\"1\">Location</td>\n                    <td colspan=\"1\">Mandatory</td>\n                    <td colspan=\"2\">Description</td>\n                </tr>\n\n                <th:block th:each=\"request, c:${table.requestList}\">\n                    <tr>\n                        <td colspan=\"2\" align=\"left\" th:text=\"${c.count} + '.' + ${request.name}\"></td>\n                        <td colspan=\"2\" th:text=\"${request.type}\"></td>\n                        <td colspan=\"1\" th:text=\"${request.paramType}\"></td>\n                        <td colspan=\"1\" th:if=\"${request.require}\" th:text=\"yes\"></td>\n                        <td colspan=\"1\" th:if=\"${!request.require}\" th:text=\"no\"></td>\n                        <td colspan=\"2\" style=\"width:40%\" th:text=\"${request.remark}\"></td>\n                        <!--                        <td th:if=\"${request.modelAttr}\" th:text=\"asdfagadfg\"></td>-->\n                    </tr>\n                    <th:block th:if=\"${request.modelAttr}\">\n                        <tbody th:include=\"this::request(${request.modelAttr.properties},${c.count} + '.', 1)\"/>\n                    </th:block>\n\n\n                </th:block>\n\n                <tr class=\"bg\">\n                    <td colspan=\"2\">Return code</td>\n                    <td colspan=\"3\">Description</td>\n                    <td colspan=\"3\">Comment</td>\n                </tr>\n\n                <tr th:each=\"response:${table.responseList}\">\n                    <td colspan=\"2\" th:text=\"${response.name}\"></td>\n                    <td colspan=\"3\" th:text=\"${response.description}\"></td>\n                    <td colspan=\"3\" th:text=\"${response.remark}\"></td>\n                </tr>\n\n                <tr class=\"bg\">\n                    <td colspan=\"2\">Response format</td>\n                    <td colspan=\"3\">Type</td>\n                    <td colspan=\"3\">Description</td>\n                </tr>\n\n<!--               对返回参数 递归生成行-->\n                <tbody th:include=\"this::response(${table.modelAttr.properties},'', 1)\"/>\n\n                <tr class=\"bg\">\n                    <td colspan=\"8\">Example</td>\n                </tr>\n                <tr class=\"specialHeight\">\n                    <td class=\"bg\">Request</td>\n                    <td colspan=\"7\" th:text=\"${table.requestParam}\"></td>\n                </tr>\n                <tr class=\"specialHeight\">\n                    <td class=\"bg\">Response</td>\n                    <td colspan=\"7\" th:text=\"${table.responseParam}\"></td>\n                </tr>\n\n            </table>\n            <br/>\n        </div>\n    </div>\n</div>\n\n<th:block th:fragment=\"request(properties,count, lv)\">\n    <th:block th:each=\"p,c : ${properties}\">\n        <tr>\n            <td colspan=\"2\" align=\"left\" th:text=\"${count} + '' + ${c.count} + '.' + ${p.name}\"\n                th:style=\"|padding-left:${10*lv}px|\"></td>\n            <td colspan=\"2\" th:text=\"${p.type}\"></td>\n            <td></td>\n            <td th:if=\"${p.require}\" th:text=\"yes\"></td>\n            <td th:if=\"${!p.require}\" th:text=\"no\"></td>\n            <td colspan=\"2\" th:text=\"${p.description}\"></td>\n        </tr>\n        <th:block th:unless=\"${#lists.isEmpty(p.properties)}\"\n                  th:include=\"this::request(${p.properties},${count} + '' + ${c.count} + '.',${lv+1})\"/>\n    </th:block>\n</th:block>\n\n<th:block th:fragment=\"response(properties,count, lv)\">\n    <th:block th:each=\"p,c : ${properties}\">\n        <tr>\n            <td colspan=\"2\" align=\"left\" th:text=\"${count} + '' + ${c.count} + '.' + ${p.name}\"\n                th:style=\"|padding-left:${10*lv}px|\"></td>\n            <td colspan=\"2\" th:text=\"${p.type}\"></td>\n            <td colspan=\"4\" th:text=\"${p.description}\"></td>\n        </tr>\n        <th:block th:unless=\"${#lists.isEmpty(p.properties)}\"\n                  th:include=\"this::response(${p.properties},${count} + '' + ${c.count} + '.',${lv+1})\"/>\n    </th:block>\n</th:block>\n</body>\n</html>\n"
  },
  {
    "path": "src/main/resources/templates/word-fr_FR.html",
    "content": "<!-- 2020/12/11 - Olivier Bretteville\n    French locale\n-->\n<!DOCTYPE html>\n<html xmlns:th=\"http://www.thymeleaf.org\">\n<head>\n    <meta http-equiv=\"Content-Type\" content=\"application/msword; charset=utf-8\"/>\n    <title>toWord</title>\n        <style type=\"text/css\">\n        .bg {\n            font-family: \"Verdana\", sans-serif;\n            font-size: 14.5px;\n            font-weight: bold;\n            color: #fff;\n            background-color: #00A6D9;\n        }\n\n        table {\n            border-width: 1px;\n            border-style: solid;\n            border-color: black;\n            table-layout: fixed;\n        }\n\n        tr {\n            height: 32px;\n            font-size: 12px;\n        }\n\n        td {\n            padding-left: 10px;\n            border-width: 1px;\n            border-style: solid;\n            border-color: black;\n            height: 32px;\n            overflow: hidden;\n            word-break: break-all;\n            word-wrap: break-word;\n            font-size: 14.5px;\n        }\n\n        .bg td {\n            font-size: 14.5px;\n        }\n\n        tr td {\n            font-size: 14.5px;\n        }\n\n        .specialHeight {\n            height: 40px;\n        }\n\n        .first_title {\n            height: 60px;\n            line-height: 60px;\n            margin: 0;\n            font-weight: bold;\n            font-size: 21px;\n        }\n\n        .second_title {\n            height: 40px;\n            line-height: 40px;\n            margin: 0;\n            font-size: 18.5px;\n        }\n\n        .doc_title {\n            font-size: 42.5px;\n            text-align: center;\n        }\n\n        .download_btn {\n            float: right;\n        }\n\n        body {\n            font-family: Sans-serif;\n        }\n    </style>\n</head>\n\n<body>\n<div style=\"width:1000px; margin: 0 auto\">\n    <div>\n        <p class=\"doc_title\" th:text=\"${info.title +'（'+ info.version +'）'}\"></p>\n        <a class=\"download_btn\" th:if=\"${download == 1}\" th:href=\"${'/downloadWord?url='+ url}\">Télécharger</a>\n        <br>\n    </div>\n    <div th:each=\"tableMap:${tableMap}\" style=\"margin-bottom:20px;\">\n        <!--这个是类的说明-->\n        <h4 class=\"first_title\" th:text=\"${tableMap.key}\"></h4>\n        <div th:each=\"table,tableStat:${tableMap.value}\">\n\n            <!--这个是每个请求的说明，方便生成文档后进行整理-->\n            <h5 class=\"second_title\" th:text=\"${tableStat.count} + '）' + ${table.tag}\"></h5>\n\n            <table border=\"1\" cellspacing=\"0\" cellpadding=\"0\" width=\"100%\">\n                <tr class=\"bg\">\n                    <td colspan=\"8\" th:text=\"${table.tag}\"></td>\n                </tr>\n                <tr>\n                    <td colspan=\"2\" width=\"25%\">Description de l'interface</td>\n                    <td colspan=\"6\" th:text=\"${table.description}\"></td>\n                </tr>\n                <tr>\n                    <td colspan=\"2\">URL</td>\n                    <td colspan=\"6\" th:text=\"${table.url}\"></td>\n                </tr>\n                <tr>\n                    <td colspan=\"2\">Verbe HTTP</td>\n                    <td colspan=\"6\" th:text=\"${table.requestType}\"></td>\n                </tr>\n                <tr>\n                    <td colspan=\"2\">Type de requête</td>\n                    <td colspan=\"6\" th:text=\"${table.requestForm}\"></td>\n                </tr>\n                <tr>\n                    <td colspan=\"2\">Type de retour</td>\n                    <td colspan=\"6\" th:text=\"${table.responseForm}\"></td>\n                </tr>\n\n                <tr class=\"bg\">\n                    <td colspan=\"2\">Nom du paramètre</td>\n                    <td colspan=\"2\">Type</td>\n                    <td colspan=\"1\">Emplacement</td>\n                    <td colspan=\"1\">Obligatoire</td>\n                    <td colspan=\"2\">Description</td>\n                </tr>\n\n                <th:block th:each=\"request, c:${table.requestList}\">\n                    <tr>\n                        <td colspan=\"2\" align=\"left\" th:text=\"${c.count} + '.' + ${request.name}\"></td>\n                        <td colspan=\"2\" th:text=\"${request.type}\"></td>\n                        <td colspan=\"1\" th:text=\"${request.paramType}\"></td>\n                        <td colspan=\"1\" th:if=\"${request.require}\" th:text=\"oui\"></td>\n                        <td colspan=\"1\" th:if=\"${!request.require}\" th:text=\"non\"></td>\n                        <td colspan=\"2\" style=\"width:40%\" th:text=\"${request.remark}\"></td>\n                        <!--                        <td th:if=\"${request.modelAttr}\" th:text=\"asdfagadfg\"></td>-->\n                    </tr>\n                    <th:block th:if=\"${request.modelAttr}\">\n                        <tbody th:include=\"this::request(${request.modelAttr.properties},${c.count} + '.', 1)\"/>\n                    </th:block>\n\n\n                </th:block>\n\n                <tr class=\"bg\">\n                    <td colspan=\"2\">Code retour</td>\n                    <td colspan=\"3\">Description</td>\n                    <td colspan=\"3\">Commentaire</td>\n                </tr>\n\n                <tr th:each=\"response:${table.responseList}\">\n                    <td colspan=\"2\" th:text=\"${response.name}\"></td>\n                    <td colspan=\"3\" th:text=\"${response.description}\"></td>\n                    <td colspan=\"3\" th:text=\"${response.remark}\"></td>\n                </tr>\n\n                <tr class=\"bg\">\n                    <td colspan=\"2\">Format de la réponse</td>\n                    <td colspan=\"3\">Type</td>\n                    <td colspan=\"3\">Description</td>\n                </tr>\n\n<!--               对返回参数 递归生成行-->\n                <tbody th:include=\"this::response(${table.modelAttr.properties},'', 1)\"/>\n\n                <tr class=\"bg\">\n                    <td colspan=\"8\">Exemple</td>\n                </tr>\n                <tr class=\"specialHeight\">\n                    <td class=\"bg\">Requête</td>\n                    <td colspan=\"7\" th:text=\"${table.requestParam}\"></td>\n                </tr>\n                <tr class=\"specialHeight\">\n                    <td class=\"bg\">Résultat</td>\n                    <td colspan=\"7\" th:text=\"${table.responseParam}\"></td>\n                </tr>\n\n            </table>\n            <br/>\n        </div>\n    </div>\n</div>\n\n<th:block th:fragment=\"request(properties,count, lv)\">\n    <th:block th:each=\"p,c : ${properties}\">\n        <tr>\n            <td colspan=\"2\" align=\"left\" th:text=\"${count} + '' + ${c.count} + '.' + ${p.name}\"\n                th:style=\"|padding-left:${10*lv}px|\"></td>\n            <td colspan=\"2\" th:text=\"${p.type}\"></td>\n            <td></td>\n            <td th:if=\"${p.require}\" th:text=\"oui\"></td>\n            <td th:if=\"${!p.require}\" th:text=\"non\"></td>\n            <td colspan=\"2\" th:text=\"${p.description}\"></td>\n        </tr>\n        <th:block th:unless=\"${#lists.isEmpty(p.properties)}\"\n                  th:include=\"this::request(${p.properties},${count} + '' + ${c.count} + '.',${lv+1})\"/>\n    </th:block>\n</th:block>\n\n<th:block th:fragment=\"response(properties,count, lv)\">\n    <th:block th:each=\"p,c : ${properties}\">\n        <tr>\n            <td colspan=\"2\" align=\"left\" th:text=\"${count} + '' + ${c.count} + '.' + ${p.name}\"\n                th:style=\"|padding-left:${10*lv}px|\"></td>\n            <td colspan=\"2\" th:text=\"${p.type}\"></td>\n            <td colspan=\"4\" th:text=\"${p.description}\"></td>\n        </tr>\n        <th:block th:unless=\"${#lists.isEmpty(p.properties)}\"\n                  th:include=\"this::response(${p.properties},${count} + '' + ${c.count} + '.',${lv+1})\"/>\n    </th:block>\n</th:block>\n</body>\n</html>\n"
  },
  {
    "path": "src/main/resources/templates/word-zh_CN.html",
    "content": "<!DOCTYPE html>\n<html xmlns:th=\"http://www.thymeleaf.org\">\n<head>\n    <meta http-equiv=\"Content-Type\" content=\"application/msword; charset=utf-8\"/>\n    <title>toWord</title>\n        <style type=\"text/css\">\n        .bg {\n            font-size: 14.5px;\n            font-weight: bold;\n            color: #000;\n            background-color: #559e68;\n        }\n\n        table {\n            border-width: 1px;\n            border-style: solid;\n            border-color: black;\n            table-layout: fixed;\n        }\n\n        tr {\n            height: 32px;\n            font-size: 12px;\n        }\n\n        td {\n            padding-left: 10px;\n            border-width: 1px;\n            border-style: solid;\n            border-color: black;\n            height: 32px;\n            overflow: hidden;\n            word-break: break-all;\n            word-wrap: break-word;\n            font-size: 14.5px;\n        }\n\n        .bg td {\n            font-size: 14.5px;\n        }\n\n        tr td {\n            font-size: 14.5px;\n        }\n\n        .specialHeight {\n            height: 40px;\n        }\n\n        .first_title {\n            height: 60px;\n            line-height: 60px;\n            margin: 0;\n            font-weight: bold;\n            font-size: 21px;\n        }\n\n        .second_title {\n            height: 40px;\n            line-height: 40px;\n            margin: 0;\n            font-size: 18.5px;\n        }\n\n        .doc_title {\n            font-size: 42.5px;\n            text-align: center;\n        }\n\n        .download_btn {\n            float: right;\n        }\n\n        body {\n            font-family: 思源黑体 Normal;\n        }\n    </style>\n</head>\n\n<body>\n<div style=\"width:1000px; margin: 0 auto\">\n    <div>\n        <p class=\"doc_title\" th:text=\"${info.title +'（'+ info.version +'）'}\"></p>\n        <a class=\"download_btn\" th:if=\"${download == 1}\" th:href=\"${'/downloadWord?url='+ url}\">下载文档</a>\n        <br>\n    </div>\n    <div th:each=\"tableMap:${tableMap}\" style=\"margin-bottom:20px;\">\n        <!--这个是类的说明-->\n        <h4 class=\"first_title\" th:text=\"${tableMap.key}\"></h4>\n        <div th:each=\"table,tableStat:${tableMap.value}\">\n\n            <!--这个是每个请求的说明，方便生成文档后进行整理-->\n            <h5 class=\"second_title\" th:text=\"${tableStat.count} + '）' + ${table.tag}\"></h5>\n\n            <table border=\"1\" cellspacing=\"0\" cellpadding=\"0\" width=\"100%\">\n                <tr class=\"bg\">\n                    <td colspan=\"5\" th:text=\"${table.tag}\"></td>\n                </tr>\n                <tr>\n                    <td width=\"25%\">接口描述</td>\n                    <td colspan=\"4\" th:text=\"${table.description}\"></td>\n                </tr>\n                <tr>\n                    <td>URL</td>\n                    <td colspan=\"4\" th:text=\"${table.url}\"></td>\n                </tr>\n                <tr>\n                    <td>请求方式</td>\n                    <td colspan=\"4\" th:text=\"${table.requestType}\"></td>\n                </tr>\n                <tr>\n                    <td>请求类型</td>\n                    <td colspan=\"4\" th:text=\"${table.requestForm}\"></td>\n                </tr>\n                <tr>\n                    <td>返回类型</td>\n                    <td colspan=\"4\" th:text=\"${table.responseForm}\"></td>\n                </tr>\n\n                <tr class=\"bg\">\n                    <td>参数名</td>\n                    <td width=\"15%\">数据类型</td>\n                    <td width=\"15%\">参数类型</td>\n                    <td width=\"15%\">是否必填</td>\n                    <td width=\"29%\">说明</td>\n                </tr>\n\n                <th:block th:each=\"request, c:${table.requestList}\">\n                    <tr>\n                        <td align=\"left\" th:text=\"${c.count} + '.' + ${request.name}\"></td>\n                        <td th:text=\"${request.type}\"></td>\n                        <td th:text=\"${request.paramType}\"></td>\n                        <td th:if=\"${request.require}\" th:text=\"Y\"></td>\n                        <td th:if=\"${!request.require}\" th:text=\"N\"></td>\n                        <td th:text=\"${request.remark}\"></td>\n                        <!--                        <td th:if=\"${request.modelAttr}\" th:text=\"asdfagadfg\"></td>-->\n                    </tr>\n                    <th:block th:if=\"${request.modelAttr}\">\n                        <tbody th:include=\"this::request(${request.modelAttr.properties},${c.count} + '.', 1)\"/>\n                    </th:block>\n\n\n                </th:block>\n\n                <tr class=\"bg\">\n                    <td>状态码</td>\n                    <td colspan=\"2\">描述</td>\n                    <td colspan=\"2\">说明</td>\n                </tr>\n\n                <tr th:each=\"response:${table.responseList}\">\n                    <td th:text=\"${response.name}\"></td>\n                    <td colspan=\"2\" th:text=\"${response.description}\"></td>\n                    <td colspan=\"2\" th:text=\"${response.remark}\"></td>\n                </tr>\n\n                <tr class=\"bg\">\n                    <td>返回属性名</td>\n                    <td colspan=\"2\">类型</td>\n                    <td colspan=\"2\">说明</td>\n                </tr>\n\n<!--               对返回参数 递归生成行-->\n                <tbody th:include=\"this::response(${table.modelAttr.properties},'', 1)\"/>\n\n                <tr class=\"bg\">\n                    <td colspan=\"5\">示例</td>\n                </tr>\n                <tr class=\"specialHeight\">\n                    <td class=\"bg\">请求参数</td>\n                    <td colspan=\"4\" th:text=\"${table.requestParam}\"></td>\n                </tr>\n                <tr class=\"specialHeight\">\n                    <td class=\"bg\">返回值</td>\n                    <td colspan=\"4\" th:text=\"${table.responseParam}\"></td>\n                </tr>\n\n            </table>\n        </div>\n    </div>\n</div>\n\n<th:block th:fragment=\"request(properties,count, lv)\">\n    <th:block th:each=\"p,c : ${properties}\">\n        <tr>\n            <td align=\"left\" th:text=\"${count} + '' + ${c.count} + '.' + ${p.name}\"\n                th:style=\"|padding-left:${10*lv}px|\"></td>\n            <td th:text=\"${p.type}\"></td>\n            <td></td>\n            <td th:if=\"${p.require}\" th:text=\"Y\"></td>\n            <td th:if=\"${!p.require}\" th:text=\"N\"></td>\n            <td th:text=\"${p.description}\"></td>\n        </tr>\n        <th:block th:unless=\"${#lists.isEmpty(p.properties)}\"\n                  th:include=\"this::request(${p.properties},${count} + '' + ${c.count} + '.',${lv+1})\"/>\n    </th:block>\n</th:block>\n\n<th:block th:fragment=\"response(properties,count, lv)\">\n    <th:block th:each=\"p,c : ${properties}\">\n        <tr>\n            <td align=\"left\" th:text=\"${count} + '' + ${c.count} + '.' + ${p.name}\"\n                th:style=\"|padding-left:${10*lv}px|\"></td>\n            <td colspan=\"2\" th:text=\"${p.type}\"></td>\n            <td colspan=\"2\" th:text=\"${p.description}\"></td>\n        </tr>\n        <th:block th:unless=\"${#lists.isEmpty(p.properties)}\"\n                  th:include=\"this::response(${p.properties},${count} + '' + ${c.count} + '.',${lv+1})\"/>\n    </th:block>\n</th:block>\n</body>\n</html>\n"
  },
  {
    "path": "src/main/resources/templates/word.html",
    "content": "<!DOCTYPE html>\n<html xmlns:th=\"http://www.thymeleaf.org\">\n<head>\n    <meta http-equiv=\"Content-Type\" content=\"application/msword; charset=utf-8\"/>\n    <title>toWord</title>\n    <style type=\"text/css\">\n        .bg {\n            font-size: 14.5px;\n            font-weight: bold;\n            color: #000;\n            background-color: #559e68;\n        }\n\n        table {\n            border-width: 1px;\n            border-style: solid;\n            border-color: black;\n            table-layout: fixed;\n        }\n\n        tr {\n            height: 32px;\n            font-size: 12px;\n        }\n\n        td {\n            padding-left: 10px;\n            border-width: 1px;\n            border-style: solid;\n            border-color: black;\n            height: 32px;\n            overflow: hidden;\n            word-break: break-all;\n            word-wrap: break-word;\n            font-size: 14.5px;\n        }\n\n        .bg td {\n            font-size: 14.5px;\n        }\n\n        tr td {\n            font-size: 14.5px;\n        }\n\n        .specialHeight {\n            height: 40px;\n        }\n\n        .first_title {\n            height: 60px;\n            line-height: 60px;\n            margin: 0;\n            font-weight: bold;\n            font-size: 21px;\n        }\n\n        .second_title {\n            height: 40px;\n            line-height: 40px;\n            margin: 0;\n            font-size: 18.5px;\n        }\n\n        .doc_title {\n            font-size: 42.5px;\n            text-align: center;\n        }\n\n        .download_btn {\n            float: right;\n        }\n\n        body {\n            font-family: 思源黑体 Normal;\n        }\n    </style>\n</head>\n\n<body>\n<div style=\"width:800px; margin: 0 auto\">\n    <div>\n        <p class=\"doc_title\" th:text=\"${info.title +'（'+ info.version +'）'}\"></p>\n        <a class=\"download_btn\" th:if=\"${download == 1}\" th:href=\"${'/downloadWord?url='+ url}\">下载文档</a>\n        <br>\n    </div>\n    <div th:each=\"tableMap:${tableMap}\" style=\"margin-bottom:20px;\">\n        <!--这个是类的说明-->\n        <h4 class=\"first_title\" th:text=\"${tableMap.key}\"></h4>\n        <div th:each=\"table,tableStat:${tableMap.value}\">\n\n            <!--这个是每个请求的说明，方便生成文档后进行整理-->\n            <h5 class=\"second_title\" th:text=\"${tableStat.count} + '）' + ${table.tag}\"></h5>\n\n            <table border=\"1\" cellspacing=\"0\" cellpadding=\"0\" width=\"100%\">\n                <tr class=\"bg\">\n                    <td colspan=\"5\" th:text=\"${table.tag}\"></td>\n                </tr>\n                <tr>\n                    <td width=\"25%\">接口描述</td>\n                    <td colspan=\"4\" th:text=\"${table.description}\"></td>\n                </tr>\n                <tr>\n                    <td>URL</td>\n                    <td colspan=\"4\" th:text=\"${table.url}\"></td>\n                </tr>\n                <tr>\n                    <td>请求方式</td>\n                    <td colspan=\"4\" th:text=\"${#strings.toUpperCase(table.requestType)}\"></td>\n                </tr>\n                <tr>\n                    <td>请求类型</td>\n                    <td colspan=\"4\" th:text=\"${table.requestForm}\"></td>\n                </tr>\n                <tr>\n                    <td>返回类型</td>\n                    <td colspan=\"4\" th:text=\"${table.responseForm}\"></td>\n                </tr>\n\n                <tr class=\"bg\">\n                    <td>参数名</td>\n                    <td width=\"15%\">数据类型</td>\n                    <td width=\"15%\">参数类型</td>\n                    <td width=\"15%\">是否必填</td>\n                    <td width=\"29%\">说明</td>\n                </tr>\n\n                <th:block th:each=\"request, c:${table.requestList}\">\n                    <tr>\n                        <td align=\"left\" th:text=\"${c.count} + '.' + ${request.name}\"></td>\n                        <td th:text=\"${request.type}\"></td>\n                        <td th:text=\"${request.paramType}\"></td>\n                        <td th:if=\"${request.require}\" th:text=\"Y\"></td>\n                        <td th:if=\"${!request.require}\" th:text=\"N\"></td>\n                        <td th:text=\"${request.remark}\"></td>\n                        <!--                        <td th:if=\"${request.modelAttr}\" th:text=\"asdfagadfg\"></td>-->\n                    </tr>\n                    <th:block th:if=\"${request.modelAttr}\">\n                        <tbody th:include=\"this::request(${request.modelAttr.properties},${c.count} + '.', 1)\"/>\n                    </th:block>\n\n\n                </th:block>\n\n                <tr class=\"bg\">\n                    <td>状态码</td>\n                    <td colspan=\"2\">描述</td>\n                    <td colspan=\"2\">说明</td>\n                </tr>\n\n                <tr th:each=\"response:${table.responseList}\">\n                    <td th:text=\"${response.name}\"></td>\n                    <td colspan=\"2\" th:text=\"${response.description}\"></td>\n                    <td colspan=\"2\" th:text=\"${response.remark}\"></td>\n                </tr>\n\n                <tr class=\"bg\">\n                    <td>返回属性名</td>\n                    <td colspan=\"2\">类型</td>\n                    <td colspan=\"2\">说明</td>\n                </tr>\n\n                <!--               对返回参数 递归生成行-->\n                <tbody th:include=\"this::response(${table.modelAttr.properties},'', 1)\"/>\n\n                <tr class=\"bg\">\n                    <td colspan=\"5\">示例</td>\n                </tr>\n                <tr class=\"specialHeight\">\n                    <td class=\"bg\">请求参数</td>\n                    <td colspan=\"4\" th:text=\"${table.requestParam}\"></td>\n                </tr>\n                <tr class=\"specialHeight\">\n                    <td class=\"bg\">返回值</td>\n                    <td colspan=\"4\" th:text=\"${table.responseParam}\"></td>\n                </tr>\n\n            </table>\n        </div>\n    </div>\n</div>\n\n<th:block th:fragment=\"request(properties,count, lv)\">\n    <th:block th:each=\"p,c : ${properties}\">\n        <tr>\n            <td align=\"left\" th:text=\"${count} + '' + ${c.count} + '.' + ${p.name}\"\n                th:style=\"|padding-left:${10*lv}px|\"></td>\n            <td th:text=\"${p.type}\"></td>\n            <td></td>\n            <td th:if=\"${p.require}\" th:text=\"Y\"></td>\n            <td th:if=\"${!p.require}\" th:text=\"N\"></td>\n            <td th:text=\"${p.description}\"></td>\n        </tr>\n        <th:block th:unless=\"${#lists.isEmpty(p.properties)}\"\n                  th:include=\"this::request(${p.properties},${count} + '' + ${c.count} + '.',${lv+1})\"/>\n    </th:block>\n</th:block>\n\n<th:block th:fragment=\"response(properties,count, lv)\">\n    <th:block th:each=\"p,c : ${properties}\">\n        <tr>\n            <td align=\"left\" th:text=\"${count} + '' + ${c.count} + '.' + ${p.name}\"\n                th:style=\"|padding-left:${10*lv}px|\"></td>\n            <td colspan=\"2\" th:text=\"${p.type}\"></td>\n            <td colspan=\"2\" th:text=\"${p.description}\"></td>\n        </tr>\n        <th:block th:unless=\"${#lists.isEmpty(p.properties)}\"\n                  th:include=\"this::response(${p.properties},${count} + '' + ${c.count} + '.',${lv+1})\"/>\n    </th:block>\n</th:block>\n</body>\n</html>\n"
  }
]