Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/marionebl/ts-transform-json-schema
Generate inline JSON schema from TypeScript types
https://github.com/marionebl/ts-transform-json-schema
Last synced: about 2 months ago
JSON representation
Generate inline JSON schema from TypeScript types
- Host: GitHub
- URL: https://github.com/marionebl/ts-transform-json-schema
- Owner: marionebl
- License: mit
- Created: 2018-09-24T22:31:39.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2023-01-04T21:42:37.000Z (almost 2 years ago)
- Last Synced: 2024-04-27T07:33:46.226Z (8 months ago)
- Language: TypeScript
- Size: 499 KB
- Stars: 26
- Watchers: 3
- Forks: 2
- Open Issues: 13
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
- awesome-typescript-ecosystem - ts-transform-json-schema - Generate inline JSON schema from TypeScript types (Transformers / General transformers)
README
# ts-transform-json-schema
* 🌳 Generate inline JSON schema from TypeScript types
## Example
### In
```ts
import * as JsonSchema from "ts-transform-json-schema";export interface SomeInterface {
a: string;
b: number;
c?: boolean;
}export const schema = JsonSchema.fromType({
additionalProperties: false
});
``````js
// tsconfig.json
{
"compilerOptions": {
"target": "es2015",
"plugins": [
{
"transform": "ts-transform-json-schema",
"type": "program"
}
]
}
}
```### Out
```ts
import * as JsonSchema from "ts-transform-json-schema";
export const schema = {
additionalProperties: false,
type: "object",
properties: {
a: { type: "string" },
b: { type: "number" },
c: { type: "boolean" }
},
$schema: "http://json-schema.org/draft-07/schema#"
};
```## Installation
```sh
npm install ts-transform-json-schema ttypescript --save-dev
```## Usage
```js
// tsconfig.json
{
"compilerOptions": {
"target": "es2015",
"plugins": [
{
"transform": "ts-transform-json-schema",
"type": "program"
}
]
}
}
```See [TTypeScript](https://github.com/cevek/ttypescript#how-to-use) for docs about integration with other toolchains.
---
See [./example](./example) for a basic setup based on [TTypeScript](https://github.com/cevek/ttypescript)
## License
MIT