JSON Schema Integration
forms4s provides integration with JSON Schema, allowing you to generate form elements directly from a JSON Schema definition. This makes it easy to create forms based on existing data models.
Usage
"org.business4s" %% "forms4s-jsonschema" % "0.1.0"
// This is just an example, schema can be acquired or produced in any way
case class MyForm(name: String, age: Int) derives sttp.tapir.Schema
val jsonSchema: sttp.apispec.Schema =
sttp.tapir.docs.apispec.schema.TapirSchemaToJsonSchema(
summon[sttp.tapir.Schema[MyForm]],
markOptionsAsNullable = true,
)
// Convert the JSON Schema to a form
import forms4s.jsonschema.*
val form = FormElement.fromJsonSchema(jsonSchema)
Limitations
- Not all JSON Schema validation keywords are supported yet
- Complex schema combinations (allOf, anyOf) are not fully supported
- Custom formats may require additional configuration
For more advanced use cases, you may need to create form elements manually or extend the FormFromJsonSchema module.
Supported types
| Description | JSON Schema | Form Element Type |
|---|---|---|
| Basic text field | |
Text |
| Multiline text field | |
Text (Multiline) |
| Date field | |
Text (Date) |
| Time field | |
Text (Time) |
| Date and time field | |
Text (DateTime) |
| Email field | |
Text (Email) |
| Integer number field | |
Number (Integer) |
| Decimal number field | |
Number (Decimal) |
| Boolean checkbox field | |
Checkbox |
| Array of form elements | |
Multivalue |
| Dropdown selection field | |
Select |
| Group of form elements | |
Group
|
| Alternative form elements | |
Alternative
|
Supported validations
TODO :)