Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: update language documentation #862

Merged
merged 2 commits into from
Aug 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 9 additions & 20 deletions docs/advanced.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ This document contains many of the advanced use-cases that you may stumble upon
- [Generate models to separate files](#generate-models-to-separate-files)
- [Include a custom function in the data model](#include-a-custom-function-in-the-data-model)
- [Use the models for data transfer](#use-the-models-for-data-transfer)
- [Extend the logic of an existing renderer](#extend-the-logic-of-an-existing-renderer)
- [Build your own model renderer](#build-your-own-model-renderer)
- [Create your own models from the ground up, instead of a supported input](#create-your-own-models-from-the-ground-up-instead-of-a-supported-input)
- [Adapting input and outputs](#adapting-input-and-outputs)
- [Add logging to library](#add-logging-to-library)
- [Change the generated indentation type and size](#change-the-generated-indentation-type-and-size)
Expand All @@ -31,13 +28,6 @@ The reason for splitting the functionality is because in certain environments (l

The file generators all follow the same pattern regardless of output language, which is the following format - `<language>FileGenerator`.

Supported by:
- Java
- TypeScript
- C#
- Go
- JavaScript

> It is not supported in browsers.

Check out this [example out for a live demonstration](../examples/generate-to-files).
Expand All @@ -48,16 +38,15 @@ Sometimes you want to include custom functionality into the generated models, th
Check out this [example out for a live demonstration](../examples/include-custom-function).

## Use the models for data transfer
TODO

## Extend the logic of an existing renderer
TODO

## Build your own model renderer
TODO

## Create your own models from the ground up, instead of a supported input
TODO
One of the primary use-cases for the generated models, is to serialize and deserilize it to for example JSON, XML or binary. Each generator can have multiple ways to achieve this, and even support multiple libraries. This is achieved through presets, you can find them here for each output:

- [C#](./languages/Csharp.md#generate-serializer-and-deserializer-functionality)
- [Dart](./languages/Dart.md#generate-serializer-and-deserializer-functionality)
- Go currently does not support this.
- [Java](./languages/Java.md#generate-serializer-and-deserializer-functionality)
- [JavaScript](./languages/JavaScript.md#generate-serializer-and-deserializer-functionality)
- [Rust](./languages/Rust.md)
- [TypeScript](./languages/TypeScript.md#generate-serializer-and-deserializer-functionality)

## Adapting input and outputs
Sometimes you simply cannot make two things work together as you wished, maybe the input does not support it, or Modelina natively doesn't. However, because of the nature with presets, we can make it work anyway.
Expand Down
47 changes: 38 additions & 9 deletions docs/languages/Csharp.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,47 @@ There are special use-cases that each language supports; this document pertains

<!-- toc -->

- [Generate serializer and deserializer functionality](#generate-serializer-and-deserializer-functionality)
- [Generate models with equals and GetHashCode methods](#generate-models-with-equals-and-gethashcode-methods)
- [Generate models with auto-implemented properties](#generate-models-with-auto-implemented-properties)
- [Change the collection type for arrays](#change-the-collection-type-for-arrays)
- [Generate custom enum value names](#generate-custom-enum-value-names)
- [Generate models with inheritance](#generate-models-with-inheritance)
* [Generate serializer and deserializer functionality](#generate-serializer-and-deserializer-functionality)
+ [To and from JSON](#to-and-from-json)
- [Using native System.Text.Json](#using-native-systemtextjson)
+ [To and from XML](#to-and-from-xml)
+ [To and from binary](#to-and-from-binary)
* [Generate models with equals and GetHashCode methods](#generate-models-with-equals-and-gethashcode-methods)
* [Generate models with auto-implemented properties](#generate-models-with-auto-implemented-properties)
* [Change the collection type for arrays](#change-the-collection-type-for-arrays)
* [Generate custom enum value names](#generate-custom-enum-value-names)
* [Generate models with inheritance](#generate-models-with-inheritance)
- [FAQ](#faq)
+ [Why is the type `dynamic` or `dynamic[]` when it should be `X`?](#why-is-the-type-dynamic-or-dynamic-when-it-should-be-x)

<!-- tocstop -->

## Generate serializer and deserializer functionality

Sometimes you want to serialize the data models into JSON. In order to do that use the preset `CSHARP_JSON_SERIALIZER_PRESET`
The most widely used usecase for Modelina is to generate models that include serilization and deserialization functionality to convert the models into payload data. This payload data can of course be many different kinds, JSON, XML, raw binary, you name it.

**External dependencies:**
Requires [System.Text.Json](https://devblogs.microsoft.com/dotnet/try-the-new-system-text-json-apis/), [System.Text.Json.Serialization](https://docs.microsoft.com/en-us/dotnet/standard/serialization/system-text-json-how-to?pivots=dotnet-6-0) and [System.Text.RegularExpressions](https://docs.microsoft.com/en-us/dotnet/api/system.text.regularexpressions?view=net-6.0) to work.
As you normally only need one library to do this, we developers can never get enough with creating new stuff, therefore there might be one specific library you need or want to integrate with. Therefore there is not one specific preset that offers everything. Below is a list of all the supported serialization presets.

### To and from JSON
Here are all the supported presets and the libraries they use:

- [Using native System.Text.Json](#using-native-systemtextjson)

#### Using native System.Text.Json

To include functionality that convert the models using the [System.Text.Json](https://devblogs.microsoft.com/dotnet/try-the-new-system-text-json-apis/), to use this, use the preset `CSHARP_JSON_SERIALIZER_PRESET`.

Check out this [example for a live demonstration](../../examples/csharp-generate-serializer).

**External dependencies**
Requires [System.Text.Json](https://devblogs.microsoft.com/dotnet/try-the-new-system-text-json-apis/), [System.Text.Json.Serialization](https://docs.microsoft.com/en-us/dotnet/standard/serialization/system-text-json-how-to?pivots=dotnet-6-0) and [System.Text.RegularExpressions](https://docs.microsoft.com/en-us/dotnet/api/system.text.regularexpressions?view=net-6.0) to work.

### To and from XML
Currently not supported, [let everyone know you need it](https:/asyncapi/modelina/issues/new?assignees=&labels=enhancement&template=enhancement.md)!

### To and from binary
Currently not supported, [let everyone know you need it](https:/asyncapi/modelina/issues/new?assignees=&labels=enhancement&template=enhancement.md)!

## Generate models with equals and GetHashCode methods

To overwrite the `Equal` and `GetHashCode` methods, use the preset `CSHARP_COMMON_PRESET` and provide the options `equal: true` and `hashCode: true`
Expand Down Expand Up @@ -53,4 +76,10 @@ Check out this [example for a live demonstration](../../examples/csharp-overwrit
If you want the generated models to inherit from a custom class, you can overwrite the existing rendering behavior and create your own class setup.

Check out this [example for a live demonstration](../../examples/csharp-use-inheritance).
# FAQ
This is the most asked questions and answers which should be your GOTO list to check before asking anywhere else. Cause it might already have been answered!

### Why is the type `dynamic` or `dynamic[]` when it should be `X`?
Often times you might encounter variables which as of type `dynamic` or `dynamic[]`, which is our fallback type when we cannot accurately find the right type.

**If you are encountering this when your input is JSON Schema/OpenAPI/AsyncAPI**, it most likely is because of a property being defined as having multiple types as a union, which the C# generator cannot natively handle and fallback to `dynamic`. For arrays, you have to remember that `additionalItems` is by default `true`, this means that even though you use `items: { type: "string"}` by not setting `additionalItems: false`, it's the same as setting `items: { type: ["array", "boolean", "integer", "null", "number", "object", "string"]}`.
27 changes: 24 additions & 3 deletions docs/languages/Dart.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,33 @@ There are special use-cases that each language supports; this document pertains

<!-- toc -->

- [Include json_annotation for the class and enums](#include-json-annotation-for-the-class)
- [Generate serializer and deserializer functionality](#generate-serializer-and-deserializer-functionality)
* [To and from JSON](#to-and-from-json)
+ [JSON annotation](#json-annotation)
* [To and from XML](#to-and-from-xml)
* [To and from binary](#to-and-from-binary)

<!-- tocstop -->

## Include Json annotation for the class and enums
## Generate serializer and deserializer functionality

When you generate the models with json annotation, generated files include json_annotation package (https://pub.dev/packages/json_annotation/) and their syntax
The most widely used usecase for Modelina is to generate models that include serilization and deserialization functionality to convert the models into payload data. This payload data can of course be many different kinds, JSON, XML, raw binary, you name it.

As you normally only need one library to do this, we developers can never get enough with creating new stuff, therefore there might be one specific library you need or want to integrate with. Therefore there is not one specific preset that offers everything. Below is a list of all the supported serialization presets.

### To and from JSON
Here are all the supported presets and the libraries they use:

- [JSON annotation](#json-annotation)

#### JSON annotation

When you generate the models with json annotation, generated files include json_annotation package (https://pub.dev/packages/json_annotation/) and their syntax.

Check out this [example for a live demonstration](../../examples/dart-generate-json-annotation).

### To and from XML
Currently not supported, [let everyone know you need it](https:/asyncapi/modelina/issues/new?assignees=&labels=enhancement&template=enhancement.md)!

### To and from binary
Currently not supported, [let everyone know you need it](https:/asyncapi/modelina/issues/new?assignees=&labels=enhancement&template=enhancement.md)!
37 changes: 31 additions & 6 deletions docs/languages/Java.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,12 @@ There are special use-cases that each language supports; this document pertains
- [Include toString function for the class](#include-tostring-function-for-the-class)
- [Include JavaDoc for properties](#include-javadoc-for-properties)
- [Include Javax validation constraint annotations for properties](#include-javax-validation-constraint-annotations-for-properties)
- [Include Jackson annotations for the class](#include-jackson-annotations-for-the-class)
- [Include JSON marshaling and unmarshaling methods](#include-json-marshaling-and-unmarshaling-methods)
- [Generate serializer and deserializer functionality](#generate-serializer-and-deserializer-functionality)
* [To and from JSON](#to-and-from-json)
+ [Jackson annotation](#jackson-annotation)
+ [JSON marshaling and unmarshaling methods](#json-marshaling-and-unmarshaling-methods)
* [To and from XML](#to-and-from-xml)
* [To and from binary](#to-and-from-binary)

<!-- tocstop -->

Expand Down Expand Up @@ -53,17 +57,38 @@ In some cases, when you generate the models from JSON Schema, you may want to in

Check out this [example for a live demonstration](../../examples/java-generate-javax-constraint-annotation).

## Include Jackson annotations for the class
## Generate serializer and deserializer functionality

The most widely used usecase for Modelina is to generate models that include serilization and deserialization functionality to convert the models into payload data. This payload data can of course be many different kinds, JSON, XML, raw binary, you name it.

As you normally only need one library to do this, we developers can never get enough with creating new stuff, therefore there might be one specific library you need or want to integrate with. Therefore there is not one specific preset that offers everything. Below is a list of all the supported serialization presets.

### To and from JSON
Here are all the supported presets and the libraries they use:

- [Jackson annotation](#jackson-annotation)
- [JSON marshaling and unmarshaling methods](#json-marshaling-and-unmarshaling-methods)

#### Jackson annotation

To generate Java data models with Jackson annotation using `JAVA_JACKSON_PRESET` option.

Check out this [example for a live demonstration](../../examples/java-generate-jackson-annotation).

## Include JSON marshaling and unmarshaling methods
**External dependencies**
Requires [com.fasterxml.jackson.annotation](https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-annotations) to work.

#### JSON marshaling and unmarshaling methods

Sometimes you just want to convert your class to JSON without the use of annotations such as Jackson.

Check out this [example for a live demonstration](../../examples/java-generate-marshalling).

External dependencies
- Requires [org.json package](https://search.maven.org/artifact/org.json/json/20211205/bundle) to work
**External dependencies**
Requires [org.json package](https://search.maven.org/artifact/org.json/json/20211205/bundle) to work.

### To and from XML
Currently not supported, [let everyone know you need it](https:/asyncapi/modelina/issues/new?assignees=&labels=enhancement&template=enhancement.md)!

### To and from binary
Currently not supported, [let everyone know you need it](https:/asyncapi/modelina/issues/new?assignees=&labels=enhancement&template=enhancement.md)!
27 changes: 23 additions & 4 deletions docs/languages/JavaScript.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ There are special use-cases that each language supports; this document pertains
<!-- toc -->

- [Rendering complete models to a specific module system](#rendering-complete-models-to-a-specific-module-system)
- [Generate un/marshal functions for classes](#generate-unmarshal-functions-for-classes)
- [Generate serializer and deserializer functionality](#generate-serializer-and-deserializer-functionality)
* [To and from JSON](#to-and-from-json)
+ [Generate marshalling and unmarshalling functions](#generate-marshalling-and-unmarshalling-functions)
* [To and from XML](#to-and-from-xml)
* [To and from binary](#to-and-from-binary)
- [Generate example data function](#generate-example-data-function)

<!-- tocstop -->
Expand All @@ -18,15 +22,30 @@ Check out this [example for a live demonstration how to generate the complete Ja

Check out this [example for a live demonstration how to generate the complete JavaScript models to use CJS module system](../../examples/javascript-use-cjs).

## Generate serializer and deserializer functionality

## Generate un/marshal functions for classes
The most widely used usecase for Modelina is to generate models that include serilization and deserialization functionality to convert the models into payload data. This payload data can of course be many different kinds, JSON, XML, raw binary, you name it.

Sometimes you want to use the models for data transfers, and while most cases would work out of the box, custom serializer functionality is needed for the advanced cases. If you generated the data models based on a JSON Schema document and you want the serialized data to validate against the schema, this functionality is REQUIRED.
As you normally only need one library to do this, we developers can never get enough with creating new stuff, therefore there might be one specific library you need or want to integrate with. Therefore there is not one specific preset that offers everything. Below is a list of all the supported serialization presets.

### To and from JSON
Here are all the supported presets and the libraries they use:

- [Generate marshalling and unmarshalling functions](#generate-marshalling-and-unmarshalling-functions)

#### Generate marshalling and unmarshalling functions

Using the preset `JS_COMMON_PRESET` with the option `marshalling` to `true`, renders two function for the class models. One which convert the model to JSON and another which convert the model from JSON to an instance of the class.

Here, this can be done by including the preset `JS_COMMON_PRESET` using the option `marshalling`.

Check out this [example out for a live demonstration](../../examples/javascript-generate-marshalling).

### To and from XML
Currently not supported, [let everyone know you need it](https:/asyncapi/modelina/issues/new?assignees=&labels=enhancement&template=enhancement.md)!

### To and from binary
Currently not supported, [let everyone know you need it](https:/asyncapi/modelina/issues/new?assignees=&labels=enhancement&template=enhancement.md)!

## Generate example data function

Generate example instance of the data model including the preset `JS_COMMON_PRESET` using the option `example`.
Expand Down
Loading