@himenon/jsonschema2ts
TypeScript icon, indicating that this package has built-in type declarations

0.1.1 • Public • Published

@himenon/jsonschema2ts

Output TypeScript type definition from jsonschema.

Usage

generateFromJsonSchema

import { generateFromJsonSchema } from "@himenon/jsonschema2ts";

const jsonSchema = {}; // your json schema
const code = generateFromJsonSchema(jsonSchema); // or yaml

generateFromFile

import { generateFromJsonSchema } from "@himenon/jsonschema2ts";

const code = generateFromJsonSchema("your/file/path.json"); // or yaml

Example

Only local reference

JSON Input

Output

export type LocalReferenceString = string;
export type StringType = string;
export type StringHasEnumType = "a" | "A" | "b" | "B" | "あ" | "ア" | "い" | "イ" | "漢" | "字";
export type NumberType = number;
export type BooleanType = boolean;
export type ArrayType = string[];
export type OneOfType = string | number | boolean;
export type AllOfType = string & number & boolean;
export interface ObjectType {
  stringType: string;
  numberType?: number;
  booleanType: boolean;
  arrayType?: string[];
}
export type RefToDefinitionString = LocalReferenceString;
export type RefToPropertyString = StringType;

Use Remote reference

JSON Input

export interface Book {
  title?: string;
}
export type Books = Book[];
export namespace Params {
  export type B = string;
  export interface A {
    B?: B;
  }
}
export type A = Params.A;

LICENCE

@himenon-node-lib-template・MIT

Package Sidebar

Install

npm i @himenon/jsonschema2ts

Weekly Downloads

1

Version

0.1.1

License

MIT

Unpacked Size

136 kB

Total Files

112

Last publish

Collaborators

  • himenoglyph