-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
916 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
160 changes: 160 additions & 0 deletions
160
core/src/test/kotlin/io/bkbn/kompendium/core/util/Constraints.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,160 @@ | ||
package io.bkbn.kompendium.core.util | ||
|
||
import io.bkbn.kompendium.core.fixtures.DoubleResponse | ||
import io.bkbn.kompendium.core.fixtures.Page | ||
import io.bkbn.kompendium.core.fixtures.TestCreatedResponse | ||
import io.bkbn.kompendium.core.fixtures.TestNested | ||
import io.bkbn.kompendium.core.metadata.GetInfo | ||
import io.bkbn.kompendium.core.plugin.NotarizedRoute | ||
import io.bkbn.kompendium.core.util.TestModules.defaultPath | ||
import io.bkbn.kompendium.enrichment.TypeEnrichment | ||
import io.ktor.http.HttpStatusCode | ||
import io.ktor.server.application.install | ||
import io.ktor.server.routing.Routing | ||
import io.ktor.server.routing.route | ||
|
||
fun Routing.intConstraints() { | ||
route(defaultPath) { | ||
install(NotarizedRoute()) { | ||
get = GetInfo.builder { | ||
summary("Get an int") | ||
description("Get an int") | ||
response { | ||
responseCode(HttpStatusCode.OK) | ||
description("An int") | ||
responseType( | ||
enrichment = TypeEnrichment("example") { | ||
TestCreatedResponse::id { | ||
minimum = 2 | ||
maximum = 100 | ||
multipleOf = 2 | ||
} | ||
} | ||
) | ||
responseCode(HttpStatusCode.OK) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
fun Routing.doubleConstraints() { | ||
route(defaultPath) { | ||
install(NotarizedRoute()) { | ||
get = GetInfo.builder { | ||
summary("Get a double") | ||
description("Get a double") | ||
response { | ||
responseCode(HttpStatusCode.OK) | ||
description("A double") | ||
responseType( | ||
enrichment = TypeEnrichment("example") { | ||
DoubleResponse::payload { | ||
minimum = 2.0 | ||
maximum = 100.0 | ||
multipleOf = 2.0 | ||
} | ||
} | ||
) | ||
responseCode(HttpStatusCode.OK) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
fun Routing.stringConstraints() { | ||
route(defaultPath) { | ||
install(NotarizedRoute()) { | ||
get = GetInfo.builder { | ||
summary("Get a string") | ||
description("Get a string with constraints") | ||
response { | ||
responseCode(HttpStatusCode.OK) | ||
description("A string") | ||
responseType( | ||
enrichment = TypeEnrichment("example") { | ||
TestNested::nesty { | ||
maxLength = 10 | ||
minLength = 2 | ||
} | ||
} | ||
) | ||
responseCode(HttpStatusCode.OK) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
fun Routing.stringPatternConstraints() { | ||
route(defaultPath) { | ||
install(NotarizedRoute()) { | ||
get = GetInfo.builder { | ||
summary("Get a string") | ||
description("This is a description") | ||
response { | ||
responseCode(HttpStatusCode.OK) | ||
description("A string") | ||
responseType( | ||
enrichment = TypeEnrichment("example") { | ||
TestNested::nesty { | ||
pattern = "[a-z]+" | ||
} | ||
} | ||
) | ||
responseCode(HttpStatusCode.OK) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
fun Routing.stringContentEncodingConstraints() { | ||
route(defaultPath) { | ||
install(NotarizedRoute()) { | ||
get = GetInfo.builder { | ||
summary("Get a string") | ||
description("This is a description") | ||
response { | ||
responseCode(HttpStatusCode.OK) | ||
description("A string") | ||
responseType( | ||
enrichment = TypeEnrichment("example") { | ||
TestNested::nesty { | ||
contentEncoding = "base64" | ||
contentMediaType = "image/png" | ||
} | ||
} | ||
) | ||
responseCode(HttpStatusCode.OK) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
fun Routing.arrayConstraints() { | ||
route(defaultPath) { | ||
install(NotarizedRoute()) { | ||
get = GetInfo.builder { | ||
summary("Get an array") | ||
description("Get an array of strings") | ||
response { | ||
responseCode(HttpStatusCode.OK) | ||
description("An array") | ||
responseType( | ||
enrichment = TypeEnrichment("example") { | ||
Page<String>::content { | ||
minItems = 2 | ||
maxItems = 10 | ||
uniqueItems = true | ||
} | ||
} | ||
) | ||
responseCode(HttpStatusCode.OK) | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
{ | ||
"openapi": "3.1.0", | ||
"jsonSchemaDialect": "https://json-schema.org/draft/2020-12/schema", | ||
"info": { | ||
"title": "Test API", | ||
"version": "1.33.7", | ||
"description": "An amazing, fully-ish 😉 generated API spec", | ||
"termsOfService": "https://example.com", | ||
"contact": { | ||
"name": "Homer Simpson", | ||
"url": "https://gph.is/1NPUDiM", | ||
"email": "[email protected]" | ||
}, | ||
"license": { | ||
"name": "MIT", | ||
"url": "https://github.com/bkbnio/kompendium/blob/main/LICENSE" | ||
} | ||
}, | ||
"servers": [ | ||
{ | ||
"url": "https://myawesomeapi.com", | ||
"description": "Production instance of my API" | ||
}, | ||
{ | ||
"url": "https://staging.myawesomeapi.com", | ||
"description": "Where the fun stuff happens" | ||
} | ||
], | ||
"paths": { | ||
"/test/{a}": { | ||
"get": { | ||
"tags": [], | ||
"summary": "Get an int", | ||
"description": "Get an int", | ||
"parameters": [], | ||
"responses": { | ||
"200": { | ||
"description": "An int", | ||
"content": { | ||
"application/json": { | ||
"schema": { | ||
"$ref": "#/components/schemas/TestCreatedResponse-example" | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
"deprecated": false | ||
}, | ||
"parameters": [] | ||
} | ||
}, | ||
"webhooks": {}, | ||
"components": { | ||
"schemas": { | ||
"TestCreatedResponse-example": { | ||
"type": "object", | ||
"properties": { | ||
"c": { | ||
"type": "string" | ||
}, | ||
"id": { | ||
"type": "number", | ||
"format": "int32", | ||
"multipleOf": 2, | ||
"maximum": 100, | ||
"minimum": 2 | ||
} | ||
}, | ||
"required": [ | ||
"c", | ||
"id" | ||
] | ||
} | ||
}, | ||
"securitySchemes": {} | ||
}, | ||
"security": [], | ||
"tags": [] | ||
} |
Oops, something went wrong.