schemaAt follows a dotted path, as used by ghmock set --at, into a schema.
(ref *openapi3.SchemaRef, at string)
| 375 | |
| 376 | // schemaAt follows a dotted path, as used by ghmock set --at, into a schema. |
| 377 | func 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. |
no test coverage detected