Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sinha-sahil/type-crafter
A tool to generate types from a yaml schema for any language
https://github.com/sinha-sahil/type-crafter
generate generator javascript types typescript yaml
Last synced: 2 months ago
JSON representation
A tool to generate types from a yaml schema for any language
- Host: GitHub
- URL: https://github.com/sinha-sahil/type-crafter
- Owner: sinha-sahil
- Created: 2023-10-10T20:36:48.000Z (over 1 year ago)
- Default Branch: release
- Last Pushed: 2024-05-13T19:57:24.000Z (8 months ago)
- Last Synced: 2024-10-29T00:30:40.465Z (3 months ago)
- Topics: generate, generator, javascript, types, typescript, yaml
- Language: TypeScript
- Homepage:
- Size: 139 KB
- Stars: 1
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
Awesome Lists containing this project
README
# Type Crafter
TypeCrafter is a CLI tool for generating types from a YAML types specification for any language.
The tool is heavily inspired by [OpenAPI Generator](https://openapi-generator.tech/) and
aims to provide similar functionality for generating types with a simple YAML specification & more flexibility.## Installation
```bash
npm i -g type-crafter
```## Usage
```bash
type-crafter generate
```### Example
```bash
type-crafter generate typescript types.yaml ./types
```Example input specification file can be found [here](https://github.com/sinha-sahil/type-crafter/blob/release/examples/input.yaml#L1)
## Input Specification
The input specification is a YAML file that contains the types specification.
Refer the following sample specification for the structure:```yaml
info:
version: 0.0.0
title: Title of your specification
types:
SampleType:
type: object
properties:
name:
type: string
groupedTypes:
SampleGroupedType:
type: object
properties:
name:
type: string
```The input specification yaml file must be of following syntax:
- `info` - The information about the specification. Specifying the version and title of your spec. **This is required.**
- `types` - These are types that will be generated in flat structure.
- `groupedTypes` - These are types that will be generated and grouped in a folder.**Note: Passing types or groupedTypes is up to your expected results. A valid spec file can contain either types or groupedTypes or both.**
The syntax for writing different types can be referred from the [OpenAPI Data Types Guide](https://swagger.io/docs/specification/data-models/data-types/).
## Supported languages
- [✔️] TypeScript
- More languages will be added soon.## Contributing & Extending
### Adding support for a new language
TypeCrafter uses Handlebars to template syntax for different languages.
To add support for a new language, you need to create a new folder in `src/templates` directory.
The folder name will be the name of the language.
The folder must implement following files:- `index.ts` - The main file that will be exporting the [generator config](https://github.com/sinha-sahil/type-crafter/blob/release/src/types/index.ts#L5).
- `object-syntax.hbs` - This Handlebars template file that will be used to generate the object syntax.
- `type-file-syntax.hbs` - This Handlebars template file that will be used to generate the syntax for file which contains the generated types & its imports.
- `exporter-module-syntax.hbs` - This Handlebars template file that will be used to generate the syntax for the module that exports the generated types.## Development
To start developing type-crafter, you need to run following commands:
```bash
pnpm i
pnpm run dev
```