Skip to content

Commit

Permalink
Merge branch 'vnext' into mk/add-convert-setting
Browse files Browse the repository at this point in the history
  • Loading branch information
MaggieKimani1 authored Nov 21, 2022
2 parents a810004 + cbafb8c commit e708a67
Show file tree
Hide file tree
Showing 18 changed files with 90 additions and 30 deletions.
9 changes: 7 additions & 2 deletions .azure-pipelines/ci-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,14 @@ stages:
- job: build
steps:
- task: UseDotNet@2
displayName: 'Use .NET 6'
displayName: 'Use .NET 2' # needed for ESRP signing
inputs:
version: 6.x
version: 2.x

- task: UseDotNet@2
displayName: 'Use .NET 7'
inputs:
version: 7.x

- task: PoliCheck@1
displayName: 'Run PoliCheck "/src"'
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci-cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: 6.0.x
dotnet-version: 7.0.x

- name: Data gatherer
id: data_gatherer
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: 6.0.x
dotnet-version: 7.0.x

- name: Initialize CodeQL
id: init_codeql
Expand Down
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"request": "launch",
"preLaunchTask": "build",
// If you have changed target frameworks, make sure to update the program path.
"program": "${workspaceFolder}/src/Microsoft.OpenApi.Hidi/bin/Debug/net6.0/Microsoft.OpenApi.Hidi.dll",
"program": "${workspaceFolder}/src/Microsoft.OpenApi.Hidi/bin/Debug/net7.0/Microsoft.OpenApi.Hidi.dll",
"args": [],
"cwd": "${workspaceFolder}/src/Microsoft.OpenApi.Hidi",
// For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Console
Expand Down
6 changes: 3 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build-env
FROM mcr.microsoft.com/dotnet/sdk:7.0 AS build-env
WORKDIR /app

COPY ./src ./hidi/src
WORKDIR /app/hidi
RUN dotnet publish ./src/Microsoft.OpenApi.Hidi/Microsoft.OpenApi.Hidi.csproj -c Release

FROM mcr.microsoft.com/dotnet/runtime:6.0 as runtime
FROM mcr.microsoft.com/dotnet/runtime:7.0 as runtime
WORKDIR /app

COPY --from=build-env /app/hidi/src/Microsoft.OpenApi.Hidi/bin/Release/net6.0 ./
COPY --from=build-env /app/hidi/src/Microsoft.OpenApi.Hidi/bin/Release/net7.0 ./

VOLUME /app/output
VOLUME /app/openapi.yml
Expand Down
6 changes: 3 additions & 3 deletions src/Microsoft.OpenApi.Hidi/Microsoft.OpenApi.Hidi.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net7.0</TargetFramework>
<LangVersion>9.0</LangVersion>
<PackAsTool>true</PackAsTool>
<PackageIconUrl>http://go.microsoft.com/fwlink/?LinkID=288890</PackageIconUrl>
Expand All @@ -15,7 +15,7 @@
<PackageId>Microsoft.OpenApi.Hidi</PackageId>
<ToolCommandName>hidi</ToolCommandName>
<PackageOutputPath>./../../artifacts</PackageOutputPath>
<Version>1.1.0-preview3</Version>
<Version>1.1.0</Version>
<Description>OpenAPI.NET CLI tool for slicing OpenAPI documents</Description>
<Copyright>© Microsoft Corporation. All rights reserved.</Copyright>
<PackageTags>OpenAPI .NET</PackageTags>
Expand Down Expand Up @@ -44,7 +44,7 @@
<PackageReference Include="System.CommandLine" Version="2.0.0-beta4.22272.1" />
<PackageReference Include="Microsoft.OData.Edm" Version="7.12.5" />
<PackageReference Include="Microsoft.OpenApi.OData" Version="1.2.0-preview8" />
<PackageReference Include="System.CommandLine.Hosting" Version="0.4.0-alpha.22114.1" />
<PackageReference Include="System.CommandLine.Hosting" Version="0.4.0-alpha.22272.1" />
</ItemGroup>

<ItemGroup>
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.4.4-preview1</Version>
<Version>1.4.4</Version>
<Description>OpenAPI.NET Readers for JSON and YAML documents</Description>
<Copyright>© Microsoft Corporation. All rights reserved.</Copyright>
<PackageTags>OpenAPI .NET</PackageTags>
Expand Down
17 changes: 11 additions & 6 deletions src/Microsoft.OpenApi.Readers/V3/OpenApiV3VersionService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ public OpenApiReference ConvertToOpenApiReference(
}
// Where fragments point into a non-OpenAPI document, the id will be the complete fragment identifier
string id = segments[1];
var openApiReference = new OpenApiReference();

// $ref: externalSource.yaml#/Pet
if (id.StartsWith("/components/"))
{
Expand All @@ -127,13 +129,16 @@ public OpenApiReference ConvertToOpenApiReference(
}
id = localSegments[3];
}

return new OpenApiReference
else
{
ExternalResource = segments[0],
Type = type,
Id = id
};
openApiReference.IsFragrament = true;
}

openApiReference.ExternalResource = segments[0];
openApiReference.Type = type;
openApiReference.Id = id;

return openApiReference;
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0-windows</TargetFramework>
<TargetFramework>net7.0-windows</TargetFramework>
<OutputType>WinExe</OutputType>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<UseWPF>true</UseWPF>
<ImportWindowsDesktopTargets>true</ImportWindowsDesktopTargets>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.DotNet.UpgradeAssistant.Extensions.Default.Analyzers" Version="0.4.346202">
<PackageReference Include="Microsoft.DotNet.UpgradeAssistant.Extensions.Default.Analyzers" Version="0.4.355802">
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.Windows.Compatibility" Version="7.0.0" />
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.4.4-preview1</Version>
<Version>1.4.4</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
12 changes: 11 additions & 1 deletion src/Microsoft.OpenApi/Models/OpenApiReference.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ public class OpenApiReference : IOpenApiSerializable
/// </summary>
public bool IsLocal => ExternalResource == null;

/// <summary>
/// Gets a flag indicating whether a file is a valid OpenAPI document or a fragment
/// </summary>
public bool IsFragrament = false;

/// <summary>
/// The OpenApiDocument that is hosting the OpenApiReference instance. This is used to enable dereferencing the reference.
/// </summary>
Expand Down Expand Up @@ -196,7 +201,12 @@ private string GetExternalReferenceV3()
{
if (Id != null)
{
return ExternalResource + "#/components/" + Type.GetDisplayName() + "/"+ Id;
if (IsFragrament)
{
return ExternalResource + "#" + Id;
}

return ExternalResource + "#/components/" + Type.GetDisplayName() + "/"+ Id;
}

return ExternalResource;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net6.0</TargetFrameworks>
<TargetFrameworks>net7.0</TargetFrameworks>
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
<Authors></Authors>
<Company>Microsoft</Company>
Expand Down Expand Up @@ -149,6 +149,9 @@
<EmbeddedResource Include="V3Tests\Samples\OpenApiDocument\petStoreWithTagAndSecurity.yaml">
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
</EmbeddedResource>
<EmbeddedResource Include="V3Tests\Samples\OpenApiDocument\documentWithExternalRefs.yaml">
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
</EmbeddedResource>
<EmbeddedResource Include="V3Tests\Samples\OpenApiDocument\securedApi.yaml" />
<EmbeddedResource Include="V3Tests\Samples\OpenApiEncoding\advancedEncoding.yaml">
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
Expand Down Expand Up @@ -253,7 +256,7 @@
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.4.0" />
<PackageReference Include="FluentAssertions" Version="6.8.0">
</PackageReference>
<PackageReference Include="Newtonsoft.Json" Version="13.0.2-beta1">
<PackageReference Include="Newtonsoft.Json" Version="13.0.2-beta2">
</PackageReference>
<PackageReference Include="SharpYaml" Version="2.1.0">
</PackageReference>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using FluentAssertions;
using Microsoft.OpenApi.Any;
Expand Down Expand Up @@ -1327,5 +1328,24 @@ public void HeaderParameterShouldAllowExample()
});
}
}

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

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

var externalRef = doc.Components.Schemas["Nested"].Properties["AnyOf"].AnyOf.First().Reference.ReferenceV3;
var externalRef2 = doc.Components.Schemas["Nested"].Properties["AnyOf"].AnyOf.Last().Reference.ReferenceV3;

// Assert
Assert.Equal("file:///C:/MySchemas.json#/definitions/ArrayObject", externalRef);
Assert.Equal("../foo/schemas.yaml#/components/schemas/Number", externalRef2);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
openapi: 3.0.1
info:
title: anyOf-oneOf
license:
name: MIT
version: 1.0.0
paths: { }
components:
schemas:
Nested:
type: object
properties:
AnyOf:
anyOf:
- $ref: file:///C:/MySchemas.json#/definitions/ArrayObject
- $ref: ../foo/schemas.yaml#/components/schemas/Number
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net6.0</TargetFrameworks>
<TargetFrameworks>net7.0</TargetFrameworks>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.4.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.2-beta1" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.2-beta2" />
<PackageReference Include="xunit" Version="2.4.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<PrivateAssets>all</PrivateAssets>
Expand Down
4 changes: 2 additions & 2 deletions test/Microsoft.OpenApi.Tests/Microsoft.OpenApi.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net6.0</TargetFrameworks>
<TargetFrameworks>net7.0</TargetFrameworks>
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
<Authors></Authors>
<Company>Microsoft</Company>
Expand All @@ -20,7 +20,7 @@
<PackageReference Include="Moq" Version="4.18.2" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="SharpYaml" Version="2.1.0" />
<PackageReference Include="Verify.Xunit" Version="18.4.0" />
<PackageReference Include="Verify.Xunit" Version="19.1.0" />
<PackageReference Include="xunit" Version="2.4.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<PrivateAssets>all</PrivateAssets>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[assembly: System.Reflection.AssemblyMetadata("RepositoryUrl", "https://github.com/Microsoft/OpenAPI.NET")]
[assembly: System.Runtime.CompilerServices.InternalsVisibleTo(@"Microsoft.OpenApi.Readers.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100957cb48387b2a5f54f5ce39255f18f26d32a39990db27cf48737afc6bc62759ba996b8a2bfb675d4e39f3d06ecb55a178b1b4031dcb2a767e29977d88cce864a0d16bfc1b3bebb0edf9fe285f10fffc0a85f93d664fa05af07faa3aad2e545182dbf787e3fd32b56aca95df1a3c4e75dec164a3f1a4c653d971b01ffc39eb3c4")]
[assembly: System.Runtime.CompilerServices.InternalsVisibleTo(@"Microsoft.OpenApi.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100957cb48387b2a5f54f5ce39255f18f26d32a39990db27cf48737afc6bc62759ba996b8a2bfb675d4e39f3d06ecb55a178b1b4031dcb2a767e29977d88cce864a0d16bfc1b3bebb0edf9fe285f10fffc0a85f93d664fa05af07faa3aad2e545182dbf787e3fd32b56aca95df1a3c4e75dec164a3f1a4c653d971b01ffc39eb3c4")]
[assembly: System.Runtime.Versioning.TargetFramework(".NETStandard,Version=v2.0", FrameworkDisplayName="")]
[assembly: System.Runtime.Versioning.TargetFramework(".NETStandard,Version=v2.0", FrameworkDisplayName=".NET Standard 2.0")]
namespace Microsoft.OpenApi.Any
{
public enum AnyType
Expand Down Expand Up @@ -773,6 +773,7 @@ namespace Microsoft.OpenApi.Models
}
public class OpenApiReference : Microsoft.OpenApi.Interfaces.IOpenApiElement, Microsoft.OpenApi.Interfaces.IOpenApiSerializable
{
public bool IsFragrament;
public OpenApiReference() { }
public OpenApiReference(Microsoft.OpenApi.Models.OpenApiReference reference) { }
public string ExternalResource { get; set; }
Expand Down

0 comments on commit e708a67

Please sign in to comment.