|
| 1 | +package test.org.springdoc.api.app9; |
| 2 | + |
| 3 | +import io.swagger.v3.oas.models.Components; |
| 4 | +import io.swagger.v3.oas.models.OpenAPI; |
| 5 | +import io.swagger.v3.oas.models.info.Contact; |
| 6 | +import io.swagger.v3.oas.models.info.Info; |
| 7 | +import io.swagger.v3.oas.models.media.ArraySchema; |
| 8 | +import io.swagger.v3.oas.models.media.Schema; |
| 9 | +import io.swagger.v3.oas.models.security.SecurityScheme; |
| 10 | +import io.swagger.v3.oas.models.tags.Tag; |
| 11 | +import org.springdoc.core.models.GroupedOpenApi; |
| 12 | +import org.springframework.context.annotation.Bean; |
| 13 | +import org.springframework.context.annotation.Configuration; |
| 14 | + |
| 15 | +import java.util.List; |
| 16 | + |
| 17 | +@Configuration |
| 18 | +public class FooConfiguration { |
| 19 | + @Bean |
| 20 | + OpenAPI customOpenApi() { |
| 21 | + return new OpenAPI() |
| 22 | + .components(new Components().addSecuritySchemes("bearerScheme", |
| 23 | + new SecurityScheme() |
| 24 | + .type(SecurityScheme.Type.HTTP) |
| 25 | + .scheme("bearer") |
| 26 | + .bearerFormat("JWT")) |
| 27 | + .addSchemas("FeedResponse", feedResponseSchema())) |
| 28 | + .info(new Info() |
| 29 | + .title("Response API") |
| 30 | + .description("API for some response") |
| 31 | + .version("0.0.1") |
| 32 | + .contact(new Contact() |
| 33 | + .name("EAlf91"))) |
| 34 | + .tags(List.of(new Tag() |
| 35 | + .name("ResponseTag") |
| 36 | + .description("ResponseTag for API"), |
| 37 | + new Tag() |
| 38 | + .name("ResponseData") |
| 39 | + .description("Version 2 ResponseApi"))); |
| 40 | + |
| 41 | + } |
| 42 | + |
| 43 | + private Schema<?> feedResponseSchema() { |
| 44 | + Schema<?> schema = new Schema<>(); |
| 45 | + schema.addProperty("_links", linkSchema()); |
| 46 | + schema.addProperty("data", new ArraySchema().items(new Schema<>().$ref("#/components/schemas/ResponseData"))); |
| 47 | + return schema; |
| 48 | + } |
| 49 | + |
| 50 | + private Schema<?> linkSchema() { |
| 51 | + Schema<?> linkSchema = new Schema<>(); |
| 52 | + linkSchema.addProperty("next", new Schema<>().$ref("#/components/schemas/Link").example("http://localhost:8080/some-link")); |
| 53 | + linkSchema.addProperty("self", new Schema<>().$ref("#/components/schemas/Link").example("http://localhost:8080/some-other-link")); |
| 54 | + return linkSchema; |
| 55 | + } |
| 56 | + |
| 57 | +} |
0 commit comments