Skip to content

Commit f4622dd

Browse files
committed
Also merge in top level fields in allOf composition
1 parent 20ef3dc commit f4622dd

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

lib/resolver.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -566,15 +566,14 @@ Resolver.prototype.resolveAllOf = function(spec, obj, depth) {
566566
if(item && typeof item.allOf !== 'undefined') {
567567
var allOf = item.allOf;
568568
if(_.isArray(allOf)) {
569-
var output = {};
569+
var output = _.cloneDeep(item);
570+
delete output['allOf'];
571+
570572
output['x-composed'] = true;
571573
if (typeof item['x-resolved-from'] !== 'undefined') {
572574
output['x-resolved-from'] = item['x-resolved-from'];
573575
}
574-
output.properties = {};
575-
if ( item.example ){
576-
output.example = item.example;
577-
}
576+
578577
for(var i = 0; i < allOf.length; i++) {
579578
var component = allOf[i];
580579
var source = 'self';

test/composition.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ describe('swagger resolver', function () {
6969
} ]
7070
},
7171
Monster: {
72+
description: 'useful information',
7273
allOf : [
7374
{
7475
$ref: '#/definitions/Ghoul'
@@ -84,6 +85,7 @@ describe('swagger resolver', function () {
8485
]
8586
},
8687
Ghoul: {
88+
description: 'a ghoul',
8789
required: [ 'fangs' ],
8890
properties: {
8991
fangs: {
@@ -113,6 +115,8 @@ describe('swagger resolver', function () {
113115
expect(properties.hasScales['x-resolved-from']).toBe('self');
114116
test.undefined(spec.definitions.Animal.properties.firstName);
115117
expect(spec.definitions.Human.example).toBe('this is example');
118+
expect(spec.definitions.Ghoul.description).toBe('a ghoul');
119+
expect(spec.definitions.Monster.description).toBe('useful information');
116120
done();
117121
});
118122
});

0 commit comments

Comments
 (0)