-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Task 28 : Add Spring Open Api with its test and Revise README.md
- Loading branch information
1 parent
dbc575c
commit 795e7ba
Showing
6 changed files
with
127 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
35 changes: 35 additions & 0 deletions
35
src/main/java/com/security/rolepermissionexample/common/config/OpenApiConfig.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package com.security.rolepermissionexample.common.config; | ||
|
||
import io.swagger.v3.oas.annotations.OpenAPIDefinition; | ||
import io.swagger.v3.oas.annotations.enums.SecuritySchemeIn; | ||
import io.swagger.v3.oas.annotations.enums.SecuritySchemeType; | ||
import io.swagger.v3.oas.annotations.info.Contact; | ||
import io.swagger.v3.oas.annotations.info.Info; | ||
import io.swagger.v3.oas.annotations.security.SecurityScheme; | ||
|
||
/** | ||
* Configuration class named {@link OpenApiConfig} for OpenAPI documentation. | ||
*/ | ||
@OpenAPIDefinition( | ||
info = @Info( | ||
contact = @Contact( | ||
name = "Sercan Noyan Germiyanoğlu", | ||
url = "https://github.com/Rapter1990/parkinglot/" | ||
), | ||
description = "Case Study - Role Permission Through Spring Security in Spring Boot" + | ||
"(Spring Boot, Spring Security , Mysql, JUnit, Integration Test, Docker, Test Container, Github Actions, Postman) ", | ||
title = "rolepermissionexample", | ||
version = "1.0.0" | ||
) | ||
) | ||
@SecurityScheme( | ||
name = "bearerAuth", | ||
description = "JWT Token", | ||
scheme = "bearer", | ||
type = SecuritySchemeType.HTTP, | ||
bearerFormat = "JWT", | ||
in = SecuritySchemeIn.HEADER | ||
) | ||
public class OpenApiConfig { | ||
|
||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,3 +23,10 @@ spring: | |
sql: | ||
init: | ||
mode: always | ||
|
||
|
||
# SWAGGER | ||
springdoc: | ||
api-docs: | ||
enabled: true | ||
show-actuator: true |
59 changes: 59 additions & 0 deletions
59
src/test/java/com/security/rolepermissionexample/common/config/OpenApiConfigTest.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package com.security.rolepermissionexample.common.config; | ||
|
||
import io.swagger.v3.oas.annotations.OpenAPIDefinition; | ||
import io.swagger.v3.oas.annotations.enums.SecuritySchemeIn; | ||
import io.swagger.v3.oas.annotations.enums.SecuritySchemeType; | ||
import io.swagger.v3.oas.annotations.info.Contact; | ||
import io.swagger.v3.oas.annotations.info.Info; | ||
import io.swagger.v3.oas.annotations.security.SecurityScheme; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
class OpenApiConfigTest { | ||
|
||
@Test | ||
void openApiInfo() { | ||
|
||
// Given | ||
OpenAPIDefinition openAPIDefinition = OpenApiConfig.class.getAnnotation(OpenAPIDefinition.class); | ||
|
||
// Then | ||
assertEquals("1.0.0", openAPIDefinition.info().version()); | ||
assertEquals("rolepermissionexample", openAPIDefinition.info().title()); | ||
assertEquals("Case Study - Role Permission Through Spring Security in Spring Boot" + | ||
"(Spring Boot, Spring Security , Mysql, JUnit, Integration Test, Docker, Test Container, Github Actions, Postman) ", | ||
openAPIDefinition.info().description()); | ||
|
||
} | ||
|
||
@Test | ||
void securityScheme() { | ||
|
||
// Given | ||
SecurityScheme securityScheme = OpenApiConfig.class.getAnnotation(SecurityScheme.class); | ||
|
||
// Then | ||
assertEquals("bearerAuth", securityScheme.name()); | ||
assertEquals("JWT Token", securityScheme.description()); | ||
assertEquals("bearer", securityScheme.scheme()); | ||
assertEquals(SecuritySchemeType.HTTP, securityScheme.type()); | ||
assertEquals("JWT", securityScheme.bearerFormat()); | ||
assertEquals(SecuritySchemeIn.HEADER, securityScheme.in()); | ||
|
||
} | ||
|
||
@Test | ||
void contactInfo() { | ||
|
||
// Given | ||
Info info = OpenApiConfig.class.getAnnotation(OpenAPIDefinition.class).info(); | ||
Contact contact = info.contact(); | ||
|
||
// Then | ||
assertEquals("Sercan Noyan Germiyanoğlu", contact.name()); | ||
assertEquals("https://github.com/Rapter1990/parkinglot/", contact.url()); | ||
|
||
} | ||
|
||
} |