Commit d1cdf8f4 authored by duanledexianxianxian's avatar duanledexianxianxian 😁

Adding tests.

parent f4af126d
......@@ -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<String> 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();
}
}
......@@ -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<String> 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<String> list){
if(Objects.nonNull(text)){
private void appendTo(List<String> list) {
if (Objects.nonNull(text)) {
list.addAll(Lists.newArrayList(text.split("/")));
}
if(next!=null){
if (next != null) {
next.appendTo(list);
}
}
......
......@@ -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<String, Row> 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.
......
......@@ -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!''} |
</#list>
</#if>
</#if>
......
......@@ -15,6 +15,6 @@ public class Query {
/**
* 查询关键字
*/
String q = "";
String q = "123";
}
......@@ -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;
}
......
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