### Run this example Source: https://github.com/asyncapi/modelina/blob/master/examples/TEMPLATE/README.md Command to install dependencies and start the example. ```sh npm i && npm run start ``` -------------------------------- ### Run this example on Windows Source: https://github.com/asyncapi/modelina/blob/master/examples/TEMPLATE/README.md Command to install dependencies and start the example on Windows. ```sh npm i && npm run start:windows ``` -------------------------------- ### Environment Setup Commands Source: https://github.com/asyncapi/modelina/blob/master/docs/development.md Commands for setting up the development environment, including installing dependencies, running tests, and linting. ```bash nvm use npm install npm run test npm run test -- -u npm run lint npm run format ``` -------------------------------- ### Modelina CLI Usage Example Source: https://github.com/asyncapi/modelina/blob/master/modelina-cli/README.md Demonstrates basic usage of the Modelina CLI, including installation, running commands, checking version, and getting help. ```sh-session $ npm install -g @asyncapi/modelina-cli $ modelina COMMAND running command... $ modelina (--version) @asyncapi/modelina-cli/5.10.0 linux-x64 node-v18.20.8 $ modelina --help [COMMAND] USAGE $ modelina COMMAND ... ``` -------------------------------- ### Run the example Source: https://github.com/asyncapi/modelina/blob/master/examples/csharp-generate-equals-and-hashcode/README.md Commands to run the example using npm. ```sh npm i && npm run start ``` ```sh npm i && npm run start:windows ``` -------------------------------- ### Install website dependencies Source: https://github.com/asyncapi/modelina/blob/master/modelina-website/README.md Command to install all necessary dependencies for the website. ```bash npm install ``` -------------------------------- ### Discriminator example Source: https://github.com/asyncapi/modelina/blob/master/docs/migrations/version-1-to-2.md Example demonstrating the support for Discriminator in schemas. ```yaml schemas: Pet: type: object discriminator: petType properties: petType: type: string name: type: string required: - petType - name Cat: allOf: - $ref: '#/components/schemas/Pet' - type: object properties: petType: const: Cat Dog: allOf: - $ref: '#/components/schemas/Pet' - type: object properties: petType: const: Dog ``` -------------------------------- ### Render Options Example Source: https://github.com/asyncapi/modelina/blob/master/docs/usage.md Example of how to pass render options to the generator's render function. ```typescript const generator = ... generator.render(model, inputModel, { ...options }); ``` -------------------------------- ### Install a plugin Source: https://github.com/asyncapi/modelina/blob/master/modelina-cli/README.md Installs a plugin into Modelina. This command is an alias for 'modelina plugins add'. Supports installation from npm registry, GitHub URL, or GitHub slug. ```bash $ modelina plugins install myplugin ``` ```bash $ modelina plugins install https://github.com/someuser/someplugin ``` ```bash $ modelina plugins install someuser/someplugin ``` -------------------------------- ### Example of adapting source code Source: https://github.com/asyncapi/modelina/blob/master/docs/contributing.md This is an example of the source code file that needs to be adapted when adding a new example. ```typescript import { Generator } from "@modelina/core"; const generator = new Generator({ // ... generator options }); // ... your code ``` -------------------------------- ### Example of adapting testing file Source: https://github.com/asyncapi/modelina/blob/master/docs/contributing.md This is an example of a testing file that needs to be adapted when adding a new example. ```typescript import { describe, it, expect } from "@jest/globals"; describe("My new feature", () => { it("should do something", () => { expect(true).toBe(true); }); }); ``` -------------------------------- ### Preset hooks example Source: https://github.com/asyncapi/modelina/blob/master/docs/presets.md This example demonstrates how to use preset hooks to customize the rendering of class properties by prepending a comment. ```typescript import { TypeScriptGenerator } from '@asyncapi/modelina'; const generator = new TypeScriptGenerator({ presets: [ { class: { property({ content }) { const description = '// Hello world!' return `${description}\n${content}`; } } } ] }); ``` -------------------------------- ### Run the website locally Source: https://github.com/asyncapi/modelina/blob/master/modelina-website/README.md Command to start the local development server for the website. ```bash npm run dev ``` -------------------------------- ### Constant values example Source: https://github.com/asyncapi/modelina/blob/master/docs/migrations/version-1-to-2.md Example of using constant values in a schema. ```yaml type: object properties: country: const: 'United States of America' ``` -------------------------------- ### C# DateTime and DateTimeOffset - Example usage Source: https://github.com/asyncapi/modelina/blob/master/docs/migrations/version-3-to-4.md Example of how to handle DateTime and DateTimeOffset in C# after the format changes. ```csharp var dateTime = new DateTime(2008, 6, 19, 7, 0, 0); // Set the DateTime property of the ModelinaModel var modelinaModel = new ModelinaModel(); modelinaModel.DateTime = dateTime; Console.WriteLine(modelinaModel.DateTime); // Get the DateTime property from the ModelinaModel DateTime dateTime2 = modelinaModel.DateTime.LocalDateTime; Console.WriteLine(dateTime2); ``` -------------------------------- ### Download and Install MacOS x64 Source: https://github.com/asyncapi/modelina/blob/master/modelina-cli/README.md Downloads the latest release package for MacOS x64 and installs it. ```sh # Download latest release curl -OL https://github.com/asyncapi/modelina/releases/latest/download/modelina.x64.pkg # Install it sudo installer -pkg modelina.pkg -target / ``` -------------------------------- ### Generator Options Example Source: https://github.com/asyncapi/modelina/blob/master/docs/usage.md Example of how to pass generator options to the TypeScriptGenerator constructor. ```typescript const generator = new TypeScriptGenerator({ ...options }); ``` -------------------------------- ### Preset Test Example Source: https://github.com/asyncapi/modelina/blob/master/docs/contributing.md Example of how to write a test for a new preset using Jest. ```typescript describe('LANGUAGE_MY_PRESET', () => { let generator: LanguageGenerator; beforeEach(() => { generator = new LanguageGenerator({ presets: [LANGUAGE_MY_PRESET] }); }); test('should render xxx', async () => { const input = { $id: 'Clazz', type: 'object', properties: { min_number_prop: { type: 'number' }, max_number_prop: { type: 'number' }, }, }; const models = await generator.generate(input); expect(models).toHaveLength(1); expect(models[0].result).toMatchSnapshot(); }); }); ``` -------------------------------- ### Install via NPM Source: https://github.com/asyncapi/modelina/blob/master/modelina-cli/README.md Installs the Modelina CLI globally using NPM. ```typescript npm install -g @asyncapi/modelina-cli ``` -------------------------------- ### Download and Install MacOS arm64 Source: https://github.com/asyncapi/modelina/blob/master/modelina-cli/README.md Downloads the latest release package for MacOS arm64 and installs it. ```sh # Download latest release curl -OL https://github.com/asyncapi/modelina/releases/latest/download/modelina.arm64.pkg # Install it sudo installer -pkg modelina.pkg -target / ``` -------------------------------- ### Preset structure example Source: https://github.com/asyncapi/modelina/blob/master/docs/presets.md An example illustrating the basic structure of a JavaScript preset object, showing how to define callbacks for different model types like 'class' and 'interface'. ```javascript { // `class` model type class: { self(...arguments) { /* logic */ }, // `setter` customization method setter(...arguments) { /* logic */ }, }, interface: { // `property` customization method property(...arguments) { /* logic */ }, additionalContent(...arguments) { /* logic */ }, }, } ``` -------------------------------- ### List installed plugins Source: https://github.com/asyncapi/modelina/blob/master/modelina-cli/README.md Lists all installed plugins in the Modelina CLI. Supports JSON output and filtering for core plugins. ```bash $ modelina plugins ``` -------------------------------- ### Constants in Python Source: https://github.com/asyncapi/modelina/blob/master/docs/migrations/version-3-to-4.md Example demonstrating how constants are now respected and not changeable via setters. ```python class Address: def __init__(self, input: Dict): self._street_name: str = 'someAddress' @property def street_name(self) -> str: return self._street_name ``` -------------------------------- ### Go Nullable and Required Properties Source: https://github.com/asyncapi/modelina/blob/master/docs/migrations/version-3-to-4.md Example of nullable and required properties in Go structs. ```go type info struct { name string // required description *string // nullable version *float64 isDevelopment *bool } ``` -------------------------------- ### Modelina Autocomplete Command Source: https://github.com/asyncapi/modelina/blob/master/modelina-cli/README.md Display autocomplete installation instructions for various shells. ```bash USAGE $ modelina autocomplete [SHELL] [-r] ARGUMENTS SHELL (zsh|bash|powershell) Shell type FLAGS -r, --refresh-cache Refresh cache (ignores displaying instructions) DESCRIPTION Display autocomplete installation instructions. EXAMPLES $ modelina autocomplete $ modelina autocomplete bash $ modelina autocomplete zsh $ modelina autocomplete powershell $ modelina autocomplete --refresh-cache ``` -------------------------------- ### Invalid TypeScript class names Source: https://github.com/asyncapi/modelina/blob/master/docs/constraints/README.md Examples of invalid TypeScript class names due to special characters or starting with numbers. ```typescript class &name {} ``` ```typescript class 1name {} ``` -------------------------------- ### Inspect a plugin Source: https://github.com/asyncapi/modelina/blob/master/modelina-cli/README.md Displays installation properties of a specified plugin. Defaults to inspecting the current directory if no plugin is specified. ```bash $ modelina plugins inspect myplugin ``` -------------------------------- ### Navigate to the website directory Source: https://github.com/asyncapi/modelina/blob/master/modelina-website/README.md Command to change the current directory to the website folder. ```bash cd modelina-website ``` -------------------------------- ### Initialize Context Source: https://github.com/asyncapi/modelina/blob/master/modelina-cli/README.md Command to initialize a new context file in a specified directory. ```bash modelina config context init [CONTEXT-FILE-PATH] ``` ```bash USAGE $ modelina config context init [CONTEXT-FILE-PATH] [-h] ARGUMENTS CONTEXT-FILE-PATH Specify directory in which context file should be created: - current directory : modelina config context init . (default) - root of current repository : modelina config context init ./ - user's home directory : modelina config context init ~ FLAGS -h, --help Show CLI help. DESCRIPTION Initialize context ``` -------------------------------- ### Inheritance with allOf Source: https://github.com/asyncapi/modelina/blob/master/docs/migrations/version-2-to-3.md Example demonstrating how `allOf` with `allowInheritance` enabled generates interfaces for schemas. ```yaml components: messages: Vehicle: payload: oneOf: - $ref: '#/components/schemas/Car' - $ref: '#/components/schemas/Truck' schemas: Vehicle: title: Vehicle type: object discriminator: vehicleType properties: vehicleType: title: VehicleType type: string length: type: number format: float required: - vehicleType Car: allOf: - '#/components/schemas/Vehicle' - type: object properties: vehicleType: const: Car Truck: allOf: - '#/components/schemas/Vehicle' - type: object properties: vehicleType: const: Truck ``` ```java public interface NewVehicle { VehicleType getVehicleType(); } public class Car implements NewVehicle, Vehicle { private final VehicleType vehicleType = VehicleType.CAR; private Float length; private Map additionalProperties; public VehicleType getVehicleType() { return this.vehicleType; } @Override public Float getLength() { return this.length; } @Override public void setLength(Float length) { this.length = length; } } public enum VehicleType { CAR((String)\"Car\"), TRUCK((String)\"Truck\"); private String value; VehicleType(String value) { this.value = value; } public String getValue() { return value; } public static VehicleType fromValue(String value) { for (VehicleType e : VehicleType.values()) { if (e.value.equals(value)) { return e; } } throw new IllegalArgumentException(\"Unexpected value '\" + value + \"'\"); } @Override public String toString() { return String.valueOf(value); } } public interface Vehicle { public Float getLength(); public void setLength(Float length); } public class Truck implements NewVehicle, Vehicle { private final VehicleType vehicleType = VehicleType.TRUCK; private Float length; private Map additionalProperties; public VehicleType getVehicleType() { return this.vehicleType; } @Override public Float getLength() { return this.length; } @Override public void setLength(Float length) { this.length = length; } } ``` -------------------------------- ### Download Windows x64 Source: https://github.com/asyncapi/modelina/blob/master/modelina-cli/README.md Provides a link to download the Windows x64 executable. ```html manually download and run [`modelina.x64.exe`](https://github.com/asyncapi/modelina/releases/latest/download/modelina.x64.exe) ``` -------------------------------- ### List Contexts Source: https://github.com/asyncapi/modelina/blob/master/modelina-cli/README.md Command to list all stored contexts. ```bash modelina config context list ``` ```bash USAGE $ modelina config context list [-h] FLAGS -h, --help Show CLI help. DESCRIPTION List all the stored contexts in the store ``` -------------------------------- ### Install Debian (Linux) Source: https://github.com/asyncapi/modelina/blob/master/modelina-cli/README.md Downloads and installs Modelina on Debian-based Linux distributions. ```sh # Download curl -OL https://github.com/asyncapi/modelina/releases/latest/download/modelina.deb # Install sudo apt install ./modelina.deb ``` -------------------------------- ### Python Type Hints - Before Source: https://github.com/asyncapi/modelina/blob/master/docs/migrations/version-3-to-4.md Example of Python class properties and accessor functions without type hints. ```python from typing import Any, Dict class ObjProperty: def __init__(self, input): if hasattr(input, 'number'): self._number = input['number'] if hasattr(input, 'additional_properties'): self._additional_properties = input['additional_properties'] @property def number(self): return self._number @number.setter def number(self, number): self._number = number @property def additional_properties(self): return self._additional_properties @additional_properties.setter def additional_properties(self, additional_properties): self._additional_properties = additional_properties ``` -------------------------------- ### Install Modelina via npm Source: https://github.com/asyncapi/modelina/blob/master/README.md Install Modelina directly as a dependency to your project using npm. ```bash npm install @asyncapi/modelina ``` -------------------------------- ### Install via Chocolatey (Windows) Source: https://github.com/asyncapi/modelina/blob/master/modelina-cli/README.md Installs Modelina using the Chocolatey package manager on Windows. ```sh choco install modelina ``` -------------------------------- ### Download Windows x32 Source: https://github.com/asyncapi/modelina/blob/master/modelina-cli/README.md Provides a link to download the Windows x32 executable. ```html manually download and run the executable [`modelina.x86.exe`](https://github.com/asyncapi/modelina/releases/latest/download/modelina.x86.exe) ``` -------------------------------- ### Accessing options in constraint logic Source: https://github.com/asyncapi/modelina/blob/master/docs/migrations/version-2-to-3.md TypeScript example showing how to import and use constraint types from `@asyncapi/modelina`. ```typescript import { ConstantConstraint, EnumKeyConstraint, EnumValueConstraint, ModelNameConstraint, PropertyKeyConstraint } from @asyncapi/modelina ``` -------------------------------- ### Install via Brew (MacOS) Source: https://github.com/asyncapi/modelina/blob/master/modelina-cli/README.md Installs Modelina using the Homebrew package manager on MacOS. ```sh brew install modelina ``` -------------------------------- ### Docker Commands Source: https://github.com/asyncapi/modelina/blob/master/docs/development.md Scripts for building and testing the Docker image. ```bash npm run docker:build npm run docker:test ``` -------------------------------- ### Python Type Hints - After Source: https://github.com/asyncapi/modelina/blob/master/docs/migrations/version-3-to-4.md Example of Python class properties and accessor functions with type hints in v4. ```python from typing import Any, Dict class ObjProperty: def __init__(self, input: Dict): if hasattr(input, 'number'): self._number: float = input['number'] if hasattr(input, 'additional_properties'): self._additional_properties: dict[str, Any] = input['additional_properties'] @property def number(self) -> float: return self._number @number.setter def number(self, number: float): self._number = number @property def additional_properties(self) -> dict[str, Any]: return self._additional_properties @additional_properties.setter def additional_properties(self, additional_properties: dict[str, Any]): self._additional_properties = additional_properties ``` -------------------------------- ### oneOf with allOf example Source: https://github.com/asyncapi/modelina/blob/master/docs/inputs/JSON_Schema.md This example demonstrates how 'oneOf' and 'allOf' are interpreted by merging the 'allOf' model into each 'oneOf' model. ```json { "allOf":[ { "title":"Animal", "type":"object", "properties":{ "animalType":{ "title":"Animal Type", "type":"string" }, "age":{ "type":"integer", "min":0 } } } ], "oneOf":[ { "title":"Cat", "type":"object", "properties":{ "animalType":{ "const":"Cat" }, "huntingSkill":{ "title":"Hunting Skill", "type":"string", "enum":[ "clueless", "lazy" ] } } }, { "title":"Dog", "type":"object", "additionalProperties":false, "properties":{ "animalType":{ "const":"Dog" }, "breed":{ "title":"Dog Breed", "type":"string", "enum":[ "bulldog", "bichons frise" ] } } } ] } ```