Skip to content

Commit

Permalink
Merge branch 'develop' into release
Browse files Browse the repository at this point in the history
  • Loading branch information
SMILEY4 committed May 17, 2024
2 parents f1624e5 + 83cfc00 commit b8ac074
Show file tree
Hide file tree
Showing 11 changed files with 101 additions and 36 deletions.
63 changes: 36 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Schema-Kenerator

[![Maven Central](https://maven-badges.herokuapp.com/maven-central/io.github.smiley4/schema-kenerator-core/badge.svg)](https://maven-badges.herokuapp.com/maven-central/io.github.smiley4/schema-kenerator-core)
[![Checks Passing](https://github.com/SMILEY4/schema-kenerator/actions/workflows/checks.yml/badge.svg?branch=develop)](https://github.com/SMILEY4/schema-kenerator/actions/workflows/checks.yml)


Customizable kotlin library to extract information from classes using reflection or kotlinx-serialization and generate schemas (json-schema, swagger) from the resulting information.


Expand All @@ -25,19 +29,16 @@ Customizable kotlin library to extract information from classes using reflection
A wiki with a short documentation is available [here](https://github.com/SMILEY4/schema-kenerator/wiki).



## Installation
## Example (json-schema & reflection)

```kotlin
dependencies {
implementation "io.github.smiley4:schema-kenerator:<VERSION>"
implementation("io.github.smiley4:schema-kenerator-core:<VERSION>")
implementation("io.github.smiley4:schema-kenerator-reflection:<VERSION>")
implementation("io.github.smiley4:schema-kenerator-jsonschema:<VERSION>")
}
```



## Example (json-schema & reflection)

```kotlin
class MyExampleClass(
val someText: String,
Expand All @@ -52,7 +53,7 @@ val jsonSchema = typeOf<MyExampleClass>()
.generateJsonSchema()
.compileInlining()
.json
.prettyPrint()        
.prettyPrint()
```

```json
Expand All @@ -61,32 +62,40 @@ val jsonSchema = typeOf<MyExampleClass>()
"title": "MyExampleClass",
"required": [ "someBoolList", "someText" ],
"properties": {
"someBoolList": {
"type": "array",
"title": "List<Boolean>",
"items": {
"type": "boolean",
"title": "Boolean"
}
},
"someNullableInt": {
"type": "integer",
"title": "Int",
"minimum": -2147483648,
"maximum": 2147483647
},
"someText": {
"type": "string",
"title": "String"
}

"someBoolList": {
"type": "array",
"title": "List<Boolean>",
"items": {
"type": "boolean",
"title": "Boolean"
}
},
"someNullableInt": {
"type": "integer",
"title": "Int",
"minimum": -2147483648,
"maximum": 2147483647
},
"someText": {
"type": "string",
"title": "String"
}
}
}
```



## Example (swagger & kotlinx-serialization)

```kotlin
dependencies {
implementation("io.github.smiley4:schema-kenerator-core:<VERSION>")
implementation("io.github.smiley4:schema-kenerator-serialization:<VERSION>")
implementation("io.github.smiley4:schema-kenerator-swagger:<VERSION>")
}
```

```kotlin
@Serializable
class MyExampleClass(
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ kotlin.code.style=official
# project id
projectGroupId=io.github.smiley4
projectArtifactIdBase=schema-kenerator
projectVersion=0.1
projectVersion=0.1.1

# publishing information
projectNameBase=Schema-Kenerator
Expand Down
6 changes: 5 additions & 1 deletion schema-kenerator-core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,21 @@ repositories {

dependencies {
val versionKotest: String by project
val versionKotlinTest: String by project
testImplementation("io.kotest:kotest-runner-junit5:$versionKotest")
testImplementation("io.kotest:kotest-assertions-core:$versionKotest")
testImplementation("io.kotest:kotest-framework-datatest:$versionKotest")
val versionKotlinTest: String by project
testImplementation("org.jetbrains.kotlin:kotlin-test:$versionKotlinTest")
}

kotlin {
jvmToolchain(11)
}

tasks.withType<Test>().configureEach {
useJUnitPlatform()
}

detekt {
ignoreFailures = false
buildUponDefaultConfig = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,9 @@ class TypeId(
}

private fun parseTypeParameters(fullTypeId: String): List<TypeId> {
if (fullTypeId.contains("<")) {
if (!fullTypeId.contains("<") || !fullTypeId.contains(">")) {
return emptyList()
}
var typeParameters = emptyList<TypeId>()
val paramList = fullTypeId
.split("<")
.toMutableList().also { it.removeFirst() }
Expand Down Expand Up @@ -124,8 +123,7 @@ class TypeId(
}
}
paramFullIds.add(current)
typeParameters = paramFullIds.map { parse(it) }
return typeParameters
return paramFullIds.map { parse(it) }
}

private fun parseAdditionalId(fullTypeId: String): String? {
Expand Down
6 changes: 5 additions & 1 deletion schema-kenerator-jackson/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,19 @@ repositories {
}

dependencies {
implementation(project(":schema-kenerator-core"))
val versionJackson: String by project
implementation(project(":schema-kenerator-core"))
implementation("com.fasterxml.jackson.module:jackson-module-kotlin:$versionJackson")
}

kotlin {
jvmToolchain(11)
}

tasks.withType<Test>().configureEach {
useJUnitPlatform()
}

detekt {
ignoreFailures = false
buildUponDefaultConfig = true
Expand Down
4 changes: 4 additions & 0 deletions schema-kenerator-jsonschema/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ kotlin {
jvmToolchain(11)
}

tasks.withType<Test>().configureEach {
useJUnitPlatform()
}

detekt {
ignoreFailures = false
buildUponDefaultConfig = true
Expand Down
4 changes: 4 additions & 0 deletions schema-kenerator-reflection/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ kotlin {
jvmToolchain(11)
}

tasks.withType<Test>().configureEach {
useJUnitPlatform()
}

detekt {
ignoreFailures = false
buildUponDefaultConfig = true
Expand Down
6 changes: 5 additions & 1 deletion schema-kenerator-serialization/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,20 @@ repositories {
}

dependencies {
val versionKotlinxSerializationJson: String by project
implementation(project(":schema-kenerator-core"))
implementation(kotlin("reflect"))
val versionKotlinxSerializationJson: String by project
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:$versionKotlinxSerializationJson")
}

kotlin {
jvmToolchain(11)
}

tasks.withType<Test>().configureEach {
useJUnitPlatform()
}

detekt {
ignoreFailures = false
buildUponDefaultConfig = true
Expand Down
6 changes: 5 additions & 1 deletion schema-kenerator-swagger/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,19 @@ repositories {
}

dependencies {
implementation(project(":schema-kenerator-core"))
val versionSwaggerParser: String by project
implementation(project(":schema-kenerator-core"))
implementation("io.swagger.parser.v3:swagger-parser:$versionSwaggerParser")
}

kotlin {
jvmToolchain(11)
}

tasks.withType<Test>().configureEach {
useJUnitPlatform()
}

detekt {
ignoreFailures = false
buildUponDefaultConfig = true
Expand Down
4 changes: 4 additions & 0 deletions schema-kenerator-test/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,8 @@ dependencies {
testImplementation(project(":schema-kenerator-jsonschema"))
testImplementation(project(":schema-kenerator-swagger"))
testImplementation(project(":schema-kenerator-jackson"))
}

tasks.withType<Test>().configureEach {
useJUnitPlatform()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package io.github.smiley4.schemakenerator.test

import io.github.smiley4.schemakenerator.serialization.processKotlinxSerialization
import io.github.smiley4.schemakenerator.swagger.compileInlining
import io.github.smiley4.schemakenerator.swagger.data.TitleType
import io.github.smiley4.schemakenerator.swagger.generateSwaggerSchema
import io.github.smiley4.schemakenerator.swagger.withAutoTitle
import io.swagger.v3.oas.models.media.Schema
import kotlinx.serialization.Serializable
import kotlin.reflect.typeOf

@Serializable
class MyExampleClass(
val someText: String,
val someNullableInt: Int?,
val someBoolList: List<Boolean>,
)

fun main() {

val swaggerSchema: Schema<*> = typeOf<MyExampleClass>()
.processKotlinxSerialization()
.generateSwaggerSchema()
.withAutoTitle(TitleType.SIMPLE)
.compileInlining()
.swagger

println(swaggerSchema)

}

0 comments on commit b8ac074

Please sign in to comment.