Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/zcong1993/ts-mongoose-code-generator
generate ts model types from mongoose schema
https://github.com/zcong1993/ts-mongoose-code-generator
code-generator model mongoose schema typescript
Last synced: about 23 hours ago
JSON representation
generate ts model types from mongoose schema
- Host: GitHub
- URL: https://github.com/zcong1993/ts-mongoose-code-generator
- Owner: zcong1993
- License: mit
- Created: 2019-09-06T09:29:54.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2022-06-23T11:07:34.000Z (over 2 years ago)
- Last Synced: 2023-02-28T14:37:12.252Z (over 1 year ago)
- Topics: code-generator, model, mongoose, schema, typescript
- Language: TypeScript
- Homepage:
- Size: 714 KB
- Stars: 2
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# ts-mongoose-code-generator
[![NPM version](https://img.shields.io/npm/v/@zcong/ts-mongoose-code-generator.svg?style=flat)](https://npmjs.com/package/@zcong/ts-mongoose-code-generator) [![NPM downloads](https://img.shields.io/npm/dm/@zcong/ts-mongoose-code-generator.svg?style=flat)](https://npmjs.com/package/@zcong/ts-mongoose-code-generator) [![CircleCI](https://circleci.com/gh/zcong1993/ts-mongoose-code-generator/tree/master.svg?style=shield)](https://circleci.com/gh/zcong1993/ts-mongoose-code-generator/tree/master) [![codecov](https://codecov.io/gh/zcong1993/ts-mongoose-code-generator/branch/master/graph/badge.svg)](https://codecov.io/gh/zcong1993/ts-mongoose-code-generator)
> generate ts model types from mongoose schema
## Install
```bash
$ yarn add @zcong/ts-mongoose-code-generator
```## Usage
### modelGenerator
```ts
import { ModelGenerator } from '@zcong/ts-mongoose-code-generator'const testSchema = new Schema({
name: String,
age: {
type: Number
},
requiredName: {
type: String,
required: true
}
}// useInterface: use class or interface as type declaration
const dtoGen = new ModelGenerator({
filename: `${__dirname}/modelGen.ts`,
useInterface: true, // use interface type or class type
arrayStyle: 'squareBrackets', // arrayStyle squareBrackets(T[]) or generic(Array)
stringEnumUseUnionType: true, // if set true, String type with enum field ['test1', 'test2'] will be type `'test1' | 'test2'`
})
dtoGen.generateModelBySchema(testSchema, 'Test')
dtoGen.getFile().saveSync() // save generated code as file
dtoGen.getGeneratedCode() // get generated code content// export interface TestModel {
// name?: string;
// age?: number;
// requiredName: string;
// }
```## License
MIT © zcong1993