@rxap/json-schema-to-typescript
Version:
Generate TypeScript interfaces from JSON Schema definitions. It allows you to programmatically create and manipulate TypeScript interface definitions based on JSON schema inputs. The package provides utilities to convert JSON schema to TypeScript interfac
38 lines (37 loc) • 1.61 kB
TypeScript
import type { JSONSchema, Options } from '@apidevtools/json-schema-ref-parser';
import { Project, SourceFile, WriterFunction } from 'ts-morph';
export interface TypescriptInterfaceGeneratorOptions extends Options {
suffix?: string;
basePath?: string;
addImports?: boolean;
/**
* false - if a schema property has an enum property a typescript enum will be created
* true - else a typescript string tuple will be used
*/
useStringTuple?: boolean;
}
export declare class TypescriptInterfaceGenerator {
private readonly schema;
private readonly options;
private readonly project;
static isRequired(schema: JSONSchema, key: string): boolean;
static coercePropertyKey(key: string): string;
static unionType(array: Array<string | WriterFunction>): WriterFunction | string;
static intersectionType(array: Array<string | WriterFunction>): WriterFunction | string;
constructor(schema: JSONSchema, options?: TypescriptInterfaceGeneratorOptions, project?: Project | null);
private bundledSchema;
static bundleSchema<T extends JSONSchema>(schema: T, options?: TypescriptInterfaceGeneratorOptions): Promise<T>;
build(name: string): Promise<SourceFile>;
buildSync(name: string, bundledSchema?: JSONSchema | null): SourceFile;
private addType;
private addTypeAlias;
private addInterface;
private buildPropertySignatureStructure;
private recordType;
private propertyTypeWriteFunction;
private getFileName;
private buildName;
private resolveRefName;
private resolveRef;
bundleSchema(): Promise<void>;
}