Skip to content
This repository was archived by the owner on Jul 23, 2021. It is now read-only.

Commit 672f62e

Browse files
KariHetchock
authored andcommitted
Handle null values in object check (#128)
1 parent 78a81be commit 672f62e

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

src/models.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ function replaceModelRefs(restApiId, cfModel) {
2626
}
2727
cfModel.DependsOn.add(match[1]+'Model');
2828
}
29-
} else if (typeof obj[key] === 'object') {
29+
} else if (typeof obj[key] === 'object' && obj[key] !== null) {
3030
replaceRefs(obj[key]);
3131
}
3232
}

src/models.spec.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,5 +145,27 @@ describe('ServerlessAWSDocumentation', function() {
145145
});
146146
});
147147

148+
it('should not crash with null values', () => {
149+
let modelInput = {
150+
contentType: 'application/json',
151+
name: 'TestModel',
152+
schema: {
153+
type: 'object',
154+
properties: {
155+
prop: {
156+
enum: ['test', null],
157+
default: null
158+
}
159+
}
160+
}
161+
};
162+
163+
let modelExecution = function() {
164+
objectUnderTest.createCfModel({
165+
Ref: 'ApiGatewayRestApi',
166+
})(modelInput);
167+
}
168+
expect(modelExecution).not.toThrow();
169+
});
148170
});
149171
})

0 commit comments

Comments
 (0)