@@ -72,25 +72,8 @@ func Test_Issue1429(t *testing.T) {
72
72
// assert well expanded
73
73
require .Truef (t , (sp .Paths != nil && sp .Paths .Paths != nil ), "expected paths to be available in fixture" )
74
74
75
- for _ , pi := range sp .Paths .Paths {
76
- for _ , param := range pi .Get .Parameters {
77
- if assert .NotNilf (t , param .Schema , "expected param schema not to be nil" ) {
78
- // all param fixtures are body param with schema
79
- // all $ref expanded
80
- assert .Equal (t , "" , param .Schema .Ref .String ())
81
- }
82
- }
83
- for code , response := range pi .Get .Responses .StatusCodeResponses {
84
- // all response fixtures are with StatusCodeResponses, but 200
85
- if code == 200 {
86
- assert .Nilf (t , response .Schema , "expected response schema to be nil" )
87
- continue
88
- }
89
- if assert .NotNilf (t , response .Schema , "expected response schema not to be nil" ) {
90
- assert .Equal (t , "" , response .Schema .Ref .String ())
91
- }
92
- }
93
- }
75
+ assertPaths1429 (t , sp )
76
+
94
77
for _ , def := range sp .Definitions {
95
78
assert .Equal (t , "" , def .Ref .String ())
96
79
}
@@ -103,48 +86,74 @@ func Test_Issue1429(t *testing.T) {
103
86
// assert well resolved
104
87
require .Truef (t , (sp .Paths != nil && sp .Paths .Paths != nil ), "expected paths to be available in fixture" )
105
88
89
+ assertPaths1429SkipSchema (t , sp )
90
+
91
+ for _ , def := range sp .Definitions {
92
+ assert .Contains (t , def .Ref .String (), "responses.yaml#/" )
93
+ }
94
+ }
95
+
96
+ func assertPaths1429 (t testing.TB , sp * spec.Swagger ) {
106
97
for _ , pi := range sp .Paths .Paths {
107
98
for _ , param := range pi .Get .Parameters {
108
- if assert .NotNilf (t , param .Schema , "expected param schema not to be nil" ) {
109
- // all param fixtures are body param with schema
110
- if param .Name == "plainRequest" {
111
- // this one is expanded
112
- assert .Equal (t , "" , param .Schema .Ref .String ())
113
- continue
114
- }
115
- if param .Name == "nestedBody" {
116
- // this one is local
117
- assert .Truef (t , strings .HasPrefix (param .Schema .Ref .String (), "#/definitions/" ),
118
- "expected rooted definitions $ref, got: %s" , param .Schema .Ref .String ())
119
- continue
120
- }
121
- if param .Name == "remoteRequest" {
122
- assert .Contains (t , param .Schema .Ref .String (), "remote/remote.yaml#/" )
123
- continue
124
- }
125
- assert .Contains (t , param .Schema .Ref .String (), "responses.yaml#/" )
126
- }
99
+ require .NotNilf (t , param .Schema , "expected param schema not to be nil" )
100
+ // all param fixtures are body param with schema
101
+ // all $ref expanded
102
+ assert .Equal (t , "" , param .Schema .Ref .String ())
127
103
}
104
+
128
105
for code , response := range pi .Get .Responses .StatusCodeResponses {
129
106
// all response fixtures are with StatusCodeResponses, but 200
130
107
if code == 200 {
131
108
assert .Nilf (t , response .Schema , "expected response schema to be nil" )
132
109
continue
133
110
}
134
- if code == 204 {
135
- assert .Contains (t , response .Schema .Ref .String (), "remote/remote.yaml#/" )
111
+ require .NotNilf (t , response .Schema , "expected response schema not to be nil" )
112
+ assert .Equal (t , "" , response .Schema .Ref .String ())
113
+ }
114
+ }
115
+ }
116
+
117
+ func assertPaths1429SkipSchema (t testing.TB , sp * spec.Swagger ) {
118
+ for _ , pi := range sp .Paths .Paths {
119
+ for _ , param := range pi .Get .Parameters {
120
+ require .NotNilf (t , param .Schema , "expected param schema not to be nil" )
121
+
122
+ // all param fixtures are body param with schema
123
+ switch param .Name {
124
+ case "plainRequest" :
125
+ // this one is expanded
126
+ assert .Equal (t , "" , param .Schema .Ref .String ())
127
+ continue
128
+ case "nestedBody" :
129
+ // this one is local
130
+ assert .Truef (t , strings .HasPrefix (param .Schema .Ref .String (), "#/definitions/" ),
131
+ "expected rooted definitions $ref, got: %s" , param .Schema .Ref .String ())
132
+ continue
133
+ case "remoteRequest" :
134
+ assert .Contains (t , param .Schema .Ref .String (), "remote/remote.yaml#/" )
136
135
continue
137
136
}
138
- if code == 404 {
137
+ assert .Contains (t , param .Schema .Ref .String (), "responses.yaml#/" )
138
+
139
+ }
140
+
141
+ for code , response := range pi .Get .Responses .StatusCodeResponses {
142
+ // all response fixtures are with StatusCodeResponses, but 200
143
+ switch code {
144
+ case 200 :
145
+ assert .Nilf (t , response .Schema , "expected response schema to be nil" )
146
+ continue
147
+ case 204 :
148
+ assert .Contains (t , response .Schema .Ref .String (), "remote/remote.yaml#/" )
149
+ continue
150
+ case 404 :
139
151
assert .Equal (t , "" , response .Schema .Ref .String ())
140
152
continue
141
153
}
142
154
assert .Containsf (t , response .Schema .Ref .String (), "responses.yaml#/" , "expected remote ref at resp. %d" , code )
143
155
}
144
156
}
145
- for _ , def := range sp .Definitions {
146
- assert .Contains (t , def .Ref .String (), "responses.yaml#/" )
147
- }
148
157
}
149
158
150
159
func Test_MoreLocalExpansion (t * testing.T ) {
0 commit comments