2021-06-24 08:47:37 +02:00
|
|
|
|
using System;
|
2021-06-24 09:58:38 +02:00
|
|
|
|
using System.Diagnostics;
|
|
|
|
|
|
using System.IO;
|
|
|
|
|
|
using System.Reflection;
|
2021-06-24 08:47:37 +02:00
|
|
|
|
using System.Threading.Tasks;
|
2021-06-24 09:58:38 +02:00
|
|
|
|
using System.Xml.Schema;
|
2021-06-24 08:47:37 +02:00
|
|
|
|
using CommandLine;
|
|
|
|
|
|
using Newtonsoft.Json;
|
|
|
|
|
|
using Newtonsoft.Json.Converters;
|
|
|
|
|
|
using NJsonSchema;
|
|
|
|
|
|
using NJsonSchema.Generation;
|
|
|
|
|
|
|
|
|
|
|
|
namespace JsonSchema
|
|
|
|
|
|
{
|
|
|
|
|
|
class Program
|
|
|
|
|
|
{
|
|
|
|
|
|
public class Options
|
|
|
|
|
|
{
|
2021-06-24 09:58:38 +02:00
|
|
|
|
[Option('o', "outputFile", Required = false, HelpText = "Set path of the output file.", Default = "../../../../Umbraco.Web.UI.NetCore/umbraco/config/appsettings-schema.json")]
|
2021-06-24 08:47:37 +02:00
|
|
|
|
public string OutputFile { get; set; }
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static async Task Main(string[] args)
|
|
|
|
|
|
{
|
|
|
|
|
|
Parser.Default.ParseArguments<Options>(args)
|
|
|
|
|
|
.WithParsedAsync<Options>(Execute);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private static async Task Execute(Options options)
|
|
|
|
|
|
{
|
|
|
|
|
|
var result = GenerateJsonSchema();
|
|
|
|
|
|
|
2021-06-24 09:58:38 +02:00
|
|
|
|
var path = Path.Combine(Environment.CurrentDirectory, options.OutputFile);
|
|
|
|
|
|
await File.WriteAllTextAsync(path, result);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Console.WriteLine("File written at " + path);
|
2021-06-24 08:47:37 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private static string GenerateJsonSchema()
|
|
|
|
|
|
{
|
|
|
|
|
|
var settings = new JsonSchemaGeneratorSettings()
|
|
|
|
|
|
{
|
|
|
|
|
|
SchemaType = SchemaType.JsonSchema,
|
|
|
|
|
|
AlwaysAllowAdditionalObjectProperties = true,
|
|
|
|
|
|
SerializerSettings = new JsonSerializerSettings(),
|
|
|
|
|
|
TypeNameGenerator = new UmbracoPrefixedTypeNameGenerator()
|
|
|
|
|
|
};
|
|
|
|
|
|
settings.SerializerSettings.Converters.Add(new StringEnumConverter());
|
|
|
|
|
|
|
|
|
|
|
|
var generator = new JsonSchemaGenerator(settings);
|
|
|
|
|
|
|
2021-06-24 09:45:52 +02:00
|
|
|
|
var schema = generator.Generate(typeof(AppSettings));
|
2021-06-24 08:47:37 +02:00
|
|
|
|
|
|
|
|
|
|
return schema.ToJson(Formatting.Indented);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|