MCPcopy Create free account
hub / github.com/goadesign/goa / initExamples

Function initExamples

http/codegen/openapi/v3/example.go:17–37  ·  view source on GitHub ↗

initExample sets the example or examples of the given object.

(obj exampler, attr *expr.AttributeExpr, r *expr.ExampleGenerator)

Source from the content-addressed store, hash-verified

15
16// initExample sets the example or examples of the given object.
17func initExamples(obj exampler, attr *expr.AttributeExpr, r *expr.ExampleGenerator) {
18 examples := attr.ExtractUserExamples()
19 switch {
20 case len(examples) > 1:
21 refs := make(map[string]*ExampleRef, len(examples))
22 for _, ex := range examples {
23 example := &Example{
24 Summary: ex.Summary,
25 Description: ex.Description,
26 Value: ex.Value,
27 }
28 refs[ex.Summary] = &ExampleRef{Value: example}
29 }
30 obj.setExamples(refs)
31 return
32 case len(examples) > 0:
33 obj.setExample(examples[0].Value)
34 default:
35 obj.setExample(attr.Example(r))
36 }
37}

Callers 4

buildOperationFunction · 0.85
paramForFunction · 0.85
headersFromAttrFunction · 0.85
responseFromExprFunction · 0.85

Calls 4

ExtractUserExamplesMethod · 0.80
setExamplesMethod · 0.65
setExampleMethod · 0.65
ExampleMethod · 0.65

Tested by

no test coverage detected