Generate data models for payload

Modelina is a library for generating data models based on inputs such as AsyncAPI, OpenAPI, or JSON Schema documents.

How to get started

You can use through the AsyncAPI CLI or install it as a library.

AsyncAPI CLI

Get started immediately with Modelina through the AsyncAPI CLI or by installing it as a library.

asyncapi generate models typescript ./asyncapi.json

Installation

Install Modelina as a library to take full control.

npm install @asyncapi/modelina

Usage

Modelina can be used in a wide range of scenarios, and is build to be apart of the core toolbox you can customize to your hearts desire. Here is just a fraction of what you can do with Modelina.

Modelina lets you generate data models from many types of inputs
const asyncapi = ...
const jsonschema = ...
const openapi = ...
const metamodel = ...
...
const models = await generator.generate(
  asyncapi | jsonschema | openapi | metamodel
);
Use the same inputs across a range of different generators
const generator = new TypeScriptGenerator();
const generator = new CsharpGenerator();
const generator = new JavaGenerator();
const generator = new RustGenerator();
...
const models = await generator.generate(input);

Easily let you interact with the generated models.- Want to show the generated models on a website? Sure! - Want to generate the models into files? Sure! - Want to combine all the models into one single file? Sure! Whatever interaction you need, you can create.

const models = await generator.generate(input);
for (const model in models) { 
  const generatedCode = model.result;
  const dependencies = model.dependencies;
  const modeltype = model.type;
  const modelName = model.modelName;
  ...
}
Easily modify how models are constrained into the into the output
const generator = new TypeScriptGenerator({
  constraints: {
    modelName: ({modelName}) => {
      // Implement your own constraining logic
      return modelName;
    }
  }
});
Seamlessly layer additional or replacement code on top of each other to customize the models to your use-case
const generator = new TypeScriptGenerator({
  presets: [
    {
      class: {
        additionalContent({ content }) {
          return `${content}
public myCustomFunction(): string {
  return 'A custom function for each class';
}`;
        },
      }
    }
  ]
});
const models = await generator.generate(input);
Seamlessly lets you combine multiple layers of additional or replacement code
const myCustomFunction1 = {
  class: {
    additionalContent({ content }) {
      return `${content}
public myCustomFunction(): string {
return 'A custom function for each class';
}`;
    },
  }
};
const myCustomFunction2 = {...};
const generator = new TypeScriptGenerator({
  presets: [
    myCustomFunction1,
    myCustomFunction2
  ]
});
const models = await generator.generate(input);