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 constraint documentation #858

Merged
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
24 changes: 17 additions & 7 deletions docs/constraints.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Constraints
Because we cannot control what is provided as input, we must constrain the internal model to be valid for the output ([read more about the process here](./processing.md)). What is considered valid entirely depends on the output so each have their own set of rules.
Because we cannot control what is provided as input, we must constrain the internal model to be valid for the output ([read more about the process here](./internal-model.md)). What is considered valid entirely depends on the output so each have their own set of rules.

As an example lets consider TypeScript as an output. Consider the model name, which are a simple string, but a string which can contain ANY characters. Some of the constraints we have found for the naming of a model are:
As an example lets consider TypeScript as an output. Consider the model name, which are a simple string, but a string which can contain ANY characters and formats. Some of the constraints we have found for the naming of a model are:

- Only a section of special characters are allowed as name for a model. For example `&name` cannot be rendered as class name, because it is syntactically incorrect:
```ts
Expand All @@ -12,15 +12,25 @@ class &name {}
class 1name {}
```

There are many rules as such, to get the full description about them read further for each corresponding output:
There are many rules as such, but to get the full description about the default constraints here:

- [C#](./constraints/CSharp.md)
- [Dart](./constraints/Dart.md)
- [Go](./constraints/Go.md)
- [Java](./constraints/Java.md)
- [JavaScript](./constraints/JavaScript.md)
- [Rust](./constraints/Rust.md)
- [TypeScript](./constraints/TypeScript.md)

# Customization
Even though there are many of these constraints, there might be reasons you want to customize the behavior to make it suit your use-case. Therefore each of the constraint rules can be overwritten completely and allow for you to implement your own behavior.

We define these as two types, either you only want to change part of the logic, or you want to overwrite the entire constraint logic.

See the following example how to overwrite the constraints:
- [Overwriting the formatter](../examples/overwrite-naming-formatting) and keep the rest of the constraints as is.
- [Overwriting the entire naming constraint logic](../examples/overwrite-naming-formatting) keeping none of the existing functionality which handles edge cases. It is recommended to **NOT** use this if it can be avoided, as you will limit yourself to what inputs can be generated to models. So make sure you know what you are doing :laughing:
- [Overwriting the entire naming constraint logic](../examples/overwrite-naming-formatting) keeping none of the existing functionality which handles edge cases. It is recommended to **NOT** use this if it can be avoided, as you will limit yourself to what inputs can be generated to models. So make sure you know what you are doing :laughing:

# Type mapping
To make it easier to use the meta models in presets and generators, we need to figure out the types for each model. This is to enable you to access the types from a property rather then calling a function. This is especially relevant because Modelina cannot fit all use-cases out of the box, and we therefore strive to make it tailorable to what ever your needs may be. The type mapping is one of those things that enable you to fine tune the types for your purpose.

Of course it's not all output formats that have a type such as JavaScript, therefore these are only used for strongly typed outputs.

You can checkout this example how to [change the type mapping](../examples/change-type-mapping/).
38 changes: 38 additions & 0 deletions docs/constraints/CSharp.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# C# Constraints

These are the C# specific constraints applied to the MetaModel before reaching the presets. [Read here to get a more general idea on the overall process](../input-processing.md) of converting a MetaModel to a ConstrainedMetaModel.

## Model Naming
These are the constraints that is applied to model naming. The `Rule key` is what you can use in the options to overwrite the default behavior. See [constraint customization](../constraints.md#Customization).

|Rule key|Rule|Resolution|
|---|---|---|
|NO_SPECIAL_CHAR|No special characters| Special characters are replaced by their name, for example `!` is replaced with `exclamation`. For csharp `_` and `$` are an exception to this rule. |
|NO_NUMBER_START_CHAR|No numbers as starting characters|Default behavior is pre pending `number_` in front of the first character|
|NO_EMPTY_VALUE|No empty values|Default behavior is to use `empty` as name. |
|NO_RESERVED_KEYWORDS|No reserved keywords|C# has a list of reserved keywords ([see the full list here](../../src/generators/csharp/Constants.ts))|
|NAMING_FORMATTER|Must be formatted equally|Model name is formatted using pascal case|

## Property naming
These are the constraints that is applied to object properties and the naming of them. The `Rule key` is what you can use in the options to overwrite the default behavior. See [constraint customization](../constraints.md#Customization).
|Rule key|Rule|Resolution|
|---|---|---|
|NO_SPECIAL_CHAR|No special characters| Special characters are replaced by their name, for example `!` is replaced with `exclamation`. For csharp `_` and `$` are an exception to this rule. |
|NO_NUMBER_START_CHAR|No numbers as starting characters|Default behavior is pre pending `number_` in front of the first character|
|NO_EMPTY_VALUE|No empty values|Default behavior is to use `empty` as name. |
|NO_RESERVED_KEYWORDS|No reserved keywords|C# has a list of reserved keywords ([see the full list here](../../src/generators/csharp/Constants.ts))|
|NAMING_FORMATTER|Must be formatted equally|Model name is formatted using pascal case|
|NO_DUPLICATE_PROPERTIES|No duplicate properties|If any of the above constraints changes the property name, we must make sure that no duplicates exist within the same object. If any is encountered `reserved_` is pre-pended. This is done recursively until no duplicates are found.|


## Enum key constraints
These are the constraints that is applied to enum keys. The `Rule key` is what you can use in the options to overwrite the default behavior. See [constraint customization](../constraints.md#Customization).

|Rule key|Rule|Resolution|
|---|---|---|
|NO_SPECIAL_CHAR|No special characters| Special characters are replaced by their name, for example `!` is replaced with `exclamation`. For csharp `_` and `$` are an exception to this rule. |
|NO_NUMBER_START_CHAR|No numbers as starting characters|Default behavior is pre pending `number_` in front of the first character|
|NO_EMPTY_VALUE|No empty values|Default behavior is to use `empty` as name. |
|NO_RESERVED_KEYWORDS|No reserved keywords|C# has a list of reserved keywords ([see the full list here](../../src/generators/csharp/Constants.ts))|
|NAMING_FORMATTER|Must be formatted equally|Model name is formatted using pascal case|
|NO_DUPLICATE_KEYS|No duplicate enum keys|If any of the above constraints changes the enum key, we must make sure that no duplicates exist within the same enum. If any is encountered `reserved_` is pre-pended. This is done recursively until no duplicates are found.|
38 changes: 38 additions & 0 deletions docs/constraints/Dart.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Dart Constraints

These are the Dart specific constraints applied to the MetaModel before reaching the presets. [Read here to get a more general idea on the overall process](../input-processing.md) of converting a MetaModel to a ConstrainedMetaModel.

## Model Naming
These are the constraints that is applied to model naming. The `Rule key` is what you can use in the options to overwrite the default behavior. See [constraint customization](../constraints.md#Customization).

|Rule key|Rule|Resolution|
|---|---|---|
|NO_SPECIAL_CHAR|No special characters| Special characters are replaced by their name, for example `!` is replaced with `exclamation`. For dart `_` and `$` are an exception to this rule. |
|NO_NUMBER_START_CHAR|No numbers as starting characters|Default behavior is pre pending `number_` in front of the first character|
|NO_EMPTY_VALUE|No empty values|Default behavior is to use `empty` as name. |
|NO_RESERVED_KEYWORDS|No reserved keywords|Dart has a list of reserved keywords ([see the full list here](../../src/generators/dart/Constants.ts))|
|NAMING_FORMATTER|Must be formatted equally|Model name is formatted using pascal case|

## Property naming
These are the constraints that is applied to object properties and the naming of them. The `Rule key` is what you can use in the options to overwrite the default behavior. See [constraint customization](../constraints.md#Customization).
|Rule key|Rule|Resolution|
|---|---|---|
|NO_SPECIAL_CHAR|No special characters| Special characters are replaced by their name, for example `!` is replaced with `exclamation`. For dart `_` and `$` are an exception to this rule. |
|NO_NUMBER_START_CHAR|No numbers as starting characters|Default behavior is pre pending `number_` in front of the first character|
|NO_EMPTY_VALUE|No empty values|Default behavior is to use `empty` as name. |
|NO_RESERVED_KEYWORDS|No reserved keywords|Dart has a list of reserved keywords ([see the full list here](../../src/generators/dart/Constants.ts))|
|NAMING_FORMATTER|Must be formatted equally|Model name is formatted using pascal case|
|NO_DUPLICATE_PROPERTIES|No duplicate properties|If any of the above constraints changes the property name, we must make sure that no duplicates exist within the same object. If any is encountered `reserved_` is pre-pended. This is done recursively until no duplicates are found.|


## Enum key constraints
These are the constraints that is applied to enum keys. The `Rule key` is what you can use in the options to overwrite the default behavior. See [constraint customization](../constraints.md#Customization).

|Rule key|Rule|Resolution|
|---|---|---|
|NO_SPECIAL_CHAR|No special characters| Special characters are replaced by their name, for example `!` is replaced with `exclamation`. For dart `_` and `$` are an exception to this rule. |
|NO_NUMBER_START_CHAR|No numbers as starting characters|Default behavior is pre pending `number_` in front of the first character|
|NO_EMPTY_VALUE|No empty values|Default behavior is to use `empty` as name. |
|NO_RESERVED_KEYWORDS|No reserved keywords|Dart has a list of reserved keywords ([see the full list here](../../src/generators/dart/Constants.ts))|
|NAMING_FORMATTER|Must be formatted equally|Model name is formatted using pascal case|
|NO_DUPLICATE_KEYS|No duplicate enum keys|If any of the above constraints changes the enum key, we must make sure that no duplicates exist within the same enum. If any is encountered `reserved_` is pre-pended. This is done recursively until no duplicates are found.|
38 changes: 38 additions & 0 deletions docs/constraints/Go.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Go Constraints

These are the Go specific constraints applied to the MetaModel before reaching the presets. [Read here to get a more general idea on the overall process](../input-processing.md) of converting a MetaModel to a ConstrainedMetaModel.

## Model Naming
These are the constraints that is applied to model naming. The `Rule key` is what you can use in the options to overwrite the default behavior. See [constraint customization](../constraints.md#Customization).

|Rule key|Rule|Resolution|
|---|---|---|
|NO_SPECIAL_CHAR|No special characters| Special characters are replaced by their name, for example `!` is replaced with `exclamation`. For go `_` and `$` are an exception to this rule. |
|NO_NUMBER_START_CHAR|No numbers as starting characters|Default behavior is pre pending `number_` in front of the first character|
|NO_EMPTY_VALUE|No empty values|Default behavior is to use `empty` as name. |
|NO_RESERVED_KEYWORDS|No reserved keywords|Go has a list of reserved keywords ([see the full list here](../../src/generators/go/Constants.ts))|
|NAMING_FORMATTER|Must be formatted equally|Model name is formatted using pascal case|

## Property naming
These are the constraints that is applied to object properties and the naming of them. The `Rule key` is what you can use in the options to overwrite the default behavior. See [constraint customization](../constraints.md#Customization).
|Rule key|Rule|Resolution|
|---|---|---|
|NO_SPECIAL_CHAR|No special characters| Special characters are replaced by their name, for example `!` is replaced with `exclamation`. For go `_` and `$` are an exception to this rule. |
|NO_NUMBER_START_CHAR|No numbers as starting characters|Default behavior is pre pending `number_` in front of the first character|
|NO_EMPTY_VALUE|No empty values|Default behavior is to use `empty` as name. |
|NO_RESERVED_KEYWORDS|No reserved keywords|Go has a list of reserved keywords ([see the full list here](../../src/generators/go/Constants.ts))|
|NAMING_FORMATTER|Must be formatted equally|Model name is formatted using pascal case|
|NO_DUPLICATE_PROPERTIES|No duplicate properties|If any of the above constraints changes the property name, we must make sure that no duplicates exist within the same object. If any is encountered `reserved_` is pre-pended. This is done recursively until no duplicates are found.|


## Enum key constraints
These are the constraints that is applied to enum keys. The `Rule key` is what you can use in the options to overwrite the default behavior. See [constraint customization](../constraints.md#Customization).

|Rule key|Rule|Resolution|
|---|---|---|
|NO_SPECIAL_CHAR|No special characters| Special characters are replaced by their name, for example `!` is replaced with `exclamation`. For go `_` and `$` are an exception to this rule. |
|NO_NUMBER_START_CHAR|No numbers as starting characters|Default behavior is pre pending `number_` in front of the first character|
|NO_EMPTY_VALUE|No empty values|Default behavior is to use `empty` as name. |
|NO_RESERVED_KEYWORDS|No reserved keywords|Go has a list of reserved keywords ([see the full list here](../../src/generators/go/Constants.ts))|
|NAMING_FORMATTER|Must be formatted equally|Model name is formatted using pascal case|
|NO_DUPLICATE_KEYS|No duplicate enum keys|If any of the above constraints changes the enum key, we must make sure that no duplicates exist within the same enum. If any is encountered `reserved_` is pre-pended. This is done recursively until no duplicates are found.|
38 changes: 38 additions & 0 deletions docs/constraints/Java.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Java Constraints

These are the Java specific constraints applied to the MetaModel before reaching the presets. [Read here to get a more general idea on the overall process](../input-processing.md) of converting a MetaModel to a ConstrainedMetaModel.

## Model Naming
These are the constraints that is applied to model naming. The `Rule key` is what you can use in the options to overwrite the default behavior. See [constraint customization](../constraints.md#Customization).

|Rule key|Rule|Resolution|
|---|---|---|
|NO_SPECIAL_CHAR|No special characters| Special characters are replaced by their name, for example `!` is replaced with `exclamation`. For java `_` and `$` are an exception to this rule. |
|NO_NUMBER_START_CHAR|No numbers as starting characters|Default behavior is pre pending `number_` in front of the first character|
|NO_EMPTY_VALUE|No empty values|Default behavior is to use `empty` as name. |
|NO_RESERVED_KEYWORDS|No reserved keywords|Java has a list of reserved keywords ([see the full list here](../../src/generators/java/Constants.ts))|
|NAMING_FORMATTER|Must be formatted equally|Model name is formatted using pascal case|

## Property naming
These are the constraints that is applied to object properties and the naming of them. The `Rule key` is what you can use in the options to overwrite the default behavior. See [constraint customization](../constraints.md#Customization).
|Rule key|Rule|Resolution|
|---|---|---|
|NO_SPECIAL_CHAR|No special characters| Special characters are replaced by their name, for example `!` is replaced with `exclamation`. For java `_` and `$` are an exception to this rule. |
|NO_NUMBER_START_CHAR|No numbers as starting characters|Default behavior is pre pending `number_` in front of the first character|
|NO_EMPTY_VALUE|No empty values|Default behavior is to use `empty` as name. |
|NO_RESERVED_KEYWORDS|No reserved keywords|Java has a list of reserved keywords ([see the full list here](../../src/generators/java/Constants.ts))|
|NAMING_FORMATTER|Must be formatted equally|Model name is formatted using pascal case|
|NO_DUPLICATE_PROPERTIES|No duplicate properties|If any of the above constraints changes the property name, we must make sure that no duplicates exist within the same object. If any is encountered `reserved_` is pre-pended. This is done recursively until no duplicates are found.|


## Enum key constraints
These are the constraints that is applied to enum keys. The `Rule key` is what you can use in the options to overwrite the default behavior. See [constraint customization](../constraints.md#Customization).

|Rule key|Rule|Resolution|
|---|---|---|
|NO_SPECIAL_CHAR|No special characters| Special characters are replaced by their name, for example `!` is replaced with `exclamation`. For java `_` and `$` are an exception to this rule. |
|NO_NUMBER_START_CHAR|No numbers as starting characters|Default behavior is pre pending `number_` in front of the first character|
|NO_EMPTY_VALUE|No empty values|Default behavior is to use `empty` as name. |
|NO_RESERVED_KEYWORDS|No reserved keywords|Java has a list of reserved keywords ([see the full list here](../../src/generators/java/Constants.ts))|
|NAMING_FORMATTER|Must be formatted equally|Model name is formatted using pascal case|
|NO_DUPLICATE_KEYS|No duplicate enum keys|If any of the above constraints changes the enum key, we must make sure that no duplicates exist within the same enum. If any is encountered `reserved_` is pre-pended. This is done recursively until no duplicates are found.|
Loading