Skip to content
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

Feign clients that uses SpringMVCContract appears in OpenApi like controllers exposed if spring-boot-starter-actuator is in classpath #1230

Closed
migueltercero opened this issue Jul 29, 2021 · 3 comments
Labels
bug Something isn't working

Comments

@migueltercero
Copy link

migueltercero commented Jul 29, 2021

Describe the feature

If you use https://spring.io/projects/spring-cloud-openfeign and define @FeingClients with SpringMVCContract, SpringDoc shows this clients in OpenApi.

The problem is that this clients uses same annotations that RestControllers (@RequestMapping, @GetMapping ...)

To Reproduce

  • Define @FeignClient
@FeignClient("feignclient")
	@RequestMapping(value = "/api/v1/echo")
	public interface EchoClient {

		@GetMapping
		String echo(@RequestParam int size);

}
  • Call OpenApi endpoint
@Test
	 void givenFeignClient_whenGetAppApiDoc_thenDontAppear() {
		given()
		.when()
			.get("/v3/api-docs/app")
		.then().log().all()
			.statusCode(200)
			.body("paths['/api/v1/echo'].get", notNullValue());
	}

Expected behavior

  • This test must be ok:
@Test
	 void givenFeignClient_whenGetAppApiDoc_thenDontAppear() {
		given()
		.when()
			.get("/v3/api-docs/app")
		.then().log().all()
			.statusCode(200)
			.body("paths['/api/v1/echo'].get", nullValue());
	}

Solution

Posibles solutions:

  • Have an annotationsToExclude and pass FeignClient.class to exclude
return GroupedOpenApi
				.builder()
					.group(info.getArtifact())
					.pathsToMatch("/api/**")
					.annotationsToExclude(FeignClient.class)
				.build();
  • Shows only endpoints that have "@RestController" or "@controller" annotation by default. If beans don´t have this annotation, spring don´t exposes it as controller, and beans that aren´t exposed as controller, dont appear in open api endpoint.
  • ...
@bnasslahsen
Copy link
Contributor

@migueltercero,

This is an enhancement request.

You can use addHiddenRestControllers, with the name of the rest controller to ignore.
We will see to get it out of the box for the next realse.

static {
		SpringDocUtils.getConfig().addHiddenRestControllers(EchoClient.class)
	}

@bnasslahsen
Copy link
Contributor

@migueltercero;

Can you provide a Minimal, Reproducible Example - with HelloController that reproduces the problem ?

You can use https://start.spring.io/.

@migueltercero
Copy link
Author

migueltercero commented Aug 2, 2021

Hi, I uploaded a sample here:

https://github.com/migueltercero/springdoc-issue

You can reproduce issue/feature if execute com.github.ma3.controller.HelloControllerTest#givenFeignClient_whenGetAppApiDoc_thenFeignClientShouldNotAppear test method.

You can see the problem with SwaggerIU too:

image

NOTE: This is related with Spring actuator starter:

<dependency>
   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-starter-actuator</artifactId>
</dependency> 

If you remove actuator dependency, client don´t appear and OpenApi is generated ok.

Thank you

@migueltercero migueltercero changed the title Feign clients that uses SpringMVCContract appears in OpenApi like controllers exposed Feign clients that uses SpringMVCContract appears in OpenApi like controllers exposed if spring-boot-starter-actuator is in classpath Aug 2, 2021
@bnasslahsen bnasslahsen added the bug Something isn't working label Jan 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants