You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
## Update README/serialization docs with details on
`$ref`/`$defs`)deduplication, `kotlin.Any` mapping to `{}`, and sealed
class discriminator behavior
- Revised `JsonSchemaConfig` table in `serializable.md` to clarify
property defaults and add new polymorphism details.
- Explained subtype discriminator constant in generated schema examples.
-**`oneOf` with `$ref`**: Each sealed subclass is referenced from a `$defs` section
666
-
-**Property inheritance**: Base class properties included in each subtype
666
+
-**`oneOf` with `$ref`**: Each sealed subclass is stored in `$defs` and referenced via `$ref`
667
+
-**Fully qualified names**: `$defs` keys and discriminator `const` values use fully qualified class names (e.g., `com.example.Animal.Cat`) to avoid collisions across packages
668
+
-**Discriminator property**: A `type` field with a `const` value is automatically added to each subtype for runtime dispatch
669
+
-**Property inheritance**: Base class properties are included in each subtype
667
670
-**Type safety**: Each subtype gets its own schema definition
668
-
-**Default values**: Subtype properties with defaults (like `lives: Int = 9`) are included
|`respectDefaultPresence`|`Boolean`|`true`| Mark fields with default values as optional (requires reflection; KSP tracks presence but not values). |
287
+
|`requireNullableFields`|`Boolean`|`false`| Include nullable fields in the `required` array. |
288
+
|`useUnionTypes`|`Boolean`|`true`| Represent nullable types as `["string", "null"]` (Draft 2020-12). |
289
+
|`useNullableField`|`Boolean`|`false`| Emit `"nullable": true` instead of union types (legacy OpenAPI compatibility). |
290
+
|`includePolymorphicDiscriminator`|`Boolean`|`true`| Add a `"type"` property with a constant discriminator value to each polymorphic subtype schema. |
291
+
|`includeOpenAPIPolymorphicDiscriminator`|`Boolean`|`false`| Include a `discriminator` mapping object in `oneOf` schemas (OpenAPI 3.x). Requires `includePolymorphicDiscriminator`. |
291
292
292
293
> [!NOTE]
293
294
> `useUnionTypes` and `useNullableField` are mutually exclusive — exactly one must be `true`.
@@ -337,7 +338,9 @@ println(schemaString)
337
338
-->
338
339
<!--- KNIT example-knit-serializable-04.kt -->
339
340
340
-
The generated schema uses `oneOf` with a `$defs` section for each subtype, with a required `type` discriminator field on each subtype object.
341
+
The generated schema uses `oneOf` with a `$defs` section for each subtype.
342
+
Each subtype gets a required `type` property containing the subtype's serial name as a constant (from `@SerialName`),
343
+
enabling runtime dispatch.
341
344
342
345
```json
343
346
{
@@ -357,18 +360,27 @@ The generated schema uses `oneOf` with a `$defs` section for each subtype, with
357
360
"com.example.Shape.Circle": {
358
361
"type": "object",
359
362
"properties": {
363
+
"type": {
364
+
"type": "string",
365
+
"const": "com.example.Shape.Circle"
366
+
},
360
367
"radius": {
361
368
"type": "number"
362
369
}
363
370
},
364
371
"required": [
372
+
"type",
365
373
"radius"
366
374
],
367
375
"additionalProperties": false
368
376
},
369
377
"com.example.Shape.Rectangle": {
370
378
"type": "object",
371
379
"properties": {
380
+
"type": {
381
+
"type": "string",
382
+
"const": "com.example.Shape.Rectangle"
383
+
},
372
384
"width": {
373
385
"type": "number"
374
386
},
@@ -377,6 +389,7 @@ The generated schema uses `oneOf` with a `$defs` section for each subtype, with
0 commit comments