Skip to content

Commit b7e2aa8

Browse files
author
Christian Compton
authored
fix: allow null values for default property (#227)
1 parent ecf2a44 commit b7e2aa8

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

src/plugins/validation/2and3/semantic-validators/walker-ibm.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ module.exports.validate = function({ jsSpec, resolvedSpec }, config) {
5252

5353
// check for and flag null values - they are not allowed by the spec and are likely mistakes
5454
Object.keys(obj).forEach(key => {
55-
if (obj[key] === null) {
55+
if (key !== 'default' && obj[key] === null) {
5656
messages.addMessage(
5757
[...path, key],
5858
'Null values are not allowed for any property.',

test/plugins/validation/2and3/walker-ibm.test.js

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ describe('validation plugin - semantic - walker-ibm', () => {
9797
expect(res.warnings.length).toEqual(0);
9898
});
9999

100-
it('should return an error when a property contains a null value', () => {
100+
it('should return an error when a non-default property contains a null value', () => {
101101
const spec = {
102102
paths: {
103103
'/pets': {
@@ -131,6 +131,29 @@ describe('validation plugin - semantic - walker-ibm', () => {
131131
expect(res.warnings.length).toEqual(0);
132132
});
133133

134+
it('should not return an error when the default property contains a null value', () => {
135+
const spec = {
136+
paths: {
137+
'/pets': {
138+
get: {
139+
parameters: [
140+
{
141+
name: 'tags',
142+
in: 'query',
143+
default: null,
144+
type: 'string'
145+
}
146+
]
147+
}
148+
}
149+
}
150+
};
151+
152+
const res = validate({ jsSpec: spec }, config);
153+
expect(res.errors.length).toEqual(0);
154+
expect(res.warnings.length).toEqual(0);
155+
});
156+
134157
it('should complain if a description sibling to a $ref matches the referenced schema description', async () => {
135158
const spec = {
136159
paths: {

0 commit comments

Comments
 (0)