podman

Форк
0
78 строк · 2.5 Кб
1
package analysis
2

3
import (
4
	"log"
5

6
	"github.com/go-openapi/spec"
7
)
8

9
// FlattenOpts configuration for flattening a swagger specification.
10
//
11
// The BasePath parameter is used to locate remote relative $ref found in the specification.
12
// This path is a file: it points to the location of the root document and may be either a local
13
// file path or a URL.
14
//
15
// If none specified, relative references (e.g. "$ref": "folder/schema.yaml#/definitions/...")
16
// found in the spec are searched from the current working directory.
17
type FlattenOpts struct {
18
	Spec           *Spec    // The analyzed spec to work with
19
	flattenContext *context // Internal context to track flattening activity
20

21
	BasePath string // The location of the root document for this spec to resolve relative $ref
22

23
	// Flattening options
24
	Expand          bool // When true, skip flattening the spec and expand it instead (if Minimal is false)
25
	Minimal         bool // When true, do not decompose complex structures such as allOf
26
	Verbose         bool // enable some reporting on possible name conflicts detected
27
	RemoveUnused    bool // When true, remove unused parameters, responses and definitions after expansion/flattening
28
	ContinueOnError bool // Continue when spec expansion issues are found
29

30
	/* Extra keys */
31
	_ struct{} // require keys
32
}
33

34
// ExpandOpts creates a spec.ExpandOptions to configure expanding a specification document.
35
func (f *FlattenOpts) ExpandOpts(skipSchemas bool) *spec.ExpandOptions {
36
	return &spec.ExpandOptions{
37
		RelativeBase:    f.BasePath,
38
		SkipSchemas:     skipSchemas,
39
		ContinueOnError: f.ContinueOnError,
40
	}
41
}
42

43
// Swagger gets the swagger specification for this flatten operation
44
func (f *FlattenOpts) Swagger() *spec.Swagger {
45
	return f.Spec.spec
46
}
47

48
// croak logs notifications and warnings about valid, but possibly unwanted constructs resulting
49
// from flattening a spec
50
func (f *FlattenOpts) croak() {
51
	if !f.Verbose {
52
		return
53
	}
54

55
	reported := make(map[string]bool, len(f.flattenContext.newRefs))
56
	for _, v := range f.Spec.references.allRefs {
57
		// warns about duplicate handling
58
		for _, r := range f.flattenContext.newRefs {
59
			if r.isOAIGen && r.path == v.String() {
60
				reported[r.newName] = true
61
			}
62
		}
63
	}
64

65
	for k := range reported {
66
		log.Printf("warning: duplicate flattened definition name resolved as %s", k)
67
	}
68

69
	// warns about possible type mismatches
70
	uniqueMsg := make(map[string]bool)
71
	for _, msg := range f.flattenContext.warnings {
72
		if _, ok := uniqueMsg[msg]; ok {
73
			continue
74
		}
75
		log.Printf("warning: %s", msg)
76
		uniqueMsg[msg] = true
77
	}
78
}
79

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.