22
33namespace LEGO . AsyncAPI . Readers
44{
5- using System ;
65 using System . Collections . Generic ;
7- using System . Linq ;
8- using System . Text . Json . Nodes ;
9- using System . Threading ;
10- using System . Threading . Tasks ;
11- using LEGO . AsyncAPI . Exceptions ;
12- using LEGO . AsyncAPI . Extensions ;
136 using LEGO . AsyncAPI . Models ;
147 using LEGO . AsyncAPI . Models . Interfaces ;
15- using LEGO . AsyncAPI . Readers . Interface ;
16- using LEGO . AsyncAPI . Readers . Services ;
178 using LEGO . AsyncAPI . Services ;
18- using LEGO . AsyncAPI . Validations ;
19-
209
2110 internal class AsyncApiReferenceHostDocumentResolver : AsyncApiVisitorBase
2211 {
@@ -42,216 +31,7 @@ public override void Visit(IAsyncApiReferenceable referenceable)
4231 if ( referenceable . Reference != null )
4332 {
4433 referenceable . Reference . HostDocument = this . currentDocument ;
45- this . currentDocument . Workspace . RegisterReference ( referenceable ) ;
4634 }
47-
4835 }
4936 }
50- //public override void Visit(AsyncApiComponents components)
51- //{
52- // this.ResolveMap(components.Parameters);
53- // this.ResolveMap(components.Channels);
54- // this.ResolveMap(components.Schemas);
55- // this.ResolveMap(components.Servers);
56- // this.ResolveMap(components.CorrelationIds);
57- // this.ResolveMap(components.MessageTraits);
58- // this.ResolveMap(components.OperationTraits);
59- // this.ResolveMap(components.SecuritySchemes);
60- // this.ResolveMap(components.ChannelBindings);
61- // this.ResolveMap(components.MessageBindings);
62- // this.ResolveMap(components.OperationBindings);
63- // this.ResolveMap(components.ServerBindings);
64- // this.ResolveMap(components.Messages);
65- //}
66-
67- //public override void Visit(AsyncApiDocument doc)
68- //{
69- // this.ResolveMap(doc.Servers);
70- // this.ResolveMap(doc.Channels);
71- //}
72-
73- //public override void Visit(AsyncApiChannel channel)
74- //{
75- // this.ResolveMap(channel.Parameters);
76- // this.ResolveObject(channel.Bindings, r => channel.Bindings = r);
77- //}
78-
79- //public override void Visit(AsyncApiMessageTrait trait)
80- //{
81- // this.ResolveObject(trait.CorrelationId, r => trait.CorrelationId = r);
82- // this.ResolveObject(trait.Headers, r => trait.Headers = r);
83- //}
84-
85- ///// <summary>
86- ///// Resolve all references used in an operation.
87- ///// </summary>
88- //public override void Visit(AsyncApiOperation operation)
89- //{
90- // this.ResolveList(operation.Message);
91- // this.ResolveList(operation.Traits);
92- // this.ResolveObject(operation.Bindings, r => operation.Bindings = r);
93- //}
94-
95- //public override void Visit(AsyncApiMessage message)
96- //{
97- // this.ResolveObject(message.Headers, r => message.Headers = r);
98-
99- // // #ToFix Resolve references correctly
100- // if (message.Payload is AsyncApiJsonSchemaPayload)
101- // {
102- // this.ResolveObject(message.Payload as AsyncApiJsonSchemaPayload, r => message.Payload = r);
103- // }
104-
105- // this.ResolveList(message.Traits);
106- // this.ResolveObject(message.CorrelationId, r => message.CorrelationId = r);
107- // this.ResolveObject(message.Bindings, r => message.Bindings = r);
108- //}
109-
110- //public override void Visit(AsyncApiServer server)
111- //{
112- // this.ResolveObject(server.Bindings, r => server.Bindings = r);
113- //}
114-
115- ///// <summary>
116- ///// Resolve all references to SecuritySchemes.
117- ///// </summary>
118- //public override void Visit(AsyncApiSecurityRequirement securityRequirement)
119- //{
120- // foreach (var scheme in securityRequirement.Keys.ToList())
121- // {
122- // this.ResolveObject(scheme, (resolvedScheme) =>
123- // {
124- // if (resolvedScheme != null)
125- // {
126- // // If scheme was unresolved
127- // // copy Scopes and remove old unresolved scheme
128- // var scopes = securityRequirement[scheme];
129- // securityRequirement.Remove(scheme);
130- // securityRequirement.Add(resolvedScheme, scopes);
131- // }
132- // });
133- // }
134- //}
135-
136- ///// <summary>
137- ///// Resolve all references to parameters.
138- ///// </summary>
139- //public override void Visit(IList<AsyncApiParameter> parameters)
140- //{
141- // this.ResolveList(parameters);
142- //}
143-
144- ///// <summary>
145- ///// Resolve all references used in a parameter.
146- ///// </summary>
147- //public override void Visit(AsyncApiParameter parameter)
148- //{
149- // this.ResolveObject(parameter.Schema, r => parameter.Schema = r);
150- //}
151-
152- ///// <summary>
153- ///// Resolve all references used in a schema.
154- ///// </summary>
155- //public override void Visit(AsyncApiJsonSchema schema)
156- //{
157- // this.ResolveObject(schema.Items, r => schema.Items = r);
158- // this.ResolveList(schema.OneOf);
159- // this.ResolveList(schema.AllOf);
160- // this.ResolveList(schema.AnyOf);
161- // this.ResolveObject(schema.Contains, r => schema.Contains = r);
162- // this.ResolveObject(schema.Else, r => schema.Else = r);
163- // this.ResolveObject(schema.If, r => schema.If = r);
164- // this.ResolveObject(schema.Items, r => schema.Items = r);
165- // this.ResolveObject(schema.Not, r => schema.Not = r);
166- // this.ResolveObject(schema.Then, r => schema.Then = r);
167- // this.ResolveObject(schema.PropertyNames, r => schema.PropertyNames = r);
168- // this.ResolveObject(schema.AdditionalProperties, r => schema.AdditionalProperties = r);
169- // this.ResolveMap(schema.Properties);
170- //}
171-
172- //private void ResolveObject<T>(T entity, Action<T> assign)
173- // where T : class, IAsyncApiReferenceable, new()
174- //{
175- // if (entity == null)
176- // {
177- // return;
178- // }
179-
180- // if (this.IsUnresolvedReference(entity))
181- // {
182- // assign(this.ResolveReference<T>(entity.Reference));
183- // }
184- //}
185-
186- //private void ResolveList<T>(IList<T> list)
187- // where T : class, IAsyncApiReferenceable, new()
188- //{
189- // if (list == null)
190- // {
191- // return;
192- // }
193-
194- // for (int i = 0; i < list.Count; i++)
195- // {
196- // var entity = list[i];
197- // if (this.IsUnresolvedReference(entity))
198- // {
199- // list[i] = this.ResolveReference<T>(entity.Reference);
200- // }
201- // }
202- //}
203-
204- //private void ResolveMap<T>(IDictionary<string, T> map)
205- // where T : class, IAsyncApiReferenceable, new()
206- //{
207- // if (map == null)
208- // {
209- // return;
210- // }
211-
212- // foreach (var key in map.Keys.ToList())
213- // {
214- // var entity = map[key];
215- // if (this.IsUnresolvedReference(entity))
216- // {
217- // map[key] = this.ResolveReference<T>(entity.Reference);
218- // }
219- // }
220- //}
221-
222- //private T ResolveReference<T>(AsyncApiReference reference)
223- // where T : class, IAsyncApiReferenceable, new()
224- //{
225- // // external references are resolved by the AsyncApiExternalReferenceResolver
226- // if (reference.IsExternal)
227- // {
228- // return new()
229- // {
230- // UnresolvedReference = true,
231- // Reference = reference,
232- // };
233- // }
234-
235- // try
236- // {
237- // var resolvedReference = this.currentDocument.ResolveReference<T>(reference);
238- // if (resolvedReference == null)
239- // {
240- // throw new AsyncApiException($"Cannot resolve reference '{reference.Reference}' to '{typeof(T).Name}'.");
241- // }
242-
243- // return resolvedReference;
244- // }
245- // catch (AsyncApiException ex)
246- // {
247- // this.errors.Add(new AsyncApiReferenceError(ex));
248- // return null;
249- // }
250- //}
251-
252- //private bool IsUnresolvedReference(IAsyncApiReferenceable possibleReference)
253- //{
254- // return (possibleReference != null && possibleReference.UnresolvedReference);
255- //}
256- //}
25737}
0 commit comments