Annotation
# @DocApi
By default, doc-apis generates documentation for all interfaces within the project that conform to its built-in rules (rules include annotations such as @RestController or @Controller, among others). If you do not wish to document every interface, you can disable this default behavior by setting doc-apis.autoGenerate=false, as mentioned in the previous configuration section. After disabling auto-generation, you can selectively designate which interfaces should be documented using the @DocApi annotation.When applied to an interface method,
@DocApi offers additional flexible settings:
- result: Directly declare the return object type. If specified, it overrides the SpringBoot return object.
- stringResult: Use this for returning a string when the response is simple, and creating a dedicated return class is unnecessary.
- url: An extension field for specifying the request URL, useful for non-SpringBoot projects.
- method: An extension field indicating the request method, helpful for non-SpringBoot scenarios.
Example:
@DocApi(result = AdminVO.class, url = "/api/v1/admin/auth", method = "post")
public void someMethod();
2
stringResult, where the JSON string will be automatically formatted in the documentation:
@DocApi(stringResult = "{code: 200, data: 'success'}")
@GetMapping("custom-json")
public Map<String, Object> customJsonResult() { ... }
2
3
# @DocIgnore
Ignoring Specific ControllersTo ignore an entire Controller, simply annotate the class with @DocIgnore
@DocIgnore
public class UserController {
// ...
}
2
3
4
Ignoring Specific MethodsAlternatively, apply @DocIgnore to a specific method to exclude just that method from documentation, providing finer control:
@PostMapping("save")
@DocIgnore
public ApiResult saveUser() {
return null;
}
2
3
4
5
6
Ignoring Specific FieldsTo exclude a field from being exported in the generated documentation, annotate that field with @DocIgnore:
public class User {
// ...
/**
* Name
*/
@DocIgnore
private String name;
}
2
3
4
5
6
7
8
9
Special Notes
- By default, the framework uses the comment content above the Controller class as the navigation title in the documentation. However, if the comment includes @description, that text will be used instead. For example:
/**
* Demonstrates some special declaration methods
*
* @description Administrator Interface
*/
@Controller
public class AdminController {
// ...
}
2
3
4
5
6
7
8
9
In this case, the navigation title in the generated documentation will be "Administrator Interface," not "Demonstrates some special declaration methods."
2.Adding @description within a method's comments allows you to append a line of additional explanation beneath the interface method. For example:
/**
* User List
* @description Frontend developers, please note, all responsibility lies with the frontend.
*/
@PostMapping("/list")
public ApiResult<List<User>> listUser() { ... }
2
3
4
5
6
Here, the generated documentation will include an extra note under the interface method: "Frontend developers, please note, all responsibility lies with the frontend."