Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

json2jsii

Package Overview
Dependencies
Maintainers
1
Versions
879
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

json2jsii

Generates jsii structs from JSON schemas

  • 0.1.95
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
33K
decreased by-56.47%
Maintainers
1
Weekly downloads
 
Created
Source

json2jsii

Generates jsii-compatible structs from JSON schemas

Usage

const g = new TypeGenerator({
  definitions: {
    Name: {
      description: 'Represents a name of a person',
      required: [ 'firstName', 'lastName' ],
      properties: {
        firstName: {
          type: 'string',
          description: 'The first name of the person',
        },
        lastName: {
          type: 'string',
          description: 'The last name of the person',
        },
      },
    },
  },
});

g.addType('Person', {
  required: [ 'name' ],
  properties: {
    name: {
      description: 'The person\'s name',
      $ref: '#/definitions/Name',
    },
    color: {
      description: 'Favorite color. Default is green',
      enum: [ 'red', 'green', 'blue', 'yellow' ],
    },
  },
});

fs.writeFileSync('gen/ts/person.ts', await g.render());

Then, gen/ts/person.ts will look like this;

/**
 * @schema Person
 */
export interface Person {
  /**
   * The person's name
   *
   * @schema Person#name
   */
  readonly name: Name;

  /**
   * Favorite color. Default is green
   *
   * @default green
   * @schema Person#color
   */
  readonly color?: any;
}

/**
 * Represents a name of a person
 *
 * @schema Name
 */
export interface Name {
  /**
   * The first name of the person
   *
   * @schema Name#firstName
   */
  readonly firstName: string;

  /**
   * The last name of the person
   *
   * @schema Name#lastName
   */
  readonly lastName: string;
}

Language bindings

Once you generate jsii-compatible TypeScript source (such as person.ts above), you can use jsii-srcmak in order to produce source code in any of the jsii supported languages.

The following command will produce Python sources for the Person types:

$ jsii-srcmak gen/ts \
  --python-outdir gen/py --python-module-name person \
  --java-outdir gen/java --java-package person

See the jsii-srcmak for library usage.

Contributions

All contributions are celebrated.

License

Distributed under the Apache 2.0 license.

FAQs

Package last updated on 10 Nov 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc