-
-
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 #344 from cmaster11/custom-path
Support new settings `interfaceFileSuffix` and `omitIndexFiles`
- Loading branch information
Showing
11 changed files
with
126 additions
and
4 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,31 @@ | ||
import {existsSync, rmdirSync} from 'fs'; | ||
|
||
import {convertFromDirectory} from '../../index'; | ||
|
||
const typeOutputDirectory = './src/__tests__/interfaceFileSuffix/interfaces'; | ||
|
||
describe('Create interfaces from schema files with a suffix in the interface filename', () => { | ||
beforeAll(() => { | ||
if (existsSync(typeOutputDirectory)) { | ||
rmdirSync(typeOutputDirectory, {recursive: true}); | ||
} | ||
}); | ||
|
||
test('generates interfaces but no index files', async () => { | ||
const result = await convertFromDirectory({ | ||
schemaDirectory: './src/__tests__/interfaceFileSuffix/schemas', | ||
interfaceFileSuffix: '.generated', | ||
typeOutputDirectory | ||
}); | ||
|
||
expect(result) | ||
.toBe(true); | ||
|
||
expect(existsSync(`${typeOutputDirectory}/One.generated.ts`)) | ||
.toBe(true) | ||
|
||
// Index file should be untouched | ||
expect(existsSync(`${typeOutputDirectory}/index.ts`)) | ||
.toBe(true) | ||
}); | ||
}); |
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,14 @@ | ||
import Joi from 'joi'; | ||
|
||
export const TestSchema = Joi.object({ | ||
name: Joi.string().optional(), | ||
propertyName1: Joi.boolean().required(), | ||
'yellow.flower': Joi.string() | ||
}) | ||
.meta({ className: 'TestSchema' }) | ||
.description('a test schema definition'); | ||
|
||
export const purple = (): void => { | ||
// eslint-disable-next-line no-console | ||
console.log('this is not a schema'); | ||
}; |
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,27 @@ | ||
import {existsSync, rmdirSync} from 'fs'; | ||
|
||
import {convertFromDirectory} from '../../index'; | ||
|
||
const typeOutputDirectory = './src/__tests__/noIndex/interfaces'; | ||
|
||
describe('Create interfaces from schema files but not index files', () => { | ||
beforeAll(() => { | ||
if (existsSync(typeOutputDirectory)) { | ||
rmdirSync(typeOutputDirectory, {recursive: true}); | ||
} | ||
}); | ||
|
||
test('generates interfaces but no index files', async () => { | ||
const result = await convertFromDirectory({ | ||
schemaDirectory: './src/__tests__/noIndex/schemas', | ||
omitIndexFiles: true, | ||
typeOutputDirectory | ||
}); | ||
|
||
expect(result) | ||
.toBe(true); | ||
|
||
expect(existsSync(`${typeOutputDirectory}/index.ts`)) | ||
.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import Joi from 'joi'; | ||
|
||
export const BarSchema = Joi.object({ | ||
id: Joi.number().required().description('Id').example(1) | ||
}).meta({ className: 'Bar' }); | ||
|
||
export const FooSchema = Joi.object({ | ||
id: Joi.number().required().description('Id').example(1), | ||
bar: BarSchema.required().description('Bar') | ||
}).meta({ className: 'Foo' }); |
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,14 @@ | ||
import Joi from 'joi'; | ||
|
||
export const TestSchema = Joi.object({ | ||
name: Joi.string().optional(), | ||
propertyName1: Joi.boolean().required(), | ||
'yellow.flower': Joi.string() | ||
}) | ||
.meta({ className: 'TestSchema' }) | ||
.description('a test schema definition'); | ||
|
||
export const purple = (): void => { | ||
// eslint-disable-next-line no-console | ||
console.log('this is not a schema'); | ||
}; |
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,4 @@ | ||
export const red = (): void => { | ||
// eslint-disable-next-line no-console | ||
console.log('this is not a schema'); | ||
}; |
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