Update HTTP Endpoint type definition renderer
This commit is contained in:
parent
54ed32ebbc
commit
e31f804ec0
|
|
@ -15,6 +15,8 @@ namespace Elsa.Activities.Http.JavaScript
|
|||
{
|
||||
public class HttpEndpointTypeDefinitionRenderer : DefaultActivityTypeDefinitionRenderer
|
||||
{
|
||||
public override bool GetCanRenderType(ActivityType activityType) => activityType.Type == typeof(HttpEndpoint);
|
||||
|
||||
public override async ValueTask RenderTypeDeclarationAsync(
|
||||
RenderingTypeScriptDefinitions notification,
|
||||
ActivityType activityType,
|
||||
|
|
@ -23,27 +25,24 @@ namespace Elsa.Activities.Http.JavaScript
|
|||
StringBuilder writer,
|
||||
CancellationToken cancellationToken = default)
|
||||
{
|
||||
if (activityType.Type == typeof(HttpEndpoint))
|
||||
var targetTypeSchema = activityDefinition.Properties.First(x => x.Name == nameof(HttpEndpoint.Schema)).Expressions.Values.First();
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(targetTypeSchema))
|
||||
{
|
||||
var targetTypeSchema = activityDefinition.Properties.First(x => x.Name == nameof(HttpEndpoint.Schema)).Expressions.Values.First();
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(targetTypeSchema))
|
||||
var jsonSchema = await JsonSchema.FromJsonAsync(targetTypeSchema, cancellationToken);
|
||||
var generator = new TypeScriptGenerator(jsonSchema, new TypeScriptGeneratorSettings
|
||||
{
|
||||
var jsonSchema = await JsonSchema.FromJsonAsync(targetTypeSchema, cancellationToken);
|
||||
var generator = new TypeScriptGenerator(jsonSchema, new TypeScriptGeneratorSettings
|
||||
{
|
||||
TypeStyle = TypeScriptTypeStyle.Interface,
|
||||
TypeScriptVersion = 4
|
||||
});
|
||||
TypeStyle = TypeScriptTypeStyle.Interface,
|
||||
TypeScriptVersion = 4
|
||||
});
|
||||
|
||||
var typeScriptType = $"{activityDefinition.Name}Output";
|
||||
var typeScriptType = $"{activityDefinition.Name}Output";
|
||||
|
||||
var jsonSchemaTypes = generator.GenerateFile(typeScriptType)
|
||||
.Replace("\r\n", "\n")
|
||||
.Replace("export interface", "declare class");
|
||||
var jsonSchemaTypes = generator.GenerateFile(typeScriptType)
|
||||
.Replace("\r\n", "\n")
|
||||
.Replace("export interface", "declare class");
|
||||
|
||||
writer.AppendLine(jsonSchemaTypes);
|
||||
}
|
||||
writer.AppendLine(jsonSchemaTypes);
|
||||
}
|
||||
|
||||
await base.RenderTypeDeclarationAsync(notification, activityType, activityDescriptor, activityDefinition, writer, cancellationToken);
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ namespace Elsa.Scripting.JavaScript.Providers
|
|||
public class DefaultActivityTypeDefinitionRenderer : IActivityTypeDefinitionRenderer
|
||||
{
|
||||
public int Priority => -1;
|
||||
public bool GetCanRenderType(ActivityType activityType) => true;
|
||||
public virtual bool GetCanRenderType(ActivityType activityType) => true;
|
||||
|
||||
public virtual async ValueTask RenderTypeDeclarationAsync(
|
||||
RenderingTypeScriptDefinitions notification,
|
||||
|
|
|
|||
Loading…
Reference in a new issue