MCPcopy Create free account
hub / github.com/cli/cli / schemaAt

Function schemaAt

script/ghmock/schemacmd.go:377–397  ·  view source on GitHub ↗

schemaAt follows a dotted path, as used by ghmock set --at, into a schema.

(ref *openapi3.SchemaRef, at string)

Source from the content-addressed store, hash-verified

375
376// schemaAt follows a dotted path, as used by ghmock set --at, into a schema.
377func schemaAt(ref *openapi3.SchemaRef, at string) (*openapi3.SchemaRef, error) {
378 if at == "" {
379 return ref, nil
380 }
381 walked := ""
382 for seg := range strings.SplitSeq(at, ".") {
383 if seg == "" {
384 return nil, newUsageError("--at %q has an empty segment", at)
385 }
386 next := childSchema(ref, seg)
387 if next == nil {
388 return nil, missingChild(ref, walked, seg)
389 }
390 ref = next
391 if walked != "" {
392 walked += "."
393 }
394 walked += seg
395 }
396 return ref, nil
397}
398
399// childSchema finds the schema for one step into a value: an array index or
400// an object key. It looks through allOf, oneOf and anyOf.

Callers 1

describeRESTFunction · 0.85

Calls 3

newUsageErrorFunction · 0.85
childSchemaFunction · 0.85
missingChildFunction · 0.85

Tested by

no test coverage detected