JSON Schema JVM is a Java/Kotlin library for generating JSON schemas from your data classes. This library simplifies the process of creating JSON schemas directly from your Java or Kotlin classes, making it easy to ensure your data structures conform to specified formats.
- Generate JSON schemas from Java/Kotlin classes
- Java 17
- Kotlin 2.0
Add the following dependencies to your build.gradle.kts
file:
plugins {
id("com.theblueground.json.schema.jvm.gradle-plugin") version "1.0.1"
}
dependencies {
implementation("io.github.bluegroundltd:generate-schema-annotation:1.0.0")
}
Here is a simple example of how to use the library to generate a JSON schema from a Kotlin data class.
package com.example
@GenerateJsonSchema
data class Person(
val name: String,
val age: Int
)
jsonSchemaJvmExtension {
packageToScan.set(setOf("com.example"))
}
{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "Person",
"type": "object",
"additionalProperties": false,
"properties": {
"name": {
"type": "string"
},
"age": {
"type": "integer"
}
},
"required": [
"age"
]
}
Just execute the jsonSchemaJvmGenerationTask
in test-json-schema-jvm
project.
We welcome contributions to the project. Please follow these steps to contribute:
- Fork the repository
- Create a feature branch (
git checkout -b feature/your-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin feature/your-feature
) - Create a new Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.