mirror of https://github.com/Squidex/squidex.git
Browse Source
* Improve tests. Fix # Conflicts: # backend/src/Squidex.Data.EntityFramework/ServiceExtensions.cs # backend/src/Squidex.Data.MongoDb/ServiceExtensions.cs * Fix all tests * Add missing files. * More stuff. * Fix workflows stuff. * Fix state. * Temp * Build fix. * Fixespull/1214/head
committed by
GitHub
282 changed files with 20767 additions and 6324 deletions
@ -0,0 +1,27 @@ |
|||
// ==========================================================================
|
|||
// Squidex Headless CMS
|
|||
// ==========================================================================
|
|||
// Copyright (c) Squidex UG (haftungsbeschraenkt)
|
|||
// All rights reserved. Licensed under the MIT license.
|
|||
// ==========================================================================
|
|||
|
|||
using Squidex.Infrastructure.Validation; |
|||
using Squidex.Web; |
|||
|
|||
namespace Squidex.Areas.Api.Controllers.Rules.Models; |
|||
|
|||
[OpenApiRequest] |
|||
public sealed class DynamicCreateRuleDto |
|||
{ |
|||
/// <summary>
|
|||
/// The trigger properties.
|
|||
/// </summary>
|
|||
[LocalizedRequired] |
|||
public RuleTriggerDto Trigger { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// The action properties.
|
|||
/// </summary>
|
|||
[LocalizedRequired] |
|||
public Dictionary<string, object> Action { get; set; } |
|||
} |
|||
@ -0,0 +1,81 @@ |
|||
// ==========================================================================
|
|||
// Squidex Headless CMS
|
|||
// ==========================================================================
|
|||
// Copyright (c) Squidex UG (haftungsbeschraenkt)
|
|||
// All rights reserved. Licensed under the MIT license.
|
|||
// ==========================================================================
|
|||
|
|||
using NodaTime; |
|||
using Squidex.Infrastructure; |
|||
using Squidex.Web; |
|||
|
|||
namespace Squidex.Areas.Api.Controllers.Rules.Models; |
|||
|
|||
public sealed class DynamicRuleDto : Resource |
|||
{ |
|||
/// <summary>
|
|||
/// The ID of the rule.
|
|||
/// </summary>
|
|||
public DomainId Id { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// The user that has created the rule.
|
|||
/// </summary>
|
|||
public RefToken CreatedBy { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// The user that has updated the rule.
|
|||
/// </summary>
|
|||
public RefToken LastModifiedBy { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// The date and time when the rule has been created.
|
|||
/// </summary>
|
|||
public Instant Created { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// The date and time when the rule has been modified last.
|
|||
/// </summary>
|
|||
public Instant LastModified { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// The version of the rule.
|
|||
/// </summary>
|
|||
public long Version { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// Determines if the rule is enabled.
|
|||
/// </summary>
|
|||
public bool IsEnabled { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// Optional rule name.
|
|||
/// </summary>
|
|||
public string? Name { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// The trigger properties.
|
|||
/// </summary>
|
|||
public RuleTriggerDto Trigger { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// The action properties.
|
|||
/// </summary>
|
|||
public Dictionary<string, object> Action { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// The number of completed executions.
|
|||
/// </summary>
|
|||
public long NumSucceeded { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// The number of failed executions.
|
|||
/// </summary>
|
|||
public long NumFailed { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// The date and time when the rule was executed the last time.
|
|||
/// </summary>
|
|||
[Obsolete("Removed when migrated to new rule statistics.")] |
|||
public Instant? LastExecuted { get; set; } |
|||
} |
|||
@ -0,0 +1,24 @@ |
|||
// ==========================================================================
|
|||
// Squidex Headless CMS
|
|||
// ==========================================================================
|
|||
// Copyright (c) Squidex UG (haftungsbeschraenkt)
|
|||
// All rights reserved. Licensed under the MIT license.
|
|||
// ==========================================================================
|
|||
|
|||
using Squidex.Infrastructure; |
|||
using Squidex.Web; |
|||
|
|||
namespace Squidex.Areas.Api.Controllers.Rules.Models; |
|||
|
|||
public sealed class DynamicRulesDto : Resource |
|||
{ |
|||
/// <summary>
|
|||
/// The rules.
|
|||
/// </summary>
|
|||
public DynamicRuleDto[] Items { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// The ID of the rule that is currently rerunning.
|
|||
/// </summary>
|
|||
public DomainId? RunningRuleId { get; set; } |
|||
} |
|||
@ -0,0 +1,34 @@ |
|||
// ==========================================================================
|
|||
// Squidex Headless CMS
|
|||
// ==========================================================================
|
|||
// Copyright (c) Squidex UG (haftungsbeschraenkt)
|
|||
// All rights reserved. Licensed under the MIT license.
|
|||
// ==========================================================================
|
|||
|
|||
using Squidex.Web; |
|||
|
|||
namespace Squidex.Areas.Api.Controllers.Rules.Models; |
|||
|
|||
[OpenApiRequest] |
|||
public sealed class DynamicUpdateRuleDto |
|||
{ |
|||
/// <summary>
|
|||
/// Optional rule name.
|
|||
/// </summary>
|
|||
public string? Name { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// The trigger properties.
|
|||
/// </summary>
|
|||
public RuleTriggerDto? Trigger { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// The action properties.
|
|||
/// </summary>
|
|||
public Dictionary<string, object>? Action { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// Enable or disable the rule.
|
|||
/// </summary>
|
|||
public bool? IsEnabled { get; set; } |
|||
} |
|||
@ -0,0 +1,22 @@ |
|||
|
|||
Microsoft Visual Studio Solution File, Format Version 12.00 |
|||
# Visual Studio Version 17 |
|||
VisualStudioVersion = 17.12.35707.178 d17.12 |
|||
MinimumVisualStudioVersion = 10.0.40219.1 |
|||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Generator", "Generator\Generator.csproj", "{0BD7AC0B-640B-4D26-A9B9-C1CCEE4C14E7}" |
|||
EndProject |
|||
Global |
|||
GlobalSection(SolutionConfigurationPlatforms) = preSolution |
|||
Debug|Any CPU = Debug|Any CPU |
|||
Release|Any CPU = Release|Any CPU |
|||
EndGlobalSection |
|||
GlobalSection(ProjectConfigurationPlatforms) = postSolution |
|||
{0BD7AC0B-640B-4D26-A9B9-C1CCEE4C14E7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU |
|||
{0BD7AC0B-640B-4D26-A9B9-C1CCEE4C14E7}.Debug|Any CPU.Build.0 = Debug|Any CPU |
|||
{0BD7AC0B-640B-4D26-A9B9-C1CCEE4C14E7}.Release|Any CPU.ActiveCfg = Release|Any CPU |
|||
{0BD7AC0B-640B-4D26-A9B9-C1CCEE4C14E7}.Release|Any CPU.Build.0 = Release|Any CPU |
|||
EndGlobalSection |
|||
GlobalSection(SolutionProperties) = preSolution |
|||
HideSolutionNode = FALSE |
|||
EndGlobalSection |
|||
EndGlobal |
|||
@ -0,0 +1,30 @@ |
|||
<Project Sdk="Microsoft.NET.Sdk"> |
|||
|
|||
<PropertyGroup> |
|||
<OutputType>Exe</OutputType> |
|||
<TargetFramework>net8.0</TargetFramework> |
|||
<ImplicitUsings>enable</ImplicitUsings> |
|||
<Nullable>enable</Nullable> |
|||
</PropertyGroup> |
|||
|
|||
<ItemGroup> |
|||
<PackageReference Include="NJsonSchema.CodeGeneration.TypeScript" Version="11.2.0" /> |
|||
<PackageReference Include="NSwag.CodeGeneration.TypeScript" Version="14.3.0" /> |
|||
</ItemGroup> |
|||
|
|||
<ItemGroup> |
|||
<None Update="Templates\ConvertToClass.liquid"> |
|||
<CopyToOutputDirectory>Always</CopyToOutputDirectory> |
|||
</None> |
|||
<None Update="Templates\Class.liquid"> |
|||
<CopyToOutputDirectory>Always</CopyToOutputDirectory> |
|||
</None> |
|||
<None Update="Templates\ConvertToJavaScript.liquid"> |
|||
<CopyToOutputDirectory>Always</CopyToOutputDirectory> |
|||
</None> |
|||
<None Update="Templates\Enum.StringLiteral.liquid"> |
|||
<CopyToOutputDirectory>Always</CopyToOutputDirectory> |
|||
</None> |
|||
</ItemGroup> |
|||
|
|||
</Project> |
|||
@ -0,0 +1,165 @@ |
|||
using NJsonSchema; |
|||
using NJsonSchema.CodeGeneration.TypeScript; |
|||
using NSwag; |
|||
using NSwag.CodeGeneration.TypeScript; |
|||
using System.Text.RegularExpressions; |
|||
|
|||
namespace Generator; |
|||
|
|||
internal partial class Program |
|||
{ |
|||
static async Task Main(string[] args) |
|||
{ |
|||
var cacheFile = "cache.json"; |
|||
|
|||
if (!File.Exists(cacheFile) || !args.Contains("--cache")) |
|||
{ |
|||
var httpClient = new HttpClient(); |
|||
var schemaResponse = await httpClient.GetAsync("https://localhost:5001/api/swagger/v1/swagger.json"); |
|||
var schemaText = await schemaResponse.Content.ReadAsStringAsync(); |
|||
|
|||
File.WriteAllText(cacheFile, schemaText); |
|||
} |
|||
|
|||
var codePath = GetCodePath(); |
|||
|
|||
var document = await OpenApiDocument.FromJsonAsync(File.ReadAllText(cacheFile)); |
|||
|
|||
foreach (var (typeName, schema) in document.Components.Schemas.ToList()) |
|||
{ |
|||
if (typeName.Equals("AssetDto")) |
|||
{ |
|||
if (schema.ActualProperties.TryGetValue("tags", out var tags)) |
|||
{ |
|||
tags.IsNullableRaw = false; |
|||
tags.IsRequired = true; |
|||
} |
|||
} |
|||
|
|||
if (typeName.Equals("LanguageDto")) |
|||
{ |
|||
schema.Properties.Remove("nativeName"); |
|||
} |
|||
|
|||
if (typeName.Equals("AppDto") || typeName.Equals("TeamDto")) |
|||
{ |
|||
if (schema.ActualProperties.ContainsKey("created") && !schema.ActualProperties.ContainsKey("createdBy")) |
|||
{ |
|||
schema.Properties["createdBy"] = new JsonSchemaProperty |
|||
{ |
|||
Description = "The user that has created the app.", |
|||
Type = JsonObjectType.String, |
|||
IsNullableRaw = true, |
|||
IsRequired = false, |
|||
IsReadOnly = true, |
|||
}; |
|||
} |
|||
|
|||
if (schema.ActualProperties.ContainsKey("lastModified") && !schema.ActualProperties.ContainsKey("lastModifiedBy")) |
|||
{ |
|||
schema.Properties["lastModifiedBy"] = new JsonSchemaProperty |
|||
{ |
|||
Description = "The user that has updated the app.", |
|||
Type = JsonObjectType.String, |
|||
IsNullableRaw = true, |
|||
IsRequired = false, |
|||
IsReadOnly = true, |
|||
}; |
|||
} |
|||
} |
|||
|
|||
foreach (var (name, property) in schema.ActualProperties) |
|||
{ |
|||
property.IsReadOnly = true; |
|||
|
|||
if (property.Type == JsonObjectType.String && !property.IsRequired) |
|||
{ |
|||
property.IsNullableRaw = true; |
|||
} |
|||
|
|||
if (name.Equals("referenceFields")) |
|||
{ |
|||
property.IsNullableRaw = false; |
|||
property.IsRequired = true; |
|||
} |
|||
|
|||
if (name.Equals("schemaName")) |
|||
{ |
|||
property.IsNullableRaw = false; |
|||
property.IsRequired = true; |
|||
} |
|||
|
|||
if (name.Equals("schemaDisplayName")) |
|||
{ |
|||
property.IsNullableRaw = false; |
|||
property.IsRequired = true; |
|||
} |
|||
} |
|||
|
|||
if (document.Components.Schemas.TryGetValue("ErrorDto", out var error)) |
|||
{ |
|||
document.Components.Schemas.Remove("ErrorDto"); |
|||
document.Components.Schemas["ServerErrorDto"] = error; |
|||
} |
|||
|
|||
if (!typeName.EndsWith("Dto") && schema.Type == JsonObjectType.Object) |
|||
{ |
|||
document.Components.Schemas.Remove(typeName); |
|||
document.Components.Schemas[$"{typeName}Dto"] = schema; |
|||
} |
|||
} |
|||
|
|||
var extensionFile = Path.Combine(codePath, @"..\\..\\src\\app\\shared\\model\\custom.ts"); |
|||
var extensionCode = File.ReadAllText(extensionFile); |
|||
|
|||
var classes = |
|||
ClassNameRegex().Matches(extensionCode) |
|||
.Select(m => m.Groups["ClassName"].Value) |
|||
.ToArray(); |
|||
|
|||
var settings = new TypeScriptClientGeneratorSettings |
|||
{ |
|||
GenerateClientClasses = false, |
|||
GenerateClientInterfaces = false, |
|||
}; |
|||
settings.TypeScriptGeneratorSettings.EnumStyle = TypeScriptEnumStyle.StringLiteral; |
|||
settings.TypeScriptGeneratorSettings.ExportTypes = true; |
|||
settings.TypeScriptGeneratorSettings.ExtendedClasses = classes; |
|||
settings.TypeScriptGeneratorSettings.ExtensionCode = extensionCode; |
|||
settings.TypeScriptGeneratorSettings.GenerateConstructorInterface = true; |
|||
settings.TypeScriptGeneratorSettings.InlineNamedDictionaries = true; |
|||
settings.TypeScriptGeneratorSettings.TemplateDirectory = Path.Combine(Directory.GetCurrentDirectory(), "Templates"); |
|||
|
|||
var generator = new TypeScriptClientGenerator(document, settings); |
|||
|
|||
var code = generator.GenerateFile(); |
|||
|
|||
code = code.Replace("I{ [key: string]", "{ [key: string]"); |
|||
code = code.Replace(": Date,", ": DateTime,"); |
|||
code = code.Replace(": Date;", ": DateTime;"); |
|||
code = code.Replace(": Date |", ": DateTime |"); |
|||
code = code.Replace("DtoDto", "Dto"); |
|||
|
|||
var targetFolder = Path.Combine(codePath, @"..\\..\\src\\app\\shared\\model\\generated.ts"); |
|||
|
|||
File.WriteAllText(targetFolder, code); |
|||
} |
|||
|
|||
[GeneratedRegex("class (?<ClassName>[^\\)]*) extends generated\\.")]
|
|||
private static partial Regex ClassNameRegex(); |
|||
|
|||
private static string GetCodePath() |
|||
{ |
|||
var folder = new DirectoryInfo(Directory.GetCurrentDirectory()); |
|||
|
|||
while (true) |
|||
{ |
|||
if (folder.Name.Equals("Generator")) |
|||
{ |
|||
return folder.FullName; |
|||
} |
|||
|
|||
folder = folder.Parent!; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,205 @@ |
|||
{% if HasDescription -%} |
|||
/** {{ Description }} */ |
|||
{% endif -%} |
|||
{% if ExportTypes %}export {% endif %}{% if IsAbstract %}abstract {% endif %}class {{ ClassName }}{{ Inheritance }} { |
|||
{% if HasDiscriminator -%} |
|||
/** The discriminator. */ |
|||
public readonly {{ BaseDiscriminator }}!: string; |
|||
{% endif -%} |
|||
{% unless HasInheritance -%} |
|||
/** Uses the cache values because the actual object is frozen. */ |
|||
private readonly cachedValues: { [key: string]: any } = {}; |
|||
{% endunless -%} |
|||
{% for property in Properties -%} |
|||
{% if property.HasDescription -%} |
|||
/** {{ property.Description | strip }} */ |
|||
{% endif -%} |
|||
{% if property.IsReadOnly %}readonly {% endif %}{{ property.PropertyName }}{% if property.IsOptional %}?{% elsif RequiresStrictPropertyInitialization %}!{% endif %}: {{ property.Type }}{{ property.TypePostfix }}; |
|||
{% endfor -%} |
|||
{% if HasIndexerProperty -%} |
|||
|
|||
[key: string]: {{ IndexerPropertyValueType }}; |
|||
{% endif -%} |
|||
|
|||
{% assign condition_temp = HasInheritance == false or ConvertConstructorInterfaceData -%} |
|||
{% if GenerateConstructorInterface or HasBaseDiscriminator -%} |
|||
constructor({% if GenerateConstructorInterface %}data?: I{{ ClassName }}{% endif %}) { |
|||
{% if HasInheritance -%} |
|||
super({% if GenerateConstructorInterface %}data{% endif %}); |
|||
{% endif -%} |
|||
{% if GenerateConstructorInterface and condition_temp -%} |
|||
if (data) { |
|||
{% if HasInheritance == false -%} |
|||
for (var property in data) { |
|||
if (data.hasOwnProperty(property)) |
|||
(<any>this)[property] = (<any>data)[property]; |
|||
} |
|||
{% endif -%} |
|||
{% if ConvertConstructorInterfaceData -%} |
|||
{% for property in Properties -%} |
|||
{% if property.SupportsConstructorConversion -%} |
|||
{% if property.IsArray -%} |
|||
if (data.{{ property.PropertyName }}) { |
|||
this.{{ property.PropertyName }} = []; |
|||
for (let i = 0; i < data.{{ property.PropertyName }}.length; i++) { |
|||
let item = data.{{ property.PropertyName }}[i]; |
|||
this.{{ property.PropertyName }}[i] = item && !(<any>item).toJSON ? new {{ property.ArrayItemType }}(item) : <{{ property.ArrayItemType }}>item; |
|||
} |
|||
} |
|||
{% elsif property.IsDictionary -%} |
|||
if (data.{{ property.PropertyName }}) { |
|||
this.{{ property.PropertyName }} = {}; |
|||
for (let key in data.{{ property.PropertyName }}) { |
|||
if (data.{{ property.PropertyName }}.hasOwnProperty(key)) { |
|||
let item = data.{{ property.PropertyName }}[key]; |
|||
this.{{ property.PropertyName }}[key] = item && !(<any>item).toJSON ? new {{ property.DictionaryItemType }}(item) : <{{ property.DictionaryItemType }}>item; |
|||
} |
|||
} |
|||
} |
|||
{% else -%} |
|||
this.{{ property.PropertyName }} = data.{{ property.PropertyName }} && !(<any>data.{{ property.PropertyName }}).toJSON ? new {{ property.Type }}(data.{{ property.PropertyName }}) : <{{ property.Type }}>this.{{ property.PropertyName }}; |
|||
{% endif -%} |
|||
{% endif -%} |
|||
{% endfor -%} |
|||
{% endif -%} |
|||
} |
|||
{% endif -%} |
|||
{% if HasBaseDiscriminator -%} |
|||
(<any>this).{{ BaseDiscriminator }} = "{{ DiscriminatorName }}"; |
|||
{% endif -%} |
|||
} |
|||
{% endif -%} |
|||
|
|||
{% if HasInheritance and SupportsOverrideKeyword %}override {% endif %}init(_data: any{% if HandleReferences %}, _mappings?: any{% endif %}) { |
|||
{% if HasInheritance -%} |
|||
super.init(_data); |
|||
{% endif -%} |
|||
{% if HasIndexerProperty or HasProperties -%} |
|||
{% if HasIndexerProperty -%} |
|||
for (var property in _data) { |
|||
if (_data.hasOwnProperty(property)) |
|||
this[property] = _data[property]; |
|||
} |
|||
{% endif -%} |
|||
{% for property in Properties -%} |
|||
{{ property.ConvertToClassCode | strip | tab }} |
|||
{% endfor -%} |
|||
{% endif -%} |
|||
this.cleanup(this); |
|||
return this; |
|||
} |
|||
|
|||
static {% if HasInheritance and SupportsOverrideKeyword %}override {% endif %}fromJSON(data: any{% if HandleReferences %}, _mappings?: any{% endif %}): {{ ClassName }} { |
|||
{% if HandleReferences -%} |
|||
{% if HasBaseDiscriminator -%} |
|||
{% for derivedClass in DerivedClasses -%} |
|||
if (data["{{ BaseDiscriminator }}"] === "{{ derivedClass.Discriminator }}") |
|||
{% if derivedClass.IsAbstract -%} |
|||
throw new Error("The abstract class '{{ derivedClass.ClassName }}' cannot be instantiated."); |
|||
{% else -%} |
|||
return createInstance<{{ derivedClass.ClassName }}>(data, _mappings, {{ derivedClass.ClassName }}); |
|||
{% endif -%} |
|||
{% endfor -%} |
|||
{% endif -%} |
|||
{% if IsAbstract -%} |
|||
throw new Error("The abstract class '{{ ClassName }}' cannot be instantiated."); |
|||
{% else -%} |
|||
return createInstance<{{ ClassName }}>(data, _mappings, {{ ClassName }}); |
|||
{% endif -%} |
|||
{% else -%} |
|||
{% if HasBaseDiscriminator -%} |
|||
{% for derivedClass in DerivedClasses -%} |
|||
if (data["{{ BaseDiscriminator }}"] === "{{ derivedClass.Discriminator }}") { |
|||
{% if derivedClass.IsAbstract -%} |
|||
throw new Error("The abstract class '{{ derivedClass.ClassName }}' cannot be instantiated."); |
|||
{% else -%} |
|||
return new {{ derivedClass.ClassName }}().init(data); |
|||
{% endif -%} |
|||
} |
|||
{% endfor -%} |
|||
{% endif -%} |
|||
{% if IsAbstract -%} |
|||
throw new Error("The abstract class '{{ ClassName }}' cannot be instantiated."); |
|||
{% else -%} |
|||
const result = new {{ ClassName }}().init(data); |
|||
result.cleanup(this); |
|||
return result; |
|||
{% endif -%} |
|||
{% endif -%} |
|||
} |
|||
|
|||
{% if HasInheritance and SupportsOverrideKeyword %}override {% endif %}toJSON(data?: any) { |
|||
data = typeof data === 'object' ? data : {}; |
|||
{% if HasIndexerProperty -%} |
|||
for (var property in this) { |
|||
if (this.hasOwnProperty(property)) |
|||
data[property] = this[property]; |
|||
} |
|||
{% endif -%} |
|||
{% if HasDiscriminator -%} |
|||
data["{{ BaseDiscriminator }}"] = this.{{ BaseDiscriminator }}; |
|||
{% endif -%} |
|||
{% for property in Properties -%} |
|||
{{ property.ConvertToJavaScriptCode | tab }} |
|||
{% endfor -%} |
|||
{% if HasInheritance -%} |
|||
super.toJSON(data); |
|||
{% endif -%} |
|||
this.cleanup(data); |
|||
return data; |
|||
} |
|||
{% if GenerateCloneMethod -%} |
|||
|
|||
clone(): {{ ClassName }} { |
|||
{% if IsAbstract -%} |
|||
throw new Error("The abstract class '{{ ClassName }}' cannot be instantiated."); |
|||
{% else -%} |
|||
const json = this.toJSON(); |
|||
let result = new {{ ClassName }}(); |
|||
result.init(json); |
|||
return result; |
|||
{% endif -%} |
|||
} |
|||
{% endif -%} |
|||
{% unless HasInheritance -%} |
|||
|
|||
protected cleanup(target: any) { |
|||
for (var property in target) { |
|||
if (target.hasOwnProperty(property)) { |
|||
const value = target[property]; |
|||
if (value === undefined) { |
|||
delete target[property]; |
|||
} |
|||
} |
|||
} |
|||
} |
|||
|
|||
protected compute<T>(key: string, action: () => T): T { |
|||
if (!this.cachedValues.hasOwnProperty(key)) { |
|||
const value = action(); |
|||
this.cachedValues[key] = value; |
|||
return value; |
|||
} else { |
|||
return this.cachedValues[key] as any; |
|||
} |
|||
} |
|||
{% endunless -%} |
|||
} |
|||
{% if GenerateConstructorInterface -%} |
|||
|
|||
{% if HasDescription -%} |
|||
/** {{ Description }} */ |
|||
{% endif -%} |
|||
{% if ExportTypes %}export {% endif %}interface I{{ ClassName }}{{ InterfaceInheritance }} { |
|||
{% for property in Properties -%} |
|||
{% if property.HasDescription -%} |
|||
/** {{ property.Description | strip }} */ |
|||
{% endif -%} |
|||
readonly {{ property.PropertyName }}{% if property.IsOptional %}?{% endif %}: {{ property.ConstructorInterfaceType }}{{ property.TypePostfix }}; |
|||
{% endfor -%} |
|||
{% if HasIndexerProperty -%} |
|||
|
|||
[key: string]: {{ IndexerPropertyValueType }}; |
|||
{% endif -%} |
|||
} |
|||
{% endif -%} |
|||
@ -0,0 +1,65 @@ |
|||
{% if IsNewableObject -%} |
|||
{% if CheckNewableObject -%} |
|||
{{ Variable }} = {{ Value }} ? {{ Type }}.fromJSON({{ Value }}{% if HandleReferences -%}, _mappings{% endif %}) : {% if HasDefaultValue %}{{ DefaultValue }}{% else %}<any>{{ NullValue }}{% endif %}; |
|||
{% else -%} |
|||
{{ Variable }} = {{ Type }}.fromJSON({{ Value }}{% if HandleReferences -%}, _mappings{% endif %}); |
|||
{% endif -%} |
|||
{% elsif IsArray -%} |
|||
if (Array.isArray({{ Value }})) { |
|||
{{ Variable }} = [] as any; |
|||
for (let item of {{ Value }}) |
|||
{% if IsArrayItemNewableObject -%} |
|||
{{ Variable }}{% if RequiresStrictPropertyInitialization %}!{% endif %}.push({{ ArrayItemType }}.fromJSON(item{% if HandleReferences %}, _mappings{% endif %})); |
|||
{% else -%} |
|||
{% if IsArrayItemDate -%} |
|||
{{ Variable }}{% if RequiresStrictPropertyInitialization %}!{% endif %}.push(DateTime.parseISO(item)); |
|||
{% elsif IsArrayItemDateTime -%} |
|||
{{ Variable }}{% if RequiresStrictPropertyInitialization %}!{% endif %}.push(DateTime.parseISO(item)); |
|||
{% else -%} |
|||
{{ Variable }}{% if RequiresStrictPropertyInitialization %}!{% endif %}.push(item); |
|||
{% endif -%} |
|||
{% endif -%} |
|||
} |
|||
{% if NullValue != "undefined" %}else { |
|||
{{ Variable }} = <any>{{ NullValue }}; |
|||
} |
|||
{% endif -%} |
|||
{% elsif IsDictionary -%} |
|||
if ({{ Value }}) { |
|||
{{ Variable }} = {} as any; |
|||
for (let key in {{ Value }}) { |
|||
if ({{ Value }}.hasOwnProperty(key)) |
|||
{% if IsDictionaryValueNewableObject -%} |
|||
(<any>{{ Variable }}){% if RequiresStrictPropertyInitialization %}!{% endif %}[key] = {{ Value }}[key] ? {{ DictionaryValueType }}.fromJSON({{ Value }}[key]{% if HandleReferences %}, _mappings{% endif %}) : {% if HasDictionaryValueDefaultValue %}{{ DictionaryValueDefaultValue }}{% else %}<any>{{ NullValue }}{% endif %}; |
|||
{% elsif IsDictionaryValueNewableArray -%} |
|||
(<any>{{ Variable }}){% if RequiresStrictPropertyInitialization %}!{% endif %}[key] = {{ Value }}[key] ? {{ Value }}[key].map((i: any) => {{ DictionaryValueArrayItemType }}.fromJSON(i{% if HandleReferences %}, _mappings{% endif %})) : {% if HasDictionaryValueDefaultValue %}{{ DictionaryValueDefaultValue }}{% else %}<any>{{ NullValue }}{% endif %}; |
|||
{% elsif IsDictionaryValueDate -%} |
|||
(<any>{{ Variable }}){% if RequiresStrictPropertyInitialization %}!{% endif %}[key] = {{ Value }}[key] ? DateTime.parseISO({{ Value }}[key].toString()) : {% if HasDictionaryValueDefaultValue %}{{ DictionaryValueDefaultValue }}{% else %}<any>{{ NullValue }}{% endif %}; |
|||
{% elsif IsDictionaryValueDateTime -%} |
|||
(<any>{{ Variable }}){% if RequiresStrictPropertyInitialization %}!{% endif %}[key] = {{ Value }}[key] ? DateTime.parseISO({{ Value }}[key].toString()) : {% if HasDictionaryValueDefaultValue %}{{ DictionaryValueDefaultValue }}{% else %}<any>{{ NullValue }}{% endif %}; |
|||
{% else -%} |
|||
{% if HasDictionaryValueDefaultValue or NullValue != "undefined" -%} |
|||
(<any>{{ Variable }}){% if RequiresStrictPropertyInitialization %}!{% endif %}[key] = {{ Value }}[key] !== undefined ? {{ Value }}[key] : {% if HasDictionaryValueDefaultValue %}{{ DictionaryValueDefaultValue }}{% else %}<any>{{ NullValue }}{% endif %}; |
|||
{% else -%} |
|||
(<any>{{ Variable }}){% if RequiresStrictPropertyInitialization %}!{% endif %}[key] = {{ Value }}[key]; |
|||
{% endif -%} |
|||
{% endif -%} |
|||
} |
|||
} |
|||
{% if NullValue != "undefined" %}else { |
|||
{{ Variable }} = <any>{{ NullValue }}; |
|||
} |
|||
{% endif -%} |
|||
{% else -%} |
|||
{% if IsDate -%} |
|||
{{ Variable }} = {{ Value }} ? DateTime.parseISO({{ Value }}.toString()) : {% if HasDefaultValue %}DateTime.parseISO({{ DefaultValue }}){% else %}<any>{{ NullValue }}{% endif %}; |
|||
{% elsif IsDateTime -%} |
|||
{{ Variable }} = {{ Value }} ? DateTime.parseISO({{ Value }}.toString()) : {% if HasDefaultValue %}DateTime.parseISO({{ DefaultValue }}){% else %}<any>{{ NullValue }}{% endif %}; |
|||
{% else -%} |
|||
{% if HasDefaultValue or NullValue != "undefined" -%} |
|||
{{ Variable }} = {{ Value }} !== undefined ? {{ Value }} : {% if HasDefaultValue %}{{ DefaultValue }}{% else %}<any>{{ NullValue }}{% endif %}; |
|||
{% else -%} |
|||
{{ Variable }} = {{ Value }}; |
|||
{% endif -%} |
|||
{% endif -%} |
|||
{% endif -%} |
|||
@ -0,0 +1,45 @@ |
|||
{%- if IsNewableObject -%} |
|||
{{ Variable }} = {{ Value }} ? {{ Value }}.toJSON() : <any>{{ NullValue }}; |
|||
{%- elsif IsArray -%} |
|||
if (Array.isArray({{ Value }})) { |
|||
{{ Variable }} = []; |
|||
for (let item of {{ Value }}) |
|||
{%- if IsArrayItemNewableObject -%} |
|||
{{ Variable }}.push(item.toJSON()); |
|||
{%- elsif IsArrayItemDate -%} |
|||
{{ Variable }}.push({% if UseJsDate %}formatDate(item){% else %}item.toISOString(){% endif %}); |
|||
{%- elsif IsArrayItemDateTime -%} |
|||
{{ Variable }}.push(item.toISOString()); |
|||
{%- else -%} |
|||
{{ Variable }}.push(item); |
|||
{%- endif -%} |
|||
} |
|||
{%- elsif IsDictionary -%} |
|||
if ({{ Value }}) { |
|||
{{ Variable }} = {}; |
|||
for (let key in {{ Value }}) { |
|||
if ({{ Value }}.hasOwnProperty(key)) |
|||
{%- if IsDictionaryValueNewableObject -%} |
|||
(<any>{{ Variable }})[key] = {{ Value }}[key] ? {{ Value }}[key].toJSON() : <any>{{ NullValue }}; |
|||
{%- elsif IsDictionaryValueDate -%} |
|||
(<any>{{ Variable }})[key] = {{ Value }}[key] ? {{ Value }}[key].toISOString() : <any>{{ NullValue }}; |
|||
{%- elsif IsDictionaryValueDateTime -%} |
|||
(<any>{{ Variable }})[key] = {{ Value }}[key] ? {{ Value }}[key].toISOString() : <any>{{ NullValue }}; |
|||
{%- else -%} |
|||
{%- if NullValue != "undefined" -%} |
|||
(<any>{{ Variable }})[key] = {{ Value }}[key] !== undefined ? {{ Value }}[key] : <any>{{ NullValue }}; |
|||
{%- else -%} |
|||
(<any>{{ Variable }})[key] = (<any>{{ Value }})[key]; |
|||
{%- endif -%} |
|||
{%- endif -%} |
|||
} |
|||
} |
|||
{%- elsif IsDate -%} |
|||
{{ Variable }} = {{ Value }} ? {{ Value }}.toISOString() : {% if HasDefaultValue %}{{ DefaultValue }}{% else %}<any>{{ NullValue }}{% endif %}; |
|||
{%- elsif IsDateTime -%} |
|||
{{ Variable }} = {{ Value }} ? {{ Value }}.toISOString() : {% if HasDefaultValue %}{{ DefaultValue }}{% else %}<any>{{ NullValue }}{% endif %}; |
|||
{%- elsif NullValue != "undefined" -%} |
|||
{{ Variable }} = {{ Value }} !== undefined ? {{ Value }} : <any>{{ NullValue }}; |
|||
{%- else -%} |
|||
{{ Variable }} = {{ Value }}; |
|||
{%- endif %} |
|||
@ -0,0 +1,10 @@ |
|||
{%- if HasDescription -%} |
|||
/** {{ Description }} */ |
|||
{%- endif -%} |
|||
{%- if ExportTypes %}export {% endif %}type {{ Name }} = {% for enumeration in Enums %}{%- if Enums.first.Value != enumeration.Value %} | {% endif %}{{ enumeration.Value }}{% endfor %}; |
|||
|
|||
export const {{ Name | uppercamelcase }}Values: ReadonlyArray<{{ Name }}> = [ |
|||
{% for enumeration in Enums -%} |
|||
{{ enumeration.Value }}{% unless forloop.last %},{% endunless %} |
|||
{% endfor -%} |
|||
]; |
|||
Some files were not shown because too many files changed in this diff
Loading…
Reference in new issue