Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

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

Awesome Lists containing this project

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