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

Springdoc is adding a 404 status response for all endpoints, even if I don't add it explicitly #2587

Open
Juansecu opened this issue May 5, 2024 · 0 comments

Comments

@Juansecu
Copy link

Juansecu commented May 5, 2024

Describe the bug

  • If you are reporting a bug, please help to speed up problem diagnosis by providing as
    much information as possible:
  • A clear and concise description of what the bug is: the title of an issue is not enough

A: I'm using Springdoc to document my API, but for any reason, all endpoints include a 404 response status, even if I don't add it explicitly.

To Reproduce
Steps to reproduce the behavior:

  • What version of spring-boot you are using?

    A: I'm using version 3.2.5 of Spring Boot

  • What modules and versions of springdoc-openapi are you using?

    A: I'm using version 2.5.0 from the module module springdoc-openapi-starter-webmvc-ui of Springdoc

  • What is the actual and the expected result using OpenAPI Description (yml or json)?

  • Provide with a sample code (HelloController) or Test that reproduces the problem

    A: For configuring Springdoc:

    @Configuration
    public class OpenApiConfig {
        @Bean
        protected OpenAPI openAPI() {
            final Info info = new Info()
                .description("Description")
                .title("Name")
                .version("1.0.0");
            final SecurityScheme jwtHeaderSecurityScheme = new SecurityScheme()
                .bearerFormat("JWT")
                .in(SecurityScheme.In.HEADER)
                .name("AuthToken")
                .scheme("bearer")
                .type(SecurityScheme.Type.HTTP);
            final Components components = new Components().addSecuritySchemes(
                "AuthToken",
                jwtHeaderSecurityScheme
            );
    
            return new OpenAPI()
                .components(components)
                .info(info);
        }
    }

    And the controller:

    @RequestMapping("/hello")
    @RequiredArgsConstructor
    @RestController
    @Tag(
        description = "Hello operations",
        name = "Hello"
    )
    public class HelloController {
        @ApiResponse(
            content = {
                @Content(
                    schema = @Schema(
                        type = "string"
                    )
                )
            },
            description = "Send greetings.",
            responseCode = "200"
        )
        @Operation(
            description = "Send greetings.",
            summary = "Send greetings"
        )
        @GetMapping()
        public String getAvatarImage() {
            return "Hello world!";
        }
    }

    By the way, you can find a real life example here.

Expected behavior

  • A clear and concise description of what you expected to happen.
  • What is the expected result using OpenAPI Description (yml or json)?

A: I expected Springdoc to only add the response status that I explicitly add.

Screenshots
If applicable, add screenshots to help explain your problem.

image
image

Additional context
Add any other context about the problem here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant