{"id":13314695,"url":"https://github.com/kontent-ai/model-generator-net","last_synced_at":"2025-09-10T19:35:12.310Z","repository":{"id":38420738,"uuid":"81316560","full_name":"kontent-ai/model-generator-net","owner":"kontent-ai","description":"Kontent.ai .NET model generator.","archived":false,"fork":false,"pushed_at":"2025-04-03T08:43:46.000Z","size":676,"stargazers_count":17,"open_issues_count":8,"forks_count":19,"subscribers_count":23,"default_branch":"master","last_synced_at":"2025-04-03T09:25:18.317Z","etag":null,"topics":["c-sharp","csharp","dotnet","dotnet-core","generator","hacktoberfest","kontent-ai","kontent-ai-tool","roslyn","templates"],"latest_commit_sha":null,"homepage":"https://www.nuget.org/packages/Kontent.Ai.ModelGenerator","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kontent-ai.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-02-08T10:15:08.000Z","updated_at":"2025-04-03T08:38:46.000Z","dependencies_parsed_at":"2023-12-12T14:44:11.951Z","dependency_job_id":null,"html_url":"https://github.com/kontent-ai/model-generator-net","commit_stats":null,"previous_names":[],"tags_count":101,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kontent-ai%2Fmodel-generator-net","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kontent-ai%2Fmodel-generator-net/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kontent-ai%2Fmodel-generator-net/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kontent-ai%2Fmodel-generator-net/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kontent-ai","download_url":"https://codeload.github.com/kontent-ai/model-generator-net/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252156937,"owners_count":21703378,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["c-sharp","csharp","dotnet","dotnet-core","generator","hacktoberfest","kontent-ai","kontent-ai-tool","roslyn","templates"],"created_at":"2024-07-29T18:11:53.512Z","updated_at":"2025-05-03T07:31:34.687Z","avatar_url":"https://github.com/kontent-ai.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Kontent.ai model generator utility for .NET\n\n[![Build \u0026 Test](https://github.com/kontent-ai/model-generator-net/actions/workflows/integrate.yml/badge.svg)](https://github.com/kontent-ai/model-generator-net/actions/workflows/integrate.yml)\n[![codecov](https://codecov.io/gh/kontent-ai/model-generator-net/branch/master/graph/badge.svg?token=9LvfJ7m8gT)](https://codecov.io/gh/kontent-ai/model-generator-net)\n[![Stack Overflow](https://img.shields.io/badge/Stack%20Overflow-ASK%20NOW-FE7A16.svg?logo=stackoverflow\u0026logoColor=white)](https://stackoverflow.com/tags/kontent-ai)\n[![Discord](https://img.shields.io/discord/821885171984891914?color=%237289DA\u0026label=Kontent%20Discord\u0026logo=discord)](https://discord.gg/SKCxwPtevJ)\n\n| Packages                  |                                                                Version                                                                |                                                              Downloads                                                              |                        Compatibility                         |        Documentation        |\n| ------------------------- | :-----------------------------------------------------------------------------------------------------------------------------------: | :---------------------------------------------------------------------------------------------------------------------------------: | :----------------------------------------------------------: | :-------------------------: |\n| Kontent.Ai.ModelGenerator | [![NuGet](https://img.shields.io/nuget/vpre/Kontent.Ai.ModelGenerator.svg)](https://www.nuget.org/packages/Kontent.Ai.ModelGenerator) | [![NuGet](https://img.shields.io/nuget/dt/Kontent.Ai.ModelGenerator.svg)](https://www.nuget.org/packages/Kontent.Ai.ModelGenerator) | [`net8.0`](https://dotnet.microsoft.com/download/dotnet/8.0) | [📖 Docs](./docs/README.md) |\n\nThis utility generates strongly-typed (POCO) models based on [content types](https://kontent.ai/learn/tutorials/manage-kontent/content-modeling/create-and-delete-content-types) in a Kontent.ai project environment. You can choose one of the following:\n\n- [Generate models compatible with the Kontent.ai Delivery SDK for .NET](#how-to-use-for-delivery-sdk)\n- [Generate models compatible with the Kontent.ai Management SDK for .NET](#how-to-use-for-management-sdk).\n\n⚠️ Please note that this tool uses [Delivery SDK](https://github.com/kontent-ai/delivery-sdk-net) and [Management SDK](https://github.com/kontent-ai/management-sdk-net).\n\n## How to use for [Delivery SDK](https://github.com/kontent-ai/delivery-sdk-net)\n\nTo fully understand all benefits of this approach, please read the [documentation](https://github.com/kontent-ai/delivery-sdk-net/blob/master/docs/customization-and-extensibility/strongly-typed-models.md#customizing-the-strong-type-binding-logic).\n\n### .NET Tool\n\nThe recommended way of obtaining this tool is installing it as a [.NET Tool](https://docs.microsoft.com/en-us/dotnet/core/tools/global-tools). You can install it as a global tool or per project as a local tool.\n\n#### Global Tool\n\n- `dotnet tool install -g Kontent.Ai.ModelGenerator`\n- `KontentModelGenerator --environmentid \"\u003cenvironmentId\u003e\" [--namespace \"\u003ccustom-namespace\u003e\"] [--outputdir \"\u003coutput-directory\u003e\"] [--withtypeprovider \u003cTrue|False\u003e] [--structuredmodel \"\u003cstructured_model\u003e\"] [--filenamesuffix \"\u003csuffix\u003e\"]`\n\n#### Local Tool\n\n- `dotnet new tool-manifest` to initialize the tools manifest (if you haven't done that already)\n- `dotnet tool install Kontent.Ai.ModelGenerator` (to install the latest version\n- `dotnet tool run KontentModelGenerator --environmentId \"\u003cenvironmentId\u003e\" [--namespace \"\u003ccustom-namespace\u003e\"] [--outputdir \"\u003coutput-directory\u003e\"] [--withtypeprovider \u003cTrue|False\u003e] [--structuredmodel \"\u003cstructured_model\u003e\"] [--filenamesuffix \"\u003csuffix\u003e\"]`\n\n### Standalone apps for Windows 🗔, Linux 🐧, macOS 🍎\n\n[Self-contained apps](https://docs.microsoft.com/en-us/dotnet/core/deploying/#publish-self-contained) are an ideal choice for machines without any version of .NET installed.\n\nLatest release: [Download](https://github.com/kontent-ai/model-generator-net/releases/latest)\n\n- `KontentModelGenerator --environmentId \"\u003cenvironmentId\u003e\" [--namespace \"\u003ccustom-namespace\u003e\"] [--outputdir \"\u003coutput-directory\u003e\"] [--withtypeprovider \u003cTrue|False\u003e] [--structuredmodel \"\u003cstructured_model\u003e\"] [--filenamesuffix \"\u003csuffix\u003e\"]`\n\nTo learn how to generate executables for your favorite target platform, follow the steps in the [docs](./docs/build-and-run.md).\n\n### Delivery API parameters\n\n| Short key |                Long key                  | Required |   Default value   | Description |\n| --------- | :--------------------------------------: | :------: | :---------------: | :--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------: |\n| `-i`      |            `--environmentId`             |   True   |      `null`       |                                                                                                                                                  A GUID that can be found in [Kontent.ai](https://app.kontent.ai) -\u003e Environment settings -\u003e Environment ID                                                                                                                                                      |\n| `-n`      |              `--namespace`               |  False   | `KontentAiModels` |                                                                                                                                                    A name of the [C# namespace](https://msdn.microsoft.com/en-us/library/z2kcy19k.aspx)                                                                                                                                                        |\n| `-o`      |              `--outputdir`               |  False   |       `\\.`        |                                                                                                                                                                                    An output folder path                                                                                                                                                                                       |\n| `-g`      |           `--generatepartials`           |  False   |      `true`       |                                                                                                                          Generates partial classes for customization. Partial classes are the best practice for customization so the recommended value is `true`.                                                                                                                              |\n| `-t`      |           `--withtypeprovider`           |  False   |      `true`       |                                          Indicates whether the `CustomTypeProvider` class should be generated (see [Customizing the strong-type binding logic](https://github.com/kontent-ai/delivery-sdk-net/blob/master/docs/customization-and-extensibility/strongly-typed-models.md#customizing-the-strong-type-binding-logic) for more info)                                              |\n| `-s`      |           `--structuredmodel`            |  False   |      `null`       | Allowed values [`RichText`, `DateTime`, `True`, `ModularContent`], as a separator you should use `,`. ⚠️ `True` parameter is **obsolete** and interprets the same value as `RichText`. For further details see [structured models rendering](https://github.com/kontent-ai/delivery-sdk-net/blob/master/docs/customization-and-extensibility/structured-models/structured-models-rendering.md) |\n| `-f`      |           `--filenamesuffix`             |  False   |      `null`       |                                                                                                                                                        Adds a suffix to generated filenames (e.g., News.cs becomes News.Generated.cs)                                                                                                                                                          |\n| `-b`      |              `--baseclass`               |  False   |      `null`       |                                                                                                                            If provided, a base class type will be created and all generated classes will derive from that base class via partial extender classes                                                                                                                              |\n| `-e`      |        `--extendeddeliverymodels`        |  False   |     `false`       |                                                                                                                                                                 Indicates whether extended deliver models should be generated                                                                                                                                                                  |\n| `-k`      |                 `--apikey`               |   True   |      `null`       |                                                                                                                                           Can be used with the extended delivery models. For details please see [Management API parameters section](#management-api-parameters)                                                                                                               |\n\nFor advanced configuration please see [Advanced configuration (Preview API, Secure API)](#advanced-configuration-preview-api-secure-api)\n\n### CLI Syntax\n\nShort keys such as `-t true` are interchangable with the long keys `--withtypeprovider true`. Other possible syntax is `-t=true` or `--withtypeprovider=true`. Parameter values are case-insensitive, so you can use both `-t=true` and `-t=True`. To see all aspects of the syntax, see the [MS docs](https://docs.microsoft.com/en-us/dotnet/api/microsoft.extensions.configuration.commandlineconfigurationextensions.addcommandline).\n\n### Config file\n\nThese parameters can also be set via the appSettings.json file located in the same directory as the executable file. Command-line parameters always take precedence.\n\n### Advanced configuration (Preview API, Secure API)\n\nThere are two ways of configuring advanced Delivery SDK options (such as secure API access, preview API access, and [others](https://github.com/kontent-ai/delivery-sdk-net/blob/master/Kontent.Ai.Delivery.Abstractions/Configuration/DeliveryOptions.cs)):\n\n1. Command-line arguments `--DeliveryOptions:UseSecureAccess true --DeliveryOptions:SecureAccessApiKey \u003cSecuredApiKey\u003e` ([syntax](https://docs.microsoft.com/en-us/dotnet/api/microsoft.extensions.configuration.commandlineconfigurationextensions.addcommandline))\n\n2. [`appSettings.json`](./src/Kontent.Ai.ModelGenerator/appSettings.json) - suitable for the standalone app release\n\n### Delivery API example output\n\n```csharp\nusing System;\nusing System.Collections.Generic;\nusing Kontent.Ai.Delivery.Abstractions;\n\nnamespace KontentAiModels\n{\n    public partial class CompleteContentType\n    {\n        public string Text { get; set; }\n        public string RichText { get; set; }\n        public decimal? Number { get; set; }\n        public IEnumerable\u003cMultipleChoiceOption\u003e MultipleChoice { get; set; }\n        public DateTime? DateTime { get; set; }\n        public IEnumerable\u003cAsset\u003e Asset { get; set; }\n        public IEnumerable\u003cobject\u003e ModularContent { get; set; }\n        public IEnumerable\u003cobject\u003e Subpages { get; set; }\n        public IEnumerable\u003cTaxonomyTerm\u003e Taxonomy { get; set; }\n        public string UrlSlug { get; set; }\n        public string CustomElement { get; set; }\n        public ContentItemSystemAttributes System { get; set; }\n    }\n}\n```\n\n### Customizing models - Extended delivery models\nProvides support to customize generated models based on content linked/subpages element constraints. This feature uses [Management SDK](https://github.com/kontent-ai/management-sdk-net) thus you'll need to provide api key as well.\n\n`KontentModelGenerator --environmentId \"\u003cenvironmentId\u003e\" -e true -k \"\u003capikey\u003e\"`\n\n#### Extended delivery models example output\nModel is generated using structured model option ModularContent.\nModel.Generated.cs\n\n```csharp\npublic partial class Home : IContentItem\n{\n    public const string SingleAllowedTypeAtMostOneLinkedContentItemCodename = \"single_allowed_type_at_most_one_linked_content_item\";\n    public const string SingleAllowedTypeSingleLinkedContentItemCodename = \"single_allowed_type_single_linked_content_item\";\n    public const string SingleAllowedTypeMultiLinkedContentItemsCodename = \"single_allowed_type_multi_linked_content_items\";\n    public const string MultiAllowedTypesSingleLinkedContentItemCodename = \"multi_allowed_types_single_linked_content_item\";\n    public const string MultiAllowedTypesAtMostSingleLinkedContentItemCodename = \"multi_allowed_types_at-most_single_linked_content_item\";\n    public const string MultiAllowedTypesMultiLinkedContentItemsCodename = \"multi_allowed_types_multi_linked_content_items\";\n\n    // Allowed Content Types == \"Article\" \u0026\u0026 Limit number of items \u003c= 1\n    public IEnumerable\u003cIContentItem\u003e SingleAllowedTypeAtMostOneLinkedContentItem { get; set; }\n    \n    // Allowed Content Types == \"Article\" \u0026\u0026 Limit number of items == 1\n    public IEnumerable\u003cIContentItem\u003e SingleAllowedTypeSingleLinkedContentItem { get; set; }\n    \n    // Allowed Content Types == \"Article\" \u0026\u0026 Limit number of items \u003e 1\n    public IEnumerable\u003cIContentItem\u003e SingleAllowedTypeMultiLinkedContentItems { get; set; }\n\n    // Allowed Content Types number \u003e 1 \u0026\u0026 Limit number of items == 1\n    public IEnumerable\u003cIContentItem\u003e MultiAllowedTypesExactlySingleLinkedContentItem { get; set; }\n\n    // Allowed Content Types number \u003e 1 \u0026\u0026 Limit number of items \u003c= 1\n    public IEnumerable\u003cIContentItem\u003e MultiAllowedTypesAtMostSingleLinkedContentItem { get; set; }\n\n    // Allowed Content Types number \u003e 1 \u0026\u0026 Limit number of items \u003e 1\n    public IEnumerable\u003cIContentItem\u003e MultiAllowedTypesMultiLinkedContentItems { get; set; }\n}\n```\n\nModel.Typed.Generated.cs\n\n```csharp\npublic partial class Home\n{\n    public Article SingleAllowedTypeAtMostOneLinkedContentItemSingle =\u003e SingleAllowedTypeAtMostOneLinkedContentItem.OfType\u003cArticle\u003e().FirstOrDefault();\n    \n    public Article SingleAllowedTypeSingleLinkedContentItemSingle =\u003e SingleAllowedTypeSingleLinkedContentItem.OfType\u003cArticle\u003e().FirstOrDefault();\n    \n    public IEnumerable\u003cArticle\u003e SingleAllowedTypeMultiLinkedContentItemsArticleTyped =\u003e SingleAllowedTypeMultiLinkedContentItems.OfType\u003cArticle\u003e();\n}\n```\n\n## How to use for [Management SDK](https://github.com/kontent-ai/management-sdk-net)\n\n### Usage\n\n```sh\nKontentModelGenerator.exe --environmentId \"\u003cenvironmentId\u003e\" --managementapi true --apikey \"\u003capikey\u003e\" [--namespace \"\u003ccustom-namespace\u003e\"] [--outputdir \"\u003coutput-directory\u003e\"] [--filenamesuffix \"\u003csuffix\u003e\"]\n```\n\n### Management API parameters\n\n| Short key |      Long key      | Required |   Default value   |                                                              Description                                                               |\n| --------- | :----------------: | :------: | :---------------: | :------------------------------------------------------------------------------------------------------------------------------------: |\n| `-p`      | `--environmentId`  |   True   |      `null`       |                        A GUID that can be found in [Kontent.ai](https://app.kontent.ai) -\u003e Environment settings -\u003e Environment ID                         |\n| `-m`      | `--managementapi`  |   True   |      `false`      |        Indicates that models should be generated for [Content Management SDK](https://github.com/kontent-ai/management-sdk-net)        |\n| `-k`      |     `--apikey`     |   True   |      `null`       |                     An api key that can be found in [Kontent.ai](https://app.kontent.ai) -\u003e Project settings -\u003e API keys -\u003e Management API keys                     |\n| `-n`      |   `--namespace`    |  False   | `KontentAiModels` |                          A name of the [C# namespace](https://msdn.microsoft.com/en-us/library/z2kcy19k.aspx)                          |\n| `-o`      |   `--outputdir`    |  False   |       `\\.`        |                                                         An output folder path                                                          |\n| `-f`      | `--filenamesuffix` |  False   |      `null`       |                             Adds a suffix to generated filenames (e.g., News.cs becomes News.Generated.cs)                             |\n| `-b`      |   `--baseclass`    |  False   |      `null`       | If provided, a base class type will be created and all generated classes will derive from that base class via partial extender classes |\n\nThese parameters can also be set via the appSettings.json file located in the same directory as the executable file. Command-line parameters always take precedence.\n\n### Management API example output\n\n\u003e `JsonProperty`'s attribute value is being generated from element codename (not from the type) and `KontentElementId` attribute value is element's ID.\n\n```csharp\nusing Kontent.Ai.Management.Models.LanguageVariants.Elements;\nusing Kontent.Ai.Management.Modules.ModelBuilders;\nusing Newtonsoft.Json;\n\nnamespace KontentAiModels\n{\n    public partial class CompleteContentType\n    {\n        [JsonProperty(\"text\")]\n        [KontentElementId(\"487f9540-0120-49dc-afb2-ee9bccb0c1d7\")]\n        public TextElement Text { get; set; }\n        [JsonProperty(\"rich_text\")]\n        [KontentElementId(\"4517b6da-ed36-48f2-9c8e-00cd6a4cb0ec\")]\n        public RichTextElement RichText { get; set; }\n        [JsonProperty(\"number\")]\n        [KontentElementId(\"4ea37483-c6b1-4b8a-8452-6046f4140923\")]\n        public NumberElement Number { get; set; }\n        [JsonProperty(\"multiple_choice\")]\n        [KontentElementId(\"8fc9a86f-d256-4786-a8f6-c8c90f6ca4e3\")]\n        public MultipleChoiceElement MultipleChoice { get; set; }\n        [JsonProperty(\"date_time\")]\n        [KontentElementId(\"d46fa45c-a1be-4bc7-8b8e-ed3c5521f83c\")]\n        public DateTimeElement DateTime { get; set; }\n        [JsonProperty(\"asset\")]\n        [KontentElementId(\"eb1d611d-b145-4ae3-b22e-ef3609572df0\")]\n        public AssetElement Asset { get; set; }\n        [JsonProperty(\"modular_content\")]\n        [KontentElementId(\"9e520c61-6879-4e83-bcc6-ee6e3e8ce9b4\")]\n        public LinkedItemsElement ModularContent { get; set; }\n        [JsonProperty(\"subpages\")]\n        [KontentElementId(\"fddd89e8-c370-4f9e-9b7d-9daa64d8a252\")]\n        public LinkedItemsElement Subpages { get; set; }\n        [JsonProperty(\"taxonomy\")]\n        [KontentElementId(\"a684d81c-68a7-40e1-85f9-2d22a71bebff\")]\n        public TaxonomyElement Taxonomy { get; set; }\n        [JsonProperty(\"url_slug\")]\n        [KontentElementId(\"1c724f49-b15f-42f5-aab4-4127aa5cf7be\")]\n        public UrlSlugElement UrlSlug { get; set; }\n        [JsonProperty(\"custom_element\")]\n        [KontentElementId(\"cb3b9df0-20df-461c-a0f7-4abb44b83c95\")]\n        public CustomElement CustomElement { get; set; }\n    }\n}\n```\n\n⚠️ Please note that _Guidelines_ element is not supported, thus it will not be included in the generated model.\n\n## Feedback \u0026 Contributing\n\nCheck out the [contributing](./CONTRIBUTING.md) page to see the best places to file issues, start discussions and begin contributing.\n\n### Wall of Fame\n\nWe would like to express our thanks to the following people who contributed and made the project possible:\n\n- [Dražen Janjiček](https://github.com/djanjicek) - [EXLRT](http://www.exlrt.com/)\n- [Kashif Jamal Soofi](https://github.com/kashifsoofi)\n- [Casey Brown](https://github.com/MajorGrits)\n\nWould you like to become a hero too? Pick an [issue](https://github.com/kontent-ai/model-generator-net/issues) and send us a pull request!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkontent-ai%2Fmodel-generator-net","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkontent-ai%2Fmodel-generator-net","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkontent-ai%2Fmodel-generator-net/lists"}