GithubHelp home page GithubHelp logo

bcherny / json-schema-to-typescript Goto Github PK

View Code? Open in Web Editor NEW
2.8K 19.0 373.0 30.13 MB

Compile JSONSchema to TypeScript type declarations

Home Page: https://bcherny.github.io/json-schema-to-typescript-browser/

License: MIT License

TypeScript 99.88% JavaScript 0.12%
typescript json-schema

json-schema-to-typescript's Introduction

json-schema-to-typescript Build Status npm mit node

Compile json schema to typescript typings

Example

Input:

{
  "title": "Example Schema",
  "type": "object",
  "properties": {
    "firstName": {
      "type": "string"
    },
    "lastName": {
      "type": "string"
    },
    "age": {
      "description": "Age in years",
      "type": "integer",
      "minimum": 0
    },
    "hairColor": {
      "enum": ["black", "brown", "blue"],
      "type": "string"
    }
  },
  "additionalProperties": false,
  "required": ["firstName", "lastName"]
}

Output:

export interface ExampleSchema {
  firstName: string;
  lastName: string;
  /**
   * Age in years
   */
  age?: number;
  hairColor?: "black" | "brown" | "blue";
}

Installation

# Using Yarn:
yarn add json-schema-to-typescript

# Or, using NPM:
npm install json-schema-to-typescript --save

Usage

import { compile, compileFromFile } from 'json-schema-to-typescript'

// compile from file
compileFromFile('foo.json')
  .then(ts => fs.writeFileSync('foo.d.ts', ts))

// or, compile a JS object
let mySchema = {
  properties: [...]
}
compile(mySchema, 'MySchema')
  .then(ts => ...)

See server demo and browser demo for full examples.

Options

compileFromFile and compile accept options as their last argument (all keys are optional):

key type default description
additionalProperties boolean true Default value for additionalProperties, when it is not explicitly set
bannerComment string "/* eslint-disable */\n/**\n* This file was automatically generated by json-schema-to-typescript.\n* DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file,\n* and run json-schema-to-typescript to regenerate this file.\n*/" Disclaimer comment prepended to the top of each generated file
cwd string process.cwd() Root directory for resolving $refs
declareExternallyReferenced boolean true Declare external schemas referenced via $ref?
enableConstEnums boolean true Prepend enums with const?
format boolean true Format code? Set this to false to improve performance.
ignoreMinAndMaxItems boolean false Ignore maxItems and minItems for array types, preventing tuples being generated.
maxItems number 20 Maximum number of unioned tuples to emit when representing bounded-size array types, before falling back to emitting unbounded arrays. Increase this to improve precision of emitted types, decrease it to improve performance, or set it to -1 to ignore maxItems.
strictIndexSignatures boolean false Append all index signatures with | undefined so that they are strictly typed.
style object { bracketSpacing: false, printWidth: 120, semi: true, singleQuote: false, tabWidth: 2, trailingComma: 'none', useTabs: false } A Prettier configuration
unknownAny boolean true Use unknown instead of any where possible
unreachableDefinitions boolean false Generates code for $defs that aren't referenced by the schema.
$refOptions object {} $RefParser Options, used when resolving $refs

CLI

A CLI utility is provided with this package.

cat foo.json | json2ts > foo.d.ts
# or
json2ts foo.json > foo.d.ts
# or
json2ts foo.json foo.d.ts
# or
json2ts --input foo.json --output foo.d.ts
# or
json2ts -i foo.json -o foo.d.ts
# or (quote globs so that your shell doesn't expand them)
json2ts -i 'schemas/**/*.json'
# or
json2ts -i schemas/ -o types/

You can pass any of the options described above (including style options) as CLI flags. Boolean values can be set to false using the no- prefix.

# generate code for definitions that aren't referenced
json2ts -i foo.json -o foo.d.ts --unreachableDefinitions
# use single quotes and disable trailing semicolons
json2ts -i foo.json -o foo.d.ts --style.singleQuote --no-style.semi

Tests

npm test

Features

  • title => interface
  • Primitive types:
    • array
    • homogeneous array
    • boolean
    • integer
    • number
    • null
    • object
    • string
    • homogeneous enum
    • heterogeneous enum
  • Non/extensible interfaces
  • Custom JSON-schema extensions
  • Nested properties
  • Schema definitions
  • Schema references
  • Local (filesystem) schema references
  • External (network) schema references
  • Add support for running in browser
  • default interface name
  • infer unnamed interface name from filename
  • deprecated
  • allOf ("intersection")
  • anyOf ("union")
  • oneOf (treated like anyOf)
  • maxItems (eg)
  • minItems (eg)
  • additionalProperties of type
  • patternProperties (partial support)
  • extends
  • required properties on objects (eg)
  • validateRequired (eg)
  • literal objects in enum (eg)
  • referencing schema by id (eg)
  • custom typescript types via tsType

Custom schema properties:

  • tsType: Overrides the type that's generated from the schema. Useful for forcing a type to any or when using non-standard JSON schema extensions (eg).
  • tsEnumNames: Overrides the names used for the elements in an enum. Can also be used to create string enums (eg).

Not expressible in TypeScript:

FAQ

JSON-Schema-to-TypeScript is crashing on my giant file. What can I do?

Prettier is known to run slowly on really big files. To skip formatting and improve performance, set the format option to false.

Further Reading

Who uses JSON-Schema-to-TypeScript?

json-schema-to-typescript's People

Contributors

bcherny avatar bradzacher avatar cherryblossom000 avatar darcyparker avatar devoto13 avatar dl748 avatar g-rath avatar gmathieu avatar henkesn avatar ikorolev93 avatar iwan-aucamp-cs avatar jefbarn avatar joanrieu avatar jochendiekenbrock avatar johnbillion avatar karel-kroeze avatar liooo avatar monolithed avatar notaphplover avatar ohana54 avatar qm3ster avatar queengooborg avatar s-weigand avatar simonsiefke avatar sokra avatar speedy37 avatar tlahav avatar travischong avatar victorandree avatar yairhalberstadt avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

json-schema-to-typescript's Issues

Need `postinstall` script in `package.json` to build `dist/index.js`

Now that dist/* files aren't included in distribution, downstream repos that depend on json-schema-to-typescript are failing with

>> Error: Cannot find module 'json-schema-to-typescript'

I think the cause is that https://github.com/bcherny/json-schema-to-typescript/blob/master/package.json#L5 refers to dist/index.js and this is not in the repo after npm install json-schema-to-typescript.

I speculate this can be resolved by adding postinstall script to your package.json like this: (See https://docs.npmjs.com/misc/scripts) (or something similar to this...)

{
  "scripts": {
    "postinstall": "./node_modules/.bin/gulp dist"
  }
}

title attribute used as type and does not resolve

I noticed that any property in a json schema which has a title does not get resolved. Instead, the title is used as a type.

Example:

    "users": {
      "type": "array",
      "title": "user id array",
      "description": "Array of authorized user ids.",
      "items": {
        "type": "string"
      }
    }

gets translated to:

users?: UserIdArray;

which leads to a undefined type UserIdArray. Is that behavior expected? How do I get json-schema-to-typescript to define the referenced types as well?

For now I created a workaround by removing || rule.title from line 168. This generates:

users?: string[];

Command line interface

It would be nice to provide simple command line application within the package. It could be almost equal to one inside example directory but allow to specify input and output file. What do you think about that?

Possible to perform batch compilation from CLI?

Hi,

Thanks for the great library, and sorry if this question has already been answered in the docs (I was not able to find anything as far as I know).

Is it possible to perform batch compilation? For example, with the following directory structure:

+- json_schema
  +-foo.json
  +-bar.json

is it possible to create the following output?

+- json_schema
  +-foo.json
  +-foo.d.ts
  +-bar.json
  +-bar.d.ts

Thanks again for all the great work on this project. It's very much appreciated.

Fail to resolve remote reference

When I try to generate typings from swagger schema(https://raw.githubusercontent.com/OAI/OpenAPI-Specification/master/schemas/v2.0/schema.json), following error reported:

ReferenceError: Unable to find referenced file "/some/file/path/http:/json-schema.org/draft-04/schema#/properties/title"                                                                                                                      
    at /Users/xxx/Projects/swagger-typings/node_modules/json-schema-to-typescript/dist/index.js:115:99                  
    at tryFn (/Users/xxx/Projects/swagger-typings/node_modules/json-schema-to-typescript/dist/index.js:288:16)
...

type of enums should not default to string

See https://github.com/bcherny/json-schema-to-typescript/blob/master/src/index.ts#L251.

As far as I understand the standard it is allowed to create a schema like { enum: [ false ] }. Currently an error is thrown if you use { enum: [ false ] }: TypeError: Enum was declared as a string type but found at least one non-string member.

E.g. given

{
  "$schema": "http://json-schema.org/draft-04/schema#",
  "type": "object",
  "properties": {
    "foo": {
      "enum": [ false ]
    }
  }
}

and

{
  "foo": false
}

is valid here: http://www.jsonschemavalidator.net/.

"understanding json schema" also says "You can use enum even without a type, to accept values of different types."


Okay, I see I can't even workaround this by using { type: 'boolean', enum: [ false ] }, because of https://github.com/bcherny/json-schema-to-typescript/blob/master/src/index.ts#L257: TypeError: Enum type must be string or integer; default is string if undefined.


It is also valid to just use false as a type in TypeScript. See this example:

interface Success<T> {
    success: true;  // type is `true`, not `boolean`
    value: T;
}

interface Failure {
    success: false;  // type is `false`, not `boolean`
    reason: string;
}

type Result<T> = Success<T> | Failure;

`null | string` is not a valid disjoint type

I made a mistake in part of the test case requested for #27.

anotherValue?: null | string;
is not valid.

Unions of other simple types are being handled nicely - thank you again for adding this capability. But I didn't realize until having tsc complain and then reading How to declare a type as nullable in TypeScript? (which coincidentally @bcherny submitted an answer) that the anotherValue?: null | string; is not valid typescript. After reading the answers to this stackoverflow question I realize that anytime there are disjoint types for a property that includes null, then null should be filtered from the list of types and the property should become optional (which in the example test case coincidentally was).

Would you agree this is a correct interpretation of how to translate a disjoint type with null in its list and transforming to a typescript interface? (If not, it's still a bug because null | string is not valid according to tsc. So I am open to other suggestions of how to handle disjoint types with null in it.)

BTW: I saw this deeper in the comments of the above stackoverflow question: microsoft/TypeScript#7140. So it looks like this is just a bug with tsc < 2.0.

Named enum for string type

How do I generate named enums for string types. My JSON Schema looks like below:

"status": {
      "enum": [
        "I",
        "A",
        "C"
      ],
      "tsEnumNames": [
        "InProgress",
        "ForApproval",
        "Complete"
      ]
    },

Should generate the following Typescript

  status: Status
....
export const enum Status {
   InProgress = "I"
   ForApproval = "A"
   Complete = "C"
}

Instead of the above, its generating the flags without quotes that results in TypeScript error. Can you please suggest, how can I generate the above typescript code?

Add setting to validate input schema before proceeding with compile

As a user I sometimes have invalid JSON schema and I would like a debugging option to tell me my schema is invalid so I don't waste time looking for issues in how JSON Schema is compiled to TS interface definition. As well, I want to be confident my JSON schema is valid before filing an issue.

A rough WIP is here: https://github.com/darcyparker/json-schema-to-typescript/tree/validateJSONSchema

An additional nice to have feature would be to log warnings about cases of not-expressible to typescript and suggest using decorators as mentioned here: #8

Types generated with full qualified schema.id url

Currently the schema.id is favored over the schema.title when generating the type name.

For instance,

{
  "id": "http://dummy.com/api/person",
  "title": "Person",
  "type": "object",
  "properties": {
    "firstName": {
      "type": "string"
    },
    "lastName": {
      "type": "string"
    }
  }
}

will generate

export interface HttpDummyComApiPerson {
  firstName?: string;
  lastName?: string;
  [k: string]: any;
}

Although it helps to avoid naming collisions, it's very awkward to have types named after URLs.

I would like to suggest one of the two possible improvements:

  • swap the id and title on index.ts:47
this.id = schema.title || schema.id || this.filePath.name || 'Interface1'

Which will favor the title over the id. The down side being that it may cause naming collisions.

  • favor the id, but generate a namespace

for id = "http://dummy.com/api/person"
we could have

namescape DummyComApi { // http protocol dropped
  export interface Person {
    firstName?: string;
    lastName?: string;
    [k: string]: any;
  }
}

Maximum call stack size exceeded

Try to compileFromFile this schema throws.

/Users/foo/webpack/node_modules/lodash/lodash.js:2591
    function baseClone(value, isDeep, isFull, customizer, key, object, stack) {
                      ^

RangeError: Maximum call stack size exceeded
    at baseClone (/Users/foo/webpack/node_modules/lodash/lodash.js:2591:23)
    at /Users/foo/webpack/node_modules/lodash/lodash.js:2644:34
    at arrayEach (/Users/foo/webpack/node_modules/lodash/lodash.js:520:11)
    at baseClone (/Users/foo/webpack/node_modules/lodash/lodash.js:2638:7)
    at baseMergeDeep (/Users/foo/webpack/node_modules/lodash/lodash.js:3627:24)
    at /Users/foo/webpack/node_modules/lodash/lodash.js:3562:11
    at arrayEach (/Users/foo/webpack/node_modules/lodash/lodash.js:520:11)
    at baseMerge (/Users/foo/webpack/node_modules/lodash/lodash.js:3555:7)
    at /Users/foo/webpack/node_modules/lodash/lodash.js:13254:7
    at Function.<anonymous> (/Users/foo/webpack/node_modules/lodash/lodash.js:4781:13)

The webpack schema is quite heavy. Perfect stress test to optimize ;) Note that you have to delete this enum because of #34 to get this working for now.

Invalid ouput

import * as jsonScheme from 'generate-schema';
import { compile } from 'json-schema-to-typescript';

let scheme = jsonScheme.json('x', {
	"x[0]": 1
});

let result = compile(scheme, undefined);

console.log(result)
export interface X {
      x[0]?: number; 
      [k: string]: any;
}

x[0] is not a valid name. What is expected:

export interface X {
      'x[0]'?: number; 
      [k: string]: any;
}

Provide the tsdoc/typedoc/jsdoc proper commentaries to generated interfaces based on schema title and/or schema description.

Currently the commentaries are based only on description.

Eg.
For schema:

{
  "title": "My Object",
  "description": "Some custom object",
  "type": "object",
  "properties": {
       "bar" : {
          "title": "Some property",
          "description": "Some property description",
          "type": "string"
       }
   }
}

We have:

/*
    Some custom object
  */
export interface MyObject {
  bar?: string; // Some property description
  [k: string]: any;
}

It will be nice to have:

/**
 * Some custom object.
 */
export interface MyObject {
 /**
   * Some property.
   * Some property description.
   */
  bar?: string;
  [k: string]: any;
}

Doesn't work under [email protected]

Latest release use some features that unsupported by [email protected] - ES6 default parameters for instance. So there is an error in attempt to run cli.js

.../.nvm/versions/node/v4.7.2/lib/node_modules/json-schema-to-typescript/dist/src/index.js:30
function compileFromFile(filename, options = exports.DEFAULT_OPTIONS) {
                                           ^

SyntaxError: Unexpected token =
    at exports.runInThisContext (vm.js:53:16)
    at Module._compile (module.js:373:25)
    at Object.Module._extensions..js (module.js:416:10)
    at Module.load (module.js:343:32)
    at Function.Module._load (module.js:300:12)
    at Module.require (module.js:353:17)

Error compiling schema with reserved words as keys

{
  "type": "object",
  "properties": {
    "definitions": {
      "$ref": "#/definitions/definitions"
    }
  },
  "definitions": {
    "definitions": {
      "$ref": "#/definitions/schema"
    },
    "schema": {
      "type": "object",
      "properties": {
        "additionalProperties": {
          "anyOf": [
            {
              "$ref": "#/definitions/schema"
            }
          ]
        }
      }
    }
  }

Add test case for `type` = `simpleTypes[]`

When a type can be multiple simple types but not all types, the resulting interface is not correct.

See https://github.com/bcherny/json-schema-to-typescript/blob/master/dist/index.d.ts#L46
and https://spacetelescope.github.io/understanding-json-schema/reference/type.html

I observed this problem with a larger schema and created this simple test case to demonstrate:

export var schema = {
  "title": "Example Schema",
  "description": "My cool schema",
  "type": "object",
  "properties": {
    "value": {
      "type": ["number", "string"]
    },
    "anotherValue": {
      "type": ["null", "string"]
    }
  },
  "required": ["value"]
}

export var types = `/** My cool schema */
export interface ExampleSchema {
  value: number | string;
  anotherValue: null | string;
}`

I haven't had time to investigate a fix.... but could try if someone else isn't able to get to it before me.

Do not reset standard constructors

export class String extends TsType<void> {
  constructor() { super(undefined) }
  toString() {
    return 'string'
  }
}
export class Boolean extends TsType<void> {
  constructor() { super(undefined) }
  toString() {
    return 'boolean'
  }
}
export class Number extends TsType<void> {
  constructor() { super(undefined) }
  toString() {
    return 'number'
  }
}
export class Object extends TsType<void> {
  constructor() { super(undefined) }
  toString() {
    return 'Object'
  }
}

export class Array extends TsType<TsType<any>> {
  constructor(value: TsType<any> = new Any) { super(value) }
  toString(settings: Settings) {
    const type = this.value.toType(settings)
    return `${type.indexOf('|') > -1 || type.indexOf('&') > -1 ? `(${type})` : type}[]` // hacky
  }
}
/node_modules/json-schema-to-typescript/dist/TsTypes.js:3
    var extendStatics = Object.setPrototypeOf ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
                              ^

TypeError: Cannot read property 'setPrototypeOf' of undefined
....

/json-schema-to-typescript/dist_tests/src/TsTypes.js:2
Object.defineProperty(exports, "__esModule", { value: true });
^

ReferenceError: Object is not defined
    at Object.<anonymous> (/json-schema-to-typescript/dist_tests/src/TsTypes.js:2:1)
    at Module._compile (module.js:571:32)
    at Module._extensions..js (module.js:580:10)
    at extensions.(anonymous function) (/json-schema-to-typescript/node_modules/require-precompiled/index.js:16:3)

Why do you reset these standard constructors? And how do you build it?

npm release

Noticed the package version is much higher than npm release. Any chance for an npm update?
Can't install direct from github because of dist directory.
Thanks!

Why not parse?

Source JSON
My code

const converter = require('json-schema-to-typescript');
var fs = require('fs');
converter.compileFromFile('./vk-api-schema/objects.json')
    .then(function (interf) {
        fs.writeFile("./types/objects.d.ts", interf);
    });

Result:

export type Objects = any;

Support generics

Can you support generics? Like generating from this:

{
   "title": "TGenericNumber",
   "type": { "$ref": "#/definitions/iarg", "generics": ["number", "string"] },
   "definitions": {
      "iarg": {
         "title": "IArg<T, R>",
         "properties": {
            "key": { "type": "T" },
            "value": { "type": "R" }
         }
      }
   }
}

to this:

export interface IArg<T, R> { key: T, value: R };
export type TGeneric = IArg<number, string>;

Missing license

I just realized that this project has no Open Source library which make it not usable in legal terms.

The path param should be optional

import { compile } from 'json-schema-to-typescript';
compile(scheme); // error
import { compile } from 'json-schema-to-typescript';
compile(scheme, undefined); // ok
export declare function compile(schema: JSONSchema, path: string | undefined, settings?: Settings): string;

It's because the path param should be optional:

export declare function compile(schema: JSONSchema, path?: string, settings?: Settings): string;

I guess it's just a typo )

PS: could you export the JSONSchema interface?

typings to json?

Thanks for the great work here.

I'm also looking for the opposite of this library. A library that converts typings to json schema.

Do you know of such library exist?

Local $ref producing duplicate interfaces for definition when title is set

Schema using a local '$ref' to a definition in the same JSON document (have not tested against external file $ref's) is producing duplicate Interface statements causing creation of invalid .ts file. This seems to occur when the following conditions are met:

  • Definition has a title (in these cases the title seems to have no effect on interface name in definitions)
  • Definition requires a complex interface (not a standard basic type), such as an object with properties or a string with enum.

i.e. a definition such as the following, if referenced will result in a duplicate Interface in the ts output:

  "definitions": {
    "firstDefinition": {
      "title": "First Definition Title",
      "type": "object",
      "properties": {
        "name": {
          "type": "string"
        }
      }
    }
  }

I've attached a test schema and the resulting ts output to better demonstrate the problem. Can try and assist if suitable - I understand @bcherny may be currently working on improvements to the $ref handling #44.

localrefs.zip

`"type": [ "array" ]` is outputting invalid interface definition

If you extend https://github.com/bcherny/json-schema-to-typescript/blob/master/test/cases/array-of-type.ts like this:

export var schema = {
  "title": "Array of type",
  "type": "object",
  "properties": {
    "foo": {
      "items": {
        "type": "string"
      },
      "type": "array"
    },
    "times": {
      "items": {
        "type": "string",
        "format": "date-time"
      },
      "type": [ "array" ]
    }
  }
}

Then the output is this:

export interface ArrayOfType {
  foo?: string[];
  times?: array;
  [k: string]: any;
}

times?: array should be times?: Array<string> or alternatively times?: string[]

I think this is connected to disjoint types test case.

Documentation: Usage with gulp

This is how we use json-schema-to-typescript in gulp. Maybe helpful for others, could be added to the docs/wiki.

gulp task:

let gulp = require('gulp');
let jsonType = require('../util/json-to-typings');

gulp.task('schema', () => {
  return gulp.src('schema/*.schema.json')
    .pipe(jsonType())
    .pipe(gulp.dest('models'));
});

file json-to-typings.js

let through = require('through2');
let PluginError = require('gulp-util').PluginError;
let jsonToType = require('json-schema-to-typescript');

module.exports = function() {
  return through.obj(function(file, encoding, callback) {
    if (file.isNull()) {
      return callback(null, file);
    }

    if (file.isStream()) {
      this.emit('error', new PluginError(PLUGIN_NAME, 'Streams not supported!'));
    }

    file.path = file.path.replace('schema.json', 'ts');
    file.contents = Buffer.from(jsonToType.compile(JSON.parse(file.contents.toString())));

    callback(null, file);
  });
};

Case where allOf is not included in compiled ts interface definition

Have a look at: https://github.com/darcyparker/json-schema-to-typescript/blob/fe3f08f1d7eb4445619488974f9f89b2353b74c7/test/cases/allOf.ts

As a comparison, dtsgenerator creates this output:

export interface Itest {
    fooAndBar: {
        a: string;
        b: number;
    };
    foo: {
        a: string;
        b: number;
    };
    more: {
        a: string;
    };
}
declare namespace Itest {
    namespace Definitions {
        export interface Bar {
            a: string;
        }
        export interface Foo {
            a: string;
            b: number;
        }
    }
}

Notes:

  • ignore the interface name and namespace Itest...: dtgenerator uses the filename rather than the title of the schema.
  • I like json-schema-typescript's compiler's choice to use the definitions of Bar and Foo in Itest. but ignoring this, you can see it picks up the properties inside allOf that is a sibling of the top level properties. I believe this is correct behavior because ajv compile -s test.json -o test.js creates a validator that checks for more.

Description with new lines `\n` are not output correctly in typescript comments

If I have a description like this in my JSON Schema:

"description": "Some description\nWith multiple lines"

The output typescript definition neglects to comment the new lines too.

It would be great if long term, the description comment could support multiple lines. For the short term, I am simply stripping the new lines out of the JSON schema before I compile it to typescript.

Enhance tsEnumNames

There are some points where tsEnumNames could be enhanced:

  • JSON is usually often snake_case. Allow ts_enum_names.
  • JSON Editor uses enum_titles for a similar scenario. Allow both or adopt.
  • Space characters will lead to invalid TS. Sanitize or explain in docs.

Support custom template of generated interfaces

It will be nice to have possibility to provide custom template (eg mustache or some other template engine) for generating the interfaces in custom way eg. for putting some comments etc.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.