@@ -19,7 +19,6 @@ import (
19
19
"log"
20
20
"net/http"
21
21
"net/url"
22
- "os"
23
22
slashpath "path"
24
23
"path/filepath"
25
24
"sort"
@@ -34,18 +33,25 @@ import (
34
33
)
35
34
36
35
// FlattenOpts configuration for flattening a swagger specification.
36
+ //
37
+ // The BasePath parameter is used to locate remote relative $ref found in the specification.
38
+ // This path is a file: it points to the location of the root document and may be either a local
39
+ // file path or a URL.
40
+ //
41
+ // If none specified, relative references (e.g. "$ref": "folder/schema.yaml#/definitions/...")
42
+ // found in the spec are searched from the current working directory.
37
43
type FlattenOpts struct {
38
44
Spec * Spec // The analyzed spec to work with
39
45
flattenContext * context // Internal context to track flattening activity
40
46
41
- BasePath string
47
+ BasePath string // The location of the root document for this spec to resolve relative $ref
42
48
43
49
// Flattening options
44
- Expand bool // If Expand is true, we skip flattening the spec and expand it instead
45
- Minimal bool
46
- Verbose bool
47
- RemoveUnused bool
48
- ContinueOnError bool // Continues when facing some issues
50
+ Expand bool // When true, skip flattening the spec and expand it instead (if Minimal is false)
51
+ Minimal bool // When true, do not decompose complex structures such as allOf
52
+ Verbose bool // enable some reporting on possible name conflicts detected
53
+ RemoveUnused bool // When true, remove unused parameters, responses and definitions after expansion/flattening
54
+ ContinueOnError bool // Continue when spec expansion issues are found
49
55
50
56
/* Extra keys */
51
57
_ struct {} // require keys
@@ -91,6 +97,7 @@ func newContext() *context {
91
97
//
92
98
// There is a minimal and a full flattening mode.
93
99
//
100
+ //
94
101
// Minimally flattening a spec means:
95
102
// - Expanding parameters, responses, path items, parameter items and header items (references to schemas are left
96
103
// unscathed)
@@ -105,6 +112,8 @@ func newContext() *context {
105
112
// NOTE: arbitrary JSON pointers (other than $refs to top level definitions) are rewritten as definitions if they
106
113
// represent a complex schema or express commonality in the spec.
107
114
// Otherwise, they are simply expanded.
115
+ // Self-referencing JSON pointers cannot resolve to a type and trigger an error.
116
+ //
108
117
//
109
118
// Minimal flattening is necessary and sufficient for codegen rendering using go-swagger.
110
119
//
@@ -137,15 +146,6 @@ func newContext() *context {
137
146
//
138
147
func Flatten (opts FlattenOpts ) error {
139
148
debugLog ("FlattenOpts: %#v" , opts )
140
- // Make sure opts.BasePath is an absolute path
141
- if ! filepath .IsAbs (opts .BasePath ) {
142
- cwd , _ := os .Getwd ()
143
- opts .BasePath = filepath .Join (cwd , opts .BasePath )
144
- }
145
- // make sure drive letter on windows is normalized to lower case
146
- u , _ := url .Parse (opts .BasePath )
147
- opts .BasePath = u .String ()
148
-
149
149
opts .flattenContext = newContext ()
150
150
151
151
// recursively expand responses, parameters, path items and items in simple schemas.
@@ -180,6 +180,7 @@ func Flatten(opts FlattenOpts) error {
180
180
// This inlining deals with name conflicts by introducing auto-generated names ("OAIGen")
181
181
var err error
182
182
if imported , err = importExternalReferences (& opts ); err != nil {
183
+ debugLog ("error in importExternalReferences: %v" , err )
183
184
return err
184
185
}
185
186
opts .Spec .reload () // re-analyze
0 commit comments