Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) {

}

}
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){

}
}
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声明的类型
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JsonIgnoreType这个可以支持,可以先添加issue

* 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) {

}
}

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) {
}
}
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) {

}


}
Loading