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

Release libs #1084

Merged
merged 65 commits into from
Nov 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
65 commits
Select commit Hold shift + click to select a range
2a22cd1
Configure CSDL via settings
darrelmiller May 11, 2022
168a58b
Bump Microsoft.OData.Edm from 7.12.4 to 7.12.5
dependabot[bot] Oct 25, 2022
6f9eab1
Merge pull request #1052 from microsoft/dependabot/nuget/Microsoft.OD…
baywet Oct 25, 2022
93d9108
Bump Verify.Xunit from 18.0.0 to 18.1.1
dependabot[bot] Oct 28, 2022
aa87e77
Bump Microsoft.Windows.Compatibility from 6.0.0 to 6.0.1
dependabot[bot] Oct 28, 2022
6352a45
Merge pull request #1055 from microsoft/dependabot/nuget/Microsoft.Wi…
baywet Oct 28, 2022
0bbb3a1
Merge pull request #1054 from microsoft/dependabot/nuget/Verify.Xunit…
baywet Oct 28, 2022
807dc2f
Bump mathieudutour/github-tag-action from 6.0 to 6.1
dependabot[bot] Oct 31, 2022
b89ebc2
Bump coverlet.collector from 3.1.2 to 3.2.0
dependabot[bot] Oct 31, 2022
5429810
Bump Verify.Xunit from 18.1.1 to 18.2.0
dependabot[bot] Oct 31, 2022
40d4f32
Merge pull request #1058 from microsoft/dependabot/nuget/coverlet.col…
baywet Oct 31, 2022
f3be735
Merge pull request #1059 from microsoft/dependabot/nuget/Verify.Xunit…
baywet Oct 31, 2022
8dd560f
Merge pull request #1057 from microsoft/dependabot/github_actions/mat…
baywet Oct 31, 2022
236a887
Bump Microsoft.OpenApi.OData from 1.2.0-preview5 to 1.2.0-preview6
dependabot[bot] Nov 2, 2022
05a1fd8
Bump Verify.Xunit from 18.2.0 to 18.3.0
dependabot[bot] Nov 2, 2022
d98e645
Merge pull request #1061 from microsoft/dependabot/nuget/Verify.Xunit…
baywet Nov 2, 2022
996dff4
Merge pull request #1060 from microsoft/dependabot/nuget/Microsoft.Op…
baywet Nov 2, 2022
2b13d3f
Remove return statement to eliminate NullReference exception
MaggieKimani1 Nov 3, 2022
e8d7410
Merge remote-tracking branch 'origin/vnext' into feature/csdlsettings
MaggieKimani1 Nov 4, 2022
e210137
Add a settingsFile parameter that allows one to input a path to the s…
MaggieKimani1 Nov 7, 2022
67586ec
Add test
MaggieKimani1 Nov 7, 2022
6f0bf13
Use backslash in filePath
MaggieKimani1 Nov 7, 2022
568cf91
Clean up tests
MaggieKimani1 Nov 7, 2022
24a0817
Merge pull request #1062 from microsoft/mk/better-error-reporting
MaggieKimani1 Nov 7, 2022
efd2ac8
Bump Microsoft.Windows.Compatibility from 6.0.1 to 7.0.0
dependabot[bot] Nov 7, 2022
4f94911
Bump Microsoft.NET.Test.Sdk from 17.3.2 to 17.4.0
dependabot[bot] Nov 7, 2022
f5e3b2e
Bump Verify.Xunit from 18.3.0 to 18.4.0
dependabot[bot] Nov 7, 2022
2bde9e8
Bump Microsoft.Extensions.Logging.Abstractions from 6.0.2 to 7.0.0
dependabot[bot] Nov 7, 2022
f07f4bd
Merge pull request #1069 from microsoft/dependabot/nuget/Microsoft.NE…
baywet Nov 7, 2022
707394e
Merge pull request #1071 from microsoft/dependabot/nuget/Microsoft.Ex…
baywet Nov 7, 2022
59c8e79
Merge pull request #1068 from microsoft/dependabot/nuget/Microsoft.Wi…
baywet Nov 7, 2022
69aa3d5
Merge pull request #1070 from microsoft/dependabot/nuget/Verify.Xunit…
baywet Nov 7, 2022
a4bbda0
Bump Microsoft.Extensions.Logging from 6.0.0 to 7.0.0
dependabot[bot] Nov 7, 2022
f354ec0
Merge pull request #1067 from microsoft/dependabot/nuget/Microsoft.Ex…
baywet Nov 7, 2022
4e81b9b
Bump Microsoft.Extensions.Logging.Console from 6.0.0 to 7.0.0
dependabot[bot] Nov 7, 2022
9b8a0a2
Merge pull request #1065 from microsoft/dependabot/nuget/Microsoft.Ex…
baywet Nov 7, 2022
a54c8f9
Bump Microsoft.Extensions.Logging.Debug from 6.0.0 to 7.0.0
dependabot[bot] Nov 7, 2022
ab9bafb
Merge pull request #1066 from microsoft/dependabot/nuget/Microsoft.Ex…
baywet Nov 7, 2022
ec05eca
Address PR feedback
MaggieKimani1 Nov 8, 2022
7637861
Merge pull request #1064 from microsoft/feature/csdlsettings
MaggieKimani1 Nov 8, 2022
973cd6d
- upgrades to dotnet 7
baywet Nov 8, 2022
c9285d3
Bump System.CommandLine.Hosting
dependabot[bot] Nov 8, 2022
4925319
Merge pull request #1074 from microsoft/dependabot/nuget/System.Comma…
baywet Nov 8, 2022
996d853
Merge branch 'vnext' into feature/net7
baywet Nov 8, 2022
07c4567
Bump Microsoft.OpenApi.OData from 1.2.0-preview6 to 1.2.0-preview7
dependabot[bot] Nov 8, 2022
75c8e15
Merge pull request #1073 from microsoft/dependabot/nuget/Microsoft.Op…
baywet Nov 8, 2022
b6a22d5
Bump Verify.Xunit from 18.4.0 to 19.0.0
dependabot[bot] Nov 9, 2022
8538d19
Bump Microsoft.DotNet.UpgradeAssistant.Extensions.Default.Analyzers
dependabot[bot] Nov 9, 2022
8f0a70f
Merge pull request #1076 from microsoft/dependabot/nuget/Microsoft.Do…
baywet Nov 9, 2022
6c994a5
Merge pull request #1075 from microsoft/dependabot/nuget/Verify.Xunit…
baywet Nov 9, 2022
fb9633d
- adds dotnet 6 since ESRP requires it
baywet Nov 10, 2022
82fa72c
Merge branch 'feature/net7' of https://github.com/microsoft/OpenAPI.N…
baywet Nov 10, 2022
8529c42
- switches to dotnet 2 to fix ESRP
baywet Nov 10, 2022
02b42e3
Merge pull request #1072 from microsoft/feature/net7
baywet Nov 10, 2022
b69da0d
Bump Verify.Xunit from 19.0.0 to 19.1.0
dependabot[bot] Nov 14, 2022
f5626b2
Merge pull request #1078 from microsoft/dependabot/nuget/Verify.Xunit…
baywet Nov 14, 2022
3a679dd
Bump Microsoft.OpenApi.OData from 1.2.0-preview7 to 1.2.0-preview8
dependabot[bot] Nov 17, 2022
ed00216
Merge pull request #1081 from microsoft/dependabot/nuget/Microsoft.Op…
baywet Nov 17, 2022
2d48b61
Adds a flag for identifying whether an external reference is a fragment
MaggieKimani1 Nov 18, 2022
901346c
Adds tests to verify external references that are fragments aren't re…
MaggieKimani1 Nov 18, 2022
f73e673
Update public API
MaggieKimani1 Nov 18, 2022
4428e67
Move variable declaration closer to assignment
MaggieKimani1 Nov 18, 2022
482175d
Merge pull request #1082 from microsoft/mk/reader-changes-external-re…
MaggieKimani1 Nov 18, 2022
5be9a79
Bump up lib versions from preview to stable releases
MaggieKimani1 Nov 21, 2022
cbafb8c
Merge pull request #1083 from microsoft/mk/bump-up-lib-versions
MaggieKimani1 Nov 21, 2022
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
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
4 changes: 2 additions & 2 deletions .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 Expand Up @@ -49,7 +49,7 @@ jobs:
- if: steps.conditionals_handler.outputs.is_default_branch == 'true'
name: Bump GH tag
id: tag_generator
uses: mathieudutour/github-tag-action@v6.0
uses: mathieudutour/github-tag-action@v6.1
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
default_bump: false
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
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ internal class TransformCommandHandler : ICommandHandler
public Option<string?> VersionOption { get; set; }
public Option<OpenApiFormat?> FormatOption { get; set; }
public Option<bool> TerseOutputOption { get; set; }
public Option<string> SettingsFileOption { get; set; }
public Option<LogLevel> LogLevelOption { get; set; }
public Option<string> FilterByOperationIdsOption { get; set; }
public Option<string> FilterByTagsOption { get; set; }
Expand All @@ -42,6 +43,7 @@ public async Task<int> InvokeAsync(InvocationContext context)
string? version = context.ParseResult.GetValueForOption(VersionOption);
OpenApiFormat? format = context.ParseResult.GetValueForOption(FormatOption);
bool terseOutput = context.ParseResult.GetValueForOption(TerseOutputOption);
string settingsFile = context.ParseResult.GetValueForOption(SettingsFileOption);
LogLevel logLevel = context.ParseResult.GetValueForOption(LogLevelOption);
bool inlineLocal = context.ParseResult.GetValueForOption(InlineLocalOption);
bool inlineExternal = context.ParseResult.GetValueForOption(InlineExternalOption);
Expand All @@ -54,7 +56,7 @@ public async Task<int> InvokeAsync(InvocationContext context)
var logger = loggerFactory.CreateLogger<OpenApiService>();
try
{
await OpenApiService.TransformOpenApiDocument(openapi, csdl, csdlFilter, output, cleanOutput, version, format, terseOutput, logLevel, inlineLocal, inlineExternal, filterbyoperationids, filterbytags, filterbycollection, cancellationToken);
await OpenApiService.TransformOpenApiDocument(openapi, csdl, csdlFilter, output, cleanOutput, version, format, terseOutput, settingsFile, logLevel, inlineLocal, inlineExternal, filterbyoperationids, filterbytags, filterbycollection, cancellationToken);

return 0;
}
Expand Down
25 changes: 17 additions & 8 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 All @@ -37,18 +37,27 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Logging" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="6.0.2" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="7.0.0" />
<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.12.4" />
<PackageReference Include="Microsoft.OpenApi.OData" Version="1.2.0-preview5" />
<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.22272.1" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Microsoft.OpenApi.Readers\Microsoft.OpenApi.Readers.csproj" />
<ProjectReference Include="..\Microsoft.OpenApi\Microsoft.OpenApi.csproj" />
</ItemGroup>

<!-- Make internals available for Unit Testing -->
<ItemGroup>
<AssemblyAttribute Include="System.Runtime.CompilerServices.InternalsVisibleTo">
<_Parameter1>Microsoft.OpenApi.Hidi.Tests</_Parameter1>
</AssemblyAttribute>
</ItemGroup>
<!-- End Unit test Internals -->

</Project>
26 changes: 22 additions & 4 deletions src/Microsoft.OpenApi.Hidi/OpenApiService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
using System.Xml.Xsl;
using System.Xml;
using System.Reflection;
using Microsoft.Extensions.Configuration;
using System.Runtime.CompilerServices;

namespace Microsoft.OpenApi.Hidi
{
Expand All @@ -44,6 +46,7 @@ public static async Task TransformOpenApiDocument(
string? version,
OpenApiFormat? format,
bool terseOutput,
string settingsFile,
LogLevel logLevel,
bool inlineLocal,
bool inlineExternal,
Expand Down Expand Up @@ -98,7 +101,8 @@ CancellationToken cancellationToken
stream = ApplyFilter(csdl, csdlFilter, transform);
stream.Position = 0;
}
document = await ConvertCsdlToOpenApi(stream);

document = await ConvertCsdlToOpenApi(stream, settingsFile);
stopwatch.Stop();
logger.LogTrace("{timestamp}ms: Generated OpenAPI with {paths} paths.", stopwatch.ElapsedMilliseconds, document.Paths.Count);
}
Expand Down Expand Up @@ -304,25 +308,37 @@ public static async Task ValidateOpenApiDocument(
}
}

internal static IConfiguration GetConfiguration(string settingsFile)
{
settingsFile ??= "appsettings.json";

IConfiguration config = new ConfigurationBuilder()
.AddJsonFile(settingsFile, true)
.Build();

return config;
}

/// <summary>
/// Converts CSDL to OpenAPI
/// </summary>
/// <param name="csdl">The CSDL stream.</param>
/// <returns>An OpenAPI document.</returns>
public static async Task<OpenApiDocument> ConvertCsdlToOpenApi(Stream csdl)
public static async Task<OpenApiDocument> ConvertCsdlToOpenApi(Stream csdl, string settingsFile = null)
{
using var reader = new StreamReader(csdl);
var csdlText = await reader.ReadToEndAsync();
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,
ErrorResponsesAsDefault = false,
PrefixEntityTypeNameBeforeKey = true,
TagDepth = 2,
EnablePagination = true,
Expand All @@ -335,6 +351,8 @@ public static async Task<OpenApiDocument> ConvertCsdlToOpenApi(Stream csdl)
EnableCount = true,
UseSuccessStatusCodeRange = true
};
config.GetSection("OpenApiConvertSettings").Bind(settings);

OpenApiDocument document = edmModel.ConvertToOpenApi(settings);

document = FixReferences(document);
Expand Down
11 changes: 11 additions & 0 deletions src/Microsoft.OpenApi.Hidi/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,14 @@
// Licensed under the MIT license.

using System.CommandLine;
using System.CommandLine.Builder;
using System.CommandLine.Hosting;
using System.CommandLine.Parsing;

using System.IO;
using System.Threading.Tasks;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using Microsoft.OpenApi.Hidi.Handlers;

Expand Down Expand Up @@ -41,6 +47,9 @@ static async Task Main(string[] args)
var terseOutputOption = new Option<bool>("--terse-output", "Produce terse json output");
terseOutputOption.AddAlias("--to");

var settingsFileOption = new Option<string>("--settings-path", "The configuration file with CSDL conversion settings.");
settingsFileOption.AddAlias("--sp");

var logLevelOption = new Option<LogLevel>("--log-level", () => LogLevel.Information, "The log level to use when logging messages to the main output.");
logLevelOption.AddAlias("--ll");

Expand Down Expand Up @@ -81,6 +90,7 @@ static async Task Main(string[] args)
versionOption,
formatOption,
terseOutputOption,
settingsFileOption,
logLevelOption,
filterByOperationIdsOption,
filterByTagsOption,
Expand All @@ -99,6 +109,7 @@ static async Task Main(string[] args)
VersionOption = versionOption,
FormatOption = formatOption,
TerseOutputOption = terseOutputOption,
SettingsFileOption = settingsFileOption,
LogLevelOption = logLevelOption,
FilterByOperationIdsOption = filterByOperationIdsOption,
FilterByTagsOption = filterByTagsOption,
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
18 changes: 11 additions & 7 deletions src/Microsoft.OpenApi.Readers/V3/OpenApiV3VersionService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,12 @@ public OpenApiReference ConvertToOpenApiReference(
catch (OpenApiException ex)
{
Diagnostic.Errors.Add(new OpenApiError(ex));
return null;
}
}
// 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 @@ -128,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,16 +1,16 @@
<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="6.0.0" />
<PackageReference Include="Microsoft.Windows.Compatibility" Version="7.0.0" />
</ItemGroup>
<ItemGroup>
<Resource Include="Themes\Metro\HowToApplyTheme.txt" />
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
Loading