fun testStandardSchemaNestedDescriptions()

in prompt/prompt-structure/src/commonTest/kotlin/ai/koog/prompt/structure/json/generator/JsonSchemaGeneratorTest.kt [461:535]


    fun testStandardSchemaNestedDescriptions() {
        val descriptions = mapOf(
            "NestedTestClass.name" to "The name (override)",
            "NestedTestClass.nestedList" to "List of nested properties",
            "NestedTestClass.nestedMap" to "Map of nested properties",

            "NestedProperty.bar" to "Nested bar property",
        )

        val result = standardGenerator.generate(json, "NestedTestClass", serializer<NestedTestClass>(), descriptions)
        val schema = json.encodeToString(result.schema)

        val expectedDotSchema = """
            {
              "${"$"}id": "NestedTestClass",
              "${"$"}defs": {
                "NestedProperty": {
                  "type": "object",
                  "properties": {
                    "foo": {
                      "type": "string",
                      "description": "Nested foo property"
                    },
                    "bar": {
                      "type": "integer",
                      "description": "Nested bar property"
                    }
                  },
                  "required": [
                    "foo",
                    "bar"
                  ],
                  "additionalProperties": false,
                  "description": "Nested property class"
                },
                "NestedTestClass": {
                  "type": "object",
                  "properties": {
                    "name": {
                      "type": "string",
                      "description": "The name (override)"
                    },
                    "nested": {
                      "${"$"}ref": "#/${"$"}defs/NestedProperty",
                      "description": "Nested property class"
                    },
                    "nestedList": {
                      "type": "array",
                      "items": {
                        "${"$"}ref": "#/${"$"}defs/NestedProperty"
                      },
                      "description": "List of nested properties"
                    },
                    "nestedMap": {
                      "type": "object",
                      "additionalProperties": {
                        "${"$"}ref": "#/${"$"}defs/NestedProperty"
                      },
                      "description": "Map of nested properties"
                    }
                  },
                  "required": [
                    "name",
                    "nested"
                  ],
                  "additionalProperties": false,
                  "description": "Nested test class"
                }
              },
              "${"$"}ref": "#/${"$"}defs/NestedTestClass"
            }
        """.trimIndent()

        assertEquals(expectedDotSchema, schema)
    }