Skip to content
Draft
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
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,7 @@ packages/
*/mono_crash*
.vscode
.dccache
.sonarqube/
.sonarqube/
*/TestResults/
TestResults/
test-report_*.html
27 changes: 22 additions & 5 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,27 @@
### Version: 1.0.0-beta.1
### Version: 1.0.0
#### Date:

- Upgraded target framework from net7.0 to net10.0
- Updated CI/CD pipeline to use .NET 10 SDK (actions/setup-dotnet@v4)
- Updated Microsoft.AspNetCore.Mvc.Testing from 9.0.9 to 10.0.0
- Fixed GetHeader method visibility (private → internal) to allow test access
##### Breaking Changes:
- Removed the `Newtonsoft.Json` dependency entirely. Both the tool's internals and the models/converters it generates now use `System.Text.Json`.
- Generated model files now use `[JsonPropertyName]` instead of `[JsonProperty]`, and reference `System.Text.Json` / `System.Text.Json.Nodes` / `System.Text.Json.Serialization` instead of `Newtonsoft.Json`.
- Generated embedded-object and modular-block converters now inherit `System.Text.Json.Serialization.JsonConverter<T>` (`Read`/`Write`) instead of Newtonsoft's `JsonConverter<T>` (`ReadJson`/`WriteJson`). Regenerating models against an existing project will change these attributes and converters - update consuming code accordingly.
- Requires **.NET 10.0** or later (previously .NET 7.0).
- `ContentstackException` no longer supports legacy `BinaryFormatter`-based serialization (removed the obsolete `SerializationInfo`/`StreamingContext` constructor and `GetObjectData` override).

##### Enhancements:
- Upgraded target framework from net7.0 to net10.0.
- Updated CI/CD pipeline to use .NET 10 SDK (actions/setup-dotnet@v4).
- Updated Microsoft.AspNetCore.Mvc.Testing from 9.0.9 to 10.0.0.
- Migrated internal model DTOs (Field, MetaData, Contenttype, StackResponse, ContentStackError, OAuth token response) from `[JsonProperty]` to `[JsonPropertyName]`.
- Migrated OAuthService token exchange/refresh deserialization to `System.Text.Json`.
- Migrated the HTTP layer (IResponse, ContentstackResponse, HTTPRequestHandler, ContentstackHttpRequest) from Newtonsoft `JObject` to `System.Text.Json.Nodes.JsonObject`.
- Migrated ContentstackClient's serializer settings, response deserialization, and error parsing to `System.Text.Json` (`JsonSerializerOptions`, `JsonNode`).
- Migrated the code-generation templates (using statements, field attributes, link class, embedded-object converter, modular-block converter, and helper class) to emit `System.Text.Json`-based generated code.
- Fixed reference-field type resolution (`GetDatatypeForContentType`) to use `System.Text.Json.JsonElement` instead of the removed Newtonsoft `JArray`/`JObject` types.

##### Bug fix:
- Fixed GetHeader method visibility (private → internal) to allow test access.
- Fixed a template bug where the generated `embeddedItems` property's nullable annotation was emitted as literal text (`{nullableString()}`) instead of being applied, for content types with RTE-embedded references.

### Version: 0.5.1
#### Date: Jan-12-2026
Expand Down
73 changes: 54 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
# Contentstack model generator
This utility is use to generate models based on ContentTypes in Stack.

## Requirements
**As of v1.0.0**, this tool targets **.NET 10.0** and requires the **.NET 10.0 SDK or later**. Versions prior to v1.0.0 targeted .NET 7.0.

## Installation
To install Contenstack model generator run following command:
```
Expand All @@ -27,11 +30,11 @@ The Contentstack Model Generator supports two authentication methods:
| `-A` | `--authtoken` | The Authtoken for the Content Management API (required for traditional auth) |
| `-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` | `--namespace` | The namespace the classes should be created in (Default Value: ContentstackModels) |
| `-N` | `--is-nullable` | The features that protect against throwing a System.NullReferenceException can be disruptive when turned on. |
| `-f` | `--force` | Automatically overwrite files that already exist |
| `-m` | `--modular-block-prefix` | The Modular block Class Prefix. |
| `-g` | `--group-prefix` | The Group Class Prefix. |
| `-m` | `--modular-block-prefix` | The Modular block Class Prefix. (Default Value: MB) |
| `-g` | `--group-prefix` | The Group Class Prefix. (Default Value: Group) |
| `-p` | `--path` | Path to the file or directory to create files in. |

### OAuth 2.0 Options
Expand Down Expand Up @@ -106,40 +109,72 @@ Here's what you'll see when running an OAuth command:

$ contentstack.model.generator --oauth -a <api_key> --client-id myclient123 --redirect-uri http://localhost:8184

Contentstack Model Generator v0.5.0
=====================================

OAuth Authentication Required
=============================

Please open the following URL in your browser to authorize the application:

https://app.contentstack.com/#!/apps/6400aa06db64de001a31c8a9/authorize?response_type=code&client_id=myclient123&redirect_uri=http%3A%2F%2Flocalhost%3A8184&code_challenge=...
https://app.contentstack.com/#!/apps/6400aa06db64de001a31c8a9/authorize?response_type=code&client_id=myclient123&redirect_uri=http%3A%2F%2Flocalhost%3A8184&code_challenge=...&code_challenge_method=S256

After authorization, you will be redirected to a local URL.
Please copy the 'code' parameter from the redirect URL and paste it here:

Authorization code: [User pastes the code here]
Authorization code: [paste the code here]

Exchanging authorization code for access token...
OAuth authentication successful!
Access token expires at: 2024-01-15 14:30:00 UTC
Access token expires at: 2026-01-15 14:30:00 UTC
Fetching stack details for the provided API key.
No path specified. Generating files in the current working directory: /Users/you/project.
Fetching content types from My Contentstack Stack stack.
Found 5 content types.
Total content types fetched: 5.
Fetching global fields from stack: My Contentstack Stack.
Found 2 global fields.
Total global fields fetched: 2.
Generating files from content types.
Files created successfully.
Opening output directory: /Users/you/project.

Fetching stack information...
Stack: My Contentstack Stack
API Key: api_key
Logging out from OAuth...
OAuth logout successful!
```

Fetching content types...
Found 5 content types:
Generating files from content type
## Generated Code

Files successfully created!
Opening <file_path>/Models
**As of v1.0.0**, generated model files use **System.Text.Json** instead of Newtonsoft.Json:

Logging out from OAuth...
OAuth logout successful!
- Properties are decorated with `[JsonPropertyName("...")]` instead of `[JsonProperty(propertyName: "...")]`.
- Generated files reference `System.Text.Json`, `System.Text.Json.Nodes`, and `System.Text.Json.Serialization` instead of `Newtonsoft.Json`.
- Generated converters (for embedded objects and modular blocks) inherit `System.Text.Json.Serialization.JsonConverter<T>` and implement `Read`/`Write` instead of Newtonsoft's `JsonConverter<T>` with `ReadJson`/`WriteJson`.

A generated model file looks like this:

```csharp
using System;
using System.Text.Json;
using System.Text.Json.Nodes;
using System.Text.Json.Serialization;
using Contentstack.Core.Models;
using Contentstack.Utils.Interfaces;

namespace ContentstackModels.Models
{
public partial class BlogPost : IEmbeddedObject
{
public const string ContentType = "blog_post";
[JsonPropertyName("uid")]
public string Uid { get; set; }
[JsonPropertyName("_content_type_uid")]
public string ContentTypeUid { get; set; }
[JsonPropertyName("title")]
public string Title { get; set; }
}
}
```

**Breaking change:** if you regenerate models for an existing project using v1.0.0 or later, the attributes and converter base classes in the output will change from the Newtonsoft-based shape to the System.Text.Json-based shape shown above. Update your consuming code and Contentstack .NET SDK versions accordingly before regenerating.

### MIT License

Copyright (c) 2012-2026 Contentstack
Expand Down
Loading
Loading