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

Method Example

expr/types.go:578–593  ·  view source on GitHub ↗

Example returns a random example value.

(r *ExampleGenerator)

Source from the content-addressed store, hash-verified

576
577// Example returns a random example value.
578func (m *Map) Example(r *ExampleGenerator) any {
579 if IsObject(m.KeyType.Type) || IsArray(m.KeyType.Type) || IsMap(m.KeyType.Type) {
580 // not much we can do for non hashable Go types
581 return nil
582 }
583 count := r.Int()%3 + 1
584 pair := map[any]any{}
585 for range count {
586 k := m.KeyType.Example(r)
587 v := m.ElemType.Example(r)
588 if k != nil && v != nil {
589 pair[k] = v
590 }
591 }
592 return m.MakeMap(pair)
593}
594
595// MakeMap examines the key type from a Map and create a map with builtin type
596// if possible. The idea is to avoid generating map[any]any,

Callers

nothing calls this directly

Calls 6

MakeMapMethod · 0.95
IsObjectFunction · 0.85
IsArrayFunction · 0.85
IsMapFunction · 0.85
IntMethod · 0.65
ExampleMethod · 0.65

Tested by

no test coverage detected