Skip to content

Commit 9155d11

Browse files
authoredMar 7, 2023
Merge pull request #1181 from microsoft/vnext
Merge dev into master
2 parents 2605650 + 8307d8e commit 9155d11

File tree

12 files changed

+69
-35
lines changed

12 files changed

+69
-35
lines changed
 

‎src/Microsoft.OpenApi.Hidi/Microsoft.OpenApi.Hidi.csproj

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<PackageId>Microsoft.OpenApi.Hidi</PackageId>
1616
<ToolCommandName>hidi</ToolCommandName>
1717
<PackageOutputPath>./../../artifacts</PackageOutputPath>
18-
<Version>1.2.3</Version>
18+
<Version>1.2.4</Version>
1919
<Description>OpenAPI.NET CLI tool for slicing OpenAPI documents</Description>
2020
<Copyright>© Microsoft Corporation. All rights reserved.</Copyright>
2121
<PackageTags>OpenAPI .NET</PackageTags>
@@ -42,7 +42,7 @@
4242
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="7.0.0" />
4343
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="7.0.0" />
4444
<PackageReference Include="System.CommandLine" Version="2.0.0-beta4.22272.1" />
45-
<PackageReference Include="Microsoft.OData.Edm" Version="7.14.1" />
45+
<PackageReference Include="Microsoft.OData.Edm" Version="7.15.0" />
4646
<PackageReference Include="Microsoft.OpenApi.OData" Version="1.3.0-preview2" />
4747
<PackageReference Include="System.CommandLine.Hosting" Version="0.4.0-alpha.22272.1" />
4848
</ItemGroup>

‎src/Microsoft.OpenApi.Hidi/OpenApiService.cs

+1-21
Original file line numberDiff line numberDiff line change
@@ -324,27 +324,7 @@ public static async Task<OpenApiDocument> ConvertCsdlToOpenApi(Stream csdl, stri
324324
var edmModel = CsdlReader.Parse(XElement.Parse(csdlText).CreateReader());
325325

326326
var config = GetConfiguration(settingsFile);
327-
var settings = new OpenApiConvertSettings()
328-
{
329-
AddSingleQuotesForStringParameters = true,
330-
AddEnumDescriptionExtension = true,
331-
DeclarePathParametersOnPathItem = true,
332-
EnableKeyAsSegment = true,
333-
EnableOperationId = true,
334-
ErrorResponsesAsDefault = false,
335-
PrefixEntityTypeNameBeforeKey = true,
336-
TagDepth = 2,
337-
EnablePagination = true,
338-
EnableDiscriminatorValue = true,
339-
EnableDerivedTypesReferencesForRequestBody = false,
340-
EnableDerivedTypesReferencesForResponses = false,
341-
ShowRootPath = false,
342-
ShowLinks = false,
343-
ExpandDerivedTypesNavigationProperties = false,
344-
EnableCount = true,
345-
UseSuccessStatusCodeRange = true,
346-
EnableTypeDisambiguationForDefaultValueOfOdataTypeProperty = true
347-
};
327+
var settings = new OpenApiConvertSettings();
348328
config.GetSection("OpenApiConvertSettings").Bind(settings);
349329

350330
OpenApiDocument document = edmModel.ConvertToOpenApi(settings);

‎src/Microsoft.OpenApi.Readers/Microsoft.OpenApi.Readers.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<Company>Microsoft</Company>
1111
<Title>Microsoft.OpenApi.Readers</Title>
1212
<PackageId>Microsoft.OpenApi.Readers</PackageId>
13-
<Version>1.6.2</Version>
13+
<Version>1.6.3</Version>
1414
<Description>OpenAPI.NET Readers for JSON and YAML documents</Description>
1515
<Copyright>© Microsoft Corporation. All rights reserved.</Copyright>
1616
<PackageTags>OpenAPI .NET</PackageTags>

‎src/Microsoft.OpenApi.Readers/OpenApiYamlDocumentReader.cs

-1
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,6 @@ private void ResolveReferences(OpenApiDiagnostic diagnostic, OpenApiDocument doc
166166
}
167167
}
168168

169-
170169
/// <summary>
171170
/// Reads the stream input and parses the fragment of an OpenAPI description into an Open API Element.
172171
/// </summary>

‎src/Microsoft.OpenApi.Readers/V3/OpenApiSecuritySchemeDeserializer.cs

+5-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,11 @@ internal static partial class OpenApiV3Deserializer
7676
public static OpenApiSecurityScheme LoadSecurityScheme(ParseNode node)
7777
{
7878
var mapNode = node.CheckMapNode("securityScheme");
79-
79+
var pointer = mapNode.GetReferencePointer();
80+
if (pointer != null)
81+
{
82+
return mapNode.GetReferencedObject<OpenApiSecurityScheme>(ReferenceType.SecurityScheme, pointer);
83+
}
8084
var securityScheme = new OpenApiSecurityScheme();
8185
foreach (var property in mapNode)
8286
{

‎src/Microsoft.OpenApi/Microsoft.OpenApi.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<Company>Microsoft</Company>
1212
<Title>Microsoft.OpenApi</Title>
1313
<PackageId>Microsoft.OpenApi</PackageId>
14-
<Version>1.6.2</Version>
14+
<Version>1.6.3</Version>
1515
<Description>.NET models with JSON and YAML writers for OpenAPI specification</Description>
1616
<Copyright>© Microsoft Corporation. All rights reserved.</Copyright>
1717
<PackageTags>OpenAPI .NET</PackageTags>

‎src/Microsoft.OpenApi/Services/OpenApiWalker.cs

+15-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) Microsoft Corporation. All rights reserved.
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT license.
33

44
using System;
@@ -116,7 +116,18 @@ internal void Walk(OpenApiComponents components)
116116
}
117117
}
118118
});
119-
119+
120+
Walk(OpenApiConstants.SecuritySchemes, () =>
121+
{
122+
if (components.SecuritySchemes != null)
123+
{
124+
foreach (var item in components.SecuritySchemes)
125+
{
126+
Walk(item.Key, () => Walk(item.Value, isComponent: true));
127+
}
128+
}
129+
});
130+
120131
Walk(OpenApiConstants.Callbacks, () =>
121132
{
122133
if (components.Callbacks != null)
@@ -996,9 +1007,9 @@ internal void Walk(OpenApiSecurityRequirement securityRequirement)
9961007
/// <summary>
9971008
/// Visits <see cref="OpenApiSecurityScheme"/> and child objects
9981009
/// </summary>
999-
internal void Walk(OpenApiSecurityScheme securityScheme)
1010+
internal void Walk(OpenApiSecurityScheme securityScheme, bool isComponent = false)
10001011
{
1001-
if (securityScheme == null || ProcessAsReference(securityScheme))
1012+
if (securityScheme == null || ProcessAsReference(securityScheme, isComponent))
10021013
{
10031014
return;
10041015
}

‎test/Microsoft.OpenApi.Readers.Tests/Microsoft.OpenApi.Readers.Tests.csproj

+3
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,9 @@
137137
<EmbeddedResource Include="V3Tests\Samples\OpenApiDocument\minimalDocument.yaml">
138138
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
139139
</EmbeddedResource>
140+
<EmbeddedResource Include="V3Tests\Samples\OpenApiDocument\docWithSecuritySchemeReference.yaml">
141+
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
142+
</EmbeddedResource>
140143
<EmbeddedResource Include="V3Tests\Samples\OpenApiDocument\apiWithFullHeaderComponent.yaml">
141144
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
142145
</EmbeddedResource>

‎test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiDocumentTests.cs

+22-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
using System;
55
using System.Collections.Generic;
6+
using System.Diagnostics.Contracts;
67
using System.Globalization;
78
using System.IO;
89
using System.Linq;
@@ -1334,10 +1335,10 @@ public void DoesNotChangeExternalReferences()
13341335
{
13351336
// Arrange
13361337
using var stream = Resources.GetStream(Path.Combine(SampleFolderPath, "documentWithExternalRefs.yaml"));
1337-
1338+
13381339
// Act
13391340
var doc = new OpenApiStreamReader(
1340-
new OpenApiReaderSettings { ReferenceResolution = ReferenceResolutionSetting.DoNotResolveReferences})
1341+
new OpenApiReaderSettings { ReferenceResolution = ReferenceResolutionSetting.DoNotResolveReferences })
13411342
.Read(stream, out var diagnostic);
13421343

13431344
var externalRef = doc.Components.Schemas["Nested"].Properties["AnyOf"].AnyOf.First().Reference.ReferenceV3;
@@ -1347,5 +1348,24 @@ public void DoesNotChangeExternalReferences()
13471348
Assert.Equal("file:///C:/MySchemas.json#/definitions/ArrayObject", externalRef);
13481349
Assert.Equal("../foo/schemas.yaml#/components/schemas/Number", externalRef2);
13491350
}
1351+
1352+
[Fact]
1353+
public void ParseDocumentWithReferencedSecuritySchemeWorks()
1354+
{
1355+
// Arrange
1356+
using var stream = Resources.GetStream(Path.Combine(SampleFolderPath, "docWithSecuritySchemeReference.yaml"));
1357+
1358+
// Act
1359+
var doc = new OpenApiStreamReader(new OpenApiReaderSettings
1360+
{
1361+
ReferenceResolution = ReferenceResolutionSetting.ResolveLocalReferences
1362+
}).Read(stream, out var diagnostic);
1363+
1364+
var securityScheme = doc.Components.SecuritySchemes["OAuth2"];
1365+
1366+
// Assert
1367+
Assert.False(securityScheme.UnresolvedReference);
1368+
Assert.NotNull(securityScheme.Flows);
1369+
}
13501370
}
13511371
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
openapi: 3.0.0
2+
info:
3+
title: Example API
4+
version: 1.0.0
5+
paths: { }
6+
components:
7+
securitySchemes:
8+
OAuth2:
9+
$ref: '#/components/securitySchemes/RefOAuth2'
10+
RefOAuth2:
11+
type: oauth2
12+
flows:
13+
implicit:
14+
authorizationUrl: https://example.com/api/oauth/dialog
15+
scopes:
16+
write:pets: modify pets in your account
17+
read:pets: read your pets

‎test/Microsoft.OpenApi.Tests/Microsoft.OpenApi.Tests.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
3636
</PackageReference>
3737
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
38-
<PackageReference Include="PublicApiGenerator" Version="10.3.0" />
38+
<PackageReference Include="PublicApiGenerator" Version="11.0.0" />
3939
</ItemGroup>
4040

4141
<ItemGroup>

‎test/Microsoft.OpenApi.Tests/PublicApi/PublicApiTests.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public void ReviewPublicApiChanges()
2626
// It takes a human to read the change, determine if it is breaking and update the PublicApi.approved.txt with the new approved API surface
2727

2828
// Arrange
29-
var publicApi = typeof(OpenApiSpecVersion).Assembly.GeneratePublicApi(new ApiGeneratorOptions() { WhitelistedNamespacePrefixes = new[] { "Microsoft.OpenApi" } } );
29+
var publicApi = typeof(OpenApiSpecVersion).Assembly.GeneratePublicApi(new ApiGeneratorOptions() { AllowNamespacePrefixes = new[] { "Microsoft.OpenApi" } } );
3030

3131
// Act
3232
var approvedFilePath = Path.Combine("PublicApi", "PublicApi.approved.txt");

0 commit comments

Comments
 (0)