npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@asyncapi/generator-model-sdk

v0.7.0

Published

The Model SDK for generating data models

Downloads

164

Readme

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):

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