Skip to content

Commit ad62a4a

Browse files
authored
Merge branch 'master' into feature/fix.tests
2 parents e6c084c + a4e3991 commit ad62a4a

File tree

9 files changed

+188
-277
lines changed

9 files changed

+188
-277
lines changed

build.cmd

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,16 @@ SET VERSION=%~1
66
Echo Building Microsoft.OpenApi
77

88
SET PROJ=%~dp0src\Microsoft.OpenApi\Microsoft.OpenApi.csproj
9-
msbuild %PROJ% /t:restore /p:Configuration=Release
10-
msbuild %PROJ% /t:build /p:Configuration=Release
11-
msbuild %PROJ% /t:pack /p:Configuration=Release;PackageOutputPath=%~dp0artifacts;Version=%VERSION%
9+
dotnet build %PROJ% /t:restore /p:Configuration=Release
10+
dotnet build %PROJ% /t:build /p:Configuration=Release
11+
dotnet build %PROJ% /t:pack /p:Configuration=Release;PackageOutputPath=%~dp0artifacts;Version=%VERSION%
1212

1313
Echo Building Microsoft.OpenApi.Readers
1414

1515
SET PROJ=%~dp0src\Microsoft.OpenApi.Readers\Microsoft.OpenApi.Readers.csproj
16-
msbuild %PROJ% /t:restore /p:Configuration=Release
17-
msbuild %PROJ% /t:build /p:Configuration=Release
18-
msbuild %PROJ% /t:pack /p:Configuration=Release;PackageOutputPath=%~dp0artifacts;Version=%VERSION%
16+
dotnet build %PROJ% /t:restore /p:Configuration=Release
17+
dotnet build %PROJ% /t:build /p:Configuration=Release
18+
dotnet build %PROJ% /t:pack /p:Configuration=Release;PackageOutputPath=%~dp0artifacts;Version=%VERSION%
1919

2020
goto :end
2121
:error

src/Microsoft.OpenApi/Properties/SRResource.Designer.cs

Lines changed: 0 additions & 19 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Microsoft.OpenApi/Properties/SRResource.resx

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -198,12 +198,6 @@
198198
<data name="Validation_ComponentsKeyMustMatchRegularExpr" xml:space="preserve">
199199
<value>The key '{0}' in '{1}' of components MUST match the regular expression '{2}'.</value>
200200
</data>
201-
<data name="Validation_CompositeSchemaMustContainPropertySpecifiedInTheDiscriminator" xml:space="preserve">
202-
<value>Composite Schema {0} must contain property specified in the discriminator {1}.</value>
203-
</data>
204-
<data name="Validation_CompositeSchemaRequiredFieldListMustContainThePropertySpecifiedInTheDiscriminator" xml:space="preserve">
205-
<value>Composite schema {0} must contain property specified in the discriminator {1} in the required field list.</value>
206-
</data>
207201
<data name="Validation_ExtensionNameMustBeginWithXDash" xml:space="preserve">
208202
<value>The extension name '{0}' in '{1}' object MUST begin with 'x-'.</value>
209203
</data>

src/Microsoft.OpenApi/Services/OpenApiVisitorBase.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,20 @@ public virtual void Visit(OpenApiSecurityRequirement securityRequirement)
276276
{
277277
}
278278

279+
/// <summary>
280+
/// Visits <see cref="OpenApiSecurityScheme"/>
281+
/// </summary>
282+
public virtual void Visit(OpenApiSecurityScheme securityScheme)
283+
{
284+
}
285+
286+
/// <summary>
287+
/// Visits <see cref="OpenApiExample"/>
288+
/// </summary>
289+
public virtual void Visit(OpenApiExample example)
290+
{
291+
}
292+
279293
/// <summary>
280294
/// Visits list of <see cref="OpenApiTag"/>
281295
/// </summary>
@@ -325,5 +339,13 @@ public virtual void Visit(IDictionary<string, OpenApiServerVariable> serverVaria
325339
public virtual void Visit(IDictionary<string, OpenApiEncoding> encodings)
326340
{
327341
}
342+
343+
/// <summary>
344+
/// Visits IOpenApiReferenceable instances that are references and not in components
345+
/// </summary>
346+
/// <param name="referenceable">referenced object</param>
347+
public virtual void Visit(IOpenApiReferenceable referenceable)
348+
{
349+
}
328350
}
329351
}

src/Microsoft.OpenApi/Services/OpenApiWalker.cs

Lines changed: 41 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ public class OpenApiWalker
1919
private readonly Stack<OpenApiSchema> _schemaLoop = new Stack<OpenApiSchema>();
2020
private readonly Stack<OpenApiPathItem> _pathItemLoop = new Stack<OpenApiPathItem>();
2121

22-
private bool _inComponents = false;
23-
2422
/// <summary>
2523
/// Initializes the <see cref="OpenApiWalker"/> class.
2624
/// </summary>
@@ -42,7 +40,6 @@ public void Walk(OpenApiDocument doc)
4240

4341
_schemaLoop.Clear();
4442
_pathItemLoop.Clear();
45-
_inComponents = false;
4643

4744
_visitor.Visit(doc);
4845

@@ -102,8 +99,6 @@ internal void Walk(OpenApiComponents components)
10299
return;
103100
}
104101

105-
EnterComponents();
106-
107102
_visitor.Visit(components);
108103

109104
if (components == null)
@@ -117,7 +112,7 @@ internal void Walk(OpenApiComponents components)
117112
{
118113
foreach (var item in components.Schemas)
119114
{
120-
Walk(item.Key, () => Walk(item.Value));
115+
Walk(item.Key, () => Walk(item.Value, isComponent: true));
121116
}
122117
}
123118
});
@@ -128,7 +123,7 @@ internal void Walk(OpenApiComponents components)
128123
{
129124
foreach (var item in components.Callbacks)
130125
{
131-
Walk(item.Key, () => Walk(item.Value));
126+
Walk(item.Key, () => Walk(item.Value, isComponent: true));
132127
}
133128
}
134129
});
@@ -139,7 +134,7 @@ internal void Walk(OpenApiComponents components)
139134
{
140135
foreach (var item in components.Parameters)
141136
{
142-
Walk(item.Key, () => Walk(item.Value));
137+
Walk(item.Key, () => Walk(item.Value, isComponent: true));
143138
}
144139
}
145140
});
@@ -150,7 +145,7 @@ internal void Walk(OpenApiComponents components)
150145
{
151146
foreach (var item in components.Examples)
152147
{
153-
Walk(item.Key, () => Walk(item.Value));
148+
Walk(item.Key, () => Walk(item.Value, isComponent: true));
154149
}
155150
}
156151
});
@@ -161,7 +156,7 @@ internal void Walk(OpenApiComponents components)
161156
{
162157
foreach (var item in components.Headers)
163158
{
164-
Walk(item.Key, () => Walk(item.Value));
159+
Walk(item.Key, () => Walk(item.Value, isComponent: true));
165160
}
166161
}
167162
});
@@ -172,7 +167,7 @@ internal void Walk(OpenApiComponents components)
172167
{
173168
foreach (var item in components.Links)
174169
{
175-
Walk(item.Key, () => Walk(item.Value));
170+
Walk(item.Key, () => Walk(item.Value, isComponent: true));
176171
}
177172
}
178173
});
@@ -183,7 +178,7 @@ internal void Walk(OpenApiComponents components)
183178
{
184179
foreach (var item in components.RequestBodies)
185180
{
186-
Walk(item.Key, () => Walk(item.Value));
181+
Walk(item.Key, () => Walk(item.Value, isComponent: true));
187182
}
188183
}
189184
});
@@ -194,13 +189,12 @@ internal void Walk(OpenApiComponents components)
194189
{
195190
foreach (var item in components.Responses)
196191
{
197-
Walk(item.Key, () => Walk(item.Value));
192+
Walk(item.Key, () => Walk(item.Value, isComponent: true));
198193
}
199194
}
200195
});
201196

202197
Walk(components as IOpenApiExtensible);
203-
ExitComponents();
204198
}
205199

206200
/// <summary>
@@ -332,9 +326,9 @@ internal void Walk(OpenApiContact contact)
332326
/// <summary>
333327
/// Visits <see cref="OpenApiCallback"/> and child objects
334328
/// </summary>
335-
internal void Walk(OpenApiCallback callback)
329+
internal void Walk(OpenApiCallback callback, bool isComponent = false)
336330
{
337-
if (callback == null)
331+
if (callback == null || ProcessAsReference(callback, isComponent))
338332
{
339333
return;
340334
}
@@ -358,7 +352,7 @@ internal void Walk(OpenApiCallback callback)
358352
/// </summary>
359353
internal void Walk(OpenApiTag tag)
360354
{
361-
if (tag == null || IsReference(tag))
355+
if (tag == null || ProcessAsReference(tag))
362356
{
363357
return;
364358
}
@@ -541,9 +535,9 @@ internal void Walk(IList<OpenApiParameter> parameters)
541535
/// <summary>
542536
/// Visits <see cref="OpenApiParameter"/> and child objects
543537
/// </summary>
544-
internal void Walk(OpenApiParameter parameter)
538+
internal void Walk(OpenApiParameter parameter, bool isComponent = false)
545539
{
546-
if (parameter == null || IsReference(parameter))
540+
if (parameter == null || ProcessAsReference(parameter, isComponent))
547541
{
548542
return;
549543
}
@@ -583,9 +577,9 @@ internal void Walk(OpenApiResponses responses)
583577
/// <summary>
584578
/// Visits <see cref="OpenApiResponse"/> and child objects
585579
/// </summary>
586-
internal void Walk(OpenApiResponse response)
580+
internal void Walk(OpenApiResponse response, bool isComponent = false)
587581
{
588-
if (response == null || IsReference(response))
582+
if (response == null || ProcessAsReference(response, isComponent))
589583
{
590584
return;
591585
}
@@ -594,16 +588,15 @@ internal void Walk(OpenApiResponse response)
594588
Walk(OpenApiConstants.Content, () => Walk(response.Content));
595589
Walk(OpenApiConstants.Links, () => Walk(response.Links));
596590
Walk(OpenApiConstants.Headers, () => Walk(response.Headers));
597-
598591
Walk(response as IOpenApiExtensible);
599592
}
600593

601594
/// <summary>
602595
/// Visits <see cref="OpenApiRequestBody"/> and child objects
603596
/// </summary>
604-
internal void Walk(OpenApiRequestBody requestBody)
597+
internal void Walk(OpenApiRequestBody requestBody, bool isComponent = false)
605598
{
606-
if (requestBody == null || IsReference(requestBody))
599+
if (requestBody == null || ProcessAsReference(requestBody, isComponent))
607600
{
608601
return;
609602
}
@@ -744,9 +737,9 @@ internal void Walk(OpenApiEncoding encoding)
744737
/// <summary>
745738
/// Visits <see cref="OpenApiSchema"/> and child objects
746739
/// </summary>
747-
internal void Walk(OpenApiSchema schema)
740+
internal void Walk(OpenApiSchema schema, bool isComponent = false)
748741
{
749-
if (schema == null || IsReference(schema))
742+
if (schema == null || ProcessAsReference(schema, isComponent))
750743
{
751744
return;
752745
}
@@ -831,9 +824,9 @@ internal void Walk(IOpenApiAny example)
831824
/// <summary>
832825
/// Visits <see cref="OpenApiExample"/> and child objects
833826
/// </summary>
834-
internal void Walk(OpenApiExample example)
827+
internal void Walk(OpenApiExample example, bool isComponent = false)
835828
{
836-
if (example == null || IsReference(example))
829+
if (example == null || ProcessAsReference(example, isComponent))
837830
{
838831
return;
839832
}
@@ -937,9 +930,9 @@ internal void Walk(IDictionary<string,OpenApiLink> links)
937930
/// <summary>
938931
/// Visits <see cref="OpenApiLink"/> and child objects
939932
/// </summary>
940-
internal void Walk(OpenApiLink link)
933+
internal void Walk(OpenApiLink link, bool isComponent = false)
941934
{
942-
if (link == null || IsReference(link))
935+
if (link == null || ProcessAsReference(link, isComponent))
943936
{
944937
return;
945938
}
@@ -952,9 +945,9 @@ internal void Walk(OpenApiLink link)
952945
/// <summary>
953946
/// Visits <see cref="OpenApiHeader"/> and child objects
954947
/// </summary>
955-
internal void Walk(OpenApiHeader header)
948+
internal void Walk(OpenApiHeader header, bool isComponent = false)
956949
{
957-
if (header == null || IsReference(header))
950+
if (header == null || ProcessAsReference(header, isComponent))
958951
{
959952
return;
960953
}
@@ -986,7 +979,7 @@ internal void Walk(OpenApiSecurityRequirement securityRequirement)
986979
/// </summary>
987980
internal void Walk(OpenApiSecurityScheme securityScheme)
988981
{
989-
if (securityScheme == null || IsReference(securityScheme))
982+
if (securityScheme == null || ProcessAsReference(securityScheme))
990983
{
991984
return;
992985
}
@@ -995,6 +988,14 @@ internal void Walk(OpenApiSecurityScheme securityScheme)
995988
Walk(securityScheme as IOpenApiExtensible);
996989
}
997990

991+
/// <summary>
992+
/// Visits <see cref="OpenApiSecurityScheme"/> and child objects
993+
/// </summary>
994+
internal void Walk(IOpenApiReferenceable referenceable)
995+
{
996+
_visitor.Visit(referenceable);
997+
}
998+
998999
/// <summary>
9991000
/// Dispatcher method that enables using a single method to walk the model
10001001
/// starting from any <see cref="IOpenApiElement"/>
@@ -1055,19 +1056,14 @@ private void Walk(string context, Action walk)
10551056
/// <summary>
10561057
/// Identify if an element is just a reference to a component, or an actual component
10571058
/// </summary>
1058-
private bool IsReference(IOpenApiReferenceable referenceable)
1059-
{
1060-
return referenceable.Reference != null && !_inComponents;
1061-
}
1062-
1063-
private void EnterComponents()
1064-
{
1065-
_inComponents = true;
1066-
}
1067-
1068-
private void ExitComponents()
1059+
private bool ProcessAsReference(IOpenApiReferenceable referenceable, bool isComponent = false)
10691060
{
1070-
_inComponents = false;
1061+
var isReference = referenceable.Reference != null && !isComponent;
1062+
if (isReference)
1063+
{
1064+
Walk(referenceable);
1065+
}
1066+
return isReference;
10711067
}
10721068
}
10731069

0 commit comments

Comments
 (0)