SkillAgentSearch skills...

Modelina

A library for generating typed models based on inputs such as AsyncAPI, OpenAPI, and JSON Schema documents with high customization

Install / Use

/learn @asyncapi/Modelina

README

AsyncAPI Modelina Coverage Status Project Status: Active – The project has reached a stable, usable state and is being actively developed. Maintenance score Npm latest version License last commit Discussions Website Playground <!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section --> All Contributors

<!-- ALL-CONTRIBUTORS-BADGE:END -->

Your one-stop tool for generating accurate and well-tested models for representing the message payloads. Use it as a tool in your development workflow, or a library in a larger integrations, entirely in your control.


<!-- toc is generated with GitHub Actions do not remove toc markers --> <!-- toc --> <!-- tocstop -->

Installing Modelina

Install Modelina directly as a dependency to your project:

npm install @asyncapi/modelina

Or if you want to run Modelina, use the CLI.

modelina generate <language> ./asyncapi.json
<h2 align="center">What Does Modelina Do?</h2> <p align="center">Modelina put YOU in control of your data models, here is how...</p> <!-- prettier-ignore-start --> <!-- markdownlint-disable --> <table> <tr> <td><b>Modelina lets you generate data models from many types of <a href="#inputs">inputs</a></b></td> <td>
const asyncapi = ...
const jsonschema = ...
const openapi = ... 
const metamodel = ... 
...
const models = await generator.generate(
  asyncapi | jsonschema | openapi | metamodel
);
</td> </tr> <tr> <td><b>Use the same inputs across a range of different <a href="#outputs">generators</a></b></td> <td>
const generator = new TypeScriptGenerator();
const generator = new CsharpGenerator();
const generator = new JavaGenerator();
const generator = new RustGenerator();
...
const models = await generator.generate(input);
</td> </tr> <tr> <td><b>Easily let you interact with the generated models.</b>
  • 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.</td>

<td>
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;
  ...
}
</td> </tr> <tr> <td><b>Easily modify how models are <a href="./docs/constraints/README.md">constrained</a> into the output</b></td> <td>
const generator = new TypeScriptGenerator({
  constraints: {
    modelName: ({modelName}) => {
      // Implement your own constraining logic
      return modelName;
    }
  }
});
</td> </tr> <tr> <td><b>Seamlessly layer additional or replacement code <a href="./docs/presets.md">on top of each other to customize the models</a> to your use-case</b></td> <td>
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);
</td> </tr> <tr> <td><b>Seamlessly lets you <a href="./docs/presets.md">combine multiple layers of additional or replacement code</a></b></td> <td>
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);
</td> </tr> </table>

Features

The following table provides a short summary of available features for supported output languages. To see the complete feature list for each language, please click the individual links for each language.

<a id="inputs"></a>

<!-- prettier-ignore-start --> <!-- markdownlint-disable --> <table> <tr> <th>Supported inputs</th> <th></th> </tr> <tr> <td><a href="./docs/usage.md#generate-models-from-asyncapi-documents">AsyncAPI</a></td> <td>We support the following AsyncAPI versions: <em>2.0.0 -> 3.0.0</em>, which generates models for all the defined message payloads. It supports the following schemaFormats AsyncAPI Schema object, JSON Schema draft 7, <a href="./examples/asyncapi-avro-schema">AVRO 1.9</a>, <a href="./examples/asyncapi-raml-schema">RAML 1.0 data type</a>, and <a href="./examples/asyncapi-openapi-schema">OpenAPI 3.0 Schema</a>.</td> </tr> <tr> <td><a href="./docs/usage.md#generate-models-from-avro-schema-documents">Avro Schema<a></td> <td>We support the following Avro versions: <a href="./examples/avro-schema-from-object">v1.x</a></td> </tr> <tr> <td><a href="./docs/usage.md#generate-models-from-json-schema-documents">JSON Schema</a></td> <td>We support the following JSON Schema versions: <em>Draft-4, Draft-6 and Draft-7</em></td> </tr> <tr> <td><a href="./docs/usage.md#generate-models-from-openapi-documents">OpenAPI</a></td> <td>We support the following OpenAPI versions: <em><a href="./docs/usage.md#generate-models-from-swagger-20-documents">Swagger 2.0</a>, <a href="./docs/usage.md#generate-models-from-openapi-documents">OpenAPI 3.0 and 3.1</a></em>, which generates models for all the defined request and response payloads.</td> </tr> <tr> <td><a href="./examples/xsd-to-typescript">XSD (XML Schema Definition)</a></td> <td>We support XML Schema Definition (XSD) with common elements including simple types, complex types, sequences, choices, attributes, and enumerations.</td> </tr> <tr> <td><a href="./docs/usage.md#generate-model-from-typescript-type-files">TypeScript</a></td> <td>We currently support TypeScript types as file input for model generation</td> </tr> <tr> <td><a href="./docs/usage.md#generate-models-from-meta-models">Meta model</a></td> <td>This is the internal representation of a model for Modelina, it is what inputs gets converted to, and what generators are provided to generate code. Instead of relying on an input processor, you can create your own models from scratch and still take advantage on the generators and the features.</td> </tr> </table>

<a id="outputs"></a>

<!-- prettier-ignore-start --> <!-- markdownlint-disable --> <table> <tr> <th>Supported outputs</th> <th></th> </tr> <tr> <td><a href="./docs/usage.md#generate-java-models">Java</a></td> <td>Class and enum generation: <em>generation of equals, hashCode, toString, Jackson annotation, custom indentation type and size, etc</em></td> </tr> <tr> <td><a href="./docs/usage.md#generate-typescript-models">TypeScript</a></td> <td>Class, interface and enum generation: <em>generation of example code, un/marshal functions, custom indentation type and size, etc</em></td> </tr> <tr> <td><a href="./docs/usage.md#generate-c#-models">C#</a></td> <td>Class and enum generation: <em>generation of example code, serializer and deserializer functions, custom indentation type and size, etc</em></td> </tr> <tr> <td><a href="./docs/usage.md#generate-go-models">Go</a></td> <td>Struct and enum generation: <em>custom indentation type and size, etc </em></td> </tr> <tr> <td><a href="./docs/usage.md#generate-javascript-models">JavaScript</a></td> <td>Class generation: <em>custom indentation type and size, etc</em></td> </tr> <tr> <td><a href="./docs/usage.md#generate-dart-models">Dart</a></td> <td>Class and enum generation: json_annotation</td> </tr> <tr> <td><a href="./docs/usage.md#generate-rust-models">Rust</a></td> <td>Struct/tuple and enum generation: <em>generation of `implement Default`, generate serde macros, custom indentation type and size, etc</em></td> </tr> <tr> <td><a href="./docs/usage.md#generate-python-models">Python</a></td> <td>Class and enum generation: <em>custom indentation type and size, etc </em></td> </tr> <tr> <td><a href="./docs/usage.md#generate-kotlin-models">Kotlin</a></td> <td>Class and enum generation: <em>use of data classes where appropriate, custom indentation type and size, etc </em></td> </tr> <tr> <td><a href="./docs/usage.md#ge
View on GitHub
GitHub Stars431
CategoryDevelopment
Updated2h ago
Forks226

Languages

TypeScript

Security Score

100/100

Audited on Mar 27, 2026

No findings