data.*coordinatingMediaGenerator.GenerateData   B
last analyzed

Complexity

Conditions 7

Size

Total Lines 17
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 7

Importance

Changes 0
Metric Value
cc 7
eloc 10
nop 2
dl 0
loc 17
ccs 9
cts 9
cp 1
crap 7
rs 8
c 0
b 0
f 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