internal/openapi/generator/content/htmlGenerator.go   A
last analyzed

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
cc 4
eloc 23
dl 0
loc 38
ccs 8
cts 8
cp 1
crap 4
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A content.*htmlGenerator.GenerateContent 0 24 4
1
package content
2
3
import (
4
	"context"
5
6
	"github.com/getkin/kin-openapi/openapi3"
7
	"github.com/muonsoft/openapi-mock/internal/openapi/generator/data"
8
	"github.com/muonsoft/openapi-mock/pkg/logcontext"
9
)
10
11
type htmlGenerator struct {
12
	contentGenerator data.MediaGenerator
13
}
14
15
func (generator *htmlGenerator) GenerateContent(ctx context.Context, response *openapi3.Response, contentType string) (interface{}, error) {
16 1
	originMediaType := response.Content.Get(contentType)
17
18 1
	schema := originMediaType.Schema
19
20 1
	if schema == nil || schema.Value.Type != "string" || schema.Value.Format != "html" {
21 1
		logger := logcontext.LoggerFromContext(ctx)
22 1
		logger.Warnf("only string schema with html format is supported for '%s' content type", contentType)
23
24 1
		schema = &openapi3.SchemaRef{
25
			Value: &openapi3.Schema{
26
				Type:   "string",
27
				Format: "html",
28
			},
29
		}
30
	}
31
32 1
	mediaType := &openapi3.MediaType{
33
		Schema:   schema,
34
		Example:  originMediaType.Example,
35
		Examples: originMediaType.Examples,
36
	}
37
38 1
	return generator.contentGenerator.GenerateData(ctx, mediaType)
39
}
40