Skip to content

Commit e3f1219

Browse files
authored
Merge pull request #679 from aman-v-singh/fix/issue#660
Fix for Issue#660
2 parents e9d1fda + b559309 commit e3f1219

File tree

3 files changed

+65
-4
lines changed

3 files changed

+65
-4
lines changed

lib/schemaUtils.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,13 @@ function safeSchemaFaker (oldSchema, resolveTo, resolveFor, parameterSourceOptio
196196
});
197197
}
198198

199+
if (schemaFormat === 'xml') {
200+
key += ' schemaFormatXML';
201+
}
202+
else {
203+
key += ' schemaFormatDEFAULT';
204+
}
205+
199206
key = hash(key);
200207
if (schemaFakerCache[key]) {
201208
return schemaFakerCache[key];

lib/xmlSchemaFaker.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ function convertSchemaToXML(name, schema, attribute, indentChar, indent) {
4747
attributes.push(`${key}="${propVal}"`);
4848
}
4949
else {
50-
childNodes += propVal;
50+
childNodes += _.isString(propVal) ? propVal : '';
5151
}
5252
});
5353
if (attributes.length > 0) {
@@ -66,7 +66,7 @@ function convertSchemaToXML(name, schema, attribute, indentChar, indent) {
6666
contents;
6767

6868
schemaItemsWithXmlProps.xml = schema.xml;
69-
contents = convertSchemaToXML(arrayElemName, schemaItemsWithXmlProps, false, indentChar, indent + extraIndent) +
69+
contents = convertSchemaToXML(arrayElemName, schemaItemsWithXmlProps, false, indentChar, indent + extraIndent) +
7070
convertSchemaToXML(arrayElemName, schemaItemsWithXmlProps, false, indentChar, indent + extraIndent);
7171
if (isWrapped) {
7272
return `\n${cIndent}<${tagPrefix}${name}>${contents}\n${cIndent}</${tagPrefix}${name}>`;

test/unit/util.test.js

Lines changed: 56 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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() {

0 commit comments

Comments
 (0)