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

[REQ][JAVA][SPRING] Adding springdoc-openapi support for service metadata and security #12220

Closed
bluenick2k17 opened this issue Apr 23, 2022 · 3 comments · Fixed by #12346
Closed

Comments

@bluenick2k17
Copy link
Contributor

Is your feature request related to a problem? Please describe.

I am configuring my auto generated API code, and I am concerned because although spring fox won't be supported in the future, springdoc doesn't currently get supplied all of the information that it should be. Without me creating an additional configuration file, the swagger page provided by springdoc just called my API "OpenAPI Definition" and doesn't provide the additional metadata that OpenAPI offers from the yaml file like the rest of the info section, servers, or Security Schemes. Security schemes being set up on this level also enables the authorization features in the swagger UI, which would be a huge functional plus.

Describe the solution you'd like

I would like there to be an additional configuration class created to handle the Open API definitions at least from the following listed annotations, to provide support for some of the swagger UI features that can't currently be used

I figure this would just be an additional class generated (e.g. SpringDocsUIConfiguration), which configures the annotations mentioned above and the @Configuration annotation, so that the docs site can pick up the new details.

Describe alternatives you've considered

  • The main alternative is being forced to add my own configuration file and supply all of this data myself, However, I would much rather have the documentation website directly linked to the swagger file.

Additional context

@bluenick2k17
Copy link
Contributor Author

bluenick2k17 commented Apr 24, 2022

Update on my Research

I've been looking into the configuration for Springfox and how OpenAPI 3 can mimick this kind of setup. This should be a scenario which avoids breaking springfoxwhile also adding separate support for springdocs. Here's an idea of the general setup that I will probably go for when I have the chance to implement this:

  • Renaming openapiDocumentationConfig.mustache to springfoxDocumentationConfig.mustache
  • Updating SpringCodegen.java with the file name change for spring fox and to add the springdoc documentation provider config option
  • Updating other files/tests which reference these file names or functionality for springfox and springdoc
  • Repurposing openapiDocumentationConfig.mustache to house the following configuration style in the mustache file (showing a sample)
    • I've done some preliminary testing to confirm that this will show the appropriate data in the swagger UI
//necessary imports for spring/OAS models

@Configuration
public class SpringDocConfiguration {

    @Bean
    OpenAPI apiInfo() {
        return new OpenAPI()
                .info(
                        new Info()
                                .title("Title")
                                .description("Description")
                                .termsOfService("")
                                .contact(
                                        new Contact()
                                                .name("")
                                                .url("")
                                                .email("")
                                )
                                .license(
                                        new License()
                                                .name("")
                                                .url("")
                                )
                                .version("")
                )
                .components(
                        new Components()
                                .addSecuritySchemes("basic_auth", new SecurityScheme()
                                        .name("basic_auth")
                                        .description("my description")
                                        .scheme("basic")
                                        .type(SecurityScheme.Type.HTTP)
                                )
                );
    }
}

@cachescrubber
Copy link
Contributor

Hi @bluenick2k17,
this is definitely a miss to get the springdoc migration feature complete. Your research seems reasonable and a contribution would be welcome. I personally would do it the other way around (introduce springdocDocumentationProvider.mustache, and delete openapiDocumentationConfig.mustache with the removal of springfox). Be sure to actually delete unused java class in the generated samples.

FYI @welshm (2022/02) @MelleD (2022/02) @atextor (2022/02) @manedev79 (2022/02) @javisst (2022/02) @borsch (2022/02) @banlevente (2022/02)

@cachescrubber
Copy link
Contributor

Just skimmed over your Draft PR. Looks good so far. Let me know if you need any help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment