Skip to content

Commit 10a3075

Browse files
committed
fix handling of nulls in samples
1 parent 8a9eac9 commit 10a3075

File tree

1 file changed

+33
-24
lines changed

1 file changed

+33
-24
lines changed

models/OpenAPI/Parser.cfc

Lines changed: 33 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -144,14 +144,19 @@ component name="OpenAPIParser" accessors="true" {
144144

145145
for( var key in DocItem){
146146

147+
if( isNull( docItem[ key ] ) ){
148+
DocItem[ key ] = nullValue();
149+
continue;
150+
}
151+
147152
// If `DocItem[ key ]` is an instance of Parser, we need to flattin it to a CFML struct
148-
if (
149-
isStruct( DocItem[ key ] ) &&
150-
findNoCase( "Parser", getMetaData( DocItem[ key ] ).name )
153+
if (
154+
isStruct( DocItem[ key ] ) &&
155+
findNoCase( "Parser", getMetaData( DocItem[ key ] ).name )
151156
) {
152157
DocItem[ key ] = DocItem[ key ].getNormalizedDocument();
153158
}
154-
159+
155160
if (
156161
isStruct( DocItem[ key ] ) &&
157162
structKeyExists( DocItem[ key ], "$ref" )
@@ -180,15 +185,15 @@ component name="OpenAPIParser" accessors="true" {
180185
* @param [XPath] The XPath to zoom the parsed document to during recursion
181186
**/
182187
public function parseDocumentInheritance( required any DocItem ){
183-
188+
184189
// If `DocItem` is an instance of Parser, we need to flattin it to a CFML struct
185-
if (
186-
isStruct( DocItem ) &&
187-
findNoCase( "Parser", getMetaData( DocItem ).name )
190+
if (
191+
isStruct( DocItem ) &&
192+
findNoCase( "Parser", getMetaData( DocItem ).name )
188193
) {
189194
DocItem = DocItem.getNormalizedDocument();
190195
}
191-
196+
192197
if( isArray( DocItem ) ) {
193198
for( var i = 1; i <= arrayLen( DocItem ); i++){
194199
DocItem[ i ] = parseDocumentInheritance( DocItem[ i ] );
@@ -201,7 +206,11 @@ component name="OpenAPIParser" accessors="true" {
201206
}
202207

203208
for( var key in DocItem ){
204-
209+
210+
if( isNull( docItem[ key ] ) ){
211+
DocItem[ key ] = nullValue();
212+
continue;
213+
}
205214
if( isStruct( DocItem[ key ] ) || isArray( DocItem[ key ] ) ){
206215
DocItem[ key ] = parseDocumentInheritance( DocItem[ key ] );
207216
}
@@ -222,12 +231,12 @@ component name="OpenAPIParser" accessors="true" {
222231
* @objects
223232
*/
224233
function extendObject( array objects ) {
225-
234+
226235
var output = {};
227236
objects.each( function( item, index ) {
228237
if ( isStruct( item ) ) {
229238
item.each( function( key, value ) {
230-
239+
231240
if (
232241
output.keyExists( key ) &&
233242
isStruct( output[ key ] )
@@ -287,7 +296,7 @@ component name="OpenAPIParser" accessors="true" {
287296

288297
var ReferenceDocument = {};
289298

290-
try{
299+
// try{
291300

292301
//Files receive a parser reference
293302
if( left( FilePath, 4 ) == 'http' ){
@@ -316,19 +325,19 @@ component name="OpenAPIParser" accessors="true" {
316325

317326
}
318327

319-
} catch( any e ){
328+
// } catch( any e ){
320329

321-
// if this is a known exception or occured via recursion, rethrow the exception so the user knows which JSON file triggered it
322-
if ( listFindNoCase( "SwaggerSDK.ParserException,CBSwagger.InvalidReferenceDocumentException", e.type ) ) {
323-
rethrow;
324-
}
325-
326-
throw(
327-
type="CBSwagger.InvalidReferenceDocumentException",
328-
message="The $ref file pointer of #$ref# could not be loaded and parsed as a valid object. If your $ref file content is an array, please nest the array within an object as a named key."
329-
);
330+
// // if this is a known exception or occured via recursion, rethrow the exception so the user knows which JSON file triggered it
331+
// if ( listFindNoCase( "SwaggerSDK.ParserException,CBSwagger.InvalidReferenceDocumentException", e.type ) ) {
332+
// rethrow;
333+
// }
330334

331-
}
335+
// throw(
336+
// type="CBSwagger.InvalidReferenceDocumentException",
337+
// message="The $ref file pointer of #$ref# could not be loaded and parsed as a valid object. If your $ref file content is an array, please nest the array within an object as a named key."
338+
// );
339+
340+
// }
332341

333342
return ReferenceDocument;
334343
}

0 commit comments

Comments
 (0)