diff --git a/apidoc-core/src/main/java/com/kim/apidoc/core/common/QueryStringBuilder.java b/apidoc-core/src/main/java/com/kim/apidoc/core/common/QueryStringBuilder.java index 1bfb72783e2d26fbb16bc0ae172f1cd22d6b51a2..a5886cbcfa00bbe40073d4784eb079b058463263 100644 --- a/apidoc-core/src/main/java/com/kim/apidoc/core/common/QueryStringBuilder.java +++ b/apidoc-core/src/main/java/com/kim/apidoc/core/common/QueryStringBuilder.java @@ -9,8 +9,8 @@ public class QueryStringBuilder { private StringBuilder builder = new StringBuilder(); - public QueryStringBuilder append(Object key, Object value){ - if(builder.length()>0){ + public QueryStringBuilder append(Object key, Object value) { + if (builder.length() > 0) { builder.append("&"); } builder.append(key); @@ -19,21 +19,21 @@ public class QueryStringBuilder { return this; } - public QueryStringBuilder append(ObjectNode objectNode){ + public QueryStringBuilder append(ObjectNode objectNode) { Iterator iterator = objectNode.fieldNames(); - while (iterator.hasNext()){ + while (iterator.hasNext()) { String key = iterator.next(); JsonNode valueNode = objectNode.get(key); - String value = valueNode.isTextual()?valueNode.asText():valueNode.toString(); - append(key,value); + String value = valueNode.isTextual() ? valueNode.asText() : valueNode.toString(); + append(key, value); } return this; } - public String toString(){ + @Override + public String toString() { return builder.toString(); } - } diff --git a/apidoc-core/src/main/java/com/kim/apidoc/core/common/URI.java b/apidoc-core/src/main/java/com/kim/apidoc/core/common/URI.java index c053981509d2bf8603e3d1446bef3a88879d9726..3ae00f58f2d7cf892527ffadfbc70ac3c0115100 100644 --- a/apidoc-core/src/main/java/com/kim/apidoc/core/common/URI.java +++ b/apidoc-core/src/main/java/com/kim/apidoc/core/common/URI.java @@ -24,34 +24,34 @@ public class URI { this.text = text; } - public URI add(String text){ + public URI add(String text) { return add(new URI(text)); } - public URI add(URI uri){ - if(next!=null){ + public URI add(URI uri) { + if (next != null) { next.add(uri); - }else{ + } else { next = uri; } return this; } - public void remove(URI uri){ - if(Objects.equals(next,uri)){ + public void remove(URI uri) { + if (Objects.equals(next, uri)) { next = null; - }else{ + } else { next.remove(uri); } } @Override - public String toString(){ + public String toString() { List list = new ArrayList<>(); appendTo(list); StringBuilder builder = new StringBuilder(); for (String text : list) { - if(StringHelper.nonBlank(text)){ + if (StringHelper.nonBlank(text)) { builder.append("/"); builder.append(text); } @@ -59,11 +59,11 @@ public class URI { return builder.toString(); } - private void appendTo(List list){ - if(Objects.nonNull(text)){ + private void appendTo(List list) { + if (Objects.nonNull(text)) { list.addAll(Lists.newArrayList(text.split("/"))); } - if(next!=null){ + if (next != null) { next.appendTo(list); } } 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 00da4e253dad1e3b9fdb5554faffbcad1c894889..dcbd1e5134f6e85c303432c92b6c7825e8f5b0da 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 @@ -7,6 +7,7 @@ import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.node.ObjectNode; import lombok.Getter; import lombok.Setter; +import org.apache.commons.lang3.StringUtils; import java.util.*; @@ -44,12 +45,10 @@ public class Section extends Node { * The Query parameter. */ boolean queryParameter = true; - /** * The Request rows. */ Map requestRows = new LinkedHashMap<>(); - /** * The Out headers. */ @@ -67,6 +66,13 @@ public class Section extends Node { */ Object rawResponse; + public void setUri(String uri) { + String value = ""; + if (StringUtils.isNotBlank(uri)) { + value = uri.replaceAll("\\{", ":").replaceAll("}", ""); + } + this.uri = value; + } /** * Add request row. diff --git a/apidoc-core/src/main/resources/templates/markdown.ftl b/apidoc-core/src/main/resources/templates/markdown.ftl index d258fc7b659c6241573ea8e3255424e07b673203..814d6dd2cbd8a53edab904069881280b711debd7 100644 --- a/apidoc-core/src/main/resources/templates/markdown.ftl +++ b/apidoc-core/src/main/resources/templates/markdown.ftl @@ -72,10 +72,10 @@ ${section.getResponseString()} <#-- 响应参数table列表--> <#if section.responseRows?? && (section.responseRows?size>0)> -| 字段 | 类型 | 描述 | -| :------- | :----- | :---------- | +| 字段 | 类型 | 默认值 | 描述 | +| :------- | :----- |:----- | :---------- | <#list section.responseRows as rowKey,rowValue> -| ${rowValue.key!''} | ${rowValue.type!''} | ${rowValue.remark!''} | +| ${rowValue.key!''} | ${rowValue.type!''} | ${rowValue.def!''} | ${rowValue.remark!''} | diff --git a/apidoc-springmvc/src/test/java/com/kim/apidoc/example/common/Query.java b/apidoc-springmvc/src/test/java/com/kim/apidoc/example/common/Query.java index fe8ab31ee15897f2f4600f52f3056714b4136d8b..81ab609bd0f8152d50ff7b407350a8101ffe808d 100644 --- a/apidoc-springmvc/src/test/java/com/kim/apidoc/example/common/Query.java +++ b/apidoc-springmvc/src/test/java/com/kim/apidoc/example/common/Query.java @@ -15,6 +15,6 @@ public class Query { /** * 查询关键字 */ - String q = ""; + String q = "123"; } diff --git a/apidoc-springmvc/src/test/java/com/kim/apidoc/example/spring/advanced/KimUserController.java b/apidoc-springmvc/src/test/java/com/kim/apidoc/example/spring/advanced/UserController.java similarity index 74% rename from apidoc-springmvc/src/test/java/com/kim/apidoc/example/spring/advanced/KimUserController.java rename to apidoc-springmvc/src/test/java/com/kim/apidoc/example/spring/advanced/UserController.java index 3a54ae5683d027d0106ef1d8d7ee6eb024e17190..d7d4c685e5baaa467f7cbaeb0db28a793dabb022 100644 --- a/apidoc-springmvc/src/test/java/com/kim/apidoc/example/spring/advanced/KimUserController.java +++ b/apidoc-springmvc/src/test/java/com/kim/apidoc/example/spring/advanced/UserController.java @@ -3,8 +3,6 @@ package com.kim.apidoc.example.spring.advanced; import com.kim.apidoc.example.annotation.KimController; import com.kim.apidoc.example.common.Query; import com.kim.apidoc.example.common.User; -import com.kim.apidoc.example.common.ResultData; -import com.kim.apidoc.example.common.ResultData; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; @@ -21,18 +19,18 @@ import org.springframework.web.bind.annotation.RequestMapping; */ @KimController @RequestMapping("/api/v1") -public class KimUserController { +public class UserController { /** - * Detail user. + * 查看用户详情 * - * @param id the id - * @param query the query + * @param userId 用户编号 + * @param query 过滤条件 * @return 用户对象 user */ - @GetMapping(value = "/{id}") - public User detail(@PathVariable String id, Query query) { + @GetMapping(value = "/{userId}") + public User detail(@PathVariable String userId, Query query) { User user = new User(); return user; }