如何用 swagger 自定义 api spec 中生成的 operationId 的值? [英] How to customize the value of operationId generated in api spec with swagger?
问题描述
我已经使用 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 spec 中生成的 operationId 的值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!