Total Lines | 30 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 0 |
1 | package data |
||
2 | |||
3 | import ( |
||
4 | "context" |
||
5 | |||
6 | "github.com/getkin/kin-openapi/openapi3" |
||
7 | ) |
||
8 | |||
9 | type coordinatingMediaGenerator struct { |
||
10 | useExamples UseExamplesEnum |
||
11 | schemaGenerator schemaGenerator |
||
12 | } |
||
13 | |||
14 | func (generator *coordinatingMediaGenerator) GenerateData(ctx context.Context, mediaType *openapi3.MediaType) (Data, error) { |
||
15 | 1 | if generator.useExamples == IfPresent || generator.useExamples == Exclusively { |
|
16 | 1 | if mediaType.Example != nil { |
|
17 | 1 | return mediaType.Example, nil |
|
18 | } |
||
19 | 1 | if mediaType.Examples != nil { |
|
20 | 1 | for _, example := range mediaType.Examples { |
|
21 | 1 | return example.Value.Value, nil |
|
22 | } |
||
23 | } |
||
24 | } |
||
25 | |||
26 | 1 | if generator.useExamples == Exclusively { |
|
27 | 1 | return nil, nil |
|
28 | } |
||
29 | |||
30 | 1 | return generator.schemaGenerator.GenerateDataBySchema(ctx, mediaType.Schema.Value) |
|
31 | } |
||
32 |