Skip to content

Commit

Permalink
Merge pull request #1181 from microsoft/vnext
Browse files Browse the repository at this point in the history
Merge dev into master
  • Loading branch information
MaggieKimani1 authored Mar 7, 2023
2 parents 2605650 + 8307d8e commit 9155d11
Show file tree
Hide file tree
Showing 12 changed files with 69 additions and 35 deletions.
4 changes: 2 additions & 2 deletions src/Microsoft.OpenApi.Hidi/Microsoft.OpenApi.Hidi.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<PackageId>Microsoft.OpenApi.Hidi</PackageId>
<ToolCommandName>hidi</ToolCommandName>
<PackageOutputPath>./../../artifacts</PackageOutputPath>
<Version>1.2.3</Version>
<Version>1.2.4</Version>
<Description>OpenAPI.NET CLI tool for slicing OpenAPI documents</Description>
<Copyright>© Microsoft Corporation. All rights reserved.</Copyright>
<PackageTags>OpenAPI .NET</PackageTags>
Expand All @@ -42,7 +42,7 @@
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="7.0.0" />
<PackageReference Include="System.CommandLine" Version="2.0.0-beta4.22272.1" />
<PackageReference Include="Microsoft.OData.Edm" Version="7.14.1" />
<PackageReference Include="Microsoft.OData.Edm" Version="7.15.0" />
<PackageReference Include="Microsoft.OpenApi.OData" Version="1.3.0-preview2" />
<PackageReference Include="System.CommandLine.Hosting" Version="0.4.0-alpha.22272.1" />
</ItemGroup>
Expand Down
22 changes: 1 addition & 21 deletions src/Microsoft.OpenApi.Hidi/OpenApiService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -324,27 +324,7 @@ public static async Task<OpenApiDocument> ConvertCsdlToOpenApi(Stream csdl, stri
var edmModel = CsdlReader.Parse(XElement.Parse(csdlText).CreateReader());

var config = GetConfiguration(settingsFile);
var settings = new OpenApiConvertSettings()
{
AddSingleQuotesForStringParameters = true,
AddEnumDescriptionExtension = true,
DeclarePathParametersOnPathItem = true,
EnableKeyAsSegment = true,
EnableOperationId = true,
ErrorResponsesAsDefault = false,
PrefixEntityTypeNameBeforeKey = true,
TagDepth = 2,
EnablePagination = true,
EnableDiscriminatorValue = true,
EnableDerivedTypesReferencesForRequestBody = false,
EnableDerivedTypesReferencesForResponses = false,
ShowRootPath = false,
ShowLinks = false,
ExpandDerivedTypesNavigationProperties = false,
EnableCount = true,
UseSuccessStatusCodeRange = true,
EnableTypeDisambiguationForDefaultValueOfOdataTypeProperty = true
};
var settings = new OpenApiConvertSettings();
config.GetSection("OpenApiConvertSettings").Bind(settings);

OpenApiDocument document = edmModel.ConvertToOpenApi(settings);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<Company>Microsoft</Company>
<Title>Microsoft.OpenApi.Readers</Title>
<PackageId>Microsoft.OpenApi.Readers</PackageId>
<Version>1.6.2</Version>
<Version>1.6.3</Version>
<Description>OpenAPI.NET Readers for JSON and YAML documents</Description>
<Copyright>© Microsoft Corporation. All rights reserved.</Copyright>
<PackageTags>OpenAPI .NET</PackageTags>
Expand Down
1 change: 0 additions & 1 deletion src/Microsoft.OpenApi.Readers/OpenApiYamlDocumentReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,6 @@ private void ResolveReferences(OpenApiDiagnostic diagnostic, OpenApiDocument doc
}
}


/// <summary>
/// Reads the stream input and parses the fragment of an OpenAPI description into an Open API Element.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,11 @@ internal static partial class OpenApiV3Deserializer
public static OpenApiSecurityScheme LoadSecurityScheme(ParseNode node)
{
var mapNode = node.CheckMapNode("securityScheme");

var pointer = mapNode.GetReferencePointer();
if (pointer != null)
{
return mapNode.GetReferencedObject<OpenApiSecurityScheme>(ReferenceType.SecurityScheme, pointer);
}
var securityScheme = new OpenApiSecurityScheme();
foreach (var property in mapNode)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Microsoft.OpenApi/Microsoft.OpenApi.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<Company>Microsoft</Company>
<Title>Microsoft.OpenApi</Title>
<PackageId>Microsoft.OpenApi</PackageId>
<Version>1.6.2</Version>
<Version>1.6.3</Version>
<Description>.NET models with JSON and YAML writers for OpenAPI specification</Description>
<Copyright>© Microsoft Corporation. All rights reserved.</Copyright>
<PackageTags>OpenAPI .NET</PackageTags>
Expand Down
19 changes: 15 additions & 4 deletions src/Microsoft.OpenApi/Services/OpenApiWalker.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.

using System;
Expand Down Expand Up @@ -116,7 +116,18 @@ internal void Walk(OpenApiComponents components)
}
}
});


Walk(OpenApiConstants.SecuritySchemes, () =>
{
if (components.SecuritySchemes != null)
{
foreach (var item in components.SecuritySchemes)
{
Walk(item.Key, () => Walk(item.Value, isComponent: true));
}
}
});

Walk(OpenApiConstants.Callbacks, () =>
{
if (components.Callbacks != null)
Expand Down Expand Up @@ -996,9 +1007,9 @@ internal void Walk(OpenApiSecurityRequirement securityRequirement)
/// <summary>
/// Visits <see cref="OpenApiSecurityScheme"/> and child objects
/// </summary>
internal void Walk(OpenApiSecurityScheme securityScheme)
internal void Walk(OpenApiSecurityScheme securityScheme, bool isComponent = false)
{
if (securityScheme == null || ProcessAsReference(securityScheme))
if (securityScheme == null || ProcessAsReference(securityScheme, isComponent))
{
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,9 @@
<EmbeddedResource Include="V3Tests\Samples\OpenApiDocument\minimalDocument.yaml">
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
</EmbeddedResource>
<EmbeddedResource Include="V3Tests\Samples\OpenApiDocument\docWithSecuritySchemeReference.yaml">
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
</EmbeddedResource>
<EmbeddedResource Include="V3Tests\Samples\OpenApiDocument\apiWithFullHeaderComponent.yaml">
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
</EmbeddedResource>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using System;
using System.Collections.Generic;
using System.Diagnostics.Contracts;
using System.Globalization;
using System.IO;
using System.Linq;
Expand Down Expand Up @@ -1334,10 +1335,10 @@ public void DoesNotChangeExternalReferences()
{
// Arrange
using var stream = Resources.GetStream(Path.Combine(SampleFolderPath, "documentWithExternalRefs.yaml"));

// Act
var doc = new OpenApiStreamReader(
new OpenApiReaderSettings { ReferenceResolution = ReferenceResolutionSetting.DoNotResolveReferences})
new OpenApiReaderSettings { ReferenceResolution = ReferenceResolutionSetting.DoNotResolveReferences })
.Read(stream, out var diagnostic);

var externalRef = doc.Components.Schemas["Nested"].Properties["AnyOf"].AnyOf.First().Reference.ReferenceV3;
Expand All @@ -1347,5 +1348,24 @@ public void DoesNotChangeExternalReferences()
Assert.Equal("file:///C:/MySchemas.json#/definitions/ArrayObject", externalRef);
Assert.Equal("../foo/schemas.yaml#/components/schemas/Number", externalRef2);
}

[Fact]
public void ParseDocumentWithReferencedSecuritySchemeWorks()
{
// Arrange
using var stream = Resources.GetStream(Path.Combine(SampleFolderPath, "docWithSecuritySchemeReference.yaml"));

// Act
var doc = new OpenApiStreamReader(new OpenApiReaderSettings
{
ReferenceResolution = ReferenceResolutionSetting.ResolveLocalReferences
}).Read(stream, out var diagnostic);

var securityScheme = doc.Components.SecuritySchemes["OAuth2"];

// Assert
Assert.False(securityScheme.UnresolvedReference);
Assert.NotNull(securityScheme.Flows);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
openapi: 3.0.0
info:
title: Example API
version: 1.0.0
paths: { }
components:
securitySchemes:
OAuth2:
$ref: '#/components/securitySchemes/RefOAuth2'
RefOAuth2:
type: oauth2
flows:
implicit:
authorizationUrl: https://example.com/api/oauth/dialog
scopes:
write:pets: modify pets in your account
read:pets: read your pets
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
<PackageReference Include="PublicApiGenerator" Version="10.3.0" />
<PackageReference Include="PublicApiGenerator" Version="11.0.0" />
</ItemGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion test/Microsoft.OpenApi.Tests/PublicApi/PublicApiTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public void ReviewPublicApiChanges()
// 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

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

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

0 comments on commit 9155d11

Please sign in to comment.