Fix to Json Schema type definition parser
This commit is contained in:
parent
dd16c1921f
commit
c1104e35d4
|
|
@ -1,5 +1,4 @@
|
|||
using System;
|
||||
using System.Dynamic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
|
|
@ -8,8 +7,6 @@ using Elsa.Scripting.JavaScript.Events;
|
|||
using Elsa.Services;
|
||||
using Elsa.Services.Models;
|
||||
using MediatR;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Converters;
|
||||
|
||||
namespace Elsa.Scripting.JavaScript.Handlers
|
||||
{
|
||||
|
|
@ -143,11 +140,7 @@ namespace Elsa.Scripting.JavaScript.Handlers
|
|||
if (string.IsNullOrWhiteSpace(json))
|
||||
return null;
|
||||
|
||||
#pragma warning disable CS8600 // Converting null literal or possible null value to non-nullable type.
|
||||
dynamic data = JsonConvert.DeserializeObject<ExpandoObject>(json, new ExpandoObjectConverter());
|
||||
#pragma warning restore CS8600 // Converting null literal or possible null value to non-nullable type.
|
||||
string title = data != null ? data.title : "Schema";
|
||||
return title;
|
||||
return "Json";
|
||||
}
|
||||
|
||||
string? GetActivityTargetType(Models.ActivityDefinition activity)
|
||||
|
|
|
|||
|
|
@ -1,14 +1,9 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Dynamic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Elsa.Models;
|
||||
using Elsa.Scripting.JavaScript.Providers;
|
||||
using MediatR;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Converters;
|
||||
using NJsonSchema;
|
||||
using NJsonSchema.CodeGeneration.TypeScript;
|
||||
|
||||
|
|
@ -16,14 +11,7 @@ namespace Elsa.Scripting.JavaScript.Services
|
|||
{
|
||||
public class JsonTypeScriptDefinitionProvider : ITypeScriptDefinitionProvider
|
||||
{
|
||||
private readonly IEnumerable<ITypeDefinitionProvider> _providers;
|
||||
private readonly IMediator _mediator;
|
||||
|
||||
public JsonTypeScriptDefinitionProvider(IEnumerable<ITypeDefinitionProvider> providers, IMediator mediator)
|
||||
{
|
||||
_providers = providers;
|
||||
_mediator = mediator;
|
||||
}
|
||||
public JsonTypeScriptDefinitionProvider() {}
|
||||
|
||||
public async Task<StringBuilder> GenerateTypeScriptDefinitionsAsync(StringBuilder builder, WorkflowDefinition? workflowDefinition = default, string? context = default, CancellationToken cancellationToken = default)
|
||||
{
|
||||
|
|
@ -39,19 +27,14 @@ namespace Elsa.Scripting.JavaScript.Services
|
|||
if (json == null) continue;
|
||||
|
||||
if (string.IsNullOrWhiteSpace(json)) continue;
|
||||
#pragma warning disable CS8600 // Converting null literal or possible null value to non-nullable type.
|
||||
dynamic data = JsonConvert.DeserializeObject<ExpandoObject>(json, new ExpandoObjectConverter());
|
||||
#pragma warning restore CS8600 // Converting null literal or possible null value to non-nullable type.
|
||||
string? title = data != null ? data.title : null;
|
||||
title = title != null ? title : "schema";
|
||||
|
||||
var schema = await JsonSchema.FromJsonAsync(json);
|
||||
var generator = new TypeScriptGenerator(schema, new TypeScriptGeneratorSettings {
|
||||
TypeStyle = TypeScriptTypeStyle.Class,
|
||||
TypeScriptVersion = 4
|
||||
});
|
||||
//var code = generator.GenerateTypes();
|
||||
var file = generator.GenerateFile(title)
|
||||
|
||||
var file = generator.GenerateFile("Json")
|
||||
.Replace("\r\n", "\n")
|
||||
.Replace("export class", "declare class")
|
||||
.Replace("export interface", "declare interface");
|
||||
|
|
|
|||
Loading…
Reference in a new issue