Code Monkey home page Code Monkey logo

kontent-generators-net's Introduction

Build status NuGet Stack Overflow

Kentico Kontent model generator utility for .NET

This utility generates strongly-typed models based on Content Types in a Kentico Kontent project. The models are supposed to be used together with the Kentico Kontent Delivery SDK for .NET or Kentico Kontent Content Management SDK for .NET. Please read the documentation to see all benefits of this approach.

Get the tool

.NET Core Global Tool

The recommended way of obtaining this tool is installing it as a .NET Core Global Tool.

  • Run dotnet tool install -g Kentico.Kontent.ModelGenerator

Then you can start using the KontentModelGenerator command in the command-line right away.

Windows

Latest release: Download

Note: The application is self-contained. There's no need to install any version of .NET on your machine.

Linux, Mac OS and other platforms

  • Clone the repository
  • Navigate to the kontent-generators-net\src\KontentModelGenerator folder
  • Run dotnet build -r <RID> to build the app
  • Run dotnet publish -c release -r <RID> to publish the app

See the list of all RIDs.

How to use for Delivery SDK

Windows

KontentModelGenerator.exe --projectid "<projectid>" [--namespace "<custom-namespace>"] [--outputdir "<output-directory>"] [--withtypeprovider] [--structuredmodel] [--filenamesuffix "<suffix>"]

Linux, Mac OS and other platforms

dotnet run --projectid "<projectid>" [--namespace "<custom-namespace>"] [--outputdir "<output-directory>"] [--withtypeprovider] [--structuredmodel] [--filenamesuffix "<suffix>"]

Parameters

Parameter (single character variant) Keyword variant Required Default value Description
-p --projectid True null A GUID that can be found in Kentico Kontent -> API keys -> Project ID
-n --namespace False KenticoKontentModels A name of the C# namespace
-o --outputdir False \. An output folder path
-g --generatepartials False null Generates partial classes for customizationfilenames
-t --withtypeprovider False true Indicates whether the CustomTypeProvider class should be generated (see Customizing the strong-type binding logic for more info)
-s --structuredmodel False false Generates IRichTextContent instead of string for rich-text elements. This enables utilizing structured rich-text rendering
-f --filenamesuffix False null Adds a suffix to generated filenames (e.g., News.cs becomes News.Generated.cs)
-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

These 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.

Example output

using System;
using System.Collections.Generic;
using Kentico.Kontent.Delivery;

namespace KenticoKontentModels
{
    public partial class CompleteContentType
    {
        public string Text { get; set; }
        public string RichText { get; set; }
        public decimal? Number { get; set; }
        public IEnumerable<MultipleChoiceOption> MultipleChoice { get; set; }
        public DateTime? DateTime { get; set; }
        public IEnumerable<Asset> Asset { get; set; }
        public IEnumerable<object> ModularContent { get; set; }
        public IEnumerable<TaxonomyTerm> Taxonomy { get; set; }
        public string UrlSlug { get; set; }
	public string CustomElement { get; set; }
        public ContentItemSystemAttributes System { get; set; }
    }
}

How to use for Content Management SDK

Windows

KontentModelGenerator.exe --projectid "<projectid>" --contentmanagementapi [--namespace "<custom-namespace>"] [--outputdir "<output-directory>"] [--filenamesuffix "<suffix>"]

Linux, Mac OS and other platforms

dotnet run --projectid "<projectid>" --contentmanagementapi [--namespace "<custom-namespace>"] [--outputdir "<output-directory>"] [--filenamesuffix "<suffix>"]

Parameters

Parameter (single character variant) Keyword variant Required Default value Description
-p --projectid True null A GUID that can be found in Kentico Kontent -> API keys -> Project ID
-c --contentmanagementapi True false Indicates that models should be generated for Content Management SDK
-n --namespace False KenticoKontentModels A name of the C# namespace
-o --outputdir False \. An output folder path
-f --filenamesuffix False null Adds a suffix to generated filenames (e.g., News.cs becomes News.Generated.cs)
-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

These 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.

Example output

using System;
using System.Collections.Generic;
using KenticoCloud.ContentManagement.Models.Assets;
using KenticoCloud.ContentManagement.Models.Items;
using Newtonsoft.Json;

namespace KenticoKontentModels
{
    public partial class CompleteContentType
    {
        public string Text { get; set; }
        public string RichText { get; set; }
        public decimal? Number { get; set; }
        public IEnumerable<MultipleChoiceOptionIdentifier> MultipleChoice { get; set; }
        public DateTime? DateTime { get; set; }
        public IEnumerable<AssetIdentifier> Asset { get; set; }
        public IEnumerable<ContentItemIdentifier> ModularContent { get; set; }
        public IEnumerable<TaxonomyTermIdentifier> Taxonomy { get; set; }
        public string UrlSlug { get; set; }
	public string CustomElement { get; set; }
    }
}

Feedback & Contributing

Check out the contributing page to see the best places to file issues, start discussions and begin contributing.

Wall of Fame

We would like to express our thanks to the following people who contributed and made the project possible:

Would you like to become a hero too? Pick an issue and send us a pull request!

Analytics

kontent-generators-net's People

Contributors

petrsvihlik avatar simply007 avatar kashifsoofi avatar ondrejsevcik avatar dconder avatar caseydbrown avatar tobiaskamenicky avatar jancerman avatar b1tf8er avatar matus-usiak avatar enngage avatar hejtmii avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.