when using swagger, each operation can have a id, by default this id is nickname of the annotation, for instance,
@ApiOperation(value = "create a new user", nickname = "oper_code_create_new_user")
The oper_code_create_new_user will be used as unique id (not sure why the lib use nickname as a unique id but it does). How if you do not add this annotation on the method, for instance, you may have a parent Controller class, and the sub-Controller class just reuse the method without override it. in this case, the unique id will be oper_code_create_new_user_1 by default (as implementated in CachingOperationNameGenerator.java in springfox-spring-web library)
if you want to customize the unique id in the sub-class, for instance, I want to add the sub-class name or the value defined in controller lever tag name which is in @Api annotation, as the suffix, you can reference below code sneppet.
@Component
@Order(SwaggerPluginSupport.SWAGGER_PLUGIN_ORDER + 1000)
public class OperationCustomizeUniqueIdReader implements OperationBuilderPlugin {
@Override
public void apply(OperationContext context) {
Optional<ApiOperation> apiOperation = context.findAnnotation(ApiOperation.class);
if (apiOperation.isPresent()) {
Optional<Api> apiOptional = context.findControllerAnnotation(Api.class);
if (apiOptional.isPresent()) {
String tagName = apiOptional.get().tags()[0];
ApiOperation operation = apiOperation.get();
String nickname = operation.nickname();
if (StringUtils.isNotEmpty(nickname) && StringUtils.isNotEmpty(tagName)) {
if (nickname.equalsIgnoreCase("oper_code_create_new_user") ) {
context.operationBuilder().uniqueId(nickname + "_" + tagName);
context.operationBuilder().codegenMethodNameStem(nickname + "_" + tagName);
}
}
}
}
}
@Override
public boolean supports(DocumentationType documentationType) {
return SwaggerPluginSupport.pluginDoesApply(documentationType);
}
}if you have a sub class with @Api(tags = {"aSubResource"}), then you will get a unique namefor this method "oper_code_create_new_user_aSubResource"