diff --git a/src/main/java/com/power/doc/usecase/rest/api/body/parameter/BodyExampleUseCase.java b/src/main/java/com/power/doc/usecase/rest/api/body/parameter/BodyExampleUseCase.java new file mode 100644 index 0000000..c38686b --- /dev/null +++ b/src/main/java/com/power/doc/usecase/rest/api/body/parameter/BodyExampleUseCase.java @@ -0,0 +1,53 @@ +package com.power.doc.usecase.rest.api.body.parameter; + +import com.power.doc.usecase.rest.pojo.value.BarValue; +import com.power.doc.usecase.rest.pojo.value.FooValue; + +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +/** + * Body Example + * @author zongzi + */ +@RestController +@RequestMapping("/query/body/parameter/body-example") +public class BodyExampleUseCase { + /** + * Default Auto Mock + * @apiNote 在默认情况下smart-doc可以根据参数的类型为你生成示例值 + * 注意: + * 1、TODO #021 下方Request-body一栏中的"fooByte"示例值为字符串,存在问题 + * 2、TODO #022 下方Request-body一栏中的"fooCharInBox"示例值为字符串,存在问题 + * 3、TODO #023 下方Request-body一栏中的"fooEnumMap"示例值的Key为字符串,存在问题 + * @param foo 测试对象 + */ + @GetMapping("/default_mock") + public void defaultMock(@RequestBody FooValue foo) { + + } + + /** + * Manual With @mock + * @apiNote 也可以使用@mock来自己指定示例值(通过在属性上使用@mock)字段,如下所示 + * + * class BarValue{ + * //@mock "this is my mock string with "{"fooString":"123"} \" " + * String barString; + * //@mock 123a + * int barInt; + * //这里没有使用@mock注解,则交由smart-doc自动生成示例值 + * long barLong; + * } + * + * 注意: + * 1. 如果想查看JSR-303标准中的注解对示例值生成的影响,请查看{@link BodyParameterRequiredUseCase} + */ + @GetMapping("/manual-mock") + public void manualMock(@RequestBody BarValue bar) { + + } + +} diff --git a/src/main/java/com/power/doc/usecase/rest/api/body/parameter/BodyParameterDescriptionUseCase.java b/src/main/java/com/power/doc/usecase/rest/api/body/parameter/BodyParameterDescriptionUseCase.java new file mode 100644 index 0000000..2fe5203 --- /dev/null +++ b/src/main/java/com/power/doc/usecase/rest/api/body/parameter/BodyParameterDescriptionUseCase.java @@ -0,0 +1,51 @@ +package com.power.doc.usecase.rest.api.body.parameter; + +import com.power.doc.usecase.rest.pojo.description.BarDescription; +import com.power.doc.usecase.rest.pojo.description.FooDescription; + +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +/** + * Description Field + * @author zongzi + */ +@RestController +@RequestMapping("/query/body/parameter/description") +public class BodyParameterDescriptionUseCase { + + /** + * Simple Parameter + * @apiNote 当传入简单的形式参数时,可以在@param中进行参数说明 + * @param fooId 测试foodId参数说明 + */ + @GetMapping("/simple-int") + public void foo(@RequestBody Integer fooId) { + + } + + /** + * Self-Definition Type + * @apiNote 如果方法的入参是个自定义对象,可以在对象的成员变量上添加注释,进行说明 + * 注意: + * 方法参数是自定义对象的场景下,在方法上@param中的参数声明在渲染文档中会失效 + * @param foo 此处会在渲染结果中失效 + */ + @GetMapping("/self-definition-type") + public void bar(@RequestBody FooDescription foo) { + + } + + + /** + * Special Character + * @apiNote 一些描述中的特殊字符 + * @param bar 测试对象 + */ + @GetMapping("/special-characters") + public void koo(@RequestBody BarDescription bar){ + + } +} diff --git a/src/main/java/com/power/doc/usecase/rest/api/body/parameter/BodyParameterParameterNameUseCase.java b/src/main/java/com/power/doc/usecase/rest/api/body/parameter/BodyParameterParameterNameUseCase.java new file mode 100644 index 0000000..f0d7741 --- /dev/null +++ b/src/main/java/com/power/doc/usecase/rest/api/body/parameter/BodyParameterParameterNameUseCase.java @@ -0,0 +1,76 @@ +package com.power.doc.usecase.rest.api.body.parameter; + +import com.power.doc.usecase.rest.pojo.parameter.FooJsonParameterName; +import com.power.doc.usecase.rest.pojo.parameter.FooParameterName; + +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +/** + * Parameter Name + * @author zongzi + */ +@RestController +@RequestMapping("/query/body/parameter/parameter-name") +public class BodyParameterParameterNameUseCase { + + /** + * Ignore Some Parameter(Use @ignore) + * @apiNote 使用@ignore字段可以在生成的Body-Parameter字段中忽略一些字段, + * 举例说明:声明一个对象Foo + * + * class Foo{ + * // 此字段应该被正常渲染 + * String fooStringNotIgnore; + * + * //此字段会在最后的渲染结果中被忽略 + * //@ignore + * String fooStringToIgnore; + * + * } + * + * @param foo 示例对象 + */ + @PostMapping("/use-ignore") + public void fooUseIgnore(@RequestBody FooParameterName foo) { + + } + + /** + * Use Jackson Annotations + * @apiNote 使用 com.fasterxml.jackson.annotation 下的注解 + * `@JsonProperty / `@JsonProperty / `@JsonIgnore /`@JsonIgnoreType进行用例展示 + *
+	 * `@JsonIgnoreProperties({"fooClassStringToIgnore"})
+	 * class Foo{
+	 *       //此字段
+	 *       `@JsonProperty("fooString")
+	 *        String fooStringWithJsonAnnotation;
+	 *
+	 *    	 `@JsonIgnore
+	 *    	 String fooStringToIgnore;
+	 *
+	 * 		 //在Class上声明被忽略的成员变量
+	 * 	     String fooClassStringToIgnore;
+	 *
+	 * 		 //使用@JsonIgnoreType声明的类型
+	 * 		 Bar bar;
+	 *   }
+	 * `@JsonIgnoreType
+	 * `@Data
+	 * class Bar {
+	 * 		String barString;
+	 * }
+	 * 
+ * TODO #026 JsonIgnoreType似乎没有起作用,查看下方的Body-Parameter, bar字段还是正常显示了 + * @param foo 使用了一些jackson的注解对象 + * + */ + @PostMapping("/use-jackson-annotation") + public void fooUseFastJsonAnnotation(@RequestBody FooJsonParameterName foo) { + + } +} + diff --git a/src/main/java/com/power/doc/usecase/rest/api/body/parameter/BodyParameterRequiredUseCase.java b/src/main/java/com/power/doc/usecase/rest/api/body/parameter/BodyParameterRequiredUseCase.java new file mode 100644 index 0000000..e11a4f9 --- /dev/null +++ b/src/main/java/com/power/doc/usecase/rest/api/body/parameter/BodyParameterRequiredUseCase.java @@ -0,0 +1,39 @@ +package com.power.doc.usecase.rest.api.body.parameter; + +import com.power.doc.usecase.rest.pojo.required.BarJsr303; +import com.power.doc.usecase.rest.pojo.required.FooRequired; + +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +/** + * Required Field + * @author zongzi + */ +@RestController +@RequestMapping("/query/body/parameter/required-field") +public class BodyParameterRequiredUseCase { + /** + * Use @required(Not Recommend) + * @apiNote 可以在成员属性上添加@required注解表明参数必填,不推荐使用,查看链接 + * + * @param foo 测试对象 + */ + @GetMapping("/use-required-set") + public void foo(@RequestBody FooRequired foo) { + } + + /** + * Use JSR-303 + * @apiNote 使用JSR-303中的标准中的注解进行用例说明,用例内容不仅仅包括Required字段,也包括Value字段和Description字段 + * 注意: + * 1、Required 字段的变化只取决于三个注解: @NotNull @NotBlank @NotEmpty , 只有标识了这三个注解之一的字段会被标识为Required = True + * 2、TODO #019 这里列举了所有JSR-303注解对文档生成的影响,查看示例对象{@link BarJsr303}或者下方参数列表。 + * @param barJsr303 测试实体 + */ + @GetMapping("use-jsr-303") + public void bar(@RequestBody BarJsr303 barJsr303) { + } +} diff --git a/src/main/java/com/power/doc/usecase/rest/api/body/parameter/BodyParameterTypeUseCase.java b/src/main/java/com/power/doc/usecase/rest/api/body/parameter/BodyParameterTypeUseCase.java new file mode 100644 index 0000000..c09308f --- /dev/null +++ b/src/main/java/com/power/doc/usecase/rest/api/body/parameter/BodyParameterTypeUseCase.java @@ -0,0 +1,139 @@ +package com.power.doc.usecase.rest.api.body.parameter; + +import java.util.List; +import java.util.Map; + +import com.power.doc.usecase.rest.pojo.type.BarType; +import com.power.doc.usecase.rest.pojo.type.FooCircleDependency; +import com.power.doc.usecase.rest.pojo.type.FooType; + +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +/** + * Type Field + * @author zongzi + */ +@RestController +@RequestMapping("/query/body/parameter/type-field") +public class BodyParameterTypeUseCase { + + /** + * Claim Self-Definition Type + * @apiNote 声明自定义简单对象 + + * @param fooType 测试对象 + */ + @PostMapping("/self-definition-type") + public void foo(@RequestBody FooType fooType) { + + } + + /** + * Claim Circle Dependency + * @apiNote 声明循环依赖对象 + * @param fooCircleDependency 循环依赖对象 + */ + @PostMapping("/circle-dependency") + public void fooCircleDependency(@RequestBody FooCircleDependency fooCircleDependency) { + + } + + + /** + * Claim Foo[] + * @apiNote 使用Foo[]作为入参 + * @param foos 自定义对象数组 + */ + @PostMapping("/array-type") + public void fooArray(@RequestBody FooType[] foos) { + + } + + /** + * Claim Foo... + * @apiNote 使用Foo...作为入参 + * @param foos 自定义对象数组 + */ + @PostMapping("/array-types") + public void fooArrays(@RequestBody FooType... foos) { + + } + + /** + * + * Claim List + * @apiNote 使用List作为入参 + * @param foos 对象列表 + */ + @PostMapping("/list-type") + public void fooListType(@RequestBody List foos) { + + } + + /** + * Claim Map + * @apiNote 使用Map类型作为入参 + * @param fooMap fooMap + */ + @PostMapping("/map-type") + public void fooMapType(@RequestBody Map fooMap) { + + } + + /** + * Claim List> + * @apiNote 使用List>类型作为入参 + * @param fooMaps fooMaps + */ + @PostMapping("/list-map-type") + public void foodListMapType(@RequestBody List> fooMaps) { + + } + + /** + * Claim With @PathVariable & @RequestBody + * @apiNote 同时使用@PathVariable 和 @RequestBody 两个注解 + * @param foodId 测试ID + * @param bar 测试自定义对象 + */ + @PostMapping("use-both-path-variable-and-request-body/{id}") + public void fooAnnotationWithPathVariableAndRequestBody(@PathVariable("id") Integer foodId,@RequestBody BarType bar){ + + } + + /** + * (❎)Claim Map + * @apiNote 反模式(不推荐),声明Map 与声明 Map相同 + * @param fooMap fooMap + */ + @PostMapping("/map-generic-type") + public void fooMapGeneric(@RequestBody Map fooMap) { + + } + + /** + * (❎)Claim T Generic Type + * @apiNote 反模式(不推荐),声明 T t 作为入参,与声明Object相同, + * @param t t + */ + @PostMapping("list-t-generic") + public void foodG(@RequestBody T t) { + + } + + /** + * (❎)Claim List + * @apiNote 反模式(不推荐),声明List与声明List相同,List 同理 + * @param foos foos + */ + @PostMapping("/list-generic-type-extends") + public void fooListGenericExtends(@RequestBody List foos) { + + } + + +} diff --git a/src/main/java/com/power/doc/usecase/rest/api/headers/RequestHeadersUseCase.java b/src/main/java/com/power/doc/usecase/rest/api/headers/RequestHeadersUseCase.java new file mode 100644 index 0000000..240c09d --- /dev/null +++ b/src/main/java/com/power/doc/usecase/rest/api/headers/RequestHeadersUseCase.java @@ -0,0 +1,99 @@ +package com.power.doc.usecase.rest.api.headers; + +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +/** + * Request Headers + * @author zongzi + */ +@RestController +@RequestMapping("/headers") +public class RequestHeadersUseCase { + + + /** + * Global Headers + * @apiNote 如果需要添加公共Headers,可以在smart-doc.json + * 中添加如下配置 + * + * "requestHeaders": [ //设置请求头,没有需求可以不设置 + * { + * "name": "global-header", //请求头名称 + * "type": "string", //请求头类型 + * "desc": "公共请求头", //请求头描述信息 + * "value": "any value", //不设置默认null + * "required": false, //是否必须 + * "since": "-" //什么版本添加的改请求头 + * } + * ] + * + * 本目录下(Request Headers)的所有请求都会携带上方所声明的Header。 + * @author zongzi + */ + @GetMapping("/set-global-headers") + public void foo() { + + } + + /** + * Specific Header + * @apiNote 如果需要根据特定请求路径添加特定请求头,可以在smart-doc.json的requestHeaders属性中 + * 添加`pathPatterns`属性,并匹配当前API的Path,如下: + * + * "requestHeaders": [ //设置请求头,没有需求可以不设置 + * { + * "name": "specific-header", //请求头名称 + * "type": "string", //请求头类型 + * "desc": "特定请求头", //请求头描述信息 + * "value": "any value", //不设置默认null + * "required": false, //是否必须 + * "since": "-" //什么版本添加的改请求头 + * "pathPatterns": "/headers/set-specific-header" + * } + * ] + * + */ + @GetMapping("/set-specific-header") + public void bar() { + + } + + /** + * Exclude Header + * @apiNote 如果想要屏蔽某个请求头,可以在smart-doc.json的requestHeaders属性中 + * 添加`excludePathPatterns`属性,并匹配当前API的Path, 如下例子, + * 将在/headers/set-exclude-header路径上屏蔽前面设置的global-header: + * + * + * "requestHeaders": [ //设置请求头,没有需求可以不设置 + * { + * "name": "global-header", //请求头名称 + * "type": "string", //请求头类型 + * "desc": "公共请求头", //请求头描述信息 + * "value": "any value", //不设置默认null + * "required": false, //是否必须 + * "since": "-" //什么版本添加的改请求头 + * "excludePathPatterns":"/headers/set-exclude-header" + * } + * ] + * + * + */ + @GetMapping("/set-exclude-header") + public void koo() { + + } + + + /** + * Claim Header At Method Level + * @apiNote 可以在方法注解上单独声明Header,使用headers属性 + * TODO #051 在此处Headers中声明的Accept字段,无法影响最终的渲染结果中Content-Type字段 + */ + @GetMapping(value = "/special-method-header", headers = {"fooKey=123","Accept=application/json"}) + public void laa() { + + } +} diff --git a/src/main/java/com/power/doc/usecase/rest/api/meta/AuthorUseCase.java b/src/main/java/com/power/doc/usecase/rest/api/meta/AuthorUseCase.java new file mode 100644 index 0000000..efb6d00 --- /dev/null +++ b/src/main/java/com/power/doc/usecase/rest/api/meta/AuthorUseCase.java @@ -0,0 +1,36 @@ +package com.power.doc.usecase.rest.api.meta; + +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +/** + * Author(@author) + * @author zongzi + */ +@RestController +@RequestMapping("/meta/author") +public class AuthorUseCase { + + + /** + * `@author` In Default + * @apiNote 默认情况下,API.Meta.Author 的取值为类文件上的@author注解所标示的值 + * TODO #003 在@author字段之后的所有内容都会被拼接上, + * + */ + @GetMapping("/default") + public void foo() { + + } + + /** + * `@author` At Method Level + * @apiNote 如果需要指定单个接口的作者,可以在方法签名上使用@author注解 + * @author zonzi at method level + */ + @GetMapping("/at-method-level") + public void bar() { + + } +} diff --git a/src/main/java/com/power/doc/usecase/rest/api/meta/ContentTypeUseCase.java b/src/main/java/com/power/doc/usecase/rest/api/meta/ContentTypeUseCase.java new file mode 100644 index 0000000..7832da8 --- /dev/null +++ b/src/main/java/com/power/doc/usecase/rest/api/meta/ContentTypeUseCase.java @@ -0,0 +1,90 @@ +package com.power.doc.usecase.rest.api.meta; + + +import com.power.doc.usecase.rest.api.query.parameter.QueryParameterTypeUseCase; +import lombok.Data; + +import org.springframework.http.MediaType; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +/** + * Content-Type + * @author zongzi + */ +@RestController +@RequestMapping("/meta/content-type") +public class ContentTypeUseCase { + + /** + * Json Format With @RequestBody + * @apiNote 使用@RequestBody时,Content-Type为 application/json + * TODO #002 只支持 application/json 、application/x-www-form-urlencoded 两种形式的Content-Type + * @param foo 任意参数 + */ + @GetMapping("/application/json") + public void fooJson(@RequestBody Foo foo) { + + } + + /** + * x-www-form-urlencoded + * @apiNote 参数中不使用任何注解时,Content-Type为 application/x-www-form-urlencoded + * @param foo 任意参数 + */ + @GetMapping("/application/www") + public void booFormUrlEncoded(Foo foo) { + + } + + /** + * x-www-form-urlencoded With @RequestParam + * @apiNote 参数中使用@RequestParam时,Content-Type为 application/x-www-form-urlencoded + * @param foo 任意参数 + */ + @GetMapping(value = "application/www/request-param") + public void fooFormUrlEncodedWithRequestParam(@RequestParam("foo") Foo foo) { + + } + + /** + * Json Format First + * @apiNote 同时使用@RequestBody,@RequestParam时, Content-Type为 application/json + * 于此同时,文档中只会出现Body-parameters。 + * TODO #001 Query-Parameters 这一项却被删除了, 而Query-Parameters中的 字段说明被拼接在了Body-parameters中。其他的Query-Parameters的性质请查看 {@link QueryParameterTypeUseCase} + * @param foo 任意参数 + * @param bar 任意参数 + * @param id id + * @author zongzi + */ + @GetMapping(value = "application/json/request-body/{id}") + public void fooJsonWithRequestParamAndRequestBody(@RequestParam("foo") Foo foo, @RequestBody Bar bar, @PathVariable("id") Integer id) { + + } + + /** + * Specify The Content-Type Using Consumes Property + * @apiNote TODO #051 使用consumes字段尝试更改接口的Content-Type不会奏效,这个字段似乎只和方法入参的声明方式有关。 + * @param bar 测试对象 + */ + @PostMapping(value = "/application/specify-the-content-type",consumes = {MediaType.TEXT_HTML_VALUE}) + public void fooConsumerProperty(Bar bar){ + + } +} + +@Data +class Foo { + private String foo; +} + +@Data +class Bar { + private String bar; + private Integer barLong; +} \ No newline at end of file diff --git a/src/main/java/com/power/doc/usecase/rest/api/meta/DescriptionUseCase.java b/src/main/java/com/power/doc/usecase/rest/api/meta/DescriptionUseCase.java new file mode 100644 index 0000000..b10f63e --- /dev/null +++ b/src/main/java/com/power/doc/usecase/rest/api/meta/DescriptionUseCase.java @@ -0,0 +1,47 @@ +package com.power.doc.usecase.rest.api.meta; + +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +/** + * Description(@apiNote) + * @author zongzi + * + */ +@RestController +@RequestMapping("/meta/description") +public class DescriptionUseCase { + + /** + * Description Default + * + */ + @GetMapping("default") + public void foo() { + + } + + /** + * Description With @apiNote + * + * @apiNote 使用@apiNote字段可以单独进行接口说明, @apiNote只能在方法层面的注解上生效, + *
+	 *     public class Foo{
+	 *         private String fooString;
+	 *     }
+	 *
+	 * 
+ * + *
  • a
  • + *
  • b
  • + *
    + * this is a link to smart-doc's doc + * TODO #004 如上所示,如果@apiNote,中含有html代码,则无法渲染。 + * + */ + @GetMapping("/api-note") + public void bar() { + + } +} diff --git a/src/main/java/com/power/doc/usecase/rest/api/meta/RequestTypeUseCase.java b/src/main/java/com/power/doc/usecase/rest/api/meta/RequestTypeUseCase.java new file mode 100644 index 0000000..6418e7c --- /dev/null +++ b/src/main/java/com/power/doc/usecase/rest/api/meta/RequestTypeUseCase.java @@ -0,0 +1,159 @@ +package com.power.doc.usecase.rest.api.meta; + +import java.lang.reflect.Method; + +import lombok.Data; + +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +/** + * Type + * @author zongzi + * @version 2.5.3 + */ +@RestController +@RequestMapping("/meta/type") +public class RequestTypeUseCase { + + /** + * Get Request + * @apiNote 生成Get请求的API文档 + * @since 2.5.3 + */ + @GetMapping("/get") + public void get() { + } + + /** + * Get Request With @PathVariable & @RequestBody & @RequestParam + * @apiNote Get请求中使用@PathVariable & @RequestBody & @RequestParam 声明入参 + * @param id id + * @param foo foo + */ + @GetMapping("/get/{id}") + public void getWithPathVariableAndRequestBody(@PathVariable Integer id, @RequestParam String foo, @RequestBody String bar) { + + } + + /** + * Post Request + * @apiNote 生成Post请求的API文档 + * @since 2.5.3 + */ + @PostMapping("/post") + public void post() { + } + + /** + * Post Request With @PathVariable & @RequestParam (Basic Type) + * @apiNote 测试使用Post方法,但是同时使用@RequestParam 和 @PathVariable注解简单对象 + * TODO #027 此处使用两个基本类型时,错误的产生了Request-body示例,产生的Curl-example不正确, + * @param id 测试id + * @param foo 测试RequestParam + */ + @PostMapping("/post/{id}") + public void postWithPathVariableAndRequestParam(@PathVariable Integer id, @RequestParam String foo) { + + } + + /** + * Post Request With @PathVariable & @RequestParam (Self-Definition Type) + * @apiNote 测试使用Post方法,但是同时使用@RequestParam 和 @PathVariable注解自定义类型 + * TODO #028 使用@RequestParam注解自定义类型时,产生的Curl-example不正确, + * @param id 测试id + * @param foo 测试RequestParam + */ + @PostMapping("/post/self-definition/{id}") + public void postWithPathVariableAndRequestParamButObject(@PathVariable Integer id, @RequestParam FooRequestType foo) { + + } + + /** + * Delete Request + * @apiNote 生成Delete请求 + * @since 2.5.3 + */ + @DeleteMapping("/delete") + public void delete() { + } + + /** + * Delete Request With @PathVariable & @RequestParam (Basic Type) + * @apiNote 使用Delete方法,但是同时使用@RequestParam 和 @PathVariable注解自定义类型 + * TODO #029 此处使用两个基本类型时,产生的Curl-example不正确 + * @since 2.5.3 + */ + @DeleteMapping("/delete/{id}") + public void delete(@PathVariable Integer id, @RequestParam String foo) { + } + + /** + * Delete Request With @PathVariable & @RequestParam (Self-Definition Type) + * @apiNote 使用Delete方法,但是同时使用@RequestParam 和 @PathVariable注解自定义类型 + * @since 2.5.3 + */ + @DeleteMapping("/delete/{id}") + public void delete(@PathVariable Integer id, @RequestParam FooRequestType foo) { + } + + /** + * Put Request + * @apiNote 测试使用Put方法 + * @since 2.5.3 + */ + @PutMapping("/put") + public void put() { + + } + + /** + * Put Request With @PathVariable & @RequestParam (Basic Type) + * @apiNote 测试使用Put方法,但是同时使用@RequestParam 和 @PathVariable注解自定义类型 + * TODO #030 此处使用两个基本类型时,错误的产生了Request-body示例,foo参数的位置在--data中,和下方示例不一致,但是也没有问题 + * @param id 测试id + * @param foo 测试RequestParam + */ + @PutMapping("/put/self-definition/{id}") + public void putWithPathVariableAndRequestParamButObject(@PathVariable Integer id, @RequestParam String foo) { + + } + + /** + * Put Request With @PathVariable & @RequestParam (Self-Definition Type) + * @apiNote 测试使用Put方法,但是同时使用@RequestParam 和 @PathVariable注解自定义类型 + * TODO #031 使用@RequestParam注解自定义类型时,产生的Curl-example不正确,多添加了一个foo + * @param id 测试id + * @param foo 测试RequestParam + */ + @PutMapping("/put/self-definition/{id}") + public void putWithPathVariableAndRequestParamButObject(@PathVariable Integer id, @RequestParam FooRequestType foo) { + + } + + /** + * Claim Multiple Request Method At Same Time + * @apiNote 实例场景来源 + * Request + * Mapping #6.2. @RequestMapping — Multiple HTTP Request Methods to the Same Controller Method + * TODO #050 产生的Curl-example中的-X 参数的值不正确 + */ + @RequestMapping(method = {RequestMethod.GET, RequestMethod.POST}, value = "multiple-methods") + public void fooMultipleHttpMethod() { + + } +} + +@Data +class FooRequestType { + String fooString; + Integer fooInteger; +} diff --git a/src/main/java/com/power/doc/usecase/rest/api/meta/UrlUseCase.java b/src/main/java/com/power/doc/usecase/rest/api/meta/UrlUseCase.java new file mode 100644 index 0000000..f2db35e --- /dev/null +++ b/src/main/java/com/power/doc/usecase/rest/api/meta/UrlUseCase.java @@ -0,0 +1,44 @@ +package com.power.doc.usecase.rest.api.meta; + +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +/** + * URL + * @author zongzi + */ +@RestController +@RequestMapping("/meta/url/") +public class UrlUseCase { + + /** + * Base URL + * @apiNote 生成一个普通Restful的链接 + */ + @GetMapping("base") + public void baseUrl() { + } + + /** + * URL With Path Variable + * @apiNote 生成一个含有路径参数的链接 + * @param foo 任意参数 + */ + @GetMapping("/base/{foo}") + public void urlWithVariable(@PathVariable("foo")Integer foo){ + + } + + + /** + * Claim Multiple URL At Same Time + * @apiNote 一次性声明多个链接 + */ + @GetMapping(value = {"multiple/url-1","multiple/url-2"}) + public void multipleUrls(){ + + } + +} \ No newline at end of file diff --git a/src/main/java/com/power/doc/usecase/rest/api/path/parameter/PathDescriptionFieldUseCase.java b/src/main/java/com/power/doc/usecase/rest/api/path/parameter/PathDescriptionFieldUseCase.java new file mode 100644 index 0000000..0796afe --- /dev/null +++ b/src/main/java/com/power/doc/usecase/rest/api/path/parameter/PathDescriptionFieldUseCase.java @@ -0,0 +1,41 @@ +package com.power.doc.usecase.rest.api.path.parameter; + +import com.power.doc.usecase.rest.pojo.type.FooEnum; + +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +/** + * Description Field + * + * @author zongzi 场景来源 + */ +@RestController +@RequestMapping("/api/path/description") +public class PathDescriptionFieldUseCase { + + /** + * Simple Mapping + * + * @param fooString 测试字符传参的注解 + */ + @GetMapping("multiple-path-param/{fooString}") + public void fooSimpleMapping(@PathVariable("fooString") String fooString) { + + } + /** + * Multiple Path Params + * @apiNote 如果类型是Enum时,@param的表述会被枚举的的示例值覆盖 {@link PathValueFieldUseCase#barStringAndEnumBox(String, FooEnum)} + * @param fooString 测试字符传参的注解 + * @param fooInt 测试int传参的注解 + * + */ + @GetMapping("multiple-path-param/{fooString}/{fooInt}") + public void foo(@PathVariable("fooString") String fooString, @PathVariable("fooInt") Integer fooInt) { + + + + } +} diff --git a/src/main/java/com/power/doc/usecase/rest/api/path/parameter/PathParameterNameUseCase.java b/src/main/java/com/power/doc/usecase/rest/api/path/parameter/PathParameterNameUseCase.java new file mode 100644 index 0000000..04baa45 --- /dev/null +++ b/src/main/java/com/power/doc/usecase/rest/api/path/parameter/PathParameterNameUseCase.java @@ -0,0 +1,59 @@ +package com.power.doc.usecase.rest.api.path.parameter; + +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +/** + * Parameter Name + * @author zongzi + */ +@RestController +@RequestMapping("/api/path/parameter-name") +public class PathParameterNameUseCase { + + + /** + * + * Specifying The Path Variable Name + * @apiNote 测试场景来源 Spring Path Variable + * @param fooStr 测试参数,路径中为fooString,此处重命名为foo, + * @param fooInt 测试参数,和路径中保持一致 + */ + @GetMapping("specifying-path-name/{fooString}/{fooInt}") + public void bar(@PathVariable("fooString") String fooStr, @PathVariable Integer fooInt) { + + } + + /** + * Path With Regex + * @apiNote 测试场景来源 Spring Request Mapping#4.3 + * TODO #043 在路径中使用正则表达式时,参数名称可以正确绑定,但是生成的Curl-example 会有问题,貌似做了一个正则替换。 + * @param fooStr 测试携带正则的参数绑定 + */ + @GetMapping("/path-with-regex/{fooStr:^\\w{1,12}-[\\d|\\w]+$}") + public void barPathWithRegex(@PathVariable String fooStr){ + + } + /** + * Multiple Path + * @apiNote 测试场景来源 Spring Path Variable + * TODO #040 如果使用了多个路径,测试的Curl-example只有一个路径(默认第一个) + * @param fooInt 测试可选参数 + */ + @GetMapping(value = {"/optional/variable/{fooInt}/{fooLong}","/optional/variable/a/{fooInt}","/optional/variable/b/{fooLong}"}) + public void koo(@PathVariable Integer fooInt,@PathVariable Long fooLong ){} + + /** + * Multiple Path With Optional Path Variables + * @apiNote 测试场景来源 Spring Path Variable + * TODO #041 如果多路径中出现类似如下可选参数的写法,则不会生成Path-parameters, 似乎只有所有的路径中都含有的参数才会生成Path-parameters, + * + * @param fooInt 测试可选参数 + */ + @GetMapping(value = {"/optional/variable/","/optional/variable/{fooInt}","/optional/variable/a/{fooInt}"}) + public void bar(@PathVariable(required = false) Integer fooInt){} + + +} \ No newline at end of file diff --git a/src/main/java/com/power/doc/usecase/rest/api/path/parameter/PathRequiredFieldUseCase.java b/src/main/java/com/power/doc/usecase/rest/api/path/parameter/PathRequiredFieldUseCase.java new file mode 100644 index 0000000..41f4710 --- /dev/null +++ b/src/main/java/com/power/doc/usecase/rest/api/path/parameter/PathRequiredFieldUseCase.java @@ -0,0 +1,26 @@ +package com.power.doc.usecase.rest.api.path.parameter; + +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +/** + * Required Field + * @author zongzi + */ +@RestController +@RequestMapping("/api/path/required-set") +public class PathRequiredFieldUseCase { + + /** + * Set Path Param Not Required + * @apiNote 可以通过指定@PathVariable(required = false)来指定一个参数非必传,默认必传。 + * @param fooStr 不是必传参数 + * @param barStr 必传参数 + */ + @GetMapping("/required-annotation/{fooStr}/{fooStr}/{barStr}") + public void foo(@PathVariable(required = false) String fooStr, @PathVariable(required = true) String barStr) { + } + +} diff --git a/src/main/java/com/power/doc/usecase/rest/api/path/parameter/PathTypeFieldUseCase.java b/src/main/java/com/power/doc/usecase/rest/api/path/parameter/PathTypeFieldUseCase.java new file mode 100644 index 0000000..54dc702 --- /dev/null +++ b/src/main/java/com/power/doc/usecase/rest/api/path/parameter/PathTypeFieldUseCase.java @@ -0,0 +1,51 @@ +package com.power.doc.usecase.rest.api.path.parameter; + +import java.util.Map; +import java.util.Optional; + +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +/** + * Type Field + * @author zongzi + */ +@RestController +@RequestMapping("/api/path/type/") +public class PathTypeFieldUseCase { + /** + * Multiple Path Params With Map + * @apiNote 测试场景来源 Spring Path Variable + * TODO #037 如果使用Map 来接收参数,不会显示Path-parameters这一栏, curl-example一栏也不正确,其他所有场景都被此特性覆盖,不用重复测试。 + * @param pathMap 使用Map接收多参数 + */ + @GetMapping("multiple-path-param-with-map/{fooString}/{fooInt}") + public void fooMultipleParamWithMap(@PathVariable Map pathMap) { + } + + /** + * Multiple Path Params With Map + * @apiNote 测试场景来源 Spring Path Variable + * TODO #038 如果使用Map 来接收参数,不会显示Path-parameters这一栏, 显示了Query-Parameters一栏 + * @param pathObjectMap 使用Map接收多参数 + */ + @GetMapping("multiple-path-param-with-object-map/{fooString}/{fooInt}") + public void fooMultipleParamWithObjectMap(@PathVariable Map pathObjectMap) { + } + + /** + * Using java.util.Optional + * @apiNote 使用java.util.Optional作为入参,测试场景来源 Spring Path Variable + * TODO #039 如果使用Map 来接收参数,不会显示Path-parameters这一栏, 显示了Query-Parameters一栏,是否需要修正? + * @param fooInt 使用Optional的Integer + */ + @GetMapping("/using-java-util-optional-type/{fooInt}") + public void fooUsingJavaUtilOptionalType(@PathVariable Optional fooInt){ + + } + + + +} diff --git a/src/main/java/com/power/doc/usecase/rest/api/path/parameter/PathValueFieldUseCase.java b/src/main/java/com/power/doc/usecase/rest/api/path/parameter/PathValueFieldUseCase.java new file mode 100644 index 0000000..0ba7ee5 --- /dev/null +++ b/src/main/java/com/power/doc/usecase/rest/api/path/parameter/PathValueFieldUseCase.java @@ -0,0 +1,79 @@ +package com.power.doc.usecase.rest.api.path.parameter; + +import com.power.doc.usecase.rest.pojo.type.FooEnum; + +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +/** + * Value Field + * @author zongzi + */ +@RestController +@RequestMapping("/api/path/value/") +public class PathValueFieldUseCase { + + + /** + * Mock boolean & char & double & float + * @param fooBool 测试bool类型的示例值 + * @param fooChar 测试字符类型的示例值 + * @param fooDouble 测试double类型的示例值 + * @param fooFloat 测试float类型的示例值 + */ + @GetMapping("/value-mock/{fooBool}/{fooChar}/{fooDouble}/{fooFloat}") + public void foo(@PathVariable boolean fooBool, @PathVariable char fooChar, @PathVariable double fooDouble, @PathVariable float fooFloat) { + + } + + /** + * Mock Boolean & Character & Double & Float + * @param fooBool 测试Boolean类型的示例值 + * @param fooChar 测试Character类型的示例值 + * @param fooDouble 测试Double类型的示例值 + * @param fooFloat 测试Float类型的示例值 + */ + @GetMapping("/value-mock-box/{fooBool}/{fooChar}/{fooDouble}/{fooFloat}") + public void fooBox(@PathVariable Boolean fooBool, @PathVariable Character fooChar, @PathVariable Double fooDouble, @PathVariable Float fooFloat) { + + } + + /** + * Mock byte & short & int & long + * @param fooByte 测试byte类型的示例值 + * @param fooShort 测试short类型的示例值 + * @param fooInt 测试int类型的示例值 + * @param fooLong 测试long类型的示例值 + */ + @GetMapping("/value-mock/{fooByte}/{fooShort}/{fooInt}/{fooLong}") + public void bar(@PathVariable byte fooByte, @PathVariable short fooShort, @PathVariable int fooInt, @PathVariable long fooLong) { + + } + + /** + * Mock Byte & Short & Integer & Long + * @param fooByte 测试Byte类型的示例值 + * @param fooShort 测试Short类型的示例值 + * @param fooInt 测试Integer类型的示例值 + * @param fooLong 测试Long类型的示例值 + */ + @GetMapping("/value-mock-box/{fooByte}/{fooShort}/{fooInt}/{fooLong}") + public void barStringAndEnumBox(@PathVariable Byte fooByte, @PathVariable Short fooShort, @PathVariable Integer fooInt, @PathVariable Long fooLong) { + + } + + /** + * Mock String & Enum + * @apiNote TODO #042 如果使用枚举类型的话,Description一栏会覆盖自己的参数描述 + * @param fooStr 测试String类型的示例值 + * @param fooEnum 测试枚举类型的示例值 + * + */ + @GetMapping("/string-and-enum-mock-box/{fooStr}/{fooEnum}") + public void barStringAndEnumBox(@PathVariable String fooStr, @PathVariable FooEnum fooEnum) { + + } + +} diff --git a/src/main/java/com/power/doc/usecase/rest/api/query/parameter/QueryParameterDescriptionUseCase.java b/src/main/java/com/power/doc/usecase/rest/api/query/parameter/QueryParameterDescriptionUseCase.java new file mode 100644 index 0000000..21b0b92 --- /dev/null +++ b/src/main/java/com/power/doc/usecase/rest/api/query/parameter/QueryParameterDescriptionUseCase.java @@ -0,0 +1,68 @@ +package com.power.doc.usecase.rest.api.query.parameter; + +import java.util.List; + +import com.power.doc.usecase.rest.pojo.description.BarDescription; +import com.power.doc.usecase.rest.pojo.description.FooDescription; + +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +/** + * Description Field + * + * @author zongzi + * TODO #020 如果两个类的类名相同,那么生成文档的时候就会忽略后一个类的文档,举例说明,如果把这个类改为DescriptionUseCase, + * 就会和 {@link com.power.doc.usecase.rest.api.meta.DescriptionUseCase}一致,那么此文档就会被忽略渲染。 + */ +@RestController +@RequestMapping("query/parameters/description") +public class QueryParameterDescriptionUseCase { + + + /** + * Simple Parameter + * @apiNote 当传入简单的形式参数时,可以在@param中进行参数说明 + * @param fooId 测试foodId参数说明 + */ + @GetMapping("/simple-int") + public void foo(Integer fooId) { + + } + + /** + * Self-Definition Type + * @apiNote 如果方法的入参是个自定义对象,可以在对象的成员变量上添加注释,进行说明 + * 注意: + * 方法参数是自定义对象的场景下,在方法上@param中的声明在渲染文档中会失效 + * @param foo 此处会在渲染结果中失效 + */ + @GetMapping("/self-definition-type") + public void bar(FooDescription foo) { + + } + + + /** + * Special Character + * @apiNote 一些描述中的特殊字符 + * @param bar 测试对象 + */ + @GetMapping("/special-characters") + public void koo(BarDescription bar){ + + } + + /** + * When Use Array Or List + * @apiNote 当使用List时,会拼接上列表元素的类型,并添加@since 字段 + * @param fooStrList 测试字符列表 + * @param fooStrArray 测试字符列表 + */ + @GetMapping("/when-use-array-or-list") + public void laa(List fooStrList,String[] fooStrArray){ + + } +} + diff --git a/src/main/java/com/power/doc/usecase/rest/api/query/parameter/QueryParameterRequiredUseCase.java b/src/main/java/com/power/doc/usecase/rest/api/query/parameter/QueryParameterRequiredUseCase.java new file mode 100644 index 0000000..36345f0 --- /dev/null +++ b/src/main/java/com/power/doc/usecase/rest/api/query/parameter/QueryParameterRequiredUseCase.java @@ -0,0 +1,55 @@ +package com.power.doc.usecase.rest.api.query.parameter; + +import com.power.doc.usecase.rest.pojo.required.BarJsr303; +import com.power.doc.usecase.rest.pojo.required.FooRequired; + +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +/** + * Required Field + * @author zongzi + */ +@RestController +@RequestMapping("/query/parameters/required") +public class QueryParameterRequiredUseCase { + + + /** + * Use @required(Not Recommend) + * @apiNote 可以在成员属性上添加@required注解表明参数必填,不推荐使用,查看链接 + * @required + * @param foo 测试对象 + */ + @GetMapping("/use-required-set") + public void foo(FooRequired foo) { + } + + /** + * Use JSR-303 + * @apiNote 使用JSR-303中的标准中的注解进行用例说明,用例内容不仅仅包括Required字段,也包括Value字段和Description字段 + * 注意: + * 1、Required 字段的变化只取决于三个注解: @NotNull @NotBlank @NotEmpty , 只有标识了这三个注解之一的字段会被标识为Required = True + * 2、TODO #019 这里列举了所有JSR-303注解对文档生成的影响,查看示例对象{@link BarJsr303}或者下方参数列表。 + * @param barJsr303 测试实体 + */ + @GetMapping("use-jsr-303") + public void bar(BarJsr303 barJsr303) { + } + + + /** + * Use @RequestParam(required = false) As Optional Param + * @apiNote 可以使用@RequestParam(required=false)来声明请求参数为可选项 + * @param fooStr 测试字符串 + * @param barStr 测试字符串 + */ + @GetMapping("use-request-param-required/") + public void koo(@RequestParam(required = false) String fooStr,@RequestParam String barStr){ + + } + +} + diff --git a/src/main/java/com/power/doc/usecase/rest/api/query/parameter/QueryParameterTypeUseCase.java b/src/main/java/com/power/doc/usecase/rest/api/query/parameter/QueryParameterTypeUseCase.java new file mode 100644 index 0000000..f405f48 --- /dev/null +++ b/src/main/java/com/power/doc/usecase/rest/api/query/parameter/QueryParameterTypeUseCase.java @@ -0,0 +1,258 @@ +package com.power.doc.usecase.rest.api.query.parameter; + +import java.math.BigDecimal; +import java.util.Date; +import java.util.List; +import java.util.Map; +import java.util.Optional; + + +import javax.servlet.http.HttpServletRequest; +import javax.xml.crypto.Data; + +import com.power.doc.usecase.rest.pojo.type.BarType; +import com.power.doc.usecase.rest.pojo.type.FooCircleDependency; +import com.power.doc.usecase.rest.pojo.type.FooEnum; +import com.power.doc.usecase.rest.pojo.type.FooType; +import org.checkerframework.framework.qual.RequiresQualifier; + +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +/** + * Type Field + * @author zongzi + */ +@RestController +@RequestMapping("query/parameters/type") +public class QueryParameterTypeUseCase { + + /** + * Claim Basic Type + * @apiNote 基础的参数类型可以直接在controller方法的参数上声明, 如下代码所示 + * + * `@GetMapping("/use-basic-type")` + * public void fooWithBaseType(Integer fooId, Double barId, String kooName){}; + * , + * 此时Content-Type为application/x-www-form-urlencoded;charset=UTF-8 + * @param fooId foo's id + * @param barId bar's id + * @param kooName koo's name + */ + @GetMapping("/use-basic-type") + public void fooWithBaseType(Integer fooId, Double barId, String kooName) { + + } + + /** + * Claim Self-Definition Type + * @apiNote 自定义类型, 可以直接在参数列表中声明,代码如下 + * + * `@GetMapping("/use-sel-definition-type")` + * public void fooWithSelfDefinitionType(Foo foo){} + * + * 注意: + * 此时自定义对象的参数名'foo'以及`@param foo`的注释无法获取 + * + * @param foo 测试自定义对象 + */ + @GetMapping("/use-sel-definition-type") + public void fooWithSelfDefinitionType(FooType foo,FooEnum fooEnum) { + + } + + /** + * Claim Circle Dependency Type + * @apiNote foo对象的成员变量有bar,bar的成员变量有foo + * + * @param foo 测试对象 + */ + @GetMapping("/use-circle-dependency-type") + public void fooWithCircleDependency(FooCircleDependency foo) { + + } + + /** + * Claim With @RequestParam + * @apiNote TODO #007 当使用@RequestParam声明参数时,生成的Curl-example的代码会多包涵一个bar参数,如下代码 + * + * `@GetMapping("/claim-with-request-param") + * public void fooWithRequestParam(@RequestParam Bar bar){} + * + * 生成的 Curl-example时,如下: + * + * curl -X GET -i http://{{host}}:{{port}}/query/parameters/type/claim-with-request-param?barString=bison&bar= + * + * @param bar 测试自定义对象 + */ + @GetMapping("/claim-with-request-param") + public void fooWithRequestParam(@RequestParam BarType bar,@RequestParam String fooStr) { + + } + + /** + * Specify The Param Name + * @apiNote 可以使用@RequestParam(value="fooStr") 来指定参数的适配 + * TODO #044 查看Curl-example一栏,--data参数的值是否正确,查看链接 https://linuxize.com/post/curl-post-request/ + * 场景来源 https://www.baeldung.com/spring-request-param #3 Specifying the Request Parameter Name + * @param fooStr 测试字符串 + * @param barStr 测试字符串 + */ + @GetMapping("specify-the-param-name/") + public void specifyTheParamName(@RequestParam("fooStr")String fooStr,@RequestParam String barStr){ + + } + + /** + * Mix Request Param Up(Basic Type) + * @apiNote 将普通参数与添加@RequestParam的参数混合声明 + * TODO #045 查看Curl-example一栏,--data参数的值是否正确。这种情况似乎在多个@RequestParam或者@RequestParam和不携带RequestParam的参数互用时才会产生(即多个入参时), + * 并且出现在--data中的示例值一定是使用@Requestparam注解的参数。下方的示例也具有同样的问题 + * @param fooStr 测试字符串入参 + * @param barStr 测试字符串入参 + * @param bizStr 测试字符串入参 + */ + @GetMapping("specify-the-param-name-2/") + public void specifyTheParamName2(String fooStr,@RequestParam String barStr,String bizStr){ + + } + + /** + * Mix Request Param Up (Http Types) + * @apiNote 将普通参数与添加@RequestParam的参数混合声明,查看代码 + * public void bar(HttpServletRequest request,@RequestParam String barStr,@RequestParam String bizStr) + * @param request 请求体 + * @param barStr 请求参数 + * @param bizStr 请求参数 + */ + @GetMapping("mix-request-param-with-no-reqeust-param/") + public void bar(HttpServletRequest request,@RequestParam String barStr,@RequestParam String bizStr){ + + } + + /** + * + * Claim With Optional API + * @apiNote 当使用Optional Api作为接口入参时的参数类型声明, + * 示例场景来源 Spring Request Param#4.1 Using Java 8 Optional + * TODO #046 使用Optional API 时, Query-Parameters的分析结果存在问题,(Type/Value/Description),Curl-Example的参数示例值存在问题 + * @param fooStr 测试字符串,声明方式Optional + */ + @GetMapping("claim-with-optional-apis") + public void fooWithOptionalApi(@RequestParam("fooStr")Optional fooStr){ + + } + + /** + * A Default Value For Request Param + * @apiNote 当指定Request Param的默认值时, + * 测试场景来源 Spring Request Param#5。A Default Value for the Request Parameter + * TODO #047 当RequestParam指定了默认值时,Curl-Example 也产生了--data的值,并且格式似乎也不正确。 + * @param fooStr 设置了defaultValue值, + */ + @GetMapping("use-request-param-with-default-value") + public void requestParamAnnotationWithDefaultValue(@RequestParam(defaultValue = "smart-doc")String fooStr){ + + } + /** + * Claim With @RequestBody + * @apiNote 参数可以和@RequestBody一同声明 + * 注意: + * TODO #006 但是和@RequestBody一同声明,如果包含对象的话(如下代码中的参数`foo`), + * + * `@GetMapping("/use-annotation-request-body")` + * public void fooWithRequestBodyAndSelfDefinitionType(Integer fooId, BarType bar1, @RequestBody BarType bar2) + * + * foo的字段会跑到Body-parameters一栏中, + * @param barId 测试自定义 + * @param bar1 测试自定义对象 + * @param bar2 测试自定义对象 + */ + @GetMapping("/use-annotation-request-body") + public void fooWithRequestBodyAndSelfDefinitionType(Integer barId, BarType bar1, @RequestBody BarType bar2) { + + } + + /** + * Claim With @RequestBody & @RequestParam + * @apiNote 同时声明@RequestParam 和 @RequestBody + * 注意:同时声明结果同 #006 的效果一致 + * @param bar1 测试对象1 + * @param bar2 测试对象2 + */ + @GetMapping("/use-annotation-request-body-and-request-param") + public void fooWithRequestBodyAndRequestParam(@RequestParam BarType bar1, @RequestBody BarType bar2) { + + } + + /** + * Claim Array(Basic Type) + * @apiNote 声明基础类型数组作为入参 TODO #048 产生的Curl-example的示例值的类型为String, + * @param ids 测试ID列表 + * @param characters TODO #049 实例值应为字符数组,但是此时为对象列表数组 + */ + @GetMapping("/use-basic-type-array") + public void fooWithArrayBasicType(Integer[] ids,Byte[] bytes,Short[] shorts,Long[] longs, + Boolean[] booleans,Character[] characters,Float[] floats,Double[] doubles, Date[] dates, BigDecimal[] bigDecimals, + FooEnum[] fooEnums) { + + } + + /** + * Claim Bar[] + * @apiNote 声明对象数组作为入参 + * 注意:TODO #008 smart-doc 在方法入参中使用对象数组时,会抛出异常,如果使用@RequestParam时,则会直接跳过Query-parameters渲染 + * @param bars 测试对象数组 + */ + @GetMapping("use-object-array") + public void fooWithArrayObjects(@RequestParam BarType[] bars) { + + } + + /** + * Claim List(Basic Type) + * @apiNote 示例场景来源 Spring Request Param #7 Mapping a Multi-Value Parameter + * @param fooStrList 示例多值列表 + */ + @GetMapping("calim-with-multiple-values") + public void fooWithMultipleParams(@RequestParam List fooStrList,@RequestParam List integers,@RequestParam List bytes,@RequestParam List shorts, + @RequestParam List longs){ + + } + /** + * Claim List + * @apiNote 使用泛型声明参数, + * 注意:TODO #009 smart-doc 在方法入参中使用集合框架时,会抛出异常,如果使用@RequestParam时,则会直接跳过Query-parameters渲染, + * 但是List却可以正常渲染 + * @param bars 测试对象列表 + */ + @GetMapping("generic-type-list") + public void fooWithGenericTypeList(@RequestParam List bars,@RequestParam List fooEnums) { + } + + /** + * Claim Map + * @apiNote 使用泛型声明参数 + * 注意:TODO #035 smart-doc 在方法入参中使用Map,生成的Curl-Example会有问题,查看链接 + * Spring Request Param #6. Mapping All Parameters/a> + * @param barMap 测试对象列表 + */ + @GetMapping("String-type-with-map") + public void fooWithStringTypeMap(@RequestParam Map barMap) { + } + + /** + * Claim Map + * @apiNote 使用泛型声明参数 + * 注意:TODO #010 smart-doc 在方法入参中使用Map时,会抛出警告,如果使用@RequestParam时,会直接渲染Map中的V + * @param barMap 测试对象列表 + */ + @GetMapping("generic-type-with-map") + public void fooWithGenericTypeMap(@RequestParam Map barMap) { + } + +} diff --git a/src/main/java/com/power/doc/usecase/rest/api/query/parameter/QueryParameterValueUseCase.java b/src/main/java/com/power/doc/usecase/rest/api/query/parameter/QueryParameterValueUseCase.java new file mode 100644 index 0000000..12a14de --- /dev/null +++ b/src/main/java/com/power/doc/usecase/rest/api/query/parameter/QueryParameterValueUseCase.java @@ -0,0 +1,55 @@ +package com.power.doc.usecase.rest.api.query.parameter; + +import com.power.doc.usecase.rest.pojo.value.BarValue; +import com.power.doc.usecase.rest.pojo.value.FooValue; + +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +/** + * Value Field + * @author zongzi + */ +@RestController +@RequestMapping("/query/parameters/value") +public class QueryParameterValueUseCase { + + + /** + * Default Auto Mock + * @apiNote 在默认情况下smart-doc可以根据参数的类型为你生成示例值 + * 注意: + * TODO #017 查看下方的Curl-Example, fooLongArray的取值和示例值不同,显示的是字符。 + * TODO #024 查看下方的Curl-Example,fooEnums的取值格式存在异常, + * TODO #025 查看下方的Curl-Example,fooEnumMap的取值不存在。 + * @param foo 测试对象 + */ + @GetMapping("/default_mock") + public void defaultMock(FooValue foo) { + + } + + /** + * Manual With @mock + * @apiNote 也可以使用@mock来自己指定示例值(通过在属性上使用@mock)字段,如下所示 + * + * class BarValue{ + * //@mock <>;'[]\` & !@#¥%……&*()——(*´▽`)ノノの😂 + * String barString; + * //@mock 123a + * int barInt; + * //这里没有使用@mock注解,则交由smart-doc自动生成示例值 + * long barLong; + * } + * + * 注意: + * 1. TODO #018 在此处使用@mock指定的值,会直接影响Curl-example中的代码生成结果(查看下方Curl-Example) + * 2. 如果想查看JSR-303标准中的注解对示例值生成的影响,请查看{@link QueryParameterRequiredUseCase} + */ + @GetMapping("/manual-mock") + public void manualMock(BarValue bar) { + + } +} + diff --git a/src/main/java/com/power/doc/usecase/rest/api/response/ResponseDescriptionUseCase.java b/src/main/java/com/power/doc/usecase/rest/api/response/ResponseDescriptionUseCase.java new file mode 100644 index 0000000..3b207bd --- /dev/null +++ b/src/main/java/com/power/doc/usecase/rest/api/response/ResponseDescriptionUseCase.java @@ -0,0 +1,72 @@ +package com.power.doc.usecase.rest.api.response; + +import java.util.Map; + +import com.power.doc.usecase.rest.pojo.description.BarDescription; +import com.power.doc.usecase.rest.pojo.description.FooDescription; +import com.power.doc.usecase.rest.pojo.type.BarType; + +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +/** + * Description Field + * @author zongzi + */ +@RestController +@RequestMapping("/response/description") +public class ResponseDescriptionUseCase { + /** + * Return Basic Type + * @apiNote 如果方法返回的是个简单对象,则没有地方进行说明 + * @return Integer id + */ + @GetMapping("/simple-int") + public Integer foo() { + return null; + } + + /** + * Return Self-Definition Type + * @apiNote 如果方法的返回对象是个自定义对象,可以在对象的成员变量上添加注释,进行说明 + * @return FooDescription + */ + @GetMapping("/self-definition-type") + public FooDescription bar() { + return null; + } + + + /** + * Special Character + * @apiNote 一些描述中的特殊字符 + * @return BarDescription 测试对象 + */ + @GetMapping("/special-characters") + public BarDescription koo(){ + return null; + } + + /** + * Return Map + * @apiNote 使用Map作为返回对象 + * TODO ?003 对比下方的Map的返回,查看Description字段的差异,此处 "A map key" 是否应该改为类似 "The Vale Type of this field is string"? + * @return Map 测试对象列表 + */ + @GetMapping("return-map-string-string") + public Map fooReturnStringTypeMap() { + return null; + } + + /** + * Return Map + * @apiNote 使用Map作为返回对象 + * 注意,此时的Description中mapKey field 字段的描述是对象上的类注释, + * @return Map 返回对象类型 + */ + @GetMapping("return-map-string-self-type") + public Map fooReturnGenericTypeMap() { + return null; + } +} diff --git a/src/main/java/com/power/doc/usecase/rest/api/response/ResponseExampleUseCase.java b/src/main/java/com/power/doc/usecase/rest/api/response/ResponseExampleUseCase.java new file mode 100644 index 0000000..7a7d8d4 --- /dev/null +++ b/src/main/java/com/power/doc/usecase/rest/api/response/ResponseExampleUseCase.java @@ -0,0 +1,61 @@ +package com.power.doc.usecase.rest.api.response; + +import com.power.doc.usecase.rest.pojo.required.BarJsr303; +import com.power.doc.usecase.rest.pojo.value.BarValue; +import com.power.doc.usecase.rest.pojo.value.FooValue; + +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +/** + * Response Example + * @author zongzi + */ +@RestController +@RequestMapping("/response/response-example") +public class ResponseExampleUseCase { + /** + * Return With Default Auto Mock + * @apiNote 在默认情况下smart-doc可以根据参数的类型为你生成示例值 + * 注意: + * 1、TODO #021 下方Response-example一栏中的"fooByte"示例值为字符串,存在问题 + * 2、TODO #022 下方Response-example一栏中的"fooCharInBox"示例值为字符串,存在问题 + * 3、TODO #023 下方Response-example一栏中的"fooEnumMap"示例值的Key为MapKey,是否存在问题? + * @param foo 测试对象 + */ + @GetMapping("/return-with-default_mock") + public FooValue defaultMock() { + return null; + } + + /** + * Return Type With @mock Tag + * @apiNote 也可以使用@mock来自己指定示例值(通过在属性上使用@mock)字段,如下所示 + * + * class BarValue{ + * //@mock "this is my mock string with "{"fooString":"123"} \" " + * String barString; + * //@mock 123a + * int barInt; + * //这里没有使用@mock注解,则交由smart-doc自动生成示例值 + * long barLong; + * } + * + */ + @GetMapping("/return-self-type-with-manual-mock") + public BarValue manualMock() { + return null; + } + + + /** + * Return Type Use JSR-303 + * @apiNote 使用JSR-303的注解无法影响示例值的产生逻辑。 + * @return BarJsr303 + */ + @GetMapping("/example-with-jsr-303") + public BarJsr303 exampleWithJsr303() { + return null; + } +} diff --git a/src/main/java/com/power/doc/usecase/rest/api/response/ResponseFieldNameUseCase.java b/src/main/java/com/power/doc/usecase/rest/api/response/ResponseFieldNameUseCase.java new file mode 100644 index 0000000..39f20be --- /dev/null +++ b/src/main/java/com/power/doc/usecase/rest/api/response/ResponseFieldNameUseCase.java @@ -0,0 +1,75 @@ +package com.power.doc.usecase.rest.api.response; + +import com.power.doc.usecase.rest.pojo.parameter.FooJsonParameterName; +import com.power.doc.usecase.rest.pojo.parameter.FooParameterName; + +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +/** + * Response Filed Name + * @author zongzi + */ +@RestController +@RequestMapping("/response/field-name") +public class ResponseFieldNameUseCase { + /** + * Ignore Some Parameter(Use @ignore) + * @apiNote 使用@ignore字段可以在生成的Body-Parameter字段中忽略一些字段, + * 举例说明:声明一个对象Foo + * + * class Foo{ + * // 此字段应该被正常渲染 + * String fooStringNotIgnore; + * + * //此字段会在最后的渲染结果中被忽略 + * //@ignore + * String fooStringToIgnore; + * + * } + * + * 并在方法上返回 + * TODO #032 在Response-example中,产生了被忽略值的示例,和Response-fields中的表现不一致 + * @return FooParameterName 示例对象 + */ + @PostMapping("/use-ignore") + public FooParameterName fooUseIgnore() { + return null; + } + + /** + * Use Jackson Annotations + * @apiNote 使用 com.fasterxml.jackson.annotation 下的注解 + * `@JsonProperty / `@JsonProperty / `@JsonIgnore /`@JsonIgnoreType进行用例展示 + *
    +	 * `@JsonIgnoreProperties({"fooClassStringToIgnore"})
    +	 * class Foo{
    +	 *       //此字段
    +	 *       `@JsonProperty("fooString")
    +	 *        String fooStringWithJsonAnnotation;
    +	 *
    +	 *    	 `@JsonIgnore
    +	 *    	 String fooStringToIgnore;
    +	 *
    +	 * 		 //在Class上声明被忽略的成员变量
    +	 * 	     String fooClassStringToIgnore;
    +	 *
    +	 * 		 //使用@JsonIgnoreType声明的类型
    +	 * 		 Bar bar;
    +	 *   }
    +	 * `@JsonIgnoreType
    +	 * `@Data
    +	 * class Bar {
    +	 * 		String barString;
    +	 * }
    +	 * 
    + * TODO #033 JsonIgnoreType似乎没有起作用,查看下方的Response-fields, bar字段还是正常显示了 + * @return FooJsonParameterName 使用了一些jackson的注解对象 + * + */ + @PostMapping("/use-jackson-annotation") + public FooJsonParameterName fooUseFastJsonAnnotation() { + return null; + } +} diff --git a/src/main/java/com/power/doc/usecase/rest/api/response/ResponseSinceFieldUseCase.java b/src/main/java/com/power/doc/usecase/rest/api/response/ResponseSinceFieldUseCase.java new file mode 100644 index 0000000..84ec7a9 --- /dev/null +++ b/src/main/java/com/power/doc/usecase/rest/api/response/ResponseSinceFieldUseCase.java @@ -0,0 +1,50 @@ +package com.power.doc.usecase.rest.api.response; + +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +/** + * Since Field + * @author zongzi + */ +@RestController +@RequestMapping("/response/since/") +public class ResponseSinceFieldUseCase { + + + /** + * Usage of @since tag + */ + @GetMapping("usage-of-since-tag") + public FooSince foo() { + return null; + } + +} +class FooSince{ + /** + * Use case of single @since tag + * @since 0.0.0.1 + */ + String fooString; + /** + * Use case of multiple @since tag + * @since 0.0.0.1 + * @since 0.0.0.2 + */ + Integer fooInteger; + + /** + * Use case of @since with special characters (etc. html,multiple lines) + * @since 2022-12-01_11.1.1.1 + * @since 2022-12-01の11.1.1.1
    + * @since
    2.5.3
    + * @since this is a since tag use + * multiple lines + * @since @mock @param @ignore @return + * @since 123456@qq.com + * @since ,,,,,,,,,, + */ + Long fooLong; +} \ No newline at end of file diff --git a/src/main/java/com/power/doc/usecase/rest/api/response/ResponseTypeFieldUseCase.java b/src/main/java/com/power/doc/usecase/rest/api/response/ResponseTypeFieldUseCase.java new file mode 100644 index 0000000..ed6c4a8 --- /dev/null +++ b/src/main/java/com/power/doc/usecase/rest/api/response/ResponseTypeFieldUseCase.java @@ -0,0 +1,193 @@ +package com.power.doc.usecase.rest.api.response; + +import java.util.List; +import java.util.Map; + +import com.power.doc.usecase.rest.pojo.result.BarResult; +import com.power.doc.usecase.rest.pojo.result.FooResult; +import com.power.doc.usecase.rest.pojo.type.BarType; +import com.power.doc.usecase.rest.pojo.type.FooCircleDependency; +import com.power.doc.usecase.rest.pojo.type.FooType; + +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +/** + * Type Field + * @author zongzi + */ +@RestController +@RequestMapping("/response/type-field") +public class ResponseTypeFieldUseCase { + /** + * Return Basic Type + * @apiNote 返回基本类型 + *
    +	 *     `@GetMapping("/return-basic-type")
    +	 *     public Integer fooReturnBasicType(){};
    +	 * 
    + * TODO #034 返回基础类型时,没有Response-fields字段了,和Response-example的表现不一致 + * @return Integer id + */ + @GetMapping("/return-basic-type") + public Integer fooReturnBasicType() { + return null; + } + + /** + * Return Self-Definition Type + * @apiNote 自定义类型, 可以直接在参数列表中声明,代码如下 + * + * `@GetMapping("/return-sel-definition-type")` + * public void fooReturnSelfDefinitionType(){} + * + * + * @return FooType 测试自定义对象 + */ + @GetMapping("/return-sel-definition-type") + public FooType fooReturnSelfDefinitionType() { + return null; + } + + /** + * Return Dependency Type + * @apiNote 返回 Foo对象,foo的成员变量有bar,bar的成员变量有foo + * + * @return FooCircleDependency 测试对象 + */ + @GetMapping("/return-circle-dependency-type") + public FooCircleDependency fooReturnCircleDependency() { + return null; + } + + + /** + * Return Integers[] + * @apiNote 声明基础类型数组作为返回对象 + * TODO ?002 返回的对象是Array, 但是Type显示为int32, 是否需要改为Array?或者在Description进行说明, 下面的三个用例的情况基本相同 + * @return Integer[] 测试ID列表 + */ + @GetMapping("/return-basic-type-array") + public Integer[] fooReturnArrayBasicType() { + return null; + } + + /** + * Return Boo[] + * @apiNote 声明对象数组作为返回对象 + * @return BarType[] 测试对象数组 + */ + @GetMapping("return-object-array") + public BarType[] fooReturnArrayObjects() { + return null; + } + + + /** + * Return List + * @apiNote 使用泛型声明作为返回对象 + * @param List 测试对象列表 + */ + @GetMapping("return-type-list") + public List fooReturnTypeList() { + return null; + } + + /** + * Return List + * @apiNote 使用泛型声明作为返回对象 + * @param List 测试对象列表 + */ + @GetMapping("return-type-list") + public List fooReturnCircleDependencyTypeList() { + return null; + } + + /** + * Return List> + * @apiNote 使用泛型声明作为返回对象 + * @param List 测试对象列表 + */ + @GetMapping("return-map-type-list") + public List> fooReturnMapStringTypeList() { + return null; + } + + /** + * Return Map + * @apiNote 使用Map作为返回对象 + * TODO ?004 对比下方的Map的返回类型,似乎Type字段应该支持 map 等类似的描述? + * @return Map 测试对象列表 + */ + @GetMapping("return-map-string-string") + public Map fooReturnStringTypeMap() { + return null; + } + + /** + * Return Map + * @apiNote 使用Map作为返回对象 + * @return Map 返回对象类型 + */ + @GetMapping("return-map-string-self-type") + public Map fooReturnGenericTypeMap() { + return null; + } + + /** + * Return Map> + * @apiNote 使用Map>作为返回对象 + * @return Map> 返回对象类型 + */ + @GetMapping("return-map-string-list-self-type") + public Map> fooReturnMapListSelfType() { + return null; + } + + /** + * Return Result + * @return FooResult + */ + @GetMapping + public FooResult fooReturnGenericResult() { + return null; + } + + /** + * Return Result + * @return FooResult + */ + @GetMapping + public FooResult fooReturnGenericBasicTypeResult() { + return null; + } + + /** + * Return Result> + * @return FooResult + */ + @GetMapping + public FooResult> fooReturnGenericListBasicTypeResult() { + return null; + } + + /** + * Return Result> + * @return FooResult + */ + @GetMapping + public FooResult> fooReturnGenericListSelfTypeResult() { + return null; + } + + /** + * Return Result + * @return + */ + @GetMapping + public BarResult fooReturnGenericType2() { + return null; + } +} + diff --git a/src/main/java/com/power/doc/usecase/rest/pojo/description/BarDescription.java b/src/main/java/com/power/doc/usecase/rest/pojo/description/BarDescription.java new file mode 100644 index 0000000..57ace4c --- /dev/null +++ b/src/main/java/com/power/doc/usecase/rest/pojo/description/BarDescription.java @@ -0,0 +1,44 @@ +package com.power.doc.usecase.rest.pojo.description; + +import lombok.Data; + +/** + * 特殊字符测试 + * @author zongzi + */ +@Data +public class BarDescription { + /** + * `!@#$%^&*()_~{}[]\;':",./<>? + * (*´▽`)ノノ + * (灬ꈍ ꈍ灬) + * 🤺 + * 😂 + * の + */ + String barString; + + /** + *  < > + * ccccccc + * + *

    这是一个段落

    + * System.out.println("this are some code") + * + * {@code System.out.println("this is a code snippet use @code ") + *
    + *
    +	 *     public class Foo {
    +	 *         private String fooString;
    +	 *     }
    +	 * 
    + * + *
  • aaa
  • + *
  • bbb
  • + *
    + * `` + * this is a link to smart-doc's doc + * TODO #014 如果代码中的注释使用`Map<_;String,Bar>_;`则生成的HTML文档中所有其他地方的< 会变成<(即进行转义),如果是类成员变量上的HTML代码,也可以在结果中正常渲染 + */ + int barInt; +} diff --git a/src/main/java/com/power/doc/usecase/rest/pojo/description/FooDescription.java b/src/main/java/com/power/doc/usecase/rest/pojo/description/FooDescription.java new file mode 100644 index 0000000..a95210b --- /dev/null +++ b/src/main/java/com/power/doc/usecase/rest/pojo/description/FooDescription.java @@ -0,0 +1,15 @@ +package com.power.doc.usecase.rest.pojo.description; + +import lombok.Data; + +/** + * 用例表述对象 + * @author zongzi + */ +@Data +public class FooDescription { + /** + * 测试参数说明 + */ + String fooString; +} diff --git a/src/main/java/com/power/doc/usecase/rest/pojo/parameter/BarJsonParameterName.java b/src/main/java/com/power/doc/usecase/rest/pojo/parameter/BarJsonParameterName.java new file mode 100644 index 0000000..6f6b4bf --- /dev/null +++ b/src/main/java/com/power/doc/usecase/rest/pojo/parameter/BarJsonParameterName.java @@ -0,0 +1,14 @@ +package com.power.doc.usecase.rest.pojo.parameter; + +import com.fasterxml.jackson.annotation.JsonIgnoreType; +import lombok.Data; + +/** + * 被忽略的com.fasterxml.jackson.annotation注解 + * @author zongzi + */ +@JsonIgnoreType +@Data +public class BarJsonParameterName { + String barString; +} diff --git a/src/main/java/com/power/doc/usecase/rest/pojo/parameter/FooJsonParameterName.java b/src/main/java/com/power/doc/usecase/rest/pojo/parameter/FooJsonParameterName.java new file mode 100644 index 0000000..1e7d4b6 --- /dev/null +++ b/src/main/java/com/power/doc/usecase/rest/pojo/parameter/FooJsonParameterName.java @@ -0,0 +1,34 @@ +package com.power.doc.usecase.rest.pojo.parameter; + +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Data; + +/** + * 使用com.fasterxml.jackson.annotation注解的返回结果 + * @author zongzi + */ +@Data +@JsonIgnoreProperties({"fooClassStringToIgnore"}) +public class FooJsonParameterName { + /** + * 此处对象中声明的参数名是:fooStringWithJsonAnnotation, + * 但是使用了 @JsonProperty("fooString") 将参数名更新为fooString + */ + @JsonProperty("fooString") + String fooStringWithJsonAnnotation; + + @JsonIgnore + String fooStringToIgnore; + + /** + * 在Class上声明被忽略的成员变量 + */ + String fooClassStringToIgnore; + + /** + * 使用@JsonIgnoreType声明的类型,应该被忽略 + */ + BarJsonParameterName bar; +} diff --git a/src/main/java/com/power/doc/usecase/rest/pojo/parameter/FooParameterName.java b/src/main/java/com/power/doc/usecase/rest/pojo/parameter/FooParameterName.java new file mode 100644 index 0000000..46d98b0 --- /dev/null +++ b/src/main/java/com/power/doc/usecase/rest/pojo/parameter/FooParameterName.java @@ -0,0 +1,18 @@ +package com.power.doc.usecase.rest.pojo.parameter; + +import lombok.Data; + +@Data +public class FooParameterName { + + /** + * 此字段应该被正常渲染 + */ + String fooStringNotIgnore; + /** + * 此字段会在最后的渲染结果中被忽略 + * @ignore + */ + String fooStringToIgnore; + +} diff --git a/src/main/java/com/power/doc/usecase/rest/pojo/required/BarJsr303.java b/src/main/java/com/power/doc/usecase/rest/pojo/required/BarJsr303.java new file mode 100644 index 0000000..427db28 --- /dev/null +++ b/src/main/java/com/power/doc/usecase/rest/pojo/required/BarJsr303.java @@ -0,0 +1,145 @@ +package com.power.doc.usecase.rest.pojo.required; + +import java.util.Date; +import java.util.List; + +import javax.validation.constraints.AssertFalse; +import javax.validation.constraints.AssertTrue; +import javax.validation.constraints.DecimalMax; +import javax.validation.constraints.DecimalMin; +import javax.validation.constraints.Digits; +import javax.validation.constraints.Email; +import javax.validation.constraints.Future; +import javax.validation.constraints.FutureOrPresent; +import javax.validation.constraints.Max; +import javax.validation.constraints.Min; +import javax.validation.constraints.Negative; +import javax.validation.constraints.NegativeOrZero; +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.NotEmpty; +import javax.validation.constraints.NotNull; +import javax.validation.constraints.Null; +import javax.validation.constraints.Past; +import javax.validation.constraints.PastOrPresent; +import javax.validation.constraints.Pattern; +import javax.validation.constraints.Positive; +import javax.validation.constraints.PositiveOrZero; +import javax.validation.constraints.Size; + +import lombok.Data; + +/** + * 测试JSR-303标准注解 + * @author zongzi + */ +@Data +public class BarJsr303 { + /** + * 使用@NotNull规定必须不为空 + */ + @NotNull + String barNotNullString; + + @NotBlank + String barNotBlankString; + + @NotEmpty + String barNotEmptyString; + + /** + * #019-1 示例值应为空,此处正常生成了示例值 + */ + @Null + String barMustNullString; + + @AssertTrue + Boolean barMustTureBool; + + /** + * #019-2 示例值应为False,此处生成的示例值为True + */ + @AssertFalse + Boolean barMustFalseBool; + + @PositiveOrZero + Integer barPositiveOrZeroInt; + + @Positive + Integer barPositiveInt; + + /** + * #019-3 示例值为正数 + */ + @NegativeOrZero + Integer barNegativeOrZeroInt; + + /** + * #019-4 示例值为正数 + */ + @Negative + Integer barNegativeInt; + + + @Min(10) + int barMinInt; + + /** + * #019-5 最大值为11,示例值大于11 + */ + @Max(11) + int barMaxInt; + + @DecimalMin("10") + Long barMinDecimal; + + /** + * #019-6 最大值为100 + */ + @DecimalMax("100") + Long barMaxDecimal; + + + /** + * #019-7-0 Size[3,4] + * #019-7-1 对于@Size注解,自动生成的Validate[],只声明了Max,没有声明Min + */ + @Size(min = 3, max = 4) + String barSizeString; + + /** + * #019-8 Size[3,4] + */ + @Size(min = 3, max = 4) + List barSizeStringArray; + + /** + * #019-8 Digits(100.100) + */ + @Digits(integer = 100, fraction = 99) + Double barDigitsDouble; + + @Past + Date barPastDate; + @PastOrPresent + Date barPastOrPresent; + + @Future + Date barFutureDate; + @FutureOrPresent + Date barFutureOrPresentDate; + + /** + * #019-10 如果声明了注释,就会省略null,结合下面的字段一起查看 + */ + @Pattern(regexp = ".*") + String barPatternStringWithComment; + + @Pattern(regexp = ".*") + String barPatternString; + + /** + * #019-11 可以使用类似Xeger的库生成符合对应正则的实例字符串 + */ + @Email(regexp = ".*") + String barEmailString; +} diff --git a/src/main/java/com/power/doc/usecase/rest/pojo/required/FooRequired.java b/src/main/java/com/power/doc/usecase/rest/pojo/required/FooRequired.java new file mode 100644 index 0000000..7f25b25 --- /dev/null +++ b/src/main/java/com/power/doc/usecase/rest/pojo/required/FooRequired.java @@ -0,0 +1,19 @@ +package com.power.doc.usecase.rest.pojo.required; + +import lombok.Data; + +/** + * 测试必填字段 + * @author zongzi + */ +@Data +public class FooRequired { + /** + * 测试字符,必填 + * @required + * + */ + String fooString; + + Integer fooInteger; +} diff --git a/src/main/java/com/power/doc/usecase/rest/pojo/result/BarResult.java b/src/main/java/com/power/doc/usecase/rest/pojo/result/BarResult.java new file mode 100644 index 0000000..1f6a28d --- /dev/null +++ b/src/main/java/com/power/doc/usecase/rest/pojo/result/BarResult.java @@ -0,0 +1,21 @@ +package com.power.doc.usecase.rest.pojo.result; + +import com.power.doc.usecase.rest.pojo.type.FooEnum; +import lombok.Data; + +/** + * 多泛型的返回对象 + * @author zongzi + * @param + * @param + */ +@Data +public class BarResult{ + + + FooEnum code; + String message; + K fooData; + V barData; + String traceId; +} diff --git a/src/main/java/com/power/doc/usecase/rest/pojo/result/FooResult.java b/src/main/java/com/power/doc/usecase/rest/pojo/result/FooResult.java new file mode 100644 index 0000000..a85c16b --- /dev/null +++ b/src/main/java/com/power/doc/usecase/rest/pojo/result/FooResult.java @@ -0,0 +1,29 @@ +package com.power.doc.usecase.rest.pojo.result; + +import lombok.Data; + +/** + * 泛型返回对象 + * @author zongzi + * @param + */ +@Data +public class FooResult { + + /** + * 编码 + */ + String code; + /** + * ID + */ + String traceId; + /** + * 数据 + */ + T data; + /** + * 描述 + */ + String message; +} diff --git a/src/main/java/com/power/doc/usecase/rest/pojo/type/BarEnum.java b/src/main/java/com/power/doc/usecase/rest/pojo/type/BarEnum.java new file mode 100644 index 0000000..6575a8c --- /dev/null +++ b/src/main/java/com/power/doc/usecase/rest/pojo/type/BarEnum.java @@ -0,0 +1,12 @@ +package com.power.doc.usecase.rest.pojo.type; + +/** + * 示例枚举对象 + * @author zongzi + */ +public enum BarEnum { + /** + * 示例枚举对象 + */ + BAR_A,BAR_B,BAR_C +} diff --git a/src/main/java/com/power/doc/usecase/rest/pojo/type/BarType.java b/src/main/java/com/power/doc/usecase/rest/pojo/type/BarType.java new file mode 100644 index 0000000..6238a74 --- /dev/null +++ b/src/main/java/com/power/doc/usecase/rest/pojo/type/BarType.java @@ -0,0 +1,12 @@ +package com.power.doc.usecase.rest.pojo.type; + +import lombok.Data; + +/** + * 测试简单对象 + * @author zongzi + */ +@Data +public class BarType { + String barString; +} diff --git a/src/main/java/com/power/doc/usecase/rest/pojo/type/FooCircleDependency.java b/src/main/java/com/power/doc/usecase/rest/pojo/type/FooCircleDependency.java new file mode 100644 index 0000000..2ca0600 --- /dev/null +++ b/src/main/java/com/power/doc/usecase/rest/pojo/type/FooCircleDependency.java @@ -0,0 +1,35 @@ +package com.power.doc.usecase.rest.pojo.type; + +import javax.validation.constraints.NotNull; + +import lombok.Data; + +/** + * 循环依赖测试对象 + * @author zongzi + */ +@Data +public class FooCircleDependency { + /** + * foo自身成员变量 + */ + @NotNull + String fooString; + + /** + * foo 的成员变量为bar + */ + BarCircleDependency bar; +} +@Data +class BarCircleDependency { + /** + * Bar的成员变量foo + */ + FooCircleDependency foo; + + /** + * bar自身成员变量 + */ + String barString; +} \ No newline at end of file diff --git a/src/main/java/com/power/doc/usecase/rest/pojo/type/FooEnum.java b/src/main/java/com/power/doc/usecase/rest/pojo/type/FooEnum.java new file mode 100644 index 0000000..ac826a2 --- /dev/null +++ b/src/main/java/com/power/doc/usecase/rest/pojo/type/FooEnum.java @@ -0,0 +1,36 @@ +package com.power.doc.usecase.rest.pojo.type; + +/** + * 测试枚举对象 + * @author zongzi + */ +public enum FooEnum { + /** + * 示例枚举 + */ + FOO_A(1, "2"), FOO_B(1, "3"), FOO_C(2, "1"); + + private int fooInt; + private String fooString; + + FooEnum(int i, String j) { + this.fooInt = i; + this.fooString = j; + } + + public int getFooInt() { + return fooInt; + } + + public void setFooInt(int fooInt) { + this.fooInt = fooInt; + } + + public String getFooString() { + return fooString; + } + + public void setFooString(String fooString) { + this.fooString = fooString; + } +} diff --git a/src/main/java/com/power/doc/usecase/rest/pojo/type/FooType.java b/src/main/java/com/power/doc/usecase/rest/pojo/type/FooType.java new file mode 100644 index 0000000..f7add7a --- /dev/null +++ b/src/main/java/com/power/doc/usecase/rest/pojo/type/FooType.java @@ -0,0 +1,75 @@ +package com.power.doc.usecase.rest.pojo.type; + +import java.math.BigDecimal; +import java.util.Date; +import java.util.List; +import java.util.Map; + +import com.power.doc.usecase.rest.api.query.parameter.QueryParameterValueUseCase; +import lombok.Data; + +/** + * 测试对象类型 + * @author zongzi + */ +@Data +public class FooType { + Boolean fooBooleanInBox; + boolean fooBoolean; + Character fooCharInBox; + char fooChar; + Double fooDoubleInBox; + double foolDouble; + Float fooFloatInBox; + float fooFloat; + /** + * TODO #005 如果这里使用的包装类型Byte类型, 显示的Type类型为Object, + */ + Byte fooByteInBox; + byte fooByte; + Short fooShortInBox; + short foolShort; + Integer fooIntInBox; + int foolInt; + Long fooLongInBox; + long fooLong; + String fooString; + BigDecimal fooBigDecimal; + Date foolDate; + boolean[] fooBooleanArray; + char[] fooCharArray; + float[] fooFloatArray; + double[] fooDoubleArray; + byte[] fooByteArray; + short[] fooShortArray; + int[] fooIntArray; + BarType[] fooBarArray; + Long[] fooLongArray; + String[] fooStringArray; + List fooStringList; + BarType bar; + /** + * TODO #011 类型List<Bar>,示例值体现不出这是个Bar对象, + * 查看{@link QueryParameterValueUseCase}获取更多示例 + */ + List fooBarList; + /** + * TODO #012 类型List<String,Integer> 没有示例值, + * 查看{@link QueryParameterValueUseCase}获取更多示例 + */ + Map foolStringIntegerMap; + + /** + * TODO #013 类型Map<String,Bar> 示例值体现不出这个Map中是String和Bar对象, + * 查看{@link QueryParameterValueUseCase}获取更多示例 + */ + Map foolStringBarMap; + + FooEnum fooEnum; + List fooEnums; + /** + * TODO ?001 生成的Type字段中,是否需要指定Value的类型? + */ + Map fooEnumMap; +} + diff --git a/src/main/java/com/power/doc/usecase/rest/pojo/value/BarValue.java b/src/main/java/com/power/doc/usecase/rest/pojo/value/BarValue.java new file mode 100644 index 0000000..afdcba2 --- /dev/null +++ b/src/main/java/com/power/doc/usecase/rest/pojo/value/BarValue.java @@ -0,0 +1,29 @@ +package com.power.doc.usecase.rest.pojo.value; + +import lombok.Data; + + +/** + * 测试示例值对象 + * @author zongzi + */ +@Data +public class BarValue { + + /** + * TODO #036 此处携带JSON的关键字符会影响生成的response-example和request-body + * @mock "this is my mock string with "{"fooString":"123"} \" " + */ + String barString; + + /** + * TODO #016 这个地方的mock示例值,如果类型不对,也能正常渲染结果 + * @mock 123a + */ + int barInt; + + /** + * 这里没有使用@mock注解,则交由smart-doc自动生成示例值 + */ + long barLong; +} diff --git a/src/main/java/com/power/doc/usecase/rest/pojo/value/FooValue.java b/src/main/java/com/power/doc/usecase/rest/pojo/value/FooValue.java new file mode 100644 index 0000000..66800b6 --- /dev/null +++ b/src/main/java/com/power/doc/usecase/rest/pojo/value/FooValue.java @@ -0,0 +1,89 @@ +package com.power.doc.usecase.rest.pojo.value; + +import java.math.BigDecimal; +import java.util.Date; +import java.util.List; +import java.util.Map; + +import com.power.doc.usecase.rest.pojo.type.BarType; +import lombok.Data; + +/** + * 测试示例值对象 + * @author zongzi + */ +@Data +public class FooValue { + Boolean fooBooleanInBox; + boolean fooBoolean; + /** + * TODO #015 如果是包装的Char类型,显示的示例值为多位的字符串 + */ + Character fooCharInBox; + char fooChar; + Double fooDoubleInBox; + double fooDouble; + Float fooFloatInBox; + float fooFloat; + Byte fooByteInBox; + byte fooByte; + Short fooShortInBox; + short fooShort; + Integer fooIntInBox; + int fooInt; + Long fooLongInBox; + long fooLong; + String fooString; + BigDecimal fooBigDecimal; + Date foolDate; + boolean[] fooBooleanArray; + char[] fooCharArray; + float[] fooFloatArray; + double[] fooDoubleArray; + byte[] fooByteArray; + short[] fooShortArray; + int[] fooIntArray; + BarType bar; + BarType[] fooBarArray; + Long[] fooLongArray; + String[] fooStringArray; + List fooStringList; + List fooBarList; + Map foolStringIntegerMap; + Map foolStringBarMap; + FooEnum fooEnum; + List fooEnums; + Map fooEnumMap; + +} + +enum FooEnum { + /** + * 示例枚举 + */ + BAR_A(1, "2"), BAR_B(1, "3"), BAR_C(2, "1"); + + private int fooInt; + private String fooString; + + FooEnum(int i, String j) { + this.fooInt = i; + this.fooString = j; + } + + public int getFooInt() { + return fooInt; + } + + public void setFooInt(int fooInt) { + this.fooInt = fooInt; + } + + public String getFooString() { + return fooString; + } + + public void setFooString(String fooString) { + this.fooString = fooString; + } +} diff --git a/src/main/java/com/power/doc/usecase/rpc/api/meta/AuthorUseCase.java b/src/main/java/com/power/doc/usecase/rpc/api/meta/AuthorUseCase.java new file mode 100644 index 0000000..a2ce2c9 --- /dev/null +++ b/src/main/java/com/power/doc/usecase/rpc/api/meta/AuthorUseCase.java @@ -0,0 +1,23 @@ +package com.power.doc.usecase.rpc.api.meta; + +/** + * RPC.Meta.Author Usecase + * @author zongzi + * @dubbo + */ +public interface AuthorUseCase { + + /** + * Default Author + * @apiNote 默认的Service作者是空,可以通过@author指定 + */ + void defaultAuthorIsNull(); + + + /** + * Method Author Is Not Available + * @apiNote 在方法上声明的@author是不会被渲染的 + * @author zongzi-1 + */ + void methodVersionIsNotAvailable(); +} diff --git a/src/main/java/com/power/doc/usecase/rpc/api/meta/ProtocolUseCase.java b/src/main/java/com/power/doc/usecase/rpc/api/meta/ProtocolUseCase.java new file mode 100644 index 0000000..26c69f1 --- /dev/null +++ b/src/main/java/com/power/doc/usecase/rpc/api/meta/ProtocolUseCase.java @@ -0,0 +1,19 @@ +package com.power.doc.usecase.rpc.api.meta; + +/** + * RPC.Meta.Protocol Usecase + * + * @author zongzi + * @dubbo + */ +public interface ProtocolUseCase { + + /** + * Default Protocol + * @apiNote TODO 0x01 一般情况下无法指定协议,都是dubbo。 + * @since 2.5.3 + */ + void thereAreNoOtherWayToSpecifyProtocol(); + + +} diff --git a/src/main/java/com/power/doc/usecase/rpc/api/meta/ServiceUseCase.java b/src/main/java/com/power/doc/usecase/rpc/api/meta/ServiceUseCase.java new file mode 100644 index 0000000..d023ac9 --- /dev/null +++ b/src/main/java/com/power/doc/usecase/rpc/api/meta/ServiceUseCase.java @@ -0,0 +1,17 @@ +package com.power.doc.usecase.rpc.api.meta; + +/** + * RPC.Meta.Service Usecase + * @dubbo + * @author zongzi + */ +public interface ServiceUseCase { + + /** + * Service Come From Class Path + * @apiNote RPC.Meta.Service 和 RPC.Meta.URI的生成逻辑相同 + */ + void fooServiceComeFromClassPath(); +} + + diff --git a/src/main/java/com/power/doc/usecase/rpc/api/meta/UriUseCase.java b/src/main/java/com/power/doc/usecase/rpc/api/meta/UriUseCase.java new file mode 100644 index 0000000..7f8784f --- /dev/null +++ b/src/main/java/com/power/doc/usecase/rpc/api/meta/UriUseCase.java @@ -0,0 +1,29 @@ +package com.power.doc.usecase.rpc.api.meta; + +/** + * RPC.Meta.URI Usecase + * @dubbo + * @author zongzi + */ +interface UriUseCase { + + /** + * URI Come From Interface's ClassPath + * @apiNote TODO 0x00 接口元数据中的URI来源于标注了@dubbo注解的类路径,但是会多带上http信息(因为smart-doc.json)中的配置。 + */ + void uriComeFromInterfaceClassPath(); + + /** + * RPC.Meta.URI(Inner Interface) Usecase + * @dubbo + */ + interface FooInnerRpc{ + /** + * URI Come From Interface's ClassPath + * @apiNote 即使是内部类,也会同样按照包路径+类名 生成接口级的文档 + */ + void foo(); + } +} + + diff --git a/src/main/java/com/power/doc/usecase/rpc/api/meta/VersionUseCase.java b/src/main/java/com/power/doc/usecase/rpc/api/meta/VersionUseCase.java new file mode 100644 index 0000000..9672855 --- /dev/null +++ b/src/main/java/com/power/doc/usecase/rpc/api/meta/VersionUseCase.java @@ -0,0 +1,36 @@ +package com.power.doc.usecase.rpc.api.meta; + +/** + * RPC.Meta.Version Usecase + * @author zongzi + * @dubbo + * @version 2.5.3 + */ +public interface VersionUseCase { + + /** + * Use @version + * @apiNote 可以使用@version来指定整个Dubbo Service的版本,不指定时,此项为空 + */ + void versionTagUse(); + + /** + * When Use Multiple Versions + * @apiNote 使用多个@version来指定dubbo,同时又包含继承关系,只会有最后一个version会生效,查看RPC.Meta.Version Inherit Use Case章节, + * 可以在@version字段使用html代码。 + * + * + */ + void multipleVersion(); +} + + +/** + * RPC.Meta.Version Inherit Usecase + * @dubbo + * @author zongzi + * @version 1.2.2 + */ +interface VersionInheritUseCase extends VersionUseCase { + +} \ No newline at end of file diff --git a/src/main/java/com/power/doc/usecase/rpc/api/method/invoke/DescriptionFieldUseCase.java b/src/main/java/com/power/doc/usecase/rpc/api/method/invoke/DescriptionFieldUseCase.java new file mode 100644 index 0000000..1cfe32a --- /dev/null +++ b/src/main/java/com/power/doc/usecase/rpc/api/method/invoke/DescriptionFieldUseCase.java @@ -0,0 +1,108 @@ +package com.power.doc.usecase.rpc.api.method.invoke; + +import java.math.BigDecimal; +import java.util.Date; +import java.util.List; +import java.util.Set; + +import javax.validation.constraints.Email; +import javax.validation.constraints.Max; +import javax.validation.constraints.Pattern; +import javax.validation.constraints.Size; + +import com.power.doc.usecase.rest.pojo.type.FooEnum; +import com.power.doc.usecase.rpc.api.pojo.description.FooDescription; +import org.beetl.ow2.asm.optimizer.Shrinker; + +/** + * RPC.Method.Invoke.Description Usecase + * @author zongzi + * @dubbo + */ +public interface DescriptionFieldUseCase { + + /** + * Basic Type Description + * @apiNote 测试基本对象的Description的渲染效果 + * @param fooByte 测试参数描述 + * @param fooShort 测试参数描述 + * @param fooInt 测试参数描述 + * @param fooLong 测试参数描述 + * @param fooBool 测试参数描述 + * @param fooChar 测试参数描述 + * @param fooDouble 测试参数描述 + * @param fooFloat 测试参数描述 + * @param fooDate 测试参数描述 + * @param fooBigDecimal 测试参数描述 + * @param fooString 测试参数描述 + * @param fooEnum 测试参数描述 TODO 0x0A Description中没有展示枚举对象的示例值 + */ + + void useBasicTypesBox(Byte fooByte, Short fooShort, Integer fooInt, Long fooLong, Boolean fooBool, Character fooChar, Double fooDouble, Float fooFloat, + Date fooDate, BigDecimal fooBigDecimal, String fooString, FooEnum fooEnum); + + + /** + * Use Arrays + * @apiNote 当使用数组时,Description中会展示(children type: xxx)
    + * TODO 0x0B 枚举数组被直接忽略未渲染,使用...方式声明的参数可以正常渲染,但是没有展示(childre type:xxx) + * @param fooBytes 测试Byte数组 + * @param fooShorts 测试Short数组 + * @param fooInts 测试Integer数组 + * @param fooLongs 测试Long数组 + * @param fooEnums 测试枚举数组(注意,这个类型被直接忽略了未渲染) + * @param fooEnums2 使用...的方式声明的枚举数组 + */ + void useArray(Byte[] fooBytes, Short[] fooShorts, Integer[] fooInts, Long[] fooLongs, FooEnum[] fooEnums, FooEnum... fooEnums2); + + /** + * Use Collections & Collection + * @apiNote 当使用List/Set的形式作为入参时 Description中会展示(children type: xxx)
    + * 同样的也存在枚举类型无法渲染的问题 + * @param fooBytes 测试参数描述 + * @param fooShorts 测试参数描述 + * @param fooInts 测试参数描述 + * @param fooLong 测试参数描述 + * @param fooDate 测试参数描述 + * @param fooString 测试参数描述 + * @param fooEnumList 测试参数描述 + * @param fooByteSet 测试参数描述 + * @param fooShortSet 测试参数描述 + * @param fooIntSet 测试参数描述 + * @param fooLonSet 测试参数描述 + * @param fooDatSet 测试参数描述 + * @param fooStrSet 测试参数描述 + * @param fooEnumSet 测试参数描述 + */ + void useCollection(List fooBytes, List fooShorts, List fooInts, List fooLong, List fooDate, List fooString, + List fooEnumList, Set fooByteSet, Set fooShortSet, Set fooIntSet, Set fooLonSet, Set fooDatSet, Set fooStrSet, + Set fooEnumSet); + + /** + * When Use JSR-303 Annotations + * @apiNote 当使用JSR-303的注解时,Description字段会拼接此类注解的描述信息Validate[]中进行显示, + * TODO 0x0E 注意:如果使用JSR-303字段,但是不添加描述的话,缺省值不是 No comments Founds 而是 null + * @param fooEmail 测试@email字段情况 + * @param fooRegex 测试@Pattern字段情况 + * @param fooSize 测试@Size字段情况 + * @param fooEmailNoComment + */ + void useJsr303(@Email(regexp = ".*")String fooEmail,@Pattern(regexp = ".*")String fooRegex,@Size(max = 10,min = 1) String fooSize, + @Email(regexp = ".*") String fooEmailNoComment); + /** + * Use Html Code At Description Area + * @apiNote 可以在参数描述区域使用HTML标签 + * @param fooStr 此处用来展示参数描述 System.out.println("this is a code snippet");
    + * smart-doc + */ + void useHtmlCode(String fooStr); + + + /** + * When Claim A Description At Class's Parameter Area + * @apiNote 在类的参数上的描述使用实例 + * @param foo 测试对象 + */ + void useSelfDefinition(FooDescription foo); +} + diff --git a/src/main/java/com/power/doc/usecase/rpc/api/method/invoke/ParameterNameUseCase.java b/src/main/java/com/power/doc/usecase/rpc/api/method/invoke/ParameterNameUseCase.java new file mode 100644 index 0000000..08945f9 --- /dev/null +++ b/src/main/java/com/power/doc/usecase/rpc/api/method/invoke/ParameterNameUseCase.java @@ -0,0 +1,23 @@ +package com.power.doc.usecase.rpc.api.method.invoke; + +import java.util.Map; + +/** + * PRC.Method.Invoke.Parameter Usecase + * @dubbo + * @author zongzi + */ +public interface ParameterNameUseCase { + + + /** + * Parameter Name + * @apiNote 测试字段名称的渲染效果。TODO 0x09 strMap的字段名称为-, 但是作为返回参数时就没有问题, + * + * @param strMap 测试数组 + * @param fooStr 测试字段 + * @param barStr 数组测试字段 + */ + void invokeParameterName(Map strMap,String fooStr,String... barStr); + +} diff --git a/src/main/java/com/power/doc/usecase/rpc/api/method/invoke/RequiredUseCase.java b/src/main/java/com/power/doc/usecase/rpc/api/method/invoke/RequiredUseCase.java new file mode 100644 index 0000000..d1d7379 --- /dev/null +++ b/src/main/java/com/power/doc/usecase/rpc/api/method/invoke/RequiredUseCase.java @@ -0,0 +1,33 @@ +package com.power.doc.usecase.rpc.api.method.invoke; + +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.NotEmpty; +import javax.validation.constraints.NotNull; + +import com.power.doc.usecase.rpc.api.pojo.required.RpcBarJsr303; + +/** + * RPC.Method.Invoke.Required Usecase + * @dubbo + * @author zongzi + */ +public interface RequiredUseCase { + + + /** + * Use JSR-303 Annotation + * @apiNote 可以使用@NotNull/@NotEmpty/@NotBlank注解来将参数标识为必传,默认情况下为false(非必传) + * @param fooStr 使用@NotNull注解 + * @param barStr 使用@NotEmpty注解 + * @param kooStr 使用@NotBlank注解 + * @param bizStr 未使用注解情况下默认为"非必传" + */ + void useJsr303Tag(@NotNull String fooStr, @NotEmpty String barStr, @NotBlank String kooStr,String bizStr); + + /** + * Use JSR-303 Inner Class + * @apiNote 同样也可以在实体类中标注JSR-303注解的形式影响Required字段 + * @param rpcBarJsr303 使用了JSR-303注解的实体类 + */ + void useJsr303TagInnerClass(RpcBarJsr303 rpcBarJsr303); +} diff --git a/src/main/java/com/power/doc/usecase/rpc/api/method/invoke/SinceFieldUseCase.java b/src/main/java/com/power/doc/usecase/rpc/api/method/invoke/SinceFieldUseCase.java new file mode 100644 index 0000000..1f977df --- /dev/null +++ b/src/main/java/com/power/doc/usecase/rpc/api/method/invoke/SinceFieldUseCase.java @@ -0,0 +1,20 @@ +package com.power.doc.usecase.rpc.api.method.invoke; + +import com.power.doc.usecase.rpc.api.pojo.since.RpcFooSince; + +/** + * RPC.Method.Invoke.Since Usecase + * @dubbo + * @author zongzi + */ +public interface SinceFieldUseCase { + + /** + * Use @since + * @apiNote 可以在类的属性注释中使用@since注解来表明开始的版本 + * @param fooSince 实例SINCE对象 + * + */ + void useSinceTagAtMethod(RpcFooSince fooSince); +} + diff --git a/src/main/java/com/power/doc/usecase/rpc/api/method/invoke/TypeFieldUseCase.java b/src/main/java/com/power/doc/usecase/rpc/api/method/invoke/TypeFieldUseCase.java new file mode 100644 index 0000000..14759c2 --- /dev/null +++ b/src/main/java/com/power/doc/usecase/rpc/api/method/invoke/TypeFieldUseCase.java @@ -0,0 +1,164 @@ +package com.power.doc.usecase.rpc.api.method.invoke; + + +import java.math.BigDecimal; +import java.util.ArrayList; +import java.util.Date; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.Set; + +import javax.persistence.criteria.CriteriaBuilder; + +import com.power.doc.usecase.rest.pojo.type.BarEnum; +import com.power.doc.usecase.rest.pojo.type.BarType; +import com.power.doc.usecase.rest.pojo.type.FooCircleDependency; +import com.power.doc.usecase.rest.pojo.type.FooEnum; +import com.power.doc.usecase.rpc.api.pojo.type.RpcFooType; + +/** + * RPC.Method.Invoke.Type Usecase + * @dubbo + * @author zongzi + */ +public interface TypeFieldUseCase { + + /** + * Use Basic Type + * @apiNote 测试基本类型 + * @param fooByte + * @param fooShor + * @param fooInt + * @param fooLong + * @param fooBool + * @param fooChar + * @param fooDouble + * @param fooFlot + */ + void useBasicTypes(byte fooByte, short fooShor, int fooInt, long fooLong, boolean fooBool, char fooChar, double fooDouble, float fooFlot); + + /** + * Use Box Basic Type + * @apiNote 测试基本对象的包装类型 + * @param fooByte 测试Byte + * @param fooShort 测试Short + * @param fooInt 测试Integer + * @param fooLong 测试Long对象 + * @param fooBool 测试Boolean对象 + * @param fooChar 测试Character + * @param fooDouble 测试Double + * @param fooFloat 测试Float + * @param fooDate 测试日期对象 + * @param fooBigDecimal 测试Decimal对象 + * @param fooString 测试字符串对象 + * @param fooEnum 测试枚举对象 + */ + void useBasicTypesBox(Byte fooByte, Short fooShort, Integer fooInt, Long fooLong, Boolean fooBool, Character fooChar, Double fooDouble, Float fooFloat, + Date fooDate, BigDecimal fooBigDecimal,String fooString,FooEnum fooEnum); + + + + /** + * Use Self-Definition Type + * @apiNote 使用自定义类型 + * @param fooType 自定义测试字段 + */ + void selfDefinitionType(RpcFooType fooType); + + /** + * Use Optional Api + * @apiNote 使用Optional-API 作为入参的场景 + * @param fooOptional 使用Optional-API + */ + void useOptionalApi(Optional fooOptional); + /** + * Use Circle Dependence Type + * @apiNote 使用自定义的循环依赖乐行 + * @param fooCircleDependency 自定义的循环依赖对象 + * + */ + void circleDependencyType(FooCircleDependency fooCircleDependency); + + + + /** + * Use Array Types + * @apiNote 使用BarType[] barsBarType... bars2作为入参时的类型渲染
    + * TODO 0x02 使用...作入参传递时,Invoke-parameters的Type类型和单独传递时无法区分 + * @param barString 测试字符串列表 + * @param bars 测试对象列表 + * @param bars2 测试对象列表 + * + */ + void arrayTypes(String[] barString, BarType[] bars, BarType... bars2); + + /** + * Use Array Enums Types + * @apiNote 使用BarEnum[] barEnums,BarEnum... barEnums2作为入参时的类型渲染
    + * TODO 0x07 BarEnum[] 类型的参数被直接忽略 + * @param barEnums 测试枚举对象列表 + * @param barEnums2 测试枚举对象列表 + * + */ + void arrayTypes(BarEnum[] barEnums, BarEnum... barEnums2); + + + /** + * Use Collection Types(List) + * @apiNote 使用基本对象类型的集合做为入参时 + * @param fooString + * @param fooBytes + * @param fooShorts + * @param fooInts + * @param fooLong + * @param fooEnums TODO 0x0B当时用List时,参数被忽略 + * @param fooDate + * + */ + + void useCollection(List fooBytes,List fooShorts,List fooInts, List fooLong,List fooEnums,List fooDate,List fooString); + + /** + * Use Collection Types(Set) + * @param fooBytes + * @param fooShorts + * @param fooInts + * @param fooLong + * @param fooEnums TODO 0x0C当时用List时,参数被忽略 + * @param fooDate + * @param fooString + */ + void useCollection(Set fooBytes,Set fooShorts,Set fooInts, Set fooLong,Set fooEnums,Set fooDate,Set fooString); + + /** + * Use Collection Types(Self-Definition) + * @apiNote TODO 0x03 使用集合对象作为入参时,与单独传递对象时无法区分
    + * TODO 0x06 Set形式的参数在方法签名中被直接忽略 + * @param barSet 测试对象集合 + * @param barList 测试对象列表 + * @param barHashSet 测试对象集合 + * @param barArrayList 测试对象列表 + * @param barEnumSet 测试枚举对象集合 + */ + + void collectionTypes(Set barSet, List barList, HashSet barHashSet, ArrayList barArrayList, Set barEnumSet); + + /** + * Use Map Types + * @apiNote TODO 0x05 使用Map作为入参对象时的问题列表 + * + *
      strMap返回的参数名被忽略,description中返回String类型
    + *
      barMap字段的Type类型问题
    + *
      如果Map的key不是String,在渲染的文档中无法显示
    + *
      enumMap被直接忽略
    + *
    + * @param strMap Map + * @param barMap Map + * @param enumBarMap Map + * @param enumMap Map + */ + void mapTypes(Map strMap, Map barMap, Map enumBarMap, Map enumMap); +} + diff --git a/src/main/java/com/power/doc/usecase/rpc/api/method/meta/DefinitionUseCase.java b/src/main/java/com/power/doc/usecase/rpc/api/method/meta/DefinitionUseCase.java new file mode 100644 index 0000000..a2f874d --- /dev/null +++ b/src/main/java/com/power/doc/usecase/rpc/api/method/meta/DefinitionUseCase.java @@ -0,0 +1,48 @@ +package com.power.doc.usecase.rpc.api.method.meta; + +import javax.validation.constraints.NotNull; + +import com.power.doc.usecase.rest.pojo.type.FooType; +import com.power.doc.usecase.rpc.api.pojo.description.FooDescription; + +/** + * RPC.Method.Meta.Definition Usecase + * @author zongzi + * @dubbo + */ +public interface DefinitionUseCase { + + /** + * Default Method Definition + * @apiNote 定义一栏来源于方法的定义。 + */ + void definitionComeFromMethod(); + + + /** + * Maintain The Param Name + * @apiNote 注意:方法参数列表中的参数名也可以在Definition这一栏被维护 + * @param fooInts 测试字段名称 + */ + void alsoMaintainTheParamName(@NotNull Integer fooInt); + + /** + * When Use Arrays + * @apiNote 当使用(String[] fooStrings,Integer... fooInts传递参数时
    + * TODO 0x08 当时用...作为入参时,Definition中显示的是单个长度,查看:void whenPassArrays(String[] fooStrings, Integer fooInts) + * @param fooStrings 测试字符串入参 + * @param fooInts 测试入参 + */ + void whenPassArrays(String[] fooStrings,Integer... fooInts); + + + /** + * Return Arrays + * @apiNote TODO 0x15 当返回对象是数组时,Definition将数组标识丢弃了 + * 此处的方法声明是FooType[] returnArrayObjects();, + * 但是展示内容是 FooType returnArrayObjects() + * @return 返回对象列表 + */ + FooType[] returnArrayObjects(); + +} diff --git a/src/main/java/com/power/doc/usecase/rpc/api/method/meta/DescriptionUseCase.java b/src/main/java/com/power/doc/usecase/rpc/api/method/meta/DescriptionUseCase.java new file mode 100644 index 0000000..8f8f138 --- /dev/null +++ b/src/main/java/com/power/doc/usecase/rpc/api/method/meta/DescriptionUseCase.java @@ -0,0 +1,49 @@ +package com.power.doc.usecase.rpc.api.method.meta; + +/** + * PRC.Method.Meta.Description Usecase + * @dubbo + * @author zongzi + * @version 2.5.3 + */ +public interface DescriptionUseCase { + + /** + * Show Method Description + * @apiNote 方法上的@apiNote之后的内容会被添加Description这一栏,缺省为空 + * 在这一栏中的HTML代码会被正常渲染 + * + *
  • first
  • + *
  • second
  • + *
    + *
    +	 *     System.out.println("this is a code snippet");
    +	 * 
    + * This is a Tag:i
    + * 使用Tag:i渲染中文
    + * 使用渲染中文
    + * This is a Tag:b
    + * 使用Tag:b渲染中文
    + * 使用渲染中文
    + * This is a Tag:u
    + * 使用Tag:u渲染中文
    + * 使用渲染中文
    + * This a Tag:a
    + * 使用Tag:a渲染中文
    + * + * TODO 0x0D 以下HTML标签无法渲染 + */ + void showDescription(); + + + /** + * Use <> AS API Name Or < > + * @apiNote <....> <<<<<<>>>>>>> This is a Code Snippet + * TODO 0x04 当代码API的名称中出现<>,或者< >,渲染结果全部被替换为了对应的转义字符,这和HTML模版中的不一致,可读性也下降了 + * + */ + void useHtmlCodeAsMethodComment(); + + + +} diff --git a/src/main/java/com/power/doc/usecase/rpc/api/method/reponse/DescriptionUseCase.java b/src/main/java/com/power/doc/usecase/rpc/api/method/reponse/DescriptionUseCase.java new file mode 100644 index 0000000..062eafb --- /dev/null +++ b/src/main/java/com/power/doc/usecase/rpc/api/method/reponse/DescriptionUseCase.java @@ -0,0 +1,65 @@ +package com.power.doc.usecase.rpc.api.method.reponse; + + +import java.util.List; +import java.util.Map; + + +import com.power.doc.usecase.rest.pojo.result.FooResult; +import com.power.doc.usecase.rest.pojo.type.FooEnum; +import com.power.doc.usecase.rpc.api.pojo.description.FooDescription; + +/** + * RPC.Method.Response.Description Usecase + * @author zongzi + * @dubbo + */ +public interface DescriptionUseCase { + + + /** + * Return Self-Definition + * @apiNote 返回值的Description来源于对象属性注释 + * @return 示例描述对象 + */ + FooDescription selfDefinition(); + + + /** + * Return Lists + * @apiNote 返回值为列表时的参数描述 + * @return 示例描述对象 + */ + List returnListObjects(); + + + /** + * Return Maps + * @apiNote 当返回值是Map时,出现mapKey字样,并且描述内容来源于Map<K,V>中V的类注释。 + * @return 示例参数描述 + */ + Map returnMaps(); + + /** + * Return Map + * @apiNote 当返回值是Map<String,String>,出现mapKey字样,并且Description被固定为A map key + * @return 示例参数描述 + */ + Map returnMaps2(); + + /** + * Return Map With Enum + * @apiNote TODO 0x13 当返回Map中的Value为枚举对象时,Description一栏中没有给出枚举值内容 + * @return 示例参数描述 + */ + Map returnEnumMap(); + + + /** + * Return Self Generic Type + * @apiNote 当返回自定义的泛型封装对象时,注解来源于两者的属性上注解 + * @return + */ + FooResult returnSelfGenericType(); +} + diff --git a/src/main/java/com/power/doc/usecase/rpc/api/method/reponse/FieldNameUseCase.java b/src/main/java/com/power/doc/usecase/rpc/api/method/reponse/FieldNameUseCase.java new file mode 100644 index 0000000..5d4e9fe --- /dev/null +++ b/src/main/java/com/power/doc/usecase/rpc/api/method/reponse/FieldNameUseCase.java @@ -0,0 +1,36 @@ +package com.power.doc.usecase.rpc.api.method.reponse; + +import java.util.List; +import java.util.Map; + + +/** + * RPC.Method.Response.Field Usecase + * @dubbo + * @author zongzi + */ +public interface FieldNameUseCase { + + /** + * Return Map + * @apiNote TODO 0x19 同时使用 Map时,入参形式和上一个相同,无法区分,只能通过Definition区分。 + * @param foo 测试对象 + * @return + */ + Map returnStringMap(Map foo); + + /** + * Return Map> + * @apiNote TODO 0x18 同时使用 Map>时,Invoke-Parameters和Response-fields的展示逻辑不同。 + * @param foo 测试对象 + * @return + */ + Map> returnStringWithListString(Map> foo); + + /** + * Return List> + * @param foo 测试对象 + * @return + */ + List> returnStringWithListString(List> foo); +} diff --git a/src/main/java/com/power/doc/usecase/rpc/api/method/reponse/SinceFieldUseCase.java b/src/main/java/com/power/doc/usecase/rpc/api/method/reponse/SinceFieldUseCase.java new file mode 100644 index 0000000..8f5c2e8 --- /dev/null +++ b/src/main/java/com/power/doc/usecase/rpc/api/method/reponse/SinceFieldUseCase.java @@ -0,0 +1,21 @@ +package com.power.doc.usecase.rpc.api.method.reponse; + +import com.power.doc.usecase.rpc.api.pojo.since.RpcFooSince; + +/** + * RPC.Method.Response.Since Usecase + * @dubbo + * @author zongzi + * + */ +public interface SinceFieldUseCase { + + + /** + * Use @since + * @apiNote 可以在类的属性注释中使用@since注解来表明开始的版本 + * + * @return + */ + RpcFooSince useSinceTagAtMethod(); +} diff --git a/src/main/java/com/power/doc/usecase/rpc/api/method/reponse/TypeFieldUseCase.java b/src/main/java/com/power/doc/usecase/rpc/api/method/reponse/TypeFieldUseCase.java new file mode 100644 index 0000000..433fcf8 --- /dev/null +++ b/src/main/java/com/power/doc/usecase/rpc/api/method/reponse/TypeFieldUseCase.java @@ -0,0 +1,163 @@ +package com.power.doc.usecase.rpc.api.method.reponse; + +import java.util.Date; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import javax.persistence.criteria.CriteriaBuilder; + +import com.power.doc.usecase.rest.pojo.result.FooResult; +import com.power.doc.usecase.rest.pojo.type.FooEnum; +import com.power.doc.usecase.rpc.api.pojo.type.RpcFooType; + +/** + * RPC.Method.Response.Type Usecase + * @author zongzi + * @dubbo + */ +public interface TypeFieldUseCase { + + + /** + * Return Basic Type + * @apiNote TODO 0x0F 当返回简单类型时,Response-fields一栏未被展示 + * @return Integer 测试返回简单类型的描述 + */ + Integer returnBasicType(); + + /** + * Return Basic Type Array + * @apiNote TODO 0x17 返回简单类型的列表,Definition一栏展示错误 + * @return 示例描述对象 + */ + Integer[] returnBasicTypeArray(); + /** + * Return Basic Type List + * @apiNote TODO 0x16 返回简单类型的列表,Response-fields一栏未被展示 + * @return 示例描述对象 + */ + List returnBasicTypeList(); + /** + * Return Basic Type Lists + * @apiNote TODO 0x10 返回简单类型集合,Response-fields一栏未被展示 + * @return 示例描述对象 + */ + Set returnBasicTypeSet(); + + /** + * Return String Map + * @return + */ + Map returnStringMap(); + /** + * Return Basic Type With Generic + * @apiNote TODO 0x17 使用泛型封装Integer时,返回的type为int32,而不是像其他一样是包装类型的全路径 + * @return + */ + FooResult returnBasicTypeWithGeneric(); + + + /** + * Return Basic Type List With Generic + * @return + */ + FooResult> returnBasicTypeListWithGeneric(); + + + /** + * Return Basic Type List Map With Generic + * @return + */ + FooResult>> returnBasicTypeListMapWithGeneric(); + + + /** + * Return Basic Type Map List With Generic + * @return + */ + FooResult>> returnBasicTypeMapListWithGeneric(); + /** + * Return Enum + * @apiNote TODO 0x11 返回枚举对象时,Response-fields一栏未被展示 + * @return 示例描述对象 + */ + FooEnum returnEnum(); + + /** + * Return Enum Array + * @return + */ + FooEnum[] returnEnumArray(); + + /** + * Return Enum List + * @apiNote TODO 0x12 返回枚举对象列表时,Response-fields一栏未被展示 + * @return 示例描述对象 + */ + List returnEnumList(); + + /** + * Return Enums Set + * @apiNote TODO 0x14 返回枚举对象集合时,Response-fields一栏未被展示 + * @return 示例返回类型 + */ + Set returnEnumSet(); + + /** + * Return Enum Map + * @apiNote TODO 0x16 返回枚举的Map时,没有展示枚举的相信信息 + * @return + */ + Map returnEnumMap(); + /** + * Return Enum With Generic Type + * @apiNote TODO 0x15 使用泛型返回枚举对象是, Data的Type类型是 object,没有展示泛型内容 + * @return + */ + FooResult returnEnumWithGeneric(); + + /** + * Return Self-Definition Type + * @apiNote 返回自定义对象列表 + * @return 示例测试对象 + */ + RpcFooType returnSelfDefinition(); + + /** + * Return Foo Array + * @return + */ + RpcFooType[] returnFooTypeArray(); + + /** + * Return Foo List + * @return + */ + List returnFooTypeList(); + + /** + * Return Foo Set + * @return + */ + Set returnFooTypeSet(); + + /** + * Return Foo Map + * @return + */ + Map returnFooTypeMap(); + /** + * Return Foo With Generic + * @return + */ + FooResult returnFooTypeWithGeneric(); + + + /** + * Return Foo List With Generic + * @return + */ + FooResult> returnFooTypeListWithGeneric(); + +} diff --git a/src/main/java/com/power/doc/usecase/rpc/api/pojo/description/FooDescription.java b/src/main/java/com/power/doc/usecase/rpc/api/pojo/description/FooDescription.java new file mode 100644 index 0000000..349b43f --- /dev/null +++ b/src/main/java/com/power/doc/usecase/rpc/api/pojo/description/FooDescription.java @@ -0,0 +1,29 @@ +package com.power.doc.usecase.rpc.api.pojo.description; + +import lombok.Data; + +/** + * 参数描述示例对象 + * @author zongzi + */ +@Data +public class FooDescription { + + /** + * 属性参数描述1
    + *
    +	 *     System.out.println("Smart-Doc");
    +	 * 
    + * + */ + String fooStr; + + + /** + * 属性参数描述2
    + * 但是包含HTML标签,因此需要在编写注释时进行转义。 + * 1. List + * 2. This is a Tag:b + */ + String barStr; +} diff --git a/src/main/java/com/power/doc/usecase/rpc/api/pojo/required/RpcBarJsr303.java b/src/main/java/com/power/doc/usecase/rpc/api/pojo/required/RpcBarJsr303.java new file mode 100644 index 0000000..ece7b9f --- /dev/null +++ b/src/main/java/com/power/doc/usecase/rpc/api/pojo/required/RpcBarJsr303.java @@ -0,0 +1,108 @@ +package com.power.doc.usecase.rpc.api.pojo.required; + +import java.util.Date; +import java.util.List; + +import javax.validation.constraints.AssertFalse; +import javax.validation.constraints.AssertTrue; +import javax.validation.constraints.DecimalMax; +import javax.validation.constraints.DecimalMin; +import javax.validation.constraints.Digits; +import javax.validation.constraints.Email; +import javax.validation.constraints.Future; +import javax.validation.constraints.FutureOrPresent; +import javax.validation.constraints.Max; +import javax.validation.constraints.Min; +import javax.validation.constraints.Negative; +import javax.validation.constraints.NegativeOrZero; +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.NotEmpty; +import javax.validation.constraints.NotNull; +import javax.validation.constraints.Null; +import javax.validation.constraints.Past; +import javax.validation.constraints.PastOrPresent; +import javax.validation.constraints.Pattern; +import javax.validation.constraints.Positive; +import javax.validation.constraints.PositiveOrZero; +import javax.validation.constraints.Size; + +import lombok.Data; + +/** + * 测试JSR-303标准注解 + * @author zongzi + */ +@Data +public class RpcBarJsr303 { + @NotNull + String barNotNullString; + + @NotBlank + String barNotBlankString; + + @NotEmpty + String barNotEmptyString; + + @Null + String barMustNullString; + + @AssertTrue + Boolean barMustTureBool; + + @AssertFalse + Boolean barMustFalseBool; + + @PositiveOrZero + Integer barPositiveOrZeroInt; + + @Positive + Integer barPositiveInt; + + @NegativeOrZero + Integer barNegativeOrZeroInt; + + @Negative + Integer barNegativeInt; + + + @Min(10) + int barMinInt; + + @Max(11) + int barMaxInt; + + @DecimalMin("10") + Long barMinDecimal; + + @DecimalMax("100") + Long barMaxDecimal; + + + @Size(min = 3, max = 4) + String barSizeString; + + @Size(min = 3, max = 4) + List barSizeStringArray; + + @Digits(integer = 100, fraction = 99) + Double barDigitsDouble; + + @Past + Date barPastDate; + @PastOrPresent + Date barPastOrPresent; + + @Future + Date barFutureDate; + @FutureOrPresent + Date barFutureOrPresentDate; + + @Pattern(regexp = ".*") + String barPatternStringWithComment; + + @Pattern(regexp = ".*") + String barPatternString; + + @Email(regexp = ".*") + String barEmailString; +} diff --git a/src/main/java/com/power/doc/usecase/rpc/api/pojo/since/RpcFooSince.java b/src/main/java/com/power/doc/usecase/rpc/api/pojo/since/RpcFooSince.java new file mode 100644 index 0000000..683348f --- /dev/null +++ b/src/main/java/com/power/doc/usecase/rpc/api/pojo/since/RpcFooSince.java @@ -0,0 +1,35 @@ +package com.power.doc.usecase.rpc.api.pojo.since; + +import lombok.Data; + +@Data +public class RpcFooSince { + /** + * 从1.0.0版本开始 + * @since 1.0.0 + */ + String fooStr; + /** + * 从1.0.1版本开始 + * @since 1.0.1 + */ + Integer fooInt; + /** + * 从1.0.2,1.0.3版本开始 + * @since 1.0.2 + * @since 1.0.3 + */ + Enum fooEnum; + + /** + * 从2.5.3版本开始 + * @since 2.5.3 + */ + Double fooDouble; + + /** + * 从@#$%^&*(!!!版本开始 + * @since @#$%^&*(!!! + */ + Long fooLong; +} diff --git a/src/main/java/com/power/doc/usecase/rpc/api/pojo/type/RpcFooType.java b/src/main/java/com/power/doc/usecase/rpc/api/pojo/type/RpcFooType.java new file mode 100644 index 0000000..d9490a7 --- /dev/null +++ b/src/main/java/com/power/doc/usecase/rpc/api/pojo/type/RpcFooType.java @@ -0,0 +1,55 @@ +package com.power.doc.usecase.rpc.api.pojo.type; + +import java.math.BigDecimal; +import java.util.Date; +import java.util.List; +import java.util.Map; + +import com.power.doc.usecase.rest.pojo.type.BarType; +import com.power.doc.usecase.rest.pojo.type.FooEnum; +import lombok.Data; + +/** + * 测试RPC对象类型 + */ +@Data +public class RpcFooType { + Boolean fooBooleanInBox; + boolean fooBoolean; + Character fooCharInBox; + char fooChar; + Double fooDoubleInBox; + double foolDouble; + Float fooFloatInBox; + float fooFloat; + Byte fooByteInBox; + byte fooByte; + Short fooShortInBox; + short foolShort; + Integer fooIntInBox; + int foolInt; + Long fooLongInBox; + long fooLong; + String fooString; + BigDecimal fooBigDecimal; + Date foolDate; + BarType bar; + boolean[] fooBooleanArray; + char[] fooCharArray; + float[] fooFloatArray; + double[] fooDoubleArray; + byte[] fooByteArray; + short[] fooShortArray; + int[] fooIntArray; + long[] fooLongArray; + String[] fooStringArray; + BarType[] fooBarArray; + List fooStringList; + List fooBarList; + Map foolStringIntegerMap; + Map foolStringBarMap; + FooEnum fooEnum; + FooEnum[] fooEnumArray; + List fooEnumList; + Map fooEnumMap; +} diff --git a/src/main/resources/smart-doc.json b/src/main/resources/smart-doc.json index 1ad2026..db0716c 100644 --- a/src/main/resources/smart-doc.json +++ b/src/main/resources/smart-doc.json @@ -5,7 +5,7 @@ "allInOne": true, "coverOld": true, "createDebugPage": true, - "style":"xt256", + "style": "xt256", "packageFilters": "", "appKey": "20210318821914523354005504", "appToken": "17081fb20b1546a196121e781d3c6d01", @@ -16,74 +16,184 @@ "tornaDebug": true, "inlineEnum": true, "skipTransientField": true, - "requestHeaders": [ //设置请求头,没有需求可以不设置 - { - "name": "token",//请求头名称 - "type": "string",//请求头类型 - "desc": "desc",//请求头描述信息 - "value":"kk",//不设置默认null - "required": false,//是否必须 - "since": "-" //什么版本添加的改请求头 + "requestHeaders": [ + //设置请求头,没有需求可以不设置 + { + "name": "token", + //请求头名称 + "type": "string", + //请求头类型 + "desc": "desc", + //请求头描述信息 + "value": "kk", + //不设置默认null + "required": false, + //是否必须 + "since": "-", + // 什么版本添加的改请求头 + "pathPatterns": "/InnovateFruit/**" + // "excludePathPatterns": "/app/login" // 登录url=/app/page/将不会有该请求头 + }, + { + "name": "global-headers", + "type": "string", + "desc": "desc", + //请求头描述信息 + "value": "any string", + //不设置默认null + "required": false, + //是否必须 + "since": "2.5.3", + //什么版本添加的改请求头 + "pathPatterns": "/headers/*", + "excludePathPatterns": "/headers/set-exclude-header" + }, + { + "name": "specific-headers", + "type": "string", + "desc": "desc", + //请求头描述信息 + "value": "any string", + //不设置默认null + "required": false, + //是否必须 + "since": "2.5.3", + //什么版本添加的改请求头 + "pathPatterns": "/headers/set-specific-header" } ], - "requestParams": [ //设置请求头,没有需求可以不设置 - { - "name": "configPathParam",//请求头名称 - "type": "string",//请求头类型 - "desc": "desc",//请求头描述信息 - "paramIn": "path", // 参数所在位置 header-请求头, path-路径参数, query-参数 - "value":"testPath",//不设置默认null - "required": false,//是否必须 - "since": "-",//什么版本添加的改请求头 - "pathPatterns": "*"//正则表达式过滤请求头 + "requestParams": [ + //设置请求头,没有需求可以不设置 + { + "name": "configPathParam", + //请求头名称 + "type": "string", + //请求头类型 + "desc": "desc", + //请求头描述信息 + "paramIn": "path", + // 参数所在位置 header-请求头, path-路径参数, query-参数 + "value": "testPath", + //不设置默认null + "required": false, + //是否必须 + "since": "-", + //什么版本添加的改请求头 + "pathPatterns": "*" + //正则表达式过滤请求头 }, { - "name": "configQueryParam",//请求头名称 - "type": "string",//请求头类型 - "desc": "desc",//请求头描述信息 + "name": "configQueryParam", + //请求头名称 + "type": "string", + //请求头类型 + "desc": "desc", + //请求头描述信息 "paramIn": "query", - "value":"testQuery",//不设置默认null - "required": false,//是否必须 - "since": "-",//什么版本添加的改请求头 - "pathPatterns": "*"//正则表达式过滤请求头 + "value": "testQuery", + //不设置默认null + "required": false, + //是否必须 + "since": "-", + //什么版本添加的改请求头 + "pathPatterns": "*" + //正则表达式过滤请求头 + } + ], + "errorCodeDictionaries": [ + { + //错误码列表,没有需求可以不设置 + "title": "title", + "enumClassName": "com.power.common.enums.HttpCodeEnum", + //错误码枚举类,如果是枚举是在一个类中定义则用$链接类BaseErrorCode$Common + "codeField": "code", + //错误码的code码字段名称 + "descField": "message" + //错误码的描述信息对应的字段名 + } + ], + "rpcApiDependencies": [ + { + // 项目开放的dubbo api接口模块依赖,配置后输出到文档方便使用者集成 + "artifactId": "SpringBoot2-Dubbo-Api", + "groupId": "com.demo", + "version": "1.0.0" + } + ], + "apiConstants": [ + { + "constantsClassName": "com.power.doc.constants.RequestParamConstant" + }, + { + "constantsClassName": "com.power.doc.constants.RequestValueConstant" + }, + { + "constantsClassName": "com.power.doc.constants.ApiVersion" + }, + { + "constantsClassName": "com.power.doc.constants.RequestHeadValue" + }, + { + "constantsClassName": "org.springframework.http.HttpHeaders" + } + ], + "dataDictionaries": [ + { + //配置数据字典,没有需求可以不设置 + "title": "http状态码字典", + //数据字典的名称 + "enumClassName": "com.power.common.enums.HttpCodeEnum", + //数据字典枚举类名称 + "codeField": "code", + //数据字典字典码对应的字段名称 + "descField": "message" + //数据字典对象的描述信息字典 } ], - "errorCodeDictionaries": [{ //错误码列表,没有需求可以不设置 - "title": "title", - "enumClassName": "com.power.common.enums.HttpCodeEnum", //错误码枚举类,如果是枚举是在一个类中定义则用$链接类BaseErrorCode$Common - "codeField": "code",//错误码的code码字段名称 - "descField": "message"//错误码的描述信息对应的字段名 - }], - - "rpcApiDependencies":[{ // 项目开放的dubbo api接口模块依赖,配置后输出到文档方便使用者集成 - "artifactId":"SpringBoot2-Dubbo-Api", - "groupId":"com.demo", - "version":"1.0.0" - }], - "apiConstants":[{ - "constantsClassName":"com.power.doc.constants.RequestParamConstant" - }, { - "constantsClassName":"com.power.doc.constants.RequestValueConstant" - }, { - "constantsClassName":"com.power.doc.constants.ApiVersion" - },{ - "constantsClassName":"com.power.doc.constants.RequestHeadValue" - }, { - "constantsClassName": "org.springframework.http.HttpHeaders" - }], - "dataDictionaries": [{ //配置数据字典,没有需求可以不设置 - "title": "http状态码字典", //数据字典的名称 - "enumClassName": "com.power.common.enums.HttpCodeEnum", //数据字典枚举类名称 - "codeField": "code",//数据字典字典码对应的字段名称 - "descField": "message"//数据字典对象的描述信息字典 - }], "customRequestFields": [ - {"name":"start", "ownerClassName":"com.gitee.fastmybatis.core.query.param.PageParam", "value":"0", "required":false,"ignore":true} - ,{"name":"limit", "ownerClassName":"com.gitee.fastmybatis.core.query.param.PageParam", "value":"0", "required":false,"ignore":true} + { + "name": "start", + "ownerClassName": "com.gitee.fastmybatis.core.query.param.PageParam", + "value": "0", + "required": false, + "ignore": true + }, + { + "name": "limit", + "ownerClassName": "com.gitee.fastmybatis.core.query.param.PageParam", + "value": "0", + "required": false, + "ignore": true + } ], - "groups": [ // @since 2.2.5, 对不同的controller进行分组 + "groups": [ + { + "name": "API Meta Info Usecase", + "apis": "com.power.doc.usecase.rest.api.meta.*" + }, + { + "name": "Path Parameters Usecase", + "apis": "com.power.doc.usecase.rest.api.path.parameter.*" + }, + { + "name": "Request Headers Usecase", + "apis": "com.power.doc.usecase.rest.api.headers.*" + }, + { + "name": "Query Parameters Usecase", + "apis": "com.power.doc.usecase.rest.api.query.parameter.*" + }, + { + "name": "Body Parameters Usecase", + "apis": "com.power.doc.usecase.rest.api.body.parameter.*" + }, + { + "name": "Response Fields Usecase", + "apis": "com.power.doc.usecase.rest.api.response.*" + }, { "name": "测试分组", + // @since 2.2.5, 对不同的controller进行分组 "apis": "com.power.doc.controller.*" } ]