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

Function generateExampleJSONForPath

pkg/parser/schema_suggestions.go:239–264  ·  view source on GitHub ↗

generateExampleJSONForPath generates an example JSON object for a specific schema path

(schemaDoc any, jsonPath string)

Source from the content-addressed store, hash-verified

237
238// generateExampleJSONForPath generates an example JSON object for a specific schema path
239func generateExampleJSONForPath(schemaDoc any, jsonPath string) string {
240 schemaMap, ok := schemaDoc.(map[string]any)
241 if !ok {
242 return ""
243 }
244
245 // Navigate to the target schema
246 targetSchema := navigateToSchemaPath(schemaMap, jsonPath)
247 if targetSchema == nil {
248 return ""
249 }
250
251 // Generate example based on schema type
252 example := generateExampleFromSchema(targetSchema)
253 if example == nil {
254 return ""
255 }
256
257 // Convert to JSON string
258 exampleJSON, err := json.Marshal(example)
259 if err != nil {
260 return ""
261 }
262
263 return string(exampleJSON)
264}
265
266// generateExampleFromSchema generates an example value based on a JSON schema
267func generateExampleFromSchema(schema map[string]any) any {

Callers 2

typeMismatchSuggestionFunction · 0.85

Calls 2

navigateToSchemaPathFunction · 0.85

Tested by 1