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.

Support multiple apis() in swagger config

See original GitHub issue

Here I tried to add the Spring-Actuator endpoints according to the stackoverflow issue - http://stackoverflow.com/questions/39159998/swagger2-document-a-springboot-mvcendpoint,

So I created the following swagger config, but seems the sendond apis will override the first one.

@Configuration
@EnableSwagger2
public class Swagger2Config {
	@Bean
	public Docket api() {
		return new Docket(DocumentationType.SWAGGER_2)
				.select()
				.apis(RequestHandlerSelectors.any())
				.apis(RequestHandlerSelectorsExt.withInterface())
				.paths(PathSelectors.any()).build();
	}

	static class RequestHandlerSelectorsExt {
		public static Predicate<RequestHandler> withInterface() {
			return new Predicate<RequestHandler>() {
				@Override
				public boolean apply(RequestHandler input) {
					return declaringClass(input) == EndpointMvcAdapter.class;
				}
			};
		}

		private static Class<?> declaringClass(RequestHandler input) {
			return input.getHandlerMethod().getMethod().getDeclaringClass();
		}
	}
}

Fome the source codes, seems this is a bug?

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:1
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

19reactions
dilipkrishcommented, Nov 8, 2016

It can have only one api call (last one wins) but can have multiple predicates. For e.g. .apis(Predicates.or(firstApi(), secondApi()

12reactions
OkieOthcommented, Feb 9, 2018

I solved a similar problem by defining my own controller annotation and attach it to the classes I want include …

@Target({ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Component
public @interface ControllerDocumentation {
}

to find my documentation classes I used the following code …

        return new Docket(DocumentationType.SWAGGER_2)
                .select()
                    .apis(RequestHandlerSelectors.withClassAnnotation(ControllerDocumentation.class))
                    .build()
                .directModelSubstitute(java.time.LocalDate.class, java.sql.Date.class)
                .directModelSubstitute(java.time.OffsetDateTime.class, java.util.Date.class)
                .apiInfo(apiInfo());
Read more comments on GitHub >

github_iconTop Results From Across the Web

Documentation Portals for Multiple APIs | Swagger Blog
Lets put the swaggerhub function to use and create a new getOrganizationData call. This will take a single input parameter, our organization's ...
Read more >
Combining multiple Swagger API endpoints in a single UI
By switching from one service to another from a list, you will get the Swagger UI rendered out based on the Open API...
Read more >
Support multiple pathmapping in Swagger UI/Spring boot
I am having swagger configuration like blow. @Configuration @EnableSwagger2 public class SwaggerConfig { @Bean public Docket postsApi() { return ...
Read more >
Distributed API Documentation - How to Aggregate Swagger
Configuring the Swagger UI to serve multiple API documents. The list of configured services is used to generate a response to /swagger-config.
Read more >
How to implement Swagger UI for multiple API's : r/golang
The second part of this is the swagger ui setup that renders all the various sub service swagger files into something that can...
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