-
-
Notifications
You must be signed in to change notification settings - Fork 184
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: merge branch master into next
- Loading branch information
Showing
42 changed files
with
793 additions
and
319 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
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
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
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,17 @@ | ||
# TypeScript Map Types | ||
|
||
A basic example showing the use of `mapType` options. | ||
|
||
## How to run this example | ||
|
||
Run this example using: | ||
|
||
```sh | ||
npm i && npm run start | ||
``` | ||
|
||
If you are on Windows, use the `start:windows` script instead: | ||
|
||
```sh | ||
npm i && npm run start:windows | ||
``` |
43 changes: 43 additions & 0 deletions
43
examples/typescript-change-map-type/__snapshots__/index.spec.ts.snap
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 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`Should be able to render correct map type based on options and should log expected output to console 1`] = ` | ||
"// Generator output as indexedObject | ||
class Root { | ||
private _person?: { [name: string]: any }; | ||
constructor(input: { | ||
person?: { [name: string]: any }, | ||
}) { | ||
this._person = input.person; | ||
} | ||
get person(): { [name: string]: any } | undefined { return this._person; } | ||
set person(person: { [name: string]: any } | undefined) { this._person = person; } | ||
} | ||
// Generator output as Map | ||
class Root { | ||
private _person?: Map<string, any>; | ||
constructor(input: { | ||
person?: Map<string, any>, | ||
}) { | ||
this._person = input.person; | ||
} | ||
get person(): Map<string, any> | undefined { return this._person; } | ||
set person(person: Map<string, any> | undefined) { this._person = person; } | ||
} | ||
// Generator output as Record | ||
class Root { | ||
private _person?: Record<string, any>; | ||
constructor(input: { | ||
person?: Record<string, any>, | ||
}) { | ||
this._person = input.person; | ||
} | ||
get person(): Record<string, any> | undefined { return this._person; } | ||
set person(person: Record<string, any> | undefined) { this._person = person; } | ||
}" | ||
`; |
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,15 @@ | ||
const spy = jest.spyOn(global.console, 'log').mockImplementation(() => { | ||
return; | ||
}); | ||
import { generate } from './index'; | ||
|
||
describe('Should be able to render correct map type based on options', () => { | ||
afterAll(() => { | ||
jest.restoreAllMocks(); | ||
}); | ||
test('and should log expected output to console', async (): Promise<void> => { | ||
await generate(); | ||
expect(spy.mock.calls.length).toEqual(6); | ||
expect(spy.mock.calls.join('\n')).toMatchSnapshot(); | ||
}); | ||
}); |
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,50 @@ | ||
import { TypeScriptGenerator } from '../../src'; | ||
|
||
const generatorIndexedObject = new TypeScriptGenerator({ | ||
mapType: 'indexedObject' | ||
}); | ||
const generatorMap = new TypeScriptGenerator({ mapType: 'map' }); | ||
const generatorRecord = new TypeScriptGenerator({ mapType: 'record' }); | ||
|
||
const jsonSchemaDraft7 = { | ||
$schema: 'http://json-schema.org/draft-07/schema#', | ||
type: 'object', | ||
additionalProperties: false, | ||
properties: { | ||
person: { | ||
type: 'object', | ||
personName: { type: 'string' }, | ||
email: { | ||
type: 'string', | ||
format: 'email' | ||
}, | ||
isStudent: { type: 'boolean' }, | ||
age: { type: 'number' } | ||
} | ||
} | ||
}; | ||
|
||
export async function generate(): Promise<void> { | ||
console.log('// Generator output as indexedObject'); | ||
const modelsIndexedObject = | ||
await generatorIndexedObject.generate(jsonSchemaDraft7); | ||
for (const model of modelsIndexedObject) { | ||
console.log(model.result); | ||
} | ||
|
||
console.log('// Generator output as Map'); | ||
const modelsMap = await generatorMap.generate(jsonSchemaDraft7); | ||
for (const model of modelsMap) { | ||
console.log(model.result); | ||
} | ||
|
||
console.log('// Generator output as Record'); | ||
const modelsRecord = await generatorRecord.generate(jsonSchemaDraft7); | ||
for (const model of modelsRecord) { | ||
console.log(model.result); | ||
} | ||
} | ||
|
||
if (require.main === module) { | ||
generate(); | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,12 @@ | ||
{ | ||
"config": { | ||
"example_name": "typescript-change-map-type" | ||
}, | ||
"scripts": { | ||
"install": "cd ../.. && npm i", | ||
"start": "../../node_modules/.bin/ts-node --cwd ../../ ./examples/$npm_package_config_example_name/index.ts", | ||
"start:windows": "..\\..\\node_modules\\.bin\\ts-node --cwd ..\\..\\ .\\examples\\%npm_package_config_example_name%\\index.ts", | ||
"test": "../../node_modules/.bin/jest --config=../../jest.config.js ./examples/$npm_package_config_example_name/index.spec.ts", | ||
"test:windows": "..\\..\\node_modules\\.bin\\jest --config=..\\..\\jest.config.js examples/%npm_package_config_example_name%/index.spec.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
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
Oops, something went wrong.