This commit is contained in:
Ryan
2021-04-11 11:18:09 -04:00
parent 98d29f2d53
commit 9c48d50394
25 changed files with 210 additions and 7 deletions

View File

@ -4,7 +4,7 @@
package kompendium package kompendium
class Library { class Library {
fun someLibraryMethod(): Boolean { fun someLibraryMethod(): String {
return true return "Heya"
} }
} }

View File

@ -0,0 +1,8 @@
package org.leafygreens.kompendium
import java.net.URI
import org.leafygreens.kompendium.models.OpenApiSpec
class Kompendium {
val spec = OpenApiSpec()
}

View File

@ -0,0 +1,12 @@
package org.leafygreens.kompendium.models
data class OpenApiSpec(
val openapi: String = "3.0.3",
val info: OpenApiSpecInfo? = null,
val servers: List<OpenApiSpecServer> = emptyList(), // TODO Needs to default to server object with url of `/`
val paths: Map<String, OpenApiSpecPathItem> = emptyMap(),
val components: OpenApiSpecComponents? = null,
val security: Map<String, String> = emptyMap(), // todo needs to reference objects in the components -> security scheme 🤔
val tags: List<OpenApiSpecTag> = emptyList(),
val externalDocs: OpenApiSpecExternalDocumentation? = null
)

View File

@ -0,0 +1,6 @@
package org.leafygreens.kompendium.models
// TODO I *think* the only thing I need here is the security https://swagger.io/specification/#components-object
data class OpenApiSpecComponents(
val securitySchemes: Map<String, OpenApiSpecReferencable>
)

View File

@ -0,0 +1,8 @@
package org.leafygreens.kompendium.models
import java.net.URI
data class OpenApiSpecExternalDocumentation(
val url: URI,
val description: String?
)

View File

@ -0,0 +1,12 @@
package org.leafygreens.kompendium.models
import java.net.URI
data class OpenApiSpecInfo(
val title: String,
val version: String,
val description: String?,
val termsOfService: URI?,
val contact: OpenApiSpecInfoContact?,
val license: OpenApiSpecInfoLicense?
)

View File

@ -0,0 +1,9 @@
package org.leafygreens.kompendium.models
import java.net.URI
data class OpenApiSpecInfoContact(
val name: String,
val url: URI?,
val email: String? // TODO Enforce email
)

View File

@ -0,0 +1,8 @@
package org.leafygreens.kompendium.models
import java.net.URI
data class OpenApiSpecInfoLicense(
val name: String,
val url: URI?
)

View File

@ -0,0 +1,10 @@
package org.leafygreens.kompendium.models
data class OpenApiSpecLink(
val operationRef: String?, // todo mutually exclusive with operationId
val operationId: String?,
val parameters: Map<String, String>, // todo sheesh https://swagger.io/specification/#link-object
val requestBody: String, // todo same
val description: String?,
val server: OpenApiSpecServer?
)

View File

@ -0,0 +1,9 @@
package org.leafygreens.kompendium.models
// TODO Oof -> https://swagger.io/specification/#media-type-object
data class OpenApiSpecMediaType(
val schema: String, // TODO sheesh -> https://swagger.io/specification/#schema-object needs to be referencable
val example: String, // TODO Enforce type? then serialize?
val examples: Map<String, String>, // needs to be mutually exclusive with example
val encoding: Map<String, String> // todo encoding object -> https://swagger.io/specification/#encoding-object
)

View File

@ -0,0 +1,10 @@
package org.leafygreens.kompendium.models
import java.net.URI
data class OpenApiSpecOAuthFlow(
val authorizationUrl: URI,
val tokenUrl: URI,
val refreshUrl: URI,
val scopes: Map<String, String>
)

View File

@ -0,0 +1,5 @@
package org.leafygreens.kompendium.models
data class OpenApiSpecOAuthFlows(
val implicit: OpenApiSpecOAuthFlow?,
)

View File

@ -0,0 +1,17 @@
package org.leafygreens.kompendium.models
data class OpenApiSpecPathItem(
val `$ref`: String?, // TODO Maybe drop this?
val summary: String?,
val description: String?,
val get: OpenApiSpecPathItemOperation?,
val put: OpenApiSpecPathItemOperation?,
val post: OpenApiSpecPathItemOperation?,
val delete: OpenApiSpecPathItemOperation?,
val options: OpenApiSpecPathItemOperation?,
val head: OpenApiSpecPathItemOperation?,
val patch: OpenApiSpecPathItemOperation?,
val trace: OpenApiSpecPathItemOperation?,
val servers: List<OpenApiSpecServer> = emptyList(),
val parameters: List<OpenApiSpecReferencable> = emptyList()
)

View File

@ -0,0 +1,16 @@
package org.leafygreens.kompendium.models
data class OpenApiSpecPathItemOperation(
val tags: Set<String> = emptySet(),
val summary: String?,
val description: String?,
val externalDocs: OpenApiSpecExternalDocumentation?,
val operationId: String?,
val parameters: List<OpenApiSpecReferencable> = emptyList(),
val requestBody: OpenApiSpecReferencable,
val responses: Map<String, OpenApiSpecReferencable>, // TODO How to enforce `default` requirement
val callbacks: Map<String, OpenApiSpecReferencable>,
val deprecated: Boolean = false,
val security: Map<String, String>, // todo needs to reference objects in the security scheme 🤔
val servers: List<OpenApiSpecServer>
)

View File

@ -0,0 +1,31 @@
package org.leafygreens.kompendium.models
sealed class OpenApiSpecReferencable
class OpenApiSpecReferenceObject(val `$ref`: String) : OpenApiSpecReferencable()
data class OpenApiSpecCallback(
val todo: String // todo fuck me -> https://swagger.io/specification/#callback-object
) : OpenApiSpecReferencable()
data class OpenApiSpecResponse(
val description: String,
val headers: Map<String, OpenApiSpecReferencable>,
val content: Map<String, OpenApiSpecMediaType>,
val links: Map<String, OpenApiSpecReferencable>
) : OpenApiSpecReferencable()
data class OpenApiSpecHeader(
val name: String,
val description: String?,
val externalDocs: OpenApiSpecExternalDocumentation?
) : OpenApiSpecReferencable()
data class OpenApiSpecParameter(
val name: String,
val `in`: String, // TODO Enum? "query", "header", "path" or "cookie"
val description: String?,
val required: Boolean = true,
val deprecated: Boolean = false,
val allowEmptyValue: Boolean = false
) : OpenApiSpecReferencable()

View File

@ -0,0 +1,7 @@
package org.leafygreens.kompendium.models
data class OpenApiSpecRequest(
val description: String?,
val content: Map<String, OpenApiSpecMediaType>,
val required: Boolean = false
)

View File

@ -0,0 +1,12 @@
package org.leafygreens.kompendium.models
data class OpenApiSpecSecuritySchema(
val type: String, // TODO Enum? "apiKey", "http", "oauth2", "openIdConnect"
val name: String,
val `in`: String,
val scheme: String,
val flows: OpenApiSpecOAuthFlows,
val bearerFormat: String?,
val description: String?,
)

View File

@ -0,0 +1,7 @@
package org.leafygreens.kompendium.models
data class OpenApiSpecServer(
val url: String,
val description: String?,
var variables: Map<String, OpenApiSpecServerVariable>?
)

View File

@ -0,0 +1,7 @@
package org.leafygreens.kompendium.models
data class OpenApiSpecServerVariable(
val `enum`: Set<String>, // todo enforce not empty
val default: String,
val description: String?
)

View File

@ -0,0 +1,7 @@
package org.leafygreens.kompendium.models
data class OpenApiSpecTag(
val name: String,
val description: String?,
val externalDocs: OpenApiSpecExternalDocumentation?
)

View File

@ -4,11 +4,12 @@
package kompendium package kompendium
import kotlin.test.Test import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertTrue import kotlin.test.assertTrue
class LibraryTest { class LibraryTest {
@Test fun testSomeLibraryMethod() { @Test fun testSomeLibraryMethod() {
val classUnderTest = Library() val classUnderTest = Library()
assertTrue(classUnderTest.someLibraryMethod(), "someLibraryMethod should return 'true'") assertEquals(classUnderTest.someLibraryMethod(), "Heya", "someLibraryMethod should return 'true'")
} }
} }

View File

@ -6,7 +6,7 @@ dependencies {
implementation(platform("org.jetbrains.kotlin:kotlin-bom")) implementation(platform("org.jetbrains.kotlin:kotlin-bom"))
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8") implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
implementation(projects.lib) implementation(projects.kompendium)
implementation(libs.bundles.ktor) implementation(libs.bundles.ktor)
implementation(libs.bundles.logging) implementation(libs.bundles.logging)

View File

@ -8,6 +8,7 @@ import io.ktor.routing.route
import io.ktor.routing.routing import io.ktor.routing.routing
import io.ktor.server.engine.embeddedServer import io.ktor.server.engine.embeddedServer
import io.ktor.server.netty.Netty import io.ktor.server.netty.Netty
import kompendium.Library
fun main() { fun main() {
embeddedServer( embeddedServer(
@ -21,7 +22,7 @@ fun Application.mainModule() {
routing { routing {
route("/") { route("/") {
get { get {
call.respondText("hi") call.respondText(Library().someLibraryMethod())
} }
} }
} }

View File

@ -1,5 +1,5 @@
rootProject.name = "kompendium" rootProject.name = "root"
include("lib") include("kompendium")
include("playground") include("playground")
// Feature Previews // Feature Previews