Compare commits
116 Commits
v4.0.0-alp
...
v4.0.0-tes
Author | SHA1 | Date | |
---|---|---|---|
c53c0b045d | |||
fb0d3bb1dd | |||
1580d679d0 | |||
540dad1f00 | |||
21f922a296 | |||
fa7b1e5833 | |||
35110e8ad4 | |||
18d64a2ed1 | |||
4ffb04976a | |||
76b6288216 | |||
80f6f28b57 | |||
bf8b2b40f6 | |||
7c6826b366 | |||
ee56c8023e | |||
01c4e0558d | |||
a760121af5 | |||
b80ff3a998 | |||
8141be4b21 | |||
7fbc2523e2 | |||
3349e9dab7 | |||
da8439e1b7 | |||
e2d7d16571 | |||
f348910b63 | |||
7ed4c8075b | |||
87ba80b6bb | |||
e10f3b4c47 | |||
a7853ce353 | |||
da654e5664 | |||
d21434fdd0 | |||
8a94f6e498 | |||
7a58914466 | |||
2da6088303 | |||
1ad82f7e8e | |||
6117443c8b | |||
f8e098eb07 | |||
e2affe3f4b | |||
a78b51be07 | |||
fa96923a5a | |||
464fa2d98a | |||
11e0d248b5 | |||
2612010a88 | |||
cb78d19b89 | |||
28bce9c443 | |||
d7dad48808 | |||
2ea97ba2c2 | |||
944c632a1d | |||
d1c52c010e | |||
d9f78b4e9f | |||
dcde50de0a | |||
889fdb41d7 | |||
837108bbef | |||
ee9e3b03b3 | |||
3cc6e9f2e7 | |||
60eb3b6474 | |||
65c0137a46 | |||
c277e559f4 | |||
8a161466d6 | |||
9a4ad2f737 | |||
eb4d3ca7de | |||
7a8bb43675 | |||
ac464ea9ca | |||
c7545b1072 | |||
353637bb94 | |||
3d1fc566d4 | |||
79ddb2e4ae | |||
d004166a2e | |||
dc6dbdf1c0 | |||
0b9b8325ce | |||
6d89773448 | |||
b236530991 | |||
8caee55f43 | |||
13042ba385 | |||
26bd7178c9 | |||
9bc39e9767 | |||
57555587e0 | |||
47a9f0a145 | |||
789b750994 | |||
65fb7fbd55 | |||
89bd9dadd0 | |||
6ca8261cd2 | |||
ae5ddc35e6 | |||
dde9e1c0a7 | |||
8328351227 | |||
36a09ef3ca | |||
261e91a750 | |||
701ab7670e | |||
62280435cd | |||
18ddb13625 | |||
b5b2e462ac | |||
1bb52347a0 | |||
80f8ce6e52 | |||
1f504e8850 | |||
18d545bbfe | |||
e03868c42e | |||
e888207773 | |||
66943ceb5a | |||
e9342b9354 | |||
480b1ccdff | |||
95009090ba | |||
10ce370c9e | |||
1814fe4eb2 | |||
b0387313fd | |||
86c4800748 | |||
01052268f8 | |||
5c6f2c93e8 | |||
ccd46b15e7 | |||
eab1bb4ce7 | |||
3fdfe875f4 | |||
1b3cf0dbeb | |||
2410c81797 | |||
833bf463e7 | |||
b7e96019be | |||
aa5eb39a30 | |||
d002ec7fd9 | |||
650eb0f0d3 | |||
1a4568a49b |
10
.envrc
Normal file
10
.envrc
Normal file
@ -0,0 +1,10 @@
|
||||
if ! has nix_direnv_version || ! nix_direnv_version 3.0.5; then
|
||||
source_url "https://raw.githubusercontent.com/nix-community/nix-direnv/3.0.5/direnvrc" "sha256-zelF0vLbEl5uaqrfIzbgNzJWGmLzCmYAkInj/LNxvKs="
|
||||
fi
|
||||
|
||||
watch_file flake.nix
|
||||
watch_file flake.lock
|
||||
if ! use flake . --impure
|
||||
then
|
||||
echo "Flake could not be used... something is broken :(" >&2
|
||||
fi
|
17
.github/ISSUE_TEMPLATE/documentation.md
vendored
Normal file
17
.github/ISSUE_TEMPLATE/documentation.md
vendored
Normal file
@ -0,0 +1,17 @@
|
||||
---
|
||||
name: Documentation
|
||||
about: Suggest an improvement to the documentation for Kompendium
|
||||
title: ''
|
||||
labels: ''
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
**Please describe the problem with the current documentation.**
|
||||
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
|
||||
|
||||
**Link any docs references**
|
||||
Link to existing docs if incorrect, or references from another project if you have an example.
|
||||
|
||||
**Additional context**
|
||||
Add any other context or screenshots about the feature request here.
|
18
.github/workflows/pr_checks.yml
vendored
18
.github/workflows/pr_checks.yml
vendored
@ -4,12 +4,12 @@ jobs:
|
||||
lint:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- name: Set up JDK 17
|
||||
uses: actions/setup-java@v3
|
||||
- uses: actions/checkout@v4
|
||||
- name: Set up JDK 21
|
||||
uses: actions/setup-java@v4
|
||||
with:
|
||||
distribution: 'adopt'
|
||||
java-version: '17'
|
||||
java-version: '21'
|
||||
- name: Lint
|
||||
uses: burrunan/gradle-cache-action@v1
|
||||
with:
|
||||
@ -18,14 +18,14 @@ jobs:
|
||||
unit:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- name: Set up JDK 17
|
||||
uses: actions/setup-java@v3
|
||||
- uses: actions/checkout@v4
|
||||
- name: Set up JDK 21
|
||||
uses: actions/setup-java@v4
|
||||
with:
|
||||
distribution: 'adopt'
|
||||
java-version: '17'
|
||||
java-version: '21'
|
||||
- name: Unit Tests
|
||||
uses: burrunan/gradle-cache-action@v1
|
||||
with:
|
||||
gradle-version: wrapper
|
||||
arguments: test koverMergedReport
|
||||
arguments: test koverHtmlReport
|
||||
|
25
.github/workflows/publish.yml
vendored
25
.github/workflows/publish.yml
vendored
@ -1,25 +0,0 @@
|
||||
name: Publish to GitHub Packages
|
||||
on:
|
||||
push:
|
||||
branches: [ main ]
|
||||
paths-ignore:
|
||||
- docs/**
|
||||
env:
|
||||
ORG_GRADLE_PROJECT_signingKey: ${{ secrets.SONATYPE_SIGNING_KEY }}
|
||||
ORG_GRADLE_PROJECT_signingPassword: ${{ secrets.SONATYPE_SIGNING_PASSWORD }}
|
||||
jobs:
|
||||
publish:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/setup-java@v3
|
||||
with:
|
||||
distribution: 'adopt'
|
||||
java-version: '17'
|
||||
- name: Publish to GitHub Packages
|
||||
uses: burrunan/gradle-cache-action@v1
|
||||
with:
|
||||
gradle-version: wrapper
|
||||
arguments: publishAllPublicationsToGithubPackagesRepository
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
21
.github/workflows/release.yml
vendored
21
.github/workflows/release.yml
vendored
@ -4,25 +4,26 @@ on:
|
||||
types:
|
||||
- prereleased
|
||||
- released
|
||||
env:
|
||||
ORG_GRADLE_PROJECT_signingKey: ${{ secrets.SONATYPE_SIGNING_KEY }}
|
||||
ORG_GRADLE_PROJECT_signingPassword: ${{ secrets.SONATYPE_SIGNING_PASSWORD }}
|
||||
jobs:
|
||||
publish-to-nexus:
|
||||
publish-to-maven-central:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/setup-java@v3
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/setup-java@v4
|
||||
with:
|
||||
distribution: 'adopt'
|
||||
java-version: '17'
|
||||
java-version: '21'
|
||||
- name: Publish to Maven Central
|
||||
uses: burrunan/gradle-cache-action@v1
|
||||
with:
|
||||
gradle-version: wrapper
|
||||
arguments: publishToSonatype closeAndReleaseSonatypeStagingRepository
|
||||
arguments: publishAndReleaseToMavenCentral
|
||||
properties: |
|
||||
SONATYPE_AUTOMATIC_RELEASE=true
|
||||
release=true
|
||||
env:
|
||||
ORG_GRADLE_PROJECT_sonatypeUsername: ${{ secrets.SONATYPE_USER }}
|
||||
ORG_GRADLE_PROJECT_sonatypePassword: ${{ secrets.SONATYPE_PASSWORD }}
|
||||
ORG_GRADLE_PROJECT_mavenCentralUsername: ${{ secrets.MAVEN_CENTRAL_USERNAME }}
|
||||
ORG_GRADLE_PROJECT_mavenCentralPassword: ${{ secrets.MAVEN_CENTRAL_PASSWORD }}
|
||||
ORG_GRADLE_PROJECT_signingInMemoryKey: ${{ secrets.MAVEN_SIGNING_KEY }}
|
||||
ORG_GRADLE_PROJECT_signingInMemoryKeyId: ${{ secrets.MAVEN_SIGNING_KEY_ID }}
|
||||
ORG_GRADLE_PROJECT_signingInMemoryKeyPassword: ${{ secrets.MAVEN_SIGNING_KEY_PASSPHRASE }}
|
||||
|
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,3 +1,4 @@
|
||||
.gradle
|
||||
build
|
||||
.idea
|
||||
.direnv
|
||||
|
13
CHANGELOG.md
13
CHANGELOG.md
@ -2,6 +2,9 @@
|
||||
|
||||
## Unreleased
|
||||
|
||||
- Updates for Ktor 3.x support
|
||||
- Remove deprecated `NotarizedLocations`
|
||||
|
||||
### Added
|
||||
|
||||
### Changed
|
||||
@ -12,6 +15,16 @@
|
||||
|
||||
## Released
|
||||
|
||||
## [4.0.0] - January 21st, 2024
|
||||
|
||||
### Added
|
||||
|
||||
- All changes from alpha release
|
||||
|
||||
### Changed
|
||||
|
||||
- Enrichments now mirror schema types
|
||||
|
||||
## [4.0.0-alpha] - September 3rd, 2023
|
||||
|
||||
### Added
|
||||
|
@ -1,21 +1,19 @@
|
||||
import com.vanniktech.maven.publish.SonatypeHost
|
||||
import io.bkbn.sourdough.gradle.library.jvm.LibraryJvmPlugin
|
||||
import io.bkbn.sourdough.gradle.library.jvm.LibraryJvmExtension
|
||||
|
||||
plugins {
|
||||
kotlin("jvm") version "1.9.10" apply false
|
||||
kotlin("plugin.serialization") version "1.9.10" 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.3.0"
|
||||
kotlin("jvm") version "2.0.21" apply false
|
||||
kotlin("plugin.serialization") version "2.0.21" apply false
|
||||
id("io.bkbn.sourdough.library.jvm") version "0.13.0" apply false
|
||||
id("io.bkbn.sourdough.application.jvm") version "0.13.0" apply false
|
||||
id("com.vanniktech.maven.publish") version "0.30.0" apply false
|
||||
id("io.bkbn.sourdough.root") version "0.13.0"
|
||||
id("org.jetbrains.kotlinx.kover") version "0.8.3"
|
||||
}
|
||||
|
||||
gitHooks {
|
||||
setHooks(
|
||||
mapOf(
|
||||
"pre-commit" to "detekt",
|
||||
"pre-push" to "test"
|
||||
)
|
||||
)
|
||||
dependencies {
|
||||
subprojects.forEach { kover(it) }
|
||||
}
|
||||
|
||||
allprojects {
|
||||
@ -31,15 +29,16 @@ allprojects {
|
||||
}
|
||||
|
||||
subprojects {
|
||||
plugins.withType(io.bkbn.sourdough.gradle.library.jvm.LibraryJvmPlugin::class) {
|
||||
extensions.configure(io.bkbn.sourdough.gradle.library.jvm.LibraryJvmExtension::class) {
|
||||
plugins.withType(LibraryJvmPlugin::class) {
|
||||
extensions.configure(LibraryJvmExtension::class) {
|
||||
githubOrg.set("bkbnio")
|
||||
githubRepo.set("kompendium")
|
||||
licenseName.set("MIT License")
|
||||
licenseUrl.set("https://mit-license.org")
|
||||
developerId.set("unredundant")
|
||||
developerId.set("brizzbuzz")
|
||||
developerName.set("Ryan Brink")
|
||||
developerEmail.set("admin@bkbn.io")
|
||||
sonatypeHost.set(SonatypeHost.CENTRAL_PORTAL)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -4,7 +4,7 @@ plugins {
|
||||
id("io.bkbn.sourdough.library.jvm")
|
||||
id("io.gitlab.arturbosch.detekt")
|
||||
id("com.adarshr.test-logger")
|
||||
id("maven-publish")
|
||||
id("com.vanniktech.maven.publish")
|
||||
id("java-library")
|
||||
id("signing")
|
||||
id("java-test-fixtures")
|
||||
@ -20,6 +20,7 @@ sourdoughLibrary {
|
||||
dependencies {
|
||||
// VERSIONS
|
||||
val kotestVersion: String by project
|
||||
val kotlinSerializeVersion: String by project
|
||||
val ktorVersion: String by project
|
||||
val detektVersion: String by project
|
||||
|
||||
@ -43,7 +44,7 @@ dependencies {
|
||||
testFixturesApi("io.kotest:kotest-assertions-core-jvm:$kotestVersion")
|
||||
testFixturesApi("io.kotest:kotest-property-jvm:$kotestVersion")
|
||||
testFixturesApi("io.kotest:kotest-assertions-json-jvm:$kotestVersion")
|
||||
testFixturesApi("io.kotest:kotest-assertions-ktor-jvm:4.4.3")
|
||||
testFixturesApi("io.kotest.extensions:kotest-assertions-ktor:2.0.0")
|
||||
|
||||
testFixturesApi("io.ktor:ktor-server-core:$ktorVersion")
|
||||
testFixturesApi("io.ktor:ktor-server-test-host:$ktorVersion")
|
||||
@ -57,7 +58,7 @@ dependencies {
|
||||
|
||||
testFixturesApi("dev.forst:ktor-api-key:2.2.4")
|
||||
|
||||
testFixturesApi("org.jetbrains.kotlinx:kotlinx-serialization-json:1.6.0")
|
||||
testFixturesApi("org.jetbrains.kotlinx:kotlinx-serialization-json:$kotlinSerializeVersion")
|
||||
}
|
||||
|
||||
testing {
|
||||
|
@ -7,7 +7,7 @@ import kotlin.reflect.typeOf
|
||||
|
||||
class RequestInfo private constructor(
|
||||
val requestType: KType,
|
||||
val typeEnrichment: TypeEnrichment<*>?,
|
||||
val enrichment: TypeEnrichment<*>?,
|
||||
val description: String,
|
||||
val examples: Map<String, MediaType.Example>?,
|
||||
val mediaTypes: Set<String>,
|
||||
@ -60,7 +60,7 @@ class RequestInfo private constructor(
|
||||
fun build() = RequestInfo(
|
||||
requestType = requestType ?: error("Request type must be present"),
|
||||
description = description ?: error("Description must be present"),
|
||||
typeEnrichment = typeEnrichment,
|
||||
enrichment = typeEnrichment,
|
||||
examples = examples,
|
||||
mediaTypes = mediaTypes ?: setOf("application/json"),
|
||||
required = required ?: true
|
||||
|
@ -10,7 +10,7 @@ import kotlin.reflect.typeOf
|
||||
class ResponseInfo private constructor(
|
||||
val responseCode: HttpStatusCode,
|
||||
val responseType: KType,
|
||||
val typeEnrichment: TypeEnrichment<*>?,
|
||||
val enrichment: TypeEnrichment<*>?,
|
||||
val description: String,
|
||||
val examples: Map<String, MediaType.Example>?,
|
||||
val mediaTypes: Set<String>,
|
||||
@ -69,7 +69,7 @@ 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,
|
||||
enrichment = typeEnrichment,
|
||||
examples = examples,
|
||||
mediaTypes = mediaTypes ?: setOf("application/json"),
|
||||
responseHeaders = responseHeaders
|
||||
|
@ -6,7 +6,6 @@ import io.bkbn.kompendium.json.schema.SchemaConfigurator
|
||||
import io.bkbn.kompendium.json.schema.definition.JsonSchema
|
||||
import io.bkbn.kompendium.json.schema.util.Helpers.getSimpleSlug
|
||||
import io.bkbn.kompendium.oas.OpenApiSpec
|
||||
import io.ktor.server.application.call
|
||||
import io.ktor.server.application.createApplicationPlugin
|
||||
import io.ktor.server.response.respond
|
||||
import io.ktor.server.routing.Routing
|
||||
|
@ -78,7 +78,7 @@ object NotarizedRoute {
|
||||
|
||||
fun Route.calculateRoutePath() = toString()
|
||||
.let {
|
||||
application.environment.rootPath.takeIf { root -> root.isNotEmpty() }
|
||||
application.rootPath.takeIf { root -> root.isNotEmpty() }
|
||||
?.let { root ->
|
||||
val sanitizedRoute = if (root.startsWith("/")) root else "/$root"
|
||||
it.replace(sanitizedRoute, "")
|
||||
|
@ -42,6 +42,7 @@ object Helpers {
|
||||
}
|
||||
}
|
||||
|
||||
@Suppress("CyclomaticComplexMethod")
|
||||
fun MethodInfo.addToSpec(
|
||||
path: Path,
|
||||
spec: OpenApiSpec,
|
||||
@ -50,36 +51,45 @@ object Helpers {
|
||||
routePath: String,
|
||||
authMethods: List<String> = emptyList()
|
||||
) {
|
||||
val type = this.response.responseType
|
||||
val enrichment = this.response.enrichment
|
||||
SchemaGenerator.fromTypeOrUnit(
|
||||
type = this.response.responseType,
|
||||
type = type,
|
||||
cache = spec.components.schemas,
|
||||
schemaConfigurator = schemaConfigurator,
|
||||
enrichment = this.response.typeEnrichment,
|
||||
enrichment = enrichment,
|
||||
)?.let { schema ->
|
||||
spec.components.schemas[this.response.responseType.getSlug(this.response.typeEnrichment)] = schema
|
||||
val slug = type.getSlug(enrichment)
|
||||
spec.components.schemas[slug] = schema
|
||||
}
|
||||
|
||||
errors.forEach { error ->
|
||||
val errorEnrichment = error.enrichment
|
||||
val errorType = error.responseType
|
||||
SchemaGenerator.fromTypeOrUnit(
|
||||
type = error.responseType,
|
||||
type = errorType,
|
||||
cache = spec.components.schemas,
|
||||
schemaConfigurator = schemaConfigurator,
|
||||
enrichment = error.typeEnrichment,
|
||||
enrichment = errorEnrichment,
|
||||
)?.let { schema ->
|
||||
spec.components.schemas[error.responseType.getSlug(error.typeEnrichment)] = schema
|
||||
val slug = errorType.getSlug(errorEnrichment)
|
||||
spec.components.schemas[slug] = schema
|
||||
}
|
||||
}
|
||||
|
||||
when (this) {
|
||||
is MethodInfoWithRequest -> {
|
||||
this.request?.let { reqInfo ->
|
||||
val reqEnrichment = reqInfo.enrichment
|
||||
val reqType = reqInfo.requestType
|
||||
SchemaGenerator.fromTypeOrUnit(
|
||||
type = reqInfo.requestType,
|
||||
type = reqType,
|
||||
cache = spec.components.schemas,
|
||||
schemaConfigurator = schemaConfigurator,
|
||||
enrichment = reqInfo.typeEnrichment,
|
||||
enrichment = reqEnrichment,
|
||||
)?.let { schema ->
|
||||
spec.components.schemas[reqInfo.requestType.getSlug(reqInfo.typeEnrichment)] = schema
|
||||
val slug = reqType.getSlug(reqEnrichment)
|
||||
spec.components.schemas[slug] = schema
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -126,7 +136,7 @@ object Helpers {
|
||||
content = reqInfo.requestType.toReferenceContent(
|
||||
examples = reqInfo.examples,
|
||||
mediaTypes = reqInfo.mediaTypes,
|
||||
enrichment = reqInfo.typeEnrichment
|
||||
enrichment = reqInfo.enrichment
|
||||
),
|
||||
required = reqInfo.required
|
||||
)
|
||||
@ -141,7 +151,7 @@ object Helpers {
|
||||
content = this.response.responseType.toReferenceContent(
|
||||
examples = this.response.examples,
|
||||
mediaTypes = this.response.mediaTypes,
|
||||
enrichment = this.response.typeEnrichment
|
||||
enrichment = this.response.enrichment
|
||||
)
|
||||
)
|
||||
).plus(this.errors.toResponseMap())
|
||||
@ -173,7 +183,7 @@ object Helpers {
|
||||
content = error.responseType.toReferenceContent(
|
||||
examples = error.examples,
|
||||
mediaTypes = error.mediaTypes,
|
||||
enrichment = error.typeEnrichment
|
||||
enrichment = error.enrichment
|
||||
)
|
||||
)
|
||||
}
|
||||
|
@ -0,0 +1,172 @@
|
||||
package io.bkbn.kompendium.core
|
||||
|
||||
import dev.forst.ktor.apikey.apiKey
|
||||
import io.bkbn.kompendium.core.fixtures.TestHelpers
|
||||
import io.bkbn.kompendium.core.util.customAuthConfig
|
||||
import io.bkbn.kompendium.core.util.customScopesOnSiblingPathOperations
|
||||
import io.bkbn.kompendium.core.util.defaultAuthConfig
|
||||
import io.bkbn.kompendium.core.util.multipleAuthStrategies
|
||||
import io.bkbn.kompendium.oas.component.Components
|
||||
import io.bkbn.kompendium.oas.security.ApiKeyAuth
|
||||
import io.bkbn.kompendium.oas.security.BasicAuth
|
||||
import io.bkbn.kompendium.oas.security.BearerAuth
|
||||
import io.bkbn.kompendium.oas.security.OAuth
|
||||
import io.kotest.core.spec.style.DescribeSpec
|
||||
import io.ktor.client.HttpClient
|
||||
import io.ktor.client.engine.cio.CIO
|
||||
import io.ktor.http.HttpMethod
|
||||
import io.ktor.server.application.install
|
||||
import io.ktor.server.auth.Authentication
|
||||
import io.ktor.server.auth.OAuthServerSettings
|
||||
import io.ktor.server.auth.Principal
|
||||
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
|
||||
|
||||
class KompendiumAuthenticationTest : DescribeSpec({
|
||||
describe("Authentication") {
|
||||
it("Can add a default auth config by default") {
|
||||
TestHelpers.openApiTestAllSerializers(
|
||||
snapshotName = "T0045__default_auth_config.json",
|
||||
applicationSetup = {
|
||||
install(Authentication) {
|
||||
basic("basic") {
|
||||
realm = "Ktor Server"
|
||||
validate { UserIdPrincipal("Placeholder") }
|
||||
}
|
||||
}
|
||||
},
|
||||
specOverrides = {
|
||||
this.copy(
|
||||
components = Components(
|
||||
securitySchemes = mutableMapOf(
|
||||
"basic" to BasicAuth()
|
||||
)
|
||||
)
|
||||
)
|
||||
}
|
||||
) { defaultAuthConfig() }
|
||||
}
|
||||
it("Can provide custom auth config with proper scopes") {
|
||||
TestHelpers.openApiTestAllSerializers(
|
||||
snapshotName = "T0046__custom_auth_config.json",
|
||||
applicationSetup = {
|
||||
install(Authentication) {
|
||||
oauth("auth-oauth-google") {
|
||||
urlProvider = { "http://localhost:8080/callback" }
|
||||
providerLookup = {
|
||||
OAuthServerSettings.OAuth2ServerSettings(
|
||||
name = "google",
|
||||
authorizeUrl = "https://accounts.google.com/o/oauth2/auth",
|
||||
accessTokenUrl = "https://accounts.google.com/o/oauth2/token",
|
||||
requestMethod = HttpMethod.Post,
|
||||
clientId = "DUMMY_VAL",
|
||||
clientSecret = "DUMMY_VAL",
|
||||
defaultScopes = listOf("https://www.googleapis.com/auth/userinfo.profile"),
|
||||
extraTokenParameters = listOf("access_type" to "offline")
|
||||
)
|
||||
}
|
||||
client = HttpClient(CIO)
|
||||
}
|
||||
}
|
||||
},
|
||||
specOverrides = {
|
||||
this.copy(
|
||||
components = Components(
|
||||
securitySchemes = mutableMapOf(
|
||||
"auth-oauth-google" to OAuth(
|
||||
flows = OAuth.Flows(
|
||||
implicit = OAuth.Flows.Implicit(
|
||||
authorizationUrl = "https://accounts.google.com/o/oauth2/auth",
|
||||
scopes = mapOf(
|
||||
"write:pets" to "modify pets in your account",
|
||||
"read:pets" to "read your pets"
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
}
|
||||
) { customAuthConfig() }
|
||||
}
|
||||
it("Can provide multiple authentication strategies") {
|
||||
data class TestAppPrincipal(val key: String) : Principal
|
||||
TestHelpers.openApiTestAllSerializers(
|
||||
snapshotName = "T0047__multiple_auth_strategies.json",
|
||||
applicationSetup = {
|
||||
install(Authentication) {
|
||||
apiKey("api-key") {
|
||||
headerName = "X-API-KEY"
|
||||
validate { key ->
|
||||
// api key library (dev.forst.ktor.apikey) is using the deprecated `Principal` class
|
||||
key
|
||||
.takeIf { it == "api-key" }
|
||||
?.let { TestAppPrincipal(it) }
|
||||
}
|
||||
}
|
||||
jwt("jwt") {
|
||||
realm = "Server"
|
||||
}
|
||||
}
|
||||
},
|
||||
specOverrides = {
|
||||
this.copy(
|
||||
components = Components(
|
||||
securitySchemes = mutableMapOf(
|
||||
"jwt" to BearerAuth("JWT"),
|
||||
"api-key" to ApiKeyAuth(ApiKeyAuth.ApiKeyLocation.HEADER, "X-API-KEY")
|
||||
)
|
||||
)
|
||||
)
|
||||
}
|
||||
) { multipleAuthStrategies() }
|
||||
}
|
||||
it("Can provide different scopes on path operations in the same route") {
|
||||
TestHelpers.openApiTestAllSerializers(
|
||||
snapshotName = "T0074__auth_on_specific_path_operation.json",
|
||||
applicationSetup = {
|
||||
install(Authentication) {
|
||||
oauth("auth-oauth-google") {
|
||||
urlProvider = { "http://localhost:8080/callback" }
|
||||
providerLookup = {
|
||||
OAuthServerSettings.OAuth2ServerSettings(
|
||||
name = "google",
|
||||
authorizeUrl = "https://accounts.google.com/o/oauth2/auth",
|
||||
accessTokenUrl = "https://accounts.google.com/o/oauth2/token",
|
||||
requestMethod = HttpMethod.Post,
|
||||
clientId = "DUMMY_VAL",
|
||||
clientSecret = "DUMMY_VAL",
|
||||
defaultScopes = listOf("https://www.googleapis.com/auth/userinfo.profile"),
|
||||
extraTokenParameters = listOf("access_type" to "offline")
|
||||
)
|
||||
}
|
||||
client = HttpClient(CIO)
|
||||
}
|
||||
}
|
||||
},
|
||||
specOverrides = {
|
||||
this.copy(
|
||||
components = Components(
|
||||
securitySchemes = mutableMapOf(
|
||||
"auth-oauth-google" to OAuth(
|
||||
flows = OAuth.Flows(
|
||||
implicit = OAuth.Flows.Implicit(
|
||||
authorizationUrl = "https://accounts.google.com/o/oauth2/auth",
|
||||
scopes = mapOf(
|
||||
"write:pets" to "modify pets in your account",
|
||||
"read:pets" to "read your pets"
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
}
|
||||
) { customScopesOnSiblingPathOperations() }
|
||||
}
|
||||
}
|
||||
})
|
@ -0,0 +1,35 @@
|
||||
package io.bkbn.kompendium.core
|
||||
|
||||
import io.bkbn.kompendium.core.fixtures.TestHelpers
|
||||
import io.bkbn.kompendium.core.util.arrayConstraints
|
||||
import io.bkbn.kompendium.core.util.doubleConstraints
|
||||
import io.bkbn.kompendium.core.util.intConstraints
|
||||
import io.bkbn.kompendium.core.util.stringConstraints
|
||||
import io.bkbn.kompendium.core.util.stringContentEncodingConstraints
|
||||
import io.bkbn.kompendium.core.util.stringPatternConstraints
|
||||
import io.kotest.core.spec.style.DescribeSpec
|
||||
|
||||
class KompendiumConstraintsTest : DescribeSpec({
|
||||
describe("Constraints") {
|
||||
it("Can apply constraints to an int field") {
|
||||
TestHelpers.openApiTestAllSerializers("T0059__int_constraints.json") { intConstraints() }
|
||||
}
|
||||
it("Can apply constraints to a double field") {
|
||||
TestHelpers.openApiTestAllSerializers("T0060__double_constraints.json") { doubleConstraints() }
|
||||
}
|
||||
it("Can apply a min and max length to a string field") {
|
||||
TestHelpers.openApiTestAllSerializers("T0061__string_min_max_constraints.json") { stringConstraints() }
|
||||
}
|
||||
it("Can apply a pattern to a string field") {
|
||||
TestHelpers.openApiTestAllSerializers("T0062__string_pattern_constraints.json") { stringPatternConstraints() }
|
||||
}
|
||||
it("Can apply a content encoding and media type to a string field") {
|
||||
TestHelpers.openApiTestAllSerializers("T0063__string_content_encoding_constraints.json") {
|
||||
stringContentEncodingConstraints()
|
||||
}
|
||||
}
|
||||
it("Can apply constraints to an array field") {
|
||||
TestHelpers.openApiTestAllSerializers("T0064__array_constraints.json") { arrayConstraints() }
|
||||
}
|
||||
}
|
||||
})
|
@ -0,0 +1,13 @@
|
||||
package io.bkbn.kompendium.core
|
||||
|
||||
import io.bkbn.kompendium.core.fixtures.TestHelpers
|
||||
import io.bkbn.kompendium.core.util.defaultParameter
|
||||
import io.kotest.core.spec.style.DescribeSpec
|
||||
|
||||
class KompendiumDefaultsTest : DescribeSpec({
|
||||
describe("Defaults") {
|
||||
it("Can generate a default parameter value") {
|
||||
TestHelpers.openApiTestAllSerializers("T0022__query_with_default_parameter.json") { defaultParameter() }
|
||||
}
|
||||
}
|
||||
})
|
@ -0,0 +1,39 @@
|
||||
package io.bkbn.kompendium.core
|
||||
|
||||
import io.bkbn.kompendium.core.fixtures.TestHelpers.openApiTestAllSerializers
|
||||
import io.bkbn.kompendium.core.util.enrichedComplexGenericType
|
||||
import io.bkbn.kompendium.core.util.enrichedGenericResponse
|
||||
import io.bkbn.kompendium.core.util.enrichedMap
|
||||
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.enrichedTopLevelCollection
|
||||
import io.kotest.core.spec.style.DescribeSpec
|
||||
|
||||
class KompendiumEnrichmentTest : DescribeSpec({
|
||||
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() }
|
||||
}
|
||||
it("Can enrich a top level list type") {
|
||||
openApiTestAllSerializers("T0077__enriched_top_level_list.json") { enrichedTopLevelCollection() }
|
||||
}
|
||||
it("can enrich a map type") {
|
||||
openApiTestAllSerializers("T0078__enriched_top_level_map.json") { enrichedMap() }
|
||||
}
|
||||
}
|
||||
})
|
@ -0,0 +1,45 @@
|
||||
package io.bkbn.kompendium.core
|
||||
|
||||
import io.bkbn.kompendium.core.fixtures.TestHelpers
|
||||
import io.bkbn.kompendium.core.util.dateTimeString
|
||||
import io.bkbn.kompendium.core.util.samePathSameMethod
|
||||
import io.bkbn.kompendium.json.schema.exception.UnknownSchemaException
|
||||
import io.kotest.assertions.throwables.shouldThrow
|
||||
import io.kotest.core.spec.style.DescribeSpec
|
||||
import io.kotest.matchers.should
|
||||
import io.kotest.matchers.string.startWith
|
||||
import io.ktor.server.application.install
|
||||
import io.ktor.server.auth.Authentication
|
||||
import io.ktor.server.auth.UserIdPrincipal
|
||||
import io.ktor.server.auth.basic
|
||||
|
||||
class KompendiumErrorHandlingTest : DescribeSpec({
|
||||
describe("Error Handling") {
|
||||
it("Throws a clear exception when an unidentified type is encountered") {
|
||||
val exception = shouldThrow<UnknownSchemaException> {
|
||||
TestHelpers.openApiTestAllSerializers(
|
||||
""
|
||||
) { dateTimeString() }
|
||||
}
|
||||
exception.message should startWith("An unknown type was encountered: class java.time.Instant")
|
||||
}
|
||||
it("Throws an exception when same method for same path has been previously registered") {
|
||||
val exception = shouldThrow<IllegalArgumentException> {
|
||||
TestHelpers.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")
|
||||
}
|
||||
}
|
||||
})
|
@ -0,0 +1,27 @@
|
||||
package io.bkbn.kompendium.core
|
||||
|
||||
import io.bkbn.kompendium.core.fixtures.TestHelpers
|
||||
import io.bkbn.kompendium.core.util.exampleParams
|
||||
import io.bkbn.kompendium.core.util.exampleSummaryAndDescription
|
||||
import io.bkbn.kompendium.core.util.optionalReqExample
|
||||
import io.bkbn.kompendium.core.util.reqRespExamples
|
||||
import io.kotest.core.spec.style.DescribeSpec
|
||||
|
||||
class KompendiumExamplesTest : DescribeSpec({
|
||||
describe("Examples") {
|
||||
it("Can generate example response and request bodies") {
|
||||
TestHelpers.openApiTestAllSerializers("T0020__example_req_and_resp.json") { reqRespExamples() }
|
||||
}
|
||||
it("Can describe example parameters") {
|
||||
TestHelpers.openApiTestAllSerializers("T0021__example_parameters.json") { exampleParams() }
|
||||
}
|
||||
it("Can generate example optional request body") {
|
||||
TestHelpers.openApiTestAllSerializers("T0069__example_optional_req.json") { optionalReqExample() }
|
||||
}
|
||||
it("Can generate example summary and description") {
|
||||
TestHelpers.openApiTestAllSerializers(
|
||||
"T0075__example_summary_and_description.json"
|
||||
) { exampleSummaryAndDescription() }
|
||||
}
|
||||
}
|
||||
})
|
@ -0,0 +1,27 @@
|
||||
package io.bkbn.kompendium.core
|
||||
|
||||
import io.bkbn.kompendium.core.fixtures.TestHelpers
|
||||
import io.bkbn.kompendium.core.util.genericException
|
||||
import io.bkbn.kompendium.core.util.multipleExceptions
|
||||
import io.bkbn.kompendium.core.util.polymorphicException
|
||||
import io.bkbn.kompendium.core.util.singleException
|
||||
import io.kotest.core.spec.style.DescribeSpec
|
||||
|
||||
class KompendiumExceptionsTest : DescribeSpec({
|
||||
describe("Exceptions") {
|
||||
it("Can add an exception status code to a response") {
|
||||
TestHelpers.openApiTestAllSerializers("T0016__notarized_get_with_exception_response.json") { singleException() }
|
||||
}
|
||||
it("Can support multiple response codes") {
|
||||
TestHelpers.openApiTestAllSerializers("T0017__notarized_get_with_multiple_exception_responses.json") {
|
||||
multipleExceptions()
|
||||
}
|
||||
}
|
||||
it("Can add a polymorphic exception response") {
|
||||
TestHelpers.openApiTestAllSerializers("T0018__polymorphic_error_status_codes.json") { polymorphicException() }
|
||||
}
|
||||
it("Can add a generic exception response") {
|
||||
TestHelpers.openApiTestAllSerializers("T0019__generic_exception.json") { genericException() }
|
||||
}
|
||||
}
|
||||
})
|
@ -0,0 +1,7 @@
|
||||
package io.bkbn.kompendium.core
|
||||
|
||||
import io.kotest.core.spec.style.DescribeSpec
|
||||
|
||||
class KompendiumFreeFormTest : DescribeSpec({
|
||||
// todo Assess strategies here
|
||||
})
|
@ -0,0 +1,67 @@
|
||||
package io.bkbn.kompendium.core
|
||||
|
||||
import io.bkbn.kompendium.core.fixtures.TestHelpers
|
||||
import io.bkbn.kompendium.core.util.genericPolymorphicResponse
|
||||
import io.bkbn.kompendium.core.util.genericPolymorphicResponseMultipleImpls
|
||||
import io.bkbn.kompendium.core.util.gnarlyGenericResponse
|
||||
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.overrideSealedTypeIdentifier
|
||||
import io.bkbn.kompendium.core.util.polymorphicCollectionResponse
|
||||
import io.bkbn.kompendium.core.util.polymorphicMapResponse
|
||||
import io.bkbn.kompendium.core.util.polymorphicResponse
|
||||
import io.bkbn.kompendium.core.util.simpleGenericResponse
|
||||
import io.bkbn.kompendium.core.util.subtypeNotCompleteSetOfParentProperties
|
||||
import io.kotest.core.spec.style.DescribeSpec
|
||||
|
||||
class KompendiumPolymorphismAndGenericsTest : DescribeSpec({
|
||||
describe("Polymorphism and Generics") {
|
||||
it("can generate a polymorphic response type") {
|
||||
TestHelpers.openApiTestAllSerializers("T0027__polymorphic_response.json") { polymorphicResponse() }
|
||||
}
|
||||
it("Can generate a collection with polymorphic response type") {
|
||||
TestHelpers.openApiTestAllSerializers("T0028__polymorphic_list_response.json") { polymorphicCollectionResponse() }
|
||||
}
|
||||
it("Can generate a map with a polymorphic response type") {
|
||||
TestHelpers.openApiTestAllSerializers("T0029__polymorphic_map_response.json") { polymorphicMapResponse() }
|
||||
}
|
||||
it("Can generate a response type with a generic type") {
|
||||
TestHelpers.openApiTestAllSerializers("T0030__simple_generic_response.json") { simpleGenericResponse() }
|
||||
}
|
||||
it("Can generate a response type with a nested generic type") {
|
||||
TestHelpers.openApiTestAllSerializers("T0031__nested_generic_response.json") { nestedGenericResponse() }
|
||||
}
|
||||
it("Can generate a polymorphic response type with generics") {
|
||||
TestHelpers.openApiTestAllSerializers(
|
||||
"T0032__polymorphic_response_with_generics.json"
|
||||
) { genericPolymorphicResponse() }
|
||||
}
|
||||
it("Can handle an absolutely psycho inheritance test") {
|
||||
TestHelpers.openApiTestAllSerializers("T0033__crazy_polymorphic_example.json") {
|
||||
genericPolymorphicResponseMultipleImpls()
|
||||
}
|
||||
}
|
||||
it("Can support nested generic collections") {
|
||||
TestHelpers.openApiTestAllSerializers("T0039__nested_generic_collection.json") { nestedGenericCollection() }
|
||||
}
|
||||
it("Can support nested generics with multiple type parameters") {
|
||||
TestHelpers.openApiTestAllSerializers("T0040__nested_generic_multiple_type_params.json") {
|
||||
nestedGenericMultipleParamsCollection()
|
||||
}
|
||||
}
|
||||
it("Can handle a really gnarly generic example") {
|
||||
TestHelpers.openApiTestAllSerializers("T0043__gnarly_generic_example.json") { gnarlyGenericResponse() }
|
||||
}
|
||||
it("Can override the type name for a sealed interface implementation") {
|
||||
TestHelpers.openApiTestAllSerializers("T0070__sealed_interface_type_name_override.json") {
|
||||
overrideSealedTypeIdentifier()
|
||||
}
|
||||
}
|
||||
it("Can serialize an object where the subtype is not a complete set of parent properties") {
|
||||
TestHelpers.openApiTestAllSerializers("T0071__subtype_not_complete_set_of_parent_properties.json") {
|
||||
subtypeNotCompleteSetOfParentProperties()
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
@ -0,0 +1,25 @@
|
||||
package io.bkbn.kompendium.core
|
||||
|
||||
import io.bkbn.kompendium.core.fixtures.TestHelpers
|
||||
import io.bkbn.kompendium.core.util.defaultField
|
||||
import io.bkbn.kompendium.core.util.nonRequiredParam
|
||||
import io.bkbn.kompendium.core.util.nullableField
|
||||
import io.bkbn.kompendium.core.util.requiredParams
|
||||
import io.kotest.core.spec.style.DescribeSpec
|
||||
|
||||
class KompendiumRequiredFieldsTest : DescribeSpec({
|
||||
describe("Required Fields") {
|
||||
it("Marks a parameter as required if there is no default and it is not marked nullable") {
|
||||
TestHelpers.openApiTestAllSerializers("T0023__required_param.json") { requiredParams() }
|
||||
}
|
||||
it("Can mark a parameter as not required") {
|
||||
TestHelpers.openApiTestAllSerializers("T0024__non_required_param.json") { nonRequiredParam() }
|
||||
}
|
||||
it("Does not mark a field as required if a default value is provided") {
|
||||
TestHelpers.openApiTestAllSerializers("T0025__default_field.json") { defaultField() }
|
||||
}
|
||||
it("Does not mark a nullable field as required") {
|
||||
TestHelpers.openApiTestAllSerializers("T0026__nullable_field.json") { nullableField() }
|
||||
}
|
||||
}
|
||||
})
|
@ -0,0 +1,29 @@
|
||||
package io.bkbn.kompendium.core
|
||||
|
||||
import io.bkbn.kompendium.core.fixtures.TestHelpers
|
||||
import io.bkbn.kompendium.core.util.nestedUnderRoot
|
||||
import io.bkbn.kompendium.core.util.paramWrapper
|
||||
import io.bkbn.kompendium.core.util.rootRoute
|
||||
import io.bkbn.kompendium.core.util.simplePathParsing
|
||||
import io.bkbn.kompendium.core.util.trailingSlash
|
||||
import io.kotest.core.spec.style.DescribeSpec
|
||||
|
||||
class KompendiumRouteParsingTest : DescribeSpec({
|
||||
describe("Route Parsing") {
|
||||
it("Can parse a simple path and store it under the expected route") {
|
||||
TestHelpers.openApiTestAllSerializers("T0012__path_parser.json") { simplePathParsing() }
|
||||
}
|
||||
it("Can notarize the root route") {
|
||||
TestHelpers.openApiTestAllSerializers("T0013__root_route.json") { rootRoute() }
|
||||
}
|
||||
it("Can notarize a route under the root module without appending trailing slash") {
|
||||
TestHelpers.openApiTestAllSerializers("T0014__nested_under_root.json") { nestedUnderRoot() }
|
||||
}
|
||||
it("Can notarize a route with a trailing slash") {
|
||||
TestHelpers.openApiTestAllSerializers("T0015__trailing_slash.json") { trailingSlash() }
|
||||
}
|
||||
it("Can notarize a route with a parameter") {
|
||||
TestHelpers.openApiTestAllSerializers("T0068__param_wrapper.json") { paramWrapper() }
|
||||
}
|
||||
}
|
||||
})
|
@ -1,39 +1,13 @@
|
||||
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
|
||||
import io.bkbn.kompendium.core.util.customScopesOnSiblingPathOperations
|
||||
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.enrichedComplexGenericType
|
||||
import io.bkbn.kompendium.core.util.enrichedGenericResponse
|
||||
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.exampleSummaryAndDescription
|
||||
import io.bkbn.kompendium.core.util.fieldOutsideConstructor
|
||||
import io.bkbn.kompendium.core.util.genericException
|
||||
import io.bkbn.kompendium.core.util.genericPolymorphicResponse
|
||||
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
|
||||
@ -47,67 +21,33 @@ import io.bkbn.kompendium.core.util.nullableEnumField
|
||||
import io.bkbn.kompendium.core.util.nullableField
|
||||
import io.bkbn.kompendium.core.util.nullableNestedObject
|
||||
import io.bkbn.kompendium.core.util.nullableReference
|
||||
import io.bkbn.kompendium.core.util.optionalReqExample
|
||||
import io.bkbn.kompendium.core.util.overrideMediaTypes
|
||||
import io.bkbn.kompendium.core.util.overrideSealedTypeIdentifier
|
||||
import io.bkbn.kompendium.core.util.paramWrapper
|
||||
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.requiredParams
|
||||
import io.bkbn.kompendium.core.util.responseHeaders
|
||||
import io.bkbn.kompendium.core.util.returnsEnumList
|
||||
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.subtypeNotCompleteSetOfParentProperties
|
||||
import io.bkbn.kompendium.core.util.topLevelNullable
|
||||
import io.bkbn.kompendium.core.util.trailingSlash
|
||||
import io.bkbn.kompendium.core.util.unbackedFieldsResponse
|
||||
import io.bkbn.kompendium.core.util.withOperationId
|
||||
import io.bkbn.kompendium.json.schema.definition.TypeDefinition
|
||||
import io.bkbn.kompendium.json.schema.exception.UnknownSchemaException
|
||||
import io.bkbn.kompendium.oas.component.Components
|
||||
import io.bkbn.kompendium.oas.security.ApiKeyAuth
|
||||
import io.bkbn.kompendium.oas.security.BasicAuth
|
||||
import io.bkbn.kompendium.oas.security.BearerAuth
|
||||
import io.bkbn.kompendium.oas.security.OAuth
|
||||
import io.bkbn.kompendium.oas.serialization.KompendiumSerializersModule
|
||||
import io.kotest.assertions.throwables.shouldThrow
|
||||
import io.kotest.core.spec.style.DescribeSpec
|
||||
import io.kotest.matchers.should
|
||||
import io.kotest.matchers.string.startWith
|
||||
import io.ktor.client.HttpClient
|
||||
import io.ktor.client.engine.cio.CIO
|
||||
import io.ktor.http.HttpMethod
|
||||
import io.ktor.serialization.kotlinx.json.json
|
||||
import io.ktor.server.application.call
|
||||
import io.ktor.server.application.install
|
||||
import io.ktor.server.auth.Authentication
|
||||
import io.ktor.server.auth.OAuthServerSettings
|
||||
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 io.ktor.server.response.respondText
|
||||
import io.ktor.server.routing.get
|
||||
import io.ktor.server.routing.route
|
||||
import kotlinx.serialization.encodeToString
|
||||
import kotlinx.serialization.json.Json
|
||||
import java.net.URI
|
||||
import java.time.Instant
|
||||
import kotlin.reflect.typeOf
|
||||
|
||||
class KompendiumTest : DescribeSpec({
|
||||
describe("Notarized Open API Metadata Tests") {
|
||||
@ -154,56 +94,6 @@ class KompendiumTest : DescribeSpec({
|
||||
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") {
|
||||
openApiTestAllSerializers("T0012__path_parser.json") { simplePathParsing() }
|
||||
}
|
||||
it("Can notarize the root route") {
|
||||
openApiTestAllSerializers("T0013__root_route.json") { rootRoute() }
|
||||
}
|
||||
it("Can notarize a route under the root module without appending trailing slash") {
|
||||
openApiTestAllSerializers("T0014__nested_under_root.json") { nestedUnderRoot() }
|
||||
}
|
||||
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") {
|
||||
openApiTestAllSerializers("T0016__notarized_get_with_exception_response.json") { singleException() }
|
||||
}
|
||||
it("Can support multiple response codes") {
|
||||
openApiTestAllSerializers("T0017__notarized_get_with_multiple_exception_responses.json") { multipleExceptions() }
|
||||
}
|
||||
it("Can add a polymorphic exception response") {
|
||||
openApiTestAllSerializers("T0018__polymorphic_error_status_codes.json") { polymorphicException() }
|
||||
}
|
||||
it("Can add a generic exception response") {
|
||||
openApiTestAllSerializers("T0019__generic_exception.json") { genericException() }
|
||||
}
|
||||
}
|
||||
describe("Examples") {
|
||||
it("Can generate example response and request bodies") {
|
||||
openApiTestAllSerializers("T0020__example_req_and_resp.json") { reqRespExamples() }
|
||||
}
|
||||
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() }
|
||||
}
|
||||
it("Can generate example summary and description") {
|
||||
openApiTestAllSerializers("T0075__example_summary_and_description.json") { exampleSummaryAndDescription() }
|
||||
}
|
||||
}
|
||||
describe("Defaults") {
|
||||
it("Can generate a default parameter value") {
|
||||
openApiTestAllSerializers("T0022__query_with_default_parameter.json") { defaultParameter() }
|
||||
}
|
||||
}
|
||||
describe("Required Fields") {
|
||||
it("Marks a parameter as required if there is no default and it is not marked nullable") {
|
||||
openApiTestAllSerializers("T0023__required_param.json") { requiredParams() }
|
||||
@ -218,47 +108,6 @@ class KompendiumTest : DescribeSpec({
|
||||
openApiTestAllSerializers("T0026__nullable_field.json") { nullableField() }
|
||||
}
|
||||
}
|
||||
describe("Polymorphism and Generics") {
|
||||
it("can generate a polymorphic response type") {
|
||||
openApiTestAllSerializers("T0027__polymorphic_response.json") { polymorphicResponse() }
|
||||
}
|
||||
it("Can generate a collection with polymorphic response type") {
|
||||
openApiTestAllSerializers("T0028__polymorphic_list_response.json") { polymorphicCollectionResponse() }
|
||||
}
|
||||
it("Can generate a map with a polymorphic response type") {
|
||||
openApiTestAllSerializers("T0029__polymorphic_map_response.json") { polymorphicMapResponse() }
|
||||
}
|
||||
it("Can generate a response type with a generic type") {
|
||||
openApiTestAllSerializers("T0030__simple_generic_response.json") { simpleGenericResponse() }
|
||||
}
|
||||
it("Can generate a response type with a nested generic type") {
|
||||
openApiTestAllSerializers("T0031__nested_generic_response.json") { nestedGenericResponse() }
|
||||
}
|
||||
it("Can generate a polymorphic response type with generics") {
|
||||
openApiTestAllSerializers("T0032__polymorphic_response_with_generics.json") { genericPolymorphicResponse() }
|
||||
}
|
||||
it("Can handle an absolutely psycho inheritance test") {
|
||||
openApiTestAllSerializers("T0033__crazy_polymorphic_example.json") { genericPolymorphicResponseMultipleImpls() }
|
||||
}
|
||||
it("Can support nested generic collections") {
|
||||
openApiTestAllSerializers("T0039__nested_generic_collection.json") { nestedGenericCollection() }
|
||||
}
|
||||
it("Can support nested generics with multiple type parameters") {
|
||||
openApiTestAllSerializers("T0040__nested_generic_multiple_type_params.json") {
|
||||
nestedGenericMultipleParamsCollection()
|
||||
}
|
||||
}
|
||||
it("Can handle a really gnarly generic example") {
|
||||
openApiTestAllSerializers("T0043__gnarly_generic_example.json") { gnarlyGenericResponse() }
|
||||
}
|
||||
it("Can override the type name for a sealed interface implementation") {
|
||||
openApiTestAllSerializers("T0070__sealed_interface_type_name_override.json") { overrideSealedTypeIdentifier() }
|
||||
}
|
||||
it("Can serialize an object where the subtype is not a complete set of parent properties") {
|
||||
openApiTestAllSerializers("T0071__subtype_not_complete_set_of_parent_properties.json") {
|
||||
subtypeNotCompleteSetOfParentProperties()
|
||||
}
|
||||
}
|
||||
describe("Custom Serializable Reader tests") {
|
||||
it("Can support ignoring fields") {
|
||||
openApiTestAllSerializers("T0048__ignored_property.json") { ignoredFieldsResponse() }
|
||||
@ -295,6 +144,9 @@ class KompendiumTest : DescribeSpec({
|
||||
it("Can have a nullable enum as a member field") {
|
||||
openApiTestAllSerializers("T0037__nullable_enum_field.json") { nullableEnumField() }
|
||||
}
|
||||
it("Can have a list of enums as a field") {
|
||||
openApiTestAllSerializers("T0076__list_of_enums.json") { returnsEnumList() }
|
||||
}
|
||||
it("Can have a nullable reference without impacting base type") {
|
||||
openApiTestAllSerializers("T0041__nullable_reference.json") { nullableReference() }
|
||||
}
|
||||
@ -329,13 +181,16 @@ class KompendiumTest : DescribeSpec({
|
||||
it("Can generate paths without application root-path") {
|
||||
openApiTestAllSerializers(
|
||||
"T0054__app_with_rootpath.json",
|
||||
applicationEnvironmentBuilder = {
|
||||
applicationSetup = {
|
||||
rootPath = "/example"
|
||||
},
|
||||
specOverrides = {
|
||||
copy(
|
||||
servers = servers.map { it.copy(url = URI("${it.url}/example")) }.toMutableList()
|
||||
)
|
||||
},
|
||||
serverConfigSetup = {
|
||||
rootPath = "/example"
|
||||
}
|
||||
) { notarizedGet() }
|
||||
}
|
||||
@ -349,15 +204,13 @@ class KompendiumTest : DescribeSpec({
|
||||
snapshotName = "T0072__custom_serialization_strategy.json",
|
||||
notarizedApplicationConfigOverrides = {
|
||||
specRoute = { spec, routing ->
|
||||
routing {
|
||||
route("/openapi.json") {
|
||||
routing.route("/openapi.json") {
|
||||
get {
|
||||
call.response.headers.append("Content-Type", "application/json")
|
||||
call.respondText { customJsonEncoder.encodeToString(spec) }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
contentNegotiation = {
|
||||
json(
|
||||
@ -373,219 +226,4 @@ class KompendiumTest : DescribeSpec({
|
||||
openApiTestAllSerializers("T0073__data_class_with_field_outside_constructor.json") { fieldOutsideConstructor() }
|
||||
}
|
||||
}
|
||||
describe("Error Handling") {
|
||||
it("Throws a clear exception when an unidentified type is encountered") {
|
||||
val exception = shouldThrow<UnknownSchemaException> { openApiTestAllSerializers("") { dateTimeString() } }
|
||||
exception.message should startWith("An unknown type was encountered: class java.time.Instant")
|
||||
}
|
||||
it("Throws an exception when same method for same path has been previously registered") {
|
||||
val exception = shouldThrow<IllegalArgumentException> {
|
||||
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("Formats") {
|
||||
it("Can set a format for a simple type schema") {
|
||||
openApiTestAllSerializers(
|
||||
snapshotName = "T0038__formatted_date_time_string.json",
|
||||
customTypes = mapOf(typeOf<Instant>() to TypeDefinition(type = "string", format = "date"))
|
||||
) { dateTimeString() }
|
||||
}
|
||||
}
|
||||
describe("Free Form") {
|
||||
// todo Assess strategies here
|
||||
}
|
||||
describe("Authentication") {
|
||||
it("Can add a default auth config by default") {
|
||||
openApiTestAllSerializers(
|
||||
snapshotName = "T0045__default_auth_config.json",
|
||||
applicationSetup = {
|
||||
install(Authentication) {
|
||||
basic("basic") {
|
||||
realm = "Ktor Server"
|
||||
validate { UserIdPrincipal("Placeholder") }
|
||||
}
|
||||
}
|
||||
},
|
||||
specOverrides = {
|
||||
this.copy(
|
||||
components = Components(
|
||||
securitySchemes = mutableMapOf(
|
||||
"basic" to BasicAuth()
|
||||
)
|
||||
)
|
||||
)
|
||||
}
|
||||
) { defaultAuthConfig() }
|
||||
}
|
||||
it("Can provide custom auth config with proper scopes") {
|
||||
openApiTestAllSerializers(
|
||||
snapshotName = "T0046__custom_auth_config.json",
|
||||
applicationSetup = {
|
||||
install(Authentication) {
|
||||
oauth("auth-oauth-google") {
|
||||
urlProvider = { "http://localhost:8080/callback" }
|
||||
providerLookup = {
|
||||
OAuthServerSettings.OAuth2ServerSettings(
|
||||
name = "google",
|
||||
authorizeUrl = "https://accounts.google.com/o/oauth2/auth",
|
||||
accessTokenUrl = "https://accounts.google.com/o/oauth2/token",
|
||||
requestMethod = HttpMethod.Post,
|
||||
clientId = "DUMMY_VAL",
|
||||
clientSecret = "DUMMY_VAL",
|
||||
defaultScopes = listOf("https://www.googleapis.com/auth/userinfo.profile"),
|
||||
extraTokenParameters = listOf("access_type" to "offline")
|
||||
)
|
||||
}
|
||||
client = HttpClient(CIO)
|
||||
}
|
||||
}
|
||||
},
|
||||
specOverrides = {
|
||||
this.copy(
|
||||
components = Components(
|
||||
securitySchemes = mutableMapOf(
|
||||
"auth-oauth-google" to OAuth(
|
||||
flows = OAuth.Flows(
|
||||
implicit = OAuth.Flows.Implicit(
|
||||
authorizationUrl = "https://accounts.google.com/o/oauth2/auth",
|
||||
scopes = mapOf(
|
||||
"write:pets" to "modify pets in your account",
|
||||
"read:pets" to "read your pets"
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
}
|
||||
) { customAuthConfig() }
|
||||
}
|
||||
it("Can provide multiple authentication strategies") {
|
||||
openApiTestAllSerializers(
|
||||
snapshotName = "T0047__multiple_auth_strategies.json",
|
||||
applicationSetup = {
|
||||
install(Authentication) {
|
||||
apiKey("api-key") {
|
||||
headerName = "X-API-KEY"
|
||||
validate {
|
||||
UserIdPrincipal("Placeholder")
|
||||
}
|
||||
}
|
||||
jwt("jwt") {
|
||||
realm = "Server"
|
||||
}
|
||||
}
|
||||
},
|
||||
specOverrides = {
|
||||
this.copy(
|
||||
components = Components(
|
||||
securitySchemes = mutableMapOf(
|
||||
"jwt" to BearerAuth("JWT"),
|
||||
"api-key" to ApiKeyAuth(ApiKeyAuth.ApiKeyLocation.HEADER, "X-API-KEY")
|
||||
)
|
||||
)
|
||||
)
|
||||
}
|
||||
) { multipleAuthStrategies() }
|
||||
}
|
||||
it("Can provide different scopes on path operations in the same route") {
|
||||
openApiTestAllSerializers(
|
||||
snapshotName = "T0074__auth_on_specific_path_operation.json",
|
||||
applicationSetup = {
|
||||
install(Authentication) {
|
||||
oauth("auth-oauth-google") {
|
||||
urlProvider = { "http://localhost:8080/callback" }
|
||||
providerLookup = {
|
||||
OAuthServerSettings.OAuth2ServerSettings(
|
||||
name = "google",
|
||||
authorizeUrl = "https://accounts.google.com/o/oauth2/auth",
|
||||
accessTokenUrl = "https://accounts.google.com/o/oauth2/token",
|
||||
requestMethod = HttpMethod.Post,
|
||||
clientId = "DUMMY_VAL",
|
||||
clientSecret = "DUMMY_VAL",
|
||||
defaultScopes = listOf("https://www.googleapis.com/auth/userinfo.profile"),
|
||||
extraTokenParameters = listOf("access_type" to "offline")
|
||||
)
|
||||
}
|
||||
client = HttpClient(CIO)
|
||||
}
|
||||
}
|
||||
},
|
||||
specOverrides = {
|
||||
this.copy(
|
||||
components = Components(
|
||||
securitySchemes = mutableMapOf(
|
||||
"auth-oauth-google" to OAuth(
|
||||
flows = OAuth.Flows(
|
||||
implicit = OAuth.Flows.Implicit(
|
||||
authorizationUrl = "https://accounts.google.com/o/oauth2/auth",
|
||||
scopes = mapOf(
|
||||
"write:pets" to "modify pets in your account",
|
||||
"read:pets" to "read your pets"
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
}
|
||||
) { customScopesOnSiblingPathOperations() }
|
||||
}
|
||||
}
|
||||
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() }
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
@ -0,0 +1,19 @@
|
||||
package io.bkbn.kompendium.core
|
||||
|
||||
import io.bkbn.kompendium.core.fixtures.TestHelpers
|
||||
import io.bkbn.kompendium.core.util.dateTimeString
|
||||
import io.bkbn.kompendium.json.schema.definition.TypeDefinition
|
||||
import io.kotest.core.spec.style.DescribeSpec
|
||||
import java.time.Instant
|
||||
import kotlin.reflect.typeOf
|
||||
|
||||
class KompendiumTypeFormatTest : DescribeSpec({
|
||||
describe("Formats") {
|
||||
it("Can set a format for a simple type schema") {
|
||||
TestHelpers.openApiTestAllSerializers(
|
||||
snapshotName = "T0038__formatted_date_time_string.json",
|
||||
customTypes = mapOf(typeOf<Instant>() to TypeDefinition(type = "string", format = "date"))
|
||||
) { dateTimeString() }
|
||||
}
|
||||
}
|
||||
})
|
@ -9,13 +9,11 @@ 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.ktor.http.HttpStatusCode
|
||||
import io.ktor.server.application.install
|
||||
import io.ktor.server.auth.authenticate
|
||||
import io.ktor.server.routing.Routing
|
||||
import io.ktor.server.routing.post
|
||||
import io.ktor.server.routing.Route
|
||||
import io.ktor.server.routing.route
|
||||
|
||||
fun Routing.defaultAuthConfig() {
|
||||
fun Route.defaultAuthConfig() {
|
||||
authenticate("basic") {
|
||||
route(rootPath) {
|
||||
basicGetGenerator<TestResponse>()
|
||||
@ -23,7 +21,7 @@ fun Routing.defaultAuthConfig() {
|
||||
}
|
||||
}
|
||||
|
||||
fun Routing.customAuthConfig() {
|
||||
fun Route.customAuthConfig() {
|
||||
authenticate("auth-oauth-google") {
|
||||
route(rootPath) {
|
||||
install(NotarizedRoute()) {
|
||||
@ -44,7 +42,7 @@ fun Routing.customAuthConfig() {
|
||||
}
|
||||
}
|
||||
|
||||
fun Routing.customScopesOnSiblingPathOperations() {
|
||||
fun Route.customScopesOnSiblingPathOperations() {
|
||||
authenticate("auth-oauth-google") {
|
||||
route(rootPath) {
|
||||
install(NotarizedRoute()) {
|
||||
@ -81,7 +79,7 @@ fun Routing.customScopesOnSiblingPathOperations() {
|
||||
}
|
||||
}
|
||||
|
||||
fun Routing.multipleAuthStrategies() {
|
||||
fun Route.multipleAuthStrategies() {
|
||||
authenticate("jwt", "api-key") {
|
||||
route(rootPath) {
|
||||
basicGetGenerator<TestResponse>()
|
||||
|
@ -7,13 +7,15 @@ 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.bkbn.kompendium.enrichment.CollectionEnrichment
|
||||
import io.bkbn.kompendium.enrichment.NumberEnrichment
|
||||
import io.bkbn.kompendium.enrichment.ObjectEnrichment
|
||||
import io.bkbn.kompendium.enrichment.StringEnrichment
|
||||
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.route
|
||||
|
||||
fun Routing.intConstraints() {
|
||||
fun Route.intConstraints() {
|
||||
route(defaultPath) {
|
||||
install(NotarizedRoute()) {
|
||||
get = GetInfo.builder {
|
||||
@ -23,22 +25,24 @@ fun Routing.intConstraints() {
|
||||
responseCode(HttpStatusCode.OK)
|
||||
description("An int")
|
||||
responseType(
|
||||
enrichment = TypeEnrichment("example") {
|
||||
enrichment = ObjectEnrichment("example") {
|
||||
TestCreatedResponse::id {
|
||||
NumberEnrichment("blah-blah-blah") {
|
||||
minimum = 2
|
||||
maximum = 100
|
||||
multipleOf = 2
|
||||
}
|
||||
}
|
||||
)
|
||||
responseCode(HttpStatusCode.OK)
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun Routing.doubleConstraints() {
|
||||
fun Route.doubleConstraints() {
|
||||
route(defaultPath) {
|
||||
install(NotarizedRoute()) {
|
||||
get = GetInfo.builder {
|
||||
@ -48,13 +52,15 @@ fun Routing.doubleConstraints() {
|
||||
responseCode(HttpStatusCode.OK)
|
||||
description("A double")
|
||||
responseType(
|
||||
enrichment = TypeEnrichment("example") {
|
||||
enrichment = ObjectEnrichment("example") {
|
||||
DoubleResponse::payload {
|
||||
NumberEnrichment("blah-blah-blah") {
|
||||
minimum = 2.0
|
||||
maximum = 100.0
|
||||
multipleOf = 2.0
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
responseCode(HttpStatusCode.OK)
|
||||
}
|
||||
@ -63,7 +69,7 @@ fun Routing.doubleConstraints() {
|
||||
}
|
||||
}
|
||||
|
||||
fun Routing.stringConstraints() {
|
||||
fun Route.stringConstraints() {
|
||||
route(defaultPath) {
|
||||
install(NotarizedRoute()) {
|
||||
get = GetInfo.builder {
|
||||
@ -73,12 +79,14 @@ fun Routing.stringConstraints() {
|
||||
responseCode(HttpStatusCode.OK)
|
||||
description("A string")
|
||||
responseType(
|
||||
enrichment = TypeEnrichment("example") {
|
||||
enrichment = ObjectEnrichment("example") {
|
||||
TestNested::nesty {
|
||||
StringEnrichment("blah") {
|
||||
maxLength = 10
|
||||
minLength = 2
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
responseCode(HttpStatusCode.OK)
|
||||
}
|
||||
@ -87,7 +95,7 @@ fun Routing.stringConstraints() {
|
||||
}
|
||||
}
|
||||
|
||||
fun Routing.stringPatternConstraints() {
|
||||
fun Route.stringPatternConstraints() {
|
||||
route(defaultPath) {
|
||||
install(NotarizedRoute()) {
|
||||
get = GetInfo.builder {
|
||||
@ -97,11 +105,13 @@ fun Routing.stringPatternConstraints() {
|
||||
responseCode(HttpStatusCode.OK)
|
||||
description("A string")
|
||||
responseType(
|
||||
enrichment = TypeEnrichment("example") {
|
||||
enrichment = ObjectEnrichment("example") {
|
||||
TestNested::nesty {
|
||||
StringEnrichment("blah") {
|
||||
pattern = "[a-z]+"
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
responseCode(HttpStatusCode.OK)
|
||||
}
|
||||
@ -110,7 +120,7 @@ fun Routing.stringPatternConstraints() {
|
||||
}
|
||||
}
|
||||
|
||||
fun Routing.stringContentEncodingConstraints() {
|
||||
fun Route.stringContentEncodingConstraints() {
|
||||
route(defaultPath) {
|
||||
install(NotarizedRoute()) {
|
||||
get = GetInfo.builder {
|
||||
@ -120,12 +130,14 @@ fun Routing.stringContentEncodingConstraints() {
|
||||
responseCode(HttpStatusCode.OK)
|
||||
description("A string")
|
||||
responseType(
|
||||
enrichment = TypeEnrichment("example") {
|
||||
enrichment = ObjectEnrichment("example") {
|
||||
TestNested::nesty {
|
||||
StringEnrichment("blah") {
|
||||
contentEncoding = "base64"
|
||||
contentMediaType = "image/png"
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
responseCode(HttpStatusCode.OK)
|
||||
}
|
||||
@ -134,7 +146,7 @@ fun Routing.stringContentEncodingConstraints() {
|
||||
}
|
||||
}
|
||||
|
||||
fun Routing.arrayConstraints() {
|
||||
fun Route.arrayConstraints() {
|
||||
route(defaultPath) {
|
||||
install(NotarizedRoute()) {
|
||||
get = GetInfo.builder {
|
||||
@ -144,13 +156,15 @@ fun Routing.arrayConstraints() {
|
||||
responseCode(HttpStatusCode.OK)
|
||||
description("An array")
|
||||
responseType(
|
||||
enrichment = TypeEnrichment("example") {
|
||||
enrichment = ObjectEnrichment("example") {
|
||||
Page<String>::content {
|
||||
CollectionEnrichment<String>("blah") {
|
||||
minItems = 2
|
||||
maxItems = 10
|
||||
uniqueItems = true
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
responseCode(HttpStatusCode.OK)
|
||||
}
|
||||
|
@ -3,8 +3,8 @@ package io.bkbn.kompendium.core.util
|
||||
import io.bkbn.kompendium.core.fixtures.SerialNameObject
|
||||
import io.bkbn.kompendium.core.fixtures.TransientObject
|
||||
import io.bkbn.kompendium.core.fixtures.UnbackedObject
|
||||
import io.ktor.server.routing.Routing
|
||||
import io.ktor.server.routing.Route
|
||||
|
||||
fun Routing.ignoredFieldsResponse() = basicGetGenerator<TransientObject>()
|
||||
fun Routing.unbackedFieldsResponse() = basicGetGenerator<UnbackedObject>()
|
||||
fun Routing.customFieldNameResponse() = basicGetGenerator<SerialNameObject>()
|
||||
fun Route.ignoredFieldsResponse() = basicGetGenerator<TransientObject>()
|
||||
fun Route.unbackedFieldsResponse() = basicGetGenerator<UnbackedObject>()
|
||||
fun Route.customFieldNameResponse() = basicGetGenerator<SerialNameObject>()
|
||||
|
@ -3,9 +3,9 @@ package io.bkbn.kompendium.core.util
|
||||
import io.bkbn.kompendium.core.fixtures.TestResponse
|
||||
import io.bkbn.kompendium.json.schema.definition.TypeDefinition
|
||||
import io.bkbn.kompendium.oas.payload.Parameter
|
||||
import io.ktor.server.routing.Routing
|
||||
import io.ktor.server.routing.Route
|
||||
|
||||
fun Routing.defaultParameter() = basicGetGenerator<TestResponse>(
|
||||
fun Route.defaultParameter() = basicGetGenerator<TestResponse>(
|
||||
params = listOf(
|
||||
Parameter(
|
||||
name = "id",
|
||||
|
@ -1,22 +1,25 @@
|
||||
package io.bkbn.kompendium.core.util
|
||||
|
||||
import io.bkbn.kompendium.core.fixtures.ComplexRequest
|
||||
import io.bkbn.kompendium.core.fixtures.GenericObject
|
||||
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.bkbn.kompendium.enrichment.CollectionEnrichment
|
||||
import io.bkbn.kompendium.enrichment.MapEnrichment
|
||||
import io.bkbn.kompendium.enrichment.NumberEnrichment
|
||||
import io.bkbn.kompendium.enrichment.ObjectEnrichment
|
||||
import io.bkbn.kompendium.enrichment.StringEnrichment
|
||||
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.route
|
||||
|
||||
fun Routing.enrichedSimpleResponse() {
|
||||
fun Route.enrichedSimpleResponse() {
|
||||
route("/enriched") {
|
||||
install(NotarizedRoute()) {
|
||||
get = GetInfo.builder {
|
||||
@ -24,11 +27,13 @@ fun Routing.enrichedSimpleResponse() {
|
||||
description(TestModules.defaultPathDescription)
|
||||
response {
|
||||
responseType(
|
||||
enrichment = TypeEnrichment("simple") {
|
||||
enrichment = ObjectEnrichment("simple") {
|
||||
TestResponse::c {
|
||||
StringEnrichment("blah-blah-blah") {
|
||||
description = "A simple description"
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
description("A good response")
|
||||
responseCode(HttpStatusCode.Created)
|
||||
@ -38,7 +43,7 @@ fun Routing.enrichedSimpleResponse() {
|
||||
}
|
||||
}
|
||||
|
||||
fun Routing.enrichedSimpleRequest() {
|
||||
fun Route.enrichedSimpleRequest() {
|
||||
route("/example") {
|
||||
install(NotarizedRoute()) {
|
||||
parameters = TestModules.defaultParams
|
||||
@ -47,14 +52,18 @@ fun Routing.enrichedSimpleRequest() {
|
||||
description(TestModules.defaultPathDescription)
|
||||
request {
|
||||
requestType(
|
||||
enrichment = TypeEnrichment("simple") {
|
||||
enrichment = ObjectEnrichment("simple") {
|
||||
TestSimpleRequest::a {
|
||||
StringEnrichment("blah-blah-blah") {
|
||||
description = "A simple description"
|
||||
}
|
||||
}
|
||||
TestSimpleRequest::b {
|
||||
NumberEnrichment("blah-blah-blah") {
|
||||
deprecated = true
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
description("A test request")
|
||||
}
|
||||
@ -68,7 +77,7 @@ fun Routing.enrichedSimpleRequest() {
|
||||
}
|
||||
}
|
||||
|
||||
fun Routing.enrichedNestedCollection() {
|
||||
fun Route.enrichedNestedCollection() {
|
||||
route("/example") {
|
||||
install(NotarizedRoute()) {
|
||||
parameters = TestModules.defaultParams
|
||||
@ -77,16 +86,20 @@ fun Routing.enrichedNestedCollection() {
|
||||
description(TestModules.defaultPathDescription)
|
||||
request {
|
||||
requestType(
|
||||
enrichment = TypeEnrichment("simple") {
|
||||
enrichment = ObjectEnrichment("simple") {
|
||||
ComplexRequest::tables {
|
||||
description = "A nested item"
|
||||
typeEnrichment = TypeEnrichment("nested") {
|
||||
CollectionEnrichment<NestedComplexItem>("blah-blah") {
|
||||
description = "A nested description"
|
||||
itemEnrichment = ObjectEnrichment("nested") {
|
||||
NestedComplexItem::name {
|
||||
StringEnrichment("beleheh") {
|
||||
description = "A nested description"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
description("A test request")
|
||||
}
|
||||
@ -100,7 +113,7 @@ fun Routing.enrichedNestedCollection() {
|
||||
}
|
||||
}
|
||||
|
||||
fun Routing.enrichedComplexGenericType() {
|
||||
fun Route.enrichedTopLevelCollection() {
|
||||
route("/example") {
|
||||
install(NotarizedRoute()) {
|
||||
parameters = TestModules.defaultParams
|
||||
@ -109,15 +122,57 @@ fun Routing.enrichedComplexGenericType() {
|
||||
description(TestModules.defaultPathDescription)
|
||||
request {
|
||||
requestType(
|
||||
enrichment = TypeEnrichment("simple") {
|
||||
enrichment = CollectionEnrichment<List<TestSimpleRequest>>("blah-blah") {
|
||||
itemEnrichment = ObjectEnrichment("simple") {
|
||||
TestSimpleRequest::a {
|
||||
StringEnrichment("blah-blah-blah") {
|
||||
description = "A simple description"
|
||||
}
|
||||
}
|
||||
TestSimpleRequest::b {
|
||||
NumberEnrichment("blah-blah-blah") {
|
||||
deprecated = true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
description("A test request")
|
||||
}
|
||||
response {
|
||||
responseCode(HttpStatusCode.Created)
|
||||
responseType<TestCreatedResponse>()
|
||||
description(TestModules.defaultResponseDescription)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun Route.enrichedComplexGenericType() {
|
||||
route("/example") {
|
||||
install(NotarizedRoute()) {
|
||||
parameters = TestModules.defaultParams
|
||||
post = PostInfo.builder {
|
||||
summary(TestModules.defaultPathSummary)
|
||||
description(TestModules.defaultPathDescription)
|
||||
request {
|
||||
requestType(
|
||||
enrichment = ObjectEnrichment("simple") {
|
||||
MultiNestedGenerics<String, ComplexRequest>::content {
|
||||
description = "Getting pretty crazy"
|
||||
typeEnrichment = TypeEnrichment("nested") {
|
||||
ComplexRequest::tables {
|
||||
description = "A nested item"
|
||||
typeEnrichment = TypeEnrichment("nested") {
|
||||
NestedComplexItem::name {
|
||||
MapEnrichment<ComplexRequest>("blah") {
|
||||
description = "A nested description"
|
||||
valueEnrichment = ObjectEnrichment("nested") {
|
||||
ComplexRequest::tables {
|
||||
CollectionEnrichment<NestedComplexItem>("blah-blah") {
|
||||
description = "A nested description"
|
||||
itemEnrichment = ObjectEnrichment("nested") {
|
||||
NestedComplexItem::name {
|
||||
StringEnrichment("beleheh") {
|
||||
description = "A nested description"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -137,7 +192,7 @@ fun Routing.enrichedComplexGenericType() {
|
||||
}
|
||||
}
|
||||
|
||||
fun Routing.enrichedGenericResponse() {
|
||||
fun Route.enrichedGenericResponse() {
|
||||
route("/example") {
|
||||
install(NotarizedRoute()) {
|
||||
get = GetInfo.builder {
|
||||
@ -145,14 +200,51 @@ fun Routing.enrichedGenericResponse() {
|
||||
description(TestModules.defaultPathDescription)
|
||||
response {
|
||||
responseType(
|
||||
enrichment = TypeEnrichment("generic") {
|
||||
enrichment = ObjectEnrichment("generic") {
|
||||
description = "another description"
|
||||
GenericObject<TestSimpleRequest>::data {
|
||||
description = "A simple description"
|
||||
typeEnrichment = TypeEnrichment("simple") {
|
||||
ObjectEnrichment("simple") {
|
||||
description = "also a description"
|
||||
TestSimpleRequest::a {
|
||||
StringEnrichment("blah-blah-blah") {
|
||||
description = "A simple description"
|
||||
}
|
||||
}
|
||||
TestSimpleRequest::b {
|
||||
NumberEnrichment("blah-blah-blah") {
|
||||
deprecated = true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
description("A good response")
|
||||
responseCode(HttpStatusCode.Created)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun Route.enrichedMap() {
|
||||
route("/example") {
|
||||
install(NotarizedRoute()) {
|
||||
get = GetInfo.builder {
|
||||
summary(TestModules.defaultPathSummary)
|
||||
description(TestModules.defaultPathDescription)
|
||||
response {
|
||||
responseType<Map<String, TestSimpleRequest>>(
|
||||
enrichment = MapEnrichment("blah") {
|
||||
description = "A nested description"
|
||||
valueEnrichment = ObjectEnrichment("nested") {
|
||||
TestSimpleRequest::a {
|
||||
StringEnrichment("blah-blah-blah") {
|
||||
description = "A simple description"
|
||||
}
|
||||
}
|
||||
TestSimpleRequest::b {
|
||||
NumberEnrichment("blah-blah-blah") {
|
||||
deprecated = true
|
||||
}
|
||||
}
|
||||
|
@ -3,10 +3,10 @@ package io.bkbn.kompendium.core.util
|
||||
import io.bkbn.kompendium.core.fixtures.TestResponse
|
||||
import io.bkbn.kompendium.core.util.TestModules.defaultPath
|
||||
import io.ktor.server.auth.authenticate
|
||||
import io.ktor.server.routing.Routing
|
||||
import io.ktor.server.routing.Route
|
||||
import io.ktor.server.routing.route
|
||||
|
||||
fun Routing.samePathSameMethod() {
|
||||
fun Route.samePathSameMethod() {
|
||||
route(defaultPath) {
|
||||
basicGetGenerator<TestResponse>()
|
||||
authenticate("basic") {
|
||||
|
@ -14,11 +14,10 @@ import io.bkbn.kompendium.json.schema.definition.TypeDefinition
|
||||
import io.bkbn.kompendium.oas.payload.MediaType
|
||||
import io.bkbn.kompendium.oas.payload.Parameter
|
||||
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.route
|
||||
|
||||
fun Routing.reqRespExamples() {
|
||||
fun Route.reqRespExamples() {
|
||||
route(rootPath) {
|
||||
install(NotarizedRoute()) {
|
||||
post = PostInfo.builder {
|
||||
@ -44,7 +43,7 @@ fun Routing.reqRespExamples() {
|
||||
}
|
||||
}
|
||||
|
||||
fun Routing.exampleParams() = basicGetGenerator<TestResponse>(
|
||||
fun Route.exampleParams() = basicGetGenerator<TestResponse>(
|
||||
params = listOf(
|
||||
Parameter(
|
||||
name = "id",
|
||||
@ -57,7 +56,7 @@ fun Routing.exampleParams() = basicGetGenerator<TestResponse>(
|
||||
)
|
||||
)
|
||||
|
||||
fun Routing.optionalReqExample() {
|
||||
fun Route.optionalReqExample() {
|
||||
route(rootPath) {
|
||||
install(NotarizedRoute()) {
|
||||
post = PostInfo.builder {
|
||||
@ -84,7 +83,7 @@ fun Routing.optionalReqExample() {
|
||||
}
|
||||
}
|
||||
|
||||
fun Routing.exampleSummaryAndDescription() {
|
||||
fun Route.exampleSummaryAndDescription() {
|
||||
route(rootPath) {
|
||||
install(NotarizedRoute()) {
|
||||
post = PostInfo.builder {
|
||||
|
@ -11,11 +11,10 @@ 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.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.route
|
||||
|
||||
fun Routing.singleException() {
|
||||
fun Route.singleException() {
|
||||
route(rootPath) {
|
||||
install(NotarizedRoute()) {
|
||||
get = GetInfo.builder {
|
||||
@ -36,7 +35,7 @@ fun Routing.singleException() {
|
||||
}
|
||||
}
|
||||
|
||||
fun Routing.multipleExceptions() {
|
||||
fun Route.multipleExceptions() {
|
||||
route(rootPath) {
|
||||
install(NotarizedRoute()) {
|
||||
get = GetInfo.builder {
|
||||
@ -62,7 +61,7 @@ fun Routing.multipleExceptions() {
|
||||
}
|
||||
}
|
||||
|
||||
fun Routing.polymorphicException() {
|
||||
fun Route.polymorphicException() {
|
||||
route(rootPath) {
|
||||
install(NotarizedRoute()) {
|
||||
get = GetInfo.builder {
|
||||
@ -83,7 +82,7 @@ fun Routing.polymorphicException() {
|
||||
}
|
||||
}
|
||||
|
||||
fun Routing.genericException() {
|
||||
fun Route.genericException() {
|
||||
route(rootPath) {
|
||||
install(NotarizedRoute()) {
|
||||
get = GetInfo.builder {
|
||||
|
@ -21,17 +21,16 @@ import io.bkbn.kompendium.core.util.TestModules.defaultResponseDescription
|
||||
import io.bkbn.kompendium.json.schema.definition.TypeDefinition
|
||||
import io.bkbn.kompendium.oas.payload.Parameter
|
||||
import io.ktor.http.HttpStatusCode
|
||||
import io.ktor.server.application.install
|
||||
import io.ktor.server.auth.authenticate
|
||||
import io.ktor.server.routing.Routing
|
||||
import io.ktor.server.routing.Route
|
||||
import io.ktor.server.routing.route
|
||||
|
||||
fun Routing.withOperationId() = basicGetGenerator<TestResponse>(operationId = "getThisDude")
|
||||
fun Routing.nullableNestedObject() = basicGetGenerator<ProfileUpdateRequest>()
|
||||
fun Routing.nullableEnumField() = basicGetGenerator<NullableEnum>()
|
||||
fun Routing.nullableReference() = basicGetGenerator<ManyThings>()
|
||||
fun Routing.dateTimeString() = basicGetGenerator<DateTimeString>()
|
||||
fun Routing.headerParameter() = basicGetGenerator<TestResponse>(
|
||||
fun Route.withOperationId() = basicGetGenerator<TestResponse>(operationId = "getThisDude")
|
||||
fun Route.nullableNestedObject() = basicGetGenerator<ProfileUpdateRequest>()
|
||||
fun Route.nullableEnumField() = basicGetGenerator<NullableEnum>()
|
||||
fun Route.nullableReference() = basicGetGenerator<ManyThings>()
|
||||
fun Route.dateTimeString() = basicGetGenerator<DateTimeString>()
|
||||
fun Route.headerParameter() = basicGetGenerator<TestResponse>(
|
||||
params = listOf(
|
||||
Parameter(
|
||||
name = "X-User-Email",
|
||||
@ -42,10 +41,10 @@ fun Routing.headerParameter() = basicGetGenerator<TestResponse>(
|
||||
)
|
||||
)
|
||||
|
||||
fun Routing.nestedTypeName() = basicGetGenerator<Nested.Response>()
|
||||
fun Routing.topLevelNullable() = basicGetGenerator<TestResponse?>()
|
||||
fun Routing.simpleRecursive() = basicGetGenerator<ColumnSchema>()
|
||||
fun Routing.samePathDifferentMethodsAndAuth() {
|
||||
fun Route.nestedTypeName() = basicGetGenerator<Nested.Response>()
|
||||
fun Route.topLevelNullable() = basicGetGenerator<TestResponse?>()
|
||||
fun Route.simpleRecursive() = basicGetGenerator<ColumnSchema>()
|
||||
fun Route.samePathDifferentMethodsAndAuth() {
|
||||
route(defaultPath) {
|
||||
install(NotarizedRoute()) {
|
||||
parameters = defaultParams
|
||||
|
@ -3,6 +3,7 @@ package io.bkbn.kompendium.core.util
|
||||
import io.bkbn.kompendium.core.fixtures.ComplexRequest
|
||||
import io.bkbn.kompendium.core.fixtures.SomethingSimilar
|
||||
import io.bkbn.kompendium.core.fixtures.TestCreatedResponse
|
||||
import io.bkbn.kompendium.core.fixtures.TestEnum
|
||||
import io.bkbn.kompendium.core.fixtures.TestRequest
|
||||
import io.bkbn.kompendium.core.fixtures.TestResponse
|
||||
import io.bkbn.kompendium.core.fixtures.TestSimpleRequest
|
||||
@ -25,11 +26,9 @@ 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
|
||||
import io.ktor.server.response.respond
|
||||
import io.ktor.server.response.respondText
|
||||
import io.ktor.server.routing.Routing
|
||||
import io.ktor.server.routing.Route
|
||||
import io.ktor.server.routing.delete
|
||||
import io.ktor.server.routing.get
|
||||
import io.ktor.server.routing.head
|
||||
@ -39,7 +38,7 @@ import io.ktor.server.routing.post
|
||||
import io.ktor.server.routing.put
|
||||
import io.ktor.server.routing.route
|
||||
|
||||
fun Routing.notarizedGet() {
|
||||
fun Route.notarizedGet() {
|
||||
route(defaultPath) {
|
||||
install(NotarizedRoute()) {
|
||||
parameters = defaultParams
|
||||
@ -59,7 +58,7 @@ fun Routing.notarizedGet() {
|
||||
}
|
||||
}
|
||||
|
||||
fun Routing.responseHeaders() {
|
||||
fun Route.responseHeaders() {
|
||||
route(defaultPath) {
|
||||
install(NotarizedRoute()) {
|
||||
parameters = defaultParams
|
||||
@ -91,7 +90,7 @@ fun Routing.responseHeaders() {
|
||||
}
|
||||
}
|
||||
|
||||
fun Routing.notarizedPost() {
|
||||
fun Route.notarizedPost() {
|
||||
route(defaultPath) {
|
||||
install(NotarizedRoute()) {
|
||||
parameters = defaultParams
|
||||
@ -115,7 +114,7 @@ fun Routing.notarizedPost() {
|
||||
}
|
||||
}
|
||||
|
||||
fun Routing.notarizedPut() {
|
||||
fun Route.notarizedPut() {
|
||||
route(defaultPath) {
|
||||
install(NotarizedRoute()) {
|
||||
parameters = defaultParams
|
||||
@ -139,7 +138,7 @@ fun Routing.notarizedPut() {
|
||||
}
|
||||
}
|
||||
|
||||
fun Routing.notarizedDelete() {
|
||||
fun Route.notarizedDelete() {
|
||||
route(defaultPath) {
|
||||
install(NotarizedRoute()) {
|
||||
parameters = defaultParams
|
||||
@ -159,7 +158,7 @@ fun Routing.notarizedDelete() {
|
||||
}
|
||||
}
|
||||
|
||||
fun Routing.notarizedPatch() {
|
||||
fun Route.notarizedPatch() {
|
||||
route(defaultPath) {
|
||||
install(NotarizedRoute()) {
|
||||
parameters = defaultParams
|
||||
@ -183,7 +182,7 @@ fun Routing.notarizedPatch() {
|
||||
}
|
||||
}
|
||||
|
||||
fun Routing.notarizedHead() {
|
||||
fun Route.notarizedHead() {
|
||||
route(defaultPath) {
|
||||
install(NotarizedRoute()) {
|
||||
parameters = defaultParams
|
||||
@ -204,7 +203,7 @@ fun Routing.notarizedHead() {
|
||||
}
|
||||
}
|
||||
|
||||
fun Routing.notarizedOptions() {
|
||||
fun Route.notarizedOptions() {
|
||||
route(defaultPath) {
|
||||
install(NotarizedRoute()) {
|
||||
parameters = defaultParams
|
||||
@ -224,7 +223,7 @@ fun Routing.notarizedOptions() {
|
||||
}
|
||||
}
|
||||
|
||||
fun Routing.complexRequest() {
|
||||
fun Route.complexRequest() {
|
||||
route(rootPath) {
|
||||
install(NotarizedRoute()) {
|
||||
put = PutInfo.builder {
|
||||
@ -247,7 +246,7 @@ fun Routing.complexRequest() {
|
||||
}
|
||||
}
|
||||
|
||||
fun Routing.primitives() {
|
||||
fun Route.primitives() {
|
||||
route(rootPath) {
|
||||
install(NotarizedRoute()) {
|
||||
put = PutInfo.builder {
|
||||
@ -267,7 +266,7 @@ fun Routing.primitives() {
|
||||
}
|
||||
}
|
||||
|
||||
fun Routing.returnsList() {
|
||||
fun Route.returnsList() {
|
||||
route(defaultPath) {
|
||||
install(NotarizedRoute()) {
|
||||
parameters = defaultParams
|
||||
@ -284,7 +283,24 @@ fun Routing.returnsList() {
|
||||
}
|
||||
}
|
||||
|
||||
fun Routing.nonRequiredParams() {
|
||||
fun Route.returnsEnumList() {
|
||||
route(defaultPath) {
|
||||
install(NotarizedRoute()) {
|
||||
parameters = defaultParams
|
||||
get = GetInfo.builder {
|
||||
summary(defaultPathSummary)
|
||||
description(defaultPathDescription)
|
||||
response {
|
||||
description("A Successful List-y Endeavor")
|
||||
responseCode(HttpStatusCode.OK)
|
||||
responseType<List<TestEnum>>()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun Route.nonRequiredParams() {
|
||||
route("/optional") {
|
||||
install(NotarizedRoute()) {
|
||||
parameters = listOf(
|
||||
@ -313,7 +329,7 @@ fun Routing.nonRequiredParams() {
|
||||
}
|
||||
}
|
||||
|
||||
fun Routing.overrideMediaTypes() {
|
||||
fun Route.overrideMediaTypes() {
|
||||
route("/media_types") {
|
||||
install(NotarizedRoute()) {
|
||||
put = PutInfo.builder {
|
||||
@ -335,7 +351,7 @@ fun Routing.overrideMediaTypes() {
|
||||
}
|
||||
}
|
||||
|
||||
fun Routing.postNoReqBody() {
|
||||
fun Route.postNoReqBody() {
|
||||
route("/no_req_body") {
|
||||
install(NotarizedRoute()) {
|
||||
post = PostInfo.builder {
|
||||
@ -351,7 +367,7 @@ fun Routing.postNoReqBody() {
|
||||
}
|
||||
}
|
||||
|
||||
fun Routing.fieldOutsideConstructor() {
|
||||
fun Route.fieldOutsideConstructor() {
|
||||
route("/field_outside_constructor") {
|
||||
install(NotarizedRoute()) {
|
||||
post = PostInfo.builder {
|
||||
|
@ -10,17 +10,17 @@ import io.bkbn.kompendium.core.fixtures.Gibbity
|
||||
import io.bkbn.kompendium.core.fixtures.Gizmo
|
||||
import io.bkbn.kompendium.core.fixtures.MultiNestedGenerics
|
||||
import io.bkbn.kompendium.core.fixtures.Page
|
||||
import io.ktor.server.routing.Routing
|
||||
import io.ktor.server.routing.Route
|
||||
|
||||
fun Routing.polymorphicResponse() = basicGetGenerator<FlibbityGibbit>()
|
||||
fun Routing.polymorphicCollectionResponse() = basicGetGenerator<List<FlibbityGibbit>>()
|
||||
fun Routing.polymorphicMapResponse() = basicGetGenerator<Map<String, FlibbityGibbit>>()
|
||||
fun Routing.simpleGenericResponse() = basicGetGenerator<Gibbity<String>>()
|
||||
fun Routing.gnarlyGenericResponse() = basicGetGenerator<Foosy<Barzo<Int>, String>>()
|
||||
fun Routing.nestedGenericResponse() = basicGetGenerator<Gibbity<Map<String, String>>>()
|
||||
fun Routing.genericPolymorphicResponse() = basicGetGenerator<Flibbity<Double>>()
|
||||
fun Routing.genericPolymorphicResponseMultipleImpls() = basicGetGenerator<Flibbity<FlibbityGibbit>>()
|
||||
fun Routing.nestedGenericCollection() = basicGetGenerator<Page<Int>>()
|
||||
fun Routing.nestedGenericMultipleParamsCollection() = basicGetGenerator<MultiNestedGenerics<String, ComplexRequest>>()
|
||||
fun Routing.overrideSealedTypeIdentifier() = basicGetGenerator<ChillaxificationMaximization>()
|
||||
fun Routing.subtypeNotCompleteSetOfParentProperties() = basicGetGenerator<Gizmo>()
|
||||
fun Route.polymorphicResponse() = basicGetGenerator<FlibbityGibbit>()
|
||||
fun Route.polymorphicCollectionResponse() = basicGetGenerator<List<FlibbityGibbit>>()
|
||||
fun Route.polymorphicMapResponse() = basicGetGenerator<Map<String, FlibbityGibbit>>()
|
||||
fun Route.simpleGenericResponse() = basicGetGenerator<Gibbity<String>>()
|
||||
fun Route.gnarlyGenericResponse() = basicGetGenerator<Foosy<Barzo<Int>, String>>()
|
||||
fun Route.nestedGenericResponse() = basicGetGenerator<Gibbity<Map<String, String>>>()
|
||||
fun Route.genericPolymorphicResponse() = basicGetGenerator<Flibbity<Double>>()
|
||||
fun Route.genericPolymorphicResponseMultipleImpls() = basicGetGenerator<Flibbity<FlibbityGibbit>>()
|
||||
fun Route.nestedGenericCollection() = basicGetGenerator<Page<Int>>()
|
||||
fun Route.nestedGenericMultipleParamsCollection() = basicGetGenerator<MultiNestedGenerics<String, ComplexRequest>>()
|
||||
fun Route.overrideSealedTypeIdentifier() = basicGetGenerator<ChillaxificationMaximization>()
|
||||
fun Route.subtypeNotCompleteSetOfParentProperties() = basicGetGenerator<Gizmo>()
|
||||
|
@ -5,9 +5,9 @@ import io.bkbn.kompendium.core.fixtures.NullableField
|
||||
import io.bkbn.kompendium.core.fixtures.TestResponse
|
||||
import io.bkbn.kompendium.json.schema.definition.TypeDefinition
|
||||
import io.bkbn.kompendium.oas.payload.Parameter
|
||||
import io.ktor.server.routing.Routing
|
||||
import io.ktor.server.routing.Route
|
||||
|
||||
fun Routing.requiredParams() = basicGetGenerator<TestResponse>(
|
||||
fun Route.requiredParams() = basicGetGenerator<TestResponse>(
|
||||
params = listOf(
|
||||
Parameter(
|
||||
name = "id",
|
||||
@ -17,7 +17,7 @@ fun Routing.requiredParams() = basicGetGenerator<TestResponse>(
|
||||
)
|
||||
)
|
||||
|
||||
fun Routing.nonRequiredParam() = basicGetGenerator<TestResponse>(
|
||||
fun Route.nonRequiredParam() = basicGetGenerator<TestResponse>(
|
||||
params = listOf(
|
||||
Parameter(
|
||||
name = "id",
|
||||
@ -28,5 +28,5 @@ fun Routing.nonRequiredParam() = basicGetGenerator<TestResponse>(
|
||||
)
|
||||
)
|
||||
|
||||
fun Routing.defaultField() = basicGetGenerator<DefaultField>()
|
||||
fun Routing.nullableField() = basicGetGenerator<NullableField>()
|
||||
fun Route.defaultField() = basicGetGenerator<DefaultField>()
|
||||
fun Route.nullableField() = basicGetGenerator<NullableField>()
|
||||
|
@ -11,12 +11,11 @@ import io.bkbn.kompendium.core.util.TestModules.rootPath
|
||||
import io.bkbn.kompendium.json.schema.definition.TypeDefinition
|
||||
import io.bkbn.kompendium.oas.payload.Parameter
|
||||
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.route
|
||||
import io.ktor.server.routing.param
|
||||
|
||||
fun Routing.simplePathParsing() {
|
||||
fun Route.simplePathParsing() {
|
||||
route("/this") {
|
||||
route("/is") {
|
||||
route("/a") {
|
||||
@ -49,7 +48,7 @@ fun Routing.simplePathParsing() {
|
||||
}
|
||||
}
|
||||
|
||||
fun Routing.rootRoute() {
|
||||
fun Route.rootRoute() {
|
||||
route(rootPath) {
|
||||
install(NotarizedRoute()) {
|
||||
parameters = listOf(defaultParams.last())
|
||||
@ -66,7 +65,7 @@ fun Routing.rootRoute() {
|
||||
}
|
||||
}
|
||||
|
||||
fun Routing.nestedUnderRoot() {
|
||||
fun Route.nestedUnderRoot() {
|
||||
route("/") {
|
||||
route("/testerino") {
|
||||
install(NotarizedRoute()) {
|
||||
@ -84,7 +83,7 @@ fun Routing.nestedUnderRoot() {
|
||||
}
|
||||
}
|
||||
|
||||
fun Routing.trailingSlash() {
|
||||
fun Route.trailingSlash() {
|
||||
route("/test") {
|
||||
route("/") {
|
||||
install(NotarizedRoute()) {
|
||||
@ -102,7 +101,7 @@ fun Routing.trailingSlash() {
|
||||
}
|
||||
}
|
||||
|
||||
fun Routing.paramWrapper() {
|
||||
fun Route.paramWrapper() {
|
||||
route("/test") {
|
||||
param("a") {
|
||||
param("b") {
|
||||
|
@ -9,7 +9,6 @@ import io.bkbn.kompendium.core.util.TestModules.rootPath
|
||||
import io.bkbn.kompendium.json.schema.definition.TypeDefinition
|
||||
import io.bkbn.kompendium.oas.payload.Parameter
|
||||
import io.ktor.http.HttpStatusCode
|
||||
import io.ktor.server.application.install
|
||||
import io.ktor.server.routing.Route
|
||||
import io.ktor.server.routing.Routing
|
||||
import io.ktor.server.routing.route
|
||||
|
@ -132,7 +132,6 @@
|
||||
]
|
||||
},
|
||||
"SimpleEnum": {
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"ONE",
|
||||
"TWO"
|
||||
|
@ -88,7 +88,6 @@
|
||||
"type": "string"
|
||||
},
|
||||
"type": {
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"io.bkbn.kompendium.core.fixtures.ComplexGibbit"
|
||||
]
|
||||
@ -111,7 +110,6 @@
|
||||
"type": "string"
|
||||
},
|
||||
"type": {
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"io.bkbn.kompendium.core.fixtures.SimpleGibbit"
|
||||
]
|
||||
|
@ -84,7 +84,6 @@
|
||||
"type": "string"
|
||||
},
|
||||
"type": {
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"io.bkbn.kompendium.core.fixtures.Bibbity"
|
||||
]
|
||||
@ -103,7 +102,6 @@
|
||||
"type": "string"
|
||||
},
|
||||
"type": {
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"io.bkbn.kompendium.core.fixtures.Gibbity"
|
||||
]
|
||||
|
@ -67,7 +67,6 @@
|
||||
"type": "string"
|
||||
},
|
||||
"type": {
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"io.bkbn.kompendium.core.fixtures.ComplexGibbit"
|
||||
]
|
||||
@ -90,7 +89,6 @@
|
||||
"type": "string"
|
||||
},
|
||||
"type": {
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"io.bkbn.kompendium.core.fixtures.SimpleGibbit"
|
||||
]
|
||||
|
@ -67,7 +67,6 @@
|
||||
"type": "string"
|
||||
},
|
||||
"type": {
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"io.bkbn.kompendium.core.fixtures.ComplexGibbit"
|
||||
]
|
||||
@ -90,7 +89,6 @@
|
||||
"type": "string"
|
||||
},
|
||||
"type": {
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"io.bkbn.kompendium.core.fixtures.SimpleGibbit"
|
||||
]
|
||||
|
@ -67,7 +67,6 @@
|
||||
"type": "string"
|
||||
},
|
||||
"type": {
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"io.bkbn.kompendium.core.fixtures.ComplexGibbit"
|
||||
]
|
||||
@ -90,7 +89,6 @@
|
||||
"type": "string"
|
||||
},
|
||||
"type": {
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"io.bkbn.kompendium.core.fixtures.SimpleGibbit"
|
||||
]
|
||||
|
@ -64,7 +64,6 @@
|
||||
"format": "double"
|
||||
},
|
||||
"type": {
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"io.bkbn.kompendium.core.fixtures.Bibbity"
|
||||
]
|
||||
@ -84,7 +83,6 @@
|
||||
"format": "double"
|
||||
},
|
||||
"type": {
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"io.bkbn.kompendium.core.fixtures.Gibbity"
|
||||
]
|
||||
|
@ -70,7 +70,6 @@
|
||||
]
|
||||
},
|
||||
"type": {
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"io.bkbn.kompendium.core.fixtures.Bibbity"
|
||||
]
|
||||
@ -96,7 +95,6 @@
|
||||
"type": "string"
|
||||
},
|
||||
"type": {
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"io.bkbn.kompendium.core.fixtures.ComplexGibbit"
|
||||
]
|
||||
@ -119,7 +117,6 @@
|
||||
"type": "string"
|
||||
},
|
||||
"type": {
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"io.bkbn.kompendium.core.fixtures.SimpleGibbit"
|
||||
]
|
||||
@ -144,7 +141,6 @@
|
||||
]
|
||||
},
|
||||
"type": {
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"io.bkbn.kompendium.core.fixtures.Gibbity"
|
||||
]
|
||||
|
@ -71,7 +71,6 @@
|
||||
},
|
||||
"TestEnum":
|
||||
{
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"YES",
|
||||
"NO"
|
||||
|
@ -119,7 +119,6 @@
|
||||
]
|
||||
},
|
||||
"SimpleEnum": {
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"ONE",
|
||||
"TWO"
|
||||
|
@ -54,7 +54,6 @@
|
||||
"components": {
|
||||
"schemas": {
|
||||
"ColumnMode": {
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"NULLABLE",
|
||||
"REQUIRED",
|
||||
|
@ -111,9 +111,9 @@
|
||||
},
|
||||
"tables": {
|
||||
"items": {
|
||||
"$ref": "#/components/schemas/NestedComplexItem-nested"
|
||||
"$ref": "#/components/schemas/NestedComplexItem-blah-blah"
|
||||
},
|
||||
"description": "A nested item",
|
||||
"description": "A nested description",
|
||||
"type": "array"
|
||||
}
|
||||
},
|
||||
@ -154,11 +154,29 @@
|
||||
]
|
||||
},
|
||||
"SimpleEnum": {
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"ONE",
|
||||
"TWO"
|
||||
]
|
||||
},
|
||||
"NestedComplexItem-blah-blah": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"alias": {
|
||||
"additionalProperties": {
|
||||
"$ref": "#/components/schemas/CrazyItem"
|
||||
},
|
||||
"type": "object"
|
||||
},
|
||||
"name": {
|
||||
"type": "string",
|
||||
"description": "A nested description"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"alias",
|
||||
"name"
|
||||
]
|
||||
}
|
||||
},
|
||||
"securitySchemes": {}
|
||||
|
@ -105,9 +105,9 @@
|
||||
"properties": {
|
||||
"content": {
|
||||
"additionalProperties": {
|
||||
"$ref": "#/components/schemas/ComplexRequest-nested"
|
||||
"$ref": "#/components/schemas/ComplexRequest-blah"
|
||||
},
|
||||
"description": "Getting pretty crazy",
|
||||
"description": "A nested description",
|
||||
"type": "object"
|
||||
}
|
||||
},
|
||||
@ -126,9 +126,9 @@
|
||||
},
|
||||
"tables": {
|
||||
"items": {
|
||||
"$ref": "#/components/schemas/NestedComplexItem-nested"
|
||||
"$ref": "#/components/schemas/NestedComplexItem-blah-blah"
|
||||
},
|
||||
"description": "A nested item",
|
||||
"description": "A nested description",
|
||||
"type": "array"
|
||||
}
|
||||
},
|
||||
@ -169,11 +169,52 @@
|
||||
]
|
||||
},
|
||||
"SimpleEnum": {
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"ONE",
|
||||
"TWO"
|
||||
]
|
||||
},
|
||||
"NestedComplexItem-blah-blah": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"alias": {
|
||||
"additionalProperties": {
|
||||
"$ref": "#/components/schemas/CrazyItem"
|
||||
},
|
||||
"type": "object"
|
||||
},
|
||||
"name": {
|
||||
"type": "string",
|
||||
"description": "A nested description"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"alias",
|
||||
"name"
|
||||
]
|
||||
},
|
||||
"ComplexRequest-blah": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"amazingField": {
|
||||
"type": "string"
|
||||
},
|
||||
"org": {
|
||||
"type": "string"
|
||||
},
|
||||
"tables": {
|
||||
"items": {
|
||||
"$ref": "#/components/schemas/NestedComplexItem-blah-blah"
|
||||
},
|
||||
"description": "A nested description",
|
||||
"type": "array"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"amazingField",
|
||||
"org",
|
||||
"tables"
|
||||
]
|
||||
}
|
||||
},
|
||||
"securitySchemes": {}
|
||||
|
@ -58,7 +58,7 @@
|
||||
"properties": {
|
||||
"data": {
|
||||
"$ref": "#/components/schemas/TestSimpleRequest-simple",
|
||||
"description": "A simple description"
|
||||
"description": "also a description"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
|
@ -60,7 +60,6 @@
|
||||
"type": "string"
|
||||
},
|
||||
"type": {
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"chillax"
|
||||
]
|
||||
@ -79,7 +78,6 @@
|
||||
"format": "int32"
|
||||
},
|
||||
"type": {
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"maximize"
|
||||
]
|
||||
|
@ -27,19 +27,19 @@
|
||||
}
|
||||
],
|
||||
"paths": {
|
||||
"/list/{name}/page/{page}": {
|
||||
"/test/{a}": {
|
||||
"get": {
|
||||
"tags": [],
|
||||
"summary": "Location",
|
||||
"description": "example location",
|
||||
"summary": "Great Summary!",
|
||||
"description": "testing more",
|
||||
"parameters": [],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "does great things",
|
||||
"description": "A Successful List-y Endeavor",
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"$ref": "#/components/schemas/TestResponse"
|
||||
"$ref": "#/components/schemas/List-TestEnum"
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -49,7 +49,7 @@
|
||||
},
|
||||
"parameters": [
|
||||
{
|
||||
"name": "name",
|
||||
"name": "a",
|
||||
"in": "path",
|
||||
"schema": {
|
||||
"type": "string"
|
||||
@ -58,8 +58,8 @@
|
||||
"deprecated": false
|
||||
},
|
||||
{
|
||||
"name": "page",
|
||||
"in": "path",
|
||||
"name": "aa",
|
||||
"in": "query",
|
||||
"schema": {
|
||||
"type": "number",
|
||||
"format": "int32"
|
||||
@ -73,16 +73,17 @@
|
||||
"webhooks": {},
|
||||
"components": {
|
||||
"schemas": {
|
||||
"TestResponse": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"c": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"c"
|
||||
"TestEnum": {
|
||||
"enum": [
|
||||
"YES",
|
||||
"NO"
|
||||
]
|
||||
},
|
||||
"List-TestEnum": {
|
||||
"items": {
|
||||
"$ref": "#/components/schemas/TestEnum"
|
||||
},
|
||||
"type": "array"
|
||||
}
|
||||
},
|
||||
"securitySchemes": {}
|
@ -27,19 +27,30 @@
|
||||
}
|
||||
],
|
||||
"paths": {
|
||||
"/type/{name}/edit": {
|
||||
"get": {
|
||||
"/example": {
|
||||
"post": {
|
||||
"tags": [],
|
||||
"summary": "Edit",
|
||||
"description": "example location",
|
||||
"summary": "Great Summary!",
|
||||
"description": "testing more",
|
||||
"parameters": [],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "does great things",
|
||||
"requestBody": {
|
||||
"description": "A test request",
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"$ref": "#/components/schemas/TestResponse"
|
||||
"$ref": "#/components/schemas/List-TestSimpleRequest-blah-blah"
|
||||
}
|
||||
}
|
||||
},
|
||||
"required": true
|
||||
},
|
||||
"responses": {
|
||||
"201": {
|
||||
"description": "A Successful Endeavor",
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"$ref": "#/components/schemas/TestCreatedResponse"
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -49,39 +60,7 @@
|
||||
},
|
||||
"parameters": [
|
||||
{
|
||||
"name": "name",
|
||||
"in": "path",
|
||||
"schema": {
|
||||
"type": "string"
|
||||
},
|
||||
"required": true,
|
||||
"deprecated": false
|
||||
}
|
||||
]
|
||||
},
|
||||
"/type/{name}/other/{page}": {
|
||||
"get": {
|
||||
"tags": [],
|
||||
"summary": "Other",
|
||||
"description": "example location",
|
||||
"parameters": [],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "does great things",
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"$ref": "#/components/schemas/TestResponse"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"deprecated": false
|
||||
},
|
||||
"parameters": [
|
||||
{
|
||||
"name": "name",
|
||||
"name": "a",
|
||||
"in": "path",
|
||||
"schema": {
|
||||
"type": "string"
|
||||
@ -90,8 +69,8 @@
|
||||
"deprecated": false
|
||||
},
|
||||
{
|
||||
"name": "page",
|
||||
"in": "path",
|
||||
"name": "aa",
|
||||
"in": "query",
|
||||
"schema": {
|
||||
"type": "number",
|
||||
"format": "int32"
|
||||
@ -105,16 +84,63 @@
|
||||
"webhooks": {},
|
||||
"components": {
|
||||
"schemas": {
|
||||
"TestResponse": {
|
||||
"TestCreatedResponse": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"c": {
|
||||
"type": "string"
|
||||
},
|
||||
"id": {
|
||||
"type": "number",
|
||||
"format": "int32"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"c"
|
||||
"c",
|
||||
"id"
|
||||
]
|
||||
},
|
||||
"TestSimpleRequest-simple": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"a": {
|
||||
"type": "string",
|
||||
"description": "A simple description"
|
||||
},
|
||||
"b": {
|
||||
"type": "number",
|
||||
"format": "int32",
|
||||
"deprecated": true
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"a",
|
||||
"b"
|
||||
]
|
||||
},
|
||||
"TestSimpleRequest-blah-blah": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"a": {
|
||||
"type": "string",
|
||||
"description": "A simple description"
|
||||
},
|
||||
"b": {
|
||||
"type": "number",
|
||||
"format": "int32",
|
||||
"deprecated": true
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"a",
|
||||
"b"
|
||||
]
|
||||
},
|
||||
"List-TestSimpleRequest-blah-blah": {
|
||||
"items": {
|
||||
"$ref": "#/components/schemas/TestSimpleRequest-blah-blah"
|
||||
},
|
||||
"type": "array"
|
||||
}
|
||||
},
|
||||
"securitySchemes": {}
|
103
core/src/test/resources/T0078__enriched_top_level_map.json
Normal file
103
core/src/test/resources/T0078__enriched_top_level_map.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": {
|
||||
"/example": {
|
||||
"get": {
|
||||
"tags": [],
|
||||
"summary": "Great Summary!",
|
||||
"description": "testing more",
|
||||
"parameters": [],
|
||||
"responses": {
|
||||
"201": {
|
||||
"description": "A good response",
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"$ref": "#/components/schemas/Map-String-TestSimpleRequest-blah"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"deprecated": false
|
||||
},
|
||||
"parameters": []
|
||||
}
|
||||
},
|
||||
"webhooks": {},
|
||||
"components": {
|
||||
"schemas": {
|
||||
"TestSimpleRequest-nested": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"a": {
|
||||
"type": "string",
|
||||
"description": "A simple description"
|
||||
},
|
||||
"b": {
|
||||
"type": "number",
|
||||
"format": "int32",
|
||||
"deprecated": true
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"a",
|
||||
"b"
|
||||
]
|
||||
},
|
||||
"TestSimpleRequest-blah": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"a": {
|
||||
"type": "string",
|
||||
"description": "A simple description"
|
||||
},
|
||||
"b": {
|
||||
"type": "number",
|
||||
"format": "int32",
|
||||
"deprecated": true
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"a",
|
||||
"b"
|
||||
]
|
||||
},
|
||||
"Map-String-TestSimpleRequest-blah": {
|
||||
"additionalProperties": {
|
||||
"$ref": "#/components/schemas/TestSimpleRequest-blah"
|
||||
},
|
||||
"type": "object"
|
||||
}
|
||||
},
|
||||
"securitySchemes": {}
|
||||
},
|
||||
"security": [],
|
||||
"tags": []
|
||||
}
|
@ -17,10 +17,11 @@ import io.ktor.client.statement.bodyAsText
|
||||
import io.ktor.http.HttpStatusCode
|
||||
import io.ktor.serialization.kotlinx.json.json
|
||||
import io.ktor.server.application.Application
|
||||
import io.ktor.server.engine.ApplicationEngineEnvironmentBuilder
|
||||
import io.ktor.server.application.ServerConfigBuilder
|
||||
import io.ktor.server.engine.ApplicationEnvironmentBuilder
|
||||
import io.ktor.server.plugins.contentnegotiation.ContentNegotiation
|
||||
import io.ktor.server.plugins.contentnegotiation.ContentNegotiationConfig
|
||||
import io.ktor.server.routing.Routing
|
||||
import io.ktor.server.routing.Route
|
||||
import io.ktor.server.testing.ApplicationTestBuilder
|
||||
import io.ktor.server.testing.testApplication
|
||||
import kotlinx.serialization.json.Json
|
||||
@ -59,7 +60,7 @@ object TestHelpers {
|
||||
customTypes: Map<KType, JsonSchema> = emptyMap(),
|
||||
applicationSetup: Application.() -> Unit = { },
|
||||
specOverrides: OpenApiSpec.() -> OpenApiSpec = { this },
|
||||
applicationEnvironmentBuilder: ApplicationEngineEnvironmentBuilder.() -> Unit = {},
|
||||
applicationEnvironmentBuilder: ApplicationEnvironmentBuilder.() -> Unit = {},
|
||||
notarizedApplicationConfigOverrides: NotarizedApplication.Config.() -> Unit = {},
|
||||
contentNegotiation: ContentNegotiationConfig.() -> Unit = {
|
||||
json(Json {
|
||||
@ -68,7 +69,9 @@ object TestHelpers {
|
||||
serializersModule = KompendiumSerializersModule.module
|
||||
})
|
||||
},
|
||||
routeUnderTest: Routing.() -> Unit
|
||||
|
||||
serverConfigSetup: ServerConfigBuilder.() -> Unit = { },
|
||||
routeUnderTest: Route.() -> Unit
|
||||
) {
|
||||
openApiTest(
|
||||
snapshotName,
|
||||
@ -78,19 +81,21 @@ object TestHelpers {
|
||||
customTypes,
|
||||
notarizedApplicationConfigOverrides,
|
||||
contentNegotiation,
|
||||
applicationEnvironmentBuilder
|
||||
applicationEnvironmentBuilder,
|
||||
serverConfigSetup
|
||||
)
|
||||
}
|
||||
|
||||
private fun openApiTest(
|
||||
snapshotName: String,
|
||||
routeUnderTest: Routing.() -> Unit,
|
||||
routeUnderTest: Route.() -> Unit,
|
||||
applicationSetup: Application.() -> Unit,
|
||||
specOverrides: OpenApiSpec.() -> OpenApiSpec,
|
||||
typeOverrides: Map<KType, JsonSchema> = emptyMap(),
|
||||
notarizedApplicationConfigOverrides: NotarizedApplication.Config.() -> Unit,
|
||||
contentNegotiation: ContentNegotiationConfig.() -> Unit,
|
||||
applicationBuilder: ApplicationEngineEnvironmentBuilder.() -> Unit
|
||||
applicationBuilder: ApplicationEnvironmentBuilder.() -> Unit,
|
||||
serverConfigSetup: ServerConfigBuilder.() -> Unit
|
||||
) = testApplication {
|
||||
environment(applicationBuilder)
|
||||
install(NotarizedApplication()) {
|
||||
@ -103,12 +108,14 @@ object TestHelpers {
|
||||
contentNegotiation()
|
||||
}
|
||||
application(applicationSetup)
|
||||
serverConfig(serverConfigSetup)
|
||||
routing {
|
||||
swagger()
|
||||
redoc()
|
||||
routeUnderTest()
|
||||
}
|
||||
val root = ApplicationEngineEnvironmentBuilder().apply(applicationBuilder).rootPath
|
||||
|
||||
val root = ServerConfigBuilder(ApplicationEnvironmentBuilder().apply(applicationBuilder).build()).apply(serverConfigSetup).rootPath
|
||||
compareOpenAPISpec(root, snapshotName)
|
||||
}
|
||||
}
|
||||
|
@ -5,8 +5,8 @@ complexity:
|
||||
active: true
|
||||
functionThreshold: 10
|
||||
constructorThreshold: 15
|
||||
ComplexMethod:
|
||||
threshold: 20
|
||||
CyclomaticComplexMethod:
|
||||
threshold: 15
|
||||
style:
|
||||
MaxLineLength:
|
||||
excludes: ['**/test/**/*']
|
||||
|
@ -4,7 +4,6 @@
|
||||
* [Plugins](plugins/index.md)
|
||||
* [Notarized Application](plugins/notarized_application.md)
|
||||
* [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)
|
||||
|
@ -12,7 +12,6 @@ At the moment, the following playground applications are
|
||||
| Gson | Serialization using Gson instead of the default Kotlinx |
|
||||
| Hidden Docs | Place your generated documentation behind authorization |
|
||||
| Jackson | Serialization using Jackson instead of the default KotlinX |
|
||||
| Locations | Using the Ktor Locations API to define routes |
|
||||
| Resources | Using the Ktor Resources API to define routes |
|
||||
|
||||
You can find all of the playground
|
||||
|
@ -7,5 +7,5 @@ From there, a `NotarizedRoute` plugin is attached to each route you wish to docu
|
||||
be an iterative process. Each route you notarize will be picked up and injected into the OpenAPI spec that Kompendium
|
||||
generates for you.
|
||||
|
||||
Finally, there is the `NotarizedLocations` plugin that allows you to leverage and document your usage of the
|
||||
Ktor [Locations](https://ktor.io/docs/locations.html) API.
|
||||
Finally, there is the `NotarizedResources` plugin that allows you to leverage and document your usage of the
|
||||
Ktor [Resources](https://ktor.io/docs/server-resources.html) API.
|
||||
|
@ -1,62 +0,0 @@
|
||||
The Ktor Locations API is an experimental API that allows users to add increased type safety to their defined routes.
|
||||
|
||||
You can read more about it [here](https://ktor.io/docs/locations.html).
|
||||
|
||||
Kompendium supports Locations through an ancillary module `kompendium-locations`
|
||||
|
||||
## Adding the Artifact
|
||||
|
||||
Prior to documenting your locations, you will need to add the artifact to your gradle build file.
|
||||
|
||||
```kotlin
|
||||
dependencies {
|
||||
implementation("io.bkbn:kompendium-locations:latest.release")
|
||||
}
|
||||
```
|
||||
|
||||
## Installing Plugin
|
||||
|
||||
Once you have installed the dependency, you can install the plugin. The `NotarizedLocations` plugin is an _application_
|
||||
level plugin, and **must** be install after both the `NotarizedApplication` plugin and the Ktor `Locations` plugin.
|
||||
|
||||
```kotlin
|
||||
private fun Application.mainModule() {
|
||||
install(Locations)
|
||||
install(NotarizedApplication()) {
|
||||
spec = baseSpec
|
||||
}
|
||||
install(NotarizedLocations()) {
|
||||
locations = mapOf(
|
||||
Listing::class to NotarizedLocations.LocationMetadata(
|
||||
parameters = listOf(
|
||||
Parameter(
|
||||
name = "name",
|
||||
`in` = Parameter.Location.path,
|
||||
schema = TypeDefinition.STRING
|
||||
),
|
||||
Parameter(
|
||||
name = "page",
|
||||
`in` = Parameter.Location.path,
|
||||
schema = TypeDefinition.INT
|
||||
)
|
||||
),
|
||||
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 😱")
|
||||
}
|
||||
}
|
||||
),
|
||||
)
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Here, the `locations` property is a map of `KClass<*>` to metadata describing that locations metadata. This
|
||||
metadata is functionally identical to how a standard `NotarizedRoute` is defined.
|
||||
|
||||
> ⚠️ If you try to map a class that is not annotated with the ktor `@Location` annotation, you will get a runtime
|
||||
> exception!
|
@ -3,7 +3,7 @@ plugins {
|
||||
id("io.bkbn.sourdough.library.jvm")
|
||||
id("io.gitlab.arturbosch.detekt")
|
||||
id("com.adarshr.test-logger")
|
||||
id("maven-publish")
|
||||
id("com.vanniktech.maven.publish")
|
||||
id("java-library")
|
||||
id("signing")
|
||||
id("org.jetbrains.kotlinx.kover")
|
||||
|
@ -0,0 +1,16 @@
|
||||
package io.bkbn.kompendium.enrichment
|
||||
|
||||
class BooleanEnrichment(override val id: String) : Enrichment {
|
||||
override var deprecated: Boolean? = null
|
||||
override var description: String? = null
|
||||
|
||||
companion object {
|
||||
inline operator fun invoke(
|
||||
id: String,
|
||||
init: BooleanEnrichment.() -> Unit
|
||||
): BooleanEnrichment {
|
||||
val builder = BooleanEnrichment(id)
|
||||
return builder.apply(init)
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
package io.bkbn.kompendium.enrichment
|
||||
|
||||
class CollectionEnrichment<T>(override val id: String) : TypeEnrichment<T> {
|
||||
|
||||
override var deprecated: Boolean? = null
|
||||
override var description: String? = null
|
||||
|
||||
var maxItems: Int? = null
|
||||
var minItems: Int? = null
|
||||
var uniqueItems: Boolean? = null
|
||||
// TODO How to handle contains, minContains, maxContains?
|
||||
|
||||
var itemEnrichment: TypeEnrichment<*>? = null
|
||||
|
||||
companion object {
|
||||
inline operator fun <reified T> invoke(
|
||||
id: String,
|
||||
init: CollectionEnrichment<T>.() -> Unit
|
||||
): CollectionEnrichment<T> {
|
||||
val builder = CollectionEnrichment<T>(id)
|
||||
return builder.apply(init)
|
||||
}
|
||||
}
|
||||
}
|
@ -1,3 +1,7 @@
|
||||
package io.bkbn.kompendium.enrichment
|
||||
|
||||
sealed interface Enrichment
|
||||
sealed interface Enrichment {
|
||||
val id: String
|
||||
var deprecated: Boolean?
|
||||
var description: String?
|
||||
}
|
||||
|
@ -0,0 +1,23 @@
|
||||
package io.bkbn.kompendium.enrichment
|
||||
|
||||
class MapEnrichment<V>(override val id: String) : TypeEnrichment<V> {
|
||||
|
||||
override var deprecated: Boolean? = null
|
||||
override var description: String? = null
|
||||
|
||||
var maxProperties: Int? = null
|
||||
var minProperties: Int? = null
|
||||
|
||||
lateinit var keyEnrichment: StringEnrichment
|
||||
lateinit var valueEnrichment: TypeEnrichment<*>
|
||||
|
||||
companion object {
|
||||
inline operator fun <reified V> invoke(
|
||||
id: String,
|
||||
init: MapEnrichment<V>.() -> Unit
|
||||
): MapEnrichment<V> {
|
||||
val builder = MapEnrichment<V>(id)
|
||||
return builder.apply(init)
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
package io.bkbn.kompendium.enrichment
|
||||
class NumberEnrichment(override val id: String) : Enrichment {
|
||||
|
||||
override var deprecated: Boolean? = null
|
||||
override var description: String? = null
|
||||
|
||||
var multipleOf: Number? = null
|
||||
var maximum: Number? = null
|
||||
var exclusiveMaximum: Number? = null
|
||||
var minimum: Number? = null
|
||||
var exclusiveMinimum: Number? = null
|
||||
|
||||
companion object {
|
||||
inline operator fun invoke(id: String, init: NumberEnrichment.() -> Unit): NumberEnrichment {
|
||||
val builder = NumberEnrichment(id)
|
||||
return builder.apply(init)
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
package io.bkbn.kompendium.enrichment
|
||||
|
||||
import kotlin.reflect.KProperty1
|
||||
|
||||
class ObjectEnrichment<T>(override val id: String) : TypeEnrichment<T> {
|
||||
|
||||
override var deprecated: Boolean? = null
|
||||
override var description: String? = null
|
||||
|
||||
private val _propertyEnrichments: MutableMap<KProperty1<*, *>, Enrichment> = mutableMapOf()
|
||||
|
||||
val propertyEnrichment: Map<KProperty1<*, *>, Enrichment>
|
||||
get() = _propertyEnrichments.toMap()
|
||||
|
||||
operator fun <R> KProperty1<T, R>.invoke(init: () -> Enrichment) {
|
||||
require(!_propertyEnrichments.containsKey(this)) { "${this.name} has already been registered" }
|
||||
val enrichment = init.invoke()
|
||||
_propertyEnrichments[this] = enrichment
|
||||
}
|
||||
|
||||
companion object {
|
||||
inline operator fun <reified T> invoke(id: String, init: ObjectEnrichment<T>.() -> Unit): ObjectEnrichment<T> {
|
||||
val builder = ObjectEnrichment<T>(id)
|
||||
return builder.apply(init)
|
||||
}
|
||||
}
|
||||
}
|
@ -1,36 +0,0 @@
|
||||
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,20 @@
|
||||
package io.bkbn.kompendium.enrichment
|
||||
|
||||
class StringEnrichment(override val id: String) : Enrichment {
|
||||
override var deprecated: Boolean? = null
|
||||
override var description: String? = null
|
||||
|
||||
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?
|
||||
|
||||
companion object {
|
||||
inline operator fun invoke(id: String, init: StringEnrichment.() -> Unit): StringEnrichment {
|
||||
val builder = StringEnrichment(id)
|
||||
return builder.apply(init)
|
||||
}
|
||||
}
|
||||
}
|
@ -1,25 +1,3 @@
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
sealed interface TypeEnrichment<T> : Enrichment
|
||||
|
64
flake.lock
generated
Normal file
64
flake.lock
generated
Normal file
@ -0,0 +1,64 @@
|
||||
{
|
||||
"nodes": {
|
||||
"flake-utils": {
|
||||
"inputs": {
|
||||
"systems": [
|
||||
"systems"
|
||||
]
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1710146030,
|
||||
"narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=",
|
||||
"owner": "numtide",
|
||||
"repo": "flake-utils",
|
||||
"rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "numtide",
|
||||
"repo": "flake-utils",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"nixpkgs": {
|
||||
"locked": {
|
||||
"lastModified": 1723362943,
|
||||
"narHash": "sha256-dFZRVSgmJkyM0bkPpaYRtG/kRMRTorUIDj8BxoOt1T4=",
|
||||
"owner": "nixos",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "a58bc8ad779655e790115244571758e8de055e3d",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "nixos",
|
||||
"ref": "nixos-unstable",
|
||||
"repo": "nixpkgs",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"root": {
|
||||
"inputs": {
|
||||
"flake-utils": "flake-utils",
|
||||
"nixpkgs": "nixpkgs",
|
||||
"systems": "systems"
|
||||
}
|
||||
},
|
||||
"systems": {
|
||||
"locked": {
|
||||
"lastModified": 1681028828,
|
||||
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
|
||||
"owner": "nix-systems",
|
||||
"repo": "default",
|
||||
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "nix-systems",
|
||||
"repo": "default",
|
||||
"type": "github"
|
||||
}
|
||||
}
|
||||
},
|
||||
"root": "root",
|
||||
"version": 7
|
||||
}
|
29
flake.nix
Normal file
29
flake.nix
Normal file
@ -0,0 +1,29 @@
|
||||
{
|
||||
description = "Minimal example of building Kotlin with Gradle and Nix";
|
||||
|
||||
inputs = {nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable";};
|
||||
|
||||
inputs.systems.url = "github:nix-systems/default";
|
||||
|
||||
inputs.flake-utils.url = "github:numtide/flake-utils";
|
||||
inputs.flake-utils.inputs.systems.follows = "systems";
|
||||
|
||||
outputs = {
|
||||
nixpkgs,
|
||||
flake-utils,
|
||||
...
|
||||
}:
|
||||
flake-utils.lib.eachDefaultSystem (system: let
|
||||
pkgs = import nixpkgs {inherit system;};
|
||||
updateLocks = pkgs.callPackage ./update-locks.nix {};
|
||||
in {
|
||||
devShells.default = pkgs.mkShell {
|
||||
buildInputs = with pkgs; [
|
||||
gradle_8
|
||||
temurin-bin-21
|
||||
updateLocks
|
||||
ktlint
|
||||
];
|
||||
};
|
||||
});
|
||||
}
|
@ -1,7 +1,10 @@
|
||||
# Kompendium
|
||||
project.version=4.0.0-alpha
|
||||
project.version=4.0.0-test
|
||||
|
||||
# Kotlin
|
||||
kotlin.code.style=official
|
||||
#kotlin.experimental.tryK2=true
|
||||
|
||||
# Gradle
|
||||
org.gradle.vfs.watch=true
|
||||
org.gradle.vfs.verbose=true
|
||||
@ -9,6 +12,8 @@ org.gradle.jvmargs=-Xmx2000m
|
||||
org.gradle.parallel=true
|
||||
|
||||
# Dependencies
|
||||
ktorVersion=2.3.4
|
||||
kotestVersion=5.7.1
|
||||
detektVersion=1.22.0
|
||||
kotlinVersion=2.0.21
|
||||
kotlinSerializeVersion=1.7.+
|
||||
ktorVersion=3.0.1
|
||||
kotestVersion=6.0.0.M1
|
||||
detektVersion=1.23.7
|
||||
|
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
Binary file not shown.
2
gradle/wrapper/gradle-wrapper.properties
vendored
2
gradle/wrapper/gradle-wrapper.properties
vendored
@ -1,6 +1,6 @@
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.3-bin.zip
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.2-bin.zip
|
||||
networkTimeout=10000
|
||||
validateDistributionUrl=true
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
|
14
gradlew
vendored
14
gradlew
vendored
@ -145,7 +145,7 @@ 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
|
||||
# shellcheck disable=SC2039,SC3045
|
||||
MAX_FD=$( ulimit -H -n ) ||
|
||||
warn "Could not query maximum file descriptor limit"
|
||||
esac
|
||||
@ -153,7 +153,7 @@ if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
|
||||
'' | soft) :;; #(
|
||||
*)
|
||||
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
|
||||
# shellcheck disable=SC3045
|
||||
# shellcheck disable=SC2039,SC3045
|
||||
ulimit -n "$MAX_FD" ||
|
||||
warn "Could not set maximum file descriptor limit to $MAX_FD"
|
||||
esac
|
||||
@ -202,11 +202,11 @@ 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
|
||||
# double quotes to make sure that they get re-expanded; and
|
||||
# * put everything else in single quotes, so that it's not re-expanded.
|
||||
# Collect all arguments for the java command:
|
||||
# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
|
||||
# and any embedded shellness will be escaped.
|
||||
# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
|
||||
# treated as '${Hostname}' itself on the command line.
|
||||
|
||||
set -- \
|
||||
"-Dorg.gradle.appname=$APP_BASE_NAME" \
|
||||
|
@ -4,7 +4,7 @@ plugins {
|
||||
id("io.bkbn.sourdough.library.jvm")
|
||||
id("io.gitlab.arturbosch.detekt")
|
||||
id("com.adarshr.test-logger")
|
||||
id("maven-publish")
|
||||
id("com.vanniktech.maven.publish")
|
||||
id("java-library")
|
||||
id("signing")
|
||||
id("org.jetbrains.kotlinx.kover")
|
||||
@ -19,12 +19,14 @@ sourdoughLibrary {
|
||||
dependencies {
|
||||
// Versions
|
||||
val detektVersion: String by project
|
||||
val kotlinVersion: String by project
|
||||
val kotlinSerializeVersion: String by project
|
||||
|
||||
// Kompendium
|
||||
api(projects.kompendiumEnrichment)
|
||||
|
||||
implementation("org.jetbrains.kotlin:kotlin-reflect:1.9.10")
|
||||
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.6.0")
|
||||
implementation("org.jetbrains.kotlin:kotlin-reflect:$kotlinVersion")
|
||||
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:$kotlinSerializeVersion")
|
||||
|
||||
// Formatting
|
||||
detektPlugins("io.gitlab.arturbosch.detekt:detekt-formatting:$detektVersion")
|
||||
|
@ -26,7 +26,7 @@ class KotlinXSchemaConfigurator : SchemaConfigurator {
|
||||
.filterIsInstance<SerialName>()
|
||||
.firstOrNull()?.value ?: property.name
|
||||
|
||||
override fun sealedTypeEnrichment(
|
||||
override fun sealedObjectEnrichment(
|
||||
implementationType: KType,
|
||||
implementationSchema: JsonSchema,
|
||||
): JsonSchema {
|
||||
@ -35,7 +35,7 @@ class KotlinXSchemaConfigurator : SchemaConfigurator {
|
||||
required = implementationSchema.required?.plus("type"),
|
||||
properties = implementationSchema.properties?.plus(
|
||||
mapOf(
|
||||
"type" to EnumDefinition("string", enum = setOf(determineTypeQualifier(implementationType)))
|
||||
"type" to EnumDefinition(enum = setOf(determineTypeQualifier(implementationType)))
|
||||
)
|
||||
)
|
||||
)
|
||||
|
@ -9,7 +9,7 @@ interface SchemaConfigurator {
|
||||
fun serializableMemberProperties(clazz: KClass<*>): Collection<KProperty1<out Any, *>>
|
||||
fun serializableName(property: KProperty1<out Any, *>): String
|
||||
|
||||
fun sealedTypeEnrichment(
|
||||
fun sealedObjectEnrichment(
|
||||
implementationType: KType,
|
||||
implementationSchema: JsonSchema
|
||||
): JsonSchema
|
||||
|
@ -1,5 +1,9 @@
|
||||
package io.bkbn.kompendium.json.schema
|
||||
|
||||
import io.bkbn.kompendium.enrichment.CollectionEnrichment
|
||||
import io.bkbn.kompendium.enrichment.Enrichment
|
||||
import io.bkbn.kompendium.enrichment.MapEnrichment
|
||||
import io.bkbn.kompendium.enrichment.ObjectEnrichment
|
||||
import io.bkbn.kompendium.enrichment.TypeEnrichment
|
||||
import io.bkbn.kompendium.json.schema.definition.JsonSchema
|
||||
import io.bkbn.kompendium.json.schema.definition.NullableDefinition
|
||||
@ -18,11 +22,12 @@ import kotlin.reflect.full.isSubclassOf
|
||||
|
||||
object SchemaGenerator {
|
||||
|
||||
@Suppress("CyclomaticComplexMethod")
|
||||
fun fromTypeToSchema(
|
||||
type: KType,
|
||||
cache: MutableMap<String, JsonSchema>,
|
||||
schemaConfigurator: SchemaConfigurator,
|
||||
enrichment: TypeEnrichment<*>? = null
|
||||
enrichment: Enrichment? = null
|
||||
): JsonSchema {
|
||||
val slug = type.getSlug(enrichment)
|
||||
|
||||
@ -46,18 +51,7 @@ object SchemaGenerator {
|
||||
String::class -> checkForNull(type, TypeDefinition.STRING)
|
||||
Boolean::class -> checkForNull(type, TypeDefinition.BOOLEAN)
|
||||
UUID::class -> checkForNull(type, TypeDefinition.UUID)
|
||||
else -> when {
|
||||
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, enrichment)
|
||||
} else {
|
||||
SimpleObjectHandler.handle(type, clazz, cache, schemaConfigurator, enrichment)
|
||||
}
|
||||
}
|
||||
}
|
||||
else -> complexTypeToSchema(clazz, type, cache, schemaConfigurator, enrichment as? TypeEnrichment<*>?)
|
||||
}
|
||||
}
|
||||
|
||||
@ -76,4 +70,59 @@ object SchemaGenerator {
|
||||
true -> OneOfDefinition(NullableDefinition(), schema)
|
||||
false -> schema
|
||||
}
|
||||
|
||||
private fun complexTypeToSchema(
|
||||
clazz: KClass<*>,
|
||||
type: KType,
|
||||
cache: MutableMap<String, JsonSchema>,
|
||||
schemaConfigurator: SchemaConfigurator,
|
||||
enrichment: Enrichment? = null
|
||||
): JsonSchema = when {
|
||||
clazz.isSubclassOf(Enum::class) -> EnumHandler.handle(type, clazz, cache)
|
||||
clazz.isSubclassOf(Collection::class) -> handleCollection(type, cache, schemaConfigurator, enrichment)
|
||||
clazz.isSubclassOf(Map::class) -> handleMap(type, cache, schemaConfigurator, enrichment)
|
||||
else -> handleObject(type, clazz, cache, schemaConfigurator, enrichment)
|
||||
}
|
||||
|
||||
private fun handleCollection(
|
||||
type: KType,
|
||||
cache: MutableMap<String, JsonSchema>,
|
||||
schemaConfigurator: SchemaConfigurator,
|
||||
enrichment: Enrichment?
|
||||
) = when (enrichment) {
|
||||
is CollectionEnrichment<*> -> CollectionHandler.handle(type, cache, schemaConfigurator, enrichment)
|
||||
null -> CollectionHandler.handle(type, cache, schemaConfigurator, null)
|
||||
else -> error("Incorrect enrichment type for enrichment id: ${enrichment.id}")
|
||||
}
|
||||
|
||||
private fun handleMap(
|
||||
type: KType,
|
||||
cache: MutableMap<String, JsonSchema>,
|
||||
schemaConfigurator: SchemaConfigurator,
|
||||
enrichment: Enrichment?
|
||||
) = when (enrichment) {
|
||||
is MapEnrichment<*> -> MapHandler.handle(type, cache, schemaConfigurator, enrichment)
|
||||
null -> MapHandler.handle(type, cache, schemaConfigurator, null)
|
||||
else -> error("Incorrect enrichment type for enrichment id: ${enrichment.id}")
|
||||
}
|
||||
|
||||
private fun handleObject(
|
||||
type: KType,
|
||||
clazz: KClass<*>,
|
||||
cache: MutableMap<String, JsonSchema>,
|
||||
schemaConfigurator: SchemaConfigurator,
|
||||
enrichment: Enrichment?
|
||||
) = when (clazz.isSealed) {
|
||||
true -> when (enrichment) {
|
||||
is ObjectEnrichment<*> -> SealedObjectHandler.handle(type, clazz, cache, schemaConfigurator, enrichment)
|
||||
null -> SealedObjectHandler.handle(type, clazz, cache, schemaConfigurator, null)
|
||||
else -> error("Incorrect enrichment type for enrichment id: ${enrichment.id}")
|
||||
}
|
||||
|
||||
false -> when (enrichment) {
|
||||
is ObjectEnrichment<*> -> SimpleObjectHandler.handle(type, clazz, cache, schemaConfigurator, enrichment)
|
||||
null -> SimpleObjectHandler.handle(type, clazz, cache, schemaConfigurator, null)
|
||||
else -> error("Incorrect enrichment type for enrichment id: ${enrichment.id}")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -4,7 +4,6 @@ import kotlinx.serialization.Serializable
|
||||
|
||||
@Serializable
|
||||
data class EnumDefinition(
|
||||
val type: String,
|
||||
val enum: Set<String>,
|
||||
override val deprecated: Boolean? = null,
|
||||
override val description: String? = null,
|
||||
|
@ -5,6 +5,8 @@ import kotlinx.serialization.Serializable
|
||||
@Serializable
|
||||
data class MapDefinition(
|
||||
val additionalProperties: JsonSchema,
|
||||
val maxProperties: Int? = null,
|
||||
val minProperties: Int? = null,
|
||||
override val deprecated: Boolean? = null,
|
||||
override val description: String? = null,
|
||||
) : JsonSchema {
|
||||
|
@ -1,9 +1,10 @@
|
||||
package io.bkbn.kompendium.json.schema.handler
|
||||
|
||||
import io.bkbn.kompendium.enrichment.TypeEnrichment
|
||||
import io.bkbn.kompendium.enrichment.CollectionEnrichment
|
||||
import io.bkbn.kompendium.json.schema.SchemaConfigurator
|
||||
import io.bkbn.kompendium.json.schema.SchemaGenerator
|
||||
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.NullableDefinition
|
||||
import io.bkbn.kompendium.json.schema.definition.OneOfDefinition
|
||||
@ -18,12 +19,17 @@ object CollectionHandler {
|
||||
type: KType,
|
||||
cache: MutableMap<String, JsonSchema>,
|
||||
schemaConfigurator: SchemaConfigurator,
|
||||
enrichment: TypeEnrichment<*>? = null
|
||||
enrichment: CollectionEnrichment<*>? = null
|
||||
): JsonSchema {
|
||||
require(enrichment is CollectionEnrichment<*> || enrichment == null) {
|
||||
"Enrichment for collection must be either null or a CollectionEnrichment"
|
||||
}
|
||||
|
||||
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, enrichment).let {
|
||||
if (it is TypeDefinition && it.type == "object") {
|
||||
val typeSchema =
|
||||
SchemaGenerator.fromTypeToSchema(collectionType, cache, schemaConfigurator, enrichment?.itemEnrichment).let {
|
||||
if ((it is TypeDefinition && it.type == "object") || it is EnumDefinition) {
|
||||
cache[collectionType.getSlug(enrichment)] = it
|
||||
ReferenceDefinition(collectionType.getReferenceSlug(enrichment))
|
||||
} else {
|
||||
|
@ -0,0 +1,94 @@
|
||||
package io.bkbn.kompendium.json.schema.handler
|
||||
|
||||
import io.bkbn.kompendium.enrichment.CollectionEnrichment
|
||||
import io.bkbn.kompendium.enrichment.Enrichment
|
||||
import io.bkbn.kompendium.enrichment.MapEnrichment
|
||||
import io.bkbn.kompendium.enrichment.NumberEnrichment
|
||||
import io.bkbn.kompendium.enrichment.ObjectEnrichment
|
||||
import io.bkbn.kompendium.enrichment.StringEnrichment
|
||||
import io.bkbn.kompendium.json.schema.definition.ArrayDefinition
|
||||
import io.bkbn.kompendium.json.schema.definition.JsonSchema
|
||||
import io.bkbn.kompendium.json.schema.definition.MapDefinition
|
||||
import io.bkbn.kompendium.json.schema.definition.ReferenceDefinition
|
||||
import io.bkbn.kompendium.json.schema.definition.TypeDefinition
|
||||
|
||||
object EnrichmentHandler {
|
||||
|
||||
fun Enrichment.applyToSchema(schema: JsonSchema): JsonSchema = when (this) {
|
||||
is NumberEnrichment -> applyToSchema(schema)
|
||||
is StringEnrichment -> applyToSchema(schema)
|
||||
is CollectionEnrichment<*> -> applyToSchema(schema)
|
||||
is MapEnrichment<*> -> applyToSchema(schema)
|
||||
is ObjectEnrichment<*> -> applyToSchema(schema)
|
||||
else -> error("Incorrect enrichment type for enrichment id: ${this.id}")
|
||||
}
|
||||
|
||||
private fun ObjectEnrichment<*>.applyToSchema(schema: JsonSchema): JsonSchema = when (schema) {
|
||||
is TypeDefinition -> schema.copy(deprecated = deprecated, description = description)
|
||||
is ReferenceDefinition -> schema.copy(deprecated = deprecated, description = description)
|
||||
else -> error("Incorrect enrichment type for enrichment id: ${this.id}")
|
||||
}
|
||||
|
||||
private fun MapEnrichment<*>.applyToSchema(schema: JsonSchema): JsonSchema = when (schema) {
|
||||
is MapDefinition -> schema.copyMapEnrichment(this)
|
||||
else -> error("Incorrect enrichment type for enrichment id: ${this.id}")
|
||||
}
|
||||
|
||||
private fun CollectionEnrichment<*>.applyToSchema(schema: JsonSchema): JsonSchema = when (schema) {
|
||||
is ArrayDefinition -> schema.copyArrayEnrichment(this)
|
||||
else -> error("Incorrect enrichment type for enrichment id: ${this.id}")
|
||||
}
|
||||
|
||||
private fun NumberEnrichment.applyToSchema(schema: JsonSchema): JsonSchema = when (schema) {
|
||||
is TypeDefinition -> schema.copyNumberEnrichment(this)
|
||||
else -> error("Incorrect enrichment type for enrichment id: ${this.id}")
|
||||
}
|
||||
|
||||
private fun StringEnrichment.applyToSchema(schema: JsonSchema): JsonSchema = when (schema) {
|
||||
is TypeDefinition -> schema.copyStringEnrichment(this)
|
||||
else -> error("Incorrect enrichment type for enrichment id: ${this.id}")
|
||||
}
|
||||
|
||||
private fun TypeDefinition.copyNumberEnrichment(
|
||||
enrichment: NumberEnrichment
|
||||
): TypeDefinition = copy(
|
||||
deprecated = enrichment.deprecated,
|
||||
description = enrichment.description,
|
||||
multipleOf = enrichment.multipleOf,
|
||||
maximum = enrichment.maximum,
|
||||
exclusiveMaximum = enrichment.exclusiveMaximum,
|
||||
minimum = enrichment.minimum,
|
||||
exclusiveMinimum = enrichment.exclusiveMinimum,
|
||||
)
|
||||
|
||||
private fun TypeDefinition.copyStringEnrichment(
|
||||
enrichment: StringEnrichment
|
||||
): TypeDefinition = copy(
|
||||
deprecated = enrichment.deprecated,
|
||||
description = enrichment.description,
|
||||
maxLength = enrichment.maxLength,
|
||||
minLength = enrichment.minLength,
|
||||
pattern = enrichment.pattern,
|
||||
contentEncoding = enrichment.contentEncoding,
|
||||
contentMediaType = enrichment.contentMediaType,
|
||||
)
|
||||
|
||||
private fun ArrayDefinition.copyArrayEnrichment(
|
||||
enrichment: CollectionEnrichment<*>
|
||||
): ArrayDefinition = copy(
|
||||
deprecated = enrichment.deprecated,
|
||||
description = enrichment.description,
|
||||
minItems = enrichment.minItems,
|
||||
maxItems = enrichment.maxItems,
|
||||
uniqueItems = enrichment.uniqueItems,
|
||||
)
|
||||
|
||||
private fun MapDefinition.copyMapEnrichment(
|
||||
enrichment: MapEnrichment<*>
|
||||
): MapDefinition = copy(
|
||||
deprecated = enrichment.deprecated,
|
||||
description = enrichment.description,
|
||||
minProperties = enrichment.minProperties,
|
||||
maxProperties = enrichment.maxProperties,
|
||||
)
|
||||
}
|
@ -1,6 +1,5 @@
|
||||
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
|
||||
@ -14,11 +13,10 @@ object EnumHandler {
|
||||
type: KType,
|
||||
clazz: KClass<*>,
|
||||
cache: MutableMap<String, JsonSchema>,
|
||||
enrichment: TypeEnrichment<*>? = null
|
||||
): JsonSchema {
|
||||
cache[type.getSlug(enrichment)] = ReferenceDefinition(type.getReferenceSlug(enrichment))
|
||||
cache[type.getSlug()] = ReferenceDefinition(type.getReferenceSlug())
|
||||
|
||||
val options = clazz.java.enumConstants.map { it.toString() }.toSet()
|
||||
return EnumDefinition(type = "string", enum = options)
|
||||
return EnumDefinition(enum = options)
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
package io.bkbn.kompendium.json.schema.handler
|
||||
|
||||
import io.bkbn.kompendium.enrichment.TypeEnrichment
|
||||
import io.bkbn.kompendium.enrichment.MapEnrichment
|
||||
import io.bkbn.kompendium.json.schema.SchemaConfigurator
|
||||
import io.bkbn.kompendium.json.schema.SchemaGenerator
|
||||
import io.bkbn.kompendium.json.schema.definition.JsonSchema
|
||||
@ -20,13 +20,17 @@ object MapHandler {
|
||||
type: KType,
|
||||
cache: MutableMap<String, JsonSchema>,
|
||||
schemaConfigurator: SchemaConfigurator,
|
||||
enrichment: TypeEnrichment<*>? = null
|
||||
enrichment: MapEnrichment<*>? = null
|
||||
): JsonSchema {
|
||||
require(enrichment is MapEnrichment<*> || enrichment == null) {
|
||||
"Enrichment for map must be either null or a MapEnrichment"
|
||||
}
|
||||
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, enrichment).let {
|
||||
val valueSchema =
|
||||
SchemaGenerator.fromTypeToSchema(valueType, cache, schemaConfigurator, enrichment?.valueEnrichment).let {
|
||||
if (it is TypeDefinition && it.type == "object") {
|
||||
cache[valueType.getSlug(enrichment)] = it
|
||||
ReferenceDefinition(valueType.getReferenceSlug(enrichment))
|
||||
|
@ -1,6 +1,6 @@
|
||||
package io.bkbn.kompendium.json.schema.handler
|
||||
|
||||
import io.bkbn.kompendium.enrichment.TypeEnrichment
|
||||
import io.bkbn.kompendium.enrichment.ObjectEnrichment
|
||||
import io.bkbn.kompendium.json.schema.SchemaConfigurator
|
||||
import io.bkbn.kompendium.json.schema.SchemaGenerator
|
||||
import io.bkbn.kompendium.json.schema.definition.AnyOfDefinition
|
||||
@ -20,14 +20,14 @@ object SealedObjectHandler {
|
||||
clazz: KClass<*>,
|
||||
cache: MutableMap<String, JsonSchema>,
|
||||
schemaConfigurator: SchemaConfigurator,
|
||||
enrichment: TypeEnrichment<*>? = null,
|
||||
enrichment: ObjectEnrichment<*>? = null,
|
||||
): JsonSchema {
|
||||
val subclasses = clazz.sealedSubclasses
|
||||
.map { it.createType(type.arguments) }
|
||||
.map { t ->
|
||||
SchemaGenerator.fromTypeToSchema(t, cache, schemaConfigurator, enrichment)
|
||||
.let {
|
||||
schemaConfigurator.sealedTypeEnrichment(t, it)
|
||||
schemaConfigurator.sealedObjectEnrichment(t, it)
|
||||
}.let { js ->
|
||||
if (js is TypeDefinition && js.type == "object") {
|
||||
val slug = t.getSlug(enrichment)
|
||||
|
@ -1,19 +1,17 @@
|
||||
package io.bkbn.kompendium.json.schema.handler
|
||||
|
||||
import io.bkbn.kompendium.enrichment.PropertyEnrichment
|
||||
import io.bkbn.kompendium.enrichment.TypeEnrichment
|
||||
import io.bkbn.kompendium.enrichment.Enrichment
|
||||
import io.bkbn.kompendium.enrichment.ObjectEnrichment
|
||||
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.handler.EnrichmentHandler.applyToSchema
|
||||
import io.bkbn.kompendium.json.schema.util.Helpers.getReferenceSlug
|
||||
import io.bkbn.kompendium.json.schema.util.Helpers.getSlug
|
||||
import kotlin.reflect.KClass
|
||||
@ -32,28 +30,31 @@ object SimpleObjectHandler {
|
||||
clazz: KClass<*>,
|
||||
cache: MutableMap<String, JsonSchema>,
|
||||
schemaConfigurator: SchemaConfigurator,
|
||||
enrichment: TypeEnrichment<*>?,
|
||||
enrichment: ObjectEnrichment<*>?,
|
||||
): JsonSchema {
|
||||
cache[type.getSlug(enrichment)] = ReferenceDefinition(type.getReferenceSlug(enrichment))
|
||||
require(enrichment is ObjectEnrichment<*> || enrichment == null) {
|
||||
"Enrichment for object must either be of type ObjectEnrichment or null"
|
||||
}
|
||||
|
||||
val slug = type.getSlug(enrichment)
|
||||
val referenceSlug = type.getReferenceSlug(enrichment)
|
||||
cache[slug] = ReferenceDefinition(referenceSlug)
|
||||
|
||||
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 propEnrichment = enrichment?.propertyEnrichment?.get(prop)
|
||||
|
||||
val schema = when (prop.needsToInjectGenerics(typeMap)) {
|
||||
true -> handleNestedGenerics(typeMap, prop, cache, schemaConfigurator, propTypeEnrichment)
|
||||
true -> handleNestedGenerics(typeMap, prop, cache, schemaConfigurator, propEnrichment)
|
||||
false -> when (typeMap.containsKey(prop.returnType.classifier)) {
|
||||
true -> handleGenericProperty(prop, typeMap, cache, schemaConfigurator, propTypeEnrichment)
|
||||
false -> handleProperty(prop, cache, schemaConfigurator, propTypeEnrichment?.typeEnrichment)
|
||||
true -> handleGenericProperty(prop, typeMap, cache, schemaConfigurator, propEnrichment)
|
||||
false -> handleProperty(prop, cache, schemaConfigurator, propEnrichment)
|
||||
}
|
||||
}
|
||||
|
||||
val enrichedSchema = propTypeEnrichment?.applyToSchema(schema) ?: schema
|
||||
val enrichedSchema = propEnrichment?.applyToSchema(schema) ?: schema
|
||||
|
||||
val nullCheckSchema = when (prop.returnType.isMarkedNullable && !enrichedSchema.isNullable()) {
|
||||
true -> OneOfDefinition(NullableDefinition(), enrichedSchema)
|
||||
@ -84,11 +85,14 @@ object SimpleObjectHandler {
|
||||
.map { schemaConfigurator.serializableName(it) }
|
||||
.toSet()
|
||||
|
||||
return TypeDefinition(
|
||||
val definition = TypeDefinition(
|
||||
type = "object",
|
||||
properties = props,
|
||||
required = required
|
||||
)
|
||||
|
||||
cache[slug] = definition
|
||||
return definition
|
||||
}
|
||||
|
||||
private fun KProperty<*>.needsToInjectGenerics(
|
||||
@ -103,7 +107,7 @@ object SimpleObjectHandler {
|
||||
prop: KProperty<*>,
|
||||
cache: MutableMap<String, JsonSchema>,
|
||||
schemaConfigurator: SchemaConfigurator,
|
||||
propEnrichment: PropertyEnrichment?
|
||||
propEnrichment: Enrichment?
|
||||
): JsonSchema {
|
||||
val propClass = prop.returnType.classifier as KClass<*>
|
||||
val types = prop.returnType.arguments.map {
|
||||
@ -111,7 +115,7 @@ object SimpleObjectHandler {
|
||||
typeMap.filterKeys { k -> k.name == typeSymbol }.values.first()
|
||||
}
|
||||
val constructedType = propClass.createType(types)
|
||||
return SchemaGenerator.fromTypeToSchema(constructedType, cache, schemaConfigurator, propEnrichment?.typeEnrichment)
|
||||
return SchemaGenerator.fromTypeToSchema(constructedType, cache, schemaConfigurator, propEnrichment)
|
||||
.let {
|
||||
if (it.isOrContainsObjectOrEnumDef()) {
|
||||
cache[constructedType.getSlug(propEnrichment)] = it
|
||||
@ -127,14 +131,14 @@ object SimpleObjectHandler {
|
||||
typeMap: Map<KTypeParameter, KTypeProjection>,
|
||||
cache: MutableMap<String, JsonSchema>,
|
||||
schemaConfigurator: SchemaConfigurator,
|
||||
propEnrichment: PropertyEnrichment?
|
||||
propEnrichment: Enrichment?
|
||||
): 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, propEnrichment?.typeEnrichment).let {
|
||||
return SchemaGenerator.fromTypeToSchema(type, cache, schemaConfigurator, propEnrichment).let {
|
||||
if (it.isOrContainsObjectOrEnumDef()) {
|
||||
cache[type.getSlug(propEnrichment?.typeEnrichment)] = it
|
||||
ReferenceDefinition(type.getReferenceSlug(propEnrichment?.typeEnrichment))
|
||||
cache[type.getSlug(propEnrichment)] = it
|
||||
ReferenceDefinition(type.getReferenceSlug(propEnrichment))
|
||||
} else {
|
||||
it
|
||||
}
|
||||
@ -145,7 +149,7 @@ object SimpleObjectHandler {
|
||||
prop: KProperty<*>,
|
||||
cache: MutableMap<String, JsonSchema>,
|
||||
schemaConfigurator: SchemaConfigurator,
|
||||
propEnrichment: TypeEnrichment<*>?
|
||||
propEnrichment: Enrichment?
|
||||
): JsonSchema =
|
||||
SchemaGenerator.fromTypeToSchema(prop.returnType, cache, schemaConfigurator, propEnrichment).let {
|
||||
if (it.isOrContainsObjectOrEnumDef()) {
|
||||
@ -165,37 +169,4 @@ 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,8 +1,6 @@
|
||||
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
|
||||
|
||||
@ -11,9 +9,8 @@ object Helpers {
|
||||
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")
|
||||
else -> getSimpleSlug()
|
||||
null -> getSimpleSlug()
|
||||
else -> getEnrichedSlug(enrichment)
|
||||
}
|
||||
|
||||
fun KType.getSimpleSlug(): String = when {
|
||||
@ -21,12 +18,11 @@ object Helpers {
|
||||
else -> (classifier as KClass<*>).kompendiumSlug() ?: error("Could not determine simple name for $this")
|
||||
}
|
||||
|
||||
private fun KType.getEnrichedSlug(enrichment: TypeEnrichment<*>) = getSimpleSlug() + "-${enrichment.id}"
|
||||
private fun KType.getEnrichedSlug(enrichment: Enrichment) = 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")
|
||||
else -> getSimpleReferenceSlug()
|
||||
null -> getSimpleReferenceSlug()
|
||||
else -> getSimpleReferenceSlug() + "-${enrichment.id}"
|
||||
}
|
||||
|
||||
private fun KType.getSimpleReferenceSlug() = when {
|
||||
|
@ -13,7 +13,10 @@ 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.enrichment.CollectionEnrichment
|
||||
import io.bkbn.kompendium.enrichment.NumberEnrichment
|
||||
import io.bkbn.kompendium.enrichment.ObjectEnrichment
|
||||
import io.bkbn.kompendium.enrichment.StringEnrichment
|
||||
import io.bkbn.kompendium.json.schema.definition.JsonSchema
|
||||
import io.kotest.assertions.json.shouldEqualJson
|
||||
import io.kotest.assertions.throwables.shouldThrow
|
||||
@ -114,47 +117,59 @@ class SchemaGeneratorTest : DescribeSpec({
|
||||
it("Can attach an enrichment to a simple type") {
|
||||
jsonSchemaTest<TestSimpleRequest>(
|
||||
snapshotName = "T0022__enriched_simple_object.json",
|
||||
enrichment = TypeEnrichment("simple") {
|
||||
enrichment = ObjectEnrichment("simple") {
|
||||
TestSimpleRequest::a {
|
||||
StringEnrichment("blah") {
|
||||
description = "This is a simple description"
|
||||
}
|
||||
}
|
||||
TestSimpleRequest::b {
|
||||
NumberEnrichment("bla") {
|
||||
deprecated = true
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
it("Can properly assign a reference to a nested enrichment") {
|
||||
jsonSchemaTest<ComplexRequest>(
|
||||
snapshotName = "T0023__enriched_nested_reference.json",
|
||||
enrichment = TypeEnrichment("example") {
|
||||
enrichment = ObjectEnrichment("example") {
|
||||
ComplexRequest::tables {
|
||||
CollectionEnrichment<List<NestedComplexItem>>("tables") {
|
||||
description = "Collection of important items"
|
||||
typeEnrichment = TypeEnrichment("table") {
|
||||
itemEnrichment = ObjectEnrichment("table") {
|
||||
NestedComplexItem::name {
|
||||
StringEnrichment("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") {
|
||||
enrichment = ObjectEnrichment("generic") {
|
||||
GenericObject<TestSimpleRequest>::data {
|
||||
description = "This is a generic param"
|
||||
typeEnrichment = TypeEnrichment("simple") {
|
||||
ObjectEnrichment<TestSimpleRequest>("blob") {
|
||||
description = "This is a generic object"
|
||||
TestSimpleRequest::a {
|
||||
StringEnrichment("blah") {
|
||||
description = "This is a simple description"
|
||||
}
|
||||
}
|
||||
TestSimpleRequest::b {
|
||||
NumberEnrichment("bla") {
|
||||
deprecated = true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
@ -168,7 +183,7 @@ class SchemaGeneratorTest : DescribeSpec({
|
||||
|
||||
private fun JsonSchema.serialize() = json.encodeToString(JsonSchema.serializer(), this)
|
||||
|
||||
private inline fun <reified T> jsonSchemaTest(snapshotName: String, enrichment: TypeEnrichment<*>? = null) {
|
||||
private inline fun <reified T> jsonSchemaTest(snapshotName: String, enrichment: ObjectEnrichment<*>? = null) {
|
||||
// act
|
||||
val schema = SchemaGenerator.fromTypeToSchema(
|
||||
type = typeOf<T>(),
|
||||
|
@ -1,4 +1,3 @@
|
||||
{
|
||||
"enum": [ "ONE", "TWO" ],
|
||||
"type": "string"
|
||||
"enum": [ "ONE", "TWO" ]
|
||||
}
|
||||
|
@ -1,4 +1,3 @@
|
||||
{
|
||||
"enum": [ "ONE", "TWO" ],
|
||||
"type": "string"
|
||||
"enum": [ "ONE", "TWO" ]
|
||||
}
|
||||
|
@ -9,7 +9,7 @@
|
||||
},
|
||||
"tables": {
|
||||
"items": {
|
||||
"$ref": "#/components/schemas/NestedComplexItem-table"
|
||||
"$ref": "#/components/schemas/NestedComplexItem-tables"
|
||||
},
|
||||
"description": "Collection of important items",
|
||||
"type": "array"
|
||||
|
@ -2,8 +2,8 @@
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"data": {
|
||||
"description": "This is a generic param",
|
||||
"$ref": "#/components/schemas/TestSimpleRequest-simple"
|
||||
"$ref": "#/components/schemas/TestSimpleRequest-blob",
|
||||
"description": "This is a generic object"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
|
@ -1,42 +0,0 @@
|
||||
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 Locations")
|
||||
libraryDescription.set("Supplemental library for Kompendium offering support for Ktor's Location API")
|
||||
compilerArgs.set(listOf("-opt-in=kotlin.RequiresOptIn"))
|
||||
}
|
||||
|
||||
dependencies {
|
||||
// Versions
|
||||
val detektVersion: String by project
|
||||
|
||||
// IMPLEMENTATION
|
||||
|
||||
implementation(projects.kompendiumCore)
|
||||
implementation("io.ktor:ktor-server-core:2.3.4")
|
||||
implementation("io.ktor:ktor-server-locations:2.3.4")
|
||||
|
||||
// TESTING
|
||||
|
||||
testImplementation(testFixtures(projects.kompendiumCore))
|
||||
|
||||
// Formatting
|
||||
detektPlugins("io.gitlab.arturbosch.detekt:detekt-formatting:$detektVersion")
|
||||
}
|
||||
|
||||
testing {
|
||||
suites {
|
||||
named("test", JvmTestSuite::class) {
|
||||
useJUnitJupiter()
|
||||
}
|
||||
}
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user