Reputation: 1148
I am using Spring Swagger library v1.0.2
Maven:
<dependency>
<groupId>com.mangofactory</groupId>
<artifactId>swagger-springmvc</artifactId>
<version>1.0.2</version>
</dependency>
I am able to scan my REST APIs and view it on the Swagger UI. I have even implemented OAuth and it is working great.
I have a unique requirement. My controllers have the @RequestMapping annotated as
@RequestMapping("/unauthorize")
@Controller
public class SomeController {
@RequestMapping(method = RequestMethod.GET, value = "/preferences/{preferenceName}")
public SomeModel getDisplayPreference( @PathVariable("preferenceName") final String preferenceName ) {
}
}
One would make an assumption that to access the getDisplayPreference() method one needs the following URL:
http://www.example.com/<some-context>/unauthorize/preferences/somepreferencename
Swagger assumes that and in the 'Try it out' feature in the Swagger UI tries to hit the above URL.
However, in our code there is an additional URL part as follows
http://www.example.com/<some-context>/unauthorize/rest-resource/preferences/somepreferencename
So you see there is 'rest-resource' that needs to be the part of the URL to make a correct call. Since Swagger UI is not aware of 'rest-resource' - which is not its fault - every call fails.
Is there a way I can force Swagger to include 'rest-resource' in the URL? Can I override it somehow?
Upvotes: 1
Views: 1100
Reputation: 1148
I figured out the answer for this.
In swagger-ui.js under the method:
SwaggerSpecConverter.prototype.declaration = function(obj, swagger) {}
there is a block of code:
for(i = 0; i < obj.apis.length; i++) {
var api = obj.apis[i];
var path = api.path;
var operations = api.operations;
this.operations(path, obj.resourcePath, operations, resourceLevelAuth, swagger);
}
I updated it to:
for(i = 0; i < obj.apis.length; i++) {
var api = obj.apis[i];
var path = '/rest-resource'+api.path;
var operations = api.operations;
this.operations(path, obj.resourcePath, operations, resourceLevelAuth, swagger);
}
This adds /rest-resource ahead of all the paths and helped me to resolve my problem.
Upvotes: 0
Reputation: 2720
What does your Swagger configuration look like? You can set the base path there.
See this blog - http://jakubstas.com/spring-jersey-swagger-configuration/#.VfsJxxHBwXA. Also a relevant discussion here - https://github.com/swagger-api/swagger-ui/issues/276.
Upvotes: 1