Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge dev into master #1181

Merged
merged 13 commits into from
Mar 7, 2023
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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