5 Temmuz 2023 Çarşamba

SpringDoc OpenAPI OpenAPI Sınıfı

addSecurityItem metodu
Örnek
Şöyle yaparız
@Bean
 public OpenAPI customizeOpenAPI() {
  String securitySchemeName = "bearerAuth";
  return new OpenAPI()
    .addSecurityItem(new SecurityRequirement().addList(securitySchemeName))
          .components(
              new Components()
                  .addSecuritySchemes(securitySchemeName,
                      new SecurityScheme()
                          .name(securitySchemeName)
                          .type(SecurityScheme.Type.HTTP)
                          .scheme("bearer")
                          .bearerFormat("JWT")
                  )
          );
 }
addServerItems metodu
Örnek
Şöyle yaparız
@Bean
public OpenAPI customOpenAPI() { return new OpenAPI() .addServersItem(new Server().url("https://myserver.com")) .addServersItem(new Server().url("https://google.com")) .components( new Components() .addSecuritySchemes("basicScheme",new SecurityScheme() .type(SecurityScheme.Type.HTTP) .scheme("basic")) ) .info( new Info() .title("SpringShop API") .version("0.0.1") .license(new License().name("Apache 2.0").url("http://springdoc.org")) ); }
Örnek
Şöyle yaparız
@Bean
 public OpenAPI openApiInformation() {
  Server localServer = new Server()
                      .url("http://localhost:8080")
                      .description("Localhost Server URL");

  Contact contact = new Contact()
                    .email("niket.agrawal90@gmail.com")
                    .name("Niket Agrawal");

  Info info = new Info()
              .contact(contact)
              .description("Spring Boot 3 + Open API 3")
              .summary("Demo of Spring Boot 3 & Open API 3 Integration")
              .title("Spring Boot 3 + Open API 3")
              .version("V1.0.0")
              .license(new License().name("Apache 2.0").url("http://springdoc.org"));

  return new OpenAPI().info(info).addServersItem(localServer);
}
http://localhost:8080/swagger-ui/index.html adresindeki ekran görüntüsü şöyle



externalDocs metodu
Örnek
Şöyle yaparız
@Bean
 public OpenAPI springOpenAPI() {
  return new OpenAPI()
    .info(new Info()
      .title("Micro service")
      .description("APIs for Test Console service")
	  .version("1.0")
      .license(new License().name("Dev Team").url("https://github.com")))
    .externalDocs(new ExternalDocumentation()
	  .description("Test Documentation")
	  .url("https://github.com"));
 }
info metodu
Örnek
Şöyle yaparız
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Info;
import io.swagger.v3.oas.models.info.License;


@Configuration
class OpenApiConfig {

  @Bean
  public OpenAPI customOpenAPI(@Value("${application-description}"
                               String appDesciption, 
                               @Value("${application-version}"
                               String appVersion) {
    return new OpenAPI()
      .info(new Info()
        .title("sample application API")
.version(appVersion)
.description(appDesciption)
.termsOfService("http://swagger.io/terms/")
.license(new License().
          name("Apache 2.0").
          url("http://springdoc.org")));
  }
}

Hiç yorum yok:

Yorum Gönder