question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

add support to prefix all swagger http requests/resources

See original GitHub issue
  • What version of the library are you using? 2.9.2

What kind of issue is this?

  • Feature Request.

we have the requirement to put all swagger documentation beneath a fix path. This first sounds close to an answer already given in How does one configure swagger-ui for non-springboot applications?. But the answer given there is to add some redirects to make it all work, but this is not going to work when you really only want to give explicit permission for one specific path e.g. /documentation/**. we don’t care about the stuff after the path prefix, but it must all be beneath it - no redirects outside this path.

Its the same reasoning why spring boot has management.endpoints.web.base-path=/ to move all endpoints to a subpath. Actuator Web Endpoint Paths

I have done a little experiment and have this:

@SpringBootApplication
@EnableSwagger2
public class SpringfoxSwaggerApplication implements WebMvcConfigurer {

	public static void main(String[] args) {
		SpringApplication.run(SpringfoxSwaggerApplication.class, args);
	}

	@Override
	public void addResourceHandlers(ResourceHandlerRegistry registry) {
		registry.addResourceHandler("/documentation/swagger-ui.html**").addResourceLocations("classpath:/META-INF/resources/swagger-ui.html");
		registry.addResourceHandler("/documentation/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/");
	}

	@Controller
	@ApiIgnore
	@RequestMapping("/documentation/swagger-resources")
	public static class MyApiResourceController extends ApiResourceController {
		public MyApiResourceController(SwaggerResourcesProvider swaggerResources) {
			super(swaggerResources);
			// how to set securityConfiguration and uiConfiguration? both are
			// @Autowired by field injection :(
		}
	}

	@Bean
	public Docket swaggerSpringMvcPlugin() {
		return new Docket(DocumentationType.SWAGGER_2).groupName("myapi").select().build();
	}

	// just a dummy controller
	@RestController
	@RequestMapping("/api")
	public class MyController {

		@GetMapping
		public String home() {
			return "hello world";
		}
	}
}

This allows me to redefine the RequestMapping for ApiResourceController. The startup works fine, and the UI stuff can also be loaded - but unfortunate these requests fail and I have no idea how to get them to work.

Also setting springfox.documentation.swagger.v2.path=/documentation/v2/api-docs does not help, it makes it even worse, as the it now tries to access http://localhost:8080/documentation/documentation/v2/api-docs?group=myapi

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:3
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
dilipkrishcommented, Aug 29, 2018

@imod thank you, will research and get back to you

1reaction
imodcommented, Aug 28, 2018

@dilipkrish here it is: https://github.com/imod/SpringfoxSwagger-ContextPath

please let me know if there is anything I can help, it is really important for us…

Read more comments on GitHub >

github_iconTop Results From Across the Web

Laravel API Documentation with OpenAPI/Swagger
The package will scan all your files and look for the patterns of OpenAPI-related comments. So, what types of comments we need to...
Read more >
Set custom path prefix in API method using Swagger in .Net ...
I would like add my custom path prefix using swagger in .Net Core API methods. ... So currently, If I invoke the API...
Read more >
Paths and Operations - Swagger
A single path can support multiple operations, for example GET /users to get a list of users and POST /users to add a...
Read more >
Get started with Swashbuckle and ASP.NET Core
Learn how to add Swashbuckle to your ASP.NET Core web API project to integrate the Swagger UI.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found