-
-
Notifications
You must be signed in to change notification settings - Fork 526
Wrong operationid generated #675
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Hi @tezine, This is not a bug, but a normal behaviour as we don't want to generate incorrect spec:
If you have two operations with the same id, your spec will be incorrect. Please make sure you use the last stable version: v1.3.9 indeed. |
Thank you @bnasslahsen for the quick response. It just think it doesn't make any sense. For instance, I'm generating REST calls to Angular in typescript. In this situation, I have two calls: MyFirstClassService.save() and MySecondClassService.save_1(). //It doesn't make sense. |
I invite you to read the spec: https://swagger.io/docs/specification/paths-and-operations/
|
In my case, I've got lots of rest controllers that extend a generalized abstract crud controller. Rather than generating operations with |
Nvm - I just realized there is an Line 641 in 2da39aa
I was able to provide a bean and customize my generated names =] Thanks for a great project!!
|
This does not require additional dependency and Is also easy to customize naming. (Main idea from here)
package com.observatory.api.config;
import com.google.common.base.Optional;
import io.swagger.annotations.ApiOperation;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
import springfox.documentation.service.Operation;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spi.service.OperationBuilderPlugin;
import springfox.documentation.spi.service.contexts.OperationContext;
import springfox.documentation.swagger.common.SwaggerPluginSupport;
import java.util.Locale;
@Component
@Order(SwaggerPluginSupport.SWAGGER_PLUGIN_ORDER + 1000)
public class SwaggerIncludeMissingNicknameIntoUniqueIdReader implements OperationBuilderPlugin {
@Override
public void apply(OperationContext context) {
Optional<ApiOperation> methodAnnotation = context.findControllerAnnotation(ApiOperation.class);
Operation operationBuilder = context.operationBuilder().build();
String uniqueId = operationBuilder.getUniqueId();
if(operationBuilder.getTags().stream().findFirst().get().isEmpty())
throw new RuntimeException("operationBuilder.getTags().stream().findFirst()");
uniqueId = uniqueId.substring(0,1).toUpperCase(Locale.ROOT)+ uniqueId.substring(1);
uniqueId = uniqueId.replaceAll("[_].+","");
String tag = operationBuilder.getTags().stream().findFirst().get();
tag = tag.replace("-controller","s");
int index = tag.indexOf("-");
while (index >= 0) {
tag = tag.substring(0,index) + tag.substring(index+1,index+2).toUpperCase(Locale.ROOT)+ tag.substring(index+2);
index = tag.indexOf("-");
}
uniqueId = tag + uniqueId;
// If nickname exists, populate the value of nickname annotation into uniqueId
String fillId = methodAnnotation.transform(ApiOperation::nickname).or(uniqueId);
context.operationBuilder().uniqueId(fillId);
context.operationBuilder().codegenMethodNameStem(fillId);
}
@Override
public boolean supports(DocumentationType delimiter) {
return SwaggerPluginSupport.pluginDoesApply(delimiter);
}
} |
How can i handle 2 paths
} |
@kozla13 , You will have unique operation ids generated by default. |
Hello,
This bug is probably the same as bug 96.
OperationID continues to be generated with a suffix, even when there's no other method with the same operationid in the same class.
This issue is easy to reproduce:
Ex:
MyFirstClass.java:
After generation, one method will have the correct operationid (save), but the other one will have a wrong operationid(save_1)
This bug is happening with SpringDoc 1.3.0, SpringBoot 2.2.6, openJDK 11 64bits on Windows.
The text was updated successfully, but these errors were encountered: