@@ -20,40 +20,43 @@ component name="OpenAPIDocument" accessors="true" {
2020 * @param Doc The document representation
2121 * @param XPath The XPath of the document to zoom this Document object to
2222 **/
23- Document function init ( required struct Doc , required string XPath = " " ){
24-
23+ Document function init (
24+ required struct Doc ,
25+ required string XPath = " "
26+ ){
2527 // Scope the root Document to handle internal inheritance $refs
2628 setRootDocument ( arguments .Doc );
2729
2830 // Set the working document which will be returned when normalized
2931 setDocument ( arguments .Doc );
3032
3133 // Zoom if requested
32- if ( len ( arguments .XPath ) ){
33- arguments .XPath = arrayToList ( listToArray ( arguments .XPath , " /" ), " ." );
34- this
35- .setXPath ( arguments .XPath )
36- .zoomToXPath ();
34+ if ( len ( arguments .XPath ) ) {
35+ arguments .XPath = arrayToList (
36+ listToArray ( arguments .XPath , " /" ),
37+ " ."
38+ );
39+ this .setXPath ( arguments .XPath ).zoomToXPath ();
3740 }
3841
3942 return this ;
4043 }
4144
4245 /**
43- * Convenience methot for setting the XPath of the Document
44- *
45- * @param XPath The XPath to zoom the parsed document to during recursion
46- **/
46+ * Convenience methot for setting the XPath of the Document
47+ *
48+ * @param XPath The XPath to zoom the parsed document to during recursion
49+ **/
4750 Document function xPath ( required string XPath ){
4851 this .setXPath ( arguments .XPath );
4952 return this ;
5053 }
5154
5255 /**
53- * Zooms this Document instance to the XPath
54- **/
56+ * Zooms this Document instance to the XPath
57+ **/
5558 Document function zoomToXPath (){
56- if ( isNull ( getXPath () ) ) return ;
59+ if ( isNull ( getXPath () ) ) return ;
5760
5861 setDocument ( locate ( getXPath () ) );
5962
@@ -71,9 +74,9 @@ component name="OpenAPIDocument" accessors="true" {
7174 * Convenience method to return a YAML string of the normalized document
7275 **/
7376 function asYAML (){
74- return server .keyExists ( " boxlang" ) ?
75- yamlSerialize ( getNormalizedDocument () ) :
76- variables . jLoader . create ( " org.yaml.snakeyaml.Yaml " ) .dump ( getNormalizedDocument () );
77+ return server .keyExists ( " boxlang" ) ? yamlSerialize ( getNormalizedDocument () ) : variables . jLoader
78+ . create ( " org.yaml.snakeyaml.Yaml " )
79+ .dump ( getNormalizedDocument () );
7780 }
7881
7982 /**
@@ -88,29 +91,39 @@ component name="OpenAPIDocument" accessors="true" {
8891 *
8992 * @param APIDoc The document to normalized. Defaults to the entity document
9093 **/
91- function getNormalizedDocument ( any APIDoc = this .getDocument () ){
92- if ( isArray ( arguments .APIDoc ) ){
93- return arrayMap ( arguments .APIDoc , function ( item ) {
94- return getNormalizedDocument ( item );
95- } );
96- } else if ( isObject ( arguments .APIDoc ) && findNoCase ( " Parser" , getMetaData ( arguments .APIDoc ).name ) ) {
97- if ( ! structKeyExists ( arguments .APIDoc , " getDocumentObject" ) ) {
98- throwForeignObjectTypeException ( arguments .APIDoc );
99- throw (
100- type = " SwaggerSDK.NormalizationException" ,
101- message = " SwaggerSDK doesn't know what do with an object of type #getMetaData ( arguments .APIDoc ).name #."
102- );
103- }
104-
105- return arguments .APIDoc .getDocumentObject ().getNormalizedDocument ();
106- } else if ( isStruct ( arguments .APIDoc ) ) {
107- return structMap ( arguments .APIDoc , function ( key , value ) {
94+ function getNormalizedDocument ( any APIDoc = this .getDocument () ){
95+ if ( isArray ( arguments .APIDoc ) ) {
96+ return arrayMap ( arguments .APIDoc , function ( item ){
97+ return getNormalizedDocument ( item );
98+ } );
99+ } else if (
100+ isObject ( arguments .APIDoc ) && findNoCase (
101+ " Parser" ,
102+ getMetadata ( arguments .APIDoc ).name
103+ )
104+ ) {
105+ if (
106+ ! structKeyExists (
107+ arguments .APIDoc ,
108+ " getDocumentObject"
109+ )
110+ ) {
111+ throwForeignObjectTypeException ( arguments .APIDoc );
112+ throw (
113+ type = " SwaggerSDK.NormalizationException" ,
114+ message = " SwaggerSDK doesn't know what do with an object of type #getMetadata ( arguments .APIDoc ).name #."
115+ );
116+ }
117+
118+ return arguments .APIDoc .getDocumentObject ().getNormalizedDocument ();
119+ } else if ( isStruct ( arguments .APIDoc ) ) {
120+ return structMap ( arguments .APIDoc , function ( key , value ){
108121 // allow explicit nulls in sample docs to pass through
109- return ! isNull ( value ) ? getNormalizedDocument ( value ) : javacast ( " null" , 0 );
110- } );
111- }
122+ return ! isNull ( value ) ? getNormalizedDocument ( value ) : javacast ( " null" , 0 );
123+ } );
124+ }
112125
113- return arguments .APIDoc ;
126+ return arguments .APIDoc ;
114127 }
115128
116129 /**
@@ -123,12 +136,17 @@ component name="OpenAPIDocument" accessors="true" {
123136 any function locate ( string key ){
124137 var rootDocument = this .getRootDocument ();
125138
126- if ( structKeyExists ( rootDocument , arguments .key ) ){
139+ if ( structKeyExists ( rootDocument , arguments .key ) ) {
127140 return rootDocument [ arguments .key ];
128- } else if ( isDefined ( ' rootDocument.#arguments .key #' ) ){
129- return evaluate ( ' rootDocument.#arguments .key #' );
141+ } else if ( isDefined ( " rootDocument.#arguments .key #" ) ) {
142+ return evaluate ( " rootDocument.#arguments .key #" );
130143 } else {
131- return { " $ref" : " ## /#arrayToList ( listToArray ( arguments .key , " ." ), " /" ) #" };
144+ return {
145+ " $ref" : " ## /#arrayToList(
146+ listToArray( arguments.key, " ." ),
147+ " / "
148+ )#"
149+ };
132150 }
133151 }
134152
@@ -137,13 +155,13 @@ component name="OpenAPIDocument" accessors="true" {
137155 /********************************************************************************/
138156
139157 /**
140- * Throws a foreign object type exception if detected when normalizing a document
141- * @param UnKnownObject The foreign object detected
142- **/
158+ * Throws a foreign object type exception if detected when normalizing a document
159+ * @param UnKnownObject The foreign object detected
160+ **/
143161 private function throwForeignObjectTypeException ( required any UnK no w nO bject ){
144162 throw (
145- type = " SwaggerSDK.ForeignObjectException" ,
146- message = " SwaggerSDK doesn't know what do with an object of type #getMetaData ( UnKnownObject ).name #."
163+ type = " SwaggerSDK.ForeignObjectException" ,
164+ message = " SwaggerSDK doesn't know what do with an object of type #getMetadata ( UnKnownObject ).name #."
147165 );
148166 }
149167
0 commit comments