Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/deploy-to-mavencentral.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ on:
MAVEN_CENTRAL_PASSWORD:
required: true
jobs:
publish-to-mavencentral:
publish-to-maven-central:
runs-on: ubuntu-latest
steps:
- name: GitHub 리포지토리 체크아웃
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,44 +3,43 @@ package io.github.bgmsound.documentify.core.environment
import com.fasterxml.jackson.databind.ObjectMapper

@Suppress("UNCHECKED_CAST")
class StandaloneContextEnvironmentDelegate<T : StandaloneContextEnvironmentSpec<T>> : StandaloneContextEnvironmentSpec<T> {
lateinit var environmentSpec: T
val controllers: MutableList<Any> = mutableListOf()
val controllerAdvices: MutableList<Any> = mutableListOf()
var objectMapper: ObjectMapper? = null
abstract class AbstractStandaloneContextEnvironment<T : StandaloneContextEnvironment<T>> : StandaloneContextEnvironment<T>, AbstractDocumentContextEnvironment() {
protected val controllers: MutableList<Any> = mutableListOf()
protected val controllerAdvices: MutableList<Any> = mutableListOf()
protected var objectMapper: ObjectMapper? = null

override fun objectMapper(objectMapper: ObjectMapper): T {
this.objectMapper = objectMapper
return environmentSpec
return this as T
}

override fun controller(controller: Any): T {
this.controllers.add(controller)
return environmentSpec
return this as T
}

override fun controllers(vararg controllers: Any): T {
this.controllers.addAll(controllers)
return environmentSpec
return this as T
}

override fun controllers(controllers: List<Any>): T {
this.controllers.addAll(controllers)
return environmentSpec
return this as T
}

override fun controllerAdvice(controllerAdvice: Any): T {
this.controllerAdvices.add(controllerAdvice)
return environmentSpec
return this as T
}

override fun controllerAdvices(vararg controllerAdvices: Any): T {
this.controllerAdvices.addAll(controllerAdvices)
return environmentSpec
return this as T
}

override fun controllerAdvices(controllerAdvices: List<Any>): T {
this.controllerAdvices.addAll(controllerAdvices)
return environmentSpec
return this as T
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package io.github.bgmsound.documentify.core.environment

import com.fasterxml.jackson.databind.ObjectMapper

interface StandaloneContextEnvironmentSpec<T> {
interface StandaloneContextEnvironment<T : StandaloneContextEnvironment<T>> : DocumentContextEnvironment {

fun objectMapper(objectMapper: ObjectMapper): T

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package io.github.bgmsound.documentify.mvc

import io.github.bgmsound.documentify.core.environment.AbstractDocumentContextEnvironment

abstract class AbstractMvcDocumentContextEnvironment : AbstractDocumentContextEnvironment(), MvcDocumentContextEnvironment
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package io.github.bgmsound.documentify.mvc

import io.github.bgmsound.documentify.core.environment.AbstractDocumentContextEnvironment
import io.github.bgmsound.documentify.core.environment.DocumentContextEnvironment
import org.springframework.test.web.servlet.MockMvc

abstract class MvcDocumentContextEnvironment : AbstractDocumentContextEnvironment() {
interface MvcDocumentContextEnvironment : DocumentContextEnvironment {

abstract fun buildMockMvc(): MockMvc
fun buildMockMvc(): MockMvc

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import org.springframework.test.web.servlet.ResultMatcher

class ValidatableMockMvcResponseAdapter private constructor(
private val restAssuredMockResponse: ValidatableMockMvcResponse
): ValidatableMockResponse {
) : ValidatableMockResponse {

override fun expect(matcher: ResultMatcher): ValidatableMockResponse {
restAssuredMockResponse.expect(matcher)
Expand All @@ -29,9 +29,9 @@ class ValidatableMockMvcResponseAdapter private constructor(
return this
}

companion object {
companion object {
fun of(restAssuredMockResponse: ValidatableMockMvcResponse): ValidatableMockResponse {
return ValidatableMockMvcResponseAdapter(restAssuredMockResponse)
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package io.github.bgmsound.documentify.mvc.environment

import io.github.bgmsound.documentify.mvc.MvcDocumentContextEnvironment
import io.github.bgmsound.documentify.mvc.AbstractMvcDocumentContextEnvironment
import org.springframework.test.web.servlet.MockMvc

class MockMvcContextEnvironment private constructor(
private val mockMvc: MockMvc
): MvcDocumentContextEnvironment() {
): AbstractMvcDocumentContextEnvironment() {
override fun buildMockMvc(): MockMvc {
return mockMvc
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package io.github.bgmsound.documentify.mvc.environment

import io.github.bgmsound.documentify.core.environment.StandaloneContextEnvironmentDelegate
import io.github.bgmsound.documentify.core.environment.StandaloneContextEnvironmentSpec
import io.github.bgmsound.documentify.core.environment.AbstractStandaloneContextEnvironment
import io.github.bgmsound.documentify.mvc.MvcDocumentContextEnvironment
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter
import org.springframework.restdocs.RestDocumentationContextProvider
Expand All @@ -12,13 +11,8 @@ import org.springframework.test.web.servlet.setup.StandaloneMockMvcBuilder
import org.springframework.web.method.support.HandlerMethodArgumentResolver

class StandaloneMvcContextEnvironment private constructor(
private val provider: RestDocumentationContextProvider,
private val delegate: StandaloneContextEnvironmentDelegate<StandaloneMvcContextEnvironment> = StandaloneContextEnvironmentDelegate()
) : StandaloneContextEnvironmentSpec<StandaloneMvcContextEnvironment> by delegate, MvcDocumentContextEnvironment() {
init {
delegate.environmentSpec = this
}

private val provider: RestDocumentationContextProvider
) : AbstractStandaloneContextEnvironment<StandaloneMvcContextEnvironment>(), MvcDocumentContextEnvironment {
private val argumentResolvers: MutableList<HandlerMethodArgumentResolver> = mutableListOf()

fun argumentResolver(argumentResolver: HandlerMethodArgumentResolver): StandaloneMvcContextEnvironment {
Expand All @@ -38,12 +32,12 @@ class StandaloneMvcContextEnvironment private constructor(

override fun buildMockMvc(): MockMvc {
return MockMvcBuilders
.standaloneSetup(*delegate.controllers.toTypedArray())
.setControllerAdvice(*delegate.controllerAdvices.toTypedArray())
.standaloneSetup(*controllers.toTypedArray())
.setControllerAdvice(*controllerAdvices.toTypedArray())
.setCustomArgumentResolvers(*argumentResolvers.toTypedArray())
.apply<StandaloneMockMvcBuilder>(documentationConfiguration(provider))
.apply { if (delegate.objectMapper != null) {
val objectMapper = delegate.objectMapper!!
.apply { if (objectMapper != null) {
val objectMapper = objectMapper!!
setMessageConverters(MappingJackson2HttpMessageConverter(objectMapper))
}}
.build()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package io.github.bgmsound.documentify.mvc.environment

import io.github.bgmsound.documentify.mvc.MvcDocumentContextEnvironment
import io.github.bgmsound.documentify.mvc.AbstractMvcDocumentContextEnvironment
import org.springframework.restdocs.RestDocumentationContextProvider
import org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.documentationConfiguration
import org.springframework.test.web.servlet.MockMvc
Expand All @@ -11,7 +11,7 @@ import org.springframework.web.context.WebApplicationContext
class WebApplicationContextEnvironment private constructor(
private val provider: RestDocumentationContextProvider,
private val applicationContext: WebApplicationContext
) : MvcDocumentContextEnvironment() {
) : AbstractMvcDocumentContextEnvironment() {

companion object {
fun webApplicationContextEnvironment(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package io.github.bgmsound.documentify.reactive

import io.github.bgmsound.documentify.core.environment.AbstractDocumentContextEnvironment

abstract class AbstractReactiveDocumentContextEnvironment : AbstractDocumentContextEnvironment(), ReactiveDocumentContextEnvironment
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package io.github.bgmsound.documentify.reactive

import io.github.bgmsound.documentify.core.environment.AbstractDocumentContextEnvironment
import io.github.bgmsound.documentify.core.environment.DocumentContextEnvironment
import org.springframework.test.web.reactive.server.WebTestClient

abstract class ReactiveDocumentContextEnvironment : AbstractDocumentContextEnvironment() {
interface ReactiveDocumentContextEnvironment : DocumentContextEnvironment {

abstract fun buildWebTestClient(): WebTestClient
fun buildWebTestClient(): WebTestClient

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package io.github.bgmsound.documentify.reactive.environment

import io.github.bgmsound.documentify.reactive.ReactiveDocumentContextEnvironment
import io.github.bgmsound.documentify.reactive.AbstractReactiveDocumentContextEnvironment
import org.springframework.context.ApplicationContext
import org.springframework.restdocs.RestDocumentationContextProvider
import org.springframework.restdocs.webtestclient.WebTestClientRestDocumentation
Expand All @@ -9,7 +9,7 @@ import org.springframework.test.web.reactive.server.WebTestClient
class ApplicationContextEnvironment private constructor(
private val provider: RestDocumentationContextProvider,
private val applicationContext: ApplicationContext
) : ReactiveDocumentContextEnvironment() {
) : AbstractReactiveDocumentContextEnvironment() {
override fun buildWebTestClient(): WebTestClient {
return WebTestClient
.bindToApplicationContext(applicationContext)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package io.github.bgmsound.documentify.reactive.environment

import com.fasterxml.jackson.databind.ObjectMapper
import io.github.bgmsound.documentify.core.environment.StandaloneContextEnvironmentDelegate
import io.github.bgmsound.documentify.core.environment.StandaloneContextEnvironmentSpec
import io.github.bgmsound.documentify.core.environment.AbstractStandaloneContextEnvironment
import io.github.bgmsound.documentify.reactive.ReactiveDocumentContextEnvironment
import org.springframework.http.MediaType
import org.springframework.http.codec.json.Jackson2JsonDecoder
Expand All @@ -15,13 +14,8 @@ import org.springframework.web.reactive.result.method.HandlerMethodArgumentResol


class StandaloneReactiveContextEnvironment private constructor(
private val provider: RestDocumentationContextProvider,
private val delegate: StandaloneContextEnvironmentDelegate<StandaloneReactiveContextEnvironment> = StandaloneContextEnvironmentDelegate()
) : StandaloneContextEnvironmentSpec<StandaloneReactiveContextEnvironment> by delegate, ReactiveDocumentContextEnvironment() {
init {
delegate.environmentSpec = this
}

private val provider: RestDocumentationContextProvider
) : AbstractStandaloneContextEnvironment<StandaloneReactiveContextEnvironment>(), ReactiveDocumentContextEnvironment {
private val argumentResolvers = mutableListOf<HandlerMethodArgumentResolver>()

fun argumentResolver(argumentResolver: HandlerMethodArgumentResolver): StandaloneReactiveContextEnvironment {
Expand All @@ -41,18 +35,18 @@ class StandaloneReactiveContextEnvironment private constructor(

override fun buildWebTestClient(): WebTestClient {
return WebTestClient
.bindToController(*delegate.controllers.toTypedArray())
.controllerAdvice(*delegate.controllerAdvices.toTypedArray())
.bindToController(*controllers.toTypedArray())
.controllerAdvice(*controllerAdvices.toTypedArray())
.argumentResolvers { configurer ->
configurer.addCustomResolver(*argumentResolvers.toTypedArray())
}
.httpMessageCodecs { configurer -> if (delegate.objectMapper != null) {
val objectMapper = delegate.objectMapper!!
.httpMessageCodecs { configurer -> if (objectMapper != null) {
val objectMapper = objectMapper!!
configurer.defaultCodecs().jackson2JsonDecoder(Jackson2JsonDecoder(objectMapper, MediaType.APPLICATION_JSON))
configurer.defaultCodecs().jackson2JsonEncoder(Jackson2JsonEncoder(objectMapper, MediaType.APPLICATION_JSON))
}}
.configureClient()
.include(delegate.objectMapper)
.include(objectMapper)
.filter(WebTestClientRestDocumentation.documentationConfiguration(provider))
.build()
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package io.github.bgmsound.documentify.reactive.environment

import io.github.bgmsound.documentify.reactive.ReactiveDocumentContextEnvironment
import io.github.bgmsound.documentify.reactive.AbstractReactiveDocumentContextEnvironment
import org.springframework.restdocs.RestDocumentationContextProvider
import org.springframework.restdocs.webtestclient.WebTestClientRestDocumentation
import org.springframework.test.web.reactive.server.WebTestClient

class WebTestClientContextEnvironment private constructor(
private val provider: RestDocumentationContextProvider,
private val webTestClient: WebTestClient
) : ReactiveDocumentContextEnvironment() {
) : AbstractReactiveDocumentContextEnvironment() {
override fun buildWebTestClient(): WebTestClient {
return webTestClient
.mutate()
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
project.name=documentify

project.group=io.github.bgmsound
project.version.id=1.2.2
project.version.id=1.2.3
project.artifact=documentify

project.description=Documentify is a tool to generate API documentation from source code.
Expand Down