internal/openapi/generator/data/coordinatingMediaGenerator.go   A
last analyzed

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
cc 7
eloc 17
dl 0
loc 30
ccs 9
cts 9
cp 1
crap 7
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B data.*coordinatingMediaGenerator.GenerateData 0 17 7
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