|
1 | | -namespace ByteBard.AsyncAPI.Readers.V2 |
| 1 | +namespace ByteBard.AsyncAPI.Readers.V2 |
2 | 2 | { |
3 | 3 | using System; |
4 | 4 | using System.Collections.Generic; |
| 5 | + using System.Text.Json.Nodes; |
5 | 6 | using ByteBard.AsyncAPI.Exceptions; |
6 | 7 | using ByteBard.AsyncAPI.Models; |
7 | 8 | using ByteBard.AsyncAPI.Models.Interfaces; |
@@ -32,12 +33,11 @@ public AsyncApiV2VersionService(AsyncApiDiagnostic diagnostic) |
32 | 33 | [typeof(AsyncApiOAuthFlows)] = AsyncApiV2Deserializer.LoadOAuthFlows, |
33 | 34 | [typeof(AsyncApiOperation)] = AsyncApiV2Deserializer.LoadOperation, |
34 | 35 | [typeof(AsyncApiParameter)] = AsyncApiV2Deserializer.LoadParameter, |
35 | | - [typeof(AsyncApiJsonSchema)] = AsyncApiJsonSchemaDeserializer.LoadSchema, |
36 | | - [typeof(AsyncApiAvroSchema)] = AsyncApiAvroSchemaDeserializer.LoadSchema, |
37 | 36 | [typeof(AsyncApiJsonSchema)] = AsyncApiV2Deserializer.LoadJsonSchemaPayload, |
38 | 37 | [typeof(AsyncApiAvroSchema)] = AsyncApiV2Deserializer.LoadAvroPayload, |
39 | | - // 2.x has no Multi Format Schema Object. Only the local reference fallback asks for one, and it reads the document after the upgrade to 3.0. |
40 | 38 | [typeof(AsyncApiMultiFormatSchema)] = AsyncApiV3Deserializer.LoadMultiFormatSchema, |
| 39 | + [typeof(AsyncApiCorrelationId)] = AsyncApiV2Deserializer.LoadCorrelationId, |
| 40 | + [typeof(AsyncApiOperationTrait)] = AsyncApiV2Deserializer.LoadOperationTrait, |
41 | 41 | [typeof(AsyncApiSecurityScheme)] = AsyncApiV2Deserializer.LoadSecurityScheme, |
42 | 42 | [typeof(AsyncApiServer)] = AsyncApiV2Deserializer.LoadServer, |
43 | 43 | [typeof(AsyncApiServerVariable)] = AsyncApiV2Deserializer.LoadServerVariable, |
@@ -81,6 +81,25 @@ public AsyncApiDocument LoadDocument(RootNode rootNode) |
81 | 81 | return AsyncApiV2Deserializer.LoadAsyncApi(rootNode); |
82 | 82 | } |
83 | 83 |
|
| 84 | + /// <summary> |
| 85 | + /// 2.x keeps a payload's schema format on its message, which the reader stored with the payload reference. |
| 86 | + /// Wrap the payload with it as a Multi Format Schema Object, so it is read in that format. |
| 87 | + /// </summary> |
| 88 | + public JsonNode PrepareReferenceFragment(JsonNode fragment, IAsyncApiReferenceable reference, ParsingContext context) |
| 89 | + { |
| 90 | + if (reference is not AsyncApiMultiFormatSchemaReference |
| 91 | + || context.GetFromTempStorage<string>(TempStorageKeys.PayloadSchemaFormat, reference) is not string schemaFormat) |
| 92 | + { |
| 93 | + return fragment; |
| 94 | + } |
| 95 | + |
| 96 | + return new JsonObject |
| 97 | + { |
| 98 | + ["schemaFormat"] = schemaFormat, |
| 99 | + ["schema"] = fragment.DeepClone(), |
| 100 | + }; |
| 101 | + } |
| 102 | + |
84 | 103 | public T LoadElement<T>(ParseNode node) |
85 | 104 | where T : IAsyncApiElement |
86 | 105 | { |
|
0 commit comments