Skip to content

Commit d7c4621

Browse files
authored
Merge pull request #2033 from microsoft/fix/missing-document-references
fix: passes missing host document references to all layers
2 parents 7a7bba1 + 4357373 commit d7c4621

File tree

86 files changed

+183
-185
lines changed

Some content is hidden

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

86 files changed

+183
-185
lines changed

src/Microsoft.OpenApi/Reader/ParseNodes/ListNode.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public ListNode(ParsingContext context, JsonArray jsonArray) : base(
2121
_nodeList = jsonArray;
2222
}
2323

24-
public override List<T> CreateList<T>(Func<MapNode, OpenApiDocument, T> map, OpenApiDocument hostDocument = null)
24+
public override List<T> CreateList<T>(Func<MapNode, OpenApiDocument, T> map, OpenApiDocument hostDocument)
2525
{
2626
if (_nodeList == null)
2727
{

src/Microsoft.OpenApi/Reader/ParseNodes/MapNode.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public PropertyNode this[string key]
4848
}
4949
}
5050

51-
public override Dictionary<string, T> CreateMap<T>(Func<MapNode, OpenApiDocument, T> map, OpenApiDocument hostDocument = null)
51+
public override Dictionary<string, T> CreateMap<T>(Func<MapNode, OpenApiDocument, T> map, OpenApiDocument hostDocument)
5252
{
5353
var jsonMap = _node ?? throw new OpenApiReaderException($"Expected map while parsing {typeof(T).Name}", Context);
5454
var nodes = jsonMap.Select(

src/Microsoft.OpenApi/Reader/ParseNodes/ParseNode.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,12 @@ public static ParseNode Create(ParsingContext context, JsonNode node)
4646
return new ValueNode(context, node as JsonValue);
4747
}
4848

49-
public virtual List<T> CreateList<T>(Func<MapNode, OpenApiDocument, T> map, OpenApiDocument hostDocument = null)
49+
public virtual List<T> CreateList<T>(Func<MapNode, OpenApiDocument, T> map, OpenApiDocument hostDocument)
5050
{
5151
throw new OpenApiReaderException("Cannot create list from this type of node.", Context);
5252
}
5353

54-
public virtual Dictionary<string, T> CreateMap<T>(Func<MapNode, OpenApiDocument, T> map, OpenApiDocument hostDocument = null)
54+
public virtual Dictionary<string, T> CreateMap<T>(Func<MapNode, OpenApiDocument, T> map, OpenApiDocument hostDocument)
5555
{
5656
throw new OpenApiReaderException("Cannot create map from this type of node.", Context);
5757
}

src/Microsoft.OpenApi/Reader/ParseNodes/PropertyNode.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public void ParseField<T>(
2828
T parentInstance,
2929
IDictionary<string, Action<T, ParseNode, OpenApiDocument>> fixedFields,
3030
IDictionary<Func<string, bool>, Action<T, string, ParseNode, OpenApiDocument>> patternFields,
31-
OpenApiDocument hostDocument = null)
31+
OpenApiDocument hostDocument)
3232
{
3333
if (fixedFields.TryGetValue(Name, out var fixedFieldMap))
3434
{

src/Microsoft.OpenApi/Reader/V2/OpenApiContactDeserializer.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ internal static partial class OpenApiV2Deserializer
3535
{s => s.StartsWith("x-"), (o, p, n, _) => o.AddExtension(p, LoadExtension(p, n))}
3636
};
3737

38-
public static OpenApiContact LoadContact(ParseNode node, OpenApiDocument hostDocument = null)
38+
public static OpenApiContact LoadContact(ParseNode node, OpenApiDocument hostDocument)
3939
{
4040
var mapNode = node as MapNode;
4141
var contact = new OpenApiContact();

src/Microsoft.OpenApi/Reader/V2/OpenApiDocumentDeserializer.cs

+4-6
Original file line numberDiff line numberDiff line change
@@ -64,20 +64,18 @@ internal static partial class OpenApiV2Deserializer
6464
},
6565
{
6666
"parameters",
67-
(o, n, _) =>
67+
(o, n, doc) =>
6868
{
69-
if (o.Components == null)
70-
{
71-
o.Components = new();
72-
}
69+
o.Components ??= new();
7370

7471
o.Components.Parameters = n.CreateMap(LoadParameter, o);
7572

7673
o.Components.RequestBodies = n.CreateMap((p, d) =>
7774
{
7875
var parameter = LoadParameter(node: p, loadRequestBody: true, hostDocument: d);
7976
return parameter != null ? CreateRequestBody(p.Context, parameter) : null;
80-
}
77+
},
78+
doc
8179
);
8280
}
8381
},

src/Microsoft.OpenApi/Reader/V2/OpenApiExternalDocsDeserializer.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ internal static partial class OpenApiV2Deserializer
3333
{s => s.StartsWith("x-"), (o, p, n, _) => o.AddExtension(p, LoadExtension(p, n))}
3434
};
3535

36-
public static OpenApiExternalDocs LoadExternalDocs(ParseNode node, OpenApiDocument hostDocument = null)
36+
public static OpenApiExternalDocs LoadExternalDocs(ParseNode node, OpenApiDocument hostDocument)
3737
{
3838
var mapNode = node.CheckMapNode("externalDocs");
3939

src/Microsoft.OpenApi/Reader/V2/OpenApiHeaderDeserializer.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ internal static partial class OpenApiV2Deserializer
3232
},
3333
{
3434
"items",
35-
(o, n, _) => GetOrCreateSchema(o).Items = LoadSchema(n)
35+
(o, n, doc) => GetOrCreateSchema(o).Items = LoadSchema(n, doc)
3636
},
3737
{
3838
"collectionFormat",
@@ -102,14 +102,14 @@ private static OpenApiSchema GetOrCreateSchema(OpenApiHeader p)
102102
return p.Schema ??= new();
103103
}
104104

105-
public static OpenApiHeader LoadHeader(ParseNode node, OpenApiDocument hostDocument = null)
105+
public static OpenApiHeader LoadHeader(ParseNode node, OpenApiDocument hostDocument)
106106
{
107107
var mapNode = node.CheckMapNode("header");
108108
var header = new OpenApiHeader();
109109

110110
foreach (var property in mapNode)
111111
{
112-
property.ParseField(header, _headerFixedFields, _headerPatternFields);
112+
property.ParseField(header, _headerFixedFields, _headerPatternFields, hostDocument);
113113
}
114114

115115
var schema = node.Context.GetFromTempStorage<OpenApiSchema>("schema");

src/Microsoft.OpenApi/Reader/V2/OpenApiInfoDeserializer.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ internal static partial class OpenApiV2Deserializer
4747
{s => s.StartsWith("x-"), (o, p, n, _) => o.AddExtension(p, LoadExtension(p, n))}
4848
};
4949

50-
public static OpenApiInfo LoadInfo(ParseNode node, OpenApiDocument hostDocument = null)
50+
public static OpenApiInfo LoadInfo(ParseNode node, OpenApiDocument hostDocument)
5151
{
5252
var mapNode = node.CheckMapNode("Info");
5353

src/Microsoft.OpenApi/Reader/V2/OpenApiLicenseDeserializer.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ internal static partial class OpenApiV2Deserializer
3131
{s => s.StartsWith("x-"), (o, p, n, _) => o.AddExtension(p, LoadExtension(p, n))}
3232
};
3333

34-
public static OpenApiLicense LoadLicense(ParseNode node, OpenApiDocument hostDocument = null)
34+
public static OpenApiLicense LoadLicense(ParseNode node, OpenApiDocument hostDocument)
3535
{
3636
var mapNode = node.CheckMapNode("OpenApiLicense");
3737

src/Microsoft.OpenApi/Reader/V2/OpenApiOperationDeserializer.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ internal static partial class OpenApiV2Deserializer
9191
{s => s.StartsWith("x-"), (o, p, n, _) => o.AddExtension(p, LoadExtension(p, n))}
9292
};
9393

94-
internal static OpenApiOperation LoadOperation(ParseNode node, OpenApiDocument hostDocument = null)
94+
internal static OpenApiOperation LoadOperation(ParseNode node, OpenApiDocument hostDocument)
9595
{
9696
// Reset these temp storage parameters for each operation.
9797
node.Context.SetTempStorage(TempStorageKeys.BodyParameter, null);
@@ -131,7 +131,7 @@ internal static OpenApiOperation LoadOperation(ParseNode node, OpenApiDocument h
131131
return operation;
132132
}
133133

134-
public static OpenApiResponses LoadResponses(ParseNode node, OpenApiDocument hostDocument = null)
134+
public static OpenApiResponses LoadResponses(ParseNode node, OpenApiDocument hostDocument)
135135
{
136136
var mapNode = node.CheckMapNode("Responses");
137137

@@ -205,7 +205,7 @@ internal static OpenApiRequestBody CreateRequestBody(
205205
}
206206

207207
private static OpenApiTagReference LoadTagByReference(
208-
string tagName, OpenApiDocument hostDocument = null)
208+
string tagName, OpenApiDocument hostDocument)
209209
{
210210
return new OpenApiTagReference(tagName, hostDocument);
211211
}

src/Microsoft.OpenApi/Reader/V2/OpenApiParameterDeserializer.cs

+5-5
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ internal static partial class OpenApiV2Deserializer
5050
},
5151
{
5252
"items",
53-
(o, n, t) => GetOrCreateSchema(o).Items = LoadSchema(n)
53+
(o, n, t) => GetOrCreateSchema(o).Items = LoadSchema(n, t)
5454
},
5555
{
5656
"collectionFormat",
@@ -138,7 +138,7 @@ private static void LoadStyle(OpenApiParameter p, string v)
138138
}
139139
}
140140

141-
private static void LoadParameterExamplesExtension(OpenApiParameter parameter, ParseNode node, OpenApiDocument hostDocument = null)
141+
private static void LoadParameterExamplesExtension(OpenApiParameter parameter, ParseNode node, OpenApiDocument hostDocument)
142142
{
143143
var examples = LoadExamplesExtension(node);
144144
node.Context.SetTempStorage(TempStorageKeys.Examples, examples, parameter);
@@ -149,7 +149,7 @@ private static OpenApiSchema GetOrCreateSchema(OpenApiParameter p)
149149
return p.Schema ??= new();
150150
}
151151

152-
private static void ProcessIn(OpenApiParameter o, ParseNode n, OpenApiDocument hostDocument = null)
152+
private static void ProcessIn(OpenApiParameter o, ParseNode n, OpenApiDocument hostDocument)
153153
{
154154
var value = n.GetScalarValue();
155155
switch (value)
@@ -183,12 +183,12 @@ private static void ProcessIn(OpenApiParameter o, ParseNode n, OpenApiDocument h
183183
}
184184
}
185185

186-
public static OpenApiParameter LoadParameter(ParseNode node, OpenApiDocument hostDocument = null)
186+
public static OpenApiParameter LoadParameter(ParseNode node, OpenApiDocument hostDocument)
187187
{
188188
return LoadParameter(node, false, hostDocument);
189189
}
190190

191-
public static OpenApiParameter LoadParameter(ParseNode node, bool loadRequestBody, OpenApiDocument hostDocument = null)
191+
public static OpenApiParameter LoadParameter(ParseNode node, bool loadRequestBody, OpenApiDocument hostDocument)
192192
{
193193
// Reset the local variables every time this method is called.
194194
node.Context.SetTempStorage(TempStorageKeys.ParameterIsBodyOrFormData, false);

src/Microsoft.OpenApi/Reader/V2/OpenApiPathItemDeserializer.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ internal static partial class OpenApiV2Deserializer
4343
{s => s.StartsWith("x-"), (o, p, n, _) => o.AddExtension(p, LoadExtension(p, n))},
4444
};
4545

46-
public static OpenApiPathItem LoadPathItem(ParseNode node, OpenApiDocument hostDocument = null)
46+
public static OpenApiPathItem LoadPathItem(ParseNode node, OpenApiDocument hostDocument)
4747
{
4848
var mapNode = node.CheckMapNode("PathItem");
4949

@@ -54,12 +54,12 @@ public static OpenApiPathItem LoadPathItem(ParseNode node, OpenApiDocument hostD
5454
return pathItem;
5555
}
5656

57-
private static void LoadPathParameters(OpenApiPathItem pathItem, ParseNode node, OpenApiDocument hostDocument = null)
57+
private static void LoadPathParameters(OpenApiPathItem pathItem, ParseNode node, OpenApiDocument hostDocument)
5858
{
5959
node.Context.SetTempStorage(TempStorageKeys.BodyParameter, null);
6060
node.Context.SetTempStorage(TempStorageKeys.FormParameters, null);
6161

62-
pathItem.Parameters = node.CreateList(LoadParameter);
62+
pathItem.Parameters = node.CreateList(LoadParameter, hostDocument);
6363

6464
// Build request body based on information determined while parsing OpenApiOperation
6565
var bodyParameter = node.Context.GetFromTempStorage<OpenApiParameter>(TempStorageKeys.BodyParameter);

src/Microsoft.OpenApi/Reader/V2/OpenApiPathsDeserializer.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ internal static partial class OpenApiV2Deserializer
2121
{s => s.StartsWith("x-"), (o, p, n, _) => o.AddExtension(p, LoadExtension(p, n))}
2222
};
2323

24-
public static OpenApiPaths LoadPaths(ParseNode node, OpenApiDocument hostDocument = null)
24+
public static OpenApiPaths LoadPaths(ParseNode node, OpenApiDocument hostDocument)
2525
{
2626
var mapNode = node.CheckMapNode("Paths");
2727

src/Microsoft.OpenApi/Reader/V2/OpenApiResponseDeserializer.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ private static void ProcessProduces(MapNode mapNode, OpenApiResponse response, P
104104
context.SetTempStorage(TempStorageKeys.ResponseProducesSet, true, response);
105105
}
106106

107-
private static void LoadResponseExamplesExtension(OpenApiResponse response, ParseNode node, OpenApiDocument hostDocument = null)
107+
private static void LoadResponseExamplesExtension(OpenApiResponse response, ParseNode node, OpenApiDocument hostDocument)
108108
{
109109
var examples = LoadExamplesExtension(node);
110110
node.Context.SetTempStorage(TempStorageKeys.Examples, examples, response);
@@ -145,7 +145,7 @@ private static Dictionary<string, OpenApiExample> LoadExamplesExtension(ParseNod
145145
return examples;
146146
}
147147

148-
private static void LoadExamples(OpenApiResponse response, ParseNode node, OpenApiDocument hostDocument = null)
148+
private static void LoadExamples(OpenApiResponse response, ParseNode node, OpenApiDocument hostDocument)
149149
{
150150
var mapNode = node.CheckMapNode("examples");
151151

@@ -178,7 +178,7 @@ private static void LoadExample(OpenApiResponse response, string mediaType, Pars
178178
mediaTypeObject.Example = exampleNode;
179179
}
180180

181-
public static OpenApiResponse LoadResponse(ParseNode node, OpenApiDocument hostDocument = null)
181+
public static OpenApiResponse LoadResponse(ParseNode node, OpenApiDocument hostDocument)
182182
{
183183
var mapNode = node.CheckMapNode("response");
184184

@@ -193,7 +193,7 @@ public static OpenApiResponse LoadResponse(ParseNode node, OpenApiDocument hostD
193193

194194
foreach (var property in mapNode)
195195
{
196-
property.ParseField(response, _responseFixedFields, _responsePatternFields);
196+
property.ParseField(response, _responseFixedFields, _responsePatternFields, hostDocument);
197197
}
198198

199199
foreach (var mediaType in response.Content.Values)

src/Microsoft.OpenApi/Reader/V2/OpenApiSchemaDeserializer.cs

+7-7
Original file line numberDiff line numberDiff line change
@@ -93,22 +93,22 @@ internal static partial class OpenApiV2Deserializer
9393
},
9494
{
9595
"items",
96-
(o, n, _) => o.Items = LoadSchema(n)
96+
(o, n, doc) => o.Items = LoadSchema(n, doc)
9797
},
9898
{
9999
"properties",
100100
(o, n, t) => o.Properties = n.CreateMap(LoadSchema, t)
101101
},
102102
{
103-
"additionalProperties", (o, n, _) =>
103+
"additionalProperties", (o, n, doc) =>
104104
{
105105
if (n is ValueNode)
106106
{
107107
o.AdditionalPropertiesAllowed = bool.Parse(n.GetScalarValue());
108108
}
109109
else
110110
{
111-
o.AdditionalProperties = LoadSchema(n);
111+
o.AdditionalProperties = LoadSchema(n, doc);
112112
}
113113
}
114114
},
@@ -139,11 +139,11 @@ internal static partial class OpenApiV2Deserializer
139139
},
140140
{
141141
"xml",
142-
(o, n, _) => o.Xml = LoadXml(n)
142+
(o, n, doc) => o.Xml = LoadXml(n, doc)
143143
},
144144
{
145145
"externalDocs",
146-
(o, n, _) => o.ExternalDocs = LoadExternalDocs(n)
146+
(o, n, doc) => o.ExternalDocs = LoadExternalDocs(n, doc)
147147
},
148148
{
149149
"example",
@@ -156,7 +156,7 @@ internal static partial class OpenApiV2Deserializer
156156
{s => s.StartsWith("x-"), (o, p, n, _) => o.AddExtension(p, LoadExtension(p, n))}
157157
};
158158

159-
public static OpenApiSchema LoadSchema(ParseNode node, OpenApiDocument hostDocument = null)
159+
public static OpenApiSchema LoadSchema(ParseNode node, OpenApiDocument hostDocument)
160160
{
161161
var mapNode = node.CheckMapNode("schema");
162162

@@ -171,7 +171,7 @@ public static OpenApiSchema LoadSchema(ParseNode node, OpenApiDocument hostDocum
171171

172172
foreach (var propertyNode in mapNode)
173173
{
174-
propertyNode.ParseField(schema, _openApiSchemaFixedFields, _openApiSchemaPatternFields);
174+
propertyNode.ParseField(schema, _openApiSchemaFixedFields, _openApiSchemaPatternFields, hostDocument);
175175
}
176176

177177
return schema;

src/Microsoft.OpenApi/Reader/V2/OpenApiSecuritySchemeDeserializer.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ internal static partial class OpenApiV2Deserializer
8080
{s => s.StartsWith("x-"), (o, p, n, _) => o.AddExtension(p, LoadExtension(p, n))}
8181
};
8282

83-
public static OpenApiSecurityScheme LoadSecurityScheme(ParseNode node, OpenApiDocument hostDocument = null)
83+
public static OpenApiSecurityScheme LoadSecurityScheme(ParseNode node, OpenApiDocument hostDocument)
8484
{
8585
// Reset the local variables every time this method is called.
8686
// TODO: Change _flow to a tempStorage variable to make the deserializer thread-safe.
@@ -92,7 +92,7 @@ public static OpenApiSecurityScheme LoadSecurityScheme(ParseNode node, OpenApiDo
9292
var securityScheme = new OpenApiSecurityScheme();
9393
foreach (var property in mapNode)
9494
{
95-
property.ParseField(securityScheme, _securitySchemeFixedFields, _securitySchemePatternFields);
95+
property.ParseField(securityScheme, _securitySchemeFixedFields, _securitySchemePatternFields, hostDocument);
9696
}
9797

9898
// Put the Flow object in the right Flows property based on the string in "flow"

src/Microsoft.OpenApi/Reader/V2/OpenApiTagDeserializer.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,15 @@ internal static partial class OpenApiV2Deserializer
3434
{s => s.StartsWith("x-"), (o, p, n, _) => o.AddExtension(p, LoadExtension(p, n))}
3535
};
3636

37-
public static OpenApiTag LoadTag(ParseNode n, OpenApiDocument hostDocument = null)
37+
public static OpenApiTag LoadTag(ParseNode n, OpenApiDocument hostDocument)
3838
{
3939
var mapNode = n.CheckMapNode("tag");
4040

4141
var domainObject = new OpenApiTag();
4242

4343
foreach (var propertyNode in mapNode)
4444
{
45-
propertyNode.ParseField(domainObject, _tagFixedFields, _tagPatternFields);
45+
propertyNode.ParseField(domainObject, _tagFixedFields, _tagPatternFields, hostDocument);
4646
}
4747

4848
return domainObject;

src/Microsoft.OpenApi/Reader/V2/OpenApiV2Deserializer.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ private static void ProcessAnyFields<T>(
7272
}
7373
}
7474

75-
public static JsonNode LoadAny(ParseNode node, OpenApiDocument hostDocument = null)
75+
public static JsonNode LoadAny(ParseNode node, OpenApiDocument hostDocument)
7676
{
7777
return node.CreateAny();
7878
}

src/Microsoft.OpenApi/Reader/V2/OpenApiXmlDeserializer.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,14 @@ internal static partial class OpenApiV2Deserializer
5454
{s => s.StartsWith("x-"), (o, p, n, _) => o.AddExtension(p, LoadExtension(p,n))}
5555
};
5656

57-
public static OpenApiXml LoadXml(ParseNode node, OpenApiDocument hostDocument = null)
57+
public static OpenApiXml LoadXml(ParseNode node, OpenApiDocument hostDocument)
5858
{
5959
var mapNode = node.CheckMapNode("xml");
6060

6161
var xml = new OpenApiXml();
6262
foreach (var property in mapNode)
6363
{
64-
property.ParseField(xml, _xmlFixedFields, _xmlPatternFields);
64+
property.ParseField(xml, _xmlFixedFields, _xmlPatternFields, hostDocument);
6565
}
6666

6767
return xml;

src/Microsoft.OpenApi/Reader/V3/OpenApiCallbackDeserializer.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ internal static partial class OpenApiV3Deserializer
2525
{s => s.StartsWith("x-"), (o, p, n, _) => o.AddExtension(p, LoadExtension(p,n))},
2626
};
2727

28-
public static OpenApiCallback LoadCallback(ParseNode node, OpenApiDocument hostDocument = null)
28+
public static OpenApiCallback LoadCallback(ParseNode node, OpenApiDocument hostDocument)
2929
{
3030
var mapNode = node.CheckMapNode("callback");
3131

0 commit comments

Comments
 (0)