From a5e6d8644b62d313d8fc267b1dd627c9da23f1a1 Mon Sep 17 00:00:00 2001 From: duanledexianxianxian Date: Fri, 27 Mar 2020 15:53:28 +0800 Subject: [PATCH] =?UTF-8?q?=E7=94=9F=E6=88=90markdown=20api=E6=96=87?= =?UTF-8?q?=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/kim/apidoc/core/schema/Section.java | 8 +- .../src/main/resources/templates/markdown.ftl | 120 +++++++++--------- .../com/kim/apidoc/springmvc/SpringTest.java | 2 +- 3 files changed, 68 insertions(+), 62 deletions(-) diff --git a/apidoc-core/src/main/java/com/kim/apidoc/core/schema/Section.java b/apidoc-core/src/main/java/com/kim/apidoc/core/schema/Section.java index 7cd8918..4f1c719 100644 --- a/apidoc-core/src/main/java/com/kim/apidoc/core/schema/Section.java +++ b/apidoc-core/src/main/java/com/kim/apidoc/core/schema/Section.java @@ -21,19 +21,19 @@ import java.util.*; public class Section extends Node { /** - * The Method. + * 请求方法. */ Method method; /** - * The Uri. + * 请求url. */ String uri; /** - * The In headers. + * 请求头. */ Map inHeaders = new LinkedHashMap<>(); /** - * The Path variable. + * 路径变量. */ ObjectNode pathVariable = ObjectMappers.instance.createObjectNode(); /** diff --git a/apidoc-core/src/main/resources/templates/markdown.ftl b/apidoc-core/src/main/resources/templates/markdown.ftl index 0da6d53..421b1b8 100644 --- a/apidoc-core/src/main/resources/templates/markdown.ftl +++ b/apidoc-core/src/main/resources/templates/markdown.ftl @@ -6,78 +6,84 @@ <#-- ---------- BEGIN 循环遍历book ----------> <#if books??> <#list books as bookKey,bookValue> - ${bookKey} <#if bookValue.name??> + +<#--book名称--> # ${bookValue.name} - + <#-- ---------- BEGIN 循环遍历chapter ----------> <#list bookValue.chapters> <#items as chapter> + + + +<#-- 章节名称--> ## ${chapter?counter}. ${chapter.name} +<#-- 章节描述--> + <#if chapter.description??> ${chapter.description} - + + <#-- ---------- BEGIN 循环遍历section ----------> <#list chapter.sections> <#items as section> - ### ${chapter?counter}.${section?counter} ${section.name} - - ${section.description} - - **request** - ```HTTP - POST /api/v1/users HTTP/1.1 - - { - "loginId":"admin", - "userName":"123456", - "passwords":"123456" - } - ``` - - **header** - - | Field | Type | Condition | Default | Description | - | :------- | :----- | :-------- | :------ | :---------- | - | loginId | String | | | 用户编号 | - | userName | String | | | 用户名 | - | password | String | | | 密码 | - - **query** - - | Field | Type | Condition | Default | Description | - | :------- | :----- | :-------- | :------ | :---------- | - <#list section.requestRows as rowKey,rowValue> - | rowValue.key | rowValue.type | rowValue.condition | rowValue.def | rowValue.remark | +<#-- 接口名称--> +### ${chapter?counter}.${section?counter} ${section.name} +<#-- 接口描述--> + <#if section.description??> + +${section.description} + + +<#-- 请求--> +**Request** + +<#-- 请求示例--> +```HTTP +${section.method} ${section.uri!''} HTTP/1.1 + <#if section.inHeaders??> + <#list section.inHeaders as inHeaderKey,inHeaderValue> +${inHeaderValue!''} + + + <#if section.hasRequestBody()> + +${section.getParameterString()} + +``` +<#-- 请求参数table列表--> + <#if section.requestRows?? && (section.requestRows?size>0)> + +**Query** +| Field | Type | Condition | Default | Description | +| :------- | :----- | :-------- | :------ | :---------- | + <#list section.requestRows as rowKey,rowValue> +| ${rowValue.key!''} | ${rowValue.type!''} | ${rowValue.condition!''} | ${rowValue.def!''} | ${rowValue.remark!''} | + + +<#-- 响应--> + <#if section.hasResponseBody()> +**Response** +``` +${section.getResponseString()} +``` + +<#-- 响应参数table列表--> + <#if section.responseRows?? && (section.responseRows?size>0)> + +| Field | Type | Description | +| :------- | :----- | :---------- | + <#list section.responseRows as rowKey,rowValue> +| ${rowValue.key!''} | ${rowValue.type!''} | ${rowValue.remark!''} | - - **body** - - | Field | Type | Condition | Default | Description | - | :------- | :----- | :-------- | :------ | :---------- | - | loginId | String | | | 用户编号 | - | userName | String | | | 用户名 | - | password | String | | | 密码 | - - **response** - - ``` - { - "loginId":"admin", - "userName":"123456", - "passwords":"123456" - } - ``` - - | Field | Type | Description | - | :------- | :----- | :---------- | - | loginId | String | 用户编号 | - | userName | String | 用户名 | - | password | String | 密码 | + + <#------------ END 循环遍历section ----------> + <#------------ END 循环遍历chapter ----------> - <#------------ END 循环遍历book ----------> + diff --git a/apidoc-springmvc/src/test/java/com/kim/apidoc/springmvc/SpringTest.java b/apidoc-springmvc/src/test/java/com/kim/apidoc/springmvc/SpringTest.java index 23b6e0d..824168d 100644 --- a/apidoc-springmvc/src/test/java/com/kim/apidoc/springmvc/SpringTest.java +++ b/apidoc-springmvc/src/test/java/com/kim/apidoc/springmvc/SpringTest.java @@ -17,7 +17,7 @@ public class SpringTest { Context context = new Context(); context.setId("test"); context.setName("测试项目"); - context.addSource(Paths.get("K:\\@project-dianli@\\tool\\apidoc\\apidoc-springmvc\\src\\test\\java")); + context.addSource(Paths.get("F:\\@project@\\@dianli@\\tool\\apidoc\\apidoc-springmvc\\src\\test\\java")); // context.setCss("https://darshandsoni.com/asciidoctor-skins/css/monospace.css"); ApiDoc apigcc = new ApiDoc(context); -- GitLab