-
Notifications
You must be signed in to change notification settings - Fork 43
Add Usecases #12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
NoNException
wants to merge
2
commits into
smart-doc-group:master
Choose a base branch
from
NoNException:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Add Usecases #12
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
53 changes: 53 additions & 0 deletions
53
src/main/java/com/power/doc/usecase/rest/api/body/parameter/BodyExampleUseCase.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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)字段,如下所示 | ||
| * <code> | ||
| * class BarValue{ | ||
| * //@mock "this is my mock string with "{"fooString":"123"} \" " | ||
| * String barString; | ||
| * //@mock 123a | ||
| * int barInt; | ||
| * //这里没有使用@mock注解,则交由smart-doc自动生成示例值 | ||
| * long barLong; | ||
| * } | ||
| * </code> | ||
| * 注意: | ||
| * 1. 如果想查看JSR-303标准中的注解对示例值生成的影响,请查看{@link BodyParameterRequiredUseCase} | ||
| */ | ||
| @GetMapping("/manual-mock") | ||
| public void manualMock(@RequestBody BarValue bar) { | ||
|
|
||
| } | ||
|
|
||
| } |
51 changes: 51 additions & 0 deletions
51
...n/java/com/power/doc/usecase/rest/api/body/parameter/BodyParameterDescriptionUseCase.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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){ | ||
|
|
||
| } | ||
| } |
76 changes: 76 additions & 0 deletions
76
...java/com/power/doc/usecase/rest/api/body/parameter/BodyParameterParameterNameUseCase.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 | ||
| * <code> | ||
| * class Foo{ | ||
| * // 此字段应该被正常渲染 | ||
| * String fooStringNotIgnore; | ||
| * | ||
| * //此字段会在最后的渲染结果中被忽略 | ||
| * //@ignore | ||
| * String fooStringToIgnore; | ||
| * | ||
| * } | ||
| * </code> | ||
| * @param foo 示例对象 | ||
| */ | ||
| @PostMapping("/use-ignore") | ||
| public void fooUseIgnore(@RequestBody FooParameterName foo) { | ||
|
|
||
| } | ||
|
|
||
| /** | ||
| * Use Jackson Annotations | ||
| * @apiNote 使用 com.fasterxml.jackson.annotation 下的注解 | ||
| * `@JsonProperty / `@JsonProperty / `@JsonIgnore /`@JsonIgnoreType进行用例展示 | ||
| * <pre> | ||
| * `@JsonIgnoreProperties({"fooClassStringToIgnore"}) | ||
| * class Foo{ | ||
| * //此字段 | ||
| * `@JsonProperty("fooString") | ||
| * String fooStringWithJsonAnnotation; | ||
| * | ||
| * `@JsonIgnore | ||
| * String fooStringToIgnore; | ||
| * | ||
| * //在Class上声明被忽略的成员变量 | ||
| * String fooClassStringToIgnore; | ||
| * | ||
| * //使用@JsonIgnoreType声明的类型 | ||
| * Bar bar; | ||
| * } | ||
| * `@JsonIgnoreType | ||
| * `@Data | ||
| * class Bar { | ||
| * String barString; | ||
| * } | ||
| * </pre> | ||
| * TODO #026 JsonIgnoreType似乎没有起作用,查看下方的Body-Parameter, bar字段还是正常显示了 | ||
| * @param foo 使用了一些jackson的注解对象 | ||
| * | ||
| */ | ||
| @PostMapping("/use-jackson-annotation") | ||
| public void fooUseFastJsonAnnotation(@RequestBody FooJsonParameterName foo) { | ||
|
|
||
| } | ||
| } | ||
|
|
||
39 changes: 39 additions & 0 deletions
39
...main/java/com/power/doc/usecase/rest/api/body/parameter/BodyParameterRequiredUseCase.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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注解表明参数必填,不推荐使用,查看链接 | ||
| * <a href="https://smart-doc-group.github.io/#/zh-cn/start/javadoc?id=_22-required%e4%bd%bf%e7%94%a8%e4%b8%8d%e6%8e%a8%e8%8d%90"></a> | ||
| * @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) { | ||
| } | ||
| } |
139 changes: 139 additions & 0 deletions
139
src/main/java/com/power/doc/usecase/rest/api/body/parameter/BodyParameterTypeUseCase.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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<Foo> | ||
| * @apiNote 使用List<Foo>作为入参 | ||
| * @param foos 对象列表 | ||
| */ | ||
| @PostMapping("/list-type") | ||
| public void fooListType(@RequestBody List<FooType> foos) { | ||
|
|
||
| } | ||
|
|
||
| /** | ||
| * Claim Map<String, Foo> | ||
| * @apiNote 使用Map<String, Foo>类型作为入参 | ||
| * @param fooMap fooMap | ||
| */ | ||
| @PostMapping("/map-type") | ||
| public void fooMapType(@RequestBody Map<String, FooType> fooMap) { | ||
|
|
||
| } | ||
|
|
||
| /** | ||
| * Claim List<Map<String,Foo>> | ||
| * @apiNote 使用List<Map<String,Foo>>类型作为入参 | ||
| * @param fooMaps fooMaps | ||
| */ | ||
| @PostMapping("/list-map-type") | ||
| public void foodListMapType(@RequestBody List<Map<String, FooType>> 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<String,?> | ||
| * @apiNote 反模式(不推荐),声明Map<String,?> 与声明 Map<String,Object>相同 | ||
| * @param fooMap fooMap | ||
| */ | ||
| @PostMapping("/map-generic-type") | ||
| public void fooMapGeneric(@RequestBody Map<String, ?> fooMap) { | ||
|
|
||
| } | ||
|
|
||
| /** | ||
| * (❎)Claim T Generic Type | ||
| * @apiNote 反模式(不推荐),声明 T t 作为入参,与声明Object相同, | ||
| * @param t t | ||
| */ | ||
| @PostMapping("list-t-generic") | ||
| public <T> void foodG(@RequestBody T t) { | ||
|
|
||
| } | ||
|
|
||
| /** | ||
| * (❎)Claim List<? extends Foo> | ||
| * @apiNote 反模式(不推荐),声明List<? extends Foo>与声明List<Object>相同,List<?> 同理 | ||
| * @param foos foos | ||
| */ | ||
| @PostMapping("/list-generic-type-extends") | ||
| public void fooListGenericExtends(@RequestBody List<? extends FooType> foos) { | ||
|
|
||
| } | ||
|
|
||
|
|
||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@JsonIgnoreType这个可以支持,可以先添加issue