-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
API paths generated with two forward slashes #423
Comments
I"m debugging more and it's coming down to this method in public String getPath() {
StringBuilder pathBuilder = new StringBuilder();
for (PathComponent pathComponent : this.pathComponents) {
pathBuilder.append(pathComponent.getPath());
}
return pathBuilder.toString();
} It has two path components, a |
it was this commit 7f15055 @dilipkrish what was the context around this change? I understood that the relativepathprovider was working as intended prior to this change? |
There was a bug #411 which I verified in the demo project as well. It was to fix that issue. The problem wa that while the swagger ui would come up fine. The requests URL that the "try" button would generate was incorrect. |
Is there a workaround I can do using SwaggerSpringMvcPlugin for now, is it possible to set ROOT in RelativeSwaggerPathProvider to an empty string? |
yo u can implement your own swaggerpathprovider and pass it to your SwaggerSpringMvcPlugin instance. |
Thanks adrian, I ended up using that solution and it worked for some of the paths but not all. I think the specific endpoint paths for each method still had the two slashes. I'll look into it more tomorrow at work. |
I think its a bug with the logic that builds the path - we need a test and fix for double slashes. |
I was able to get it working with the follow path provider implementation. Specifically import org.springframework.web.util.UriComponentsBuilder;
import com.mangofactory.swagger.paths.SwaggerPathProvider;
public class AgreementPathProvider extends SwaggerPathProvider {
private String apiResourcePrefix = "";
public String getApiResourcePrefix() {
return apiResourcePrefix;
}
public void setApiResourcePrefix(String apiResourcePrefix) {
Assert.notNull(apiResourcePrefix);
Assert.isTrue(!apiResourcePrefix.startsWith("/"));
Assert.isTrue(!apiResourcePrefix.endsWith("/"));
this.apiResourcePrefix = apiResourcePrefix;
}
@Override
protected String applicationPath() {
return "/services/agr";
}
@Override
protected String getDocumentationPath() {
return "";
}
@Override
public String getOperationPath(String operationPath) {
UriComponentsBuilder uriComponentsBuilder = UriComponentsBuilder.fromPath("");
if (!isBlank(apiResourcePrefix)) {
uriComponentsBuilder.path(apiResourcePrefix);
}
return uriComponentsBuilder.path(operationPath).build().toString();
}
} |
Scratch that. The URLs look correct but the actual request url in swagger-ui is wrong. I'll keep playing around with it. |
you could wrap/decorate relativeswaggerpathprovider and do a replaceall '//' with '/' |
I was able to get the whole thing working by returning my context path in applicationPath(), i put my edits in the code above. |
@yate Thats exactly what the RelativeSwaggerPathProvider does. Are you by any chance having dynamic servlets? |
No I don't believe so. I have one dispatcher servlet defined in my web.xml which is mapped to The only difference between my path provider and the relative path provider is that |
I am too facing this issue. And my analysis is also indicating to me that RelativeSwaggerPathProvider's getDocumentationPath() or applicationPath() is causing the issue. Will chip in with more info in some time. |
@simplyDoingIT @yate can you try the latest 0.9.0-SNAPSHOT snapshot. I'm guessing its some bug with some earlier version of springs UriComponents.. The following commit should fix the issue: e359280 |
@adrianbk I do not have gradle set up. I spend couple of hours setting it up however, I could not make a breakthrough through the proxies that we have. Thus, I may have to wait until a release is done by you for testing it. If you can provide me with the compiled jar, may be then I can locally install it and attempt testing. |
@adrianbk I was able to compile the project. And publish project in my local maven repository.
It is unable to identify Swagger annotations and swagger model which are essentially made available transitively by swagger-springmvc. On comparing the pom.xmls of swagger-springmvc with version 0.8.8 and 0.0.9-Snapshot, I noticed that all dependencies in 0.0.9-snapshot are having scope runtime. I am guessing that is why compilation is failing. Kindly remove the runtime scope. then I will be able to test it successfully. Thanks in advance. |
@simplyDoingIT the latest 0.9.0-snapshot should have a fix. It's an issue with the gradle publishing mechanism we are using Good work catching this 👍 Our next release will be the first one using (gradle/jcenter) [https://github.com//issues/422] so it's great to have someone finding these issues early. |
@adrianbk I did the testing after the fix you did for pom's runtime issue. After your change for fixing the double slash, my url started coming as http://localhost:7070/rest/api-docs/apiGrouping/apideclaration1 Your couple of fixes worked fine. This issue can be closed. Thanks a lot for your support. Eagerly waiting for you to make the next release with these two fixes included Adding @yate in the loop. |
@adrianbk I here by would like to appreciate you for providing SpringSwaggerConfig as a composition element rather than inheritance. It has been a instructing example for preference of composition over inheritance for me. Thank you to your team. |
@adrianbk @simplyDoingIT Thanks very much! |
V0.9.0 released |
I'm generating using the default configuration class
com.mangofactory.swagger.configuration.SpringSwaggerConfig
swagger-springmvc 0.8.8
spring 3.2.1.RELEASE
My controller is annotated with
@Controller
with no valueMy method endpoints do not start with
/
My
DispatcherServlet
is mapped to/
in my web.xmlThe context root of the ear (I have two wars in my ear) i'm deploying is
/services/agr
I've tried to debug this and i've gotten here in
ApiListingReferenceScanner
line 97swaggerGroup = default
resourceGroupName = agreement
this path comes back as
//default/agreement
but I can't figure out why, I would like it to be/default/agreement/
.The text was updated successfully, but these errors were encountered: