@@ -104,18 +104,21 @@ func ExtractSpecInfoWithDocumentCheck(spec []byte, bypass bool) (*SpecInfo, erro
104
104
_ , openAPI2 := utils .FindKeyNode (utils .OpenApi2 , parsedSpec .Content )
105
105
_ , asyncAPI := utils .FindKeyNode (utils .AsyncApi , parsedSpec .Content )
106
106
107
- parseJSON := func (bytes []byte , spec * SpecInfo , parsedNode * yaml.Node ) {
107
+ parseJSON := func (bytes []byte , spec * SpecInfo , parsedNode * yaml.Node ) error {
108
108
var jsonSpec map [string ]interface {}
109
109
if utils .IsYAML (string (bytes )) {
110
110
_ = parsedNode .Decode (& jsonSpec )
111
111
b , _ := json .Marshal (& jsonSpec )
112
112
spec .SpecJSONBytes = & b
113
113
spec .SpecJSON = & jsonSpec
114
114
} else {
115
- _ = json .Unmarshal (bytes , & jsonSpec )
115
+ if err := json .Unmarshal (bytes , & jsonSpec ); err != nil {
116
+ return err
117
+ }
116
118
spec .SpecJSONBytes = & bytes
117
119
spec .SpecJSON = & jsonSpec
118
120
}
121
+ return nil
119
122
}
120
123
121
124
// if !bypass {
@@ -149,7 +152,9 @@ func ExtractSpecInfoWithDocumentCheck(spec []byte, bypass bool) (*SpecInfo, erro
149
152
}
150
153
151
154
// parse JSON
152
- parseJSON (spec , specInfo , & parsedSpec )
155
+ if err := parseJSON (spec , specInfo , & parsedSpec ); err != nil {
156
+ return nil , fmt .Errorf ("failed to parse json specification: %w" , err )
157
+ }
153
158
parsed = true
154
159
155
160
// double check for the right version, people mix this up.
@@ -176,7 +181,9 @@ func ExtractSpecInfoWithDocumentCheck(spec []byte, bypass bool) (*SpecInfo, erro
176
181
specInfo .APISchema = OpenAPI2SchemaData
177
182
178
183
// parse JSON
179
- parseJSON (spec , specInfo , & parsedSpec )
184
+ if err := parseJSON (spec , specInfo , & parsedSpec ); err != nil {
185
+ return nil , fmt .Errorf ("failed to parse json specification: %w" , err )
186
+ }
180
187
parsed = true
181
188
182
189
// I am not certain this edge-case is very frequent, but let's make sure we handle it anyway.
@@ -200,7 +207,9 @@ func ExtractSpecInfoWithDocumentCheck(spec []byte, bypass bool) (*SpecInfo, erro
200
207
// TODO: format for AsyncAPI.
201
208
202
209
// parse JSON
203
- parseJSON (spec , specInfo , & parsedSpec )
210
+ if err := parseJSON (spec , specInfo , & parsedSpec ); err != nil {
211
+ return nil , fmt .Errorf ("failed to parse json specification: %w" , err )
212
+ }
204
213
parsed = true
205
214
206
215
// so far there is only 2 as a major release of AsyncAPI
@@ -215,7 +224,9 @@ func ExtractSpecInfoWithDocumentCheck(spec []byte, bypass bool) (*SpecInfo, erro
215
224
if specInfo .SpecType == "" {
216
225
// parse JSON
217
226
if ! bypass {
218
- parseJSON (spec , specInfo , & parsedSpec )
227
+ if err := parseJSON (spec , specInfo , & parsedSpec ); err != nil {
228
+ return nil , fmt .Errorf ("failed to parse json specification: %w" , err )
229
+ }
219
230
parsed = true
220
231
specInfo .Error = errors .New ("spec type not supported by libopenapi, sorry" )
221
232
return specInfo , specInfo .Error
@@ -227,7 +238,9 @@ func ExtractSpecInfoWithDocumentCheck(spec []byte, bypass bool) (*SpecInfo, erro
227
238
//}
228
239
229
240
if ! parsed {
230
- parseJSON (spec , specInfo , & parsedSpec )
241
+ if err := parseJSON (spec , specInfo , & parsedSpec ); err != nil {
242
+ return nil , fmt .Errorf ("failed to parse json specification: %w" , err )
243
+ }
231
244
}
232
245
233
246
// detect the original whitespace indentation
0 commit comments