0

i have already swagger-ui installed externally, i just wanted to connect that swagger-ui (open source) instance to localhost:8000/doc/api (.yaml) from openapi.yaml . any thoughts? PS : i tried to use

 @Bean
public OpenAPI customOpenAPI() {
    return new OpenAPI()
            .components(new Components().addSecuritySchemes("basicScheme",
                    new SecurityScheme().type(SecurityScheme.Type.HTTP).scheme("basic")))
            .info(new Info().title("SpringShop API").version("0.1")
                    .license(new License().name("Apache 2.0").url("http://springdoc.org")))
            .externalDocs(new ExternalDocumentation()
                    .url("restapi/doc/openapi.yaml"));
}

    @Bean
    public SpringDocConfiguration springDocConfiguration(){
        return new SpringDocConfiguration();
    }
    @Bean
    public SpringDocConfigProperties springDocConfigProperties() {
        return new SpringDocConfigProperties();
    }

but i did not find anything useful. thanks.

    application.properties:
    springdoc.api-docs.enabled=false
springdoc.swagger-ui.url=openapi.yaml
springdoc.swagger-ui.path=/doc/api/ui.html

dependecies:
<dependency>
        <groupId>org.springdoc</groupId>
        <artifactId>springdoc-openapi-ui</artifactId>
        <version>1.4.4</version>
    </dependency>
  • Did you read through the integration docs [here](https://springdoc.org/) properly? When you already have the Swagger UI integrated with Springdoc, I don't see why you would want to use an external one? Like, you can do it, but it can lead to CORS issues in particular. Also, you should take care not to use the Swagger UI 2.x with the OpenAPI 3 specification when you're having the Swagger UI externally. – Debargha Roy Oct 14 '20 at 17:25
  • Yes, i already know that, nd i v got the auto generated api-doc.yaml, but i want my own yaml specification outside the project nd without using any type of annotations also. Thanks for replying. – Bedreddine Zarrouk Oct 14 '20 at 19:42
  • I fear that's not possible. I don't see a way how you can generate the specification without the annotation, unless you generate the spec manually. – Debargha Roy Oct 15 '20 at 05:19
  • well, just to clear my point. when using springdoc-openapi, it will expose auto generated yaml/json specification via localhost:8000/v3/api-doc.yaml (default) right? so i want to expose my own openapi.yaml when acceding to localhost:8000/swagger-ui.html. – Bedreddine Zarrouk Oct 15 '20 at 08:41
  • 1
    In that case, [this](https://springdoc.org/faq.html#how-can-use-custom-jsonyml-file-instead-of-generated-one-) should help. – Debargha Roy Oct 15 '20 at 09:33
  • yess, thank you for the help ^_^ – Bedreddine Zarrouk Oct 15 '20 at 11:04
  • It worked. So helpful. Thank you guys – Bedreddine Zarrouk Oct 16 '20 at 18:44
  • You might want to check this answear too: https://stackoverflow.com/questions/54361017/generate-api-docs-with-openapi-maven-plugin/68220592#68220592 – akasha Jul 02 '21 at 06:45

1 Answers1

6

First configuration: External OPENAPI Definition:

The properties springdoc.swagger-ui.urls.*, are suitable to configure external url (http://myhoost.com/v3/api-docs)

For example if you want to agreagte all the endpoints of other services, inside one single application. Don’t forget that CORS needs to be enabled as well.

Second configuration: Internal OPENAPI Definition with static file:

If you want to use a static file that contains your openAPI definition, then simply declare: The file name can be anything you want, from the moment your declaration is consistent yaml or json OpenAPI Spec.

springdoc.swagger-ui.url=/openapi.yaml

Then the file openapi.yaml, should be located in: src/main/resources/static No additional configuration is needed.

brianbro
  • 4,141
  • 2
  • 24
  • 37