Skip to content

Commit 2cb608b

Browse files
committed
Update Kotlin documentation
This commit updates the Kotlin documentation to showcase the new Kotlin reflection capabilities allowing to identify required properties.
1 parent d7fe07b commit 2cb608b

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

spring-ai-docs/src/main/antora/modules/ROOT/pages/api/chat/openai-chat.adoc

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -376,14 +376,14 @@ Kotlin::
376376
[source,kotlin]
377377
----
378378
data class MathReasoning(
379-
@get:JsonProperty(required = true, value = "steps") val steps: Steps,
380-
@get:JsonProperty(required = true, value = "final_answer") val finalAnswer: String) {
379+
val steps: Steps,
380+
@get:JsonProperty(value = "final_answer") val finalAnswer: String) {
381381
382-
data class Steps(@get:JsonProperty(required = true, value = "items") val items: Array<Items>) {
382+
data class Steps(val items: Array<Items>) {
383383
384384
data class Items(
385-
@get:JsonProperty(required = true, value = "explanation") val explanation: String,
386-
@get:JsonProperty(required = true, value = "output") val output: String)
385+
val explanation: String,
386+
val output: String)
387387
}
388388
}
389389
@@ -405,9 +405,7 @@ val mathReasoning = outputConverter.convert(content)
405405
======
406406
--
407407

408-
NOTE: Ensure you use the `@JsonProperty(required = true,...)` annotation (`@get:JsonProperty(required = true,...)` with Kotlin in order to generate the annotation on the related getters, see link:https://kotlinlang.org/docs/annotations.html#annotation-use-site-targets[related documentation]).
409-
This is crucial for generating a schema that accurately marks fields as `required`.
410-
Although this is optional for JSON Schema, OpenAI link:https://platform.openai.com/docs/guides/structured-outputs/all-fields-must-be-required[mandates] it for the structured response to function correctly.
408+
NOTE: Although this is optional for JSON Schema, OpenAI link:https://platform.openai.com/docs/guides/structured-outputs/all-fields-must-be-required#all-fields-must-be-required[mandates] required fields for the structured response to function correctly. Kotlin reflection is used to infer which property are required or not based on the nullability of types and default values of parameters, so for most use case `@get:JsonProperty(required = true)` is not needed. `@get:JsonProperty(value = "custom_name")` can be useful to customize the property name. Make sure to generate the annotation on the related getters with this `@get:` syntax, see link:https://kotlinlang.org/docs/annotations.html#annotation-use-site-targets[related documentation].
411409

412410
==== Configuring via Application Properties
413411

0 commit comments

Comments
 (0)