Skip to content

Commit 06abb47

Browse files
committed
remote notion of HostDocument in favour of workspace
1 parent 31f4868 commit 06abb47

19 files changed

+41
-37
lines changed

src/LEGO.AsyncAPI.Readers/AsyncApiJsonDocumentReader.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ private void ResolveInternalReferences(AsyncApiDiagnostic diagnostic, AsyncApiDo
197197
{
198198
var reader = new AsyncApiStringReader(this.settings);
199199

200-
var resolver = new AsyncApiReferenceHostDocumentResolver(document);
200+
var resolver = new AsyncApiReferenceHostDocumentResolver(this.context.Workspace);
201201
var walker = new AsyncApiWalker(resolver);
202202
walker.Walk(document);
203203

@@ -210,7 +210,7 @@ private void ResolveInternalReferences(AsyncApiDiagnostic diagnostic, AsyncApiDo
210210
private void ResolveExternalReferences(AsyncApiDiagnostic diagnostic, IAsyncApiSerializable serializable, AsyncApiDocument hostDocument)
211211
{
212212
var loader = this.settings.ExternalReferenceLoader ??= new DefaultStreamLoader(this.settings);
213-
var collector = new AsyncApiRemoteReferenceCollector(hostDocument);
213+
var collector = new AsyncApiRemoteReferenceCollector(this.context.Workspace);
214214
var walker = new AsyncApiWalker(collector);
215215
walker.Walk(serializable);
216216

src/LEGO.AsyncAPI.Readers/AsyncApiReferenceHostDocumentResolver.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ namespace LEGO.AsyncAPI.Readers
99

1010
internal class AsyncApiReferenceHostDocumentResolver : AsyncApiVisitorBase
1111
{
12-
private AsyncApiDocument currentDocument;
12+
private AsyncApiWorkspace workspace;
1313
private List<AsyncApiError> errors = new List<AsyncApiError>();
1414

1515
public AsyncApiReferenceHostDocumentResolver(
16-
AsyncApiDocument currentDocument)
16+
AsyncApiWorkspace workspace)
1717
{
18-
this.currentDocument = currentDocument;
18+
this.workspace = workspace;
1919
}
2020

2121
public IEnumerable<AsyncApiError> Errors
@@ -30,7 +30,7 @@ public override void Visit(IAsyncApiReferenceable referenceable)
3030
{
3131
if (referenceable.Reference != null)
3232
{
33-
referenceable.Reference.HostDocument = this.currentDocument;
33+
referenceable.Reference.Workspace = this.workspace;
3434
}
3535
}
3636
}

src/LEGO.AsyncAPI.Readers/Services/AsyncApiRemoteReferenceCollector.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ namespace LEGO.AsyncAPI.Readers.Services
1010
internal class AsyncApiRemoteReferenceCollector : AsyncApiVisitorBase
1111
{
1212
private readonly List<IAsyncApiReferenceable> references = new();
13-
private AsyncApiDocument currentDocument;
13+
private AsyncApiWorkspace workspace;
1414

1515
public AsyncApiRemoteReferenceCollector(
16-
AsyncApiDocument currentDocument)
16+
AsyncApiWorkspace workspace)
1717
{
18-
this.currentDocument = currentDocument;
18+
this.workspace = workspace;
1919
}
2020
/// <summary>
2121
/// List of all external references collected from AsyncApiDocument.
@@ -36,9 +36,9 @@ public override void Visit(IAsyncApiReferenceable referenceable)
3636
{
3737
if (referenceable.Reference != null && referenceable.Reference.IsExternal)
3838
{
39-
if (referenceable.Reference.HostDocument == null)
39+
if (referenceable.Reference.Workspace == null)
4040
{
41-
referenceable.Reference.HostDocument = this.currentDocument;
41+
referenceable.Reference.Workspace = this.workspace;
4242
}
4343

4444
this.references.Add(referenceable);

src/LEGO.AsyncAPI/AsyncApiWorkspace.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,12 @@ public bool Contains(string location)
161161
return this.resolvedReferenceRegistry.ContainsKey(key) || this.artifactsRegistry.ContainsKey(key);
162162
}
163163

164+
public T ResolveReference<T>(AsyncApiReference reference)
165+
where T : class
166+
{
167+
return this.ResolveReference<T>(reference.Reference);
168+
}
169+
164170
public T ResolveReference<T>(string location)
165171
where T : class
166172
{

src/LEGO.AsyncAPI/Models/AsyncApiDocument.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ public void SerializeV2(IAsyncApiWriter writer)
7474
}
7575

7676
this.Workspace.RegisterComponents(this);
77+
writer.Workspace = this.Workspace;
7778

78-
writer.RootDocument = this;
7979
writer.WriteStartObject();
8080

8181
// asyncApi

src/LEGO.AsyncAPI/Models/AsyncApiReference.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ public string ExternalResource
105105
/// <summary>
106106
/// Gets or sets the AsyncApiDocument that is hosting the AsyncApiReference instance. This is used to enable dereferencing the reference.
107107
/// </summary>
108-
public AsyncApiDocument HostDocument { get; set; } = null;
108+
public AsyncApiWorkspace Workspace { get; set; } = null;
109109

110110
/// <summary>
111111
/// Gets a flag indicating whether a file is a valid OpenAPI document or a fragment.

src/LEGO.AsyncAPI/Models/References/AsyncApiChannelReference.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ private AsyncApiChannel Target
1414
{
1515
get
1616
{
17-
this.target ??= this.Reference.HostDocument?.ResolveReference<AsyncApiChannel>(this.Reference);
17+
this.target ??= this.Reference.Workspace?.ResolveReference<AsyncApiChannel>(this.Reference.Reference);
1818
return this.target;
1919
}
2020
}
@@ -51,7 +51,7 @@ public override void SerializeV2(IAsyncApiWriter writer)
5151
}
5252
else
5353
{
54-
this.Reference.HostDocument = writer.RootDocument;
54+
this.Reference.Workspace = writer.Workspace;
5555
this.Target.SerializeV2(writer);
5656
}
5757
}

src/LEGO.AsyncAPI/Models/References/AsyncApiCorrelationIdReference.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ private AsyncApiCorrelationId Target
1717
{
1818
get
1919
{
20-
this.target ??= this.Reference.HostDocument?.ResolveReference<AsyncApiCorrelationId>(this.Reference);
20+
this.target ??= this.Reference.Workspace?.ResolveReference<AsyncApiCorrelationId>(this.Reference.Reference);
2121
return this.target;
2222
}
2323
}
@@ -46,7 +46,7 @@ public override void SerializeV2(IAsyncApiWriter writer)
4646
}
4747
else
4848
{
49-
this.Reference.HostDocument = writer.RootDocument;
49+
this.Reference.Workspace = writer.Workspace;
5050
this.Target.SerializeV2(writer);
5151
}
5252
}

src/LEGO.AsyncAPI/Models/References/AsyncApiJsonSchemaReference.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ private AsyncApiJsonSchema Target
1515
{
1616
get
1717
{
18-
this.target ??= this.Reference.HostDocument?.ResolveReference<AsyncApiJsonSchema>(this.Reference);
18+
this.target ??= this.Reference.Workspace?.ResolveReference<AsyncApiJsonSchema>(this.Reference);
1919
return this.target;
2020
}
2121
}
@@ -304,7 +304,7 @@ public override void SerializeV2(IAsyncApiWriter writer)
304304
return;
305305
}
306306

307-
this.Reference.HostDocument = writer.RootDocument;
307+
this.Reference.Workspace = writer.Workspace;
308308
// If Loop is detected then just Serialize as a reference.
309309
if (!settings.LoopDetector.PushLoop(this))
310310
{

src/LEGO.AsyncAPI/Models/References/AsyncApiMessageReference.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ private AsyncApiMessage Target
1717
{
1818
get
1919
{
20-
this.target ??= this.Reference.HostDocument?.ResolveReference<AsyncApiMessage>(this.Reference);
20+
this.target ??= this.Reference.Workspace?.ResolveReference<AsyncApiMessage>(this.Reference.Reference);
2121
return this.target;
2222
}
2323
}
@@ -72,7 +72,7 @@ public override void SerializeV2(IAsyncApiWriter writer)
7272
}
7373
else
7474
{
75-
this.Reference.HostDocument = writer.RootDocument;
75+
this.Reference.Workspace = writer.Workspace;
7676
this.Target.SerializeV2(writer);
7777
}
7878
}

0 commit comments

Comments
 (0)