Skip to content

Commit 3245254

Browse files
authored
Merge pull request #680 from aman-v-singh/fix/issue#627
Fix Issue#627: Add defined example parameter when schema $ref is resolved
2 parents 008e32d + 08ffde6 commit 3245254

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

lib/deref.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,9 @@ module.exports = {
297297
resolvedSchema = concreteUtils.addOuterPropsToRefSchemaIfIsSupported(resolvedSchema, outerProperties);
298298
}
299299
if (resolvedSchema) {
300+
if (schema.example) {
301+
resolvedSchema.example = schema.example;
302+
}
300303
let refResolvedSchema = this.resolveRefs(resolvedSchema, parameterSourceOption,
301304
components, {
302305
resolveFor,

test/unit/deref.test.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,33 @@ describe('DEREF FUNCTION TESTS ', function() {
313313
expect(output.required).to.not.include('tag');
314314
done();
315315
});
316+
317+
it('should return schema with example parameter(if given) for $ref just like inline schema', function(done) {
318+
var schema = {
319+
$ref: '#/components/schemas/schema1',
320+
example: 'asc'
321+
},
322+
componentsAndPaths = {
323+
components: {
324+
schemas: {
325+
schema1: {
326+
description: 'The unique identifier of a spacecraft',
327+
enum: [
328+
'asc',
329+
'desc'
330+
],
331+
type: 'string'
332+
}
333+
}
334+
}
335+
},
336+
parameterSource = 'REQUEST',
337+
// deref.resolveRefs modifies the input schema and components so cloning to keep tests independent of each other
338+
output = deref.resolveRefs(schema, parameterSource, _.cloneDeep(componentsAndPaths), {});
339+
340+
expect(output.example).to.equal(schema.example);
341+
done();
342+
});
316343
});
317344

318345
describe('resolveAllOf Function', function () {

0 commit comments

Comments
 (0)