Skip to content

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

Closed
@migueltercero

Description

@migueltercero

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.
  • ...

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions