@@ -206,7 +206,7 @@ describe('SCHEMA UTILITY FUNCTION TESTS ', function () {
206206 schemaCache = {
207207 schemaFakerCache : { }
208208 } ,
209- key = hash ( 'resolveToSchema ' + JSON . stringify ( resolvedSchema ) ) ,
209+ key = hash ( 'resolveToSchema ' + JSON . stringify ( resolvedSchema ) + ' schemaFormatDEFAULT' ) ,
210210 options = {
211211 indentCharacter : ' ' ,
212212 stackLimit : 10 ,
@@ -251,7 +251,7 @@ describe('SCHEMA UTILITY FUNCTION TESTS ', function () {
251251 { components, concreteUtils } ,
252252 { resolveFor, resolveTo }
253253 ) ,
254- key = hash ( 'resolveToExample ' + JSON . stringify ( resolvedSchema ) ) ,
254+ key = hash ( 'resolveToExample ' + JSON . stringify ( resolvedSchema ) + ' schemaFormatDEFAULT' ) ,
255255 options = {
256256 indentCharacter : ' ' ,
257257 stackLimit : 10 ,
@@ -268,6 +268,60 @@ describe('SCHEMA UTILITY FUNCTION TESTS ', function () {
268268 done ( ) ;
269269
270270 } ) ;
271+
272+ it ( 'should populate schemaFakerCache with distinct value when only the schemaFormat is different' , function ( done ) {
273+ var schema = {
274+ $ref : '#/components/schema/request'
275+ } ,
276+ components = {
277+ schema : {
278+ request : {
279+ properties : {
280+ name : {
281+ type : 'string'
282+ }
283+ }
284+ }
285+ }
286+ } ,
287+ parameterSource = 'REQUEST' ,
288+ resolveTo = 'schema' ,
289+ resolveFor = 'CONVERSION' ,
290+ resolvedSchema = deref . resolveRefs ( schema ,
291+ parameterSource ,
292+ { components, concreteUtils } ,
293+ { resolveFor, resolveTo }
294+ ) ,
295+ schemaCache = {
296+ schemaFakerCache : { }
297+ } ,
298+ xml_key = hash ( 'resolveToSchema ' + JSON . stringify ( resolvedSchema ) + ' schemaFormatXML' ) ,
299+ default_key = hash ( 'resolveToSchema ' + JSON . stringify ( resolvedSchema ) + ' schemaFormatDEFAULT' ) ,
300+ options = {
301+ indentCharacter : ' ' ,
302+ stackLimit : 10 ,
303+ includeDeprecated : true
304+ } ,
305+ fakedSchema_default = SchemaUtils . safeSchemaFaker ( schema , resolveTo , resolveFor , parameterSource ,
306+ { components, concreteUtils } , 'default' , schemaCache , options ) ,
307+ fakedSchema_xml = SchemaUtils . safeSchemaFaker ( schema , resolveTo , resolveFor , parameterSource ,
308+ { components, concreteUtils } , 'xml' , schemaCache , options ) ;
309+
310+ expect ( schemaCache . schemaFakerCache ) . to . have . property ( default_key ) ;
311+ expect ( schemaCache . schemaFakerCache [ default_key ] ) . to . equal ( fakedSchema_default ) ;
312+ expect ( fakedSchema_default ) . to . eql ( {
313+ name : '<string>'
314+ } ) ;
315+
316+ expect ( schemaCache . schemaFakerCache ) . to . have . property ( xml_key ) ;
317+ expect ( schemaCache . schemaFakerCache [ xml_key ] ) . to . equal ( fakedSchema_xml ) ;
318+ expect ( fakedSchema_xml ) . to . eql (
319+ '<element>\n <name>(string)</name>\n</element>'
320+ ) ;
321+
322+ done ( ) ;
323+ } ) ;
324+
271325 } ) ;
272326
273327 describe ( 'convertToPmCollectionVariables function' , function ( ) {
@@ -2577,6 +2631,13 @@ describe('SCHEMA UTILITY FUNCTION TESTS ', function () {
25772631 } ) ;
25782632
25792633 describe ( 'fixPathVariablesInUrl function' , function ( ) {
2634+ it ( 'should be able to handle incorrect urls' , function ( done ) {
2635+ expect ( SchemaUtils . fixPathVariablesInUrl ( { } ) ) . to . equal ( '' ) ;
2636+ expect ( SchemaUtils . fixPathVariablesInUrl ( null ) ) . to . equal ( '' ) ;
2637+ expect ( SchemaUtils . fixPathVariablesInUrl ( undefined ) ) . to . equal ( '' ) ;
2638+ done ( ) ;
2639+ } ) ;
2640+
25802641 it ( 'should convert a url with scheme and path variables' , function ( done ) {
25812642 var convertedUrl = SchemaUtils . fixPathVariablesInUrl ( '{scheme}://developer.uspto.gov/{path0}/segment/{path1}' ) ;
25822643 expect ( convertedUrl ) . to . equal ( '{{scheme}}://developer.uspto.gov/{{path0}}/segment/{{path1}}' ) ;
@@ -2593,6 +2654,18 @@ describe('SCHEMA UTILITY FUNCTION TESTS ', function () {
25932654
25942655 done ( ) ;
25952656 } ) ;
2657+
2658+ it ( 'should correctly handle non string values' , function ( done ) {
2659+ expect ( SchemaUtils . fixPathVariablesInUrl ( 123 ) ) . to . equal ( '' ) ;
2660+
2661+ expect ( SchemaUtils . fixPathVariablesInUrl ( [ ] ) ) . to . equal ( '' ) ;
2662+
2663+ expect ( SchemaUtils . fixPathVariablesInUrl ( { } ) ) . to . equal ( '' ) ;
2664+
2665+ expect ( SchemaUtils . fixPathVariablesInUrl ( true ) ) . to . equal ( '' ) ;
2666+
2667+ done ( ) ;
2668+ } ) ;
25962669 } ) ;
25972670
25982671 describe ( 'findPathVariablesFromPath function' , function ( ) {
0 commit comments