-
-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #376 from cmaster11/default-interface-suffix
Introduce the defaultInterfaceSuffix setting
- Loading branch information
Showing
5 changed files
with
76 additions
and
5 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
43 changes: 43 additions & 0 deletions
43
src/__tests__/defaultInterfaceSuffix/defaultInterfaceSuffix.ts
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,43 @@ | ||
import { existsSync, readFileSync, rmdirSync } from 'fs'; | ||
|
||
import { convertFromDirectory } from '../../index'; | ||
|
||
const typeOutputDirectory = './src/__tests__/defaultInterfaceSuffix/interfaces'; | ||
|
||
describe('Create interfaces from schema files and applies a default interface suffix', () => { | ||
beforeAll(() => { | ||
if (existsSync(typeOutputDirectory)) { | ||
rmdirSync(typeOutputDirectory, { recursive: true }); | ||
} | ||
}); | ||
|
||
test('generates interfaces', async () => { | ||
const result = await convertFromDirectory({ | ||
schemaDirectory: './src/__tests__/defaultInterfaceSuffix/schemas', | ||
typeOutputDirectory, | ||
defaultInterfaceSuffix: 'Interface' | ||
}); | ||
|
||
expect(result).toBe(true); | ||
|
||
const oneContent = readFileSync(`${typeOutputDirectory}/One.ts`).toString(); | ||
expect(oneContent).toBe( | ||
`/** | ||
* This file was automatically generated by joi-to-typescript | ||
* Do not modify this file manually | ||
*/ | ||
/** | ||
* a test schema definition | ||
*/ | ||
export interface TestInterface { | ||
name?: string; | ||
} | ||
export interface TestWithMetaInterface { | ||
name?: string; | ||
} | ||
` | ||
); | ||
}); | ||
}); |
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,11 @@ | ||
import Joi from 'joi'; | ||
|
||
export const TestSchema = Joi.object({ | ||
name: Joi.string().optional() | ||
}).description('a test schema definition'); | ||
|
||
export const TestWithMetaSchema = Joi.object({ | ||
name: Joi.string().optional() | ||
}).meta({ | ||
myMeta: 'Hello' | ||
}); |
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