Created
October 11, 2021 15:09
-
-
Save devphilip/f5d577f08c7854cbbb0b735658ce6bba to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.devphilip.myaneeque.config; | |
import io.swagger.v3.oas.models.Components; | |
import io.swagger.v3.oas.models.OpenAPI; | |
import io.swagger.v3.oas.models.info.Contact; | |
import io.swagger.v3.oas.models.info.Info; | |
import io.swagger.v3.oas.models.info.License; | |
import io.swagger.v3.oas.models.security.SecurityRequirement; | |
import io.swagger.v3.oas.models.security.SecurityScheme; | |
import org.springframework.beans.factory.annotation.Value; | |
import org.springframework.context.annotation.Bean; | |
import org.springframework.context.annotation.Configuration; | |
import java.util.Collections; | |
@Configuration | |
public class OpenAPIConfig { | |
private static final String SECURITY_SCHEME_NAME = "Bearer token"; | |
/** | |
* Open API Configuration Bean | |
* | |
* @param title | |
* @param version | |
* @param description | |
* @return | |
*/ | |
@Bean | |
public OpenAPI openApiConfiguration( | |
@Value("${openapi.title}") final String title, | |
@Value("${openapi.version}") final String version, | |
@Value("${openapi.description}") final String description) { | |
return new OpenAPI() | |
.addSecurityItem(new SecurityRequirement().addList(SECURITY_SCHEME_NAME)) | |
.components( | |
new Components() | |
.addSecuritySchemes(SECURITY_SCHEME_NAME, | |
new SecurityScheme() | |
.name(SECURITY_SCHEME_NAME) | |
.type(SecurityScheme.Type.HTTP) | |
.scheme("bearer") | |
.bearerFormat("JWT") | |
) | |
) | |
.info(new Info() | |
.title(title) | |
.version(version) | |
.description(description) | |
.termsOfService("Terms of service") | |
.license(getLicense()) | |
.contact(getContact()) | |
); | |
} | |
/** | |
* Contact details for the developer(s) | |
* | |
* @return | |
*/ | |
private Contact getContact() { | |
Contact contact = new Contact(); | |
contact.setEmail("[email protected]"); | |
contact.setName("[email protected]"); | |
contact.setUrl("https://devphilip.com"); | |
contact.setExtensions(Collections.emptyMap()); | |
return contact; | |
} | |
/** | |
* License creation | |
* | |
* @return | |
*/ | |
private License getLicense() { | |
License license = new License(); | |
license.setName("Apache License, Version 2.0"); | |
license.setUrl("https://www.apache.org/licenses/LICENSE-2.0"); | |
license.setExtensions(Collections.emptyMap()); | |
return license; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment