json-schema-to-typescript

  • Version 10.1.5
  • Published
  • 200 kB
  • 15 dependencies
  • MIT license

Install

npm i json-schema-to-typescript
yarn add json-schema-to-typescript
pnpm add json-schema-to-typescript

Overview

compile json schema to typescript typings

Index

Variables

variable DEFAULT_OPTIONS

const DEFAULT_OPTIONS: Options;

    Functions

    function compile

    compile: (
    schema: any,
    name: string,
    options?: Partial<Options>
    ) => Promise<string>;

      function compileFromFile

      compileFromFile: (
      filename: string,
      options?: Partial<Options>
      ) => Promise<string>;

        Classes

        class ValidationError

        class ValidationError extends Error {}

          Interfaces

          interface CustomTypeJSONSchema

          interface CustomTypeJSONSchema extends NormalizedJSONSchema {}

            property tsType

            tsType: string;

              interface EnumJSONSchema

              interface EnumJSONSchema extends NormalizedJSONSchema {}

                property enum

                enum: any[];

                  interface JSONSchema

                  interface JSONSchema extends JSONSchema4 {}

                    property tsEnumNames

                    tsEnumNames?: string[];
                    • schema extension to support numeric enums

                    property tsType

                    tsType?: string;
                    • schema extension to support custom types

                    interface NamedEnumJSONSchema

                    interface NamedEnumJSONSchema extends NormalizedJSONSchema {}

                      property tsEnumNames

                      tsEnumNames: string[];

                        interface Options

                        interface Options {}

                          property $refOptions

                          $refOptions: $RefOptions;
                          • [$RefParser](https://github.com/BigstickCarpet/json-schema-ref-parser) Options, used when resolving $refs

                          property bannerComment

                          bannerComment: string;
                          • Disclaimer comment prepended to the top of each generated file.

                          property cwd

                          cwd: string;
                          • Root directory for resolving [$ref](https://tools.ietf.org/id/draft-pbryan-zyp-json-ref-03.html)s.

                          property declareExternallyReferenced

                          declareExternallyReferenced: boolean;
                          • Declare external schemas referenced via $ref?

                          property enableConstEnums

                          enableConstEnums: boolean;
                          • Prepend enums with [const](https://www.typescriptlang.org/docs/handbook/enums.html#computed-and-constant-members)?

                          property format

                          format: boolean;
                          • Format code? Set this to false to improve performance.

                          property ignoreMinAndMaxItems

                          ignoreMinAndMaxItems: boolean;
                          • Ignore maxItems and minItems for array types, preventing tuples being generated.

                          property strictIndexSignatures

                          strictIndexSignatures: boolean;
                          • Append all index signatures with | undefined so that they are strictly typed.

                            This is required to be compatible with strictNullChecks.

                          property style

                          style: PrettierOptions;
                          • A [Prettier](https://prettier.io/docs/en/options.html) configuration.

                          property unknownAny

                          unknownAny: boolean;
                          • Generate unknown type instead of any

                          property unreachableDefinitions

                          unreachableDefinitions: boolean;
                          • Generate code for definitions that aren't referenced by the schema?

                          Namespaces

                          namespace fast-diff

                          module 'fast-diff' {}

                            variable DELETE

                            const DELETE: number;

                              variable EQUAL

                              const EQUAL: number;

                                variable INSERT

                                const INSERT: number;

                                  function diff

                                  diff: typeof diff;

                                    type DeleteEdit

                                    type DeleteEdit = [-1, string];

                                      type Edit

                                      type Edit = DeleteEdit | EqualEdit | InsertEdit;

                                        type EqualEdit

                                        type EqualEdit = [0, string];

                                          type InsertEdit

                                          type InsertEdit = [1, string];

                                            namespace json-schema-ref-parser

                                            module 'json-schema-ref-parser' {}

                                              class $RefParser

                                              class $RefParser {}
                                              • This is the default export of JSON Schema $Ref Parser. You can creates instances of this class using new $RefParser(), or you can just call its static methods.

                                                See https://github.com/BigstickCarpet/json-schema-ref-parser/blob/master/docs/ref-parser.md

                                              property $refs

                                              $refs: $Refs;
                                              • The $refs property is a $Refs object, which lets you access all of the externally-referenced files in the schema, as well as easily get and set specific values in the schema using JSON pointers.

                                                This is the same value that is passed to the callback function (or Promise) when calling the resolve method.

                                                See https://github.com/BigstickCarpet/json-schema-ref-parser/blob/master/docs/ref-parser.md#refs

                                              property schema

                                              schema: any;
                                              • The schema property is the parsed/bundled/dereferenced JSON Schema object. This is the same value that is passed to the callback function (or Promise) when calling the parse, bundle, or dereference methods.

                                                See https://github.com/BigstickCarpet/json-schema-ref-parser/blob/master/docs/ref-parser.md#schema

                                              method bundle

                                              bundle: (
                                              schema: string | JSONSchema4,
                                              options?: Options,
                                              callback?: (err: Error | null, schema: JSONSchema4 | null) => any
                                              ) => Promise<JSONSchema4>;
                                              • Bundles all referenced files/URLs into a single schema that only has internal $ref pointers. This lets you split-up your schema however you want while you're building it, but easily combine all those files together when it's time to package or distribute the schema to other people. The resulting schema size will be small, since it will still contain internal JSON references rather than being fully-dereferenced.

                                                This also eliminates the risk of circular references, so the schema can be safely serialized using JSON.stringify().

                                                See https://github.com/BigstickCarpet/json-schema-ref-parser/blob/master/docs/ref-parser.md#bundleschema-options-callback

                                                Parameter schema

                                                A JSON Schema object, or the file path or URL of a JSON Schema file. See the parse method for more info.

                                                Parameter options

                                                (optional)

                                                Parameter callback

                                                (optional) A callback that will receive the bundled schema object

                                              method dereference

                                              dereference: {
                                              (
                                              path: string,
                                              schema: string | JSONSchema4,
                                              options?: Options,
                                              callback?: (err: Error | null, schema: JSONSchema4 | null) => any
                                              ): Promise<JSONSchema4>;
                                              (
                                              path: string,
                                              options?: $RefParser.Options,
                                              callback?: (err: Error, schema: any) => any
                                              ): Promise<any>;
                                              (
                                              schema: any,
                                              options?: $RefParser.Options,
                                              callback?: (err: Error, schema: any) => any
                                              ): Promise<any>;
                                              };
                                              • Dereferences all $ref pointers in the JSON Schema, replacing each reference with its resolved value. This results in a schema object that does not contain any $ref pointers. Instead, it's a normal JavaScript object tree that can easily be crawled and used just like any other JavaScript object. This is great for programmatic usage, especially when using tools that don't understand JSON references.

                                                The dereference method maintains object reference equality, meaning that all $ref pointers that point to the same object will be replaced with references to the same object. Again, this is great for programmatic usage, but it does introduce the risk of circular references, so be careful if you intend to serialize the schema using JSON.stringify(). Consider using the bundle method instead, which does not create circular references.

                                                See https://github.com/BigstickCarpet/json-schema-ref-parser/blob/master/docs/ref-parser.md#dereferenceschema-options-callback

                                                Parameter schema

                                                A JSON Schema object, or the file path or URL of a JSON Schema file. See the parse method for more info.

                                                Parameter options

                                                (optional)

                                                Parameter callback

                                                (optional) A callback that will receive the dereferenced schema object

                                              method parse

                                              parse: (
                                              schema: string | JSONSchema4,
                                              options?: Options,
                                              callback?: (err: Error | null, schema: JSONSchema4 | null) => any
                                              ) => Promise<JSONSchema4>;
                                              • *This method is used internally by other methods, such as bundle and dereference. You probably won't need to call this method yourself.*

                                                Parses the given JSON Schema file (in JSON or YAML format), and returns it as a JavaScript object. This method does not resolve $ref pointers or dereference anything. It simply parses one file and returns it.

                                                See https://github.com/BigstickCarpet/json-schema-ref-parser/blob/master/docs/ref-parser.md#parseschema-options-callback

                                                Parameter schema

                                                A JSON Schema object, or the file path or URL of a JSON Schema file. The path can be absolute or relative. In Node, the path is relative to process.cwd(). In the browser, it's relative to the URL of the page.

                                                Parameter options

                                                (optional)

                                                Parameter callback

                                                (optional) A callback that will receive the parsed schema object, or an error

                                              method resolve

                                              resolve: (
                                              schema: string | JSONSchema4,
                                              options?: Options,
                                              callback?: (err: Error | null, $refs: $Refs | null) => any
                                              ) => Promise<$Refs>;
                                              • *This method is used internally by other methods, such as bundle and dereference. You probably won't need to call this method yourself.*

                                                Resolves all JSON references ($ref pointers) in the given JSON Schema file. If it references any other files/URLs, then they will be downloaded and resolved as well. This method **does not** dereference anything. It simply gives you a $Refs object, which is a map of all the resolved references and their values.

                                                See https://github.com/BigstickCarpet/json-schema-ref-parser/blob/master/docs/ref-parser.md#resolveschema-options-callback

                                                Parameter schema

                                                A JSON Schema object, or the file path or URL of a JSON Schema file. See the parse method for more info.

                                                Parameter options

                                                (optional)

                                                Parameter callback

                                                (optional) A callback that will receive a $Refs object

                                              type Options

                                              type Options = object & {
                                              /**
                                              * The `parse` options determine how different types of files will be parsed.
                                              *
                                              * JSON Schema `$Ref` Parser comes with built-in JSON, YAML, plain-text, and binary parsers, any of which you can configure or disable. You can also add your own custom parsers if you want.
                                              */
                                              parse?: {
                                              json?: ParserOptions | boolean;
                                              yaml?: ParserOptions | boolean;
                                              text?: (ParserOptions & { encoding?: string }) | boolean;
                                              };
                                              /**
                                              * The `resolve` options control how JSON Schema $Ref Parser will resolve file paths and URLs, and how those files will be read/downloaded.
                                              *
                                              * JSON Schema `$Ref` Parser comes with built-in support for HTTP and HTTPS, as well as support for local files (when running in Node.js). You can configure or disable either of these built-in resolvers. You can also add your own custom resolvers if you want.
                                              */
                                              resolve?: {
                                              /**
                                              * Determines whether external $ref pointers will be resolved. If this option is disabled, then external `$ref` pointers will simply be ignored.
                                              */
                                              external?: boolean;
                                              file?: ResolverOptions | boolean;
                                              http?: HTTPResolverOptions | boolean;
                                              };
                                              /**
                                              * The `dereference` options control how JSON Schema `$Ref` Parser will dereference `$ref` pointers within the JSON schema.
                                              */
                                              dereference?: {
                                              /**
                                              * Determines whether circular `$ref` pointers are handled.
                                              *
                                              * If set to `false`, then a `ReferenceError` will be thrown if the schema contains any circular references.
                                              *
                                              * If set to `"ignore"`, then circular references will simply be ignored. No error will be thrown, but the `$Refs.circular` property will still be set to `true`.
                                              */
                                              circular?: boolean | 'ignore';
                                              };
                                              };
                                              • See https://github.com/BigstickCarpet/json-schema-ref-parser/blob/master/docs/options.md

                                              namespace json-stringify-safe

                                              module 'json-stringify-safe' {}

                                                function stringify

                                                stringify: (
                                                value: any,
                                                replacer?: (key: string, value: any) => any,
                                                space?: string | number,
                                                cycleReplacer?: (key: string, value: any) => string
                                                ) => string | undefined;

                                                  Package Files (5)

                                                  Dependencies (15)

                                                  Dev Dependencies (21)

                                                  Peer Dependencies (0)

                                                  No peer dependencies.

                                                  Badge

                                                  To add a badge like this onejsDocs.io badgeto your package's README, use the codes available below.

                                                  You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/json-schema-to-typescript.

                                                  • Markdown
                                                    [![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/json-schema-to-typescript)
                                                  • HTML
                                                    <a href="https://www.jsdocs.io/package/json-schema-to-typescript"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>