-
Notifications
You must be signed in to change notification settings - Fork 434
/
JsonSchemaModel.cs
80 lines (66 loc) · 2.33 KB
/
JsonSchemaModel.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
// ==========================================================================
// Squidex Headless CMS
// ==========================================================================
// Copyright (c) Squidex UG (haftungsbeschränkt)
// All rights reserved. Licensed under the MIT license.
// ==========================================================================
using System;
using Newtonsoft.Json;
using Squidex.Infrastructure;
namespace Squidex.Domain.Apps.Core.Schemas.Json
{
public sealed class JsonSchemaModel
{
[JsonProperty]
public string Name { get; set; }
[JsonProperty]
public bool IsPublished { get; set; }
[JsonProperty]
public SchemaProperties Properties { get; set; }
[JsonProperty]
public JsonFieldModel[] Fields { get; set; }
public JsonSchemaModel()
{
}
public JsonSchemaModel(Schema schema)
{
Name = schema.Name;
Properties = schema.Properties;
Fields =
schema.Fields.ToArray(x =>
new JsonFieldModel
{
Id = x.Id,
Name = x.Name,
Children = CreateChildren(x),
IsHidden = x.IsHidden,
IsLocked = x.IsLocked,
IsDisabled = x.IsDisabled,
Partitioning = x.Partitioning.Key,
Properties = x.RawProperties
});
IsPublished = schema.IsPublished;
}
private static JsonNestedFieldModel[] CreateChildren(IField field)
{
if (field is ArrayField arrayField)
{
return arrayField.Fields.ToArray(x =>
new JsonNestedFieldModel
{
Id = x.Id,
Name = x.Name,
IsHidden = x.IsHidden,
IsDisabled = x.IsDisabled,
Properties = x.RawProperties
});
}
return null;
}
public Schema ToSchema()
{
var fields = Fields.ToArray(f => f.ToField()) ?? Array.Empty<RootField>();
return new Schema(Name, fields, Properties, IsPublished);
}
}
}