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

Create umbraco-jsonschema .NET tool to generate JSON schemas #13560

Closed
wants to merge 4 commits into from

Conversation

ronaldbarendse
Copy link
Contributor

@ronaldbarendse ronaldbarendse commented Dec 12, 2022

Prerequisites

  • I have added steps to test this contribution in the description below

Description

This converts the Umbraco.JsonSchema console application into a .NET tool to generate JSON schemas from a specific type in an assembly file.

Although the CMS still directly invokes the console application to generate the JSON schema for the CMS (at least for now), it now does so in the same way as invoking it as a .NET tool.

To this this, first check whether the Umbraco.Cms.Targets NuGet package still includes the generated appsettings-schema.Umbraco.Cms.json file (both on a local build and in the Azure Pipeline build artifacts). Next, create a local build, install the tool and generate the JSON schema using:

dotnet pack --configuration Release --output build.out
dotnet tool install Umbraco.JsonSchema --global --add-source build.out --prerelease
umbraco-jsonschema --assembly src\Umbraco.Cms.Targets\bin\Release\net7.0\Umbraco.Cms.Targets.dll --type Umbraco.Cms.Targets.UmbracoCmsSchema --output appsettings-schema.Umbraco.Cms.json

After validating whether the generated JSON schema is correct, you can uninstall this global tool using dotnet tool uninstall Umbraco.JsonSchema --global.


We might want to move this into a separate repository, since we don't need new releases with every CMS version and the CMS can then also use the tool. Either way, once this tool is published on NuGet, this can be used as a local tool by other packages:

dotnet new tool-manifest
dotnet tool install Umbraco.JsonSchema

You can then create the C# class to generate the JSON schema from (e.g. Umbraco.Forms.UmbracoFormsSchema) and add this to the same project file to automatically generate it on build and include it as part of the NuGet package (this generated JSON schema file can be added to .gitignore):

<Project Sdk="Microsoft.NET.Sdk">
  <ItemGroup>
    <Content Include="buildTransitive\**" PackagePath="buildTransitive" />
    <Content Include="appsettings-schema.Umbraco.Forms.json" PackagePath="" Visible="false" />
  </ItemGroup>

  <!-- Generate JSON schema on build -->
  <Target Name="GenerateJsonSchema" AfterTargets="Build" Condition="!Exists('appsettings-schema.Umbraco.Forms.json')">
    <Exec Command="dotnet tool run umbraco-jsonschema --assembly &quot;$(TargetPath)&quot; --type &quot;Umbraco.Forms.UmbracoFormsSchema&quot; --output &quot;appsettings-schema.Umbraco.Forms.json&quot;" />
  </Target>

  <!-- Delete generated JSON schema on clean -->
  <Target Name="CleanJsonSchema" AfterTargets="Clean" Condition="Exists('appsettings-schema.Umbraco.Forms.json')">
    <Delete Files="appsettings-schema.Umbraco.Forms.json" />
  </Target>
</Project>

The following build property file (e.g. buildTransitive\Umbraco.Forms.props) ensures the JSON schema that's included in the NuGet package gets automatically copied into the Umbraco project directory and added as a reference in the appsettings-schema.json file:

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <ItemGroup>
    <UmbracoJsonSchemaFiles Include="$(MSBuildThisFileDirectory)..\appsettings-schema.Umbraco.Forms.json" />
  </ItemGroup>
</Project>

@iOvergaard
Copy link
Contributor

This has grown stale, but feel free to recreate it against v15/dev if you still deem it relevant!

@iOvergaard iOvergaard closed this Nov 21, 2024
@iOvergaard iOvergaard added the status/stale Marked as stale due to inactivity label Nov 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status/stale Marked as stale due to inactivity
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants