Skip to content

Commit eca0a9f

Browse files
committed
Fix Issue#627: Add defined example parameter when schema is resolved
1 parent e3f1219 commit eca0a9f

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

lib/deref.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,9 @@ module.exports = {
295295
resolvedSchema = concreteUtils.addOuterPropsToRefSchemaIfIsSupported(resolvedSchema, outerProperties);
296296
}
297297
if (resolvedSchema) {
298+
if (schema.example) {
299+
resolvedSchema.example = schema.example;
300+
}
298301
let refResolvedSchema = this.resolveRefs(resolvedSchema, parameterSourceOption,
299302
components, {
300303
resolveFor,

test/unit/deref.test.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,32 @@ 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+
},
321+
componentsAndPaths = {
322+
components: {
323+
schemas: {
324+
schema1: {
325+
description: 'The unique identifier of a spacecraft',
326+
enum: [
327+
'asc',
328+
'desc'
329+
],
330+
type: 'string'
331+
}
332+
}
333+
}
334+
},
335+
parameterSource = 'REQUEST',
336+
// deref.resolveRefs modifies the input schema and components so cloning to keep tests independent of each other
337+
output = deref.resolveRefs(schema, parameterSource, _.cloneDeep(componentsAndPaths), {});
338+
339+
expect(output.example).to.equal(schema.example);
340+
done();
341+
});
316342
});
317343

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

0 commit comments

Comments
 (0)