fix: bug in testing suite + lots of documentation updates

This commit is contained in:
Ryan Brink
2022-01-12 09:15:27 -05:00
committed by GitHub
parent bc380077fb
commit aa21c1219b
24 changed files with 376 additions and 87 deletions

View File

@ -15,9 +15,6 @@ jobs:
with:
gradle-version: wrapper
arguments: detekt
properties: |
org.gradle.vfs.watch=false
org.gradle.vfs.verbose=false
unit:
runs-on: ubuntu-latest
steps:
@ -32,6 +29,3 @@ jobs:
with:
gradle-version: wrapper
arguments: test koverCollectReports
properties: |
org.gradle.vfs.watch=false
org.gradle.vfs.verbose=false

View File

@ -2,6 +2,8 @@ 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 }}
@ -19,8 +21,5 @@ jobs:
with:
gradle-version: wrapper
arguments: publishAllPublicationsToGithubPackagesRepository
properties: |
org.gradle.vfs.watch=false
org.gradle.vfs.verbose=false
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

View File

@ -8,23 +8,6 @@ env:
ORG_GRADLE_PROJECT_signingKey: ${{ secrets.SONATYPE_SIGNING_KEY }}
ORG_GRADLE_PROJECT_signingPassword: ${{ secrets.SONATYPE_SIGNING_PASSWORD }}
jobs:
publish-to-github:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-java@v2
with:
distribution: 'adopt'
java-version: '17'
- name: Publish to GitHub Packages
uses: burrunan/gradle-cache-action@v1
with:
gradle-version: wrapper
arguments: publishAllPublicationsToGithubPackagesRepository
properties: |
release=true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
publish-to-nexus:
runs-on: ubuntu-latest
steps:
@ -43,3 +26,28 @@ jobs:
env:
ORG_GRADLE_PROJECT_sonatypeUsername: ${{ secrets.SONATYPE_USER }}
ORG_GRADLE_PROJECT_sonatypePassword: ${{ secrets.SONATYPE_PASSWORD }}
build-documentation:
runs-on: ubuntu-latest
needs:
- publish-to-nexus
steps:
- uses: actions/checkout@v2
with:
token: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
- uses: actions/setup-java@v2
with:
distribution: 'adopt'
java-version: '17'
- name: Build New Documentation
uses: burrunan/gradle-cache-action@v1
with:
gradle-version: wrapper
arguments: dokkaHtmlMultiModule
properties: |
release=true
- name: Push New Documentation
uses: EndBug/add-and-commit@v7
with:
default_author: github_actions
branch: main
message: 'doc: Added Latest Documentation ✨'

View File

@ -2,13 +2,8 @@
## Unreleased
### Added
- Support for HTTP Patch, Head, and Options methods
- Support for including parameter examples via `MethodInfo`
### Changed
- Kompendium now leverages the chosen API serializer. Supports Jackson, Gson and Kotlinx Serialization
- Fixed bug where overridden field names were not reflected in serialized object and required array
- Fixed bug where Ktor Location parents were not being scanned for parameters
### Remove
@ -16,7 +11,20 @@
## Released
## [2.0.0-alpha] - January 2nd, 2021
## [2.0.0-beta] - January 12th, 2022
### Added
- Support for HTTP Patch, Head, and Options methods
- Support for including parameter examples via `MethodInfo`
- Dokka Pipeline Generation
- GitHub Pages integration
- Sourdough Gradle updates
### Changed
- Kompendium now leverages the chosen API serializer. Supports Jackson, Gson and Kotlinx Serialization
- Fixed bug where overridden field names were not reflected in serialized object and required array
- Fixed bug where Ktor Location parents were not being scanned for parameters
## [2.0.0-alpha] - January 2nd, 2022
### Added
- Support for OAuth authentication
- Gradle Toolchain feature to ensure match between local JDK and compile target

41
Project.md Normal file
View File

@ -0,0 +1,41 @@
# Kompendium
Welcome to Kompendium, the straight-forward, minimally-invasive OpenAPI generator for Ktor.
## How to install
Kompendium publishes all releases to Maven Central. As such, using the release versions of `Kompendium` is as simple as
declaring it as an implementation dependency in your `build.gradle.kts`
```kotlin
repositories {
mavenCentral()
}
dependencies {
implementation("io.bkbn:kompendium-core:latest.release")
}
```
In addition to publishing releases to Maven Central, a snapshot version gets published to GitHub Packages on every merge
to `main`. These can be consumed by adding the repository to your gradle build file. Instructions can be
found [here](https://docs.github.com/en/packages/working-with-a-github-packages-registry/working-with-the-gradle-registry#using-a-published-package)
## Setting up the Kompendium Plugin
Kompendium is instantiated as a Ktor Feature/Plugin. It can be added to your API as follows
```kotlin
private fun Application.mainModule() {
// Installs the Kompendium Plugin and sets up baseline server metadata
install(Kompendium) {
spec = OpenApiSpec(/*..*/)
}
// ...
}
```
## Notarization
The concept of notarizing routes / exceptions / etc. is central to Kompendium. More details on _how_ to notarize your
API can be found in the kompendium-core module.

View File

@ -31,15 +31,13 @@ dependencies {
}
```
The last two dependencies are optional.
In addition to publishing releases to Maven Central, a snapshot version gets published to GitHub Packages on every merge
to `main`. These can be consumed by adding the repository to your gradle build file. Instructions can be
found [here](https://docs.github.com/en/packages/working-with-a-github-packages-registry/working-with-the-gradle-registry#using-a-published-package)
# Library Details
Details on how to use Kompendium can be found in the Wiki (WIP, this is new for V2 and will be fleshed out prior to release)
Forthcoming, more details on V2 will be published soon :)
## Local Development

View File

@ -1,14 +1,10 @@
import io.bkbn.sourdough.gradle.core.extension.SourdoughLibraryExtension
plugins {
id("io.bkbn.sourdough.root") version "0.3.3"
kotlin("jvm") version "1.6.10" apply false
id("io.bkbn.sourdough.root") version "0.5.4"
id("com.github.jakemarsden.git-hooks") version "0.0.2"
}
sourdough {
toolChainJavaVersion.set(JavaLanguageVersion.of(JavaVersion.VERSION_17.majorVersion))
jvmTarget.set(JavaVersion.VERSION_11.majorVersion)
compilerArgs.set(listOf("-opt-in=kotlin.RequiresOptIn"))
id("org.jetbrains.dokka") version "1.6.10"
id("org.jetbrains.kotlinx.kover") version "0.5.0-RC"
id("io.github.gradle-nexus.publish-plugin") version "1.1.0"
}
gitHooks {
@ -31,21 +27,3 @@ allprojects {
}
}
}
subprojects {
if (this.name != "kompendium-playground") {
apply(plugin = "io.bkbn.sourdough.library")
configure<SourdoughLibraryExtension> {
githubOrg.set("bkbnio")
githubRepo.set("kompendium")
libraryName.set("Kompendium")
libraryDescription.set("A minimally invasive OpenAPI spec generator for Ktor")
licenseName.set("MIT License")
licenseUrl.set("https://mit-license.org")
developerId.set("bkbnio")
developerName.set("Ryan Brink")
developerEmail.set("admin@bkbn.io")
}
}
}

View File

@ -7,3 +7,7 @@ It is separated from core predominantly to allow for potential future integratio
# Package io.bkbn.kompendium.annotations
Contains all annotations used by Kompendium
# Package io.bkbn.kompendium.annotations.constraint
Annotations that place bespoke constraints on individual fields of your API schemas.

View File

@ -1,3 +1,29 @@
plugins {
id("io.bkbn.sourdough.library")
kotlin("jvm")
id("io.bkbn.sourdough.library.jvm") version "0.5.4"
id("io.gitlab.arturbosch.detekt") version "1.19.0"
id("com.adarshr.test-logger") version "3.1.0"
id("org.jetbrains.dokka")
id("maven-publish")
id("java-library")
}
sourdough {
githubOrg.set("bkbnio")
githubRepo.set("kompendium")
libraryName.set("Kompendium Annotations")
libraryDescription.set("A set of annotations used by Kompendium to generate OpenAPI Specifications")
licenseName.set("MIT License")
licenseUrl.set("https://mit-license.org")
developerId.set("unredundant")
developerName.set("Ryan Brink")
developerEmail.set("admin@bkbn.io")
}
testing {
suites {
named("test", JvmTestSuite::class) {
useJUnitJupiter()
}
}
}

View File

@ -5,5 +5,9 @@ their API authentication with minimal modifications to their existing configurat
# Package io.bkbn.kompendium.auth
Base package that is responsible for setting up required authentication route handlers along with exposing
wrapper methods for each ktor-auth authentication mechanism.
Base package that is responsible for setting up required authentication route handlers along with exposing wrapper
methods for each ktor-auth authentication mechanism.
# Package io.bkbn.kompendium.auth
Houses the available security configurations. At the moment, `Basic`, `JWT`, `ApiKey`, and `OAuth` are supported

View File

@ -1,7 +1,24 @@
plugins {
id("io.bkbn.sourdough.library")
kotlin("jvm")
id("io.bkbn.sourdough.library.jvm") version "0.5.4"
id("io.gitlab.arturbosch.detekt") version "1.19.0"
id("com.adarshr.test-logger") version "3.1.0"
id("org.jetbrains.dokka")
id("maven-publish")
id("java-library")
}
sourdough {
githubOrg.set("bkbnio")
githubRepo.set("kompendium")
libraryName.set("Kompendium Authentication")
libraryDescription.set("Kompendium library to pair with Ktor Auth to provide authorization info to OpenAPI")
licenseName.set("MIT License")
licenseUrl.set("https://mit-license.org")
developerId.set("unredundant")
developerName.set("Ryan Brink")
developerEmail.set("admin@bkbn.io")
}
dependencies {
// IMPLEMENTATION
@ -16,3 +33,11 @@ dependencies {
testImplementation(testFixtures(projects.kompendiumCore))
}
testing {
suites {
named("test", JvmTestSuite::class) {
useJUnitJupiter()
}
}
}

View File

@ -1,9 +1,100 @@
# Module kompendium-core
This is where the magic happens. This module houses all the reflective goodness that powers Kompendium.
This is where the magic happens. This module houses all the reflective goodness that powers Kompendium.
It is also the only mandatory client-facing module for a basic setup.
# Package io.bkbn.kompendium.core
The root package contains several objects that power Kompendium
The root package contains several objects that power Kompendium, including the Kompendium Ktor Plugin, route
notarization methods, and the reflection engine that analyzes method info type parameters.
## Plugin
The Kompendium plugin is an extremely light-weight plugin, with only a couple areas of customization.
### Serialization
Kompendium relies on your API to provide a properly-configured `ContentNegotiator` in order to convert the `OpenApiSpec`
into JSON. The advantage to this approach is that all of your data classes will be serialized precisely how you define.
The downside is that issues could exist in serialization frameworks that have not been tested. At the moment, Jackson,
Gson and KotlinX serialization have all been tested. If you run into any serialization issues, particularly with a
serializer not listed above, please open an issue on GitHub 🙏
## Notarization
Central to Kompendium is the concept of notarization.
Notarizing a route is the mechanism by which Kompendium analyzes your route types, along with provided metadata, and
converts to the expected OpenAPI format.
Before jumping into notarization, lets first look at a standard Ktor route
```kotlin
routing {
get {
call.respond(HttpStatusCode.OK, BasicResponse(c = UUID.randomUUID().toString()))
}
}
```
Now, let's compare this to the same functionality, but notarized using Kompendium
```kotlin
routing {
notarizedGet(simpleGetExample) {
call.respond(HttpStatusCode.OK, BasicResponse(c = UUID.randomUUID().toString()))
}
}
```
Pretty simple huh. But hold on... what is this `simpleGetExample`? How can I know that it is so "simple". Let's take a
look
```kotlin
val simpleGetExample = GetInfo<Unit, BasicResponse>(
summary = "Simple, Documented GET Request",
description = "This is to showcase just how easy it is to document your Ktor API!",
responseInfo = ResponseInfo(
status = HttpStatusCode.OK,
description = "This means everything went as expected!",
examples = mapOf("demo" to BasicResponse(c = "52c099d7-8642-46cc-b34e-22f39b923cf4"))
),
tags = setOf("Simple")
)
```
See, not so bad 😄 `GetInfo<*,*>` is an implementation of `MethodInfo<TParam, TResp>`, a sealed interface designed to
encapsulate all the metadata required for documenting an API route. Kompendium leverages this data, along with the
provided type parameters `TParam` and `TResp` to construct the full OpenAPI Specification for your route.
Additionally, just as a backup, each notarization method includes a "post-processing' hook that will allow you to have
final say in the generated route info prior to being attached to the spec. This can be accessed via the optional
parameter
```kotlin
routing {
notarizedGet(simpleGetExample, postProcess = { spec -> spec }) {
call.respond(HttpStatusCode.OK, BasicResponse(c = UUID.randomUUID().toString()))
}
}
```
This should only be used in _extremely_ rare scenarios, but it is nice to know it is there if you need it.
# Package io.bkbn.kompendium.core.metadata
Houses all interfaces and types related to describing route metadata.
# Package io.bkbn.kompendium.core.parser
Responsible for the parse of method information. Base implementation is an interface to support extensibility as shown
in the `kompendium-locations` module.
# Package io.bkbn.kompendium.core.routes
Houses any routes provided by the core module. At the moment the only supported route is to enable ReDoc support.
# Package io.bkbn.kompendium.core.util
Collection of utility functions used by Kompendium

View File

@ -1,6 +1,25 @@
plugins {
id("io.bkbn.sourdough.library")
`java-test-fixtures`
kotlin("jvm")
id("io.bkbn.sourdough.library.jvm") version "0.5.4"
id("io.gitlab.arturbosch.detekt") version "1.19.0"
id("com.adarshr.test-logger") version "3.1.0"
id("org.jetbrains.dokka")
id("maven-publish")
id("java-library")
id("java-test-fixtures")
}
sourdough {
githubOrg.set("bkbnio")
githubRepo.set("kompendium")
libraryName.set("Kompendium Core")
libraryDescription.set("Core functionality for the Kompendium library")
licenseName.set("MIT License")
licenseUrl.set("https://mit-license.org")
developerId.set("unredundant")
developerName.set("Ryan Brink")
developerEmail.set("admin@bkbn.io")
compilerArgs.set(listOf("-opt-in=kotlin.RequiresOptIn"))
}
dependencies {
@ -31,3 +50,11 @@ dependencies {
testFixturesApi(group = "org.jetbrains.kotlinx", name = "kotlinx-serialization-json", version = "1.3.2")
}
testing {
suites {
named("test", JvmTestSuite::class) {
useJUnitJupiter()
}
}
}

View File

@ -1,5 +0,0 @@
package io.bkbn.kompendium.core
import io.bkbn.kompendium.core.parser.IMethodParser
object DefaultMethodParser : IMethodParser

View File

@ -1,9 +1,7 @@
package io.bkbn.kompendium.core
import io.bkbn.kompendium.annotations.Param
import io.bkbn.kompendium.core.DefaultMethodParser.calculateRoutePath
import io.bkbn.kompendium.core.KompendiumPreFlight.methodNotarizationPreFlight
import io.bkbn.kompendium.core.DefaultMethodParser.parseMethodInfo
import io.bkbn.kompendium.core.metadata.method.DeleteInfo
import io.bkbn.kompendium.core.metadata.method.GetInfo
import io.bkbn.kompendium.core.metadata.method.HeadInfo
@ -11,6 +9,8 @@ import io.bkbn.kompendium.core.metadata.method.OptionsInfo
import io.bkbn.kompendium.core.metadata.method.PatchInfo
import io.bkbn.kompendium.core.metadata.method.PostInfo
import io.bkbn.kompendium.core.metadata.method.PutInfo
import io.bkbn.kompendium.core.parser.DefaultMethodParser.calculateRoutePath
import io.bkbn.kompendium.core.parser.DefaultMethodParser.parseMethodInfo
import io.bkbn.kompendium.oas.path.Path
import io.bkbn.kompendium.oas.path.PathOperation
import io.ktor.application.ApplicationCall

View File

@ -22,8 +22,3 @@ sealed interface MethodInfo<TParam, TResp> {
val operationId: String?
get() = null
}
fun main() {
data class Potato(val a: String)
println(Potato::a)
}

View File

@ -0,0 +1,3 @@
package io.bkbn.kompendium.core.parser
object DefaultMethodParser : IMethodParser

View File

@ -1 +1,4 @@
# Module kompendium-locations
Adds support for Ktor [Locations](https://ktor.io/docs/locations.html) API. Any notarized location _must_ be provided
with a `TParam` annotated with `@Location`. Nested Locations are supported

View File

@ -1,5 +1,24 @@
plugins {
id("io.bkbn.sourdough.library")
kotlin("jvm")
id("io.bkbn.sourdough.library.jvm") version "0.5.4"
id("io.gitlab.arturbosch.detekt") version "1.19.0"
id("com.adarshr.test-logger") version "3.1.0"
id("org.jetbrains.dokka")
id("maven-publish")
id("java-library")
}
sourdough {
githubOrg.set("bkbnio")
githubRepo.set("kompendium")
libraryName.set("Kompendium Locations")
libraryDescription.set("Supplemental library for Kompendium offering support for Ktor's Location API")
licenseName.set("MIT License")
licenseUrl.set("https://mit-license.org")
developerId.set("unredundant")
developerName.set("Ryan Brink")
developerEmail.set("admin@bkbn.io")
compilerArgs.set(listOf("-opt-in=kotlin.RequiresOptIn"))
}
dependencies {
@ -14,3 +33,11 @@ dependencies {
testImplementation(testFixtures(projects.kompendiumCore))
}
testing {
suites {
named("test", JvmTestSuite::class) {
useJUnitJupiter()
}
}
}

View File

@ -1,8 +1,35 @@
plugins {
id("io.bkbn.sourdough.library")
kotlin("jvm")
kotlin("plugin.serialization") version "1.6.10"
id("io.bkbn.sourdough.library.jvm") version "0.5.4"
id("io.gitlab.arturbosch.detekt") version "1.19.0"
id("com.adarshr.test-logger") version "3.1.0"
id("org.jetbrains.dokka")
id("maven-publish")
id("java-library")
}
sourdough {
githubOrg.set("bkbnio")
githubRepo.set("kompendium")
libraryName.set("Kompendium OpenAPI Spec")
libraryDescription.set("Collections of kotlin data classes modeling the OpenAPI specification")
licenseName.set("MIT License")
licenseUrl.set("https://mit-license.org")
developerId.set("unredundant")
developerName.set("Ryan Brink")
developerEmail.set("admin@bkbn.io")
compilerArgs.set(listOf("-opt-in=kotlin.RequiresOptIn"))
}
dependencies {
implementation(group = "org.jetbrains.kotlinx", "kotlinx-serialization-json", version = "1.3.1")
}
testing {
suites {
named("test", JvmTestSuite::class) {
useJUnitJupiter()
}
}
}

View File

@ -1,6 +1,12 @@
plugins {
kotlin("jvm")
kotlin("plugin.serialization") version "1.6.10"
application
id("io.bkbn.sourdough.application.jvm") version "0.5.4"
id("application")
}
sourdough {
compilerArgs.set(listOf("-opt-in=kotlin.RequiresOptIn"))
}
dependencies {

View File

@ -6,9 +6,11 @@ import io.bkbn.kompendium.oas.info.Info
import io.bkbn.kompendium.oas.info.License
import io.bkbn.kompendium.oas.serialization.KompendiumSerializersModule
import io.bkbn.kompendium.oas.server.Server
import kotlinx.serialization.ExperimentalSerializationApi
import kotlinx.serialization.json.Json
import java.net.URI
@OptIn(ExperimentalSerializationApi::class)
object Util {
val kotlinxConfig = Json {
classDiscriminator = "class"

View File

@ -1 +1,3 @@
# Module kompendium-swagger-ui
Contains the code necessary to launch `swagger` as your documentation frontend.

View File

@ -1,5 +1,23 @@
plugins {
id("io.bkbn.sourdough.library")
kotlin("jvm")
id("io.bkbn.sourdough.library.jvm") version "0.5.4"
id("io.gitlab.arturbosch.detekt") version "1.19.0"
id("com.adarshr.test-logger") version "3.1.0"
id("org.jetbrains.dokka")
id("maven-publish")
id("java-library")
}
sourdough {
githubOrg.set("bkbnio")
githubRepo.set("kompendium")
libraryName.set("Kompendium Swagger")
libraryDescription.set("Offers Swagger as a bundled WebJAR for Ktor")
licenseName.set("MIT License")
licenseUrl.set("https://mit-license.org")
developerId.set("unredundant")
developerName.set("Ryan Brink")
developerEmail.set("admin@bkbn.io")
}
dependencies {
@ -8,3 +26,11 @@ dependencies {
implementation(group = "io.ktor", name = "ktor-webjars", version = ktorVersion)
implementation(group = "org.webjars", name = "swagger-ui", version = "4.1.3")
}
testing {
suites {
named("test", JvmTestSuite::class) {
useJUnitJupiter()
}
}
}