MCPcopy Create free account
hub / github.com/github/gh-aw / extractSchemaExamples

Function extractSchemaExamples

pkg/parser/schema_suggestions.go:70–92  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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.
70func 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
95func extractAcceptedFieldsFromSchema(schemaDoc any, jsonPath string) []string {

Callers 2

Calls 1

navigateToSchemaPathFunction · 0.85

Tested by 1