Skip to content

Commit eeb99ee

Browse files
committed
Revert parser changes
1 parent 92deeaf commit eeb99ee

File tree

1 file changed

+35
-43
lines changed

1 file changed

+35
-43
lines changed

models/OpenAPI/Parser.cfc

Lines changed: 35 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
* Open API Parser
66
*/
77
component name="OpenAPIParser" accessors="true" {
8-
98
//the base path of the APIDoc
109
property name="DocumentObject";
1110
property name="baseDocumentPath";
@@ -144,11 +143,22 @@ component name="OpenAPIParser" accessors="true" {
144143
}
145144

146145
for( var key in DocItem){
146+
147147
if( isNull( docItem[ key ] ) ){
148+
DocItem[ key ] = nullValue();
148149
continue;
149-
} else if (
150-
isStruct( DocItem[ key ] )
151-
&&
150+
}
151+
152+
// If `DocItem[ key ]` is an instance of Parser, we need to flattin it to a CFML struct
153+
if (
154+
isStruct( DocItem[ key ] ) &&
155+
findNoCase( "Parser", getMetaData( DocItem[ key ] ).name )
156+
) {
157+
DocItem[ key ] = DocItem[ key ].getNormalizedDocument();
158+
}
159+
160+
if (
161+
isStruct( DocItem[ key ] ) &&
152162
structKeyExists( DocItem[ key ], "$ref" )
153163
) {
154164

@@ -176,10 +186,9 @@ component name="OpenAPIParser" accessors="true" {
176186
**/
177187
public function parseDocumentInheritance( required any DocItem ){
178188

179-
// If `DocItem` is an instance of Parser, we need to flatten it to a CFML struct
189+
// If `DocItem` is an instance of Parser, we need to flattin it to a CFML struct
180190
if (
181191
isStruct( DocItem ) &&
182-
structKeyExists( getMetaData( DocItem ), "name" ) &&
183192
findNoCase( "Parser", getMetaData( DocItem ).name )
184193
) {
185194
DocItem = DocItem.getNormalizedDocument();
@@ -189,33 +198,22 @@ component name="OpenAPIParser" accessors="true" {
189198
for( var i = 1; i <= arrayLen( DocItem ); i++){
190199
DocItem[ i ] = parseDocumentInheritance( DocItem[ i ] );
191200
}
192-
} else if( isStruct( DocItem ) ) {
201+
} else if( isStruct( DocItem ) ) {
193202

194-
var compositionKeys = [ "$allOf", "$oneOf", "$extend" ];
203+
// handle top-level extension
204+
if( structKeyExists( DocItem, "$extend" ) ) {
205+
return extendObject( parseDocumentInheritance( DocItem[ "$extend" ] ) );
206+
}
195207

196-
for( var composition in compositionKeys ){
208+
for( var key in DocItem ){
197209

198-
// handle top-level extension
199-
if(
200-
structKeyExists( DocItem, composition ) &&
201-
isArray( DocItem[ composition ] )
202-
) {
203-
return extendObject( DocItem[ composition ] );
204-
}
205-
206-
for( var key in DocItem){
207-
if( isNull( docItem[ key ] ) ){
208-
continue;
209-
} else if (
210-
isStruct( DocItem[ key ] ) &&
211-
structKeyExists( DocItem[ key ], composition ) &&
212-
isArray( DocItem[ key ][ composition ] )
213-
) {
214-
DocItem[ key ] = parseDocumentReferences( extendObject( DocItem[ key ][ composition ] ) );
215-
} else if( isStruct( DocItem[ key ] ) || isArray( DocItem[ key ] ) ){
216-
DocItem[ key ] = parseDocumentInheritance( parseDocumentReferences( DocItem[ key ] ) );
217-
}
210+
if( isNull( docItem[ key ] ) ){
211+
DocItem[ key ] = nullValue();
212+
continue;
218213
}
214+
if( isStruct( DocItem[ key ] ) || isArray( DocItem[ key ] ) ){
215+
DocItem[ key ] = parseDocumentInheritance( DocItem[ key ] );
216+
}
219217

220218
}
221219

@@ -237,12 +235,6 @@ component name="OpenAPIParser" accessors="true" {
237235
var output = {};
238236
objects.each( function( item, index ) {
239237
if ( isStruct( item ) ) {
240-
241-
// If `item` is an instance of Parser, we need to flatten it to a CFML struct
242-
if ( findNoCase( "Parser", getMetaData( item ).name ) ) {
243-
item = item.getNormalizedDocument();
244-
}
245-
246238
item.each( function( key, value ) {
247239

248240
if (
@@ -305,34 +297,34 @@ component name="OpenAPIParser" accessors="true" {
305297
var ReferenceDocument = {};
306298

307299
try{
308-
var basePath = isNull( getBaseDocumentPath() ) ? "/" : getDirectoryFromPath( getBaseDocumentPath() );
309300

310301
//Files receive a parser reference
311302
if( left( FilePath, 4 ) == 'http' ){
312303

313304
ReferenceDocument = Wirebox.getInstance( "OpenAPIParser@SwaggerSDK" ).init( $ref );
314305

315-
} else if( len( FilePath ) && fileExists( basePath & FilePath )){
306+
} else if( len( FilePath ) && fileExists( getDirectoryFromPath( getBaseDocumentPath() ) & FilePath )){
316307

317-
ReferenceDocument = Wirebox.getInstance( "OpenAPIParser@SwaggerSDK" ).init( basePath & $ref );
308+
ReferenceDocument = Wirebox.getInstance( "OpenAPIParser@SwaggerSDK" ).init( getDirectoryFromPath( getBaseDocumentPath() ) & $ref );
318309

319310
} else if( len( FilePath ) && fileExists( expandPath( FilePath ) ) ) {
320311

321-
ReferenceDocument = Wirebox.getInstance( "OpenAPIParser@SwaggerSDK" ).init( expandPath( FilePath ) & ( !isNull( xPath ) ? "##" & xPath : "" ) );
312+
ReferenceDocument = Wirebox.getInstance( "OpenAPIParser@SwaggerSDK" ).init( expandPath( FilePath ) & ( !isNull( xPath ) ? "##" & xPath : "" ) );
322313

323-
} else if( len( FilePath ) && !fileExists( basePath & FilePath )) {
314+
} else if( len( FilePath ) && !fileExists( getDirectoryFromPath( getBaseDocumentPath() ) & FilePath )) {
324315

325-
throw( type="SwaggerSDK.ParserException", message="File #( basePath & FilePath )# does not exist" );
316+
throw( type="SwaggerSDK.ParserException", message="File #( getDirectoryFromPath( getBaseDocumentPath() ) & FilePath )# does not exist" );
326317

327318
} else if( !isNull( XPath ) && len( XPath ) ) {
328319

329320
ReferenceDocument = getInternalXPath( XPath );
330321

331322
} else {
323+
332324
throw( type="SwaggerSDK.ParserException", message="The $ref #$ref# could not be resolved as either an internal or external reference");
325+
333326
}
334-
} catch( SwaggerSDK.ParserException e ){
335-
rethrow;
327+
336328
} catch( any e ){
337329

338330
// if this is a known exception or occured via recursion, rethrow the exception so the user knows which JSON file triggered it

0 commit comments

Comments
 (0)