Total Lines | 38 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 0 |
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 |