-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: no error for inline array schema when items field is a ref (#257)
Purpose: - generator flattens reference to an array schema back into an inline schema Changes: - Add a check to see if the schema is an array with an items field that uses a ref - Add a check to see if the array schema has primitive type items - Add reusable isPrimitiveType function Tests: - Add tests to ensure the validator does not flag different variations of this array schema - Update expected warnings in tests that use specs with this array schema - Add test to ensure arrays with primitive-type items are not flagged - Add tests for isPrimitiveType function
- Loading branch information
1 parent
4b7ae88
commit 4dd3708
Showing
7 changed files
with
218 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
// takes a schema object that has a 'type' field | ||
module.exports = function(schema) { | ||
return ( | ||
schema.type && | ||
['boolean', 'integer', 'number', 'string'].includes(schema.type) | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
const expect = require('expect'); | ||
const isPrimitiveType = require('../../../src/plugins/utils/isPrimitiveType'); | ||
|
||
describe('isPrimitiveType - util', () => { | ||
it('should return true when the schema uses a primitive type', () => { | ||
const exampleObject = { | ||
schema: { | ||
type: 'string' | ||
} | ||
}; | ||
|
||
expect(isPrimitiveType(exampleObject.schema)).toBe(true); | ||
}); | ||
|
||
it('should return true when given items with a primitive type', () => { | ||
const exampleObject = { | ||
schema: { | ||
type: 'array', | ||
items: { | ||
type: 'boolean' | ||
} | ||
} | ||
}; | ||
|
||
expect(isPrimitiveType(exampleObject.schema.items)).toBe(true); | ||
}); | ||
|
||
it('should return false when the schema uses a non-primitive type', () => { | ||
const exampleObject = { | ||
schema: { | ||
type: 'object', | ||
properties: { | ||
exampleProp: { | ||
type: 'string' | ||
} | ||
} | ||
} | ||
}; | ||
|
||
expect(isPrimitiveType(exampleObject.schema)).toBe(false); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters