Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
jonaslagoni authored Feb 7, 2024
2 parents 2346cd0 + 293d4f9 commit 828e2cc
Show file tree
Hide file tree
Showing 265 changed files with 5,367 additions and 1,279 deletions.
10 changes: 10 additions & 0 deletions .all-contributorsrc
Original file line number Diff line number Diff line change
Expand Up @@ -838,6 +838,16 @@
"contributions": [
"doc"
]
},
{
"login": "RowlandBanks",
"name": "RowlandBanks",
"avatar_url": "https://avatars.githubusercontent.com/u/9962551?v=4",
"profile": "https://github.com/RowlandBanks",
"contributions": [
"code",
"test"
]
}
],
"contributorsPerLine": 7,
Expand Down
6 changes: 3 additions & 3 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"security",
"github",
"jest",
"prettier"
"prettier",
"unused-imports"
],
"extends": [
"eslint:recommended",
Expand Down Expand Up @@ -55,7 +56,7 @@
"no-empty-character-class": 2,
"no-self-compare": 2,
"valid-typeof": 2,
"no-unused-vars": 0,
"unused-imports/no-unused-imports": 2,
"handle-callback-err": 2,
"no-shadow-restricted-names": 2,
"no-new-require": 2,
Expand Down Expand Up @@ -138,7 +139,6 @@
"prefer-const": 2,
"prefer-spread": 2,
"prefer-template": 2,
"@typescript-eslint/no-unused-vars": 2,
"prettier/prettier": 2,
"sonarjs/no-identical-functions": "off",
"sonarjs/prefer-single-boolean-return": "off",
Expand Down
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
[![Discussions](https://img.shields.io/github/discussions/asyncapi/modelina)](https://github.com/asyncapi/modelina/discussions)
[![Website](https://img.shields.io/website?label=website&url=https%3A%2F%2Fwww.modelina.org)](https://www.modelina.org)
[![Playground](https://img.shields.io/website?label=playground&url=https%3A%2F%2Fwww.modelina.org%2Fplayground)](https://www.modelina.org/playground) <!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
[![All Contributors](https://img.shields.io/badge/all_contributors-77-orange.svg?style=flat-square)](#contributors-)
[![All Contributors](https://img.shields.io/badge/all_contributors-78-orange.svg?style=flat-square)](#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.
Expand Down Expand Up @@ -422,6 +422,9 @@ Thanks go out to these wonderful people ([emoji key](https://allcontributors.org
<td align="center" valign="top" width="14.28%"><a href="https://github.com/officialasishkumar"><img src="https://avatars.githubusercontent.com/u/87874775?v=4?s=100" width="100px;" alt="Asish Kumar"/><br /><sub><b>Asish Kumar</b></sub></a><br /><a href="https://github.com/asyncapi/modelina/commits?author=officialasishkumar" title="Documentation">📖</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/ankur0904"><img src="https://avatars.githubusercontent.com/u/98346896?v=4?s=100" width="100px;" alt="Ankur Singh"/><br /><sub><b>Ankur Singh</b></sub></a><br /><a href="https://github.com/asyncapi/modelina/commits?author=ankur0904" title="Documentation">📖</a></td>
</tr>
<tr>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/RowlandBanks"><img src="https://avatars.githubusercontent.com/u/9962551?v=4?s=100" width="100px;" alt="RowlandBanks"/><br /><sub><b>RowlandBanks</b></sub></a><br /><a href="https://github.com/asyncapi/modelina/commits?author=RowlandBanks" title="Code">💻</a> <a href="https://github.com/asyncapi/modelina/commits?author=RowlandBanks" title="Tests">⚠️</a></td>
</tr>
</tbody>
</table>

Expand Down
1 change: 1 addition & 0 deletions docs/generators.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ Below is a list of additional options available for a given generator.
| Option | Type | Description | Default value |
|---|---|---|---|
| `renderTypes` | Boolean | Render signature for types. | `true` |
| `mapType` | String | It indicates which mapping type should be rendered for the `object` type. Its value can be one of `map`, `record` or `indexedObject`. | `map` |
| `modelType` | String | It indicates which model type should be rendered for the `object` type. Its value can be either `interface` or `class`. | `class` |
| `enumType` | String | It indicates which type should be rendered for the `enum` type. Its value can be either `union` or `enum`. | `enum` |
| `namingConvention` | Object | Options for naming conventions. | - |
Expand Down
33 changes: 32 additions & 1 deletion docs/languages/TypeScript.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ There are special use-cases that each language supports; this document pertains
<!-- toc -->

- [Generate an interface instead of classes](#generate-an-interface-instead-of-classes)
- [Generate different `mapType`s for an `object` type](#generate-different-maptypes-for-an-object)
- [Generate union types instead of enums](#generate-union-types-instead-of-enums)
- [Generate serializer and deserializer functionality](#generate-serializer-and-deserializer-functionality)
* [To and from JSON](#to-and-from-json)
Expand All @@ -17,6 +18,7 @@ There are special use-cases that each language supports; this document pertains
- [Generate example data function](#generate-example-data-function)
- [Rendering complete models to a specific module system](#rendering-complete-models-to-a-specific-module-system)
- [Rendering comments from description and example fields](#rendering-comments-from-description-and-example-fields)
- [Rendering raw properties for interface](#rendering-raw-properties-for-interface)

<!-- tocstop -->

Expand All @@ -26,6 +28,29 @@ Sometimes you don't care about classes, but rather have interfaces generated. Th

Check out this [example out for a live demonstration](../../examples/typescript-interface).

## Generate different `mapType`s for an `object`

Typescript offers different `mapType`s which can simplify the use based on the needs. This behavior can be changed through the [`mapType` configuration](https://github.com/asyncapi/modelina/blob/master/docs/generators.md#typescript).

- Use `map` when you need a dynamic collection of key-value pairs with built-in methods for manipulation.
- Use `record` when you want to define an object with specific keys and their corresponding value types.
- Use `indexedObject` (or an interface with index signature) for a more generic approach when working with objects with dynamic keys.

An example of the generated code can be seen below:

```ts
// mapType = indexedObject
private _person?: { [name: string]: any };

// mapType = map
private _person?: Map<string, any>;

// mapType = record
private _person?: Record<string, any>;
```

Also, check out this [example for a live demonstration](../../examples/typescript-change-map-type).

## Generate union types instead of enums

Typescript offers union types which can simplify the use as no keywords are needed and the values can be set directly. This behavior can be changed through the [modelType configuration](https://github.com/asyncapi/modelina/blob/master/docs/generators.md#typescript). An example of the generated code can be seen below:
Expand Down Expand Up @@ -101,4 +126,10 @@ Check out this [example for a live demonstration how to generate the complete Ty
## Rendering comments from description and example fields
You can use the `TS_DESCRIPTION_PRESET` to generate JSDoc style comments from description and example fields in your model.

See [this example](../../examples/typescript-generate-comments) for how this can be used.
See [this example](../../examples/typescript-generate-comments) for how this can be used.

## Rendering raw properties for interface

You can use the `rawPropertyNames: true` and `modelType: 'interface'` together to generate models that use raw properties.

See [this example](../../examples/typescript-generate-raw-properties) for how this can be used.
Loading

0 comments on commit 828e2cc

Please sign in to comment.