问题描述
我已经使用 springfox 2.0 配置了我的 spring 项目.我可以用它生成开放的 api 规范.
I have configured my spring project using springfox 2.0. I am able to generate the open api spec with it.
"paths": {
"/test/testinfo": {
"post": {
"tags": [
"test-controller"
],
"summary": "getTestInfo",
"operationId": "getTestInfoInfoUsingGET",
"consumes": [
"application/json"
],
"produces": [
"application/json"
]
如您所见,operationId 的值是格式
As you can see the value of operationId is of format
[java_method_name_here]Using[HTTP_verb_here]
例如.getPetsUsingGET
ex. getPetsUsingGET
此 operationId 在使用 swagger-codegen 生成客户端时使用.有谁知道如何自定义它?我知道这可以使用 @ApiOperation
为每个 api 完成,但是有没有更通用的方法来为所有 api 定义这种格式?
This operationId is used while generating clients using swagger-codegen.Does anyone know how to customize it? I know this can be done per api using @ApiOperation
but is there a more generic way to define this format for all apis?
推荐答案
我们也可以使用 Nickname 这种覆盖默认 operationId 的方法.
We can also use this approach of Nickname which overrides default operationId.
@ApiOperation(value = "", nickname = "getMeAllThePetsPlease")
@RequestMapping(value = "/pets", method = RequestMethod.GET)
public Model getAllThePets() {
...
}
因此我们将使用 getMeAllThePetsPlease 覆盖 operationId: getAllThePetsByGet.
so we will be overriding operationId: getAllThePetsByGet with getMeAllThePetsPlease.
注意:昵称将覆盖 operationId,因此可以相应地进行自定义.
Note: Nickname will overrides the operationId so this can be customized accordingly.
这篇关于如何使用swagger自定义api规范中生成的operationId的值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!