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

Function pickExample

script/ghmock/restscaffold.go:97–114  ·  view source on GitHub ↗

pickExample returns a copy of the example for a response body, preferring the one named default.

(media *openapi3.MediaType)

Source from the content-addressed store, hash-verified

95// pickExample returns a copy of the example for a response body, preferring
96// the one named default.
97func pickExample(media *openapi3.MediaType) (any, bool) {
98 value := media.Example
99 if value == nil && len(media.Examples) > 0 {
100 name := "default"
101 if media.Examples[name] == nil {
102 name = slices.Sorted(maps.Keys(media.Examples))[0]
103 }
104 if ex := media.Examples[name]; ex != nil && ex.Value != nil {
105 value = ex.Value.Value
106 }
107 }
108 if value == nil {
109 return nil, false
110 }
111 // The filler changes values in place, and the example belongs to the
112 // loaded description.
113 return cloneJSON(value), true
114}
115
116// restFiller makes a JSON value match a REST schema. It adds required
117// properties that are missing and replaces values of the wrong type, and

Callers 1

scaffoldMethod · 0.85

Calls 1

cloneJSONFunction · 0.85

Tested by

no test coverage detected