Contentstack .NET Model Generator
This utility is used to generate models based on content types in stack.
Installation
To install Contenstack Model Generator, run following command:
dotnet tool install --global contentstack.model.generator
If you want to update your Model Generator, use the following:
dotnet tool update --global contentstack.model.generator
Note: In the above command, if you skip version, you will still be able to download the latest version of the Model Generator.
Use the Model Generator
Once you install the Contentstack Model Generator utility, run --help to view the list of available commands. The following table lists the shortcut keys for running specific operations:
Short key | Long Key | Description |
-a | --api-key | The stack API key for the Content Management API |
-A |
--authtoken | The authtoken for the Content Management API |
-b | --branch | The branch header in the API request to fetch or manage modules located within specific branches. |
-e | --endpoint | The Contentstack host for the Content Management API |
-n | --namespace | The namespace the classes should be created in |
-N | --is-nullable | The features that protect against throwing a System.NullReferenceException can be disruptive when turned on. |
-f | --force | Automatically overwrites files that already exist |
-m | --modular-block-prefix | The modular block class prefix |
-g | --group-prefix | The group class prefix |
-p | --path | Path of the file or a directory to create files in |
Example 1
To create classes in the current directory, run the following command:
contentstack.model.generator -a <stack_api_key> -A <authtoken>
Example 2
To create classes in a specific path, run the following command:
contentstack.model.generator -a <stack_api_key> -A <authtoken> -p /User/xxx/Desktop
Example 3
To create classes with namespace, run the following command:
contentstack.model.generator -a <stack_api_key> -A <authtoken> -n YourProject.Models
Example 4
To allow Nullable annotation context in model creation, run following command
contentstack.model.generator -a <stack_api_key> -A <authtoken> -N
Reference
For more details, refer to our GitHub page.