Introducing Socket Firewall: Free, Proactive Protection for Your Software Supply Chain.Learn More
Socket
Book a DemoInstallSign in
Socket

@asyncapi/generator-model-sdk

Package Overview
Dependencies
Maintainers
3
Versions
30
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@asyncapi/generator-model-sdk

The Model SDK for generating data models

latest
Source
npmnpm
Version
0.7.0
Version published
Maintainers
3
Created
Source

AsyncAPI logo
AsyncAPI Model SDK

The official SDK for generating data models from JSON Schema and AsyncAPI spec

Coverage Status

All Contributors

AsyncAPI Model SDK is a set of classes/functions for generating data models from JSON Schema and AsyncAPI spec.

:loudspeaker: ATTENTION:

This package is under development and it has not reached version 1.0.0 yet, which means its API might get breaking changes without prior notice. Once it reaches its first stable version, we'll follow semantic versioning.

Installation

Run this command to install the SDK in your project:

npm install --save @asyncapi/generator-model-sdk

How it works

The process of creating data models from input data consists of 2 processes, the input and generation process.

The input process

The input process ensures that any supported input is handled correctly, the basics are that any input needs to be converted into our internal model representation CommonModel. The following inputs are supported:

Read more about the input process here.

The generation process

The generation process uses the predefined CommonModels from the input stage to easily generate models regardless of input. The package supports the following output languages:

  • JavaScript
  • TypeScript
  • Java

Check out the example to see how to use the library and generators document for more info.

NOTE: Each implemented language has different options, dictated by the nature of the language. Keep this in mind when selecting a language.

Example

import { TypeScriptGenerator } from '@asyncapi/generator-model-sdk';

const generator = new TypeScriptGenerator({ modelType: 'interface' });

const doc = {
  $id: "Address",
  type: "object",
  properties: {
    street_name:    { type: "string" },
    city:           { type: "string", description: "City description" },
    state:          { type: "string" },
    house_number:   { type: "number" },
    marriage:       { type: "boolean", description: "Status if marriage live in given house" },
    pet_names:      { type: "array", items: { type: "string" } },
    state:          { type: "string", enum: ["Texas", "Alabama", "California", "other"] },
  },
  required: ["street_name", "city", "state", "house_number", "state"],
};

const interfaceModel = await generator.generate(doc);

// interfaceModel[0] should have the shape:
interface Address {
  streetName: string;
  city: string;
  state: string;
  houseNumber: number;
  marriage?: boolean;
  petNames?: Array<string>;
  state?: "Texas" | "Alabama" | "California" | "other";
}

Supported input

These are the supported inputs.

AsyncAPI input

The library expects the asyncapi property for the document to be sat in order to understand the input format.

const parser = require('@asyncapi/parser');
const doc = await parser.parse(`{asyncapi: '2.0.0'}`);
generator.generate(doc);
  • Generate from a pure JS object:
generator.generate({asyncapi: '2.0.0'});

JSON Schema input

  • Generate from a pure JS object:
generator.generate({$schema: 'http://json-schema.org/draft-07/schema#'});

Customization

There are multiple ways to customize the library both in terms of processing, logging and output generation, check the customization document.

Development

To setup your development environment please read the development document.

Contributing

Read CONTRIBUTING guide.

Contributors ✨

Thanks goes to these wonderful people (emoji key):


Maciej Urbańczyk

🐛 💻 📖 🤔 🚧 💬 ⚠️ 👀

czlowiek488

🐛 👀 🤔

Sergio Moya

🐛

Jonas Lagoni

🐛 💻 📖 🤔 🚧 💬 ⚠️ 👀

Lukasz Gornicki

👀

Arjun Garg

💻

Fran Méndez

👀

This project follows the all-contributors specification. Contributions of any kind welcome!

Keywords

asyncapi

FAQs

Package last updated on 07 Jun 2021

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