Skip to content

Commit 0749d65

Browse files
committed
Upgraded createLinkedHashMap() to use new ACF structNew( "ordered" ) instead.
1 parent 5c7b746 commit 0749d65

File tree

5 files changed

+56
-50
lines changed

5 files changed

+56
-50
lines changed

ModuleConfig.cfc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ component {
2020
// CF Mapping
2121
this.cfmapping = "SwaggerSDK";
2222
// Auto-map models
23-
this.autoMapModels = true;
23+
this.autoMapModels = false;
2424
// Module Dependencies That Must Be Loaded First, use internal names or aliases
2525
this.dependencies = [ "cbjavaloader" ];
2626

changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
* Added more tests
1111
* Added ability to chain methods on all methods that where void before.
1212
* `document.asYAML()` is not fully implemented so you can convert the document to yaml.
13+
* Upgraded `createLinkedHashMap()` to use new ACF `structNew( "ordered" )` instead.
1314

1415
## v1.0.4
1516

models/OpenAPI/Parser.cfc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ component name="OpenAPIParser" accessors="true" {
120120

121121
var Parser = JSONFactory.createParser( arguments.JSONData );
122122
var Mapper = jLoader.create( "java.util.Map" );
123-
var HashMap = createLinkedHashMap();
123+
var HashMap = structNew( "ordered" );
124124

125125
HashMap.putAll( deSerializeJSON( JSONData ) );
126126
}

models/OpenAPI/Util.cfc

Lines changed: 50 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,19 @@
66
*/
77
component name="OpenAPIUtil" accessors="true" {
88

9-
public function init(){
9+
/**
10+
* Constructor
11+
*/
12+
function init(){
1013
return this;
1114
}
1215

16+
/**
17+
* Generate a new template for the Open API spec
18+
*/
1319
any function newTemplate(){
1420
//We need to use Linked Hashmaps to maintain struct order for serialization and deserialization
15-
var template = createLinkedHashMap();
21+
var template = structNew( "ordered" );
1622
var templateDefaults = [
1723
{"openapi" : "3.0.2"},
1824
{
@@ -21,12 +27,12 @@ component name="OpenAPIUtil" accessors="true" {
2127
"title" : "",
2228
"description" : "",
2329
"termsOfService": "",
24-
"contact" : createLinkedHashMap(),
25-
"license" : createLinkedHashMap()
30+
"contact" : structNew( "ordered" ),
31+
"license" : structNew( "ordered" )
2632
}
2733
},
2834
{"servers":[]},
29-
{"paths" : createLinkedHashMap()},
35+
{"paths" : structNew( "ordered" )},
3036
{"security": []},
3137
{
3238
"externalDocs": {
@@ -44,9 +50,12 @@ component name="OpenAPIUtil" accessors="true" {
4450
return template;
4551
}
4652

53+
/**
54+
* Create a new method representation
55+
*/
4756
any function newMethod(){
48-
var method = createLinkedHashMap();
49-
var descMap = createLinkedHashMap();
57+
var method = structNew( "ordered" );
58+
var descMap = structNew( "ordered" );
5059
descMap.put( "description", "" );
5160
//Other supported options are requestBody and tag will be added runtime
5261
var methodDefaults = [
@@ -68,14 +77,25 @@ component name="OpenAPIUtil" accessors="true" {
6877
return method;
6978
}
7079

71-
any function defaultMethods(){
80+
/**
81+
* Get an array of default methods
82+
*/
83+
array function defaultMethods(){
7284
return [ "GET", "PUT", "POST" , "PATCH" , "DELETE" , "HEAD" ];
7385
}
7486

75-
any function defaultSuccessResponses(){
87+
/**
88+
* Get an array of default response codes
89+
*/
90+
array function defaultSuccessResponses(){
7691
return [ 200, 200, 201, 200, 204, 204 ];
7792
}
7893

94+
/**
95+
* Translate path from URL Path
96+
*
97+
* @URLPath
98+
*/
7999
string function translatePath( required string URLPath ){
80100
var pathArray = listToArray( arguments.URLPath, '/' );
81101
for( var i=1; i <= arrayLen( pathArray ); i++ ){
@@ -88,42 +108,46 @@ component name="OpenAPIUtil" accessors="true" {
88108

89109
}
90110

91-
92111
/**
93-
* Converts a Java object to native CFML structure
94-
* @param Object Map The Java map object or array to be converted
95-
*/
96-
function toCF( Map ){
112+
* Converts a Java object to native CFML structure
113+
*
114+
* @param Object Map The Java map object or array to be converted
115+
*/
116+
function toCF( map ){
97117

98-
if(isNull( Map )) return;
118+
if( isNull( arguments.map ) ) return;
99119

100120
//if we're in a loop iteration and the array item is simple, return it
101-
if(isSimpleValue( Map )) return Map;
121+
if( isSimpleValue( arguments.map ) ) return arguments.map;
102122

103-
if(isArray( Map )){
123+
if( isArray( map ) ){
104124
var cfObj = [];
105125

106-
for(var obj in Map){
107-
arrayAppend(cfObj,toCF(obj));
126+
for( var obj in arguments.map ){
127+
arrayAppend( cfObj, toCF( obj ) );
108128
}
109129

110130
} else {
111131

112132
var cfObj = {};
113133

114134
try{
115-
cfObj.putAll( Map );
135+
cfObj.putAll( arguments.map );
116136

117-
} catch (any e){
137+
} catch ( any e ){
118138

119-
return Map;
139+
return arguments.map;
120140
}
121141

122-
//loop our keys to ensure first-level items with sub-documents objects are converted
123-
for(var key in cfObj){
124-
125-
if(!isNull(cfObj[key]) && ( isArray(cfObj[key]) || isStruct(cfObj[key]) ) ) cfObj[key] = toCF(cfObj[key]);
142+
// loop our keys to ensure first-level items with sub-documents objects are converted
143+
for( var key in cfObj ){
126144

145+
if(
146+
!isNull( cfObj[ key ] ) &&
147+
( isArray( cfObj[ key ] ) || isStruct( cfObj[ key ] ) )
148+
){
149+
cfObj[ key ] = toCF( cfObj[ key ] );
150+
}
127151
}
128152
}
129153

models/mixins/hashMap.cfm

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,7 @@
33
* Mixin utility to handle the way older versions of ACF handle the init method when creating a java object
44
**/
55
function createLinkedHashMap(){
6-
if( !isNull( VARIABLES ) && structKeyExists( VARIABLES, "Controller" ) ){
7-
var controller = VARIABLES.controller;
8-
} else if( structKeyExists( APPLICATION, "cbController" ) ) {
9-
var controller = application.cbController;
10-
} else {
11-
throw( "This method must be called from within the Coldbox request or application context" );
12-
}
13-
14-
if( !isNull(VARIABLES) && structKeyExists( VARIABLES, "jLoader" ) ){
15-
var HashMap = VARIABLES.jLoader.create( "java", "java.util.LinkedHashMap" );
16-
} else {
17-
var HashMap = createObject( "java", "java.util.LinkedHashMap" );
18-
}
19-
20-
switch( controller.getCFMLEngine().getEngine() ){
21-
case "ADOBE":
22-
return HashMap.init();
23-
break;
24-
default:
25-
return HashMap;
26-
}
27-
}
6+
// Left for backwards compat
7+
return structNew( "ordered" );
8+
}
289
</cfscript>

0 commit comments

Comments
 (0)