Skip to content

Commit 31f4868

Browse files
committed
fix writing via rootdocument for workspace.
1 parent 4a81385 commit 31f4868

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+197
-653
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ public class AsyncApiAvroSchemaDeserializer
212212
{ s => s.StartsWith(string.Empty), (a, p, n) => a.Metadata[p] = n.CreateAny() },
213213
};
214214

215-
public static AvroSchema LoadSchema(ParseNode node)
215+
public static AsyncApiAvroSchema LoadSchema(ParseNode node)
216216
{
217217
if (node is ValueNode valueNode)
218218
{
@@ -284,7 +284,7 @@ public static AvroSchema LoadSchema(ParseNode node)
284284
throw new AsyncApiReaderException("Invalid node type");
285285
}
286286

287-
private static AvroSchema LoadLogicalType(MapNode mapNode)
287+
private static AsyncApiAvroSchema LoadLogicalType(MapNode mapNode)
288288
{
289289
var type = mapNode["logicalType"]?.Value.GetScalarValue();
290290
switch (type)

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,9 @@ private static IAsyncApiMessagePayload LoadPayload(ParseNode n, string format)
8888
case null:
8989
case "":
9090
case var _ when SupportedJsonSchemaFormats.Where(s => format.StartsWith(s)).Any():
91-
return new AsyncApiJsonSchemaPayload(AsyncApiSchemaDeserializer.LoadSchema(n));
91+
return AsyncApiSchemaDeserializer.LoadSchema(n);
9292
case var _ when SupportedAvroSchemaFormats.Where(s => format.StartsWith(s)).Any():
93-
return new AsyncApiAvroSchemaPayload(AsyncApiAvroSchemaDeserializer.LoadSchema(n));
93+
return AsyncApiAvroSchemaDeserializer.LoadSchema(n);
9494
default:
9595
var supportedFormats = SupportedJsonSchemaFormats.Concat(SupportedAvroSchemaFormats);
9696
throw new AsyncApiException($"'Could not deserialize Payload. Supported formats are {string.Join(", ", supportedFormats)}");

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ public AsyncApiV2VersionService(AsyncApiDiagnostic diagnostic)
3535
[typeof(AsyncApiOperation)] = AsyncApiV2Deserializer.LoadOperation,
3636
[typeof(AsyncApiParameter)] = AsyncApiV2Deserializer.LoadParameter,
3737
[typeof(AsyncApiJsonSchema)] = AsyncApiSchemaDeserializer.LoadSchema,
38-
[typeof(AvroSchema)] = AsyncApiAvroSchemaDeserializer.LoadSchema,
39-
[typeof(AsyncApiJsonSchemaPayload)] = AsyncApiV2Deserializer.LoadJsonSchemaPayload,
40-
[typeof(AsyncApiAvroSchemaPayload)] = AsyncApiV2Deserializer.LoadAvroPayload,
38+
[typeof(AsyncApiAvroSchema)] = AsyncApiAvroSchemaDeserializer.LoadSchema,
39+
[typeof(AsyncApiJsonSchema)] = AsyncApiV2Deserializer.LoadJsonSchemaPayload,
40+
[typeof(AsyncApiAvroSchema)] = AsyncApiV2Deserializer.LoadAvroPayload,
4141
[typeof(AsyncApiSecurityRequirement)] = AsyncApiV2Deserializer.LoadSecurityRequirement,
4242
[typeof(AsyncApiSecurityScheme)] = AsyncApiV2Deserializer.LoadSecurityScheme,
4343
[typeof(AsyncApiServer)] = AsyncApiV2Deserializer.LoadServer,

src/LEGO.AsyncAPI/AsyncApiWorkspace.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ public void RegisterComponents(AsyncApiDocument document)
7171
{
7272
location = baseUri + ReferenceType.SecurityScheme.GetDisplayName() + "/" + item.Key;
7373
this.RegisterComponent(location, item.Value);
74+
this.RegisterComponent(item.Key, item.Value);
7475
}
7576

7677
// Register Parameters

src/LEGO.AsyncAPI/Models/AsyncApiAvroSchemaPayload.cs

Lines changed: 0 additions & 66 deletions
This file was deleted.

src/LEGO.AsyncAPI/Models/AsyncApiDocument.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ namespace LEGO.AsyncAPI.Models
1212
/// </summary>
1313
public class AsyncApiDocument : IAsyncApiExtensible, IAsyncApiSerializable
1414
{
15-
internal AsyncApiWorkspace Workspace { get; set; }
15+
internal AsyncApiWorkspace Workspace { get; set; } = new AsyncApiWorkspace();
1616

1717
/// <summary>
1818
/// REQUIRED. Specifies the AsyncAPI Specification version being used.
@@ -73,6 +73,9 @@ public void SerializeV2(IAsyncApiWriter writer)
7373
throw new ArgumentNullException(nameof(writer));
7474
}
7575

76+
this.Workspace.RegisterComponents(this);
77+
78+
writer.RootDocument = this;
7679
writer.WriteStartObject();
7780

7881
// asyncApi

src/LEGO.AsyncAPI/Models/AsyncApiJsonSchemaPayload.cs

Lines changed: 0 additions & 109 deletions
This file was deleted.

src/LEGO.AsyncAPI/Models/AsyncApiReference.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,6 @@ public void SerializeV2(IAsyncApiWriter writer)
155155

156156
private string GetExternalReferenceV2()
157157
{
158-
159158
return this.ExternalResource + (this.FragmentId != null ? "#" + this.FragmentId : string.Empty);
160159
}
161160

src/LEGO.AsyncAPI/Models/Avro/AvroSchema.cs renamed to src/LEGO.AsyncAPI/Models/Avro/AsyncApiAvroSchema.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ namespace LEGO.AsyncAPI.Models
77
using LEGO.AsyncAPI.Models.Interfaces;
88
using LEGO.AsyncAPI.Writers;
99

10-
public abstract class AvroSchema : IAsyncApiSerializable, IAsyncApiReferenceable
10+
public abstract class AsyncApiAvroSchema : IAsyncApiSerializable, IAsyncApiReferenceable, IAsyncApiMessagePayload
1111
{
1212
public abstract string Type { get; }
1313

@@ -20,7 +20,7 @@ public abstract class AvroSchema : IAsyncApiSerializable, IAsyncApiReferenceable
2020

2121
public AsyncApiReference Reference { get; set; }
2222

23-
public static implicit operator AvroSchema(AvroPrimitiveType type)
23+
public static implicit operator AsyncApiAvroSchema(AvroPrimitiveType type)
2424
{
2525
return new AvroPrimitive(type);
2626
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@ namespace LEGO.AsyncAPI.Models
66
using System.Linq;
77
using LEGO.AsyncAPI.Writers;
88

9-
public class AvroArray : AvroSchema
9+
public class AvroArray : AsyncApiAvroSchema
1010
{
1111
public override string Type { get; } = "array";
1212

1313
/// <summary>
1414
/// The schema of the array's items.
1515
/// </summary>
16-
public AvroSchema Items { get; set; }
16+
public AsyncApiAvroSchema Items { get; set; }
1717

1818
/// <summary>
1919
/// A map of properties not in the schema, but added as additional metadata.

0 commit comments

Comments
 (0)