Skip to content

Commit

Permalink
Merge pull request #23 from wafflestudio/feat/swagger-init
Browse files Browse the repository at this point in the history
Swagger init settings
  • Loading branch information
JunBye authored Jan 1, 2025
2 parents 958dd43 + 7f3dc6f commit 89b56c6
Show file tree
Hide file tree
Showing 16 changed files with 124 additions and 6 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
/shelf/
/.idea/workspace.xml
/.idea/modules.xml
/.idea/httpRequests/*
# Editor-based HTTP Client requests
/httpRequests/
# Datasource local storage ignored files
Expand Down
3 changes: 3 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ dependencies {
implementation("org.springframework.boot:spring-boot-starter-web")
implementation("com.fasterxml.jackson.module:jackson-module-kotlin")
implementation("org.jetbrains.kotlin:kotlin-reflect")
implementation("org.springdoc:springdoc-openapi-starter-webmvc-ui:2.2.0")
runtimeOnly("com.mysql:mysql-connector-j")
testImplementation("org.springframework.boot:spring-boot-starter-test")
testImplementation("org.jetbrains.kotlin:kotlin-test-junit5")
Expand Down
47 changes: 47 additions & 0 deletions src/main/kotlin/com/example/toyTeam6Airbnb/SwaggerConfig.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package com.example.toyTeam6Airbnb

import io.swagger.v3.oas.annotations.OpenAPIDefinition
import io.swagger.v3.oas.models.Components
import io.swagger.v3.oas.models.OpenAPI
import io.swagger.v3.oas.models.info.Info
import io.swagger.v3.oas.models.security.SecurityRequirement
import io.swagger.v3.oas.models.security.SecurityScheme
import io.swagger.v3.oas.models.security.SecurityScheme.Type
import io.swagger.v3.oas.models.servers.Server
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer

@Configuration
@OpenAPIDefinition(
info = io.swagger.v3.oas.annotations.info.Info(
title = "Airbnb API",
version = "1.0"
)
)
class SwaggerConfig : WebMvcConfigurer {

@Bean
fun openAPI(): OpenAPI {
return OpenAPI()
.addSecurityItem(
SecurityRequirement().addList("Bearer Authentication")
)
.components(
Components().addSecuritySchemes
("Bearer Authentication", createAPIKeyScheme())
)
.addServersItem(Server().url("/"))
.info(
Info().title("WEBTOON API")
.description("Webtoon API Spec")
.version("v1.0.0")
)
}

fun createAPIKeyScheme(): SecurityScheme? {
return SecurityScheme().type(Type.HTTP)
.bearerFormat("JWT")
.scheme("bearer")
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
package com.example.toyTeam6Airbnb.profile.controller

import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RestController

@RestController
@RequestMapping("/api/v1")
class ProfileController
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
package com.example.toyTeam6Airbnb.profile.service

class ProfileServiceImpl
import org.springframework.stereotype.Service

@Service
class ProfileServiceImpl : ProfileService
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
package com.example.toyTeam6Airbnb.reservation.controller

import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RestController

@RestController
@RequestMapping("/api/v1")
class ReservationController
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
package com.example.toyTeam6Airbnb.reservation.service

class ReservationServiceImpl
import org.springframework.stereotype.Service

@Service
class ReservationServiceImpl : ReservationService
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
package com.example.toyTeam6Airbnb.review.controller

import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RestController

@RestController
@RequestMapping("/api/v1")
class ReviewController
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
package com.example.toyTeam6Airbnb.review.service

class ReviewServiceImpl
import org.springframework.stereotype.Service

@Service
class ReviewServiceImpl : ReviewService
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
package com.example.toyTeam6Airbnb.room.controller

import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RestController

@RestController
@RequestMapping("/api/v1")
class RoomController
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
package com.example.toyTeam6Airbnb.room.service

class RoomServiceImpl
import org.springframework.stereotype.Service

@Service
class RoomServiceImpl : RoomService
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
package com.example.toyTeam6Airbnb.user.controller

class UserController
import com.example.toyTeam6Airbnb.user.service.UserService
import io.swagger.v3.oas.annotations.Operation
import io.swagger.v3.oas.annotations.tags.Tag
import org.springframework.http.ResponseEntity
import org.springframework.web.bind.annotation.PostMapping
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RestController

@RestController
@RequestMapping("/api/v1")
@Tag(name = "User Controller", description = "User Controller API")
class UserController(
private val userService: UserService
) {
@PostMapping("/ping")
@Operation(summary = "Ping pong", description = "Sample ping pong api for testing")
fun ping(): ResponseEntity<String> {
return ResponseEntity.ok("pong")
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
package com.example.toyTeam6Airbnb.user.service

class UserServiceImpl
import org.springframework.stereotype.Service

@Service
class UserServiceImpl : UserService
6 changes: 6 additions & 0 deletions src/main/resources/UserApi.http
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
### Pingpong
POST http://localhost:8080/api/v1/ping
Content-Type: application/json

{
}
6 changes: 6 additions & 0 deletions src/main/resources/application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ spring:
profiles:
active: dev

springdoc:
api-docs:
path: /api-docs
swagger-ui:
path: /swagger-ui

cache:
expire-after-write: 1m
maximum-size: 100

0 comments on commit 89b56c6

Please sign in to comment.