extractSchemaExamples navigates the schema to the given JSON path using navigateToSchemaPath and returns any "examples" array entries as formatted strings. Returns nil if the path does not exist in the schema or the field has no examples. The schema must have a top-level "properties" map for path na
(schemaDoc any, jsonPath string)
| 68 | // Returns nil if the path does not exist in the schema or the field has no examples. |
| 69 | // The schema must have a top-level "properties" map for path navigation to succeed. |
| 70 | func extractSchemaExamples(schemaDoc any, jsonPath string) []string { |
| 71 | schemaMap, ok := schemaDoc.(map[string]any) |
| 72 | if !ok { |
| 73 | return nil |
| 74 | } |
| 75 | target := navigateToSchemaPath(schemaMap, jsonPath) |
| 76 | if target == nil { |
| 77 | return nil |
| 78 | } |
| 79 | raw, ok := target["examples"] |
| 80 | if !ok { |
| 81 | return nil |
| 82 | } |
| 83 | items, ok := raw.([]any) |
| 84 | if !ok || len(items) == 0 { |
| 85 | return nil |
| 86 | } |
| 87 | examples := make([]string, 0, len(items)) |
| 88 | for _, item := range items { |
| 89 | examples = append(examples, fmt.Sprintf("%v", item)) |
| 90 | } |
| 91 | return examples |
| 92 | } |
| 93 | |
| 94 | // extractAcceptedFieldsFromSchema extracts the list of accepted fields from a schema at a given JSON path |
| 95 | func extractAcceptedFieldsFromSchema(schemaDoc any, jsonPath string) []string { |