Commit d1cdf8f4 authored by duanledexianxianxian's avatar duanledexianxianxian 😁

Adding tests.

parent f4af126d
...@@ -9,8 +9,8 @@ public class QueryStringBuilder { ...@@ -9,8 +9,8 @@ public class QueryStringBuilder {
private StringBuilder builder = new StringBuilder(); private StringBuilder builder = new StringBuilder();
public QueryStringBuilder append(Object key, Object value){ public QueryStringBuilder append(Object key, Object value) {
if(builder.length()>0){ if (builder.length() > 0) {
builder.append("&"); builder.append("&");
} }
builder.append(key); builder.append(key);
...@@ -19,21 +19,21 @@ public class QueryStringBuilder { ...@@ -19,21 +19,21 @@ public class QueryStringBuilder {
return this; return this;
} }
public QueryStringBuilder append(ObjectNode objectNode){ public QueryStringBuilder append(ObjectNode objectNode) {
Iterator<String> iterator = objectNode.fieldNames(); Iterator<String> iterator = objectNode.fieldNames();
while (iterator.hasNext()){ while (iterator.hasNext()) {
String key = iterator.next(); String key = iterator.next();
JsonNode valueNode = objectNode.get(key); JsonNode valueNode = objectNode.get(key);
String value = valueNode.isTextual()?valueNode.asText():valueNode.toString(); String value = valueNode.isTextual() ? valueNode.asText() : valueNode.toString();
append(key,value); append(key, value);
} }
return this; return this;
} }
public String toString(){ @Override
public String toString() {
return builder.toString(); return builder.toString();
} }
} }
...@@ -24,34 +24,34 @@ public class URI { ...@@ -24,34 +24,34 @@ public class URI {
this.text = text; this.text = text;
} }
public URI add(String text){ public URI add(String text) {
return add(new URI(text)); return add(new URI(text));
} }
public URI add(URI uri){ public URI add(URI uri) {
if(next!=null){ if (next != null) {
next.add(uri); next.add(uri);
}else{ } else {
next = uri; next = uri;
} }
return this; return this;
} }
public void remove(URI uri){ public void remove(URI uri) {
if(Objects.equals(next,uri)){ if (Objects.equals(next, uri)) {
next = null; next = null;
}else{ } else {
next.remove(uri); next.remove(uri);
} }
} }
@Override @Override
public String toString(){ public String toString() {
List<String> list = new ArrayList<>(); List<String> list = new ArrayList<>();
appendTo(list); appendTo(list);
StringBuilder builder = new StringBuilder(); StringBuilder builder = new StringBuilder();
for (String text : list) { for (String text : list) {
if(StringHelper.nonBlank(text)){ if (StringHelper.nonBlank(text)) {
builder.append("/"); builder.append("/");
builder.append(text); builder.append(text);
} }
...@@ -59,11 +59,11 @@ public class URI { ...@@ -59,11 +59,11 @@ public class URI {
return builder.toString(); return builder.toString();
} }
private void appendTo(List<String> list){ private void appendTo(List<String> list) {
if(Objects.nonNull(text)){ if (Objects.nonNull(text)) {
list.addAll(Lists.newArrayList(text.split("/"))); list.addAll(Lists.newArrayList(text.split("/")));
} }
if(next!=null){ if (next != null) {
next.appendTo(list); next.appendTo(list);
} }
} }
......
...@@ -7,6 +7,7 @@ import com.fasterxml.jackson.databind.JsonNode; ...@@ -7,6 +7,7 @@ import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ObjectNode; import com.fasterxml.jackson.databind.node.ObjectNode;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
import org.apache.commons.lang3.StringUtils;
import java.util.*; import java.util.*;
...@@ -44,12 +45,10 @@ public class Section extends Node { ...@@ -44,12 +45,10 @@ public class Section extends Node {
* The Query parameter. * The Query parameter.
*/ */
boolean queryParameter = true; boolean queryParameter = true;
/** /**
* The Request rows. * The Request rows.
*/ */
Map<String, Row> requestRows = new LinkedHashMap<>(); Map<String, Row> requestRows = new LinkedHashMap<>();
/** /**
* The Out headers. * The Out headers.
*/ */
...@@ -67,6 +66,13 @@ public class Section extends Node { ...@@ -67,6 +66,13 @@ public class Section extends Node {
*/ */
Object rawResponse; Object rawResponse;
public void setUri(String uri) {
String value = "";
if (StringUtils.isNotBlank(uri)) {
value = uri.replaceAll("\\{", ":").replaceAll("}", "");
}
this.uri = value;
}
/** /**
* Add request row. * Add request row.
......
...@@ -72,10 +72,10 @@ ${section.getResponseString()} ...@@ -72,10 +72,10 @@ ${section.getResponseString()}
<#-- 响应参数table列表--> <#-- 响应参数table列表-->
<#if section.responseRows?? && (section.responseRows?size>0)> <#if section.responseRows?? && (section.responseRows?size>0)>
| 字段 | 类型 | 描述 | | 字段 | 类型 | 默认值 | 描述 |
| :------- | :----- | :---------- | | :------- | :----- |:----- | :---------- |
<#list section.responseRows as rowKey,rowValue> <#list section.responseRows as rowKey,rowValue>
| ${rowValue.key!''} | ${rowValue.type!''} | ${rowValue.remark!''} | | ${rowValue.key!''} | ${rowValue.type!''} | ${rowValue.def!''} | ${rowValue.remark!''} |
</#list> </#list>
</#if> </#if>
</#if> </#if>
......
...@@ -15,6 +15,6 @@ public class Query { ...@@ -15,6 +15,6 @@ public class Query {
/** /**
* 查询关键字 * 查询关键字
*/ */
String q = ""; String q = "123";
} }
...@@ -3,8 +3,6 @@ package com.kim.apidoc.example.spring.advanced; ...@@ -3,8 +3,6 @@ package com.kim.apidoc.example.spring.advanced;
import com.kim.apidoc.example.annotation.KimController; import com.kim.apidoc.example.annotation.KimController;
import com.kim.apidoc.example.common.Query; import com.kim.apidoc.example.common.Query;
import com.kim.apidoc.example.common.User; 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.GetMapping;
import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
...@@ -21,18 +19,18 @@ import org.springframework.web.bind.annotation.RequestMapping; ...@@ -21,18 +19,18 @@ import org.springframework.web.bind.annotation.RequestMapping;
*/ */
@KimController @KimController
@RequestMapping("/api/v1") @RequestMapping("/api/v1")
public class KimUserController { public class UserController {
/** /**
* Detail user. * 查看用户详情
* *
* @param id the id * @param userId 用户编号
* @param query the query * @param query 过滤条件
* @return 用户对象 user * @return 用户对象 user
*/ */
@GetMapping(value = "/{id}") @GetMapping(value = "/{userId}")
public User detail(@PathVariable String id, Query query) { public User detail(@PathVariable String userId, Query query) {
User user = new User(); User user = new User();
return user; return user;
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment