Compare commits
80 Commits
Author | SHA1 | Date | |
---|---|---|---|
bf6d08c2bd | |||
68bae4918e | |||
592c116c3b | |||
c7fe5c288f | |||
e059633055 | |||
884a50fc83 | |||
588e52c9df | |||
f49fcb2a22 | |||
0a9475a7ab | |||
f8fbb7ad25 | |||
f792fb5d1f | |||
845d1a971d | |||
9396b2ecfe | |||
d74b7b3f28 | |||
e783630845 | |||
d907ba004a | |||
5c7ec4fdb4 | |||
097413067b | |||
eb7360b8d2 | |||
3ec467c1d8 | |||
152476c26e | |||
c4df4c7b2c | |||
87fa0b5602 | |||
53c76d6037 | |||
44324ca3a4 | |||
9364fb19e4 | |||
ca1f632665 | |||
9bb3184735 | |||
9a139b5713 | |||
9861c8e258 | |||
02f8ed04f2 | |||
3e23939386 | |||
d0575944db | |||
ccc81c2813 | |||
e8da52fd75 | |||
34c14e26da | |||
209b5e38a3 | |||
902faa9471 | |||
c7ef70a844 | |||
f83c3d203d | |||
bd05dbcfcb | |||
cb5c0e71a3 | |||
a209cafa74 | |||
3d27d30a31 | |||
8cc229667e | |||
54d12de67a | |||
9b93c887a2 | |||
19d828956b | |||
eabe90acfc | |||
7c2a2a9c9d | |||
15cdfb229d | |||
5a40f37f81 | |||
64f2516f19 | |||
2e5e39d3b2 | |||
5342cf00d1 | |||
8c0b658033 | |||
b7b1171685 | |||
1f730869a8 | |||
377a60614e | |||
e34bea1769 | |||
91bf93a866 | |||
73fb8b137f | |||
d3d6e79329 | |||
f2b7d924e0 | |||
f62010b4e7 | |||
5bd1534270 | |||
4c151ffeea | |||
08a0d2e47c | |||
f19476d3a3 | |||
8ede53fd5c | |||
31a9f44ec1 | |||
0eb2f126b3 | |||
0d658bd6a8 | |||
e924671c2b | |||
04996631b9 | |||
82d80873c8 | |||
487eaba741 | |||
b935cc1e1d | |||
9f2d2dd4e3 | |||
20f8a4f08f |
64
CHANGELOG.md
64
CHANGELOG.md
@ -12,6 +12,70 @@
|
||||
|
||||
## Released
|
||||
|
||||
## [3.14.4] - June 5th, 2023
|
||||
|
||||
### Changed
|
||||
|
||||
- Components definitions were not in the proper schema section. Prefixed the path with component slug in `protobuf java converter`.
|
||||
|
||||
## [3.14.3] - May 22nd, 2023
|
||||
|
||||
### Added
|
||||
|
||||
- Added `required` parameter in request info builder.
|
||||
|
||||
## [3.14.2] - May 8rd, 2023
|
||||
|
||||
### Changed
|
||||
|
||||
- Fixed bug where routes were not resolving when a parameter was declared via the ktor SDK
|
||||
|
||||
## [3.14.1] - April 28th, 2023
|
||||
|
||||
### Changed
|
||||
|
||||
- Generating enrichments for generic classes no longer throws the `Slugs should not be generated for field enrichments` error.
|
||||
|
||||
## [3.14.0] - April 6th, 2023
|
||||
|
||||
### Added
|
||||
|
||||
- Add support for response headers
|
||||
|
||||
## [3.13.0] - March 15th, 2023
|
||||
|
||||
### Changed
|
||||
|
||||
- Post, Put, and Patch now support not providing request info
|
||||
|
||||
## [3.12.0] - March 14th, 2023
|
||||
|
||||
### Added
|
||||
|
||||
- Add support for swagger documentation
|
||||
|
||||
## [3.11.0] - January 5th, 2023
|
||||
|
||||
### Added
|
||||
|
||||
- Support for type constraints.
|
||||
|
||||
## [3.10.0] - January 4th, 2023
|
||||
|
||||
### Added
|
||||
|
||||
- Support for type enrichments! `deprecated` and `description` to start
|
||||
|
||||
## [3.9.0] - November 15th, 2022
|
||||
|
||||
### Added
|
||||
|
||||
- `protobuf-java-converter` module for converting generated protobuf objects to `JsonSchema` representations
|
||||
|
||||
### Changed
|
||||
|
||||
- Application `rootPath` is no longer prefixed to serialized route path when `NotarizedRoute` is resolved
|
||||
|
||||
## [3.8.0] - November 9th, 2022
|
||||
|
||||
### Added
|
||||
|
@ -3,3 +3,7 @@
|
||||
[](https://search.maven.org/search?q=io.bkbn%20kompendium)
|
||||
|
||||
Documentation is stored in the `docs` folder and is hosted [here](https://bkbn.gitbook.io/kompendium)
|
||||
|
||||
## Showcase
|
||||
|
||||
If you would like to showcase docs that you build using Kompendium, add them to [the showcase discussion](https://github.com/bkbnio/kompendium/discussions/444)
|
||||
|
@ -1,12 +1,12 @@
|
||||
plugins {
|
||||
kotlin("jvm") version "1.7.21" apply false
|
||||
kotlin("plugin.serialization") version "1.7.21" apply false
|
||||
kotlin("jvm") version "1.8.21" apply false
|
||||
kotlin("plugin.serialization") version "1.8.21" apply false
|
||||
id("io.bkbn.sourdough.library.jvm") version "0.12.0" apply false
|
||||
id("io.bkbn.sourdough.application.jvm") version "0.12.0" apply false
|
||||
id("io.bkbn.sourdough.root") version "0.12.0"
|
||||
id("com.github.jakemarsden.git-hooks") version "0.0.2"
|
||||
id("org.jetbrains.kotlinx.kover") version "0.6.1"
|
||||
id("io.github.gradle-nexus.publish-plugin") version "1.1.0"
|
||||
id("io.github.gradle-nexus.publish-plugin") version "1.3.0"
|
||||
}
|
||||
|
||||
gitHooks {
|
||||
|
@ -33,7 +33,6 @@ dependencies {
|
||||
implementation("io.ktor:ktor-server-html-builder:$ktorVersion")
|
||||
implementation("io.ktor:ktor-server-content-negotiation:$ktorVersion")
|
||||
implementation("io.ktor:ktor-serialization-kotlinx-json:$ktorVersion")
|
||||
implementation("ch.qos.logback:logback-classic:1.4.4")
|
||||
|
||||
// Formatting
|
||||
detektPlugins("io.gitlab.arturbosch.detekt:detekt-formatting:$detektVersion")
|
||||
@ -58,9 +57,9 @@ dependencies {
|
||||
testFixturesApi("io.ktor:ktor-client:$ktorVersion")
|
||||
testFixturesApi("io.ktor:ktor-client-cio:$ktorVersion")
|
||||
|
||||
testFixturesApi("dev.forst:ktor-api-key:2.1.3")
|
||||
testFixturesApi("dev.forst:ktor-api-key:2.2.4")
|
||||
|
||||
testFixturesApi("org.jetbrains.kotlinx:kotlinx-serialization-json:1.4.1")
|
||||
testFixturesApi("org.jetbrains.kotlinx:kotlinx-serialization-json:1.5.1")
|
||||
}
|
||||
|
||||
testing {
|
||||
|
@ -1,7 +1,7 @@
|
||||
package io.bkbn.kompendium.core.metadata
|
||||
|
||||
sealed interface MethodInfoWithRequest : MethodInfo {
|
||||
val request: RequestInfo
|
||||
val request: RequestInfo?
|
||||
|
||||
abstract class Builder<T : MethodInfoWithRequest> : MethodInfo.Builder<T>() {
|
||||
internal var request: RequestInfo? = null
|
||||
|
@ -4,7 +4,7 @@ import io.bkbn.kompendium.oas.common.ExternalDocumentation
|
||||
import io.bkbn.kompendium.oas.payload.Parameter
|
||||
|
||||
class PatchInfo private constructor(
|
||||
override val request: RequestInfo,
|
||||
override val request: RequestInfo?,
|
||||
override val errors: MutableList<ResponseInfo>,
|
||||
override val response: ResponseInfo,
|
||||
override val tags: Set<String>,
|
||||
@ -26,7 +26,7 @@ class PatchInfo private constructor(
|
||||
|
||||
class Builder : MethodInfoWithRequest.Builder<PatchInfo>() {
|
||||
override fun build() = PatchInfo(
|
||||
request = request ?: error("request info must be present"),
|
||||
request = request,
|
||||
errors = errors,
|
||||
response = response ?: error("response info must be present"),
|
||||
tags = tags,
|
||||
|
@ -4,7 +4,7 @@ import io.bkbn.kompendium.oas.common.ExternalDocumentation
|
||||
import io.bkbn.kompendium.oas.payload.Parameter
|
||||
|
||||
class PostInfo private constructor(
|
||||
override val request: RequestInfo,
|
||||
override val request: RequestInfo?,
|
||||
override val errors: MutableList<ResponseInfo>,
|
||||
override val response: ResponseInfo,
|
||||
override val tags: Set<String>,
|
||||
@ -26,7 +26,7 @@ class PostInfo private constructor(
|
||||
|
||||
class Builder : MethodInfoWithRequest.Builder<PostInfo>() {
|
||||
override fun build() = PostInfo(
|
||||
request = request ?: error("request info must be present"),
|
||||
request = request,
|
||||
errors = errors,
|
||||
response = response ?: error("response info must be present"),
|
||||
tags = tags,
|
||||
|
@ -4,7 +4,7 @@ import io.bkbn.kompendium.oas.common.ExternalDocumentation
|
||||
import io.bkbn.kompendium.oas.payload.Parameter
|
||||
|
||||
class PutInfo private constructor(
|
||||
override val request: RequestInfo,
|
||||
override val request: RequestInfo?,
|
||||
override val errors: MutableList<ResponseInfo>,
|
||||
override val response: ResponseInfo,
|
||||
override val tags: Set<String>,
|
||||
@ -26,7 +26,7 @@ class PutInfo private constructor(
|
||||
|
||||
class Builder : MethodInfoWithRequest.Builder<PutInfo>() {
|
||||
override fun build() = PutInfo(
|
||||
request = request ?: error("request info must be present"),
|
||||
request = request,
|
||||
errors = errors,
|
||||
response = response ?: error("response info must be present"),
|
||||
tags = tags,
|
||||
|
@ -1,14 +1,17 @@
|
||||
package io.bkbn.kompendium.core.metadata
|
||||
|
||||
import io.bkbn.kompendium.enrichment.TypeEnrichment
|
||||
import io.bkbn.kompendium.oas.payload.MediaType
|
||||
import kotlin.reflect.KType
|
||||
import kotlin.reflect.typeOf
|
||||
|
||||
class RequestInfo private constructor(
|
||||
val requestType: KType,
|
||||
val typeEnrichment: TypeEnrichment<*>?,
|
||||
val description: String,
|
||||
val examples: Map<String, MediaType.Example>?,
|
||||
val mediaTypes: Set<String>
|
||||
val mediaTypes: Set<String>,
|
||||
val required: Boolean
|
||||
) {
|
||||
|
||||
companion object {
|
||||
@ -21,15 +24,28 @@ class RequestInfo private constructor(
|
||||
|
||||
class Builder {
|
||||
private var requestType: KType? = null
|
||||
private var typeEnrichment: TypeEnrichment<*>? = null
|
||||
private var description: String? = null
|
||||
private var examples: Map<String, MediaType.Example>? = null
|
||||
private var mediaTypes: Set<String>? = null
|
||||
private var required: Boolean? = null
|
||||
|
||||
fun required(r: Boolean) = apply {
|
||||
this.required = r
|
||||
}
|
||||
|
||||
fun requestType(t: KType) = apply {
|
||||
this.requestType = t
|
||||
}
|
||||
|
||||
inline fun <reified T> requestType() = apply { requestType(typeOf<T>()) }
|
||||
fun enrichment(t: TypeEnrichment<*>) = apply {
|
||||
this.typeEnrichment = t
|
||||
}
|
||||
|
||||
inline fun <reified T> requestType(enrichment: TypeEnrichment<T>? = null) = apply {
|
||||
requestType(typeOf<T>())
|
||||
enrichment?.let { enrichment(it) }
|
||||
}
|
||||
|
||||
fun description(s: String) = apply { this.description = s }
|
||||
|
||||
@ -44,8 +60,10 @@ class RequestInfo private constructor(
|
||||
fun build() = RequestInfo(
|
||||
requestType = requestType ?: error("Request type must be present"),
|
||||
description = description ?: error("Description must be present"),
|
||||
typeEnrichment = typeEnrichment,
|
||||
examples = examples,
|
||||
mediaTypes = mediaTypes ?: setOf("application/json")
|
||||
mediaTypes = mediaTypes ?: setOf("application/json"),
|
||||
required = required ?: true
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,7 @@
|
||||
package io.bkbn.kompendium.core.metadata
|
||||
|
||||
import io.bkbn.kompendium.enrichment.TypeEnrichment
|
||||
import io.bkbn.kompendium.oas.payload.Header
|
||||
import io.bkbn.kompendium.oas.payload.MediaType
|
||||
import io.ktor.http.HttpStatusCode
|
||||
import kotlin.reflect.KType
|
||||
@ -8,9 +10,11 @@ import kotlin.reflect.typeOf
|
||||
class ResponseInfo private constructor(
|
||||
val responseCode: HttpStatusCode,
|
||||
val responseType: KType,
|
||||
val typeEnrichment: TypeEnrichment<*>?,
|
||||
val description: String,
|
||||
val examples: Map<String, MediaType.Example>?,
|
||||
val mediaTypes: Set<String>
|
||||
val mediaTypes: Set<String>,
|
||||
val responseHeaders: Map<String, Header>?
|
||||
) {
|
||||
|
||||
companion object {
|
||||
@ -24,9 +28,15 @@ class ResponseInfo private constructor(
|
||||
class Builder {
|
||||
private var responseCode: HttpStatusCode? = null
|
||||
private var responseType: KType? = null
|
||||
private var typeEnrichment: TypeEnrichment<*>? = null
|
||||
private var description: String? = null
|
||||
private var examples: Map<String, MediaType.Example>? = null
|
||||
private var mediaTypes: Set<String>? = null
|
||||
private var responseHeaders: Map<String, Header>? = null
|
||||
|
||||
fun responseHeaders(headers: Map<String, Header>) = apply {
|
||||
this.responseHeaders = headers
|
||||
}
|
||||
|
||||
fun responseCode(code: HttpStatusCode) = apply {
|
||||
this.responseCode = code
|
||||
@ -36,7 +46,14 @@ class ResponseInfo private constructor(
|
||||
this.responseType = t
|
||||
}
|
||||
|
||||
inline fun <reified T> responseType() = apply { responseType(typeOf<T>()) }
|
||||
fun enrichment(t: TypeEnrichment<*>) = apply {
|
||||
this.typeEnrichment = t
|
||||
}
|
||||
|
||||
inline fun <reified T> responseType(enrichment: TypeEnrichment<T>? = null) = apply {
|
||||
responseType(typeOf<T>())
|
||||
enrichment?.let { enrichment(it) }
|
||||
}
|
||||
|
||||
fun description(s: String) = apply { this.description = s }
|
||||
|
||||
@ -52,8 +69,10 @@ class ResponseInfo private constructor(
|
||||
responseCode = responseCode ?: error("You must provide a response code in order to build a Response!"),
|
||||
responseType = responseType ?: error("You must provide a response type in order to build a Response!"),
|
||||
description = description ?: error("You must provide a description in order to build a Response!"),
|
||||
typeEnrichment = typeEnrichment,
|
||||
examples = examples,
|
||||
mediaTypes = mediaTypes ?: setOf("application/json")
|
||||
mediaTypes = mediaTypes ?: setOf("application/json"),
|
||||
responseHeaders = responseHeaders
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -18,6 +18,7 @@ import io.ktor.server.application.Hook
|
||||
import io.ktor.server.application.PluginBuilder
|
||||
import io.ktor.server.application.createRouteScopedPlugin
|
||||
import io.ktor.server.routing.Route
|
||||
import io.ktor.server.routing.application
|
||||
|
||||
object NotarizedRoute {
|
||||
class Config : SpecConfig {
|
||||
@ -43,7 +44,6 @@ object NotarizedRoute {
|
||||
name = "NotarizedRoute",
|
||||
createConfiguration = ::Config
|
||||
) {
|
||||
|
||||
// This is required in order to introspect the route path and authentication
|
||||
on(InstallHook) {
|
||||
val route = it as? Route ?: return@on
|
||||
@ -76,7 +76,18 @@ object NotarizedRoute {
|
||||
spec.paths[fullPath] = path
|
||||
}
|
||||
|
||||
fun Route.calculateRoutePath() = toString().replace(Regex("/\\(.+\\)"), "")
|
||||
fun Route.calculateRoutePath() = toString()
|
||||
.let {
|
||||
application.environment.rootPath.takeIf { root -> root.isNotEmpty() }
|
||||
?.let { root ->
|
||||
val sanitizedRoute = if (root.startsWith("/")) root else "/$root"
|
||||
it.replace(sanitizedRoute, "")
|
||||
}
|
||||
?: it
|
||||
}
|
||||
.replace(Regex("/\\(.+\\)"), "")
|
||||
.replace(Regex("/\\[.+\\]"), "")
|
||||
|
||||
fun Route.collectAuthMethods() = toString()
|
||||
.split("/")
|
||||
.filter { it.contains(Regex("\\(authenticate .*\\)")) }
|
||||
|
@ -18,7 +18,7 @@ import kotlinx.html.unsafe
|
||||
/**
|
||||
* Provides an out-of-the-box route to view docs using ReDoc on the specified [path].
|
||||
* @param pageTitle Webpage title you wish to be displayed on your docs
|
||||
* @param route path to docs resource
|
||||
* @param path path to docs resource
|
||||
* @param specUrl url to point ReDoc to the OpenAPI json document
|
||||
*/
|
||||
fun Route.redoc(pageTitle: String = "Docs", path: String = "/docs", specUrl: String = "/openapi.json") {
|
||||
|
@ -0,0 +1,91 @@
|
||||
package io.bkbn.kompendium.core.routes
|
||||
|
||||
import io.ktor.server.application.call
|
||||
import io.ktor.server.html.respondHtml
|
||||
import io.ktor.server.routing.Route
|
||||
import io.ktor.server.routing.get
|
||||
import io.ktor.server.routing.route
|
||||
import kotlinx.html.body
|
||||
import kotlinx.html.div
|
||||
import kotlinx.html.head
|
||||
import kotlinx.html.id
|
||||
import kotlinx.html.link
|
||||
import kotlinx.html.meta
|
||||
import kotlinx.html.script
|
||||
import kotlinx.html.title
|
||||
import kotlinx.html.unsafe
|
||||
|
||||
/**
|
||||
* Provides an out-of-the-box route to view docs using Swagger
|
||||
* @see <a href="https://swagger.io/specification/">Swagger OpenApi Specification</a>
|
||||
* for the latest supported open api version.
|
||||
* @param pageTitle Webpage title you wish to be displayed on your docs
|
||||
* @param path path to docs resource
|
||||
* @param specUrl url to point Swagger to the OpenAPI json document
|
||||
* @param swaggerVersion version of swagger-ui distribution
|
||||
*/
|
||||
fun Route.swagger(
|
||||
pageTitle: String = "Docs",
|
||||
path: String = "/swagger-ui",
|
||||
specUrl: String = "/openapi.json",
|
||||
swaggerVersion: String? = null
|
||||
) {
|
||||
val swaggerVersionSuffix = if (swaggerVersion == null) "" else "@$swaggerVersion"
|
||||
|
||||
route(path) {
|
||||
get {
|
||||
call.respondHtml {
|
||||
head {
|
||||
title {
|
||||
+pageTitle
|
||||
}
|
||||
meta {
|
||||
charset = "utf-8"
|
||||
}
|
||||
meta {
|
||||
name = "viewport"
|
||||
content = "width=device-width, initial-scale=1"
|
||||
}
|
||||
link {
|
||||
href = "https://unpkg.com/swagger-ui-dist$swaggerVersionSuffix/swagger-ui.css"
|
||||
rel = "stylesheet"
|
||||
}
|
||||
}
|
||||
body {
|
||||
div {
|
||||
id = "swagger-ui"
|
||||
}
|
||||
script {
|
||||
src = "https://unpkg.com/swagger-ui-dist$swaggerVersionSuffix/swagger-ui-standalone-preset.js"
|
||||
}
|
||||
script {
|
||||
src = "https://unpkg.com/swagger-ui-dist$swaggerVersionSuffix/swagger-ui-bundle.js"
|
||||
}
|
||||
unsafe {
|
||||
+"""
|
||||
<script>
|
||||
window.onload = function () {
|
||||
// Build a system
|
||||
const ui = SwaggerUIBundle({
|
||||
url: "$specUrl",
|
||||
dom_id: '#swagger-ui',
|
||||
deepLinking: true,
|
||||
presets: [
|
||||
SwaggerUIBundle.presets.apis,
|
||||
SwaggerUIStandalonePreset
|
||||
],
|
||||
plugins: [
|
||||
SwaggerUIBundle.plugins.DownloadUrl
|
||||
],
|
||||
layout: "StandaloneLayout",
|
||||
})
|
||||
window.ui = ui
|
||||
}
|
||||
</script>
|
||||
""".trimIndent()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -10,13 +10,14 @@ import io.bkbn.kompendium.core.metadata.PatchInfo
|
||||
import io.bkbn.kompendium.core.metadata.PostInfo
|
||||
import io.bkbn.kompendium.core.metadata.PutInfo
|
||||
import io.bkbn.kompendium.core.metadata.ResponseInfo
|
||||
import io.bkbn.kompendium.enrichment.TypeEnrichment
|
||||
import io.bkbn.kompendium.json.schema.SchemaConfigurator
|
||||
import io.bkbn.kompendium.json.schema.SchemaGenerator
|
||||
import io.bkbn.kompendium.json.schema.definition.NullableDefinition
|
||||
import io.bkbn.kompendium.json.schema.definition.OneOfDefinition
|
||||
import io.bkbn.kompendium.json.schema.definition.ReferenceDefinition
|
||||
import io.bkbn.kompendium.json.schema.util.Helpers.getReferenceSlug
|
||||
import io.bkbn.kompendium.json.schema.util.Helpers.getSimpleSlug
|
||||
import io.bkbn.kompendium.json.schema.util.Helpers.getSlug
|
||||
import io.bkbn.kompendium.oas.OpenApiSpec
|
||||
import io.bkbn.kompendium.oas.path.Path
|
||||
import io.bkbn.kompendium.oas.path.PathOperation
|
||||
@ -50,26 +51,36 @@ object Helpers {
|
||||
authMethods: List<String> = emptyList()
|
||||
) {
|
||||
SchemaGenerator.fromTypeOrUnit(
|
||||
this.response.responseType,
|
||||
spec.components.schemas, schemaConfigurator
|
||||
type = this.response.responseType,
|
||||
cache = spec.components.schemas,
|
||||
schemaConfigurator = schemaConfigurator,
|
||||
enrichment = this.response.typeEnrichment,
|
||||
)?.let { schema ->
|
||||
spec.components.schemas[this.response.responseType.getSimpleSlug()] = schema
|
||||
spec.components.schemas[this.response.responseType.getSlug(this.response.typeEnrichment)] = schema
|
||||
}
|
||||
|
||||
errors.forEach { error ->
|
||||
SchemaGenerator.fromTypeOrUnit(error.responseType, spec.components.schemas, schemaConfigurator)?.let { schema ->
|
||||
spec.components.schemas[error.responseType.getSimpleSlug()] = schema
|
||||
SchemaGenerator.fromTypeOrUnit(
|
||||
type = error.responseType,
|
||||
cache = spec.components.schemas,
|
||||
schemaConfigurator = schemaConfigurator,
|
||||
enrichment = error.typeEnrichment,
|
||||
)?.let { schema ->
|
||||
spec.components.schemas[error.responseType.getSlug(error.typeEnrichment)] = schema
|
||||
}
|
||||
}
|
||||
|
||||
when (this) {
|
||||
is MethodInfoWithRequest -> {
|
||||
this.request?.let { reqInfo ->
|
||||
SchemaGenerator.fromTypeOrUnit(
|
||||
this.request.requestType,
|
||||
spec.components.schemas,
|
||||
schemaConfigurator
|
||||
type = reqInfo.requestType,
|
||||
cache = spec.components.schemas,
|
||||
schemaConfigurator = schemaConfigurator,
|
||||
enrichment = reqInfo.typeEnrichment,
|
||||
)?.let { schema ->
|
||||
spec.components.schemas[this.request.requestType.getSimpleSlug()] = schema
|
||||
spec.components.schemas[reqInfo.requestType.getSlug(reqInfo.typeEnrichment)] = schema
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -112,18 +123,29 @@ object Helpers {
|
||||
?.map { listOf(it).toMap() }
|
||||
?.toMutableList(),
|
||||
requestBody = when (this) {
|
||||
is MethodInfoWithRequest -> Request(
|
||||
description = this.request.description,
|
||||
content = this.request.requestType.toReferenceContent(this.request.examples, this.request.mediaTypes),
|
||||
required = true
|
||||
is MethodInfoWithRequest -> this.request?.let { reqInfo ->
|
||||
Request(
|
||||
description = reqInfo.description,
|
||||
content = reqInfo.requestType.toReferenceContent(
|
||||
examples = reqInfo.examples,
|
||||
mediaTypes = reqInfo.mediaTypes,
|
||||
enrichment = reqInfo.typeEnrichment
|
||||
),
|
||||
required = reqInfo.required
|
||||
)
|
||||
}
|
||||
|
||||
else -> null
|
||||
},
|
||||
responses = mapOf(
|
||||
this.response.responseCode.value to Response(
|
||||
description = this.response.description,
|
||||
content = this.response.responseType.toReferenceContent(this.response.examples, this.response.mediaTypes)
|
||||
headers = this.response.responseHeaders,
|
||||
content = this.response.responseType.toReferenceContent(
|
||||
examples = this.response.examples,
|
||||
mediaTypes = this.response.mediaTypes,
|
||||
enrichment = this.response.typeEnrichment
|
||||
)
|
||||
)
|
||||
).plus(this.errors.toResponseMap())
|
||||
)
|
||||
@ -131,22 +153,32 @@ object Helpers {
|
||||
private fun List<ResponseInfo>.toResponseMap(): Map<Int, Response> = associate { error ->
|
||||
error.responseCode.value to Response(
|
||||
description = error.description,
|
||||
content = error.responseType.toReferenceContent(error.examples, error.mediaTypes)
|
||||
headers = error.responseHeaders,
|
||||
content = error.responseType.toReferenceContent(
|
||||
examples = error.examples,
|
||||
mediaTypes = error.mediaTypes,
|
||||
enrichment = error.typeEnrichment
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
private fun KType.toReferenceContent(
|
||||
examples: Map<String, MediaType.Example>?,
|
||||
mediaTypes: Set<String>
|
||||
mediaTypes: Set<String>,
|
||||
enrichment: TypeEnrichment<*>?
|
||||
): Map<String, MediaType>? =
|
||||
when (this.classifier as KClass<*>) {
|
||||
Unit::class -> null
|
||||
else -> mediaTypes.associateWith {
|
||||
MediaType(
|
||||
schema = if (this.isMarkedNullable) OneOfDefinition(
|
||||
schema = if (this.isMarkedNullable) {
|
||||
OneOfDefinition(
|
||||
NullableDefinition(),
|
||||
ReferenceDefinition(this.getReferenceSlug())
|
||||
) else ReferenceDefinition(this.getReferenceSlug()),
|
||||
ReferenceDefinition(this.getReferenceSlug(enrichment))
|
||||
)
|
||||
} else {
|
||||
ReferenceDefinition(this.getReferenceSlug(enrichment))
|
||||
},
|
||||
examples = examples
|
||||
)
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ package io.bkbn.kompendium.core
|
||||
|
||||
import dev.forst.ktor.apikey.apiKey
|
||||
import io.bkbn.kompendium.core.fixtures.TestHelpers.openApiTestAllSerializers
|
||||
import io.bkbn.kompendium.core.util.arrayConstraints
|
||||
import io.bkbn.kompendium.core.util.complexRequest
|
||||
import io.bkbn.kompendium.core.util.customAuthConfig
|
||||
import io.bkbn.kompendium.core.util.customFieldNameResponse
|
||||
@ -9,6 +10,12 @@ import io.bkbn.kompendium.core.util.dateTimeString
|
||||
import io.bkbn.kompendium.core.util.defaultAuthConfig
|
||||
import io.bkbn.kompendium.core.util.defaultField
|
||||
import io.bkbn.kompendium.core.util.defaultParameter
|
||||
import io.bkbn.kompendium.core.util.doubleConstraints
|
||||
import io.bkbn.kompendium.core.util.enrichedGenericResponse
|
||||
import io.bkbn.kompendium.core.util.enrichedComplexGenericType
|
||||
import io.bkbn.kompendium.core.util.enrichedNestedCollection
|
||||
import io.bkbn.kompendium.core.util.enrichedSimpleRequest
|
||||
import io.bkbn.kompendium.core.util.enrichedSimpleResponse
|
||||
import io.bkbn.kompendium.core.util.exampleParams
|
||||
import io.bkbn.kompendium.core.util.genericException
|
||||
import io.bkbn.kompendium.core.util.genericPolymorphicResponse
|
||||
@ -16,12 +23,14 @@ import io.bkbn.kompendium.core.util.genericPolymorphicResponseMultipleImpls
|
||||
import io.bkbn.kompendium.core.util.gnarlyGenericResponse
|
||||
import io.bkbn.kompendium.core.util.headerParameter
|
||||
import io.bkbn.kompendium.core.util.ignoredFieldsResponse
|
||||
import io.bkbn.kompendium.core.util.intConstraints
|
||||
import io.bkbn.kompendium.core.util.multipleAuthStrategies
|
||||
import io.bkbn.kompendium.core.util.multipleExceptions
|
||||
import io.bkbn.kompendium.core.util.nestedGenericCollection
|
||||
import io.bkbn.kompendium.core.util.nestedGenericMultipleParamsCollection
|
||||
import io.bkbn.kompendium.core.util.nestedGenericResponse
|
||||
import io.bkbn.kompendium.core.util.nestedTypeName
|
||||
import io.bkbn.kompendium.core.util.nestedUnderRoot
|
||||
import io.bkbn.kompendium.core.util.nonRequiredParam
|
||||
import io.bkbn.kompendium.core.util.nonRequiredParams
|
||||
import io.bkbn.kompendium.core.util.notarizedDelete
|
||||
@ -40,22 +49,28 @@ import io.bkbn.kompendium.core.util.polymorphicCollectionResponse
|
||||
import io.bkbn.kompendium.core.util.polymorphicException
|
||||
import io.bkbn.kompendium.core.util.polymorphicMapResponse
|
||||
import io.bkbn.kompendium.core.util.polymorphicResponse
|
||||
import io.bkbn.kompendium.core.util.postNoReqBody
|
||||
import io.bkbn.kompendium.core.util.primitives
|
||||
import io.bkbn.kompendium.core.util.reqRespExamples
|
||||
import io.bkbn.kompendium.core.util.optionalReqExample
|
||||
import io.bkbn.kompendium.core.util.requiredParams
|
||||
import io.bkbn.kompendium.core.util.responseHeaders
|
||||
import io.bkbn.kompendium.core.util.returnsList
|
||||
import io.bkbn.kompendium.core.util.rootRoute
|
||||
import io.bkbn.kompendium.core.util.samePathDifferentMethodsAndAuth
|
||||
import io.bkbn.kompendium.core.util.samePathSameMethod
|
||||
import io.bkbn.kompendium.core.util.simpleGenericResponse
|
||||
import io.bkbn.kompendium.core.util.simplePathParsing
|
||||
import io.bkbn.kompendium.core.util.simpleRecursive
|
||||
import io.bkbn.kompendium.core.util.singleException
|
||||
import io.bkbn.kompendium.core.util.stringConstraints
|
||||
import io.bkbn.kompendium.core.util.stringContentEncodingConstraints
|
||||
import io.bkbn.kompendium.core.util.stringPatternConstraints
|
||||
import io.bkbn.kompendium.core.util.topLevelNullable
|
||||
import io.bkbn.kompendium.core.util.trailingSlash
|
||||
import io.bkbn.kompendium.core.util.paramWrapper
|
||||
import io.bkbn.kompendium.core.util.unbackedFieldsResponse
|
||||
import io.bkbn.kompendium.core.util.withOperationId
|
||||
import io.bkbn.kompendium.core.util.nestedUnderRoot
|
||||
import io.bkbn.kompendium.core.util.rootRoute
|
||||
import io.bkbn.kompendium.core.util.simplePathParsing
|
||||
import io.bkbn.kompendium.core.util.trailingSlash
|
||||
import io.bkbn.kompendium.json.schema.definition.TypeDefinition
|
||||
import io.bkbn.kompendium.json.schema.exception.UnknownSchemaException
|
||||
import io.bkbn.kompendium.oas.component.Components
|
||||
@ -77,6 +92,7 @@ import io.ktor.server.auth.UserIdPrincipal
|
||||
import io.ktor.server.auth.basic
|
||||
import io.ktor.server.auth.jwt.jwt
|
||||
import io.ktor.server.auth.oauth
|
||||
import java.net.URI
|
||||
import java.time.Instant
|
||||
import kotlin.reflect.typeOf
|
||||
|
||||
@ -118,6 +134,12 @@ class KompendiumTest : DescribeSpec({
|
||||
it("Can override media types") {
|
||||
openApiTestAllSerializers("T0052__override_media_types.json") { overrideMediaTypes() }
|
||||
}
|
||||
it("Can support a post request with no request body") {
|
||||
openApiTestAllSerializers("T0065__post_no_req_body.json") { postNoReqBody() }
|
||||
}
|
||||
it("Can notarize a route with response headers") {
|
||||
openApiTestAllSerializers("T0066__notarized_get_with_response_headers.json") { responseHeaders() }
|
||||
}
|
||||
}
|
||||
describe("Route Parsing") {
|
||||
it("Can parse a simple path and store it under the expected route") {
|
||||
@ -132,6 +154,9 @@ class KompendiumTest : DescribeSpec({
|
||||
it("Can notarize a route with a trailing slash") {
|
||||
openApiTestAllSerializers("T0015__trailing_slash.json") { trailingSlash() }
|
||||
}
|
||||
it("Can notarize a route with a parameter") {
|
||||
openApiTestAllSerializers("T0068__param_wrapper.json") { paramWrapper() }
|
||||
}
|
||||
}
|
||||
describe("Exceptions") {
|
||||
it("Can add an exception status code to a response") {
|
||||
@ -154,6 +179,9 @@ class KompendiumTest : DescribeSpec({
|
||||
it("Can describe example parameters") {
|
||||
openApiTestAllSerializers("T0021__example_parameters.json") { exampleParams() }
|
||||
}
|
||||
it("Can generate example optional request body") {
|
||||
openApiTestAllSerializers("T0069__example_optional_req.json") { optionalReqExample() }
|
||||
}
|
||||
}
|
||||
describe("Defaults") {
|
||||
it("Can generate a default parameter value") {
|
||||
@ -275,6 +303,19 @@ class KompendiumTest : DescribeSpec({
|
||||
}
|
||||
) { samePathDifferentMethodsAndAuth() }
|
||||
}
|
||||
it("Can generate paths without application root-path") {
|
||||
openApiTestAllSerializers(
|
||||
"T0054__app_with_rootpath.json",
|
||||
applicationEnvironmentBuilder = {
|
||||
rootPath = "/example"
|
||||
},
|
||||
specOverrides = {
|
||||
copy(
|
||||
servers = servers.map { it.copy(url = URI("${it.url}/example")) }.toMutableList()
|
||||
)
|
||||
}
|
||||
) { notarizedGet() }
|
||||
}
|
||||
}
|
||||
describe("Error Handling") {
|
||||
it("Throws a clear exception when an unidentified type is encountered") {
|
||||
@ -283,16 +324,23 @@ class KompendiumTest : DescribeSpec({
|
||||
}
|
||||
it("Throws an exception when same method for same path has been previously registered") {
|
||||
val exception = shouldThrow<IllegalArgumentException> {
|
||||
openApiTestAllSerializers("") {
|
||||
openApiTestAllSerializers(
|
||||
snapshotName = "",
|
||||
applicationSetup = {
|
||||
install(Authentication) {
|
||||
basic("basic") {
|
||||
realm = "Ktor Server"
|
||||
validate { UserIdPrincipal("Placeholder") }
|
||||
}
|
||||
}
|
||||
},
|
||||
) {
|
||||
samePathSameMethod()
|
||||
}
|
||||
}
|
||||
exception.message should startWith("A route has already been registered for path: /test/{a} and method: GET")
|
||||
}
|
||||
}
|
||||
describe("Constraints") {
|
||||
// TODO Assess strategies here
|
||||
}
|
||||
describe("Formats") {
|
||||
it("Can set a format for a simple type schema") {
|
||||
openApiTestAllSerializers(
|
||||
@ -400,4 +448,43 @@ class KompendiumTest : DescribeSpec({
|
||||
) { multipleAuthStrategies() }
|
||||
}
|
||||
}
|
||||
describe("Enrichment") {
|
||||
it("Can enrich a simple request") {
|
||||
openApiTestAllSerializers("T0055__enriched_simple_request.json") { enrichedSimpleRequest() }
|
||||
}
|
||||
it("Can enrich a simple response") {
|
||||
openApiTestAllSerializers("T0058__enriched_simple_response.json") { enrichedSimpleResponse() }
|
||||
}
|
||||
it("Can enrich a nested collection") {
|
||||
openApiTestAllSerializers("T0056__enriched_nested_collection.json") { enrichedNestedCollection() }
|
||||
}
|
||||
it("Can enrich a complex generic type") {
|
||||
openApiTestAllSerializers("T0057__enriched_complex_generic_type.json") { enrichedComplexGenericType() }
|
||||
}
|
||||
it("Can enrich a generic object") {
|
||||
openApiTestAllSerializers("T0067__enriched_generic_object.json") { enrichedGenericResponse() }
|
||||
}
|
||||
}
|
||||
describe("Constraints") {
|
||||
it("Can apply constraints to an int field") {
|
||||
openApiTestAllSerializers("T0059__int_constraints.json") { intConstraints() }
|
||||
}
|
||||
it("Can apply constraints to a double field") {
|
||||
openApiTestAllSerializers("T0060__double_constraints.json") { doubleConstraints() }
|
||||
}
|
||||
it("Can apply a min and max length to a string field") {
|
||||
openApiTestAllSerializers("T0061__string_min_max_constraints.json") { stringConstraints() }
|
||||
}
|
||||
it("Can apply a pattern to a string field") {
|
||||
openApiTestAllSerializers("T0062__string_pattern_constraints.json") { stringPatternConstraints() }
|
||||
}
|
||||
it("Can apply a content encoding and media type to a string field") {
|
||||
openApiTestAllSerializers("T0063__string_content_encoding_constraints.json") {
|
||||
stringContentEncodingConstraints()
|
||||
}
|
||||
}
|
||||
it("Can apply constraints to an array field") {
|
||||
openApiTestAllSerializers("T0064__array_constraints.json") { arrayConstraints() }
|
||||
}
|
||||
}
|
||||
})
|
||||
|
160
core/src/test/kotlin/io/bkbn/kompendium/core/util/Constraints.kt
Normal file
160
core/src/test/kotlin/io/bkbn/kompendium/core/util/Constraints.kt
Normal file
@ -0,0 +1,160 @@
|
||||
package io.bkbn.kompendium.core.util
|
||||
|
||||
import io.bkbn.kompendium.core.fixtures.DoubleResponse
|
||||
import io.bkbn.kompendium.core.fixtures.Page
|
||||
import io.bkbn.kompendium.core.fixtures.TestCreatedResponse
|
||||
import io.bkbn.kompendium.core.fixtures.TestNested
|
||||
import io.bkbn.kompendium.core.metadata.GetInfo
|
||||
import io.bkbn.kompendium.core.plugin.NotarizedRoute
|
||||
import io.bkbn.kompendium.core.util.TestModules.defaultPath
|
||||
import io.bkbn.kompendium.enrichment.TypeEnrichment
|
||||
import io.ktor.http.HttpStatusCode
|
||||
import io.ktor.server.application.install
|
||||
import io.ktor.server.routing.Routing
|
||||
import io.ktor.server.routing.route
|
||||
|
||||
fun Routing.intConstraints() {
|
||||
route(defaultPath) {
|
||||
install(NotarizedRoute()) {
|
||||
get = GetInfo.builder {
|
||||
summary("Get an int")
|
||||
description("Get an int")
|
||||
response {
|
||||
responseCode(HttpStatusCode.OK)
|
||||
description("An int")
|
||||
responseType(
|
||||
enrichment = TypeEnrichment("example") {
|
||||
TestCreatedResponse::id {
|
||||
minimum = 2
|
||||
maximum = 100
|
||||
multipleOf = 2
|
||||
}
|
||||
}
|
||||
)
|
||||
responseCode(HttpStatusCode.OK)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun Routing.doubleConstraints() {
|
||||
route(defaultPath) {
|
||||
install(NotarizedRoute()) {
|
||||
get = GetInfo.builder {
|
||||
summary("Get a double")
|
||||
description("Get a double")
|
||||
response {
|
||||
responseCode(HttpStatusCode.OK)
|
||||
description("A double")
|
||||
responseType(
|
||||
enrichment = TypeEnrichment("example") {
|
||||
DoubleResponse::payload {
|
||||
minimum = 2.0
|
||||
maximum = 100.0
|
||||
multipleOf = 2.0
|
||||
}
|
||||
}
|
||||
)
|
||||
responseCode(HttpStatusCode.OK)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun Routing.stringConstraints() {
|
||||
route(defaultPath) {
|
||||
install(NotarizedRoute()) {
|
||||
get = GetInfo.builder {
|
||||
summary("Get a string")
|
||||
description("Get a string with constraints")
|
||||
response {
|
||||
responseCode(HttpStatusCode.OK)
|
||||
description("A string")
|
||||
responseType(
|
||||
enrichment = TypeEnrichment("example") {
|
||||
TestNested::nesty {
|
||||
maxLength = 10
|
||||
minLength = 2
|
||||
}
|
||||
}
|
||||
)
|
||||
responseCode(HttpStatusCode.OK)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun Routing.stringPatternConstraints() {
|
||||
route(defaultPath) {
|
||||
install(NotarizedRoute()) {
|
||||
get = GetInfo.builder {
|
||||
summary("Get a string")
|
||||
description("This is a description")
|
||||
response {
|
||||
responseCode(HttpStatusCode.OK)
|
||||
description("A string")
|
||||
responseType(
|
||||
enrichment = TypeEnrichment("example") {
|
||||
TestNested::nesty {
|
||||
pattern = "[a-z]+"
|
||||
}
|
||||
}
|
||||
)
|
||||
responseCode(HttpStatusCode.OK)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun Routing.stringContentEncodingConstraints() {
|
||||
route(defaultPath) {
|
||||
install(NotarizedRoute()) {
|
||||
get = GetInfo.builder {
|
||||
summary("Get a string")
|
||||
description("This is a description")
|
||||
response {
|
||||
responseCode(HttpStatusCode.OK)
|
||||
description("A string")
|
||||
responseType(
|
||||
enrichment = TypeEnrichment("example") {
|
||||
TestNested::nesty {
|
||||
contentEncoding = "base64"
|
||||
contentMediaType = "image/png"
|
||||
}
|
||||
}
|
||||
)
|
||||
responseCode(HttpStatusCode.OK)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun Routing.arrayConstraints() {
|
||||
route(defaultPath) {
|
||||
install(NotarizedRoute()) {
|
||||
get = GetInfo.builder {
|
||||
summary("Get an array")
|
||||
description("Get an array of strings")
|
||||
response {
|
||||
responseCode(HttpStatusCode.OK)
|
||||
description("An array")
|
||||
responseType(
|
||||
enrichment = TypeEnrichment("example") {
|
||||
Page<String>::content {
|
||||
minItems = 2
|
||||
maxItems = 10
|
||||
uniqueItems = true
|
||||
}
|
||||
}
|
||||
)
|
||||
responseCode(HttpStatusCode.OK)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
168
core/src/test/kotlin/io/bkbn/kompendium/core/util/Enrichment.kt
Normal file
168
core/src/test/kotlin/io/bkbn/kompendium/core/util/Enrichment.kt
Normal file
@ -0,0 +1,168 @@
|
||||
package io.bkbn.kompendium.core.util
|
||||
|
||||
import io.bkbn.kompendium.core.fixtures.ComplexRequest
|
||||
import io.bkbn.kompendium.core.fixtures.MultiNestedGenerics
|
||||
import io.bkbn.kompendium.core.fixtures.NestedComplexItem
|
||||
import io.bkbn.kompendium.core.fixtures.TestCreatedResponse
|
||||
import io.bkbn.kompendium.core.fixtures.TestResponse
|
||||
import io.bkbn.kompendium.core.fixtures.TestSimpleRequest
|
||||
import io.bkbn.kompendium.core.fixtures.GenericObject
|
||||
import io.bkbn.kompendium.core.metadata.GetInfo
|
||||
import io.bkbn.kompendium.core.metadata.PostInfo
|
||||
import io.bkbn.kompendium.core.plugin.NotarizedRoute
|
||||
import io.bkbn.kompendium.enrichment.TypeEnrichment
|
||||
import io.ktor.http.HttpStatusCode
|
||||
import io.ktor.server.application.install
|
||||
import io.ktor.server.routing.Routing
|
||||
import io.ktor.server.routing.route
|
||||
|
||||
fun Routing.enrichedSimpleResponse() {
|
||||
route("/enriched") {
|
||||
install(NotarizedRoute()) {
|
||||
get = GetInfo.builder {
|
||||
summary(TestModules.defaultPathSummary)
|
||||
description(TestModules.defaultPathDescription)
|
||||
response {
|
||||
responseType(
|
||||
enrichment = TypeEnrichment("simple") {
|
||||
TestResponse::c {
|
||||
description = "A simple description"
|
||||
}
|
||||
}
|
||||
)
|
||||
description("A good response")
|
||||
responseCode(HttpStatusCode.Created)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun Routing.enrichedSimpleRequest() {
|
||||
route("/example") {
|
||||
install(NotarizedRoute()) {
|
||||
parameters = TestModules.defaultParams
|
||||
post = PostInfo.builder {
|
||||
summary(TestModules.defaultPathSummary)
|
||||
description(TestModules.defaultPathDescription)
|
||||
request {
|
||||
requestType(
|
||||
enrichment = TypeEnrichment("simple") {
|
||||
TestSimpleRequest::a {
|
||||
description = "A simple description"
|
||||
}
|
||||
TestSimpleRequest::b {
|
||||
deprecated = true
|
||||
}
|
||||
}
|
||||
)
|
||||
description("A test request")
|
||||
}
|
||||
response {
|
||||
responseCode(HttpStatusCode.Created)
|
||||
responseType<TestCreatedResponse>()
|
||||
description(TestModules.defaultResponseDescription)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun Routing.enrichedNestedCollection() {
|
||||
route("/example") {
|
||||
install(NotarizedRoute()) {
|
||||
parameters = TestModules.defaultParams
|
||||
post = PostInfo.builder {
|
||||
summary(TestModules.defaultPathSummary)
|
||||
description(TestModules.defaultPathDescription)
|
||||
request {
|
||||
requestType(
|
||||
enrichment = TypeEnrichment("simple") {
|
||||
ComplexRequest::tables {
|
||||
description = "A nested item"
|
||||
typeEnrichment = TypeEnrichment("nested") {
|
||||
NestedComplexItem::name {
|
||||
description = "A nested description"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
description("A test request")
|
||||
}
|
||||
response {
|
||||
responseCode(HttpStatusCode.Created)
|
||||
responseType<TestCreatedResponse>()
|
||||
description(TestModules.defaultResponseDescription)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun Routing.enrichedComplexGenericType() {
|
||||
route("/example") {
|
||||
install(NotarizedRoute()) {
|
||||
parameters = TestModules.defaultParams
|
||||
post = PostInfo.builder {
|
||||
summary(TestModules.defaultPathSummary)
|
||||
description(TestModules.defaultPathDescription)
|
||||
request {
|
||||
requestType(
|
||||
enrichment = TypeEnrichment("simple") {
|
||||
MultiNestedGenerics<String, ComplexRequest>::content {
|
||||
description = "Getting pretty crazy"
|
||||
typeEnrichment = TypeEnrichment("nested") {
|
||||
ComplexRequest::tables {
|
||||
description = "A nested item"
|
||||
typeEnrichment = TypeEnrichment("nested") {
|
||||
NestedComplexItem::name {
|
||||
description = "A nested description"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
description("A test request")
|
||||
}
|
||||
response {
|
||||
responseCode(HttpStatusCode.Created)
|
||||
responseType<TestCreatedResponse>()
|
||||
description(TestModules.defaultResponseDescription)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun Routing.enrichedGenericResponse() {
|
||||
route("/example") {
|
||||
install(NotarizedRoute()) {
|
||||
get = GetInfo.builder {
|
||||
summary(TestModules.defaultPathSummary)
|
||||
description(TestModules.defaultPathDescription)
|
||||
response {
|
||||
responseType(
|
||||
enrichment = TypeEnrichment("generic") {
|
||||
GenericObject<TestSimpleRequest>::data {
|
||||
description = "A simple description"
|
||||
typeEnrichment = TypeEnrichment("simple") {
|
||||
TestSimpleRequest::a {
|
||||
description = "A simple description"
|
||||
}
|
||||
TestSimpleRequest::b {
|
||||
deprecated = true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
description("A good response")
|
||||
responseCode(HttpStatusCode.Created)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -9,7 +9,7 @@ import io.ktor.server.routing.route
|
||||
fun Routing.samePathSameMethod() {
|
||||
route(defaultPath) {
|
||||
basicGetGenerator<TestResponse>()
|
||||
authenticate {
|
||||
authenticate("basic") {
|
||||
basicGetGenerator<TestResponse>()
|
||||
}
|
||||
}
|
||||
|
@ -55,3 +55,30 @@ fun Routing.exampleParams() = basicGetGenerator<TestResponse>(
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
fun Routing.optionalReqExample() {
|
||||
route(rootPath) {
|
||||
install(NotarizedRoute()) {
|
||||
post = PostInfo.builder {
|
||||
summary(defaultPathSummary)
|
||||
description(defaultPathDescription)
|
||||
request {
|
||||
description(defaultRequestDescription)
|
||||
requestType<TestRequest>()
|
||||
examples(
|
||||
"Testerina" to TestRequest(TestNested("asdf"), 1.5, emptyList())
|
||||
)
|
||||
required(false)
|
||||
}
|
||||
response {
|
||||
description(defaultResponseDescription)
|
||||
responseCode(HttpStatusCode.OK)
|
||||
responseType<TestResponse>()
|
||||
examples(
|
||||
"Testerino" to TestResponse("Heya")
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -20,7 +20,9 @@ import io.bkbn.kompendium.core.util.TestModules.defaultPathSummary
|
||||
import io.bkbn.kompendium.core.util.TestModules.defaultResponseDescription
|
||||
import io.bkbn.kompendium.core.util.TestModules.rootPath
|
||||
import io.bkbn.kompendium.json.schema.definition.TypeDefinition
|
||||
import io.bkbn.kompendium.oas.payload.Header
|
||||
import io.bkbn.kompendium.oas.payload.Parameter
|
||||
import io.ktor.http.HttpHeaders
|
||||
import io.ktor.http.HttpStatusCode
|
||||
import io.ktor.server.application.call
|
||||
import io.ktor.server.application.install
|
||||
@ -56,6 +58,38 @@ fun Routing.notarizedGet() {
|
||||
}
|
||||
}
|
||||
|
||||
fun Routing.responseHeaders() {
|
||||
route(defaultPath) {
|
||||
install(NotarizedRoute()) {
|
||||
parameters = defaultParams
|
||||
get = GetInfo.builder {
|
||||
response {
|
||||
responseCode(HttpStatusCode.OK)
|
||||
responseType<TestResponse>()
|
||||
description(defaultResponseDescription)
|
||||
responseHeaders(
|
||||
mapOf(
|
||||
HttpHeaders.ETag to Header(
|
||||
TypeDefinition.STRING,
|
||||
"https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/ETag"
|
||||
),
|
||||
HttpHeaders.LastModified to Header(
|
||||
TypeDefinition.STRING,
|
||||
"https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Last-Modified"
|
||||
),
|
||||
)
|
||||
)
|
||||
}
|
||||
summary(defaultPathSummary)
|
||||
description(defaultPathDescription)
|
||||
}
|
||||
}
|
||||
get {
|
||||
call.respondText { "hey dude ‼️ congrats on the get request" }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun Routing.notarizedPost() {
|
||||
route(defaultPath) {
|
||||
install(NotarizedRoute()) {
|
||||
@ -299,3 +333,19 @@ fun Routing.overrideMediaTypes() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun Routing.postNoReqBody() {
|
||||
route("/no_req_body") {
|
||||
install(NotarizedRoute()) {
|
||||
post = PostInfo.builder {
|
||||
summary(defaultPathSummary)
|
||||
description(defaultPathDescription)
|
||||
response {
|
||||
responseType<TestResponse>()
|
||||
description("Cool response")
|
||||
responseCode(HttpStatusCode.Created)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -14,6 +14,7 @@ import io.ktor.http.HttpStatusCode
|
||||
import io.ktor.server.application.install
|
||||
import io.ktor.server.routing.Routing
|
||||
import io.ktor.server.routing.route
|
||||
import io.ktor.server.routing.param
|
||||
|
||||
fun Routing.simplePathParsing() {
|
||||
route("/this") {
|
||||
@ -100,3 +101,32 @@ fun Routing.trailingSlash() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun Routing.paramWrapper() {
|
||||
route("/test") {
|
||||
param("a") {
|
||||
param("b") {
|
||||
param("c") {
|
||||
install(NotarizedRoute()) {
|
||||
parameters = listOf(
|
||||
Parameter(
|
||||
name = "test",
|
||||
`in` = Parameter.Location.query,
|
||||
schema = TypeDefinition.STRING
|
||||
)
|
||||
)
|
||||
get = GetInfo.builder {
|
||||
summary(defaultPathSummary)
|
||||
description(defaultPathDescription)
|
||||
response {
|
||||
description(defaultResponseDescription)
|
||||
responseCode(HttpStatusCode.OK)
|
||||
responseType<TestResponse>()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
92
core/src/test/resources/T0054__app_with_rootpath.json
Normal file
92
core/src/test/resources/T0054__app_with_rootpath.json
Normal file
@ -0,0 +1,92 @@
|
||||
{
|
||||
"openapi": "3.1.0",
|
||||
"jsonSchemaDialect": "https://json-schema.org/draft/2020-12/schema",
|
||||
"info": {
|
||||
"title": "Test API",
|
||||
"version": "1.33.7",
|
||||
"description": "An amazing, fully-ish 😉 generated API spec",
|
||||
"termsOfService": "https://example.com",
|
||||
"contact": {
|
||||
"name": "Homer Simpson",
|
||||
"url": "https://gph.is/1NPUDiM",
|
||||
"email": "chunkylover53@aol.com"
|
||||
},
|
||||
"license": {
|
||||
"name": "MIT",
|
||||
"url": "https://github.com/bkbnio/kompendium/blob/main/LICENSE"
|
||||
}
|
||||
},
|
||||
"servers": [
|
||||
{
|
||||
"url": "https://myawesomeapi.com/example",
|
||||
"description": "Production instance of my API"
|
||||
},
|
||||
{
|
||||
"url": "https://staging.myawesomeapi.com/example",
|
||||
"description": "Where the fun stuff happens"
|
||||
}
|
||||
],
|
||||
"paths": {
|
||||
"/test/{a}": {
|
||||
"get": {
|
||||
"tags": [],
|
||||
"summary": "Great Summary!",
|
||||
"description": "testing more",
|
||||
"parameters": [],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "A Successful Endeavor",
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"$ref": "#/components/schemas/TestResponse"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"deprecated": false
|
||||
},
|
||||
"parameters": [
|
||||
{
|
||||
"name": "a",
|
||||
"in": "path",
|
||||
"schema": {
|
||||
"type": "string"
|
||||
},
|
||||
"required": true,
|
||||
"deprecated": false
|
||||
},
|
||||
{
|
||||
"name": "aa",
|
||||
"in": "query",
|
||||
"schema": {
|
||||
"type": "number",
|
||||
"format": "int32"
|
||||
},
|
||||
"required": true,
|
||||
"deprecated": false
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"webhooks": {},
|
||||
"components": {
|
||||
"schemas": {
|
||||
"TestResponse": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"c": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"c"
|
||||
]
|
||||
}
|
||||
},
|
||||
"securitySchemes": {}
|
||||
},
|
||||
"security": [],
|
||||
"tags": []
|
||||
}
|
126
core/src/test/resources/T0055__enriched_simple_request.json
Normal file
126
core/src/test/resources/T0055__enriched_simple_request.json
Normal file
@ -0,0 +1,126 @@
|
||||
{
|
||||
"openapi": "3.1.0",
|
||||
"jsonSchemaDialect": "https://json-schema.org/draft/2020-12/schema",
|
||||
"info": {
|
||||
"title": "Test API",
|
||||
"version": "1.33.7",
|
||||
"description": "An amazing, fully-ish 😉 generated API spec",
|
||||
"termsOfService": "https://example.com",
|
||||
"contact": {
|
||||
"name": "Homer Simpson",
|
||||
"url": "https://gph.is/1NPUDiM",
|
||||
"email": "chunkylover53@aol.com"
|
||||
},
|
||||
"license": {
|
||||
"name": "MIT",
|
||||
"url": "https://github.com/bkbnio/kompendium/blob/main/LICENSE"
|
||||
}
|
||||
},
|
||||
"servers": [
|
||||
{
|
||||
"url": "https://myawesomeapi.com",
|
||||
"description": "Production instance of my API"
|
||||
},
|
||||
{
|
||||
"url": "https://staging.myawesomeapi.com",
|
||||
"description": "Where the fun stuff happens"
|
||||
}
|
||||
],
|
||||
"paths": {
|
||||
"/example": {
|
||||
"post": {
|
||||
"tags": [],
|
||||
"summary": "Great Summary!",
|
||||
"description": "testing more",
|
||||
"parameters": [],
|
||||
"requestBody": {
|
||||
"description": "A test request",
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"$ref": "#/components/schemas/TestSimpleRequest-simple"
|
||||
}
|
||||
}
|
||||
},
|
||||
"required": true
|
||||
},
|
||||
"responses": {
|
||||
"201": {
|
||||
"description": "A Successful Endeavor",
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"$ref": "#/components/schemas/TestCreatedResponse"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"deprecated": false
|
||||
},
|
||||
"parameters": [
|
||||
{
|
||||
"name": "a",
|
||||
"in": "path",
|
||||
"schema": {
|
||||
"type": "string"
|
||||
},
|
||||
"required": true,
|
||||
"deprecated": false
|
||||
},
|
||||
{
|
||||
"name": "aa",
|
||||
"in": "query",
|
||||
"schema": {
|
||||
"type": "number",
|
||||
"format": "int32"
|
||||
},
|
||||
"required": true,
|
||||
"deprecated": false
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"webhooks": {},
|
||||
"components": {
|
||||
"schemas": {
|
||||
"TestCreatedResponse": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"c": {
|
||||
"type": "string"
|
||||
},
|
||||
"id": {
|
||||
"type": "number",
|
||||
"format": "int32"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"c",
|
||||
"id"
|
||||
]
|
||||
},
|
||||
"TestSimpleRequest-simple": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"a": {
|
||||
"type": "string",
|
||||
"description": "A simple description"
|
||||
},
|
||||
"b": {
|
||||
"type": "number",
|
||||
"format": "int32",
|
||||
"deprecated": true
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"a",
|
||||
"b"
|
||||
]
|
||||
}
|
||||
},
|
||||
"securitySchemes": {}
|
||||
},
|
||||
"security": [],
|
||||
"tags": []
|
||||
}
|
168
core/src/test/resources/T0056__enriched_nested_collection.json
Normal file
168
core/src/test/resources/T0056__enriched_nested_collection.json
Normal file
@ -0,0 +1,168 @@
|
||||
{
|
||||
"openapi": "3.1.0",
|
||||
"jsonSchemaDialect": "https://json-schema.org/draft/2020-12/schema",
|
||||
"info": {
|
||||
"title": "Test API",
|
||||
"version": "1.33.7",
|
||||
"description": "An amazing, fully-ish 😉 generated API spec",
|
||||
"termsOfService": "https://example.com",
|
||||
"contact": {
|
||||
"name": "Homer Simpson",
|
||||
"url": "https://gph.is/1NPUDiM",
|
||||
"email": "chunkylover53@aol.com"
|
||||
},
|
||||
"license": {
|
||||
"name": "MIT",
|
||||
"url": "https://github.com/bkbnio/kompendium/blob/main/LICENSE"
|
||||
}
|
||||
},
|
||||
"servers": [
|
||||
{
|
||||
"url": "https://myawesomeapi.com",
|
||||
"description": "Production instance of my API"
|
||||
},
|
||||
{
|
||||
"url": "https://staging.myawesomeapi.com",
|
||||
"description": "Where the fun stuff happens"
|
||||
}
|
||||
],
|
||||
"paths": {
|
||||
"/example": {
|
||||
"post": {
|
||||
"tags": [],
|
||||
"summary": "Great Summary!",
|
||||
"description": "testing more",
|
||||
"parameters": [],
|
||||
"requestBody": {
|
||||
"description": "A test request",
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"$ref": "#/components/schemas/ComplexRequest-simple"
|
||||
}
|
||||
}
|
||||
},
|
||||
"required": true
|
||||
},
|
||||
"responses": {
|
||||
"201": {
|
||||
"description": "A Successful Endeavor",
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"$ref": "#/components/schemas/TestCreatedResponse"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"deprecated": false
|
||||
},
|
||||
"parameters": [
|
||||
{
|
||||
"name": "a",
|
||||
"in": "path",
|
||||
"schema": {
|
||||
"type": "string"
|
||||
},
|
||||
"required": true,
|
||||
"deprecated": false
|
||||
},
|
||||
{
|
||||
"name": "aa",
|
||||
"in": "query",
|
||||
"schema": {
|
||||
"type": "number",
|
||||
"format": "int32"
|
||||
},
|
||||
"required": true,
|
||||
"deprecated": false
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"webhooks": {},
|
||||
"components": {
|
||||
"schemas": {
|
||||
"TestCreatedResponse": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"c": {
|
||||
"type": "string"
|
||||
},
|
||||
"id": {
|
||||
"type": "number",
|
||||
"format": "int32"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"c",
|
||||
"id"
|
||||
]
|
||||
},
|
||||
"ComplexRequest-simple": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"amazingField": {
|
||||
"type": "string"
|
||||
},
|
||||
"org": {
|
||||
"type": "string"
|
||||
},
|
||||
"tables": {
|
||||
"items": {
|
||||
"$ref": "#/components/schemas/NestedComplexItem-nested"
|
||||
},
|
||||
"description": "A nested item",
|
||||
"type": "array"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"amazingField",
|
||||
"org",
|
||||
"tables"
|
||||
]
|
||||
},
|
||||
"NestedComplexItem-nested": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"alias": {
|
||||
"additionalProperties": {
|
||||
"$ref": "#/components/schemas/CrazyItem"
|
||||
},
|
||||
"type": "object"
|
||||
},
|
||||
"name": {
|
||||
"type": "string",
|
||||
"description": "A nested description"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"alias",
|
||||
"name"
|
||||
]
|
||||
},
|
||||
"CrazyItem": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"enumeration": {
|
||||
"$ref": "#/components/schemas/SimpleEnum"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"enumeration"
|
||||
]
|
||||
},
|
||||
"SimpleEnum": {
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"ONE",
|
||||
"TWO"
|
||||
]
|
||||
}
|
||||
},
|
||||
"securitySchemes": {}
|
||||
},
|
||||
"security": [],
|
||||
"tags": []
|
||||
}
|
@ -0,0 +1,183 @@
|
||||
{
|
||||
"openapi": "3.1.0",
|
||||
"jsonSchemaDialect": "https://json-schema.org/draft/2020-12/schema",
|
||||
"info": {
|
||||
"title": "Test API",
|
||||
"version": "1.33.7",
|
||||
"description": "An amazing, fully-ish 😉 generated API spec",
|
||||
"termsOfService": "https://example.com",
|
||||
"contact": {
|
||||
"name": "Homer Simpson",
|
||||
"url": "https://gph.is/1NPUDiM",
|
||||
"email": "chunkylover53@aol.com"
|
||||
},
|
||||
"license": {
|
||||
"name": "MIT",
|
||||
"url": "https://github.com/bkbnio/kompendium/blob/main/LICENSE"
|
||||
}
|
||||
},
|
||||
"servers": [
|
||||
{
|
||||
"url": "https://myawesomeapi.com",
|
||||
"description": "Production instance of my API"
|
||||
},
|
||||
{
|
||||
"url": "https://staging.myawesomeapi.com",
|
||||
"description": "Where the fun stuff happens"
|
||||
}
|
||||
],
|
||||
"paths": {
|
||||
"/example": {
|
||||
"post": {
|
||||
"tags": [],
|
||||
"summary": "Great Summary!",
|
||||
"description": "testing more",
|
||||
"parameters": [],
|
||||
"requestBody": {
|
||||
"description": "A test request",
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"$ref": "#/components/schemas/MultiNestedGenerics-String-ComplexRequest-simple"
|
||||
}
|
||||
}
|
||||
},
|
||||
"required": true
|
||||
},
|
||||
"responses": {
|
||||
"201": {
|
||||
"description": "A Successful Endeavor",
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"$ref": "#/components/schemas/TestCreatedResponse"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"deprecated": false
|
||||
},
|
||||
"parameters": [
|
||||
{
|
||||
"name": "a",
|
||||
"in": "path",
|
||||
"schema": {
|
||||
"type": "string"
|
||||
},
|
||||
"required": true,
|
||||
"deprecated": false
|
||||
},
|
||||
{
|
||||
"name": "aa",
|
||||
"in": "query",
|
||||
"schema": {
|
||||
"type": "number",
|
||||
"format": "int32"
|
||||
},
|
||||
"required": true,
|
||||
"deprecated": false
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"webhooks": {},
|
||||
"components": {
|
||||
"schemas": {
|
||||
"TestCreatedResponse": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"c": {
|
||||
"type": "string"
|
||||
},
|
||||
"id": {
|
||||
"type": "number",
|
||||
"format": "int32"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"c",
|
||||
"id"
|
||||
]
|
||||
},
|
||||
"MultiNestedGenerics-String-ComplexRequest-simple": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"content": {
|
||||
"additionalProperties": {
|
||||
"$ref": "#/components/schemas/ComplexRequest-nested"
|
||||
},
|
||||
"description": "Getting pretty crazy",
|
||||
"type": "object"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"content"
|
||||
]
|
||||
},
|
||||
"ComplexRequest-nested": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"amazingField": {
|
||||
"type": "string"
|
||||
},
|
||||
"org": {
|
||||
"type": "string"
|
||||
},
|
||||
"tables": {
|
||||
"items": {
|
||||
"$ref": "#/components/schemas/NestedComplexItem-nested"
|
||||
},
|
||||
"description": "A nested item",
|
||||
"type": "array"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"amazingField",
|
||||
"org",
|
||||
"tables"
|
||||
]
|
||||
},
|
||||
"NestedComplexItem-nested": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"alias": {
|
||||
"additionalProperties": {
|
||||
"$ref": "#/components/schemas/CrazyItem"
|
||||
},
|
||||
"type": "object"
|
||||
},
|
||||
"name": {
|
||||
"type": "string",
|
||||
"description": "A nested description"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"alias",
|
||||
"name"
|
||||
]
|
||||
},
|
||||
"CrazyItem": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"enumeration": {
|
||||
"$ref": "#/components/schemas/SimpleEnum"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"enumeration"
|
||||
]
|
||||
},
|
||||
"SimpleEnum": {
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"ONE",
|
||||
"TWO"
|
||||
]
|
||||
}
|
||||
},
|
||||
"securitySchemes": {}
|
||||
},
|
||||
"security": [],
|
||||
"tags": []
|
||||
}
|
73
core/src/test/resources/T0058__enriched_simple_response.json
Normal file
73
core/src/test/resources/T0058__enriched_simple_response.json
Normal file
@ -0,0 +1,73 @@
|
||||
{
|
||||
"openapi": "3.1.0",
|
||||
"jsonSchemaDialect": "https://json-schema.org/draft/2020-12/schema",
|
||||
"info": {
|
||||
"title": "Test API",
|
||||
"version": "1.33.7",
|
||||
"description": "An amazing, fully-ish 😉 generated API spec",
|
||||
"termsOfService": "https://example.com",
|
||||
"contact": {
|
||||
"name": "Homer Simpson",
|
||||
"url": "https://gph.is/1NPUDiM",
|
||||
"email": "chunkylover53@aol.com"
|
||||
},
|
||||
"license": {
|
||||
"name": "MIT",
|
||||
"url": "https://github.com/bkbnio/kompendium/blob/main/LICENSE"
|
||||
}
|
||||
},
|
||||
"servers": [
|
||||
{
|
||||
"url": "https://myawesomeapi.com",
|
||||
"description": "Production instance of my API"
|
||||
},
|
||||
{
|
||||
"url": "https://staging.myawesomeapi.com",
|
||||
"description": "Where the fun stuff happens"
|
||||
}
|
||||
],
|
||||
"paths": {
|
||||
"/enriched": {
|
||||
"get": {
|
||||
"tags": [],
|
||||
"summary": "Great Summary!",
|
||||
"description": "testing more",
|
||||
"parameters": [],
|
||||
"responses": {
|
||||
"201": {
|
||||
"description": "A good response",
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"$ref": "#/components/schemas/TestResponse-simple"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"deprecated": false
|
||||
},
|
||||
"parameters": []
|
||||
}
|
||||
},
|
||||
"webhooks": {},
|
||||
"components": {
|
||||
"schemas": {
|
||||
"TestResponse-simple": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"c": {
|
||||
"type": "string",
|
||||
"description": "A simple description"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"c"
|
||||
]
|
||||
}
|
||||
},
|
||||
"securitySchemes": {}
|
||||
},
|
||||
"security": [],
|
||||
"tags": []
|
||||
}
|
80
core/src/test/resources/T0059__int_constraints.json
Normal file
80
core/src/test/resources/T0059__int_constraints.json
Normal file
@ -0,0 +1,80 @@
|
||||
{
|
||||
"openapi": "3.1.0",
|
||||
"jsonSchemaDialect": "https://json-schema.org/draft/2020-12/schema",
|
||||
"info": {
|
||||
"title": "Test API",
|
||||
"version": "1.33.7",
|
||||
"description": "An amazing, fully-ish 😉 generated API spec",
|
||||
"termsOfService": "https://example.com",
|
||||
"contact": {
|
||||
"name": "Homer Simpson",
|
||||
"url": "https://gph.is/1NPUDiM",
|
||||
"email": "chunkylover53@aol.com"
|
||||
},
|
||||
"license": {
|
||||
"name": "MIT",
|
||||
"url": "https://github.com/bkbnio/kompendium/blob/main/LICENSE"
|
||||
}
|
||||
},
|
||||
"servers": [
|
||||
{
|
||||
"url": "https://myawesomeapi.com",
|
||||
"description": "Production instance of my API"
|
||||
},
|
||||
{
|
||||
"url": "https://staging.myawesomeapi.com",
|
||||
"description": "Where the fun stuff happens"
|
||||
}
|
||||
],
|
||||
"paths": {
|
||||
"/test/{a}": {
|
||||
"get": {
|
||||
"tags": [],
|
||||
"summary": "Get an int",
|
||||
"description": "Get an int",
|
||||
"parameters": [],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "An int",
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"$ref": "#/components/schemas/TestCreatedResponse-example"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"deprecated": false
|
||||
},
|
||||
"parameters": []
|
||||
}
|
||||
},
|
||||
"webhooks": {},
|
||||
"components": {
|
||||
"schemas": {
|
||||
"TestCreatedResponse-example": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"c": {
|
||||
"type": "string"
|
||||
},
|
||||
"id": {
|
||||
"type": "number",
|
||||
"format": "int32",
|
||||
"multipleOf": 2,
|
||||
"maximum": 100,
|
||||
"minimum": 2
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"c",
|
||||
"id"
|
||||
]
|
||||
}
|
||||
},
|
||||
"securitySchemes": {}
|
||||
},
|
||||
"security": [],
|
||||
"tags": []
|
||||
}
|
76
core/src/test/resources/T0060__double_constraints.json
Normal file
76
core/src/test/resources/T0060__double_constraints.json
Normal file
@ -0,0 +1,76 @@
|
||||
{
|
||||
"openapi": "3.1.0",
|
||||
"jsonSchemaDialect": "https://json-schema.org/draft/2020-12/schema",
|
||||
"info": {
|
||||
"title": "Test API",
|
||||
"version": "1.33.7",
|
||||
"description": "An amazing, fully-ish 😉 generated API spec",
|
||||
"termsOfService": "https://example.com",
|
||||
"contact": {
|
||||
"name": "Homer Simpson",
|
||||
"url": "https://gph.is/1NPUDiM",
|
||||
"email": "chunkylover53@aol.com"
|
||||
},
|
||||
"license": {
|
||||
"name": "MIT",
|
||||
"url": "https://github.com/bkbnio/kompendium/blob/main/LICENSE"
|
||||
}
|
||||
},
|
||||
"servers": [
|
||||
{
|
||||
"url": "https://myawesomeapi.com",
|
||||
"description": "Production instance of my API"
|
||||
},
|
||||
{
|
||||
"url": "https://staging.myawesomeapi.com",
|
||||
"description": "Where the fun stuff happens"
|
||||
}
|
||||
],
|
||||
"paths": {
|
||||
"/test/{a}": {
|
||||
"get": {
|
||||
"tags": [],
|
||||
"summary": "Get a double",
|
||||
"description": "Get a double",
|
||||
"parameters": [],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "A double",
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"$ref": "#/components/schemas/DoubleResponse-example"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"deprecated": false
|
||||
},
|
||||
"parameters": []
|
||||
}
|
||||
},
|
||||
"webhooks": {},
|
||||
"components": {
|
||||
"schemas": {
|
||||
"DoubleResponse-example": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"payload": {
|
||||
"type": "number",
|
||||
"format": "double",
|
||||
"multipleOf": 2.0,
|
||||
"maximum": 100.0,
|
||||
"minimum": 2.0
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"payload"
|
||||
]
|
||||
}
|
||||
},
|
||||
"securitySchemes": {}
|
||||
},
|
||||
"security": [],
|
||||
"tags": []
|
||||
}
|
@ -0,0 +1,74 @@
|
||||
{
|
||||
"openapi": "3.1.0",
|
||||
"jsonSchemaDialect": "https://json-schema.org/draft/2020-12/schema",
|
||||
"info": {
|
||||
"title": "Test API",
|
||||
"version": "1.33.7",
|
||||
"description": "An amazing, fully-ish 😉 generated API spec",
|
||||
"termsOfService": "https://example.com",
|
||||
"contact": {
|
||||
"name": "Homer Simpson",
|
||||
"url": "https://gph.is/1NPUDiM",
|
||||
"email": "chunkylover53@aol.com"
|
||||
},
|
||||
"license": {
|
||||
"name": "MIT",
|
||||
"url": "https://github.com/bkbnio/kompendium/blob/main/LICENSE"
|
||||
}
|
||||
},
|
||||
"servers": [
|
||||
{
|
||||
"url": "https://myawesomeapi.com",
|
||||
"description": "Production instance of my API"
|
||||
},
|
||||
{
|
||||
"url": "https://staging.myawesomeapi.com",
|
||||
"description": "Where the fun stuff happens"
|
||||
}
|
||||
],
|
||||
"paths": {
|
||||
"/test/{a}": {
|
||||
"get": {
|
||||
"tags": [],
|
||||
"summary": "Get a string",
|
||||
"description": "Get a string with constraints",
|
||||
"parameters": [],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "A string",
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"$ref": "#/components/schemas/TestNested-example"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"deprecated": false
|
||||
},
|
||||
"parameters": []
|
||||
}
|
||||
},
|
||||
"webhooks": {},
|
||||
"components": {
|
||||
"schemas": {
|
||||
"TestNested-example": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"nesty": {
|
||||
"type": "string",
|
||||
"maxLength": 10,
|
||||
"minLength": 2
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"nesty"
|
||||
]
|
||||
}
|
||||
},
|
||||
"securitySchemes": {}
|
||||
},
|
||||
"security": [],
|
||||
"tags": []
|
||||
}
|
@ -0,0 +1,73 @@
|
||||
{
|
||||
"openapi": "3.1.0",
|
||||
"jsonSchemaDialect": "https://json-schema.org/draft/2020-12/schema",
|
||||
"info": {
|
||||
"title": "Test API",
|
||||
"version": "1.33.7",
|
||||
"description": "An amazing, fully-ish 😉 generated API spec",
|
||||
"termsOfService": "https://example.com",
|
||||
"contact": {
|
||||
"name": "Homer Simpson",
|
||||
"url": "https://gph.is/1NPUDiM",
|
||||
"email": "chunkylover53@aol.com"
|
||||
},
|
||||
"license": {
|
||||
"name": "MIT",
|
||||
"url": "https://github.com/bkbnio/kompendium/blob/main/LICENSE"
|
||||
}
|
||||
},
|
||||
"servers": [
|
||||
{
|
||||
"url": "https://myawesomeapi.com",
|
||||
"description": "Production instance of my API"
|
||||
},
|
||||
{
|
||||
"url": "https://staging.myawesomeapi.com",
|
||||
"description": "Where the fun stuff happens"
|
||||
}
|
||||
],
|
||||
"paths": {
|
||||
"/test/{a}": {
|
||||
"get": {
|
||||
"tags": [],
|
||||
"summary": "Get a string",
|
||||
"description": "This is a description",
|
||||
"parameters": [],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "A string",
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"$ref": "#/components/schemas/TestNested-example"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"deprecated": false
|
||||
},
|
||||
"parameters": []
|
||||
}
|
||||
},
|
||||
"webhooks": {},
|
||||
"components": {
|
||||
"schemas": {
|
||||
"TestNested-example": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"nesty": {
|
||||
"type": "string",
|
||||
"pattern": "[a-z]+"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"nesty"
|
||||
]
|
||||
}
|
||||
},
|
||||
"securitySchemes": {}
|
||||
},
|
||||
"security": [],
|
||||
"tags": []
|
||||
}
|
@ -0,0 +1,74 @@
|
||||
{
|
||||
"openapi": "3.1.0",
|
||||
"jsonSchemaDialect": "https://json-schema.org/draft/2020-12/schema",
|
||||
"info": {
|
||||
"title": "Test API",
|
||||
"version": "1.33.7",
|
||||
"description": "An amazing, fully-ish 😉 generated API spec",
|
||||
"termsOfService": "https://example.com",
|
||||
"contact": {
|
||||
"name": "Homer Simpson",
|
||||
"url": "https://gph.is/1NPUDiM",
|
||||
"email": "chunkylover53@aol.com"
|
||||
},
|
||||
"license": {
|
||||
"name": "MIT",
|
||||
"url": "https://github.com/bkbnio/kompendium/blob/main/LICENSE"
|
||||
}
|
||||
},
|
||||
"servers": [
|
||||
{
|
||||
"url": "https://myawesomeapi.com",
|
||||
"description": "Production instance of my API"
|
||||
},
|
||||
{
|
||||
"url": "https://staging.myawesomeapi.com",
|
||||
"description": "Where the fun stuff happens"
|
||||
}
|
||||
],
|
||||
"paths": {
|
||||
"/test/{a}": {
|
||||
"get": {
|
||||
"tags": [],
|
||||
"summary": "Get a string",
|
||||
"description": "This is a description",
|
||||
"parameters": [],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "A string",
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"$ref": "#/components/schemas/TestNested-example"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"deprecated": false
|
||||
},
|
||||
"parameters": []
|
||||
}
|
||||
},
|
||||
"webhooks": {},
|
||||
"components": {
|
||||
"schemas": {
|
||||
"TestNested-example": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"nesty": {
|
||||
"type": "string",
|
||||
"contentEncoding": "base64",
|
||||
"contentMediaType": "image/png"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"nesty"
|
||||
]
|
||||
}
|
||||
},
|
||||
"securitySchemes": {}
|
||||
},
|
||||
"security": [],
|
||||
"tags": []
|
||||
}
|
103
core/src/test/resources/T0064__array_constraints.json
Normal file
103
core/src/test/resources/T0064__array_constraints.json
Normal file
@ -0,0 +1,103 @@
|
||||
{
|
||||
"openapi": "3.1.0",
|
||||
"jsonSchemaDialect": "https://json-schema.org/draft/2020-12/schema",
|
||||
"info": {
|
||||
"title": "Test API",
|
||||
"version": "1.33.7",
|
||||
"description": "An amazing, fully-ish 😉 generated API spec",
|
||||
"termsOfService": "https://example.com",
|
||||
"contact": {
|
||||
"name": "Homer Simpson",
|
||||
"url": "https://gph.is/1NPUDiM",
|
||||
"email": "chunkylover53@aol.com"
|
||||
},
|
||||
"license": {
|
||||
"name": "MIT",
|
||||
"url": "https://github.com/bkbnio/kompendium/blob/main/LICENSE"
|
||||
}
|
||||
},
|
||||
"servers": [
|
||||
{
|
||||
"url": "https://myawesomeapi.com",
|
||||
"description": "Production instance of my API"
|
||||
},
|
||||
{
|
||||
"url": "https://staging.myawesomeapi.com",
|
||||
"description": "Where the fun stuff happens"
|
||||
}
|
||||
],
|
||||
"paths": {
|
||||
"/test/{a}": {
|
||||
"get": {
|
||||
"tags": [],
|
||||
"summary": "Get an array",
|
||||
"description": "Get an array of strings",
|
||||
"parameters": [],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "An array",
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"$ref": "#/components/schemas/Page-String-example"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"deprecated": false
|
||||
},
|
||||
"parameters": []
|
||||
}
|
||||
},
|
||||
"webhooks": {},
|
||||
"components": {
|
||||
"schemas": {
|
||||
"Page-String-example": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"content": {
|
||||
"items": {
|
||||
"type": "string"
|
||||
},
|
||||
"maxItems": 10,
|
||||
"minItems": 2,
|
||||
"uniqueItems": true,
|
||||
"type": "array"
|
||||
},
|
||||
"number": {
|
||||
"type": "number",
|
||||
"format": "int32"
|
||||
},
|
||||
"numberOfElements": {
|
||||
"type": "number",
|
||||
"format": "int32"
|
||||
},
|
||||
"size": {
|
||||
"type": "number",
|
||||
"format": "int32"
|
||||
},
|
||||
"totalElements": {
|
||||
"type": "number",
|
||||
"format": "int64"
|
||||
},
|
||||
"totalPages": {
|
||||
"type": "number",
|
||||
"format": "int32"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"content",
|
||||
"number",
|
||||
"numberOfElements",
|
||||
"size",
|
||||
"totalElements",
|
||||
"totalPages"
|
||||
]
|
||||
}
|
||||
},
|
||||
"securitySchemes": {}
|
||||
},
|
||||
"security": [],
|
||||
"tags": []
|
||||
}
|
72
core/src/test/resources/T0065__post_no_req_body.json
Normal file
72
core/src/test/resources/T0065__post_no_req_body.json
Normal file
@ -0,0 +1,72 @@
|
||||
{
|
||||
"openapi": "3.1.0",
|
||||
"jsonSchemaDialect": "https://json-schema.org/draft/2020-12/schema",
|
||||
"info": {
|
||||
"title": "Test API",
|
||||
"version": "1.33.7",
|
||||
"description": "An amazing, fully-ish 😉 generated API spec",
|
||||
"termsOfService": "https://example.com",
|
||||
"contact": {
|
||||
"name": "Homer Simpson",
|
||||
"url": "https://gph.is/1NPUDiM",
|
||||
"email": "chunkylover53@aol.com"
|
||||
},
|
||||
"license": {
|
||||
"name": "MIT",
|
||||
"url": "https://github.com/bkbnio/kompendium/blob/main/LICENSE"
|
||||
}
|
||||
},
|
||||
"servers": [
|
||||
{
|
||||
"url": "https://myawesomeapi.com",
|
||||
"description": "Production instance of my API"
|
||||
},
|
||||
{
|
||||
"url": "https://staging.myawesomeapi.com",
|
||||
"description": "Where the fun stuff happens"
|
||||
}
|
||||
],
|
||||
"paths": {
|
||||
"/no_req_body": {
|
||||
"post": {
|
||||
"tags": [],
|
||||
"summary": "Great Summary!",
|
||||
"description": "testing more",
|
||||
"parameters": [],
|
||||
"responses": {
|
||||
"201": {
|
||||
"description": "Cool response",
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"$ref": "#/components/schemas/TestResponse"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"deprecated": false
|
||||
},
|
||||
"parameters": []
|
||||
}
|
||||
},
|
||||
"webhooks": {},
|
||||
"components": {
|
||||
"schemas": {
|
||||
"TestResponse": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"c": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"c"
|
||||
]
|
||||
}
|
||||
},
|
||||
"securitySchemes": {}
|
||||
},
|
||||
"security": [],
|
||||
"tags": []
|
||||
}
|
@ -0,0 +1,110 @@
|
||||
{
|
||||
"openapi": "3.1.0",
|
||||
"jsonSchemaDialect": "https://json-schema.org/draft/2020-12/schema",
|
||||
"info": {
|
||||
"title": "Test API",
|
||||
"version": "1.33.7",
|
||||
"description": "An amazing, fully-ish 😉 generated API spec",
|
||||
"termsOfService": "https://example.com",
|
||||
"contact": {
|
||||
"name": "Homer Simpson",
|
||||
"url": "https://gph.is/1NPUDiM",
|
||||
"email": "chunkylover53@aol.com"
|
||||
},
|
||||
"license": {
|
||||
"name": "MIT",
|
||||
"url": "https://github.com/bkbnio/kompendium/blob/main/LICENSE"
|
||||
}
|
||||
},
|
||||
"servers": [
|
||||
{
|
||||
"url": "https://myawesomeapi.com",
|
||||
"description": "Production instance of my API"
|
||||
},
|
||||
{
|
||||
"url": "https://staging.myawesomeapi.com",
|
||||
"description": "Where the fun stuff happens"
|
||||
}
|
||||
],
|
||||
"paths": {
|
||||
"/test/{a}": {
|
||||
"get": {
|
||||
"tags": [],
|
||||
"summary": "Great Summary!",
|
||||
"description": "testing more",
|
||||
"parameters": [],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "A Successful Endeavor",
|
||||
"headers": {
|
||||
"ETag": {
|
||||
"schema": {
|
||||
"type": "string"
|
||||
},
|
||||
"description": "https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/ETag",
|
||||
"required": true,
|
||||
"deprecated": false
|
||||
},
|
||||
"Last-Modified": {
|
||||
"schema": {
|
||||
"type": "string"
|
||||
},
|
||||
"description": "https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Last-Modified",
|
||||
"required": true,
|
||||
"deprecated": false
|
||||
}
|
||||
},
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"$ref": "#/components/schemas/TestResponse"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"deprecated": false
|
||||
},
|
||||
"parameters": [
|
||||
{
|
||||
"name": "a",
|
||||
"in": "path",
|
||||
"schema": {
|
||||
"type": "string"
|
||||
},
|
||||
"required": true,
|
||||
"deprecated": false
|
||||
},
|
||||
{
|
||||
"name": "aa",
|
||||
"in": "query",
|
||||
"schema": {
|
||||
"type": "number",
|
||||
"format": "int32"
|
||||
},
|
||||
"required": true,
|
||||
"deprecated": false
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"webhooks": {},
|
||||
"components": {
|
||||
"schemas": {
|
||||
"TestResponse": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"c": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"c"
|
||||
]
|
||||
}
|
||||
},
|
||||
"securitySchemes": {}
|
||||
},
|
||||
"security": [],
|
||||
"tags": []
|
||||
}
|
91
core/src/test/resources/T0067__enriched_generic_object.json
Normal file
91
core/src/test/resources/T0067__enriched_generic_object.json
Normal file
@ -0,0 +1,91 @@
|
||||
{
|
||||
"openapi": "3.1.0",
|
||||
"jsonSchemaDialect": "https://json-schema.org/draft/2020-12/schema",
|
||||
"info": {
|
||||
"title": "Test API",
|
||||
"version": "1.33.7",
|
||||
"description": "An amazing, fully-ish 😉 generated API spec",
|
||||
"termsOfService": "https://example.com",
|
||||
"contact": {
|
||||
"name": "Homer Simpson",
|
||||
"url": "https://gph.is/1NPUDiM",
|
||||
"email": "chunkylover53@aol.com"
|
||||
},
|
||||
"license": {
|
||||
"name": "MIT",
|
||||
"url": "https://github.com/bkbnio/kompendium/blob/main/LICENSE"
|
||||
}
|
||||
},
|
||||
"servers": [
|
||||
{
|
||||
"url": "https://myawesomeapi.com",
|
||||
"description": "Production instance of my API"
|
||||
},
|
||||
{
|
||||
"url": "https://staging.myawesomeapi.com",
|
||||
"description": "Where the fun stuff happens"
|
||||
}
|
||||
],
|
||||
"paths": {
|
||||
"/example": {
|
||||
"get": {
|
||||
"tags": [],
|
||||
"summary": "Great Summary!",
|
||||
"description": "testing more",
|
||||
"parameters": [],
|
||||
"responses": {
|
||||
"201": {
|
||||
"description": "A good response",
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"$ref": "#/components/schemas/GenericObject-TestSimpleRequest-generic"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"deprecated": false
|
||||
},
|
||||
"parameters": []
|
||||
}
|
||||
},
|
||||
"webhooks": {},
|
||||
"components": {
|
||||
"schemas": {
|
||||
"GenericObject-TestSimpleRequest-generic": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"data": {
|
||||
"$ref": "#/components/schemas/TestSimpleRequest-simple",
|
||||
"description": "A simple description"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"data"
|
||||
]
|
||||
},
|
||||
"TestSimpleRequest-simple": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"a": {
|
||||
"type": "string",
|
||||
"description": "A simple description"
|
||||
},
|
||||
"b": {
|
||||
"type": "number",
|
||||
"format": "int32",
|
||||
"deprecated": true
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"a",
|
||||
"b"
|
||||
]
|
||||
}
|
||||
},
|
||||
"securitySchemes": {}
|
||||
},
|
||||
"security": [],
|
||||
"tags": []
|
||||
}
|
82
core/src/test/resources/T0068__param_wrapper.json
Normal file
82
core/src/test/resources/T0068__param_wrapper.json
Normal file
@ -0,0 +1,82 @@
|
||||
{
|
||||
"openapi": "3.1.0",
|
||||
"jsonSchemaDialect": "https://json-schema.org/draft/2020-12/schema",
|
||||
"info": {
|
||||
"title": "Test API",
|
||||
"version": "1.33.7",
|
||||
"description": "An amazing, fully-ish 😉 generated API spec",
|
||||
"termsOfService": "https://example.com",
|
||||
"contact": {
|
||||
"name": "Homer Simpson",
|
||||
"url": "https://gph.is/1NPUDiM",
|
||||
"email": "chunkylover53@aol.com"
|
||||
},
|
||||
"license": {
|
||||
"name": "MIT",
|
||||
"url": "https://github.com/bkbnio/kompendium/blob/main/LICENSE"
|
||||
}
|
||||
},
|
||||
"servers": [
|
||||
{
|
||||
"url": "https://myawesomeapi.com",
|
||||
"description": "Production instance of my API"
|
||||
},
|
||||
{
|
||||
"url": "https://staging.myawesomeapi.com",
|
||||
"description": "Where the fun stuff happens"
|
||||
}
|
||||
],
|
||||
"paths": {
|
||||
"/test": {
|
||||
"get": {
|
||||
"tags": [],
|
||||
"summary": "Great Summary!",
|
||||
"description": "testing more",
|
||||
"parameters": [],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "A Successful Endeavor",
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"$ref": "#/components/schemas/TestResponse"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"deprecated": false
|
||||
},
|
||||
"parameters": [
|
||||
{
|
||||
"name": "test",
|
||||
"in": "query",
|
||||
"schema": {
|
||||
"type": "string"
|
||||
},
|
||||
"required": true,
|
||||
"deprecated": false
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"webhooks": {},
|
||||
"components": {
|
||||
"schemas": {
|
||||
"TestResponse": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"c": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"c"
|
||||
]
|
||||
}
|
||||
},
|
||||
"securitySchemes": {}
|
||||
},
|
||||
"security": [],
|
||||
"tags": []
|
||||
}
|
136
core/src/test/resources/T0069__example_optional_req.json
Normal file
136
core/src/test/resources/T0069__example_optional_req.json
Normal file
@ -0,0 +1,136 @@
|
||||
{
|
||||
"openapi": "3.1.0",
|
||||
"jsonSchemaDialect": "https://json-schema.org/draft/2020-12/schema",
|
||||
"info": {
|
||||
"title": "Test API",
|
||||
"version": "1.33.7",
|
||||
"description": "An amazing, fully-ish 😉 generated API spec",
|
||||
"termsOfService": "https://example.com",
|
||||
"contact": {
|
||||
"name": "Homer Simpson",
|
||||
"url": "https://gph.is/1NPUDiM",
|
||||
"email": "chunkylover53@aol.com"
|
||||
},
|
||||
"license": {
|
||||
"name": "MIT",
|
||||
"url": "https://github.com/bkbnio/kompendium/blob/main/LICENSE"
|
||||
}
|
||||
},
|
||||
"servers": [
|
||||
{
|
||||
"url": "https://myawesomeapi.com",
|
||||
"description": "Production instance of my API"
|
||||
},
|
||||
{
|
||||
"url": "https://staging.myawesomeapi.com",
|
||||
"description": "Where the fun stuff happens"
|
||||
}
|
||||
],
|
||||
"paths": {
|
||||
"/": {
|
||||
"post": {
|
||||
"tags": [],
|
||||
"summary": "Great Summary!",
|
||||
"description": "testing more",
|
||||
"parameters": [],
|
||||
"requestBody": {
|
||||
"description": "You gotta send it",
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"$ref": "#/components/schemas/TestRequest"
|
||||
},
|
||||
"examples": {
|
||||
"Testerina": {
|
||||
"value": {
|
||||
"fieldName": {
|
||||
"nesty": "asdf"
|
||||
},
|
||||
"b": 1.5,
|
||||
"aaa": []
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"required": false
|
||||
},
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "A Successful Endeavor",
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"$ref": "#/components/schemas/TestResponse"
|
||||
},
|
||||
"examples": {
|
||||
"Testerino": {
|
||||
"value": {
|
||||
"c": "Heya"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"deprecated": false
|
||||
},
|
||||
"parameters": []
|
||||
}
|
||||
},
|
||||
"webhooks": {},
|
||||
"components": {
|
||||
"schemas": {
|
||||
"TestResponse": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"c": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"c"
|
||||
]
|
||||
},
|
||||
"TestRequest": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"aaa": {
|
||||
"items": {
|
||||
"type": "number",
|
||||
"format": "int64"
|
||||
},
|
||||
"type": "array"
|
||||
},
|
||||
"b": {
|
||||
"type": "number",
|
||||
"format": "double"
|
||||
},
|
||||
"fieldName": {
|
||||
"$ref": "#/components/schemas/TestNested"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"aaa",
|
||||
"b",
|
||||
"fieldName"
|
||||
]
|
||||
},
|
||||
"TestNested": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"nesty": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"nesty"
|
||||
]
|
||||
}
|
||||
},
|
||||
"securitySchemes": {}
|
||||
},
|
||||
"security": [],
|
||||
"tags": []
|
||||
}
|
@ -5,6 +5,7 @@ import com.fasterxml.jackson.databind.SerializationFeature
|
||||
import io.bkbn.kompendium.core.fixtures.TestSpecs.defaultSpec
|
||||
import io.bkbn.kompendium.core.plugin.NotarizedApplication
|
||||
import io.bkbn.kompendium.core.routes.redoc
|
||||
import io.bkbn.kompendium.core.routes.swagger
|
||||
import io.bkbn.kompendium.json.schema.KotlinXSchemaConfigurator
|
||||
import io.bkbn.kompendium.json.schema.definition.JsonSchema
|
||||
import io.bkbn.kompendium.oas.OpenApiSpec
|
||||
@ -21,13 +22,14 @@ import io.ktor.serialization.gson.gson
|
||||
import io.ktor.serialization.jackson.jackson
|
||||
import io.ktor.serialization.kotlinx.json.json
|
||||
import io.ktor.server.application.Application
|
||||
import io.ktor.server.engine.ApplicationEngineEnvironmentBuilder
|
||||
import io.ktor.server.plugins.contentnegotiation.ContentNegotiation
|
||||
import io.ktor.server.routing.Routing
|
||||
import io.ktor.server.testing.ApplicationTestBuilder
|
||||
import io.ktor.server.testing.testApplication
|
||||
import kotlin.reflect.KType
|
||||
import kotlinx.serialization.json.Json
|
||||
import java.io.File
|
||||
import kotlinx.serialization.json.Json
|
||||
import kotlin.reflect.KType
|
||||
|
||||
object TestHelpers {
|
||||
private const val OPEN_API_ENDPOINT = "/openapi.json"
|
||||
@ -43,8 +45,8 @@ object TestHelpers {
|
||||
* exists as expected, and that the content matches the expected blob found in the specified file
|
||||
* @param snapshotName The snapshot file to retrieve from the resources folder
|
||||
*/
|
||||
private suspend fun ApplicationTestBuilder.compareOpenAPISpec(snapshotName: String) {
|
||||
val response = client.get(OPEN_API_ENDPOINT)
|
||||
private suspend fun ApplicationTestBuilder.compareOpenAPISpec(rootPath: String, snapshotName: String) {
|
||||
val response = client.get("$rootPath$OPEN_API_ENDPOINT")
|
||||
response shouldHaveStatus HttpStatusCode.OK
|
||||
response.bodyAsText() shouldNot beBlank()
|
||||
response.bodyAsText() shouldEqualJson getFileSnapshot(snapshotName)
|
||||
@ -61,11 +63,36 @@ object TestHelpers {
|
||||
customTypes: Map<KType, JsonSchema> = emptyMap(),
|
||||
applicationSetup: Application.() -> Unit = { },
|
||||
specOverrides: OpenApiSpec.() -> OpenApiSpec = { this },
|
||||
applicationEnvironmentBuilder: ApplicationEngineEnvironmentBuilder.() -> Unit = {},
|
||||
routeUnderTest: Routing.() -> Unit
|
||||
) {
|
||||
openApiTest(snapshotName, SupportedSerializer.KOTLINX, routeUnderTest, applicationSetup, specOverrides, customTypes)
|
||||
openApiTest(snapshotName, SupportedSerializer.JACKSON, routeUnderTest, applicationSetup, specOverrides, customTypes)
|
||||
openApiTest(snapshotName, SupportedSerializer.GSON, routeUnderTest, applicationSetup, specOverrides, customTypes)
|
||||
openApiTest(
|
||||
snapshotName,
|
||||
SupportedSerializer.KOTLINX,
|
||||
routeUnderTest,
|
||||
applicationSetup,
|
||||
specOverrides,
|
||||
customTypes,
|
||||
applicationEnvironmentBuilder
|
||||
)
|
||||
openApiTest(
|
||||
snapshotName,
|
||||
SupportedSerializer.JACKSON,
|
||||
routeUnderTest,
|
||||
applicationSetup,
|
||||
specOverrides,
|
||||
customTypes,
|
||||
applicationEnvironmentBuilder
|
||||
)
|
||||
openApiTest(
|
||||
snapshotName,
|
||||
SupportedSerializer.GSON,
|
||||
routeUnderTest,
|
||||
applicationSetup,
|
||||
specOverrides,
|
||||
customTypes,
|
||||
applicationEnvironmentBuilder
|
||||
)
|
||||
}
|
||||
|
||||
private fun openApiTest(
|
||||
@ -74,8 +101,10 @@ object TestHelpers {
|
||||
routeUnderTest: Routing.() -> Unit,
|
||||
applicationSetup: Application.() -> Unit,
|
||||
specOverrides: OpenApiSpec.() -> OpenApiSpec,
|
||||
typeOverrides: Map<KType, JsonSchema> = emptyMap()
|
||||
typeOverrides: Map<KType, JsonSchema> = emptyMap(),
|
||||
applicationBuilder: ApplicationEngineEnvironmentBuilder.() -> Unit = {}
|
||||
) = testApplication {
|
||||
environment(applicationBuilder)
|
||||
install(NotarizedApplication()) {
|
||||
customTypes = typeOverrides
|
||||
spec = defaultSpec().specOverrides()
|
||||
@ -102,9 +131,11 @@ object TestHelpers {
|
||||
}
|
||||
application(applicationSetup)
|
||||
routing {
|
||||
swagger()
|
||||
redoc()
|
||||
routeUnderTest()
|
||||
}
|
||||
compareOpenAPISpec(snapshotName)
|
||||
val root = ApplicationEngineEnvironmentBuilder().apply(applicationBuilder).rootPath
|
||||
compareOpenAPISpec(root, snapshotName)
|
||||
}
|
||||
}
|
||||
|
@ -12,6 +12,9 @@ import java.time.Instant
|
||||
@Serializable
|
||||
data class TestNested(val nesty: String)
|
||||
|
||||
@Serializable
|
||||
data class DoubleResponse(val payload: Double)
|
||||
|
||||
@Serializable
|
||||
data class TestRequest(
|
||||
val fieldName: TestNested,
|
||||
@ -177,6 +180,10 @@ data class SerialNameObject(
|
||||
val camelCaseName: String
|
||||
)
|
||||
|
||||
data class GenericObject<T>(
|
||||
val data: T
|
||||
)
|
||||
|
||||
enum class Color {
|
||||
RED,
|
||||
GREEN,
|
||||
|
@ -22,6 +22,8 @@ formatting:
|
||||
indentSize: 2
|
||||
ImportOrdering:
|
||||
active: false
|
||||
EnumEntryNameCase:
|
||||
active: false
|
||||
naming:
|
||||
ConstructorParameterNaming:
|
||||
active: false
|
||||
|
@ -6,4 +6,8 @@
|
||||
* [Notarized Route](plugins/notarized_route.md)
|
||||
* [Notarized Locations](plugins/notarized_locations.md)
|
||||
* [Notarized Resources](plugins/notarized_resources.md)
|
||||
* [Concepts](concepts/index.md)
|
||||
* [Enrichment](concepts/enrichment.md)
|
||||
* [Helpers](helpers/index.md)
|
||||
* [Protobuf java converter](helpers/protobuf_java_converter.md)
|
||||
* [The Playground](playground.md)
|
||||
|
106
docs/concepts/enrichment.md
Normal file
106
docs/concepts/enrichment.md
Normal file
@ -0,0 +1,106 @@
|
||||
Kompendium allows users to enrich their data types with additional information. This can be done by defining a
|
||||
`TypeEnrichment` object and passing it to the `enrichment` parameter of the relevant `requestType` or `responseType`.
|
||||
|
||||
```kotlin
|
||||
data class SimpleData(val a: String, val b: Int? = null)
|
||||
|
||||
val myEnrichment = TypeEnrichment<SimpleData>(id = "simple-enrichment") {
|
||||
SimpleData::a {
|
||||
description = "This will update the field description"
|
||||
}
|
||||
SimpleData::b {
|
||||
// Will indicate in the UI that the field will be removed soon
|
||||
deprecated = true
|
||||
}
|
||||
}
|
||||
|
||||
// In your route documentation
|
||||
fun Routing.enrichedSimpleRequest() {
|
||||
route("/example") {
|
||||
install(NotarizedRoute()) {
|
||||
parameters = TestModules.defaultParams
|
||||
post = PostInfo.builder {
|
||||
summary(TestModules.defaultPathSummary)
|
||||
description(TestModules.defaultPathDescription)
|
||||
request {
|
||||
requestType<SimpleData>(enrichment = myEnrichment) // Simply attach the enrichment to the request
|
||||
description("A test request")
|
||||
}
|
||||
response {
|
||||
responseCode(HttpStatusCode.Created)
|
||||
responseType<TestCreatedResponse>()
|
||||
description(TestModules.defaultResponseDescription)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
{% hint style="warning" %}
|
||||
An enrichment must provide an `id` field that is unique to the data class that is being enriched. This is because
|
||||
under the hood, Kompendium appends this id to the data class identifier in order to support multiple different
|
||||
enrichments
|
||||
on the same data class.
|
||||
|
||||
If you provide duplicate ids, all but the first enrichment will be ignored, as Kompendium will view that as a cache hit,
|
||||
and skip analyzing the new enrichment.
|
||||
{% endhint %}
|
||||
|
||||
### Nested Enrichments
|
||||
|
||||
Enrichments are portable and composable, meaning that we can take an enrichment for a child data class
|
||||
and apply it inside a parent data class using the `typeEnrichment` property.
|
||||
|
||||
```kotlin
|
||||
data class ParentData(val a: String, val b: ChildData)
|
||||
data class ChildData(val c: String, val d: Int? = null)
|
||||
|
||||
val childEnrichment = TypeEnrichment<ChildData>(id = "child-enrichment") {
|
||||
ChildData::c {
|
||||
description = "This will update the field description of field c on child data"
|
||||
}
|
||||
ChildData::d {
|
||||
description = "This will update the field description of field d on child data"
|
||||
}
|
||||
}
|
||||
|
||||
val parentEnrichment = TypeEnrichment<ParentData>(id = "parent-enrichment") {
|
||||
ParentData::a {
|
||||
description = "This will update the field description"
|
||||
}
|
||||
ParentData::b {
|
||||
description = "This will update the field description of field b on parent data"
|
||||
typeEnrichment = childEnrichment // Will apply the child enrichment to the internals of field b
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## Available Enrichments
|
||||
|
||||
All enrichments support the following properties:
|
||||
|
||||
- description -> Provides a reader friendly description of the field in the object
|
||||
- deprecated -> Indicates that the field is deprecated and should not be used
|
||||
|
||||
### String
|
||||
|
||||
- minLength -> The minimum length of the string
|
||||
- maxLength -> The maximum length of the string
|
||||
- pattern -> A regex pattern that the string must match
|
||||
- contentEncoding -> The encoding of the string
|
||||
- contentMediaType -> The media type of the string
|
||||
|
||||
### Numbers
|
||||
|
||||
- minimum -> The minimum value of the number
|
||||
- maximum -> The maximum value of the number
|
||||
- exclusiveMinimum -> Indicates that the minimum value is exclusive
|
||||
- exclusiveMaximum -> Indicates that the maximum value is exclusive
|
||||
- multipleOf -> Indicates that the number must be a multiple of the provided value
|
||||
|
||||
### Arrays
|
||||
|
||||
- minItems -> The minimum number of items in the array
|
||||
- maxItems -> The maximum number of items in the array
|
||||
- uniqueItems -> Indicates that the array must contain unique items
|
2
docs/concepts/index.md
Normal file
2
docs/concepts/index.md
Normal file
@ -0,0 +1,2 @@
|
||||
Various concepts that are core to Kompendium but not necessarily exclusive
|
||||
to any given module or plugin
|
7
docs/helpers/index.md
Normal file
7
docs/helpers/index.md
Normal file
@ -0,0 +1,7 @@
|
||||
Helper modules help you to interact with Kompendium.
|
||||
|
||||
Some functionality is not possible or difficult to do with Kompendium by default. Modules in this folder help you to get
|
||||
functionality that would otherwise be difficult.
|
||||
|
||||
The first one of which is [Protobuf java converter](protobuf_java_converter.md) which translates java protobuf classes
|
||||
to `customTypes` entries.
|
153
docs/helpers/protobuf_java_converter.md
Normal file
153
docs/helpers/protobuf_java_converter.md
Normal file
@ -0,0 +1,153 @@
|
||||
The `Protobuf java converter` functions allow you to generate documentation from your generated Java classes.
|
||||
Since Kompendium relies a lot on `KProperties` we have yet to find a way to connect this with our Java.
|
||||
For now the documentation is generated for the `customTypes` in `NotarizedApplication`.
|
||||
|
||||
## Usage with Kotlinx
|
||||
|
||||
setup:
|
||||
```kotlin
|
||||
install(ContentNegotiation) {
|
||||
json(Json {
|
||||
encodeDefaults = false
|
||||
// Combine the kompendium serializers with your custom java proto serializers
|
||||
serializersModule =
|
||||
KompendiumSerializersModule.module + SerializersModule { serializersModule = yourCustomProtoSerializers }
|
||||
})
|
||||
}
|
||||
```
|
||||
|
||||
For one message and all its nested sub messages:
|
||||
```kotlin
|
||||
private fun Application.mainModule() {
|
||||
// ...
|
||||
install(NotarizedApplication()) {
|
||||
spec = baseSpec
|
||||
customTypes = MyJavaProto.getDefaultInstance().createCustomTypesForTypeAndSubTypes().toMap()
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
For multiple messages and their submesages:
|
||||
```kotlin
|
||||
private fun Application.mainModule() {
|
||||
// ...
|
||||
install(NotarizedApplication()) {
|
||||
spec = baseSpec
|
||||
customTypes = MyJavaProto.getDefaultInstance().createCustomTypesForTypeAndSubTypes()
|
||||
.plus(AnotherJavaProto.getDefaultInstance().createCustomTypesForTypeAndSubTypes()).toMap()
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Example User
|
||||
|
||||
The protobuf that is used on our endpoint
|
||||
```proto
|
||||
message User {
|
||||
string id = 1;
|
||||
string email = 2;
|
||||
string mobile_phone = 3;
|
||||
string name = 4;
|
||||
}
|
||||
```
|
||||
|
||||
A custom serializer deserializer:
|
||||
```kotlin
|
||||
@OptIn(ExperimentalSerializationApi::class)
|
||||
object UserSerializer : KSerializer<User> {
|
||||
|
||||
override val descriptor: SerialDescriptor = buildClassSerialDescriptor("User") {
|
||||
element("id", serialDescriptor<String>())
|
||||
element("email", serialDescriptor<String>())
|
||||
element("mobile_phone", serialDescriptor<String>())
|
||||
element("name", serialDescriptor<String>())
|
||||
}
|
||||
|
||||
override fun deserialize(decoder: Decoder): User {
|
||||
return decoder.decodeStructure(descriptor) {
|
||||
var id: String? = null
|
||||
var email: String? = null
|
||||
var mobilePhone: String? = null
|
||||
var name: String? = null
|
||||
|
||||
loop@ while (true) {
|
||||
when (val index = decodeElementIndex(descriptor)) {
|
||||
CompositeDecoder.DECODE_DONE -> break@loop
|
||||
0 -> id = decodeStringElement(descriptor, index)
|
||||
1 -> email = decodeStringElement(descriptor, index)
|
||||
2 -> mobilePhone = decodeStringElement(descriptor, index)
|
||||
3 -> name = decodeStringElement(descriptor, index)
|
||||
else -> throw RuntimeException(
|
||||
"Unexpected index field ${descriptor.getElementName(index)}"
|
||||
)
|
||||
}
|
||||
}
|
||||
// building the protobuf object
|
||||
val user = User.newBuilder().apply {
|
||||
id?.let { v -> this.id = v }
|
||||
email?.let { v -> this.email = v }
|
||||
mobilePhone?.let { v -> this.mobilePhone = v }
|
||||
name?.let { v -> this.name = v }
|
||||
}.build()
|
||||
user
|
||||
}
|
||||
}
|
||||
|
||||
override fun serialize(encoder: Encoder, value: User) {
|
||||
encoder.encodeStructure(descriptor) {
|
||||
encodeStringElement(descriptor, 0, value.id)
|
||||
encodeStringElement(descriptor, 1, value.email)
|
||||
encodeStringElement(descriptor, 2, value.mobilePhone)
|
||||
encodeStringElement(descriptor, 3, value.name)
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
Setting the content type:
|
||||
```kotlin
|
||||
install(ContentNegotiation) {
|
||||
json(Json {
|
||||
encodeDefaults = false
|
||||
// Combine the kompendium serializers with your custom java proto serializers
|
||||
serializersModule =
|
||||
KompendiumSerializersModule.module + SerializersModule {
|
||||
serializersModule = SerializersModule {
|
||||
contextual(UserSerializer)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
```
|
||||
The installation of the noterized application:
|
||||
```kotlin
|
||||
install(NotarizedApplication()) {
|
||||
spec = baseSpec
|
||||
customTypes = User.getDefaultInstance().createCustomTypesForTypeAndSubTypes().toMap()
|
||||
}
|
||||
```
|
||||
Route configuration as you normally would with one exception which is `createType()` to create kotlin type from a javaClass.
|
||||
|
||||
```kotlin
|
||||
private fun Route.userDocumentation() {
|
||||
install(NotarizedRoute()) {
|
||||
post = PostInfo.builder {
|
||||
summary("My User API")
|
||||
description("Create a user")
|
||||
request {
|
||||
requestType(User::class.createType())
|
||||
description("My user creation object")
|
||||
}
|
||||
response {
|
||||
responseCode(HttpStatusCode.OK)
|
||||
responseType(CreateUserResponse::class.createType())
|
||||
description("Returns simulation object")
|
||||
}
|
||||
canRespond {
|
||||
responseCode(HttpStatusCode.NotFound)
|
||||
responseType<String>()
|
||||
description("Indicates that the user could not be found")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
34
enrichment/build.gradle.kts
Normal file
34
enrichment/build.gradle.kts
Normal file
@ -0,0 +1,34 @@
|
||||
plugins {
|
||||
kotlin("jvm")
|
||||
id("io.bkbn.sourdough.library.jvm")
|
||||
id("io.gitlab.arturbosch.detekt")
|
||||
id("com.adarshr.test-logger")
|
||||
id("maven-publish")
|
||||
id("java-library")
|
||||
id("signing")
|
||||
id("org.jetbrains.kotlinx.kover")
|
||||
}
|
||||
|
||||
sourdoughLibrary {
|
||||
libraryName.set("Kompendium Type Enrichment")
|
||||
libraryDescription.set("Utility library for creating portable type enrichments")
|
||||
compilerArgs.set(listOf("-opt-in=kotlin.RequiresOptIn"))
|
||||
}
|
||||
|
||||
dependencies {
|
||||
// Versions
|
||||
val detektVersion: String by project
|
||||
|
||||
// Formatting
|
||||
detektPlugins("io.gitlab.arturbosch.detekt:detekt-formatting:$detektVersion")
|
||||
|
||||
testImplementation(testFixtures(projects.kompendiumCore))
|
||||
}
|
||||
|
||||
testing {
|
||||
suites {
|
||||
named("test", JvmTestSuite::class) {
|
||||
useJUnitJupiter()
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,3 @@
|
||||
package io.bkbn.kompendium.enrichment
|
||||
|
||||
sealed interface Enrichment
|
@ -0,0 +1,36 @@
|
||||
package io.bkbn.kompendium.enrichment
|
||||
|
||||
/**
|
||||
* Reference https://json-schema.org/draft/2020-12/json-schema-validation.html#name-multipleof
|
||||
*/
|
||||
class PropertyEnrichment : Enrichment {
|
||||
// Metadata
|
||||
var deprecated: Boolean? = null
|
||||
var description: String? = null
|
||||
var typeEnrichment: TypeEnrichment<*>? = null
|
||||
|
||||
// Number and Integer Constraints
|
||||
var multipleOf: Number? = null
|
||||
var maximum: Number? = null
|
||||
var exclusiveMaximum: Number? = null
|
||||
var minimum: Number? = null
|
||||
var exclusiveMinimum: Number? = null
|
||||
|
||||
// String constraints
|
||||
var maxLength: Int? = null
|
||||
var minLength: Int? = null
|
||||
var pattern: String? = null
|
||||
var contentEncoding: String? = null
|
||||
var contentMediaType: String? = null
|
||||
// TODO how to handle contentSchema?
|
||||
|
||||
// Array constraints
|
||||
var maxItems: Int? = null
|
||||
var minItems: Int? = null
|
||||
var uniqueItems: Boolean? = null
|
||||
// TODO How to handle contains, minContains, maxContains?
|
||||
|
||||
// Object constraints
|
||||
var maxProperties: Int? = null
|
||||
var minProperties: Int? = null
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
package io.bkbn.kompendium.enrichment
|
||||
|
||||
import kotlin.reflect.KProperty
|
||||
import kotlin.reflect.KProperty1
|
||||
|
||||
class TypeEnrichment<T>(val id: String) : Enrichment {
|
||||
|
||||
private val enrichments: MutableMap<KProperty1<*, *>, Enrichment> = mutableMapOf()
|
||||
|
||||
fun getEnrichmentForProperty(property: KProperty<*>): Enrichment? = enrichments[property]
|
||||
|
||||
operator fun <R> KProperty1<T, R>.invoke(init: PropertyEnrichment.() -> Unit) {
|
||||
require(!enrichments.containsKey(this)) { "${this.name} has already been registered" }
|
||||
val propertyEnrichment = PropertyEnrichment()
|
||||
init.invoke(propertyEnrichment)
|
||||
enrichments[this] = propertyEnrichment
|
||||
}
|
||||
|
||||
companion object {
|
||||
inline operator fun <reified T> invoke(id: String, init: TypeEnrichment<T>.() -> Unit): TypeEnrichment<T> {
|
||||
val builder = TypeEnrichment<T>(id)
|
||||
return builder.apply(init)
|
||||
}
|
||||
}
|
||||
}
|
@ -1,13 +1,14 @@
|
||||
# Kompendium
|
||||
project.version=3.8.0
|
||||
project.version=3.14.4
|
||||
# Kotlin
|
||||
kotlin.code.style=official
|
||||
# Gradle
|
||||
org.gradle.vfs.watch=true
|
||||
org.gradle.vfs.verbose=true
|
||||
org.gradle.jvmargs=-Xmx2000m
|
||||
org.gradle.parallel=true
|
||||
|
||||
# Dependencies
|
||||
ktorVersion=2.1.3
|
||||
kotestVersion=5.5.4
|
||||
detektVersion=1.21.0
|
||||
ktorVersion=2.3.1
|
||||
kotestVersion=5.6.2
|
||||
detektVersion=1.22.0
|
||||
|
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
Binary file not shown.
3
gradle/wrapper/gradle-wrapper.properties
vendored
3
gradle/wrapper/gradle-wrapper.properties
vendored
@ -1,5 +1,6 @@
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.1.1-bin.zip
|
||||
networkTimeout=10000
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
|
25
gradlew
vendored
25
gradlew
vendored
@ -55,7 +55,7 @@
|
||||
# Darwin, MinGW, and NonStop.
|
||||
#
|
||||
# (3) This script is generated from the Groovy template
|
||||
# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
|
||||
# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
|
||||
# within the Gradle project.
|
||||
#
|
||||
# You can find Gradle at https://github.com/gradle/gradle/.
|
||||
@ -80,13 +80,10 @@ do
|
||||
esac
|
||||
done
|
||||
|
||||
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
|
||||
|
||||
APP_NAME="Gradle"
|
||||
# This is normally unused
|
||||
# shellcheck disable=SC2034
|
||||
APP_BASE_NAME=${0##*/}
|
||||
|
||||
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
|
||||
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
|
||||
|
||||
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
||||
MAX_FD=maximum
|
||||
@ -143,12 +140,16 @@ fi
|
||||
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
|
||||
case $MAX_FD in #(
|
||||
max*)
|
||||
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
|
||||
# shellcheck disable=SC3045
|
||||
MAX_FD=$( ulimit -H -n ) ||
|
||||
warn "Could not query maximum file descriptor limit"
|
||||
esac
|
||||
case $MAX_FD in #(
|
||||
'' | soft) :;; #(
|
||||
*)
|
||||
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
|
||||
# shellcheck disable=SC3045
|
||||
ulimit -n "$MAX_FD" ||
|
||||
warn "Could not set maximum file descriptor limit to $MAX_FD"
|
||||
esac
|
||||
@ -193,6 +194,10 @@ if "$cygwin" || "$msys" ; then
|
||||
done
|
||||
fi
|
||||
|
||||
|
||||
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
|
||||
|
||||
# Collect all arguments for the java command;
|
||||
# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
|
||||
# shell script including quotes and variable substitutions, so put them in
|
||||
@ -205,6 +210,12 @@ set -- \
|
||||
org.gradle.wrapper.GradleWrapperMain \
|
||||
"$@"
|
||||
|
||||
# Stop when "xargs" is not available.
|
||||
if ! command -v xargs >/dev/null 2>&1
|
||||
then
|
||||
die "xargs is not available"
|
||||
fi
|
||||
|
||||
# Use "xargs" to parse quoted args.
|
||||
#
|
||||
# With -n1 it outputs one arg per line, with the quotes and backslashes removed.
|
||||
|
11
gradlew.bat
vendored
11
gradlew.bat
vendored
@ -26,6 +26,7 @@ if "%OS%"=="Windows_NT" setlocal
|
||||
|
||||
set DIRNAME=%~dp0
|
||||
if "%DIRNAME%"=="" set DIRNAME=.
|
||||
@rem This is normally unused
|
||||
set APP_BASE_NAME=%~n0
|
||||
set APP_HOME=%DIRNAME%
|
||||
|
||||
@ -40,7 +41,7 @@ if defined JAVA_HOME goto findJavaFromJavaHome
|
||||
|
||||
set JAVA_EXE=java.exe
|
||||
%JAVA_EXE% -version >NUL 2>&1
|
||||
if "%ERRORLEVEL%" == "0" goto execute
|
||||
if %ERRORLEVEL% equ 0 goto execute
|
||||
|
||||
echo.
|
||||
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||
@ -75,13 +76,15 @@ set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
|
||||
|
||||
:end
|
||||
@rem End local scope for the variables with windows NT shell
|
||||
if "%ERRORLEVEL%"=="0" goto mainEnd
|
||||
if %ERRORLEVEL% equ 0 goto mainEnd
|
||||
|
||||
:fail
|
||||
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
|
||||
rem the _cmd.exe /c_ return code!
|
||||
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
|
||||
exit /b 1
|
||||
set EXIT_CODE=%ERRORLEVEL%
|
||||
if %EXIT_CODE% equ 0 set EXIT_CODE=1
|
||||
if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
|
||||
exit /b %EXIT_CODE%
|
||||
|
||||
:mainEnd
|
||||
if "%OS%"=="Windows_NT" endlocal
|
||||
|
@ -20,8 +20,11 @@ dependencies {
|
||||
// Versions
|
||||
val detektVersion: String by project
|
||||
|
||||
implementation("org.jetbrains.kotlin:kotlin-reflect:1.7.21")
|
||||
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.4.1")
|
||||
// Kompendium
|
||||
api(projects.kompendiumEnrichment)
|
||||
|
||||
implementation("org.jetbrains.kotlin:kotlin-reflect:1.8.21")
|
||||
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.5.1")
|
||||
|
||||
// Formatting
|
||||
detektPlugins("io.gitlab.arturbosch.detekt:detekt-formatting:$detektVersion")
|
||||
|
@ -1,5 +1,6 @@
|
||||
package io.bkbn.kompendium.json.schema
|
||||
|
||||
import io.bkbn.kompendium.enrichment.TypeEnrichment
|
||||
import io.bkbn.kompendium.json.schema.definition.JsonSchema
|
||||
import io.bkbn.kompendium.json.schema.definition.NullableDefinition
|
||||
import io.bkbn.kompendium.json.schema.definition.OneOfDefinition
|
||||
@ -9,28 +10,26 @@ import io.bkbn.kompendium.json.schema.handler.EnumHandler
|
||||
import io.bkbn.kompendium.json.schema.handler.MapHandler
|
||||
import io.bkbn.kompendium.json.schema.handler.SealedObjectHandler
|
||||
import io.bkbn.kompendium.json.schema.handler.SimpleObjectHandler
|
||||
import io.bkbn.kompendium.json.schema.util.Helpers.getSimpleSlug
|
||||
import io.bkbn.kompendium.json.schema.util.Helpers.getSlug
|
||||
import java.util.UUID
|
||||
import kotlin.reflect.KClass
|
||||
import kotlin.reflect.KType
|
||||
import kotlin.reflect.full.isSubclassOf
|
||||
import kotlin.reflect.typeOf
|
||||
import java.util.UUID
|
||||
|
||||
object SchemaGenerator {
|
||||
|
||||
inline fun <reified T : Any?> fromTypeToSchema(
|
||||
cache: MutableMap<String, JsonSchema> = mutableMapOf(),
|
||||
schemaConfigurator: SchemaConfigurator = SchemaConfigurator.Default()
|
||||
) = fromTypeToSchema(typeOf<T>(), cache, schemaConfigurator)
|
||||
|
||||
fun fromTypeToSchema(
|
||||
type: KType,
|
||||
cache: MutableMap<String, JsonSchema>,
|
||||
schemaConfigurator: SchemaConfigurator
|
||||
schemaConfigurator: SchemaConfigurator,
|
||||
enrichment: TypeEnrichment<*>? = null
|
||||
): JsonSchema {
|
||||
cache[type.getSimpleSlug()]?.let {
|
||||
val slug = type.getSlug(enrichment)
|
||||
|
||||
cache[slug]?.let {
|
||||
return it
|
||||
}
|
||||
|
||||
return when (val clazz = type.classifier as KClass<*>) {
|
||||
Unit::class -> error(
|
||||
"""
|
||||
@ -48,14 +47,14 @@ object SchemaGenerator {
|
||||
Boolean::class -> checkForNull(type, TypeDefinition.BOOLEAN)
|
||||
UUID::class -> checkForNull(type, TypeDefinition.UUID)
|
||||
else -> when {
|
||||
clazz.isSubclassOf(Enum::class) -> EnumHandler.handle(type, clazz, cache)
|
||||
clazz.isSubclassOf(Collection::class) -> CollectionHandler.handle(type, cache, schemaConfigurator)
|
||||
clazz.isSubclassOf(Map::class) -> MapHandler.handle(type, cache, schemaConfigurator)
|
||||
clazz.isSubclassOf(Enum::class) -> EnumHandler.handle(type, clazz, cache, enrichment)
|
||||
clazz.isSubclassOf(Collection::class) -> CollectionHandler.handle(type, cache, schemaConfigurator, enrichment)
|
||||
clazz.isSubclassOf(Map::class) -> MapHandler.handle(type, cache, schemaConfigurator, enrichment)
|
||||
else -> {
|
||||
if (clazz.isSealed) {
|
||||
SealedObjectHandler.handle(type, clazz, cache, schemaConfigurator)
|
||||
SealedObjectHandler.handle(type, clazz, cache, schemaConfigurator, enrichment)
|
||||
} else {
|
||||
SimpleObjectHandler.handle(type, clazz, cache, schemaConfigurator)
|
||||
SimpleObjectHandler.handle(type, clazz, cache, schemaConfigurator, enrichment)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -65,11 +64,12 @@ object SchemaGenerator {
|
||||
fun fromTypeOrUnit(
|
||||
type: KType,
|
||||
cache: MutableMap<String, JsonSchema> = mutableMapOf(),
|
||||
schemaConfigurator: SchemaConfigurator
|
||||
schemaConfigurator: SchemaConfigurator,
|
||||
enrichment: TypeEnrichment<*>? = null
|
||||
): JsonSchema? =
|
||||
when (type.classifier as KClass<*>) {
|
||||
Unit::class -> null
|
||||
else -> fromTypeToSchema(type, cache, schemaConfigurator)
|
||||
else -> fromTypeToSchema(type, cache, schemaConfigurator, enrichment)
|
||||
}
|
||||
|
||||
private fun checkForNull(type: KType, schema: JsonSchema): JsonSchema = when (type.isMarkedNullable) {
|
||||
|
@ -3,4 +3,8 @@ package io.bkbn.kompendium.json.schema.definition
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
@Serializable
|
||||
data class AnyOfDefinition(val anyOf: Set<JsonSchema>) : JsonSchema
|
||||
data class AnyOfDefinition(
|
||||
val anyOf: Set<JsonSchema>,
|
||||
override val deprecated: Boolean? = null,
|
||||
override val description: String? = null,
|
||||
) : JsonSchema
|
||||
|
@ -4,7 +4,14 @@ import kotlinx.serialization.Serializable
|
||||
|
||||
@Serializable
|
||||
data class ArrayDefinition(
|
||||
val items: JsonSchema
|
||||
val items: JsonSchema,
|
||||
override val deprecated: Boolean? = null,
|
||||
override val description: String? = null,
|
||||
|
||||
// Constraints
|
||||
val maxItems: Int? = null,
|
||||
val minItems: Int? = null,
|
||||
val uniqueItems: Boolean? = null,
|
||||
) : JsonSchema {
|
||||
val type: String = "array"
|
||||
}
|
||||
|
@ -5,5 +5,7 @@ import kotlinx.serialization.Serializable
|
||||
@Serializable
|
||||
data class EnumDefinition(
|
||||
val type: String,
|
||||
val enum: Set<String>
|
||||
val enum: Set<String>,
|
||||
override val deprecated: Boolean? = null,
|
||||
override val description: String? = null,
|
||||
) : JsonSchema
|
||||
|
@ -11,6 +11,9 @@ import kotlinx.serialization.encoding.Encoder
|
||||
@Serializable(with = JsonSchema.Serializer::class)
|
||||
sealed interface JsonSchema {
|
||||
|
||||
val description: String?
|
||||
val deprecated: Boolean?
|
||||
|
||||
object Serializer : KSerializer<JsonSchema> {
|
||||
override val descriptor: SerialDescriptor = PrimitiveSerialDescriptor("JsonSchema", PrimitiveKind.STRING)
|
||||
override fun deserialize(decoder: Decoder): JsonSchema {
|
||||
|
@ -4,7 +4,9 @@ import kotlinx.serialization.Serializable
|
||||
|
||||
@Serializable
|
||||
data class MapDefinition(
|
||||
val additionalProperties: JsonSchema
|
||||
val additionalProperties: JsonSchema,
|
||||
override val deprecated: Boolean? = null,
|
||||
override val description: String? = null,
|
||||
) : JsonSchema {
|
||||
val type: String = "object"
|
||||
}
|
||||
|
@ -3,4 +3,8 @@ package io.bkbn.kompendium.json.schema.definition
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
@Serializable
|
||||
data class NullableDefinition(val type: String = "null") : JsonSchema
|
||||
data class NullableDefinition(
|
||||
val type: String = "null",
|
||||
override val deprecated: Boolean? = null,
|
||||
override val description: String? = null,
|
||||
) : JsonSchema
|
||||
|
@ -3,6 +3,10 @@ package io.bkbn.kompendium.json.schema.definition
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
@Serializable
|
||||
data class OneOfDefinition(val oneOf: Set<JsonSchema>) : JsonSchema {
|
||||
data class OneOfDefinition(
|
||||
val oneOf: Set<JsonSchema>,
|
||||
override val deprecated: Boolean? = null,
|
||||
override val description: String? = null,
|
||||
) : JsonSchema {
|
||||
constructor(vararg types: JsonSchema) : this(types.toSet())
|
||||
}
|
||||
|
@ -3,4 +3,8 @@ package io.bkbn.kompendium.json.schema.definition
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
@Serializable
|
||||
data class ReferenceDefinition(val `$ref`: String) : JsonSchema
|
||||
data class ReferenceDefinition(
|
||||
val `$ref`: String,
|
||||
override val deprecated: Boolean? = null,
|
||||
override val description: String? = null,
|
||||
) : JsonSchema
|
||||
|
@ -1,5 +1,6 @@
|
||||
package io.bkbn.kompendium.json.schema.definition
|
||||
|
||||
import io.bkbn.kompendium.json.schema.util.Serializers
|
||||
import kotlinx.serialization.Contextual
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
@ -7,10 +8,35 @@ import kotlinx.serialization.Serializable
|
||||
data class TypeDefinition(
|
||||
val type: String,
|
||||
val format: String? = null,
|
||||
val description: String? = null,
|
||||
val properties: Map<String, JsonSchema>? = null,
|
||||
val required: Set<String>? = null,
|
||||
@Contextual val default: Any? = null,
|
||||
override val deprecated: Boolean? = null,
|
||||
override val description: String? = null,
|
||||
// Constraints
|
||||
|
||||
// Number
|
||||
@Serializable(with = Serializers.Number::class)
|
||||
val multipleOf: Number? = null,
|
||||
@Serializable(with = Serializers.Number::class)
|
||||
val maximum: Number? = null,
|
||||
@Serializable(with = Serializers.Number::class)
|
||||
val exclusiveMaximum: Number? = null,
|
||||
@Serializable(with = Serializers.Number::class)
|
||||
val minimum: Number? = null,
|
||||
@Serializable(with = Serializers.Number::class)
|
||||
val exclusiveMinimum: Number? = null,
|
||||
|
||||
// String
|
||||
val maxLength: Int? = null,
|
||||
val minLength: Int? = null,
|
||||
val pattern: String? = null,
|
||||
val contentEncoding: String? = null,
|
||||
val contentMediaType: String? = null,
|
||||
|
||||
// Object
|
||||
val maxProperties: Int? = null,
|
||||
val minProperties: Int? = null,
|
||||
) : JsonSchema {
|
||||
|
||||
fun withDefault(default: Any): TypeDefinition = this.copy(default = default)
|
||||
|
@ -1,5 +1,6 @@
|
||||
package io.bkbn.kompendium.json.schema.handler
|
||||
|
||||
import io.bkbn.kompendium.enrichment.TypeEnrichment
|
||||
import io.bkbn.kompendium.json.schema.SchemaConfigurator
|
||||
import io.bkbn.kompendium.json.schema.SchemaGenerator
|
||||
import io.bkbn.kompendium.json.schema.definition.ArrayDefinition
|
||||
@ -9,17 +10,22 @@ import io.bkbn.kompendium.json.schema.definition.OneOfDefinition
|
||||
import io.bkbn.kompendium.json.schema.definition.ReferenceDefinition
|
||||
import io.bkbn.kompendium.json.schema.definition.TypeDefinition
|
||||
import io.bkbn.kompendium.json.schema.util.Helpers.getReferenceSlug
|
||||
import io.bkbn.kompendium.json.schema.util.Helpers.getSimpleSlug
|
||||
import io.bkbn.kompendium.json.schema.util.Helpers.getSlug
|
||||
import kotlin.reflect.KType
|
||||
|
||||
object CollectionHandler {
|
||||
fun handle(type: KType, cache: MutableMap<String, JsonSchema>, schemaConfigurator: SchemaConfigurator): JsonSchema {
|
||||
fun handle(
|
||||
type: KType,
|
||||
cache: MutableMap<String, JsonSchema>,
|
||||
schemaConfigurator: SchemaConfigurator,
|
||||
enrichment: TypeEnrichment<*>? = null
|
||||
): JsonSchema {
|
||||
val collectionType = type.arguments.first().type
|
||||
?: error("This indicates a bug in Kompendium, please open a GitHub issue!")
|
||||
val typeSchema = SchemaGenerator.fromTypeToSchema(collectionType, cache, schemaConfigurator).let {
|
||||
val typeSchema = SchemaGenerator.fromTypeToSchema(collectionType, cache, schemaConfigurator, enrichment).let {
|
||||
if (it is TypeDefinition && it.type == "object") {
|
||||
cache[collectionType.getSimpleSlug()] = it
|
||||
ReferenceDefinition(collectionType.getReferenceSlug())
|
||||
cache[collectionType.getSlug(enrichment)] = it
|
||||
ReferenceDefinition(collectionType.getReferenceSlug(enrichment))
|
||||
} else {
|
||||
it
|
||||
}
|
||||
|
@ -1,16 +1,22 @@
|
||||
package io.bkbn.kompendium.json.schema.handler
|
||||
|
||||
import io.bkbn.kompendium.enrichment.TypeEnrichment
|
||||
import io.bkbn.kompendium.json.schema.definition.EnumDefinition
|
||||
import io.bkbn.kompendium.json.schema.definition.JsonSchema
|
||||
import io.bkbn.kompendium.json.schema.definition.ReferenceDefinition
|
||||
import io.bkbn.kompendium.json.schema.util.Helpers.getReferenceSlug
|
||||
import io.bkbn.kompendium.json.schema.util.Helpers.getSimpleSlug
|
||||
import io.bkbn.kompendium.json.schema.util.Helpers.getSlug
|
||||
import kotlin.reflect.KClass
|
||||
import kotlin.reflect.KType
|
||||
|
||||
object EnumHandler {
|
||||
fun handle(type: KType, clazz: KClass<*>, cache: MutableMap<String, JsonSchema>): JsonSchema {
|
||||
cache[type.getSimpleSlug()] = ReferenceDefinition(type.getReferenceSlug())
|
||||
fun handle(
|
||||
type: KType,
|
||||
clazz: KClass<*>,
|
||||
cache: MutableMap<String, JsonSchema>,
|
||||
enrichment: TypeEnrichment<*>? = null
|
||||
): JsonSchema {
|
||||
cache[type.getSlug(enrichment)] = ReferenceDefinition(type.getReferenceSlug(enrichment))
|
||||
|
||||
val options = clazz.java.enumConstants.map { it.toString() }.toSet()
|
||||
return EnumDefinition(type = "string", enum = options)
|
||||
|
@ -1,5 +1,6 @@
|
||||
package io.bkbn.kompendium.json.schema.handler
|
||||
|
||||
import io.bkbn.kompendium.enrichment.TypeEnrichment
|
||||
import io.bkbn.kompendium.json.schema.SchemaConfigurator
|
||||
import io.bkbn.kompendium.json.schema.SchemaGenerator
|
||||
import io.bkbn.kompendium.json.schema.definition.JsonSchema
|
||||
@ -9,21 +10,26 @@ import io.bkbn.kompendium.json.schema.definition.OneOfDefinition
|
||||
import io.bkbn.kompendium.json.schema.definition.ReferenceDefinition
|
||||
import io.bkbn.kompendium.json.schema.definition.TypeDefinition
|
||||
import io.bkbn.kompendium.json.schema.util.Helpers.getReferenceSlug
|
||||
import io.bkbn.kompendium.json.schema.util.Helpers.getSimpleSlug
|
||||
import io.bkbn.kompendium.json.schema.util.Helpers.getSlug
|
||||
import kotlin.reflect.KClass
|
||||
import kotlin.reflect.KType
|
||||
|
||||
object MapHandler {
|
||||
|
||||
fun handle(type: KType, cache: MutableMap<String, JsonSchema>, schemaConfigurator: SchemaConfigurator): JsonSchema {
|
||||
fun handle(
|
||||
type: KType,
|
||||
cache: MutableMap<String, JsonSchema>,
|
||||
schemaConfigurator: SchemaConfigurator,
|
||||
enrichment: TypeEnrichment<*>? = null
|
||||
): JsonSchema {
|
||||
require(type.arguments.first().type?.classifier as KClass<*> == String::class) {
|
||||
"JSON requires that map keys MUST be Strings. You provided ${type.arguments.first().type}"
|
||||
}
|
||||
val valueType = type.arguments[1].type ?: error("this indicates a bug in Kompendium, please open a GitHub issue")
|
||||
val valueSchema = SchemaGenerator.fromTypeToSchema(valueType, cache, schemaConfigurator).let {
|
||||
val valueSchema = SchemaGenerator.fromTypeToSchema(valueType, cache, schemaConfigurator, enrichment).let {
|
||||
if (it is TypeDefinition && it.type == "object") {
|
||||
cache[valueType.getSimpleSlug()] = it
|
||||
ReferenceDefinition(valueType.getReferenceSlug())
|
||||
cache[valueType.getSlug(enrichment)] = it
|
||||
ReferenceDefinition(valueType.getReferenceSlug(enrichment))
|
||||
} else {
|
||||
it
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package io.bkbn.kompendium.json.schema.handler
|
||||
|
||||
import io.bkbn.kompendium.enrichment.TypeEnrichment
|
||||
import io.bkbn.kompendium.json.schema.SchemaConfigurator
|
||||
import io.bkbn.kompendium.json.schema.SchemaGenerator
|
||||
import io.bkbn.kompendium.json.schema.definition.AnyOfDefinition
|
||||
@ -7,7 +8,7 @@ import io.bkbn.kompendium.json.schema.definition.JsonSchema
|
||||
import io.bkbn.kompendium.json.schema.definition.ReferenceDefinition
|
||||
import io.bkbn.kompendium.json.schema.definition.TypeDefinition
|
||||
import io.bkbn.kompendium.json.schema.util.Helpers.getReferenceSlug
|
||||
import io.bkbn.kompendium.json.schema.util.Helpers.getSimpleSlug
|
||||
import io.bkbn.kompendium.json.schema.util.Helpers.getSlug
|
||||
import kotlin.reflect.KClass
|
||||
import kotlin.reflect.KType
|
||||
import kotlin.reflect.full.createType
|
||||
@ -18,15 +19,17 @@ object SealedObjectHandler {
|
||||
type: KType,
|
||||
clazz: KClass<*>,
|
||||
cache: MutableMap<String, JsonSchema>,
|
||||
schemaConfigurator: SchemaConfigurator
|
||||
schemaConfigurator: SchemaConfigurator,
|
||||
enrichment: TypeEnrichment<*>? = null,
|
||||
): JsonSchema {
|
||||
val subclasses = clazz.sealedSubclasses
|
||||
.map { it.createType(type.arguments) }
|
||||
.map { t ->
|
||||
SchemaGenerator.fromTypeToSchema(t, cache, schemaConfigurator).let { js ->
|
||||
SchemaGenerator.fromTypeToSchema(t, cache, schemaConfigurator, enrichment).let { js ->
|
||||
if (js is TypeDefinition && js.type == "object") {
|
||||
cache[t.getSimpleSlug()] = js
|
||||
ReferenceDefinition(t.getReferenceSlug())
|
||||
val slug = t.getSlug(enrichment)
|
||||
cache[slug] = js
|
||||
ReferenceDefinition(t.getReferenceSlug(enrichment))
|
||||
} else {
|
||||
js
|
||||
}
|
||||
|
@ -1,16 +1,21 @@
|
||||
package io.bkbn.kompendium.json.schema.handler
|
||||
|
||||
import io.bkbn.kompendium.enrichment.PropertyEnrichment
|
||||
import io.bkbn.kompendium.enrichment.TypeEnrichment
|
||||
import io.bkbn.kompendium.json.schema.SchemaConfigurator
|
||||
import io.bkbn.kompendium.json.schema.SchemaGenerator
|
||||
import io.bkbn.kompendium.json.schema.definition.AnyOfDefinition
|
||||
import io.bkbn.kompendium.json.schema.definition.ArrayDefinition
|
||||
import io.bkbn.kompendium.json.schema.definition.EnumDefinition
|
||||
import io.bkbn.kompendium.json.schema.definition.JsonSchema
|
||||
import io.bkbn.kompendium.json.schema.definition.MapDefinition
|
||||
import io.bkbn.kompendium.json.schema.definition.NullableDefinition
|
||||
import io.bkbn.kompendium.json.schema.definition.OneOfDefinition
|
||||
import io.bkbn.kompendium.json.schema.definition.ReferenceDefinition
|
||||
import io.bkbn.kompendium.json.schema.definition.TypeDefinition
|
||||
import io.bkbn.kompendium.json.schema.exception.UnknownSchemaException
|
||||
import io.bkbn.kompendium.json.schema.util.Helpers.getReferenceSlug
|
||||
import io.bkbn.kompendium.json.schema.util.Helpers.getSimpleSlug
|
||||
import io.bkbn.kompendium.json.schema.util.Helpers.getSlug
|
||||
import kotlin.reflect.KClass
|
||||
import kotlin.reflect.KProperty
|
||||
import kotlin.reflect.KType
|
||||
@ -26,26 +31,33 @@ object SimpleObjectHandler {
|
||||
type: KType,
|
||||
clazz: KClass<*>,
|
||||
cache: MutableMap<String, JsonSchema>,
|
||||
schemaConfigurator: SchemaConfigurator
|
||||
schemaConfigurator: SchemaConfigurator,
|
||||
enrichment: TypeEnrichment<*>?,
|
||||
): JsonSchema {
|
||||
|
||||
cache[type.getSimpleSlug()] = ReferenceDefinition(type.getReferenceSlug())
|
||||
cache[type.getSlug(enrichment)] = ReferenceDefinition(type.getReferenceSlug(enrichment))
|
||||
|
||||
val typeMap = clazz.typeParameters.zip(type.arguments).toMap()
|
||||
val props = schemaConfigurator.serializableMemberProperties(clazz)
|
||||
.filterNot { it.javaField == null }
|
||||
.associate { prop ->
|
||||
val propTypeEnrichment = when (val pe = enrichment?.getEnrichmentForProperty(prop)) {
|
||||
is PropertyEnrichment -> pe
|
||||
else -> null
|
||||
}
|
||||
|
||||
val schema = when (prop.needsToInjectGenerics(typeMap)) {
|
||||
true -> handleNestedGenerics(typeMap, prop, cache, schemaConfigurator)
|
||||
true -> handleNestedGenerics(typeMap, prop, cache, schemaConfigurator, propTypeEnrichment)
|
||||
false -> when (typeMap.containsKey(prop.returnType.classifier)) {
|
||||
true -> handleGenericProperty(prop, typeMap, cache, schemaConfigurator)
|
||||
false -> handleProperty(prop, cache, schemaConfigurator)
|
||||
true -> handleGenericProperty(prop, typeMap, cache, schemaConfigurator, propTypeEnrichment)
|
||||
false -> handleProperty(prop, cache, schemaConfigurator, propTypeEnrichment?.typeEnrichment)
|
||||
}
|
||||
}
|
||||
|
||||
val nullCheckSchema = when (prop.returnType.isMarkedNullable && !schema.isNullable()) {
|
||||
true -> OneOfDefinition(NullableDefinition(), schema)
|
||||
false -> schema
|
||||
val enrichedSchema = propTypeEnrichment?.applyToSchema(schema) ?: schema
|
||||
|
||||
val nullCheckSchema = when (prop.returnType.isMarkedNullable && !enrichedSchema.isNullable()) {
|
||||
true -> OneOfDefinition(NullableDefinition(), enrichedSchema)
|
||||
false -> enrichedSchema
|
||||
}
|
||||
|
||||
schemaConfigurator.serializableName(prop) to nullCheckSchema
|
||||
@ -90,7 +102,8 @@ object SimpleObjectHandler {
|
||||
typeMap: Map<KTypeParameter, KTypeProjection>,
|
||||
prop: KProperty<*>,
|
||||
cache: MutableMap<String, JsonSchema>,
|
||||
schemaConfigurator: SchemaConfigurator
|
||||
schemaConfigurator: SchemaConfigurator,
|
||||
propEnrichment: PropertyEnrichment?
|
||||
): JsonSchema {
|
||||
val propClass = prop.returnType.classifier as KClass<*>
|
||||
val types = prop.returnType.arguments.map {
|
||||
@ -98,10 +111,11 @@ object SimpleObjectHandler {
|
||||
typeMap.filterKeys { k -> k.name == typeSymbol }.values.first()
|
||||
}
|
||||
val constructedType = propClass.createType(types)
|
||||
return SchemaGenerator.fromTypeToSchema(constructedType, cache, schemaConfigurator).let {
|
||||
return SchemaGenerator.fromTypeToSchema(constructedType, cache, schemaConfigurator, propEnrichment?.typeEnrichment)
|
||||
.let {
|
||||
if (it.isOrContainsObjectOrEnumDef()) {
|
||||
cache[constructedType.getSimpleSlug()] = it
|
||||
ReferenceDefinition(prop.returnType.getReferenceSlug())
|
||||
cache[constructedType.getSlug(propEnrichment)] = it
|
||||
ReferenceDefinition(prop.returnType.getReferenceSlug(propEnrichment))
|
||||
} else {
|
||||
it
|
||||
}
|
||||
@ -112,14 +126,15 @@ object SimpleObjectHandler {
|
||||
prop: KProperty<*>,
|
||||
typeMap: Map<KTypeParameter, KTypeProjection>,
|
||||
cache: MutableMap<String, JsonSchema>,
|
||||
schemaConfigurator: SchemaConfigurator
|
||||
schemaConfigurator: SchemaConfigurator,
|
||||
propEnrichment: PropertyEnrichment?
|
||||
): JsonSchema {
|
||||
val type = typeMap[prop.returnType.classifier]?.type
|
||||
?: error("This indicates a bug in Kompendium, please open a GitHub issue")
|
||||
return SchemaGenerator.fromTypeToSchema(type, cache, schemaConfigurator).let {
|
||||
return SchemaGenerator.fromTypeToSchema(type, cache, schemaConfigurator, propEnrichment?.typeEnrichment).let {
|
||||
if (it.isOrContainsObjectOrEnumDef()) {
|
||||
cache[type.getSimpleSlug()] = it
|
||||
ReferenceDefinition(type.getReferenceSlug())
|
||||
cache[type.getSlug(propEnrichment?.typeEnrichment)] = it
|
||||
ReferenceDefinition(type.getReferenceSlug(propEnrichment?.typeEnrichment))
|
||||
} else {
|
||||
it
|
||||
}
|
||||
@ -129,12 +144,13 @@ object SimpleObjectHandler {
|
||||
private fun handleProperty(
|
||||
prop: KProperty<*>,
|
||||
cache: MutableMap<String, JsonSchema>,
|
||||
schemaConfigurator: SchemaConfigurator
|
||||
schemaConfigurator: SchemaConfigurator,
|
||||
propEnrichment: TypeEnrichment<*>?
|
||||
): JsonSchema =
|
||||
SchemaGenerator.fromTypeToSchema(prop.returnType, cache, schemaConfigurator).let {
|
||||
SchemaGenerator.fromTypeToSchema(prop.returnType, cache, schemaConfigurator, propEnrichment).let {
|
||||
if (it.isOrContainsObjectOrEnumDef()) {
|
||||
cache[prop.returnType.getSimpleSlug()] = it
|
||||
ReferenceDefinition(prop.returnType.getReferenceSlug())
|
||||
cache[prop.returnType.getSlug(propEnrichment)] = it
|
||||
ReferenceDefinition(prop.returnType.getReferenceSlug(propEnrichment))
|
||||
} else {
|
||||
it
|
||||
}
|
||||
@ -149,4 +165,37 @@ object SimpleObjectHandler {
|
||||
}
|
||||
|
||||
private fun JsonSchema.isNullable(): Boolean = this is OneOfDefinition && this.oneOf.any { it is NullableDefinition }
|
||||
|
||||
private fun PropertyEnrichment.applyToSchema(schema: JsonSchema): JsonSchema = when (schema) {
|
||||
is AnyOfDefinition -> schema.copy(deprecated = deprecated, description = description)
|
||||
is ArrayDefinition -> schema.copy(
|
||||
deprecated = deprecated,
|
||||
description = description,
|
||||
minItems = minItems,
|
||||
maxItems = maxItems,
|
||||
uniqueItems = uniqueItems,
|
||||
)
|
||||
|
||||
is EnumDefinition -> schema.copy(deprecated = deprecated, description = description)
|
||||
is MapDefinition -> schema.copy(deprecated = deprecated, description = description)
|
||||
is NullableDefinition -> schema.copy(deprecated = deprecated, description = description)
|
||||
is OneOfDefinition -> schema.copy(deprecated = deprecated, description = description)
|
||||
is ReferenceDefinition -> schema.copy(deprecated = deprecated, description = description)
|
||||
is TypeDefinition -> schema.copy(
|
||||
deprecated = deprecated,
|
||||
description = description,
|
||||
multipleOf = multipleOf,
|
||||
maximum = maximum,
|
||||
exclusiveMaximum = exclusiveMaximum,
|
||||
minimum = minimum,
|
||||
exclusiveMinimum = exclusiveMinimum,
|
||||
maxLength = maxLength,
|
||||
minLength = minLength,
|
||||
pattern = pattern,
|
||||
contentEncoding = contentEncoding,
|
||||
contentMediaType = contentMediaType,
|
||||
maxProperties = maxProperties,
|
||||
minProperties = minProperties,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -1,18 +1,35 @@
|
||||
package io.bkbn.kompendium.json.schema.util
|
||||
|
||||
import io.bkbn.kompendium.enrichment.Enrichment
|
||||
import io.bkbn.kompendium.enrichment.PropertyEnrichment
|
||||
import io.bkbn.kompendium.enrichment.TypeEnrichment
|
||||
import kotlin.reflect.KClass
|
||||
import kotlin.reflect.KType
|
||||
|
||||
object Helpers {
|
||||
|
||||
private const val COMPONENT_SLUG = "#/components/schemas"
|
||||
const val COMPONENT_SLUG = "#/components/schemas"
|
||||
|
||||
fun KType.getSlug(enrichment: Enrichment? = null) = when (enrichment) {
|
||||
is TypeEnrichment<*> -> getEnrichedSlug(enrichment)
|
||||
is PropertyEnrichment -> error("Slugs should not be generated for field enrichments")
|
||||
null -> getSimpleSlug()
|
||||
}
|
||||
|
||||
fun KType.getSimpleSlug(): String = when {
|
||||
this.arguments.isNotEmpty() -> genericNameAdapter(this, classifier as KClass<*>)
|
||||
else -> (classifier as KClass<*>).kompendiumSlug() ?: error("Could not determine simple name for $this")
|
||||
}
|
||||
|
||||
fun KType.getReferenceSlug(): String = when {
|
||||
private fun KType.getEnrichedSlug(enrichment: TypeEnrichment<*>) = getSimpleSlug() + "-${enrichment.id}"
|
||||
|
||||
fun KType.getReferenceSlug(enrichment: Enrichment? = null): String = when (enrichment) {
|
||||
is TypeEnrichment<*> -> getSimpleReferenceSlug() + "-${enrichment.id}"
|
||||
is PropertyEnrichment -> error("Reference slugs should never be generated for field enrichments")
|
||||
null -> getSimpleReferenceSlug()
|
||||
}
|
||||
|
||||
private fun KType.getSimpleReferenceSlug() = when {
|
||||
arguments.isNotEmpty() -> "$COMPONENT_SLUG/${genericNameAdapter(this, classifier as KClass<*>)}"
|
||||
else -> "$COMPONENT_SLUG/${(classifier as KClass<*>).kompendiumSlug()}"
|
||||
}
|
||||
|
@ -0,0 +1,43 @@
|
||||
package io.bkbn.kompendium.json.schema.util
|
||||
|
||||
import kotlinx.serialization.KSerializer
|
||||
import kotlinx.serialization.descriptors.PrimitiveKind
|
||||
import kotlinx.serialization.descriptors.PrimitiveSerialDescriptor
|
||||
import kotlinx.serialization.descriptors.SerialDescriptor
|
||||
import kotlinx.serialization.encoding.Decoder
|
||||
import kotlinx.serialization.encoding.Encoder
|
||||
import java.util.UUID
|
||||
import kotlin.Number as KNumber
|
||||
|
||||
object Serializers {
|
||||
|
||||
object Uuid : KSerializer<UUID> {
|
||||
override val descriptor = PrimitiveSerialDescriptor("UUID", PrimitiveKind.STRING)
|
||||
|
||||
override fun deserialize(decoder: Decoder): UUID {
|
||||
return UUID.fromString(decoder.decodeString())
|
||||
}
|
||||
|
||||
override fun serialize(encoder: Encoder, value: UUID) {
|
||||
encoder.encodeString(value.toString())
|
||||
}
|
||||
}
|
||||
|
||||
object Number : KSerializer<KNumber> {
|
||||
override val descriptor: SerialDescriptor = PrimitiveSerialDescriptor("Number", PrimitiveKind.STRING)
|
||||
|
||||
override fun deserialize(decoder: Decoder): KNumber {
|
||||
TODO("Not yet implemented")
|
||||
}
|
||||
|
||||
override fun serialize(encoder: Encoder, value: KNumber) {
|
||||
when (value) {
|
||||
is Int -> encoder.encodeInt(value)
|
||||
is Long -> encoder.encodeLong(value)
|
||||
is Double -> encoder.encodeDouble(value)
|
||||
is Float -> encoder.encodeFloat(value)
|
||||
else -> throw IllegalArgumentException("Number is not a valid type")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -2,21 +2,25 @@ package io.bkbn.kompendium.json.schema
|
||||
|
||||
import io.bkbn.kompendium.core.fixtures.ComplexRequest
|
||||
import io.bkbn.kompendium.core.fixtures.FlibbityGibbit
|
||||
import io.bkbn.kompendium.core.fixtures.NestedComplexItem
|
||||
import io.bkbn.kompendium.core.fixtures.ObjectWithEnum
|
||||
import io.bkbn.kompendium.core.fixtures.SerialNameObject
|
||||
import io.bkbn.kompendium.core.fixtures.SimpleEnum
|
||||
import io.bkbn.kompendium.core.fixtures.SlammaJamma
|
||||
import io.bkbn.kompendium.core.fixtures.TestHelpers.getFileSnapshot
|
||||
import io.bkbn.kompendium.core.fixtures.TestResponse
|
||||
import io.bkbn.kompendium.core.fixtures.TestSimpleRequest
|
||||
import io.bkbn.kompendium.core.fixtures.TransientObject
|
||||
import io.bkbn.kompendium.core.fixtures.UnbackedObject
|
||||
import io.bkbn.kompendium.core.fixtures.GenericObject
|
||||
import io.bkbn.kompendium.core.fixtures.TestHelpers.getFileSnapshot
|
||||
import io.bkbn.kompendium.enrichment.TypeEnrichment
|
||||
import io.bkbn.kompendium.json.schema.definition.JsonSchema
|
||||
import io.kotest.assertions.json.shouldEqualJson
|
||||
import io.kotest.assertions.throwables.shouldThrow
|
||||
import io.kotest.core.spec.style.DescribeSpec
|
||||
import kotlinx.serialization.json.Json
|
||||
import java.util.UUID
|
||||
import kotlin.reflect.typeOf
|
||||
|
||||
class SchemaGeneratorTest : DescribeSpec({
|
||||
describe("Scalars") {
|
||||
@ -59,6 +63,9 @@ class SchemaGeneratorTest : DescribeSpec({
|
||||
it("Can generate the schema for object with SerialName annotation") {
|
||||
jsonSchemaTest<SerialNameObject>("T0020__serial_name_object.json")
|
||||
}
|
||||
it("Can generate the schema for object with generic property") {
|
||||
jsonSchemaTest<GenericObject<TestSimpleRequest>>("T0024__generic_object.json")
|
||||
}
|
||||
}
|
||||
describe("Enums") {
|
||||
it("Can generate the schema for a simple enum") {
|
||||
@ -88,7 +95,13 @@ class SchemaGeneratorTest : DescribeSpec({
|
||||
jsonSchemaTest<Map<String, Int>>("T0012__scalar_map.json")
|
||||
}
|
||||
it("Throws an error when map keys are not strings") {
|
||||
shouldThrow<IllegalArgumentException> { SchemaGenerator.fromTypeToSchema<Map<Int, Int>>() }
|
||||
shouldThrow<IllegalArgumentException> {
|
||||
SchemaGenerator.fromTypeToSchema(
|
||||
typeOf<Map<Int, Int>>(),
|
||||
cache = mutableMapOf(),
|
||||
schemaConfigurator = KotlinXSchemaConfigurator()
|
||||
)
|
||||
}
|
||||
}
|
||||
it("Can generate the schema for a map of objects") {
|
||||
jsonSchemaTest<Map<String, TestResponse>>("T0013__object_map.json")
|
||||
@ -97,6 +110,54 @@ class SchemaGeneratorTest : DescribeSpec({
|
||||
jsonSchemaTest<Map<String, Int>?>("T0014__nullable_map.json")
|
||||
}
|
||||
}
|
||||
describe("Enrichment") {
|
||||
it("Can attach an enrichment to a simple type") {
|
||||
jsonSchemaTest<TestSimpleRequest>(
|
||||
snapshotName = "T0022__enriched_simple_object.json",
|
||||
enrichment = TypeEnrichment("simple") {
|
||||
TestSimpleRequest::a {
|
||||
description = "This is a simple description"
|
||||
}
|
||||
TestSimpleRequest::b {
|
||||
deprecated = true
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
it("Can properly assign a reference to a nested enrichment") {
|
||||
jsonSchemaTest<ComplexRequest>(
|
||||
snapshotName = "T0023__enriched_nested_reference.json",
|
||||
enrichment = TypeEnrichment("example") {
|
||||
ComplexRequest::tables {
|
||||
description = "Collection of important items"
|
||||
typeEnrichment = TypeEnrichment("table") {
|
||||
NestedComplexItem::name {
|
||||
description = "The name of the table"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
it("Can properly assign a reference to a generic object") {
|
||||
jsonSchemaTest<GenericObject<TestSimpleRequest>>(
|
||||
snapshotName = "T0025__enrichment_generic_object.json",
|
||||
enrichment = TypeEnrichment("generic") {
|
||||
GenericObject<TestSimpleRequest>::data {
|
||||
description = "This is a generic param"
|
||||
typeEnrichment = TypeEnrichment("simple") {
|
||||
TestSimpleRequest::a {
|
||||
description = "This is a simple description"
|
||||
}
|
||||
TestSimpleRequest::b {
|
||||
deprecated = true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
}) {
|
||||
companion object {
|
||||
private val json = Json {
|
||||
@ -107,11 +168,14 @@ class SchemaGeneratorTest : DescribeSpec({
|
||||
|
||||
private fun JsonSchema.serialize() = json.encodeToString(JsonSchema.serializer(), this)
|
||||
|
||||
private inline fun <reified T> jsonSchemaTest(snapshotName: String) {
|
||||
private inline fun <reified T> jsonSchemaTest(snapshotName: String, enrichment: TypeEnrichment<*>? = null) {
|
||||
// act
|
||||
val schema = SchemaGenerator.fromTypeToSchema<T>(schemaConfigurator = KotlinXSchemaConfigurator())
|
||||
|
||||
// todo add cache assertions!!!
|
||||
val schema = SchemaGenerator.fromTypeToSchema(
|
||||
type = typeOf<T>(),
|
||||
cache = mutableMapOf(),
|
||||
schemaConfigurator = KotlinXSchemaConfigurator(),
|
||||
enrichment = enrichment,
|
||||
)
|
||||
|
||||
// assert
|
||||
schema.serialize() shouldEqualJson getFileSnapshot(snapshotName)
|
||||
|
@ -0,0 +1,18 @@
|
||||
{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"a": {
|
||||
"type": "string",
|
||||
"description": "This is a simple description"
|
||||
},
|
||||
"b": {
|
||||
"type": "number",
|
||||
"format": "int32",
|
||||
"deprecated": true
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"a",
|
||||
"b"
|
||||
]
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"amazingField": {
|
||||
"type": "string"
|
||||
},
|
||||
"org": {
|
||||
"type": "string"
|
||||
},
|
||||
"tables": {
|
||||
"items": {
|
||||
"$ref": "#/components/schemas/NestedComplexItem-table"
|
||||
},
|
||||
"description": "Collection of important items",
|
||||
"type": "array"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"amazingField",
|
||||
"org",
|
||||
"tables"
|
||||
]
|
||||
}
|
11
json-schema/src/test/resources/T0024__generic_object.json
Normal file
11
json-schema/src/test/resources/T0024__generic_object.json
Normal file
@ -0,0 +1,11 @@
|
||||
{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"data": {
|
||||
"$ref": "#/components/schemas/TestSimpleRequest"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"data"
|
||||
]
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"data": {
|
||||
"description": "This is a generic param",
|
||||
"$ref": "#/components/schemas/TestSimpleRequest-simple"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"data"
|
||||
]
|
||||
}
|
@ -22,8 +22,8 @@ dependencies {
|
||||
// IMPLEMENTATION
|
||||
|
||||
implementation(projects.kompendiumCore)
|
||||
implementation("io.ktor:ktor-server-core:2.1.3")
|
||||
implementation("io.ktor:ktor-server-locations:2.1.3")
|
||||
implementation("io.ktor:ktor-server-core:2.3.1")
|
||||
implementation("io.ktor:ktor-server-locations:2.3.1")
|
||||
|
||||
// TESTING
|
||||
|
||||
|
@ -7,6 +7,7 @@ data class Listing(val name: String, val page: Int)
|
||||
data class Type(val name: String) {
|
||||
@Location("/edit")
|
||||
data class Edit(val parent: Type)
|
||||
|
||||
@Location("/other/{page}")
|
||||
data class Other(val parent: Type, val page: Int)
|
||||
}
|
||||
|
@ -21,7 +21,8 @@ dependencies {
|
||||
val detektVersion: String by project
|
||||
|
||||
api(projects.kompendiumJsonSchema)
|
||||
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.4.1")
|
||||
api(projects.kompendiumEnrichment)
|
||||
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.5.1")
|
||||
|
||||
// Formatting
|
||||
detektPlugins("io.gitlab.arturbosch.detekt:detekt-formatting:$detektVersion")
|
||||
|
@ -15,6 +15,7 @@ dependencies {
|
||||
implementation(projects.kompendiumCore)
|
||||
implementation(projects.kompendiumLocations)
|
||||
implementation(projects.kompendiumResources)
|
||||
implementation(projects.kompendiumProtobufJavaConverter)
|
||||
|
||||
// Ktor
|
||||
val ktorVersion: String by project
|
||||
@ -34,14 +35,14 @@ dependencies {
|
||||
|
||||
// Logging
|
||||
implementation("org.apache.logging.log4j:log4j-api-kotlin:1.2.0")
|
||||
implementation("org.apache.logging.log4j:log4j-api:2.19.0")
|
||||
implementation("org.apache.logging.log4j:log4j-core:2.19.0")
|
||||
implementation("org.slf4j:slf4j-api:2.0.3")
|
||||
implementation("org.slf4j:slf4j-simple:2.0.3")
|
||||
implementation("org.apache.logging.log4j:log4j-api:2.20.0")
|
||||
implementation("org.apache.logging.log4j:log4j-core:2.20.0")
|
||||
implementation("org.slf4j:slf4j-api:2.0.7")
|
||||
implementation("org.slf4j:slf4j-simple:2.0.7")
|
||||
|
||||
|
||||
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.4.1")
|
||||
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.5.1")
|
||||
implementation("org.jetbrains.kotlinx:kotlinx-datetime:0.4.0")
|
||||
|
||||
implementation("joda-time:joda-time:2.12.1")
|
||||
implementation("joda-time:joda-time:2.12.5")
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ import io.bkbn.kompendium.core.metadata.GetInfo
|
||||
import io.bkbn.kompendium.core.plugin.NotarizedApplication
|
||||
import io.bkbn.kompendium.core.plugin.NotarizedRoute
|
||||
import io.bkbn.kompendium.core.routes.redoc
|
||||
import io.bkbn.kompendium.core.routes.swagger
|
||||
import io.bkbn.kompendium.json.schema.definition.TypeDefinition
|
||||
import io.bkbn.kompendium.oas.component.Components
|
||||
import io.bkbn.kompendium.oas.payload.Parameter
|
||||
@ -68,6 +69,7 @@ private fun Application.mainModule() {
|
||||
)
|
||||
}
|
||||
routing {
|
||||
swagger(pageTitle = "Simple API Docs")
|
||||
redoc(pageTitle = "Simple API Docs")
|
||||
authenticate("basic") {
|
||||
route("/{id}") {
|
||||
|
@ -4,6 +4,7 @@ import io.bkbn.kompendium.core.metadata.GetInfo
|
||||
import io.bkbn.kompendium.core.plugin.NotarizedApplication
|
||||
import io.bkbn.kompendium.core.plugin.NotarizedRoute
|
||||
import io.bkbn.kompendium.core.routes.redoc
|
||||
import io.bkbn.kompendium.core.routes.swagger
|
||||
import io.bkbn.kompendium.json.schema.KotlinXSchemaConfigurator
|
||||
import io.bkbn.kompendium.json.schema.definition.TypeDefinition
|
||||
import io.bkbn.kompendium.oas.payload.Parameter
|
||||
@ -49,8 +50,8 @@ private fun Application.mainModule() {
|
||||
schemaConfigurator = KotlinXSchemaConfigurator()
|
||||
}
|
||||
routing {
|
||||
swagger(pageTitle = "Simple API Docs")
|
||||
redoc(pageTitle = "Simple API Docs")
|
||||
|
||||
route("/{id}") {
|
||||
idDocumentation()
|
||||
get {
|
||||
|
@ -4,6 +4,7 @@ import io.bkbn.kompendium.core.metadata.GetInfo
|
||||
import io.bkbn.kompendium.core.plugin.NotarizedApplication
|
||||
import io.bkbn.kompendium.core.plugin.NotarizedRoute
|
||||
import io.bkbn.kompendium.core.routes.redoc
|
||||
import io.bkbn.kompendium.core.routes.swagger
|
||||
import io.bkbn.kompendium.json.schema.definition.TypeDefinition
|
||||
import io.bkbn.kompendium.oas.payload.Parameter
|
||||
import io.bkbn.kompendium.oas.serialization.KompendiumSerializersModule
|
||||
@ -51,6 +52,7 @@ private fun Application.mainModule() {
|
||||
)
|
||||
}
|
||||
routing {
|
||||
swagger(pageTitle = "Simple API Docs")
|
||||
redoc(pageTitle = "Simple API Docs")
|
||||
|
||||
route("/{id}") {
|
||||
|
@ -0,0 +1,158 @@
|
||||
package io.bkbn.kompendium.playground
|
||||
|
||||
import io.bkbn.kompendium.core.metadata.GetInfo
|
||||
import io.bkbn.kompendium.core.metadata.PostInfo
|
||||
import io.bkbn.kompendium.core.plugin.NotarizedApplication
|
||||
import io.bkbn.kompendium.core.plugin.NotarizedRoute
|
||||
import io.bkbn.kompendium.core.routes.redoc
|
||||
import io.bkbn.kompendium.core.routes.swagger
|
||||
import io.bkbn.kompendium.enrichment.TypeEnrichment
|
||||
import io.bkbn.kompendium.json.schema.KotlinXSchemaConfigurator
|
||||
import io.bkbn.kompendium.json.schema.definition.TypeDefinition
|
||||
import io.bkbn.kompendium.oas.payload.Parameter
|
||||
import io.bkbn.kompendium.oas.serialization.KompendiumSerializersModule
|
||||
import io.bkbn.kompendium.playground.util.ExampleRequest
|
||||
import io.bkbn.kompendium.playground.util.ExampleResponse
|
||||
import io.bkbn.kompendium.playground.util.ExceptionResponse
|
||||
import io.bkbn.kompendium.playground.util.InnerRequest
|
||||
import io.bkbn.kompendium.playground.util.Util.baseSpec
|
||||
import io.ktor.http.HttpStatusCode
|
||||
import io.ktor.serialization.kotlinx.json.json
|
||||
import io.ktor.server.application.Application
|
||||
import io.ktor.server.application.call
|
||||
import io.ktor.server.application.install
|
||||
import io.ktor.server.cio.CIO
|
||||
import io.ktor.server.engine.embeddedServer
|
||||
import io.ktor.server.plugins.contentnegotiation.ContentNegotiation
|
||||
import io.ktor.server.response.respond
|
||||
import io.ktor.server.routing.*
|
||||
import kotlinx.serialization.json.Json
|
||||
|
||||
fun main() {
|
||||
embeddedServer(
|
||||
CIO,
|
||||
port = 8081,
|
||||
module = Application::mainModule
|
||||
).start(wait = true)
|
||||
}
|
||||
|
||||
private fun Application.mainModule() {
|
||||
install(ContentNegotiation) {
|
||||
json(Json {
|
||||
serializersModule = KompendiumSerializersModule.module
|
||||
encodeDefaults = true
|
||||
explicitNulls = false
|
||||
})
|
||||
}
|
||||
install(NotarizedApplication()) {
|
||||
spec = baseSpec
|
||||
// Adds support for @Transient and @SerialName
|
||||
// If you are not using them this is not required.
|
||||
schemaConfigurator = KotlinXSchemaConfigurator()
|
||||
}
|
||||
routing {
|
||||
swagger(pageTitle = "Simple API Docs")
|
||||
redoc(pageTitle = "Simple API Docs")
|
||||
enrichedDocumentation()
|
||||
post {
|
||||
call.respond(HttpStatusCode.OK, ExampleResponse(false))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private val testEnrichment = TypeEnrichment("testerino") {
|
||||
ExampleRequest::thingA {
|
||||
description = "This is a thing"
|
||||
}
|
||||
ExampleRequest::thingB {
|
||||
description = "This is another thing"
|
||||
}
|
||||
ExampleRequest::thingC {
|
||||
deprecated = true
|
||||
description = "A good but old field"
|
||||
typeEnrichment = TypeEnrichment("big-tings") {
|
||||
InnerRequest::d {
|
||||
exclusiveMaximum = 10.0
|
||||
exclusiveMinimum = 1.1
|
||||
description = "THE BIG D"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private val testResponseEnrichment = TypeEnrichment("testerino") {
|
||||
ExampleResponse::isReal {
|
||||
description = "Is this thing real or not?"
|
||||
}
|
||||
}
|
||||
|
||||
private fun Route.enrichedDocumentation() {
|
||||
install(NotarizedRoute()) {
|
||||
post = PostInfo.builder {
|
||||
summary("Do a thing")
|
||||
description("This is a thing")
|
||||
request {
|
||||
requestType(enrichment = testEnrichment)
|
||||
description("This is the request")
|
||||
}
|
||||
response {
|
||||
responseCode(HttpStatusCode.OK)
|
||||
responseType(enrichment = testResponseEnrichment)
|
||||
description("This is the response")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun Route.idDocumentation() {
|
||||
install(NotarizedRoute()) {
|
||||
parameters = listOf(
|
||||
Parameter(
|
||||
name = "id",
|
||||
`in` = Parameter.Location.path,
|
||||
schema = TypeDefinition.STRING
|
||||
)
|
||||
)
|
||||
get = GetInfo.builder {
|
||||
summary("Get user by id")
|
||||
description("A very neat endpoint!")
|
||||
response {
|
||||
responseCode(HttpStatusCode.OK)
|
||||
responseType<ExampleResponse>()
|
||||
description("Will return whether or not the user is real 😱")
|
||||
}
|
||||
|
||||
canRespond {
|
||||
responseType<ExceptionResponse>()
|
||||
responseCode(HttpStatusCode.NotFound)
|
||||
description("Indicates that a user with this id does not exist")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun Route.profileDocumentation() {
|
||||
install(NotarizedRoute()) {
|
||||
parameters = listOf(
|
||||
Parameter(
|
||||
name = "id",
|
||||
`in` = Parameter.Location.path,
|
||||
schema = TypeDefinition.STRING
|
||||
)
|
||||
)
|
||||
get = GetInfo.builder {
|
||||
summary("Get a users profile")
|
||||
description("A cool endpoint!")
|
||||
response {
|
||||
responseCode(HttpStatusCode.OK)
|
||||
responseType<ExampleResponse>()
|
||||
description("Returns user profile information")
|
||||
}
|
||||
canRespond {
|
||||
responseType<ExceptionResponse>()
|
||||
responseCode(HttpStatusCode.NotFound)
|
||||
description("Indicates that a user with this id does not exist")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -4,6 +4,7 @@ import io.bkbn.kompendium.core.metadata.GetInfo
|
||||
import io.bkbn.kompendium.core.plugin.NotarizedApplication
|
||||
import io.bkbn.kompendium.core.plugin.NotarizedRoute
|
||||
import io.bkbn.kompendium.core.routes.redoc
|
||||
import io.bkbn.kompendium.core.routes.swagger
|
||||
import io.bkbn.kompendium.json.schema.definition.TypeDefinition
|
||||
import io.bkbn.kompendium.oas.payload.Parameter
|
||||
import io.bkbn.kompendium.oas.serialization.KompendiumSerializersModule
|
||||
@ -50,6 +51,7 @@ private fun Application.mainModule() {
|
||||
}
|
||||
}
|
||||
routing {
|
||||
swagger(pageTitle = "Simple API Docs")
|
||||
redoc(pageTitle = "Simple API Docs")
|
||||
|
||||
route("/{id}") {
|
||||
|
@ -6,6 +6,7 @@ import io.bkbn.kompendium.core.metadata.GetInfo
|
||||
import io.bkbn.kompendium.core.plugin.NotarizedApplication
|
||||
import io.bkbn.kompendium.core.plugin.NotarizedRoute
|
||||
import io.bkbn.kompendium.core.routes.redoc
|
||||
import io.bkbn.kompendium.core.routes.swagger
|
||||
import io.bkbn.kompendium.json.schema.SchemaConfigurator
|
||||
import io.bkbn.kompendium.json.schema.definition.TypeDefinition
|
||||
import io.bkbn.kompendium.oas.payload.Parameter
|
||||
@ -48,6 +49,7 @@ private fun Application.mainModule() {
|
||||
schemaConfigurator = GsonSchemaConfigurator()
|
||||
}
|
||||
routing {
|
||||
swagger(pageTitle = "Simple API Docs")
|
||||
redoc(pageTitle = "Simple API Docs")
|
||||
|
||||
route("/{id}") {
|
||||
|
@ -5,6 +5,7 @@ import io.bkbn.kompendium.core.metadata.GetInfo
|
||||
import io.bkbn.kompendium.core.plugin.NotarizedApplication
|
||||
import io.bkbn.kompendium.core.plugin.NotarizedRoute
|
||||
import io.bkbn.kompendium.core.routes.redoc
|
||||
import io.bkbn.kompendium.core.routes.swagger
|
||||
import io.bkbn.kompendium.json.schema.definition.TypeDefinition
|
||||
import io.bkbn.kompendium.oas.component.Components
|
||||
import io.bkbn.kompendium.oas.payload.Parameter
|
||||
@ -80,6 +81,7 @@ private fun Application.mainModule() {
|
||||
}
|
||||
routing {
|
||||
authenticate("basic") {
|
||||
swagger(pageTitle = "Simple API Docs")
|
||||
redoc(pageTitle = "Simple API Docs")
|
||||
route("/{id}") {
|
||||
locationDocumentation()
|
||||
|
@ -8,6 +8,7 @@ import io.bkbn.kompendium.core.metadata.GetInfo
|
||||
import io.bkbn.kompendium.core.plugin.NotarizedApplication
|
||||
import io.bkbn.kompendium.core.plugin.NotarizedRoute
|
||||
import io.bkbn.kompendium.core.routes.redoc
|
||||
import io.bkbn.kompendium.core.routes.swagger
|
||||
import io.bkbn.kompendium.json.schema.SchemaConfigurator
|
||||
import io.bkbn.kompendium.json.schema.definition.TypeDefinition
|
||||
import io.bkbn.kompendium.oas.payload.Parameter
|
||||
@ -51,6 +52,7 @@ private fun Application.mainModule() {
|
||||
schemaConfigurator = JacksonSchemaConfigurator()
|
||||
}
|
||||
routing {
|
||||
swagger(pageTitle = "Simple API Docs")
|
||||
redoc(pageTitle = "Simple API Docs")
|
||||
|
||||
route("/{id}") {
|
||||
|
@ -3,6 +3,7 @@ package io.bkbn.kompendium.playground
|
||||
import io.bkbn.kompendium.core.metadata.GetInfo
|
||||
import io.bkbn.kompendium.core.plugin.NotarizedApplication
|
||||
import io.bkbn.kompendium.core.routes.redoc
|
||||
import io.bkbn.kompendium.core.routes.swagger
|
||||
import io.bkbn.kompendium.json.schema.definition.TypeDefinition
|
||||
import io.bkbn.kompendium.locations.NotarizedLocations
|
||||
import io.bkbn.kompendium.oas.payload.Parameter
|
||||
@ -72,6 +73,7 @@ private fun Application.mainModule() {
|
||||
)
|
||||
}
|
||||
routing {
|
||||
swagger(pageTitle = "Simple API Docs")
|
||||
redoc(pageTitle = "Simple API Docs")
|
||||
get<Listing> { listing ->
|
||||
call.respondText("Listing ${listing.name}, page ${listing.page}")
|
||||
|
@ -3,6 +3,7 @@ package io.bkbn.kompendium.playground
|
||||
import io.bkbn.kompendium.core.metadata.GetInfo
|
||||
import io.bkbn.kompendium.core.plugin.NotarizedApplication
|
||||
import io.bkbn.kompendium.core.routes.redoc
|
||||
import io.bkbn.kompendium.core.routes.swagger
|
||||
import io.bkbn.kompendium.json.schema.definition.TypeDefinition
|
||||
import io.bkbn.kompendium.oas.payload.Parameter
|
||||
import io.bkbn.kompendium.oas.serialization.KompendiumSerializersModule
|
||||
@ -73,6 +74,7 @@ private fun Application.mainModule() {
|
||||
)
|
||||
}
|
||||
routing {
|
||||
swagger(pageTitle = "Simple API Docs")
|
||||
redoc(pageTitle = "Simple API Docs")
|
||||
get<ListingResource> { listing ->
|
||||
call.respondText("Listing ${listing.name}, page ${listing.page}")
|
||||
|
@ -5,6 +5,19 @@ import io.ktor.server.locations.Location
|
||||
import kotlinx.datetime.Instant
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
@Serializable
|
||||
data class ExampleRequest(
|
||||
val thingA: String,
|
||||
val thingB: Int,
|
||||
val thingC: InnerRequest,
|
||||
)
|
||||
|
||||
@Serializable
|
||||
data class InnerRequest(
|
||||
val d: Float,
|
||||
val e: Boolean,
|
||||
)
|
||||
|
||||
@Serializable
|
||||
data class ExampleResponse(val isReal: Boolean)
|
||||
|
||||
|
43
protobuf-java-converter/build.gradle.kts
Normal file
43
protobuf-java-converter/build.gradle.kts
Normal file
@ -0,0 +1,43 @@
|
||||
plugins {
|
||||
kotlin("jvm")
|
||||
kotlin("plugin.serialization")
|
||||
id("io.bkbn.sourdough.library.jvm")
|
||||
id("io.gitlab.arturbosch.detekt")
|
||||
id("com.adarshr.test-logger")
|
||||
id("maven-publish")
|
||||
id("java-library")
|
||||
id("signing")
|
||||
id("org.jetbrains.kotlinx.kover")
|
||||
}
|
||||
|
||||
sourdoughLibrary {
|
||||
libraryName.set("Kompendium Protobuf java converter")
|
||||
libraryDescription.set("Converts Java protobuf generated classes to custom type maps")
|
||||
compilerArgs.set(listOf("-opt-in=kotlin.RequiresOptIn"))
|
||||
}
|
||||
|
||||
dependencies {
|
||||
// Versions
|
||||
val detektVersion: String by project
|
||||
|
||||
|
||||
implementation(projects.kompendiumJsonSchema)
|
||||
implementation("com.google.protobuf:protobuf-java:3.23.2")
|
||||
implementation("org.jetbrains.kotlin:kotlin-reflect:1.8.21")
|
||||
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.5.1")
|
||||
|
||||
// Formatting
|
||||
detektPlugins("io.gitlab.arturbosch.detekt:detekt-formatting:$detektVersion")
|
||||
testImplementation(testFixtures(projects.kompendiumCore))
|
||||
}
|
||||
|
||||
|
||||
testing {
|
||||
|
||||
suites {
|
||||
named("test", JvmTestSuite::class) {
|
||||
useJUnitJupiter()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,178 @@
|
||||
package io.bkbn.kompendium.protobufjavaconverter.converters
|
||||
|
||||
import com.google.protobuf.Descriptors
|
||||
import com.google.protobuf.GeneratedMessageV3
|
||||
import io.bkbn.kompendium.json.schema.definition.ArrayDefinition
|
||||
import io.bkbn.kompendium.json.schema.definition.EnumDefinition
|
||||
import io.bkbn.kompendium.json.schema.definition.JsonSchema
|
||||
import io.bkbn.kompendium.json.schema.definition.MapDefinition
|
||||
import io.bkbn.kompendium.json.schema.definition.NullableDefinition
|
||||
import io.bkbn.kompendium.json.schema.definition.ReferenceDefinition
|
||||
import io.bkbn.kompendium.json.schema.definition.TypeDefinition
|
||||
import io.bkbn.kompendium.json.schema.util.Helpers
|
||||
import kotlin.reflect.KType
|
||||
import kotlin.reflect.full.createType
|
||||
|
||||
/**
|
||||
* Extension function to generate all custom TypeDefinitions for.
|
||||
*
|
||||
* Traverses all fields and subfields of the message it also generates references for nested messages.
|
||||
*
|
||||
* @property GeneratedMessageV3 the protobuf message to generate all the custom definitions for
|
||||
* @param snakeCase whether to convert the names to snake case or not
|
||||
* @return a [Map] of ([KType], [TypeDefinition]) to be used in `customTypes` in [NoterizedApplication]
|
||||
*
|
||||
*/
|
||||
fun GeneratedMessageV3.createCustomTypesForTypeAndSubTypes(snakeCase: Boolean = false): Map<KType, JsonSchema> {
|
||||
val cache: MutableMap<String, JsonSchema> = mutableMapOf()
|
||||
return mapOf(
|
||||
this::class.createType() to TypeDefinition(
|
||||
type = "object",
|
||||
properties = toJsonSchemaMap(this.descriptorForType, cache, snakeCase)
|
||||
)
|
||||
)
|
||||
// Dont forget to add the definitions for our references
|
||||
.plus(
|
||||
cache.map {
|
||||
// Get the class from the respective key (which should be a fullname of the class
|
||||
val clazz = Class.forName(it.key)
|
||||
clazz.kotlin.createType() to it.value
|
||||
}.toMap()
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Loops over all fields of the provided Descriptor to discover the field types
|
||||
*
|
||||
* @param protoDescriptor the [Descriptors.FieldDescriptor] to convert
|
||||
* @param cache map of cached definitions
|
||||
* @param snakeCase whether to convert the names to snake case or not
|
||||
* @return a [Map] of ([String], [JsonSchema])
|
||||
*
|
||||
*/
|
||||
fun toJsonSchemaMap(
|
||||
protoDescriptor: Descriptors.Descriptor,
|
||||
cache: MutableMap<String, JsonSchema> = mutableMapOf(),
|
||||
snakeCase: Boolean = false
|
||||
): Map<String, JsonSchema> =
|
||||
protoDescriptor.fields.map {
|
||||
val key = if (snakeCase) it.jsonName.toSnakeCase() else it.jsonName
|
||||
key to fromNestedTypeToSchema(it, cache)
|
||||
}.toMap()
|
||||
|
||||
/**
|
||||
* Very simple snake case conversion
|
||||
*/
|
||||
fun String.toSnakeCase() =
|
||||
this.map {
|
||||
if (it.isUpperCase()) "_${it.lowercase()}" else it.toString()
|
||||
}.reduce { acc, s -> acc + s }
|
||||
|
||||
/**
|
||||
* Converts a field from a proto message to a JsonSchema
|
||||
*
|
||||
* @param javaProtoField the [Descriptors.FieldDescriptor] to convert
|
||||
* @param cache map of cached definitions
|
||||
* @return the resulting [JsonSchema]
|
||||
*
|
||||
*/
|
||||
fun fromNestedTypeToSchema(
|
||||
javaProtoField: Descriptors.FieldDescriptor,
|
||||
cache: MutableMap<String, JsonSchema> = mutableMapOf()
|
||||
): JsonSchema =
|
||||
when {
|
||||
javaProtoField.isRepeated && !javaProtoField.isMapField -> ArrayDefinition(fromTypeToSchema(javaProtoField, cache))
|
||||
javaProtoField.isMapField -> handleMapField(javaProtoField, cache)
|
||||
else -> fromTypeToSchema(javaProtoField, cache)
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a map field descriptor
|
||||
*
|
||||
* It generates some key examples based on the type provided and gets the TypeDefinition of the value.
|
||||
*
|
||||
* @param javaProtoField the field to convert (which should be a mapField)
|
||||
* @param cache map of cached definitions
|
||||
* @return returns the a [MapDefinition] schema with additional properties to describe the key and value
|
||||
*/
|
||||
@Suppress("MagicNumber")
|
||||
fun handleMapField(
|
||||
javaProtoField: Descriptors.FieldDescriptor,
|
||||
cache: MutableMap<String, JsonSchema> = mutableMapOf()
|
||||
): JsonSchema {
|
||||
require(javaProtoField.isMapField) { "Should never be called for a non map type" }
|
||||
|
||||
val keyField = javaProtoField.containingType.nestedTypes.first().findFieldByName("key")
|
||||
val valueField = javaProtoField.containingType.nestedTypes.first().findFieldByName("value")
|
||||
val valueType = fromTypeToSchema(valueField, cache)
|
||||
// Keys can only be string in json but we can still have "0", "0.0" or "true", "ENUM_VALUE" as keys
|
||||
val keys: List<String> = when (keyField.javaType) {
|
||||
Descriptors.FieldDescriptor.JavaType.INT,
|
||||
Descriptors.FieldDescriptor.JavaType.LONG -> (0..1).map { it.toString() }
|
||||
Descriptors.FieldDescriptor.JavaType.FLOAT,
|
||||
Descriptors.FieldDescriptor.JavaType.DOUBLE -> listOf(0.0, 0.1, 0.2).map { it.toString() }
|
||||
Descriptors.FieldDescriptor.JavaType.BOOLEAN -> listOf(true, false).map { it.toString() }
|
||||
Descriptors.FieldDescriptor.JavaType.STRING -> (0..1).map { "myVariable$it" }
|
||||
Descriptors.FieldDescriptor.JavaType.BYTE_STRING -> (0..1).map { "0x$it" }
|
||||
Descriptors.FieldDescriptor.JavaType.ENUM -> (0..1).map { "ENUM_VALUE$it" }
|
||||
null,
|
||||
Descriptors.FieldDescriptor.JavaType.MESSAGE -> throw IllegalArgumentException("Cant use object as key")
|
||||
}
|
||||
return MapDefinition(
|
||||
TypeDefinition(
|
||||
type = "object",
|
||||
properties = keys.map { it to valueType }.toMap()
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts scalar, enum and message type descriptors to TypeDefinitions
|
||||
*
|
||||
* @param javaProtoField the field to convert
|
||||
* @param cache map of cached definitions
|
||||
* @return returns a matching [JsonSchema]
|
||||
*/
|
||||
fun fromTypeToSchema(
|
||||
javaProtoField: Descriptors.FieldDescriptor,
|
||||
cache: MutableMap<String, JsonSchema> = mutableMapOf()
|
||||
): JsonSchema {
|
||||
checkTypeCache(javaProtoField, cache)?.let { return it }
|
||||
return when (javaProtoField.javaType) {
|
||||
Descriptors.FieldDescriptor.JavaType.INT -> TypeDefinition.INT
|
||||
Descriptors.FieldDescriptor.JavaType.LONG -> TypeDefinition.LONG
|
||||
Descriptors.FieldDescriptor.JavaType.FLOAT -> TypeDefinition.FLOAT
|
||||
Descriptors.FieldDescriptor.JavaType.DOUBLE -> TypeDefinition.DOUBLE
|
||||
Descriptors.FieldDescriptor.JavaType.BOOLEAN -> TypeDefinition.BOOLEAN
|
||||
Descriptors.FieldDescriptor.JavaType.STRING -> TypeDefinition.STRING
|
||||
Descriptors.FieldDescriptor.JavaType.BYTE_STRING -> TypeDefinition.STRING
|
||||
Descriptors.FieldDescriptor.JavaType.ENUM -> {
|
||||
cache[javaProtoField.enumType.fullName] = EnumDefinition(
|
||||
type = "string",
|
||||
enum = javaProtoField.enumType.values.map { it.name }.toSet()
|
||||
)
|
||||
ReferenceDefinition("${Helpers.COMPONENT_SLUG}/${javaProtoField.enumType.name}")
|
||||
}
|
||||
Descriptors.FieldDescriptor.JavaType.MESSAGE -> {
|
||||
// Traverse through possible nested messages
|
||||
cache[javaProtoField.messageType.fullName] = TypeDefinition(
|
||||
type = "object",
|
||||
properties = javaProtoField.messageType.fields.map {
|
||||
it.jsonName to fromNestedTypeToSchema(it, cache)
|
||||
}.toMap()
|
||||
)
|
||||
ReferenceDefinition("${Helpers.COMPONENT_SLUG}/${javaProtoField.messageType.name}")
|
||||
}
|
||||
null -> NullableDefinition()
|
||||
}
|
||||
}
|
||||
|
||||
fun checkTypeCache(
|
||||
javaProtoField: Descriptors.FieldDescriptor,
|
||||
cache: MutableMap<String, JsonSchema>
|
||||
): JsonSchema? =
|
||||
when (javaProtoField.javaType) {
|
||||
Descriptors.FieldDescriptor.JavaType.ENUM -> cache[javaProtoField.enumType.name]
|
||||
Descriptors.FieldDescriptor.JavaType.MESSAGE -> cache[javaProtoField.messageType.name]
|
||||
else -> null
|
||||
}
|
@ -0,0 +1,167 @@
|
||||
// Generated by the protocol buffer compiler. DO NOT EDIT!
|
||||
// source: io/bkbn/kompendium/protobufjavaconverter/converters/test.proto
|
||||
|
||||
package io.bkbn.kompendium.protobufjavaconverter;
|
||||
|
||||
/**
|
||||
* Protobuf enum {@code io.bkbn.kompendium.protobufjavaconverter.Corpus}
|
||||
*/
|
||||
public enum Corpus
|
||||
implements com.google.protobuf.ProtocolMessageEnum {
|
||||
/**
|
||||
* <code>CORPUS_UNSPECIFIED = 0;</code>
|
||||
*/
|
||||
CORPUS_UNSPECIFIED(0),
|
||||
/**
|
||||
* <code>CORPUS_UNIVERSAL = 1;</code>
|
||||
*/
|
||||
CORPUS_UNIVERSAL(1),
|
||||
/**
|
||||
* <code>CORPUS_WEB = 2;</code>
|
||||
*/
|
||||
CORPUS_WEB(2),
|
||||
/**
|
||||
* <code>CORPUS_IMAGES = 3;</code>
|
||||
*/
|
||||
CORPUS_IMAGES(3),
|
||||
/**
|
||||
* <code>CORPUS_LOCAL = 4;</code>
|
||||
*/
|
||||
CORPUS_LOCAL(4),
|
||||
/**
|
||||
* <code>CORPUS_NEWS = 5;</code>
|
||||
*/
|
||||
CORPUS_NEWS(5),
|
||||
/**
|
||||
* <code>CORPUS_PRODUCTS = 6;</code>
|
||||
*/
|
||||
CORPUS_PRODUCTS(6),
|
||||
/**
|
||||
* <code>CORPUS_VIDEO = 7;</code>
|
||||
*/
|
||||
CORPUS_VIDEO(7),
|
||||
UNRECOGNIZED(-1),
|
||||
;
|
||||
|
||||
/**
|
||||
* <code>CORPUS_UNSPECIFIED = 0;</code>
|
||||
*/
|
||||
public static final int CORPUS_UNSPECIFIED_VALUE = 0;
|
||||
/**
|
||||
* <code>CORPUS_UNIVERSAL = 1;</code>
|
||||
*/
|
||||
public static final int CORPUS_UNIVERSAL_VALUE = 1;
|
||||
/**
|
||||
* <code>CORPUS_WEB = 2;</code>
|
||||
*/
|
||||
public static final int CORPUS_WEB_VALUE = 2;
|
||||
/**
|
||||
* <code>CORPUS_IMAGES = 3;</code>
|
||||
*/
|
||||
public static final int CORPUS_IMAGES_VALUE = 3;
|
||||
/**
|
||||
* <code>CORPUS_LOCAL = 4;</code>
|
||||
*/
|
||||
public static final int CORPUS_LOCAL_VALUE = 4;
|
||||
/**
|
||||
* <code>CORPUS_NEWS = 5;</code>
|
||||
*/
|
||||
public static final int CORPUS_NEWS_VALUE = 5;
|
||||
/**
|
||||
* <code>CORPUS_PRODUCTS = 6;</code>
|
||||
*/
|
||||
public static final int CORPUS_PRODUCTS_VALUE = 6;
|
||||
/**
|
||||
* <code>CORPUS_VIDEO = 7;</code>
|
||||
*/
|
||||
public static final int CORPUS_VIDEO_VALUE = 7;
|
||||
|
||||
|
||||
public final int getNumber() {
|
||||
if (this == UNRECOGNIZED) {
|
||||
throw new java.lang.IllegalArgumentException(
|
||||
"Can't get the number of an unknown enum value.");
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param value The numeric wire value of the corresponding enum entry.
|
||||
* @return The enum associated with the given numeric wire value.
|
||||
* @deprecated Use {@link #forNumber(int)} instead.
|
||||
*/
|
||||
@java.lang.Deprecated
|
||||
public static Corpus valueOf(int value) {
|
||||
return forNumber(value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param value The numeric wire value of the corresponding enum entry.
|
||||
* @return The enum associated with the given numeric wire value.
|
||||
*/
|
||||
public static Corpus forNumber(int value) {
|
||||
switch (value) {
|
||||
case 0: return CORPUS_UNSPECIFIED;
|
||||
case 1: return CORPUS_UNIVERSAL;
|
||||
case 2: return CORPUS_WEB;
|
||||
case 3: return CORPUS_IMAGES;
|
||||
case 4: return CORPUS_LOCAL;
|
||||
case 5: return CORPUS_NEWS;
|
||||
case 6: return CORPUS_PRODUCTS;
|
||||
case 7: return CORPUS_VIDEO;
|
||||
default: return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static com.google.protobuf.Internal.EnumLiteMap<Corpus>
|
||||
internalGetValueMap() {
|
||||
return internalValueMap;
|
||||
}
|
||||
private static final com.google.protobuf.Internal.EnumLiteMap<
|
||||
Corpus> internalValueMap =
|
||||
new com.google.protobuf.Internal.EnumLiteMap<Corpus>() {
|
||||
public Corpus findValueByNumber(int number) {
|
||||
return Corpus.forNumber(number);
|
||||
}
|
||||
};
|
||||
|
||||
public final com.google.protobuf.Descriptors.EnumValueDescriptor
|
||||
getValueDescriptor() {
|
||||
if (this == UNRECOGNIZED) {
|
||||
throw new java.lang.IllegalStateException(
|
||||
"Can't get the descriptor of an unrecognized enum value.");
|
||||
}
|
||||
return getDescriptor().getValues().get(ordinal());
|
||||
}
|
||||
public final com.google.protobuf.Descriptors.EnumDescriptor
|
||||
getDescriptorForType() {
|
||||
return getDescriptor();
|
||||
}
|
||||
public static final com.google.protobuf.Descriptors.EnumDescriptor
|
||||
getDescriptor() {
|
||||
return io.bkbn.kompendium.protobufjavaconverter.Test.getDescriptor().getEnumTypes().get(0);
|
||||
}
|
||||
|
||||
private static final Corpus[] VALUES = values();
|
||||
|
||||
public static Corpus valueOf(
|
||||
com.google.protobuf.Descriptors.EnumValueDescriptor desc) {
|
||||
if (desc.getType() != getDescriptor()) {
|
||||
throw new java.lang.IllegalArgumentException(
|
||||
"EnumValueDescriptor is not for this type.");
|
||||
}
|
||||
if (desc.getIndex() == -1) {
|
||||
return UNRECOGNIZED;
|
||||
}
|
||||
return VALUES[desc.getIndex()];
|
||||
}
|
||||
|
||||
private final int value;
|
||||
|
||||
private Corpus(int value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
// @@protoc_insertion_point(enum_scope:io.bkbn.kompendium.protobufjavaconverter.Corpus)
|
||||
}
|
||||
|
@ -0,0 +1,607 @@
|
||||
// Generated by the protocol buffer compiler. DO NOT EDIT!
|
||||
// source: io/bkbn/kompendium/protobufjavaconverter/converters/test.proto
|
||||
|
||||
package io.bkbn.kompendium.protobufjavaconverter;
|
||||
|
||||
/**
|
||||
* Protobuf type {@code io.bkbn.kompendium.protobufjavaconverter.DoubleNestedMessage}
|
||||
*/
|
||||
public final class DoubleNestedMessage extends
|
||||
com.google.protobuf.GeneratedMessageV3 implements
|
||||
// @@protoc_insertion_point(message_implements:io.bkbn.kompendium.protobufjavaconverter.DoubleNestedMessage)
|
||||
DoubleNestedMessageOrBuilder {
|
||||
private static final long serialVersionUID = 0L;
|
||||
// Use DoubleNestedMessage.newBuilder() to construct.
|
||||
private DoubleNestedMessage(com.google.protobuf.GeneratedMessageV3.Builder<?> builder) {
|
||||
super(builder);
|
||||
}
|
||||
private DoubleNestedMessage() {
|
||||
}
|
||||
|
||||
@java.lang.Override
|
||||
@SuppressWarnings({"unused"})
|
||||
protected java.lang.Object newInstance(
|
||||
UnusedPrivateParameter unused) {
|
||||
return new DoubleNestedMessage();
|
||||
}
|
||||
|
||||
@java.lang.Override
|
||||
public final com.google.protobuf.UnknownFieldSet
|
||||
getUnknownFields() {
|
||||
return this.unknownFields;
|
||||
}
|
||||
private DoubleNestedMessage(
|
||||
com.google.protobuf.CodedInputStream input,
|
||||
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
|
||||
throws com.google.protobuf.InvalidProtocolBufferException {
|
||||
this();
|
||||
if (extensionRegistry == null) {
|
||||
throw new java.lang.NullPointerException();
|
||||
}
|
||||
com.google.protobuf.UnknownFieldSet.Builder unknownFields =
|
||||
com.google.protobuf.UnknownFieldSet.newBuilder();
|
||||
try {
|
||||
boolean done = false;
|
||||
while (!done) {
|
||||
int tag = input.readTag();
|
||||
switch (tag) {
|
||||
case 0:
|
||||
done = true;
|
||||
break;
|
||||
case 10: {
|
||||
io.bkbn.kompendium.protobufjavaconverter.NestedMessage.Builder subBuilder = null;
|
||||
if (nestedField_ != null) {
|
||||
subBuilder = nestedField_.toBuilder();
|
||||
}
|
||||
nestedField_ = input.readMessage(io.bkbn.kompendium.protobufjavaconverter.NestedMessage.parser(), extensionRegistry);
|
||||
if (subBuilder != null) {
|
||||
subBuilder.mergeFrom(nestedField_);
|
||||
nestedField_ = subBuilder.buildPartial();
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
if (!parseUnknownField(
|
||||
input, unknownFields, extensionRegistry, tag)) {
|
||||
done = true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (com.google.protobuf.InvalidProtocolBufferException e) {
|
||||
throw e.setUnfinishedMessage(this);
|
||||
} catch (java.io.IOException e) {
|
||||
throw new com.google.protobuf.InvalidProtocolBufferException(
|
||||
e).setUnfinishedMessage(this);
|
||||
} finally {
|
||||
this.unknownFields = unknownFields.build();
|
||||
makeExtensionsImmutable();
|
||||
}
|
||||
}
|
||||
public static final com.google.protobuf.Descriptors.Descriptor
|
||||
getDescriptor() {
|
||||
return io.bkbn.kompendium.protobufjavaconverter.Test.internal_static_io_bkbn_kompendium_protobufjavaconverter_DoubleNestedMessage_descriptor;
|
||||
}
|
||||
|
||||
@java.lang.Override
|
||||
protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable
|
||||
internalGetFieldAccessorTable() {
|
||||
return io.bkbn.kompendium.protobufjavaconverter.Test.internal_static_io_bkbn_kompendium_protobufjavaconverter_DoubleNestedMessage_fieldAccessorTable
|
||||
.ensureFieldAccessorsInitialized(
|
||||
io.bkbn.kompendium.protobufjavaconverter.DoubleNestedMessage.class, io.bkbn.kompendium.protobufjavaconverter.DoubleNestedMessage.Builder.class);
|
||||
}
|
||||
|
||||
public static final int NESTED_FIELD_FIELD_NUMBER = 1;
|
||||
private io.bkbn.kompendium.protobufjavaconverter.NestedMessage nestedField_;
|
||||
/**
|
||||
* <code>.io.bkbn.kompendium.protobufjavaconverter.NestedMessage nested_field = 1;</code>
|
||||
* @return Whether the nestedField field is set.
|
||||
*/
|
||||
@java.lang.Override
|
||||
public boolean hasNestedField() {
|
||||
return nestedField_ != null;
|
||||
}
|
||||
/**
|
||||
* <code>.io.bkbn.kompendium.protobufjavaconverter.NestedMessage nested_field = 1;</code>
|
||||
* @return The nestedField.
|
||||
*/
|
||||
@java.lang.Override
|
||||
public io.bkbn.kompendium.protobufjavaconverter.NestedMessage getNestedField() {
|
||||
return nestedField_ == null ? io.bkbn.kompendium.protobufjavaconverter.NestedMessage.getDefaultInstance() : nestedField_;
|
||||
}
|
||||
/**
|
||||
* <code>.io.bkbn.kompendium.protobufjavaconverter.NestedMessage nested_field = 1;</code>
|
||||
*/
|
||||
@java.lang.Override
|
||||
public io.bkbn.kompendium.protobufjavaconverter.NestedMessageOrBuilder getNestedFieldOrBuilder() {
|
||||
return getNestedField();
|
||||
}
|
||||
|
||||
private byte memoizedIsInitialized = -1;
|
||||
@java.lang.Override
|
||||
public final boolean isInitialized() {
|
||||
byte isInitialized = memoizedIsInitialized;
|
||||
if (isInitialized == 1) return true;
|
||||
if (isInitialized == 0) return false;
|
||||
|
||||
memoizedIsInitialized = 1;
|
||||
return true;
|
||||
}
|
||||
|
||||
@java.lang.Override
|
||||
public void writeTo(com.google.protobuf.CodedOutputStream output)
|
||||
throws java.io.IOException {
|
||||
if (nestedField_ != null) {
|
||||
output.writeMessage(1, getNestedField());
|
||||
}
|
||||
unknownFields.writeTo(output);
|
||||
}
|
||||
|
||||
@java.lang.Override
|
||||
public int getSerializedSize() {
|
||||
int size = memoizedSize;
|
||||
if (size != -1) return size;
|
||||
|
||||
size = 0;
|
||||
if (nestedField_ != null) {
|
||||
size += com.google.protobuf.CodedOutputStream
|
||||
.computeMessageSize(1, getNestedField());
|
||||
}
|
||||
size += unknownFields.getSerializedSize();
|
||||
memoizedSize = size;
|
||||
return size;
|
||||
}
|
||||
|
||||
@java.lang.Override
|
||||
public boolean equals(final java.lang.Object obj) {
|
||||
if (obj == this) {
|
||||
return true;
|
||||
}
|
||||
if (!(obj instanceof io.bkbn.kompendium.protobufjavaconverter.DoubleNestedMessage)) {
|
||||
return super.equals(obj);
|
||||
}
|
||||
io.bkbn.kompendium.protobufjavaconverter.DoubleNestedMessage other = (io.bkbn.kompendium.protobufjavaconverter.DoubleNestedMessage) obj;
|
||||
|
||||
if (hasNestedField() != other.hasNestedField()) return false;
|
||||
if (hasNestedField()) {
|
||||
if (!getNestedField()
|
||||
.equals(other.getNestedField())) return false;
|
||||
}
|
||||
if (!unknownFields.equals(other.unknownFields)) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@java.lang.Override
|
||||
public int hashCode() {
|
||||
if (memoizedHashCode != 0) {
|
||||
return memoizedHashCode;
|
||||
}
|
||||
int hash = 41;
|
||||
hash = (19 * hash) + getDescriptor().hashCode();
|
||||
if (hasNestedField()) {
|
||||
hash = (37 * hash) + NESTED_FIELD_FIELD_NUMBER;
|
||||
hash = (53 * hash) + getNestedField().hashCode();
|
||||
}
|
||||
hash = (29 * hash) + unknownFields.hashCode();
|
||||
memoizedHashCode = hash;
|
||||
return hash;
|
||||
}
|
||||
|
||||
public static io.bkbn.kompendium.protobufjavaconverter.DoubleNestedMessage parseFrom(
|
||||
java.nio.ByteBuffer data)
|
||||
throws com.google.protobuf.InvalidProtocolBufferException {
|
||||
return PARSER.parseFrom(data);
|
||||
}
|
||||
public static io.bkbn.kompendium.protobufjavaconverter.DoubleNestedMessage parseFrom(
|
||||
java.nio.ByteBuffer data,
|
||||
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
|
||||
throws com.google.protobuf.InvalidProtocolBufferException {
|
||||
return PARSER.parseFrom(data, extensionRegistry);
|
||||
}
|
||||
public static io.bkbn.kompendium.protobufjavaconverter.DoubleNestedMessage parseFrom(
|
||||
com.google.protobuf.ByteString data)
|
||||
throws com.google.protobuf.InvalidProtocolBufferException {
|
||||
return PARSER.parseFrom(data);
|
||||
}
|
||||
public static io.bkbn.kompendium.protobufjavaconverter.DoubleNestedMessage parseFrom(
|
||||
com.google.protobuf.ByteString data,
|
||||
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
|
||||
throws com.google.protobuf.InvalidProtocolBufferException {
|
||||
return PARSER.parseFrom(data, extensionRegistry);
|
||||
}
|
||||
public static io.bkbn.kompendium.protobufjavaconverter.DoubleNestedMessage parseFrom(byte[] data)
|
||||
throws com.google.protobuf.InvalidProtocolBufferException {
|
||||
return PARSER.parseFrom(data);
|
||||
}
|
||||
public static io.bkbn.kompendium.protobufjavaconverter.DoubleNestedMessage parseFrom(
|
||||
byte[] data,
|
||||
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
|
||||
throws com.google.protobuf.InvalidProtocolBufferException {
|
||||
return PARSER.parseFrom(data, extensionRegistry);
|
||||
}
|
||||
public static io.bkbn.kompendium.protobufjavaconverter.DoubleNestedMessage parseFrom(java.io.InputStream input)
|
||||
throws java.io.IOException {
|
||||
return com.google.protobuf.GeneratedMessageV3
|
||||
.parseWithIOException(PARSER, input);
|
||||
}
|
||||
public static io.bkbn.kompendium.protobufjavaconverter.DoubleNestedMessage parseFrom(
|
||||
java.io.InputStream input,
|
||||
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
|
||||
throws java.io.IOException {
|
||||
return com.google.protobuf.GeneratedMessageV3
|
||||
.parseWithIOException(PARSER, input, extensionRegistry);
|
||||
}
|
||||
public static io.bkbn.kompendium.protobufjavaconverter.DoubleNestedMessage parseDelimitedFrom(java.io.InputStream input)
|
||||
throws java.io.IOException {
|
||||
return com.google.protobuf.GeneratedMessageV3
|
||||
.parseDelimitedWithIOException(PARSER, input);
|
||||
}
|
||||
public static io.bkbn.kompendium.protobufjavaconverter.DoubleNestedMessage parseDelimitedFrom(
|
||||
java.io.InputStream input,
|
||||
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
|
||||
throws java.io.IOException {
|
||||
return com.google.protobuf.GeneratedMessageV3
|
||||
.parseDelimitedWithIOException(PARSER, input, extensionRegistry);
|
||||
}
|
||||
public static io.bkbn.kompendium.protobufjavaconverter.DoubleNestedMessage parseFrom(
|
||||
com.google.protobuf.CodedInputStream input)
|
||||
throws java.io.IOException {
|
||||
return com.google.protobuf.GeneratedMessageV3
|
||||
.parseWithIOException(PARSER, input);
|
||||
}
|
||||
public static io.bkbn.kompendium.protobufjavaconverter.DoubleNestedMessage parseFrom(
|
||||
com.google.protobuf.CodedInputStream input,
|
||||
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
|
||||
throws java.io.IOException {
|
||||
return com.google.protobuf.GeneratedMessageV3
|
||||
.parseWithIOException(PARSER, input, extensionRegistry);
|
||||
}
|
||||
|
||||
@java.lang.Override
|
||||
public Builder newBuilderForType() { return newBuilder(); }
|
||||
public static Builder newBuilder() {
|
||||
return DEFAULT_INSTANCE.toBuilder();
|
||||
}
|
||||
public static Builder newBuilder(io.bkbn.kompendium.protobufjavaconverter.DoubleNestedMessage prototype) {
|
||||
return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype);
|
||||
}
|
||||
@java.lang.Override
|
||||
public Builder toBuilder() {
|
||||
return this == DEFAULT_INSTANCE
|
||||
? new Builder() : new Builder().mergeFrom(this);
|
||||
}
|
||||
|
||||
@java.lang.Override
|
||||
protected Builder newBuilderForType(
|
||||
com.google.protobuf.GeneratedMessageV3.BuilderParent parent) {
|
||||
Builder builder = new Builder(parent);
|
||||
return builder;
|
||||
}
|
||||
/**
|
||||
* Protobuf type {@code io.bkbn.kompendium.protobufjavaconverter.DoubleNestedMessage}
|
||||
*/
|
||||
public static final class Builder extends
|
||||
com.google.protobuf.GeneratedMessageV3.Builder<Builder> implements
|
||||
// @@protoc_insertion_point(builder_implements:io.bkbn.kompendium.protobufjavaconverter.DoubleNestedMessage)
|
||||
io.bkbn.kompendium.protobufjavaconverter.DoubleNestedMessageOrBuilder {
|
||||
public static final com.google.protobuf.Descriptors.Descriptor
|
||||
getDescriptor() {
|
||||
return io.bkbn.kompendium.protobufjavaconverter.Test.internal_static_io_bkbn_kompendium_protobufjavaconverter_DoubleNestedMessage_descriptor;
|
||||
}
|
||||
|
||||
@java.lang.Override
|
||||
protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable
|
||||
internalGetFieldAccessorTable() {
|
||||
return io.bkbn.kompendium.protobufjavaconverter.Test.internal_static_io_bkbn_kompendium_protobufjavaconverter_DoubleNestedMessage_fieldAccessorTable
|
||||
.ensureFieldAccessorsInitialized(
|
||||
io.bkbn.kompendium.protobufjavaconverter.DoubleNestedMessage.class, io.bkbn.kompendium.protobufjavaconverter.DoubleNestedMessage.Builder.class);
|
||||
}
|
||||
|
||||
// Construct using io.bkbn.kompendium.protobufjavaconverter.DoubleNestedMessage.newBuilder()
|
||||
private Builder() {
|
||||
maybeForceBuilderInitialization();
|
||||
}
|
||||
|
||||
private Builder(
|
||||
com.google.protobuf.GeneratedMessageV3.BuilderParent parent) {
|
||||
super(parent);
|
||||
maybeForceBuilderInitialization();
|
||||
}
|
||||
private void maybeForceBuilderInitialization() {
|
||||
if (com.google.protobuf.GeneratedMessageV3
|
||||
.alwaysUseFieldBuilders) {
|
||||
}
|
||||
}
|
||||
@java.lang.Override
|
||||
public Builder clear() {
|
||||
super.clear();
|
||||
if (nestedFieldBuilder_ == null) {
|
||||
nestedField_ = null;
|
||||
} else {
|
||||
nestedField_ = null;
|
||||
nestedFieldBuilder_ = null;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
@java.lang.Override
|
||||
public com.google.protobuf.Descriptors.Descriptor
|
||||
getDescriptorForType() {
|
||||
return io.bkbn.kompendium.protobufjavaconverter.Test.internal_static_io_bkbn_kompendium_protobufjavaconverter_DoubleNestedMessage_descriptor;
|
||||
}
|
||||
|
||||
@java.lang.Override
|
||||
public io.bkbn.kompendium.protobufjavaconverter.DoubleNestedMessage getDefaultInstanceForType() {
|
||||
return io.bkbn.kompendium.protobufjavaconverter.DoubleNestedMessage.getDefaultInstance();
|
||||
}
|
||||
|
||||
@java.lang.Override
|
||||
public io.bkbn.kompendium.protobufjavaconverter.DoubleNestedMessage build() {
|
||||
io.bkbn.kompendium.protobufjavaconverter.DoubleNestedMessage result = buildPartial();
|
||||
if (!result.isInitialized()) {
|
||||
throw newUninitializedMessageException(result);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@java.lang.Override
|
||||
public io.bkbn.kompendium.protobufjavaconverter.DoubleNestedMessage buildPartial() {
|
||||
io.bkbn.kompendium.protobufjavaconverter.DoubleNestedMessage result = new io.bkbn.kompendium.protobufjavaconverter.DoubleNestedMessage(this);
|
||||
if (nestedFieldBuilder_ == null) {
|
||||
result.nestedField_ = nestedField_;
|
||||
} else {
|
||||
result.nestedField_ = nestedFieldBuilder_.build();
|
||||
}
|
||||
onBuilt();
|
||||
return result;
|
||||
}
|
||||
|
||||
@java.lang.Override
|
||||
public Builder clone() {
|
||||
return super.clone();
|
||||
}
|
||||
@java.lang.Override
|
||||
public Builder setField(
|
||||
com.google.protobuf.Descriptors.FieldDescriptor field,
|
||||
java.lang.Object value) {
|
||||
return super.setField(field, value);
|
||||
}
|
||||
@java.lang.Override
|
||||
public Builder clearField(
|
||||
com.google.protobuf.Descriptors.FieldDescriptor field) {
|
||||
return super.clearField(field);
|
||||
}
|
||||
@java.lang.Override
|
||||
public Builder clearOneof(
|
||||
com.google.protobuf.Descriptors.OneofDescriptor oneof) {
|
||||
return super.clearOneof(oneof);
|
||||
}
|
||||
@java.lang.Override
|
||||
public Builder setRepeatedField(
|
||||
com.google.protobuf.Descriptors.FieldDescriptor field,
|
||||
int index, java.lang.Object value) {
|
||||
return super.setRepeatedField(field, index, value);
|
||||
}
|
||||
@java.lang.Override
|
||||
public Builder addRepeatedField(
|
||||
com.google.protobuf.Descriptors.FieldDescriptor field,
|
||||
java.lang.Object value) {
|
||||
return super.addRepeatedField(field, value);
|
||||
}
|
||||
@java.lang.Override
|
||||
public Builder mergeFrom(com.google.protobuf.Message other) {
|
||||
if (other instanceof io.bkbn.kompendium.protobufjavaconverter.DoubleNestedMessage) {
|
||||
return mergeFrom((io.bkbn.kompendium.protobufjavaconverter.DoubleNestedMessage)other);
|
||||
} else {
|
||||
super.mergeFrom(other);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
public Builder mergeFrom(io.bkbn.kompendium.protobufjavaconverter.DoubleNestedMessage other) {
|
||||
if (other == io.bkbn.kompendium.protobufjavaconverter.DoubleNestedMessage.getDefaultInstance()) return this;
|
||||
if (other.hasNestedField()) {
|
||||
mergeNestedField(other.getNestedField());
|
||||
}
|
||||
this.mergeUnknownFields(other.unknownFields);
|
||||
onChanged();
|
||||
return this;
|
||||
}
|
||||
|
||||
@java.lang.Override
|
||||
public final boolean isInitialized() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@java.lang.Override
|
||||
public Builder mergeFrom(
|
||||
com.google.protobuf.CodedInputStream input,
|
||||
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
|
||||
throws java.io.IOException {
|
||||
io.bkbn.kompendium.protobufjavaconverter.DoubleNestedMessage parsedMessage = null;
|
||||
try {
|
||||
parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry);
|
||||
} catch (com.google.protobuf.InvalidProtocolBufferException e) {
|
||||
parsedMessage = (io.bkbn.kompendium.protobufjavaconverter.DoubleNestedMessage) e.getUnfinishedMessage();
|
||||
throw e.unwrapIOException();
|
||||
} finally {
|
||||
if (parsedMessage != null) {
|
||||
mergeFrom(parsedMessage);
|
||||
}
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
private io.bkbn.kompendium.protobufjavaconverter.NestedMessage nestedField_;
|
||||
private com.google.protobuf.SingleFieldBuilderV3<
|
||||
io.bkbn.kompendium.protobufjavaconverter.NestedMessage, io.bkbn.kompendium.protobufjavaconverter.NestedMessage.Builder, io.bkbn.kompendium.protobufjavaconverter.NestedMessageOrBuilder> nestedFieldBuilder_;
|
||||
/**
|
||||
* <code>.io.bkbn.kompendium.protobufjavaconverter.NestedMessage nested_field = 1;</code>
|
||||
* @return Whether the nestedField field is set.
|
||||
*/
|
||||
public boolean hasNestedField() {
|
||||
return nestedFieldBuilder_ != null || nestedField_ != null;
|
||||
}
|
||||
/**
|
||||
* <code>.io.bkbn.kompendium.protobufjavaconverter.NestedMessage nested_field = 1;</code>
|
||||
* @return The nestedField.
|
||||
*/
|
||||
public io.bkbn.kompendium.protobufjavaconverter.NestedMessage getNestedField() {
|
||||
if (nestedFieldBuilder_ == null) {
|
||||
return nestedField_ == null ? io.bkbn.kompendium.protobufjavaconverter.NestedMessage.getDefaultInstance() : nestedField_;
|
||||
} else {
|
||||
return nestedFieldBuilder_.getMessage();
|
||||
}
|
||||
}
|
||||
/**
|
||||
* <code>.io.bkbn.kompendium.protobufjavaconverter.NestedMessage nested_field = 1;</code>
|
||||
*/
|
||||
public Builder setNestedField(io.bkbn.kompendium.protobufjavaconverter.NestedMessage value) {
|
||||
if (nestedFieldBuilder_ == null) {
|
||||
if (value == null) {
|
||||
throw new NullPointerException();
|
||||
}
|
||||
nestedField_ = value;
|
||||
onChanged();
|
||||
} else {
|
||||
nestedFieldBuilder_.setMessage(value);
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* <code>.io.bkbn.kompendium.protobufjavaconverter.NestedMessage nested_field = 1;</code>
|
||||
*/
|
||||
public Builder setNestedField(
|
||||
io.bkbn.kompendium.protobufjavaconverter.NestedMessage.Builder builderForValue) {
|
||||
if (nestedFieldBuilder_ == null) {
|
||||
nestedField_ = builderForValue.build();
|
||||
onChanged();
|
||||
} else {
|
||||
nestedFieldBuilder_.setMessage(builderForValue.build());
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* <code>.io.bkbn.kompendium.protobufjavaconverter.NestedMessage nested_field = 1;</code>
|
||||
*/
|
||||
public Builder mergeNestedField(io.bkbn.kompendium.protobufjavaconverter.NestedMessage value) {
|
||||
if (nestedFieldBuilder_ == null) {
|
||||
if (nestedField_ != null) {
|
||||
nestedField_ =
|
||||
io.bkbn.kompendium.protobufjavaconverter.NestedMessage.newBuilder(nestedField_).mergeFrom(value).buildPartial();
|
||||
} else {
|
||||
nestedField_ = value;
|
||||
}
|
||||
onChanged();
|
||||
} else {
|
||||
nestedFieldBuilder_.mergeFrom(value);
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* <code>.io.bkbn.kompendium.protobufjavaconverter.NestedMessage nested_field = 1;</code>
|
||||
*/
|
||||
public Builder clearNestedField() {
|
||||
if (nestedFieldBuilder_ == null) {
|
||||
nestedField_ = null;
|
||||
onChanged();
|
||||
} else {
|
||||
nestedField_ = null;
|
||||
nestedFieldBuilder_ = null;
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* <code>.io.bkbn.kompendium.protobufjavaconverter.NestedMessage nested_field = 1;</code>
|
||||
*/
|
||||
public io.bkbn.kompendium.protobufjavaconverter.NestedMessage.Builder getNestedFieldBuilder() {
|
||||
|
||||
onChanged();
|
||||
return getNestedFieldFieldBuilder().getBuilder();
|
||||
}
|
||||
/**
|
||||
* <code>.io.bkbn.kompendium.protobufjavaconverter.NestedMessage nested_field = 1;</code>
|
||||
*/
|
||||
public io.bkbn.kompendium.protobufjavaconverter.NestedMessageOrBuilder getNestedFieldOrBuilder() {
|
||||
if (nestedFieldBuilder_ != null) {
|
||||
return nestedFieldBuilder_.getMessageOrBuilder();
|
||||
} else {
|
||||
return nestedField_ == null ?
|
||||
io.bkbn.kompendium.protobufjavaconverter.NestedMessage.getDefaultInstance() : nestedField_;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* <code>.io.bkbn.kompendium.protobufjavaconverter.NestedMessage nested_field = 1;</code>
|
||||
*/
|
||||
private com.google.protobuf.SingleFieldBuilderV3<
|
||||
io.bkbn.kompendium.protobufjavaconverter.NestedMessage, io.bkbn.kompendium.protobufjavaconverter.NestedMessage.Builder, io.bkbn.kompendium.protobufjavaconverter.NestedMessageOrBuilder>
|
||||
getNestedFieldFieldBuilder() {
|
||||
if (nestedFieldBuilder_ == null) {
|
||||
nestedFieldBuilder_ = new com.google.protobuf.SingleFieldBuilderV3<
|
||||
io.bkbn.kompendium.protobufjavaconverter.NestedMessage, io.bkbn.kompendium.protobufjavaconverter.NestedMessage.Builder, io.bkbn.kompendium.protobufjavaconverter.NestedMessageOrBuilder>(
|
||||
getNestedField(),
|
||||
getParentForChildren(),
|
||||
isClean());
|
||||
nestedField_ = null;
|
||||
}
|
||||
return nestedFieldBuilder_;
|
||||
}
|
||||
@java.lang.Override
|
||||
public final Builder setUnknownFields(
|
||||
final com.google.protobuf.UnknownFieldSet unknownFields) {
|
||||
return super.setUnknownFields(unknownFields);
|
||||
}
|
||||
|
||||
@java.lang.Override
|
||||
public final Builder mergeUnknownFields(
|
||||
final com.google.protobuf.UnknownFieldSet unknownFields) {
|
||||
return super.mergeUnknownFields(unknownFields);
|
||||
}
|
||||
|
||||
|
||||
// @@protoc_insertion_point(builder_scope:io.bkbn.kompendium.protobufjavaconverter.DoubleNestedMessage)
|
||||
}
|
||||
|
||||
// @@protoc_insertion_point(class_scope:io.bkbn.kompendium.protobufjavaconverter.DoubleNestedMessage)
|
||||
private static final io.bkbn.kompendium.protobufjavaconverter.DoubleNestedMessage DEFAULT_INSTANCE;
|
||||
static {
|
||||
DEFAULT_INSTANCE = new io.bkbn.kompendium.protobufjavaconverter.DoubleNestedMessage();
|
||||
}
|
||||
|
||||
public static io.bkbn.kompendium.protobufjavaconverter.DoubleNestedMessage getDefaultInstance() {
|
||||
return DEFAULT_INSTANCE;
|
||||
}
|
||||
|
||||
private static final com.google.protobuf.Parser<DoubleNestedMessage>
|
||||
PARSER = new com.google.protobuf.AbstractParser<DoubleNestedMessage>() {
|
||||
@java.lang.Override
|
||||
public DoubleNestedMessage parsePartialFrom(
|
||||
com.google.protobuf.CodedInputStream input,
|
||||
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
|
||||
throws com.google.protobuf.InvalidProtocolBufferException {
|
||||
return new DoubleNestedMessage(input, extensionRegistry);
|
||||
}
|
||||
};
|
||||
|
||||
public static com.google.protobuf.Parser<DoubleNestedMessage> parser() {
|
||||
return PARSER;
|
||||
}
|
||||
|
||||
@java.lang.Override
|
||||
public com.google.protobuf.Parser<DoubleNestedMessage> getParserForType() {
|
||||
return PARSER;
|
||||
}
|
||||
|
||||
@java.lang.Override
|
||||
public io.bkbn.kompendium.protobufjavaconverter.DoubleNestedMessage getDefaultInstanceForType() {
|
||||
return DEFAULT_INSTANCE;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,24 @@
|
||||
// Generated by the protocol buffer compiler. DO NOT EDIT!
|
||||
// source: io/bkbn/kompendium/protobufjavaconverter/converters/test.proto
|
||||
|
||||
package io.bkbn.kompendium.protobufjavaconverter;
|
||||
|
||||
public interface DoubleNestedMessageOrBuilder extends
|
||||
// @@protoc_insertion_point(interface_extends:io.bkbn.kompendium.protobufjavaconverter.DoubleNestedMessage)
|
||||
com.google.protobuf.MessageOrBuilder {
|
||||
|
||||
/**
|
||||
* <code>.io.bkbn.kompendium.protobufjavaconverter.NestedMessage nested_field = 1;</code>
|
||||
* @return Whether the nestedField field is set.
|
||||
*/
|
||||
boolean hasNestedField();
|
||||
/**
|
||||
* <code>.io.bkbn.kompendium.protobufjavaconverter.NestedMessage nested_field = 1;</code>
|
||||
* @return The nestedField.
|
||||
*/
|
||||
io.bkbn.kompendium.protobufjavaconverter.NestedMessage getNestedField();
|
||||
/**
|
||||
* <code>.io.bkbn.kompendium.protobufjavaconverter.NestedMessage nested_field = 1;</code>
|
||||
*/
|
||||
io.bkbn.kompendium.protobufjavaconverter.NestedMessageOrBuilder getNestedFieldOrBuilder();
|
||||
}
|
@ -0,0 +1,515 @@
|
||||
// Generated by the protocol buffer compiler. DO NOT EDIT!
|
||||
// source: io/bkbn/kompendium/protobufjavaconverter/converters/test.proto
|
||||
|
||||
package io.bkbn.kompendium.protobufjavaconverter;
|
||||
|
||||
/**
|
||||
* Protobuf type {@code io.bkbn.kompendium.protobufjavaconverter.EnumMessage}
|
||||
*/
|
||||
public final class EnumMessage extends
|
||||
com.google.protobuf.GeneratedMessageV3 implements
|
||||
// @@protoc_insertion_point(message_implements:io.bkbn.kompendium.protobufjavaconverter.EnumMessage)
|
||||
EnumMessageOrBuilder {
|
||||
private static final long serialVersionUID = 0L;
|
||||
// Use EnumMessage.newBuilder() to construct.
|
||||
private EnumMessage(com.google.protobuf.GeneratedMessageV3.Builder<?> builder) {
|
||||
super(builder);
|
||||
}
|
||||
private EnumMessage() {
|
||||
corpus_ = 0;
|
||||
}
|
||||
|
||||
@java.lang.Override
|
||||
@SuppressWarnings({"unused"})
|
||||
protected java.lang.Object newInstance(
|
||||
UnusedPrivateParameter unused) {
|
||||
return new EnumMessage();
|
||||
}
|
||||
|
||||
@java.lang.Override
|
||||
public final com.google.protobuf.UnknownFieldSet
|
||||
getUnknownFields() {
|
||||
return this.unknownFields;
|
||||
}
|
||||
private EnumMessage(
|
||||
com.google.protobuf.CodedInputStream input,
|
||||
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
|
||||
throws com.google.protobuf.InvalidProtocolBufferException {
|
||||
this();
|
||||
if (extensionRegistry == null) {
|
||||
throw new java.lang.NullPointerException();
|
||||
}
|
||||
com.google.protobuf.UnknownFieldSet.Builder unknownFields =
|
||||
com.google.protobuf.UnknownFieldSet.newBuilder();
|
||||
try {
|
||||
boolean done = false;
|
||||
while (!done) {
|
||||
int tag = input.readTag();
|
||||
switch (tag) {
|
||||
case 0:
|
||||
done = true;
|
||||
break;
|
||||
case 8: {
|
||||
int rawValue = input.readEnum();
|
||||
|
||||
corpus_ = rawValue;
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
if (!parseUnknownField(
|
||||
input, unknownFields, extensionRegistry, tag)) {
|
||||
done = true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (com.google.protobuf.InvalidProtocolBufferException e) {
|
||||
throw e.setUnfinishedMessage(this);
|
||||
} catch (java.io.IOException e) {
|
||||
throw new com.google.protobuf.InvalidProtocolBufferException(
|
||||
e).setUnfinishedMessage(this);
|
||||
} finally {
|
||||
this.unknownFields = unknownFields.build();
|
||||
makeExtensionsImmutable();
|
||||
}
|
||||
}
|
||||
public static final com.google.protobuf.Descriptors.Descriptor
|
||||
getDescriptor() {
|
||||
return io.bkbn.kompendium.protobufjavaconverter.Test.internal_static_io_bkbn_kompendium_protobufjavaconverter_EnumMessage_descriptor;
|
||||
}
|
||||
|
||||
@java.lang.Override
|
||||
protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable
|
||||
internalGetFieldAccessorTable() {
|
||||
return io.bkbn.kompendium.protobufjavaconverter.Test.internal_static_io_bkbn_kompendium_protobufjavaconverter_EnumMessage_fieldAccessorTable
|
||||
.ensureFieldAccessorsInitialized(
|
||||
io.bkbn.kompendium.protobufjavaconverter.EnumMessage.class, io.bkbn.kompendium.protobufjavaconverter.EnumMessage.Builder.class);
|
||||
}
|
||||
|
||||
public static final int CORPUS_FIELD_NUMBER = 1;
|
||||
private int corpus_;
|
||||
/**
|
||||
* <code>.io.bkbn.kompendium.protobufjavaconverter.Corpus corpus = 1;</code>
|
||||
* @return The enum numeric value on the wire for corpus.
|
||||
*/
|
||||
@java.lang.Override public int getCorpusValue() {
|
||||
return corpus_;
|
||||
}
|
||||
/**
|
||||
* <code>.io.bkbn.kompendium.protobufjavaconverter.Corpus corpus = 1;</code>
|
||||
* @return The corpus.
|
||||
*/
|
||||
@java.lang.Override public io.bkbn.kompendium.protobufjavaconverter.Corpus getCorpus() {
|
||||
@SuppressWarnings("deprecation")
|
||||
io.bkbn.kompendium.protobufjavaconverter.Corpus result = io.bkbn.kompendium.protobufjavaconverter.Corpus.valueOf(corpus_);
|
||||
return result == null ? io.bkbn.kompendium.protobufjavaconverter.Corpus.UNRECOGNIZED : result;
|
||||
}
|
||||
|
||||
private byte memoizedIsInitialized = -1;
|
||||
@java.lang.Override
|
||||
public final boolean isInitialized() {
|
||||
byte isInitialized = memoizedIsInitialized;
|
||||
if (isInitialized == 1) return true;
|
||||
if (isInitialized == 0) return false;
|
||||
|
||||
memoizedIsInitialized = 1;
|
||||
return true;
|
||||
}
|
||||
|
||||
@java.lang.Override
|
||||
public void writeTo(com.google.protobuf.CodedOutputStream output)
|
||||
throws java.io.IOException {
|
||||
if (corpus_ != io.bkbn.kompendium.protobufjavaconverter.Corpus.CORPUS_UNSPECIFIED.getNumber()) {
|
||||
output.writeEnum(1, corpus_);
|
||||
}
|
||||
unknownFields.writeTo(output);
|
||||
}
|
||||
|
||||
@java.lang.Override
|
||||
public int getSerializedSize() {
|
||||
int size = memoizedSize;
|
||||
if (size != -1) return size;
|
||||
|
||||
size = 0;
|
||||
if (corpus_ != io.bkbn.kompendium.protobufjavaconverter.Corpus.CORPUS_UNSPECIFIED.getNumber()) {
|
||||
size += com.google.protobuf.CodedOutputStream
|
||||
.computeEnumSize(1, corpus_);
|
||||
}
|
||||
size += unknownFields.getSerializedSize();
|
||||
memoizedSize = size;
|
||||
return size;
|
||||
}
|
||||
|
||||
@java.lang.Override
|
||||
public boolean equals(final java.lang.Object obj) {
|
||||
if (obj == this) {
|
||||
return true;
|
||||
}
|
||||
if (!(obj instanceof io.bkbn.kompendium.protobufjavaconverter.EnumMessage)) {
|
||||
return super.equals(obj);
|
||||
}
|
||||
io.bkbn.kompendium.protobufjavaconverter.EnumMessage other = (io.bkbn.kompendium.protobufjavaconverter.EnumMessage) obj;
|
||||
|
||||
if (corpus_ != other.corpus_) return false;
|
||||
if (!unknownFields.equals(other.unknownFields)) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@java.lang.Override
|
||||
public int hashCode() {
|
||||
if (memoizedHashCode != 0) {
|
||||
return memoizedHashCode;
|
||||
}
|
||||
int hash = 41;
|
||||
hash = (19 * hash) + getDescriptor().hashCode();
|
||||
hash = (37 * hash) + CORPUS_FIELD_NUMBER;
|
||||
hash = (53 * hash) + corpus_;
|
||||
hash = (29 * hash) + unknownFields.hashCode();
|
||||
memoizedHashCode = hash;
|
||||
return hash;
|
||||
}
|
||||
|
||||
public static io.bkbn.kompendium.protobufjavaconverter.EnumMessage parseFrom(
|
||||
java.nio.ByteBuffer data)
|
||||
throws com.google.protobuf.InvalidProtocolBufferException {
|
||||
return PARSER.parseFrom(data);
|
||||
}
|
||||
public static io.bkbn.kompendium.protobufjavaconverter.EnumMessage parseFrom(
|
||||
java.nio.ByteBuffer data,
|
||||
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
|
||||
throws com.google.protobuf.InvalidProtocolBufferException {
|
||||
return PARSER.parseFrom(data, extensionRegistry);
|
||||
}
|
||||
public static io.bkbn.kompendium.protobufjavaconverter.EnumMessage parseFrom(
|
||||
com.google.protobuf.ByteString data)
|
||||
throws com.google.protobuf.InvalidProtocolBufferException {
|
||||
return PARSER.parseFrom(data);
|
||||
}
|
||||
public static io.bkbn.kompendium.protobufjavaconverter.EnumMessage parseFrom(
|
||||
com.google.protobuf.ByteString data,
|
||||
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
|
||||
throws com.google.protobuf.InvalidProtocolBufferException {
|
||||
return PARSER.parseFrom(data, extensionRegistry);
|
||||
}
|
||||
public static io.bkbn.kompendium.protobufjavaconverter.EnumMessage parseFrom(byte[] data)
|
||||
throws com.google.protobuf.InvalidProtocolBufferException {
|
||||
return PARSER.parseFrom(data);
|
||||
}
|
||||
public static io.bkbn.kompendium.protobufjavaconverter.EnumMessage parseFrom(
|
||||
byte[] data,
|
||||
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
|
||||
throws com.google.protobuf.InvalidProtocolBufferException {
|
||||
return PARSER.parseFrom(data, extensionRegistry);
|
||||
}
|
||||
public static io.bkbn.kompendium.protobufjavaconverter.EnumMessage parseFrom(java.io.InputStream input)
|
||||
throws java.io.IOException {
|
||||
return com.google.protobuf.GeneratedMessageV3
|
||||
.parseWithIOException(PARSER, input);
|
||||
}
|
||||
public static io.bkbn.kompendium.protobufjavaconverter.EnumMessage parseFrom(
|
||||
java.io.InputStream input,
|
||||
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
|
||||
throws java.io.IOException {
|
||||
return com.google.protobuf.GeneratedMessageV3
|
||||
.parseWithIOException(PARSER, input, extensionRegistry);
|
||||
}
|
||||
public static io.bkbn.kompendium.protobufjavaconverter.EnumMessage parseDelimitedFrom(java.io.InputStream input)
|
||||
throws java.io.IOException {
|
||||
return com.google.protobuf.GeneratedMessageV3
|
||||
.parseDelimitedWithIOException(PARSER, input);
|
||||
}
|
||||
public static io.bkbn.kompendium.protobufjavaconverter.EnumMessage parseDelimitedFrom(
|
||||
java.io.InputStream input,
|
||||
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
|
||||
throws java.io.IOException {
|
||||
return com.google.protobuf.GeneratedMessageV3
|
||||
.parseDelimitedWithIOException(PARSER, input, extensionRegistry);
|
||||
}
|
||||
public static io.bkbn.kompendium.protobufjavaconverter.EnumMessage parseFrom(
|
||||
com.google.protobuf.CodedInputStream input)
|
||||
throws java.io.IOException {
|
||||
return com.google.protobuf.GeneratedMessageV3
|
||||
.parseWithIOException(PARSER, input);
|
||||
}
|
||||
public static io.bkbn.kompendium.protobufjavaconverter.EnumMessage parseFrom(
|
||||
com.google.protobuf.CodedInputStream input,
|
||||
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
|
||||
throws java.io.IOException {
|
||||
return com.google.protobuf.GeneratedMessageV3
|
||||
.parseWithIOException(PARSER, input, extensionRegistry);
|
||||
}
|
||||
|
||||
@java.lang.Override
|
||||
public Builder newBuilderForType() { return newBuilder(); }
|
||||
public static Builder newBuilder() {
|
||||
return DEFAULT_INSTANCE.toBuilder();
|
||||
}
|
||||
public static Builder newBuilder(io.bkbn.kompendium.protobufjavaconverter.EnumMessage prototype) {
|
||||
return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype);
|
||||
}
|
||||
@java.lang.Override
|
||||
public Builder toBuilder() {
|
||||
return this == DEFAULT_INSTANCE
|
||||
? new Builder() : new Builder().mergeFrom(this);
|
||||
}
|
||||
|
||||
@java.lang.Override
|
||||
protected Builder newBuilderForType(
|
||||
com.google.protobuf.GeneratedMessageV3.BuilderParent parent) {
|
||||
Builder builder = new Builder(parent);
|
||||
return builder;
|
||||
}
|
||||
/**
|
||||
* Protobuf type {@code io.bkbn.kompendium.protobufjavaconverter.EnumMessage}
|
||||
*/
|
||||
public static final class Builder extends
|
||||
com.google.protobuf.GeneratedMessageV3.Builder<Builder> implements
|
||||
// @@protoc_insertion_point(builder_implements:io.bkbn.kompendium.protobufjavaconverter.EnumMessage)
|
||||
io.bkbn.kompendium.protobufjavaconverter.EnumMessageOrBuilder {
|
||||
public static final com.google.protobuf.Descriptors.Descriptor
|
||||
getDescriptor() {
|
||||
return io.bkbn.kompendium.protobufjavaconverter.Test.internal_static_io_bkbn_kompendium_protobufjavaconverter_EnumMessage_descriptor;
|
||||
}
|
||||
|
||||
@java.lang.Override
|
||||
protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable
|
||||
internalGetFieldAccessorTable() {
|
||||
return io.bkbn.kompendium.protobufjavaconverter.Test.internal_static_io_bkbn_kompendium_protobufjavaconverter_EnumMessage_fieldAccessorTable
|
||||
.ensureFieldAccessorsInitialized(
|
||||
io.bkbn.kompendium.protobufjavaconverter.EnumMessage.class, io.bkbn.kompendium.protobufjavaconverter.EnumMessage.Builder.class);
|
||||
}
|
||||
|
||||
// Construct using io.bkbn.kompendium.protobufjavaconverter.EnumMessage.newBuilder()
|
||||
private Builder() {
|
||||
maybeForceBuilderInitialization();
|
||||
}
|
||||
|
||||
private Builder(
|
||||
com.google.protobuf.GeneratedMessageV3.BuilderParent parent) {
|
||||
super(parent);
|
||||
maybeForceBuilderInitialization();
|
||||
}
|
||||
private void maybeForceBuilderInitialization() {
|
||||
if (com.google.protobuf.GeneratedMessageV3
|
||||
.alwaysUseFieldBuilders) {
|
||||
}
|
||||
}
|
||||
@java.lang.Override
|
||||
public Builder clear() {
|
||||
super.clear();
|
||||
corpus_ = 0;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@java.lang.Override
|
||||
public com.google.protobuf.Descriptors.Descriptor
|
||||
getDescriptorForType() {
|
||||
return io.bkbn.kompendium.protobufjavaconverter.Test.internal_static_io_bkbn_kompendium_protobufjavaconverter_EnumMessage_descriptor;
|
||||
}
|
||||
|
||||
@java.lang.Override
|
||||
public io.bkbn.kompendium.protobufjavaconverter.EnumMessage getDefaultInstanceForType() {
|
||||
return io.bkbn.kompendium.protobufjavaconverter.EnumMessage.getDefaultInstance();
|
||||
}
|
||||
|
||||
@java.lang.Override
|
||||
public io.bkbn.kompendium.protobufjavaconverter.EnumMessage build() {
|
||||
io.bkbn.kompendium.protobufjavaconverter.EnumMessage result = buildPartial();
|
||||
if (!result.isInitialized()) {
|
||||
throw newUninitializedMessageException(result);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@java.lang.Override
|
||||
public io.bkbn.kompendium.protobufjavaconverter.EnumMessage buildPartial() {
|
||||
io.bkbn.kompendium.protobufjavaconverter.EnumMessage result = new io.bkbn.kompendium.protobufjavaconverter.EnumMessage(this);
|
||||
result.corpus_ = corpus_;
|
||||
onBuilt();
|
||||
return result;
|
||||
}
|
||||
|
||||
@java.lang.Override
|
||||
public Builder clone() {
|
||||
return super.clone();
|
||||
}
|
||||
@java.lang.Override
|
||||
public Builder setField(
|
||||
com.google.protobuf.Descriptors.FieldDescriptor field,
|
||||
java.lang.Object value) {
|
||||
return super.setField(field, value);
|
||||
}
|
||||
@java.lang.Override
|
||||
public Builder clearField(
|
||||
com.google.protobuf.Descriptors.FieldDescriptor field) {
|
||||
return super.clearField(field);
|
||||
}
|
||||
@java.lang.Override
|
||||
public Builder clearOneof(
|
||||
com.google.protobuf.Descriptors.OneofDescriptor oneof) {
|
||||
return super.clearOneof(oneof);
|
||||
}
|
||||
@java.lang.Override
|
||||
public Builder setRepeatedField(
|
||||
com.google.protobuf.Descriptors.FieldDescriptor field,
|
||||
int index, java.lang.Object value) {
|
||||
return super.setRepeatedField(field, index, value);
|
||||
}
|
||||
@java.lang.Override
|
||||
public Builder addRepeatedField(
|
||||
com.google.protobuf.Descriptors.FieldDescriptor field,
|
||||
java.lang.Object value) {
|
||||
return super.addRepeatedField(field, value);
|
||||
}
|
||||
@java.lang.Override
|
||||
public Builder mergeFrom(com.google.protobuf.Message other) {
|
||||
if (other instanceof io.bkbn.kompendium.protobufjavaconverter.EnumMessage) {
|
||||
return mergeFrom((io.bkbn.kompendium.protobufjavaconverter.EnumMessage)other);
|
||||
} else {
|
||||
super.mergeFrom(other);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
public Builder mergeFrom(io.bkbn.kompendium.protobufjavaconverter.EnumMessage other) {
|
||||
if (other == io.bkbn.kompendium.protobufjavaconverter.EnumMessage.getDefaultInstance()) return this;
|
||||
if (other.corpus_ != 0) {
|
||||
setCorpusValue(other.getCorpusValue());
|
||||
}
|
||||
this.mergeUnknownFields(other.unknownFields);
|
||||
onChanged();
|
||||
return this;
|
||||
}
|
||||
|
||||
@java.lang.Override
|
||||
public final boolean isInitialized() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@java.lang.Override
|
||||
public Builder mergeFrom(
|
||||
com.google.protobuf.CodedInputStream input,
|
||||
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
|
||||
throws java.io.IOException {
|
||||
io.bkbn.kompendium.protobufjavaconverter.EnumMessage parsedMessage = null;
|
||||
try {
|
||||
parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry);
|
||||
} catch (com.google.protobuf.InvalidProtocolBufferException e) {
|
||||
parsedMessage = (io.bkbn.kompendium.protobufjavaconverter.EnumMessage) e.getUnfinishedMessage();
|
||||
throw e.unwrapIOException();
|
||||
} finally {
|
||||
if (parsedMessage != null) {
|
||||
mergeFrom(parsedMessage);
|
||||
}
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
private int corpus_ = 0;
|
||||
/**
|
||||
* <code>.io.bkbn.kompendium.protobufjavaconverter.Corpus corpus = 1;</code>
|
||||
* @return The enum numeric value on the wire for corpus.
|
||||
*/
|
||||
@java.lang.Override public int getCorpusValue() {
|
||||
return corpus_;
|
||||
}
|
||||
/**
|
||||
* <code>.io.bkbn.kompendium.protobufjavaconverter.Corpus corpus = 1;</code>
|
||||
* @param value The enum numeric value on the wire for corpus to set.
|
||||
* @return This builder for chaining.
|
||||
*/
|
||||
public Builder setCorpusValue(int value) {
|
||||
|
||||
corpus_ = value;
|
||||
onChanged();
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* <code>.io.bkbn.kompendium.protobufjavaconverter.Corpus corpus = 1;</code>
|
||||
* @return The corpus.
|
||||
*/
|
||||
@java.lang.Override
|
||||
public io.bkbn.kompendium.protobufjavaconverter.Corpus getCorpus() {
|
||||
@SuppressWarnings("deprecation")
|
||||
io.bkbn.kompendium.protobufjavaconverter.Corpus result = io.bkbn.kompendium.protobufjavaconverter.Corpus.valueOf(corpus_);
|
||||
return result == null ? io.bkbn.kompendium.protobufjavaconverter.Corpus.UNRECOGNIZED : result;
|
||||
}
|
||||
/**
|
||||
* <code>.io.bkbn.kompendium.protobufjavaconverter.Corpus corpus = 1;</code>
|
||||
* @param value The corpus to set.
|
||||
* @return This builder for chaining.
|
||||
*/
|
||||
public Builder setCorpus(io.bkbn.kompendium.protobufjavaconverter.Corpus value) {
|
||||
if (value == null) {
|
||||
throw new NullPointerException();
|
||||
}
|
||||
|
||||
corpus_ = value.getNumber();
|
||||
onChanged();
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* <code>.io.bkbn.kompendium.protobufjavaconverter.Corpus corpus = 1;</code>
|
||||
* @return This builder for chaining.
|
||||
*/
|
||||
public Builder clearCorpus() {
|
||||
|
||||
corpus_ = 0;
|
||||
onChanged();
|
||||
return this;
|
||||
}
|
||||
@java.lang.Override
|
||||
public final Builder setUnknownFields(
|
||||
final com.google.protobuf.UnknownFieldSet unknownFields) {
|
||||
return super.setUnknownFields(unknownFields);
|
||||
}
|
||||
|
||||
@java.lang.Override
|
||||
public final Builder mergeUnknownFields(
|
||||
final com.google.protobuf.UnknownFieldSet unknownFields) {
|
||||
return super.mergeUnknownFields(unknownFields);
|
||||
}
|
||||
|
||||
|
||||
// @@protoc_insertion_point(builder_scope:io.bkbn.kompendium.protobufjavaconverter.EnumMessage)
|
||||
}
|
||||
|
||||
// @@protoc_insertion_point(class_scope:io.bkbn.kompendium.protobufjavaconverter.EnumMessage)
|
||||
private static final io.bkbn.kompendium.protobufjavaconverter.EnumMessage DEFAULT_INSTANCE;
|
||||
static {
|
||||
DEFAULT_INSTANCE = new io.bkbn.kompendium.protobufjavaconverter.EnumMessage();
|
||||
}
|
||||
|
||||
public static io.bkbn.kompendium.protobufjavaconverter.EnumMessage getDefaultInstance() {
|
||||
return DEFAULT_INSTANCE;
|
||||
}
|
||||
|
||||
private static final com.google.protobuf.Parser<EnumMessage>
|
||||
PARSER = new com.google.protobuf.AbstractParser<EnumMessage>() {
|
||||
@java.lang.Override
|
||||
public EnumMessage parsePartialFrom(
|
||||
com.google.protobuf.CodedInputStream input,
|
||||
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
|
||||
throws com.google.protobuf.InvalidProtocolBufferException {
|
||||
return new EnumMessage(input, extensionRegistry);
|
||||
}
|
||||
};
|
||||
|
||||
public static com.google.protobuf.Parser<EnumMessage> parser() {
|
||||
return PARSER;
|
||||
}
|
||||
|
||||
@java.lang.Override
|
||||
public com.google.protobuf.Parser<EnumMessage> getParserForType() {
|
||||
return PARSER;
|
||||
}
|
||||
|
||||
@java.lang.Override
|
||||
public io.bkbn.kompendium.protobufjavaconverter.EnumMessage getDefaultInstanceForType() {
|
||||
return DEFAULT_INSTANCE;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,20 @@
|
||||
// Generated by the protocol buffer compiler. DO NOT EDIT!
|
||||
// source: io/bkbn/kompendium/protobufjavaconverter/converters/test.proto
|
||||
|
||||
package io.bkbn.kompendium.protobufjavaconverter;
|
||||
|
||||
public interface EnumMessageOrBuilder extends
|
||||
// @@protoc_insertion_point(interface_extends:io.bkbn.kompendium.protobufjavaconverter.EnumMessage)
|
||||
com.google.protobuf.MessageOrBuilder {
|
||||
|
||||
/**
|
||||
* <code>.io.bkbn.kompendium.protobufjavaconverter.Corpus corpus = 1;</code>
|
||||
* @return The enum numeric value on the wire for corpus.
|
||||
*/
|
||||
int getCorpusValue();
|
||||
/**
|
||||
* <code>.io.bkbn.kompendium.protobufjavaconverter.Corpus corpus = 1;</code>
|
||||
* @return The corpus.
|
||||
*/
|
||||
io.bkbn.kompendium.protobufjavaconverter.Corpus getCorpus();
|
||||
}
|
@ -0,0 +1,843 @@
|
||||
// Generated by the protocol buffer compiler. DO NOT EDIT!
|
||||
// source: io/bkbn/kompendium/protobufjavaconverter/converters/test.proto
|
||||
|
||||
package io.bkbn.kompendium.protobufjavaconverter;
|
||||
|
||||
/**
|
||||
* Protobuf type {@code io.bkbn.kompendium.protobufjavaconverter.GoogleTypes}
|
||||
*/
|
||||
public final class GoogleTypes extends
|
||||
com.google.protobuf.GeneratedMessageV3 implements
|
||||
// @@protoc_insertion_point(message_implements:io.bkbn.kompendium.protobufjavaconverter.GoogleTypes)
|
||||
GoogleTypesOrBuilder {
|
||||
private static final long serialVersionUID = 0L;
|
||||
// Use GoogleTypes.newBuilder() to construct.
|
||||
private GoogleTypes(com.google.protobuf.GeneratedMessageV3.Builder<?> builder) {
|
||||
super(builder);
|
||||
}
|
||||
private GoogleTypes() {
|
||||
}
|
||||
|
||||
@java.lang.Override
|
||||
@SuppressWarnings({"unused"})
|
||||
protected java.lang.Object newInstance(
|
||||
UnusedPrivateParameter unused) {
|
||||
return new GoogleTypes();
|
||||
}
|
||||
|
||||
@java.lang.Override
|
||||
public final com.google.protobuf.UnknownFieldSet
|
||||
getUnknownFields() {
|
||||
return this.unknownFields;
|
||||
}
|
||||
private GoogleTypes(
|
||||
com.google.protobuf.CodedInputStream input,
|
||||
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
|
||||
throws com.google.protobuf.InvalidProtocolBufferException {
|
||||
this();
|
||||
if (extensionRegistry == null) {
|
||||
throw new java.lang.NullPointerException();
|
||||
}
|
||||
com.google.protobuf.UnknownFieldSet.Builder unknownFields =
|
||||
com.google.protobuf.UnknownFieldSet.newBuilder();
|
||||
try {
|
||||
boolean done = false;
|
||||
while (!done) {
|
||||
int tag = input.readTag();
|
||||
switch (tag) {
|
||||
case 0:
|
||||
done = true;
|
||||
break;
|
||||
case 10: {
|
||||
com.google.protobuf.Timestamp.Builder subBuilder = null;
|
||||
if (timestampField_ != null) {
|
||||
subBuilder = timestampField_.toBuilder();
|
||||
}
|
||||
timestampField_ = input.readMessage(com.google.protobuf.Timestamp.parser(), extensionRegistry);
|
||||
if (subBuilder != null) {
|
||||
subBuilder.mergeFrom(timestampField_);
|
||||
timestampField_ = subBuilder.buildPartial();
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
case 18: {
|
||||
com.google.protobuf.Duration.Builder subBuilder = null;
|
||||
if (durationField_ != null) {
|
||||
subBuilder = durationField_.toBuilder();
|
||||
}
|
||||
durationField_ = input.readMessage(com.google.protobuf.Duration.parser(), extensionRegistry);
|
||||
if (subBuilder != null) {
|
||||
subBuilder.mergeFrom(durationField_);
|
||||
durationField_ = subBuilder.buildPartial();
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
if (!parseUnknownField(
|
||||
input, unknownFields, extensionRegistry, tag)) {
|
||||
done = true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (com.google.protobuf.InvalidProtocolBufferException e) {
|
||||
throw e.setUnfinishedMessage(this);
|
||||
} catch (java.io.IOException e) {
|
||||
throw new com.google.protobuf.InvalidProtocolBufferException(
|
||||
e).setUnfinishedMessage(this);
|
||||
} finally {
|
||||
this.unknownFields = unknownFields.build();
|
||||
makeExtensionsImmutable();
|
||||
}
|
||||
}
|
||||
public static final com.google.protobuf.Descriptors.Descriptor
|
||||
getDescriptor() {
|
||||
return io.bkbn.kompendium.protobufjavaconverter.Test.internal_static_io_bkbn_kompendium_protobufjavaconverter_GoogleTypes_descriptor;
|
||||
}
|
||||
|
||||
@java.lang.Override
|
||||
protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable
|
||||
internalGetFieldAccessorTable() {
|
||||
return io.bkbn.kompendium.protobufjavaconverter.Test.internal_static_io_bkbn_kompendium_protobufjavaconverter_GoogleTypes_fieldAccessorTable
|
||||
.ensureFieldAccessorsInitialized(
|
||||
io.bkbn.kompendium.protobufjavaconverter.GoogleTypes.class, io.bkbn.kompendium.protobufjavaconverter.GoogleTypes.Builder.class);
|
||||
}
|
||||
|
||||
public static final int TIMESTAMP_FIELD_FIELD_NUMBER = 1;
|
||||
private com.google.protobuf.Timestamp timestampField_;
|
||||
/**
|
||||
* <code>.google.protobuf.Timestamp timestamp_field = 1;</code>
|
||||
* @return Whether the timestampField field is set.
|
||||
*/
|
||||
@java.lang.Override
|
||||
public boolean hasTimestampField() {
|
||||
return timestampField_ != null;
|
||||
}
|
||||
/**
|
||||
* <code>.google.protobuf.Timestamp timestamp_field = 1;</code>
|
||||
* @return The timestampField.
|
||||
*/
|
||||
@java.lang.Override
|
||||
public com.google.protobuf.Timestamp getTimestampField() {
|
||||
return timestampField_ == null ? com.google.protobuf.Timestamp.getDefaultInstance() : timestampField_;
|
||||
}
|
||||
/**
|
||||
* <code>.google.protobuf.Timestamp timestamp_field = 1;</code>
|
||||
*/
|
||||
@java.lang.Override
|
||||
public com.google.protobuf.TimestampOrBuilder getTimestampFieldOrBuilder() {
|
||||
return getTimestampField();
|
||||
}
|
||||
|
||||
public static final int DURATION_FIELD_FIELD_NUMBER = 2;
|
||||
private com.google.protobuf.Duration durationField_;
|
||||
/**
|
||||
* <pre>
|
||||
* TODO value types
|
||||
* </pre>
|
||||
*
|
||||
* <code>.google.protobuf.Duration duration_field = 2;</code>
|
||||
* @return Whether the durationField field is set.
|
||||
*/
|
||||
@java.lang.Override
|
||||
public boolean hasDurationField() {
|
||||
return durationField_ != null;
|
||||
}
|
||||
/**
|
||||
* <pre>
|
||||
* TODO value types
|
||||
* </pre>
|
||||
*
|
||||
* <code>.google.protobuf.Duration duration_field = 2;</code>
|
||||
* @return The durationField.
|
||||
*/
|
||||
@java.lang.Override
|
||||
public com.google.protobuf.Duration getDurationField() {
|
||||
return durationField_ == null ? com.google.protobuf.Duration.getDefaultInstance() : durationField_;
|
||||
}
|
||||
/**
|
||||
* <pre>
|
||||
* TODO value types
|
||||
* </pre>
|
||||
*
|
||||
* <code>.google.protobuf.Duration duration_field = 2;</code>
|
||||
*/
|
||||
@java.lang.Override
|
||||
public com.google.protobuf.DurationOrBuilder getDurationFieldOrBuilder() {
|
||||
return getDurationField();
|
||||
}
|
||||
|
||||
private byte memoizedIsInitialized = -1;
|
||||
@java.lang.Override
|
||||
public final boolean isInitialized() {
|
||||
byte isInitialized = memoizedIsInitialized;
|
||||
if (isInitialized == 1) return true;
|
||||
if (isInitialized == 0) return false;
|
||||
|
||||
memoizedIsInitialized = 1;
|
||||
return true;
|
||||
}
|
||||
|
||||
@java.lang.Override
|
||||
public void writeTo(com.google.protobuf.CodedOutputStream output)
|
||||
throws java.io.IOException {
|
||||
if (timestampField_ != null) {
|
||||
output.writeMessage(1, getTimestampField());
|
||||
}
|
||||
if (durationField_ != null) {
|
||||
output.writeMessage(2, getDurationField());
|
||||
}
|
||||
unknownFields.writeTo(output);
|
||||
}
|
||||
|
||||
@java.lang.Override
|
||||
public int getSerializedSize() {
|
||||
int size = memoizedSize;
|
||||
if (size != -1) return size;
|
||||
|
||||
size = 0;
|
||||
if (timestampField_ != null) {
|
||||
size += com.google.protobuf.CodedOutputStream
|
||||
.computeMessageSize(1, getTimestampField());
|
||||
}
|
||||
if (durationField_ != null) {
|
||||
size += com.google.protobuf.CodedOutputStream
|
||||
.computeMessageSize(2, getDurationField());
|
||||
}
|
||||
size += unknownFields.getSerializedSize();
|
||||
memoizedSize = size;
|
||||
return size;
|
||||
}
|
||||
|
||||
@java.lang.Override
|
||||
public boolean equals(final java.lang.Object obj) {
|
||||
if (obj == this) {
|
||||
return true;
|
||||
}
|
||||
if (!(obj instanceof io.bkbn.kompendium.protobufjavaconverter.GoogleTypes)) {
|
||||
return super.equals(obj);
|
||||
}
|
||||
io.bkbn.kompendium.protobufjavaconverter.GoogleTypes other = (io.bkbn.kompendium.protobufjavaconverter.GoogleTypes) obj;
|
||||
|
||||
if (hasTimestampField() != other.hasTimestampField()) return false;
|
||||
if (hasTimestampField()) {
|
||||
if (!getTimestampField()
|
||||
.equals(other.getTimestampField())) return false;
|
||||
}
|
||||
if (hasDurationField() != other.hasDurationField()) return false;
|
||||
if (hasDurationField()) {
|
||||
if (!getDurationField()
|
||||
.equals(other.getDurationField())) return false;
|
||||
}
|
||||
if (!unknownFields.equals(other.unknownFields)) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@java.lang.Override
|
||||
public int hashCode() {
|
||||
if (memoizedHashCode != 0) {
|
||||
return memoizedHashCode;
|
||||
}
|
||||
int hash = 41;
|
||||
hash = (19 * hash) + getDescriptor().hashCode();
|
||||
if (hasTimestampField()) {
|
||||
hash = (37 * hash) + TIMESTAMP_FIELD_FIELD_NUMBER;
|
||||
hash = (53 * hash) + getTimestampField().hashCode();
|
||||
}
|
||||
if (hasDurationField()) {
|
||||
hash = (37 * hash) + DURATION_FIELD_FIELD_NUMBER;
|
||||
hash = (53 * hash) + getDurationField().hashCode();
|
||||
}
|
||||
hash = (29 * hash) + unknownFields.hashCode();
|
||||
memoizedHashCode = hash;
|
||||
return hash;
|
||||
}
|
||||
|
||||
public static io.bkbn.kompendium.protobufjavaconverter.GoogleTypes parseFrom(
|
||||
java.nio.ByteBuffer data)
|
||||
throws com.google.protobuf.InvalidProtocolBufferException {
|
||||
return PARSER.parseFrom(data);
|
||||
}
|
||||
public static io.bkbn.kompendium.protobufjavaconverter.GoogleTypes parseFrom(
|
||||
java.nio.ByteBuffer data,
|
||||
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
|
||||
throws com.google.protobuf.InvalidProtocolBufferException {
|
||||
return PARSER.parseFrom(data, extensionRegistry);
|
||||
}
|
||||
public static io.bkbn.kompendium.protobufjavaconverter.GoogleTypes parseFrom(
|
||||
com.google.protobuf.ByteString data)
|
||||
throws com.google.protobuf.InvalidProtocolBufferException {
|
||||
return PARSER.parseFrom(data);
|
||||
}
|
||||
public static io.bkbn.kompendium.protobufjavaconverter.GoogleTypes parseFrom(
|
||||
com.google.protobuf.ByteString data,
|
||||
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
|
||||
throws com.google.protobuf.InvalidProtocolBufferException {
|
||||
return PARSER.parseFrom(data, extensionRegistry);
|
||||
}
|
||||
public static io.bkbn.kompendium.protobufjavaconverter.GoogleTypes parseFrom(byte[] data)
|
||||
throws com.google.protobuf.InvalidProtocolBufferException {
|
||||
return PARSER.parseFrom(data);
|
||||
}
|
||||
public static io.bkbn.kompendium.protobufjavaconverter.GoogleTypes parseFrom(
|
||||
byte[] data,
|
||||
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
|
||||
throws com.google.protobuf.InvalidProtocolBufferException {
|
||||
return PARSER.parseFrom(data, extensionRegistry);
|
||||
}
|
||||
public static io.bkbn.kompendium.protobufjavaconverter.GoogleTypes parseFrom(java.io.InputStream input)
|
||||
throws java.io.IOException {
|
||||
return com.google.protobuf.GeneratedMessageV3
|
||||
.parseWithIOException(PARSER, input);
|
||||
}
|
||||
public static io.bkbn.kompendium.protobufjavaconverter.GoogleTypes parseFrom(
|
||||
java.io.InputStream input,
|
||||
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
|
||||
throws java.io.IOException {
|
||||
return com.google.protobuf.GeneratedMessageV3
|
||||
.parseWithIOException(PARSER, input, extensionRegistry);
|
||||
}
|
||||
public static io.bkbn.kompendium.protobufjavaconverter.GoogleTypes parseDelimitedFrom(java.io.InputStream input)
|
||||
throws java.io.IOException {
|
||||
return com.google.protobuf.GeneratedMessageV3
|
||||
.parseDelimitedWithIOException(PARSER, input);
|
||||
}
|
||||
public static io.bkbn.kompendium.protobufjavaconverter.GoogleTypes parseDelimitedFrom(
|
||||
java.io.InputStream input,
|
||||
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
|
||||
throws java.io.IOException {
|
||||
return com.google.protobuf.GeneratedMessageV3
|
||||
.parseDelimitedWithIOException(PARSER, input, extensionRegistry);
|
||||
}
|
||||
public static io.bkbn.kompendium.protobufjavaconverter.GoogleTypes parseFrom(
|
||||
com.google.protobuf.CodedInputStream input)
|
||||
throws java.io.IOException {
|
||||
return com.google.protobuf.GeneratedMessageV3
|
||||
.parseWithIOException(PARSER, input);
|
||||
}
|
||||
public static io.bkbn.kompendium.protobufjavaconverter.GoogleTypes parseFrom(
|
||||
com.google.protobuf.CodedInputStream input,
|
||||
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
|
||||
throws java.io.IOException {
|
||||
return com.google.protobuf.GeneratedMessageV3
|
||||
.parseWithIOException(PARSER, input, extensionRegistry);
|
||||
}
|
||||
|
||||
@java.lang.Override
|
||||
public Builder newBuilderForType() { return newBuilder(); }
|
||||
public static Builder newBuilder() {
|
||||
return DEFAULT_INSTANCE.toBuilder();
|
||||
}
|
||||
public static Builder newBuilder(io.bkbn.kompendium.protobufjavaconverter.GoogleTypes prototype) {
|
||||
return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype);
|
||||
}
|
||||
@java.lang.Override
|
||||
public Builder toBuilder() {
|
||||
return this == DEFAULT_INSTANCE
|
||||
? new Builder() : new Builder().mergeFrom(this);
|
||||
}
|
||||
|
||||
@java.lang.Override
|
||||
protected Builder newBuilderForType(
|
||||
com.google.protobuf.GeneratedMessageV3.BuilderParent parent) {
|
||||
Builder builder = new Builder(parent);
|
||||
return builder;
|
||||
}
|
||||
/**
|
||||
* Protobuf type {@code io.bkbn.kompendium.protobufjavaconverter.GoogleTypes}
|
||||
*/
|
||||
public static final class Builder extends
|
||||
com.google.protobuf.GeneratedMessageV3.Builder<Builder> implements
|
||||
// @@protoc_insertion_point(builder_implements:io.bkbn.kompendium.protobufjavaconverter.GoogleTypes)
|
||||
io.bkbn.kompendium.protobufjavaconverter.GoogleTypesOrBuilder {
|
||||
public static final com.google.protobuf.Descriptors.Descriptor
|
||||
getDescriptor() {
|
||||
return io.bkbn.kompendium.protobufjavaconverter.Test.internal_static_io_bkbn_kompendium_protobufjavaconverter_GoogleTypes_descriptor;
|
||||
}
|
||||
|
||||
@java.lang.Override
|
||||
protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable
|
||||
internalGetFieldAccessorTable() {
|
||||
return io.bkbn.kompendium.protobufjavaconverter.Test.internal_static_io_bkbn_kompendium_protobufjavaconverter_GoogleTypes_fieldAccessorTable
|
||||
.ensureFieldAccessorsInitialized(
|
||||
io.bkbn.kompendium.protobufjavaconverter.GoogleTypes.class, io.bkbn.kompendium.protobufjavaconverter.GoogleTypes.Builder.class);
|
||||
}
|
||||
|
||||
// Construct using io.bkbn.kompendium.protobufjavaconverter.GoogleTypes.newBuilder()
|
||||
private Builder() {
|
||||
maybeForceBuilderInitialization();
|
||||
}
|
||||
|
||||
private Builder(
|
||||
com.google.protobuf.GeneratedMessageV3.BuilderParent parent) {
|
||||
super(parent);
|
||||
maybeForceBuilderInitialization();
|
||||
}
|
||||
private void maybeForceBuilderInitialization() {
|
||||
if (com.google.protobuf.GeneratedMessageV3
|
||||
.alwaysUseFieldBuilders) {
|
||||
}
|
||||
}
|
||||
@java.lang.Override
|
||||
public Builder clear() {
|
||||
super.clear();
|
||||
if (timestampFieldBuilder_ == null) {
|
||||
timestampField_ = null;
|
||||
} else {
|
||||
timestampField_ = null;
|
||||
timestampFieldBuilder_ = null;
|
||||
}
|
||||
if (durationFieldBuilder_ == null) {
|
||||
durationField_ = null;
|
||||
} else {
|
||||
durationField_ = null;
|
||||
durationFieldBuilder_ = null;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
@java.lang.Override
|
||||
public com.google.protobuf.Descriptors.Descriptor
|
||||
getDescriptorForType() {
|
||||
return io.bkbn.kompendium.protobufjavaconverter.Test.internal_static_io_bkbn_kompendium_protobufjavaconverter_GoogleTypes_descriptor;
|
||||
}
|
||||
|
||||
@java.lang.Override
|
||||
public io.bkbn.kompendium.protobufjavaconverter.GoogleTypes getDefaultInstanceForType() {
|
||||
return io.bkbn.kompendium.protobufjavaconverter.GoogleTypes.getDefaultInstance();
|
||||
}
|
||||
|
||||
@java.lang.Override
|
||||
public io.bkbn.kompendium.protobufjavaconverter.GoogleTypes build() {
|
||||
io.bkbn.kompendium.protobufjavaconverter.GoogleTypes result = buildPartial();
|
||||
if (!result.isInitialized()) {
|
||||
throw newUninitializedMessageException(result);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@java.lang.Override
|
||||
public io.bkbn.kompendium.protobufjavaconverter.GoogleTypes buildPartial() {
|
||||
io.bkbn.kompendium.protobufjavaconverter.GoogleTypes result = new io.bkbn.kompendium.protobufjavaconverter.GoogleTypes(this);
|
||||
if (timestampFieldBuilder_ == null) {
|
||||
result.timestampField_ = timestampField_;
|
||||
} else {
|
||||
result.timestampField_ = timestampFieldBuilder_.build();
|
||||
}
|
||||
if (durationFieldBuilder_ == null) {
|
||||
result.durationField_ = durationField_;
|
||||
} else {
|
||||
result.durationField_ = durationFieldBuilder_.build();
|
||||
}
|
||||
onBuilt();
|
||||
return result;
|
||||
}
|
||||
|
||||
@java.lang.Override
|
||||
public Builder clone() {
|
||||
return super.clone();
|
||||
}
|
||||
@java.lang.Override
|
||||
public Builder setField(
|
||||
com.google.protobuf.Descriptors.FieldDescriptor field,
|
||||
java.lang.Object value) {
|
||||
return super.setField(field, value);
|
||||
}
|
||||
@java.lang.Override
|
||||
public Builder clearField(
|
||||
com.google.protobuf.Descriptors.FieldDescriptor field) {
|
||||
return super.clearField(field);
|
||||
}
|
||||
@java.lang.Override
|
||||
public Builder clearOneof(
|
||||
com.google.protobuf.Descriptors.OneofDescriptor oneof) {
|
||||
return super.clearOneof(oneof);
|
||||
}
|
||||
@java.lang.Override
|
||||
public Builder setRepeatedField(
|
||||
com.google.protobuf.Descriptors.FieldDescriptor field,
|
||||
int index, java.lang.Object value) {
|
||||
return super.setRepeatedField(field, index, value);
|
||||
}
|
||||
@java.lang.Override
|
||||
public Builder addRepeatedField(
|
||||
com.google.protobuf.Descriptors.FieldDescriptor field,
|
||||
java.lang.Object value) {
|
||||
return super.addRepeatedField(field, value);
|
||||
}
|
||||
@java.lang.Override
|
||||
public Builder mergeFrom(com.google.protobuf.Message other) {
|
||||
if (other instanceof io.bkbn.kompendium.protobufjavaconverter.GoogleTypes) {
|
||||
return mergeFrom((io.bkbn.kompendium.protobufjavaconverter.GoogleTypes)other);
|
||||
} else {
|
||||
super.mergeFrom(other);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
public Builder mergeFrom(io.bkbn.kompendium.protobufjavaconverter.GoogleTypes other) {
|
||||
if (other == io.bkbn.kompendium.protobufjavaconverter.GoogleTypes.getDefaultInstance()) return this;
|
||||
if (other.hasTimestampField()) {
|
||||
mergeTimestampField(other.getTimestampField());
|
||||
}
|
||||
if (other.hasDurationField()) {
|
||||
mergeDurationField(other.getDurationField());
|
||||
}
|
||||
this.mergeUnknownFields(other.unknownFields);
|
||||
onChanged();
|
||||
return this;
|
||||
}
|
||||
|
||||
@java.lang.Override
|
||||
public final boolean isInitialized() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@java.lang.Override
|
||||
public Builder mergeFrom(
|
||||
com.google.protobuf.CodedInputStream input,
|
||||
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
|
||||
throws java.io.IOException {
|
||||
io.bkbn.kompendium.protobufjavaconverter.GoogleTypes parsedMessage = null;
|
||||
try {
|
||||
parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry);
|
||||
} catch (com.google.protobuf.InvalidProtocolBufferException e) {
|
||||
parsedMessage = (io.bkbn.kompendium.protobufjavaconverter.GoogleTypes) e.getUnfinishedMessage();
|
||||
throw e.unwrapIOException();
|
||||
} finally {
|
||||
if (parsedMessage != null) {
|
||||
mergeFrom(parsedMessage);
|
||||
}
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
private com.google.protobuf.Timestamp timestampField_;
|
||||
private com.google.protobuf.SingleFieldBuilderV3<
|
||||
com.google.protobuf.Timestamp, com.google.protobuf.Timestamp.Builder, com.google.protobuf.TimestampOrBuilder> timestampFieldBuilder_;
|
||||
/**
|
||||
* <code>.google.protobuf.Timestamp timestamp_field = 1;</code>
|
||||
* @return Whether the timestampField field is set.
|
||||
*/
|
||||
public boolean hasTimestampField() {
|
||||
return timestampFieldBuilder_ != null || timestampField_ != null;
|
||||
}
|
||||
/**
|
||||
* <code>.google.protobuf.Timestamp timestamp_field = 1;</code>
|
||||
* @return The timestampField.
|
||||
*/
|
||||
public com.google.protobuf.Timestamp getTimestampField() {
|
||||
if (timestampFieldBuilder_ == null) {
|
||||
return timestampField_ == null ? com.google.protobuf.Timestamp.getDefaultInstance() : timestampField_;
|
||||
} else {
|
||||
return timestampFieldBuilder_.getMessage();
|
||||
}
|
||||
}
|
||||
/**
|
||||
* <code>.google.protobuf.Timestamp timestamp_field = 1;</code>
|
||||
*/
|
||||
public Builder setTimestampField(com.google.protobuf.Timestamp value) {
|
||||
if (timestampFieldBuilder_ == null) {
|
||||
if (value == null) {
|
||||
throw new NullPointerException();
|
||||
}
|
||||
timestampField_ = value;
|
||||
onChanged();
|
||||
} else {
|
||||
timestampFieldBuilder_.setMessage(value);
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* <code>.google.protobuf.Timestamp timestamp_field = 1;</code>
|
||||
*/
|
||||
public Builder setTimestampField(
|
||||
com.google.protobuf.Timestamp.Builder builderForValue) {
|
||||
if (timestampFieldBuilder_ == null) {
|
||||
timestampField_ = builderForValue.build();
|
||||
onChanged();
|
||||
} else {
|
||||
timestampFieldBuilder_.setMessage(builderForValue.build());
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* <code>.google.protobuf.Timestamp timestamp_field = 1;</code>
|
||||
*/
|
||||
public Builder mergeTimestampField(com.google.protobuf.Timestamp value) {
|
||||
if (timestampFieldBuilder_ == null) {
|
||||
if (timestampField_ != null) {
|
||||
timestampField_ =
|
||||
com.google.protobuf.Timestamp.newBuilder(timestampField_).mergeFrom(value).buildPartial();
|
||||
} else {
|
||||
timestampField_ = value;
|
||||
}
|
||||
onChanged();
|
||||
} else {
|
||||
timestampFieldBuilder_.mergeFrom(value);
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* <code>.google.protobuf.Timestamp timestamp_field = 1;</code>
|
||||
*/
|
||||
public Builder clearTimestampField() {
|
||||
if (timestampFieldBuilder_ == null) {
|
||||
timestampField_ = null;
|
||||
onChanged();
|
||||
} else {
|
||||
timestampField_ = null;
|
||||
timestampFieldBuilder_ = null;
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* <code>.google.protobuf.Timestamp timestamp_field = 1;</code>
|
||||
*/
|
||||
public com.google.protobuf.Timestamp.Builder getTimestampFieldBuilder() {
|
||||
|
||||
onChanged();
|
||||
return getTimestampFieldFieldBuilder().getBuilder();
|
||||
}
|
||||
/**
|
||||
* <code>.google.protobuf.Timestamp timestamp_field = 1;</code>
|
||||
*/
|
||||
public com.google.protobuf.TimestampOrBuilder getTimestampFieldOrBuilder() {
|
||||
if (timestampFieldBuilder_ != null) {
|
||||
return timestampFieldBuilder_.getMessageOrBuilder();
|
||||
} else {
|
||||
return timestampField_ == null ?
|
||||
com.google.protobuf.Timestamp.getDefaultInstance() : timestampField_;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* <code>.google.protobuf.Timestamp timestamp_field = 1;</code>
|
||||
*/
|
||||
private com.google.protobuf.SingleFieldBuilderV3<
|
||||
com.google.protobuf.Timestamp, com.google.protobuf.Timestamp.Builder, com.google.protobuf.TimestampOrBuilder>
|
||||
getTimestampFieldFieldBuilder() {
|
||||
if (timestampFieldBuilder_ == null) {
|
||||
timestampFieldBuilder_ = new com.google.protobuf.SingleFieldBuilderV3<
|
||||
com.google.protobuf.Timestamp, com.google.protobuf.Timestamp.Builder, com.google.protobuf.TimestampOrBuilder>(
|
||||
getTimestampField(),
|
||||
getParentForChildren(),
|
||||
isClean());
|
||||
timestampField_ = null;
|
||||
}
|
||||
return timestampFieldBuilder_;
|
||||
}
|
||||
|
||||
private com.google.protobuf.Duration durationField_;
|
||||
private com.google.protobuf.SingleFieldBuilderV3<
|
||||
com.google.protobuf.Duration, com.google.protobuf.Duration.Builder, com.google.protobuf.DurationOrBuilder> durationFieldBuilder_;
|
||||
/**
|
||||
* <pre>
|
||||
* TODO value types
|
||||
* </pre>
|
||||
*
|
||||
* <code>.google.protobuf.Duration duration_field = 2;</code>
|
||||
* @return Whether the durationField field is set.
|
||||
*/
|
||||
public boolean hasDurationField() {
|
||||
return durationFieldBuilder_ != null || durationField_ != null;
|
||||
}
|
||||
/**
|
||||
* <pre>
|
||||
* TODO value types
|
||||
* </pre>
|
||||
*
|
||||
* <code>.google.protobuf.Duration duration_field = 2;</code>
|
||||
* @return The durationField.
|
||||
*/
|
||||
public com.google.protobuf.Duration getDurationField() {
|
||||
if (durationFieldBuilder_ == null) {
|
||||
return durationField_ == null ? com.google.protobuf.Duration.getDefaultInstance() : durationField_;
|
||||
} else {
|
||||
return durationFieldBuilder_.getMessage();
|
||||
}
|
||||
}
|
||||
/**
|
||||
* <pre>
|
||||
* TODO value types
|
||||
* </pre>
|
||||
*
|
||||
* <code>.google.protobuf.Duration duration_field = 2;</code>
|
||||
*/
|
||||
public Builder setDurationField(com.google.protobuf.Duration value) {
|
||||
if (durationFieldBuilder_ == null) {
|
||||
if (value == null) {
|
||||
throw new NullPointerException();
|
||||
}
|
||||
durationField_ = value;
|
||||
onChanged();
|
||||
} else {
|
||||
durationFieldBuilder_.setMessage(value);
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* <pre>
|
||||
* TODO value types
|
||||
* </pre>
|
||||
*
|
||||
* <code>.google.protobuf.Duration duration_field = 2;</code>
|
||||
*/
|
||||
public Builder setDurationField(
|
||||
com.google.protobuf.Duration.Builder builderForValue) {
|
||||
if (durationFieldBuilder_ == null) {
|
||||
durationField_ = builderForValue.build();
|
||||
onChanged();
|
||||
} else {
|
||||
durationFieldBuilder_.setMessage(builderForValue.build());
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* <pre>
|
||||
* TODO value types
|
||||
* </pre>
|
||||
*
|
||||
* <code>.google.protobuf.Duration duration_field = 2;</code>
|
||||
*/
|
||||
public Builder mergeDurationField(com.google.protobuf.Duration value) {
|
||||
if (durationFieldBuilder_ == null) {
|
||||
if (durationField_ != null) {
|
||||
durationField_ =
|
||||
com.google.protobuf.Duration.newBuilder(durationField_).mergeFrom(value).buildPartial();
|
||||
} else {
|
||||
durationField_ = value;
|
||||
}
|
||||
onChanged();
|
||||
} else {
|
||||
durationFieldBuilder_.mergeFrom(value);
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* <pre>
|
||||
* TODO value types
|
||||
* </pre>
|
||||
*
|
||||
* <code>.google.protobuf.Duration duration_field = 2;</code>
|
||||
*/
|
||||
public Builder clearDurationField() {
|
||||
if (durationFieldBuilder_ == null) {
|
||||
durationField_ = null;
|
||||
onChanged();
|
||||
} else {
|
||||
durationField_ = null;
|
||||
durationFieldBuilder_ = null;
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* <pre>
|
||||
* TODO value types
|
||||
* </pre>
|
||||
*
|
||||
* <code>.google.protobuf.Duration duration_field = 2;</code>
|
||||
*/
|
||||
public com.google.protobuf.Duration.Builder getDurationFieldBuilder() {
|
||||
|
||||
onChanged();
|
||||
return getDurationFieldFieldBuilder().getBuilder();
|
||||
}
|
||||
/**
|
||||
* <pre>
|
||||
* TODO value types
|
||||
* </pre>
|
||||
*
|
||||
* <code>.google.protobuf.Duration duration_field = 2;</code>
|
||||
*/
|
||||
public com.google.protobuf.DurationOrBuilder getDurationFieldOrBuilder() {
|
||||
if (durationFieldBuilder_ != null) {
|
||||
return durationFieldBuilder_.getMessageOrBuilder();
|
||||
} else {
|
||||
return durationField_ == null ?
|
||||
com.google.protobuf.Duration.getDefaultInstance() : durationField_;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* <pre>
|
||||
* TODO value types
|
||||
* </pre>
|
||||
*
|
||||
* <code>.google.protobuf.Duration duration_field = 2;</code>
|
||||
*/
|
||||
private com.google.protobuf.SingleFieldBuilderV3<
|
||||
com.google.protobuf.Duration, com.google.protobuf.Duration.Builder, com.google.protobuf.DurationOrBuilder>
|
||||
getDurationFieldFieldBuilder() {
|
||||
if (durationFieldBuilder_ == null) {
|
||||
durationFieldBuilder_ = new com.google.protobuf.SingleFieldBuilderV3<
|
||||
com.google.protobuf.Duration, com.google.protobuf.Duration.Builder, com.google.protobuf.DurationOrBuilder>(
|
||||
getDurationField(),
|
||||
getParentForChildren(),
|
||||
isClean());
|
||||
durationField_ = null;
|
||||
}
|
||||
return durationFieldBuilder_;
|
||||
}
|
||||
@java.lang.Override
|
||||
public final Builder setUnknownFields(
|
||||
final com.google.protobuf.UnknownFieldSet unknownFields) {
|
||||
return super.setUnknownFields(unknownFields);
|
||||
}
|
||||
|
||||
@java.lang.Override
|
||||
public final Builder mergeUnknownFields(
|
||||
final com.google.protobuf.UnknownFieldSet unknownFields) {
|
||||
return super.mergeUnknownFields(unknownFields);
|
||||
}
|
||||
|
||||
|
||||
// @@protoc_insertion_point(builder_scope:io.bkbn.kompendium.protobufjavaconverter.GoogleTypes)
|
||||
}
|
||||
|
||||
// @@protoc_insertion_point(class_scope:io.bkbn.kompendium.protobufjavaconverter.GoogleTypes)
|
||||
private static final io.bkbn.kompendium.protobufjavaconverter.GoogleTypes DEFAULT_INSTANCE;
|
||||
static {
|
||||
DEFAULT_INSTANCE = new io.bkbn.kompendium.protobufjavaconverter.GoogleTypes();
|
||||
}
|
||||
|
||||
public static io.bkbn.kompendium.protobufjavaconverter.GoogleTypes getDefaultInstance() {
|
||||
return DEFAULT_INSTANCE;
|
||||
}
|
||||
|
||||
private static final com.google.protobuf.Parser<GoogleTypes>
|
||||
PARSER = new com.google.protobuf.AbstractParser<GoogleTypes>() {
|
||||
@java.lang.Override
|
||||
public GoogleTypes parsePartialFrom(
|
||||
com.google.protobuf.CodedInputStream input,
|
||||
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
|
||||
throws com.google.protobuf.InvalidProtocolBufferException {
|
||||
return new GoogleTypes(input, extensionRegistry);
|
||||
}
|
||||
};
|
||||
|
||||
public static com.google.protobuf.Parser<GoogleTypes> parser() {
|
||||
return PARSER;
|
||||
}
|
||||
|
||||
@java.lang.Override
|
||||
public com.google.protobuf.Parser<GoogleTypes> getParserForType() {
|
||||
return PARSER;
|
||||
}
|
||||
|
||||
@java.lang.Override
|
||||
public io.bkbn.kompendium.protobufjavaconverter.GoogleTypes getDefaultInstanceForType() {
|
||||
return DEFAULT_INSTANCE;
|
||||
}
|
||||
|
||||
}
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user