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

Function discriminatorValue

script/ghmock/restscaffold.go:344–358  ·  view source on GitHub ↗

discriminatorValue is the value that selects alt, such as "private" for GitHub's private-user schema.

(d *openapi3.Discriminator, alt *openapi3.SchemaRef)

Source from the content-addressed store, hash-verified

342// discriminatorValue is the value that selects alt, such as "private" for
343// GitHub's private-user schema.
344func discriminatorValue(d *openapi3.Discriminator, alt *openapi3.SchemaRef) string {
345 for _, key := range slices.Sorted(maps.Keys(d.Mapping)) {
346 if d.Mapping[key].Ref == alt.Ref {
347 return key
348 }
349 }
350 if alt.Value != nil {
351 if p := alt.Value.Properties[d.PropertyName]; p != nil && p.Value != nil && len(p.Value.Enum) > 0 {
352 if v, ok := p.Value.Enum[0].(string); ok {
353 return v
354 }
355 }
356 }
357 return refName(alt)
358}
359
360func cloneJSON(v any) any {
361 data, err := json.Marshal(v)

Callers 2

fillMethod · 0.85
generateMethod · 0.85

Calls 1

refNameFunction · 0.85

Tested by

no test coverage detected