Skip to content

Commit 3c2728c

Browse files
committed
docs(json): Update Module.md to document Multiplatform support and revise examples
- Added detailed platform support for Reflection-based (JVM) and Serialization-based (Multiplatform) schema generators. - Enhanced examples to include code snippets for Multiplatform usage with kotlinx-serialization. - Revised feature and limitation sections for improved clarity and separation between JVM and Multiplatform implementations.
1 parent 9d8642a commit 3c2728c

File tree

1 file changed

+40
-7
lines changed

1 file changed

+40
-7
lines changed

kotlinx-schema-generator-json/Module.md

Lines changed: 40 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,40 +2,73 @@
22

33
Runtime JSON Schema generation from Kotlin classes and functions.
44

5-
Concrete implementations of schema generators for JVM runtime analysis via Kotlin reflection and kotlinx-serialization.
5+
Concrete implementations of schema generators using Kotlin reflection (JVM) and kotlinx-serialization (Multiplatform).
66

7-
**Platform Support:** JVM only (requires Kotlin reflection) • Kotlin 2.2+
7+
**Platform Support:**
8+
- **Multiplatform**: Transformers and serialization-based generators (Common)
9+
- **JVM only**: Reflection-based generators (require kotlin-reflect)
810

911
## Generators
1012

13+
### Reflection-Based (JVM Only)
14+
1115
- [ReflectionClassJsonSchemaGenerator] - generates schemas from any KClass via reflection
1216
- [ReflectionFunctionCallingSchemaGenerator] - generates function calling schemas from KCallable
13-
- [SerializationClassJsonSchemaGenerator] - generates schemas from @Serializable classes
1417

15-
## Example
18+
### Serialization-Based (Multiplatform)
19+
20+
- [SerializationClassJsonSchemaGenerator] - generates schemas from @Serializable classes (works on JVM, Native, JS, Wasm)
21+
22+
## Examples
23+
24+
### Reflection Generator (JVM)
1625

1726
```kotlin
1827
// Class schema generation
1928
val generator = ReflectionClassJsonSchemaGenerator.Default
2029
val schema: JsonObject = generator.generateSchema(User::class)
2130

22-
// Function schema generation
31+
// Function calling schema generation
2332
val funcGenerator = ReflectionFunctionCallingSchemaGenerator.Default
2433
val funcSchema = funcGenerator.generateSchema(::myFunction)
2534
```
2635

36+
### Serialization Generator (Multiplatform)
37+
38+
```kotlin
39+
import kotlinx.serialization.Serializable
40+
import kotlinx.schema.generator.json.serialization.SerializationClassJsonSchemaGenerator
41+
42+
@Serializable
43+
data class User(val name: String, val email: String? = null)
44+
45+
val generator = SerializationClassJsonSchemaGenerator.Default
46+
val schema = generator.generateSchema(User.serializer().descriptor)
47+
```
48+
2749
## Features
2850

51+
**Reflection Generators (JVM only):**
2952
- Analyze third-party classes without source modification
3053
- Extract default values from data class properties
31-
- Recognize foreign annotations (Jackson, LangChain4j, Koog)
54+
- Recognize foreign annotations (Jackson, Koog, LangChain4j)
3255
- OpenAI/Anthropic function calling format
3356
- Sealed class hierarchies with `oneOf`
3457

58+
**Serialization Generators (Multiplatform):**
59+
- Works on all kotlinx-serialization targets (JVM, Native, JS, Wasm)
60+
- Consistent with kotlinx-serialization behavior
61+
3562
## Limitations
3663

37-
- KDoc annotations not available at runtime
64+
**Reflection Generators:**
3865
- Function parameter defaults cannot be extracted (data class property defaults work)
66+
- JVM only
67+
68+
**Serialization Generators:**
69+
- Requires `@Serializable` annotation
70+
- Cannot extract actual default values (only detects presence)
71+
- Cannot extract descriptions, because of the `SerialDescriptor` limitation
3972

4073
# Package kotlinx.schema.generator.json
4174

0 commit comments

Comments
 (0)