-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Changed module provider to work with KTypes to allow for generic spec…
…ialization Changed module provider to guarantee insertion order is preserved, and last insertion is at the end added status info
- Loading branch information
Showing
26 changed files
with
181 additions
and
72 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
3 changes: 2 additions & 1 deletion
3
src/main/kotlin/com/papsign/ktor/openapigen/OpenAPIGenModuleExtension.kt
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 |
---|---|---|
@@ -1,13 +1,14 @@ | ||
package com.papsign.ktor.openapigen | ||
|
||
import com.papsign.ktor.openapigen.modules.OpenAPIModule | ||
import kotlin.reflect.full.starProjectedType | ||
|
||
/** | ||
* implement this to automatically register an object as [OpenAPIModule] in the global context | ||
* only works if the object is in a package declared in [OpenAPIGen.Configuration.scanPackagesForModules] | ||
*/ | ||
interface OpenAPIGenModuleExtension: OpenAPIModule, OpenAPIGenExtension { | ||
override fun onInit(gen: OpenAPIGen) { | ||
gen.globalModuleProvider.registerModule(this) | ||
gen.globalModuleProvider.registerModule(this, this::class.starProjectedType) | ||
} | ||
} |
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
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
17 changes: 11 additions & 6 deletions
17
src/main/kotlin/com/papsign/ktor/openapigen/modules/ModuleProvider.kt
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 |
---|---|---|
@@ -1,14 +1,19 @@ | ||
package com.papsign.ktor.openapigen.modules | ||
|
||
import kotlin.reflect.KClass | ||
import com.papsign.ktor.openapigen.getKType | ||
import kotlin.reflect.KType | ||
|
||
interface ModuleProvider<THIS: ModuleProvider<THIS>> { | ||
fun <T: OpenAPIModule> ofClass(clazz: KClass<T>): Collection<T> | ||
fun registerModule(module: OpenAPIModule) | ||
fun ofType(type: KType): Collection<Any> | ||
fun registerModule(module: OpenAPIModule, type: KType) | ||
fun unRegisterModule(module: OpenAPIModule) | ||
fun child(): THIS | ||
} | ||
|
||
inline fun <reified T: OpenAPIModule> ModuleProvider<*>.ofClass(): Collection<T> { | ||
return ofClass(T::class) | ||
} | ||
inline fun <reified T: OpenAPIModule> ModuleProvider<*>.ofType(): Collection<T> { | ||
return ofType(getKType<T>()) as Collection<T> | ||
} | ||
|
||
inline fun <reified T: OpenAPIModule> ModuleProvider<*>.registerModule(module: T) { | ||
return registerModule(module, getKType<T>()) | ||
} |
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
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
9 changes: 9 additions & 0 deletions
9
src/main/kotlin/com/papsign/ktor/openapigen/modules/providers/StatusProvider.kt
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,9 @@ | ||
package com.papsign.ktor.openapigen.modules.providers | ||
|
||
import com.papsign.ktor.openapigen.modules.OpenAPIModule | ||
import io.ktor.http.HttpStatusCode | ||
import kotlin.reflect.KType | ||
|
||
interface StatusProvider : OpenAPIModule { | ||
fun getStatusForType(responseType: KType): HttpStatusCode | ||
} |
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
Oops, something went wrong.