-
-
Notifications
You must be signed in to change notification settings - Fork 334
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(core): add mode include/exclude to input filters option
- Loading branch information
Showing
8 changed files
with
216 additions
and
20 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
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,98 @@ | ||
import { describe, expect, it } from 'vitest'; | ||
import type { ContextSpecs, InputFiltersOption, SchemasObject } from '../types'; | ||
import { generateSchemasDefinition } from './schema-definition'; | ||
|
||
describe('generateSchemasDefinition', () => { | ||
const context: ContextSpecs = { | ||
specKey: 'testSpec', | ||
output: { | ||
override: { | ||
useNativeEnums: false, | ||
}, | ||
}, | ||
target: 'typescript', | ||
specs: {}, | ||
}; | ||
|
||
it('should return an empty array if schemas are empty', () => { | ||
const result = generateSchemasDefinition({}, context, 'Suffix'); | ||
expect(result).toEqual([]); | ||
}); | ||
|
||
it('should generate schemas without filters', () => { | ||
const schemas: SchemasObject = { | ||
TestSchema: { | ||
type: 'object', | ||
properties: { | ||
id: { type: 'string' }, | ||
}, | ||
}, | ||
}; | ||
|
||
const result = generateSchemasDefinition(schemas, context, 'Suffix'); | ||
expect(result).toHaveLength(1); | ||
expect(result[0].name).toBe('TestSchemaSuffix'); | ||
}); | ||
|
||
it('should generate schemas with include filters', () => { | ||
const schemas: SchemasObject = { | ||
TestSchema: { | ||
type: 'object', | ||
properties: { | ||
id: { type: 'string' }, | ||
}, | ||
}, | ||
AnotherSchema: { | ||
type: 'object', | ||
properties: { | ||
name: { type: 'string' }, | ||
}, | ||
}, | ||
}; | ||
|
||
const filters: InputFiltersOption = { | ||
schemas: ['TestSchema'], | ||
mode: 'include', | ||
}; | ||
|
||
const result = generateSchemasDefinition( | ||
schemas, | ||
context, | ||
'Suffix', | ||
filters, | ||
); | ||
expect(result).toHaveLength(1); | ||
expect(result[0].name).toBe('TestSchemaSuffix'); | ||
}); | ||
|
||
it('should generate schemas with exclude filters', () => { | ||
const schemas: SchemasObject = { | ||
TestSchema: { | ||
type: 'object', | ||
properties: { | ||
id: { type: 'string' }, | ||
}, | ||
}, | ||
AnotherSchema: { | ||
type: 'object', | ||
properties: { | ||
name: { type: 'string' }, | ||
}, | ||
}, | ||
}; | ||
|
||
const filters: InputFiltersOption = { | ||
schemas: ['TestSchema'], | ||
mode: 'exclude', | ||
}; | ||
|
||
const result = generateSchemasDefinition( | ||
schemas, | ||
context, | ||
'Suffix', | ||
filters, | ||
); | ||
expect(result).toHaveLength(1); | ||
expect(result[0].name).toBe('AnotherSchemaSuffix'); | ||
}); | ||
}); |
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
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