Skip to content

Commit 4a81385

Browse files
committed
partiall done with json schema
1 parent f922979 commit 4a81385

20 files changed

+812
-276
lines changed

src/LEGO.AsyncAPI.Readers/V2/AsyncApiComponentsDeserializer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ internal static partial class AsyncApiV2Deserializer
1010
{
1111
private static FixedFieldMap<AsyncApiComponents> componentsFixedFields = new()
1212
{
13-
{ "schemas", (a, n) => a.Schemas = n.CreateMapWithReference(ReferenceType.Schema, AsyncApiSchemaDeserializer.LoadSchema) },
13+
{ "schemas", (a, n) => a.Schemas = n.CreateMap(AsyncApiSchemaDeserializer.LoadSchema) },
1414
{ "servers", (a, n) => a.Servers = n.CreateMap(LoadServer) },
1515
{ "channels", (a, n) => a.Channels = n.CreateMap(LoadChannel) },
1616
{ "messages", (a, n) => a.Messages = n.CreateMap(LoadMessage) },

src/LEGO.AsyncAPI.Readers/V2/AsyncApiSchemaDeserializer.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -229,11 +229,7 @@ public static AsyncApiJsonSchema LoadSchema(ParseNode node)
229229

230230
if (pointer != null)
231231
{
232-
return new AsyncApiJsonSchema
233-
{
234-
UnresolvedReference = true,
235-
Reference = node.Context.VersionService.ConvertToAsyncApiReference(pointer, ReferenceType.Schema),
236-
};
232+
return new AsyncApiJsonSchemaReference(pointer);
237233
}
238234

239235
var schema = new AsyncApiJsonSchema();

src/LEGO.AsyncAPI/Models/AsyncApiComponents.cs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -101,17 +101,17 @@ public void SerializeV2(IAsyncApiWriter writer)
101101
{
102102
var loops = writer.GetSettings().LoopDetector.Loops;
103103
writer.WriteStartObject();
104-
if (loops.TryGetValue(typeof(AsyncApiJsonSchema), out List<object> schemas))
104+
if (loops.TryGetValue(typeof(AsyncApiJsonSchemaReference), out List<object> schemas))
105105
{
106-
var asyncApiSchemas = schemas.Cast<AsyncApiJsonSchema>().Distinct().ToList()
107-
.ToDictionary<AsyncApiJsonSchema, string>(k => k.Reference.FragmentId);
106+
var asyncApiSchemas = schemas.Cast<AsyncApiJsonSchemaReference>().Distinct().ToList()
107+
.ToDictionary<AsyncApiJsonSchemaReference, string>(k => k.Reference.FragmentId);
108108

109109
writer.WriteOptionalMap(
110110
AsyncApiConstants.Schemas,
111111
this.Schemas,
112112
(w, key, component) =>
113113
{
114-
component.SerializeV2WithoutReference(w);
114+
component.SerializeV2(w);
115115
});
116116
}
117117

@@ -130,11 +130,9 @@ public void SerializeV2(IAsyncApiWriter writer)
130130
this.Schemas,
131131
(w, key, component) =>
132132
{
133-
if (component.Reference != null &&
134-
component.Reference.Type == ReferenceType.Schema &&
135-
component.Reference.FragmentId == key)
133+
if (component is AsyncApiJsonSchemaReference reference)
136134
{
137-
component.SerializeV2WithoutReference(w);
135+
reference.SerializeV2(w);
138136
}
139137
else
140138
{

src/LEGO.AsyncAPI/Models/AsyncApiJsonSchemaPayload.cs

Lines changed: 109 additions & 127 deletions
Original file line numberDiff line numberDiff line change
@@ -1,127 +1,109 @@
1-
// Copyright (c) The LEGO Group. All rights reserved.
2-
3-
namespace LEGO.AsyncAPI.Models
4-
{
5-
using System.Collections.Generic;
6-
using LEGO.AsyncAPI.Models.Interfaces;
7-
using LEGO.AsyncAPI.Writers;
8-
9-
public class AsyncApiJsonSchemaPayload : IAsyncApiMessagePayload
10-
{
11-
private readonly AsyncApiJsonSchema schema;
12-
13-
public AsyncApiJsonSchemaPayload()
14-
{
15-
this.schema = new AsyncApiJsonSchema();
16-
}
17-
18-
public AsyncApiJsonSchemaPayload(AsyncApiJsonSchema schema)
19-
{
20-
this.schema = schema;
21-
}
22-
23-
public string Title { get => this.schema.Title; set => this.schema.Title = value; }
24-
25-
public SchemaType? Type { get => this.schema.Type; set => this.schema.Type = value; }
26-
27-
public string Format { get => this.schema.Format; set => this.schema.Format = value; }
28-
29-
public string Description { get => this.schema.Description; set => this.schema.Description = value; }
30-
31-
public double? Maximum { get => this.schema.Maximum; set => this.schema.Maximum = value; }
32-
33-
public double? ExclusiveMaximum { get => this.schema.ExclusiveMaximum; set => this.schema.ExclusiveMaximum = value; }
34-
35-
public double? Minimum { get => this.schema.Minimum; set => this.schema.Minimum = value; }
36-
37-
public double? ExclusiveMinimum { get => this.schema.ExclusiveMinimum; set => this.schema.ExclusiveMinimum = value; }
38-
39-
public int? MaxLength { get => this.schema.MaxLength; set => this.schema.MaxLength = value; }
40-
41-
public int? MinLength { get => this.schema.MinLength; set => this.schema.MinLength = value; }
42-
43-
public string Pattern { get => this.schema.Pattern; set => this.schema.Pattern = value; }
44-
45-
public double? MultipleOf { get => this.schema.MultipleOf; set => this.schema.MultipleOf = value; }
46-
47-
public AsyncApiAny Default { get => this.schema.Default; set => this.schema.Default = value; }
48-
49-
public bool ReadOnly { get => this.schema.ReadOnly; set => this.schema.ReadOnly = value; }
50-
51-
public bool WriteOnly { get => this.schema.WriteOnly; set => this.schema.WriteOnly = value; }
52-
53-
public IList<AsyncApiJsonSchema> AllOf { get => this.schema.AllOf; set => this.schema.AllOf = value; }
54-
55-
public IList<AsyncApiJsonSchema> OneOf { get => this.schema.OneOf; set => this.schema.OneOf = value; }
56-
57-
public IList<AsyncApiJsonSchema> AnyOf { get => this.schema.AnyOf; set => this.schema.AnyOf = value; }
58-
59-
public AsyncApiJsonSchema Not { get => this.schema.Not; set => this.schema.Not = value; }
60-
61-
public AsyncApiJsonSchema Contains { get => this.schema.Contains; set => this.schema.Contains = value; }
62-
63-
public AsyncApiJsonSchema If { get => this.schema.If; set => this.schema.If = value; }
64-
65-
public AsyncApiJsonSchema Then { get => this.schema.Then; set => this.schema.Then = value; }
66-
67-
public AsyncApiJsonSchema Else { get => this.schema.Else; set => this.schema.Else = value; }
68-
69-
public ISet<string> Required { get => this.schema.Required; set => this.schema.Required = value; }
70-
71-
public AsyncApiJsonSchema Items { get => this.schema.Items; set => this.schema.Items = value; }
72-
73-
public AsyncApiJsonSchema AdditionalItems { get => this.schema.AdditionalItems; set => this.schema.AdditionalItems = value; }
74-
75-
public int? MaxItems { get => this.schema.MaxItems; set => this.schema.MaxItems = value; }
76-
77-
public int? MinItems { get => this.schema.MinItems; set => this.schema.MinItems = value; }
78-
79-
public bool? UniqueItems { get => this.schema.UniqueItems; set => this.schema.UniqueItems = value; }
80-
81-
public IDictionary<string, AsyncApiJsonSchema> Properties { get => this.schema.Properties; set => this.schema.Properties = value; }
82-
83-
public int? MaxProperties { get => this.schema.MaxProperties; set => this.schema.MaxProperties = value; }
84-
85-
public int? MinProperties { get => this.schema.MinProperties; set => this.schema.MinProperties = value; }
86-
87-
public IDictionary<string, AsyncApiJsonSchema> PatternProperties { get => this.schema.PatternProperties; set => this.schema.PatternProperties = value; }
88-
89-
public AsyncApiJsonSchema PropertyNames { get => this.schema.PropertyNames; set => this.schema.PropertyNames = value; }
90-
91-
public string Discriminator { get => this.schema.Discriminator; set => this.schema.Discriminator = value; }
92-
93-
public IList<AsyncApiAny> Enum { get => this.schema.Enum; set => this.schema.Enum = value; }
94-
95-
public IList<AsyncApiAny> Examples { get => this.schema.Examples; set => this.schema.Examples = value; }
96-
97-
public AsyncApiAny Const { get => this.schema.Const; set => this.schema.Const = value; }
98-
99-
public bool Nullable { get => this.schema.Nullable; set => this.schema.Nullable = value; }
100-
101-
public AsyncApiExternalDocumentation ExternalDocs { get => this.schema.ExternalDocs; set => this.schema.ExternalDocs = value; }
102-
103-
public bool Deprecated { get => this.schema.Deprecated; set => this.schema.Deprecated = value; }
104-
105-
public bool UnresolvedReference { get => this.schema.UnresolvedReference; set => this.schema.UnresolvedReference = value; }
106-
107-
public AsyncApiReference Reference { get => this.schema.Reference; set => this.schema.Reference = value; }
108-
109-
public IDictionary<string, IAsyncApiExtension> Extensions { get => this.schema.Extensions; set => this.schema.Extensions = value; }
110-
111-
public AsyncApiJsonSchema AdditionalProperties { get => this.schema.AdditionalProperties; set => this.schema.AdditionalProperties = value; }
112-
113-
public static implicit operator AsyncApiJsonSchema(AsyncApiJsonSchemaPayload payload) => payload.schema;
114-
115-
public static implicit operator AsyncApiJsonSchemaPayload(AsyncApiJsonSchema schema) => new AsyncApiJsonSchemaPayload(schema);
116-
117-
public void SerializeV2(IAsyncApiWriter writer)
118-
{
119-
this.schema.SerializeV2(writer);
120-
}
121-
122-
public void SerializeV2WithoutReference(IAsyncApiWriter writer)
123-
{
124-
this.schema.SerializeV2WithoutReference(writer);
125-
}
126-
}
127-
}
1+
// Copyright (c) The LEGO Group. All rights reserved.
2+
3+
namespace LEGO.AsyncAPI.Models{ using System.Collections.Generic; using LEGO.AsyncAPI.Models.Interfaces; using LEGO.AsyncAPI.Writers; public class AsyncApiJsonSchemaPayload : IAsyncApiMessagePayload { private readonly AsyncApiJsonSchema schema;
4+
5+
public AsyncApiJsonSchemaPayload()
6+
{
7+
this.schema = new AsyncApiJsonSchema();
8+
}
9+
10+
public AsyncApiJsonSchemaPayload(AsyncApiJsonSchema schema)
11+
{
12+
this.schema = schema;
13+
}
14+
15+
public virtual string Title { get => this.schema.Title; set => this.schema.Title = value; }
16+
17+
public virtual SchemaType? Type { get => this.schema.Type; set => this.schema.Type = value; }
18+
19+
public virtual string Format { get => this.schema.Format; set => this.schema.Format = value; }
20+
21+
public virtual string Description { get => this.schema.Description; set => this.schema.Description = value; }
22+
23+
public virtual double? Maximum { get => this.schema.Maximum; set => this.schema.Maximum = value; }
24+
25+
public virtual double? ExclusiveMaximum { get => this.schema.ExclusiveMaximum; set => this.schema.ExclusiveMaximum = value; }
26+
27+
public virtual double? Minimum { get => this.schema.Minimum; set => this.schema.Minimum = value; }
28+
29+
public virtual double? ExclusiveMinimum { get => this.schema.ExclusiveMinimum; set => this.schema.ExclusiveMinimum = value; }
30+
31+
public virtual int? MaxLength { get => this.schema.MaxLength; set => this.schema.MaxLength = value; }
32+
33+
public virtual int? MinLength { get => this.schema.MinLength; set => this.schema.MinLength = value; }
34+
35+
public virtual string Pattern { get => this.schema.Pattern; set => this.schema.Pattern = value; }
36+
37+
public virtual double? MultipleOf { get => this.schema.MultipleOf; set => this.schema.MultipleOf = value; }
38+
39+
public virtual AsyncApiAny Default { get => this.schema.Default; set => this.schema.Default = value; }
40+
41+
public virtual bool ReadOnly { get => this.schema.ReadOnly; set => this.schema.ReadOnly = value; }
42+
43+
public virtual bool WriteOnly { get => this.schema.WriteOnly; set => this.schema.WriteOnly = value; }
44+
45+
public virtual IList<AsyncApiJsonSchema> AllOf { get => this.schema.AllOf; set => this.schema.AllOf = value; }
46+
47+
public virtual IList<AsyncApiJsonSchema> OneOf { get => this.schema.OneOf; set => this.schema.OneOf = value; }
48+
49+
public virtual IList<AsyncApiJsonSchema> AnyOf { get => this.schema.AnyOf; set => this.schema.AnyOf = value; }
50+
51+
public virtual AsyncApiJsonSchema Not { get => this.schema.Not; set => this.schema.Not = value; }
52+
53+
public virtual AsyncApiJsonSchema Contains { get => this.schema.Contains; set => this.schema.Contains = value; }
54+
55+
public virtual AsyncApiJsonSchema If { get => this.schema.If; set => this.schema.If = value; }
56+
57+
public virtual AsyncApiJsonSchema Then { get => this.schema.Then; set => this.schema.Then = value; }
58+
59+
public virtual AsyncApiJsonSchema Else { get => this.schema.Else; set => this.schema.Else = value; }
60+
61+
public virtual ISet<string> Required { get => this.schema.Required; set => this.schema.Required = value; }
62+
63+
public virtual AsyncApiJsonSchema Items { get => this.schema.Items; set => this.schema.Items = value; }
64+
65+
public virtual AsyncApiJsonSchema AdditionalItems { get => this.schema.AdditionalItems; set => this.schema.AdditionalItems = value; }
66+
67+
public virtual int? MaxItems { get => this.schema.MaxItems; set => this.schema.MaxItems = value; }
68+
69+
public virtual int? MinItems { get => this.schema.MinItems; set => this.schema.MinItems = value; }
70+
71+
public virtual bool? UniqueItems { get => this.schema.UniqueItems; set => this.schema.UniqueItems = value; }
72+
73+
public virtual IDictionary<string, AsyncApiJsonSchema> Properties { get => this.schema.Properties; set => this.schema.Properties = value; }
74+
75+
public virtual int? MaxProperties { get => this.schema.MaxProperties; set => this.schema.MaxProperties = value; }
76+
77+
public virtual int? MinProperties { get => this.schema.MinProperties; set => this.schema.MinProperties = value; }
78+
79+
public virtual IDictionary<string, AsyncApiJsonSchema> PatternProperties { get => this.schema.PatternProperties; set => this.schema.PatternProperties = value; }
80+
81+
public virtual AsyncApiJsonSchema PropertyNames { get => this.schema.PropertyNames; set => this.schema.PropertyNames = value; }
82+
83+
public virtual string Discriminator { get => this.schema.Discriminator; set => this.schema.Discriminator = value; }
84+
85+
public virtual IList<AsyncApiAny> Enum { get => this.schema.Enum; set => this.schema.Enum = value; }
86+
87+
public virtual IList<AsyncApiAny> Examples { get => this.schema.Examples; set => this.schema.Examples = value; }
88+
89+
public virtual AsyncApiAny Const { get => this.schema.Const; set => this.schema.Const = value; }
90+
91+
public virtual bool Nullable { get => this.schema.Nullable; set => this.schema.Nullable = value; }
92+
93+
public virtual AsyncApiExternalDocumentation ExternalDocs { get => this.schema.ExternalDocs; set => this.schema.ExternalDocs = value; }
94+
95+
public virtual bool Deprecated { get => this.schema.Deprecated; set => this.schema.Deprecated = value; }
96+
97+
public virtual IDictionary<string, IAsyncApiExtension> Extensions { get => this.schema.Extensions; set => this.schema.Extensions = value; }
98+
99+
public virtual AsyncApiJsonSchema AdditionalProperties { get => this.schema.AdditionalProperties; set => this.schema.AdditionalProperties = value; }
100+
101+
public static implicit operator AsyncApiJsonSchema(AsyncApiJsonSchemaPayload payload) => payload.schema;
102+
103+
public static implicit operator AsyncApiJsonSchemaPayload(AsyncApiJsonSchema schema) => new AsyncApiJsonSchemaPayload(schema);
104+
105+
public virtual void SerializeV2(IAsyncApiWriter writer)
106+
{
107+
this.schema.SerializeV2(writer);
108+
}
109+
}}

src/LEGO.AsyncAPI/Models/Avro/AvroArray.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public class AvroArray : AvroSchema
2020
/// </summary>
2121
public override IDictionary<string, AsyncApiAny> Metadata { get; set; } = new Dictionary<string, AsyncApiAny>();
2222

23-
public override void SerializeV2WithoutReference(IAsyncApiWriter writer)
23+
public override void SerializeV2Core(IAsyncApiWriter writer)
2424
{
2525
writer.WriteStartObject();
2626
writer.WriteOptionalProperty("type", this.Type);

src/LEGO.AsyncAPI/Models/Avro/AvroEnum.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public class AvroEnum : AvroSchema
4545
/// </summary>
4646
public override IDictionary<string, AsyncApiAny> Metadata { get; set; } = new Dictionary<string, AsyncApiAny>();
4747

48-
public override void SerializeV2WithoutReference(IAsyncApiWriter writer)
48+
public override void SerializeV2Core(IAsyncApiWriter writer)
4949
{
5050
writer.WriteStartObject();
5151
writer.WriteOptionalProperty("type", this.Type);

src/LEGO.AsyncAPI/Models/Avro/AvroFixed.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public class AvroFixed : AvroSchema
3636
/// </summary>
3737
public override IDictionary<string, AsyncApiAny> Metadata { get; set; } = new Dictionary<string, AsyncApiAny>();
3838

39-
public override void SerializeV2WithoutReference(IAsyncApiWriter writer)
39+
public override void SerializeV2Core(IAsyncApiWriter writer)
4040
{
4141
writer.WriteStartObject();
4242
writer.WriteOptionalProperty("type", this.Type);

src/LEGO.AsyncAPI/Models/Avro/AvroMap.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public class AvroMap : AvroSchema
1717
/// </summary>
1818
public override IDictionary<string, AsyncApiAny> Metadata { get; set; } = new Dictionary<string, AsyncApiAny>();
1919

20-
public override void SerializeV2WithoutReference(IAsyncApiWriter writer)
20+
public override void SerializeV2Core(IAsyncApiWriter writer)
2121
{
2222
writer.WriteStartObject();
2323
writer.WriteOptionalProperty("type", this.Type);

src/LEGO.AsyncAPI/Models/Avro/AvroPrimitive.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public AvroPrimitive(AvroPrimitiveType type)
2020
this.Type = type.GetDisplayName();
2121
}
2222

23-
public override void SerializeV2WithoutReference(IAsyncApiWriter writer)
23+
public override void SerializeV2Core(IAsyncApiWriter writer)
2424
{
2525
writer.WriteValue(this.Type);
2626
if (this.Metadata.Any())

src/LEGO.AsyncAPI/Models/Avro/AvroRecord.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public class AvroRecord : AvroSchema
4040
/// </summary>
4141
public override IDictionary<string, AsyncApiAny> Metadata { get; set; } = new Dictionary<string, AsyncApiAny>();
4242

43-
public override void SerializeV2WithoutReference(IAsyncApiWriter writer)
43+
public override void SerializeV2Core(IAsyncApiWriter writer)
4444
{
4545
writer.WriteStartObject();
4646
writer.WriteOptionalProperty("type", this.Type);

0 commit comments

Comments
 (0)