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 v2-preview-3 #1987

Closed
wants to merge 101 commits into from
Closed
Show file tree
Hide file tree
Changes from 87 commits
Commits
Show all changes
101 commits
Select commit Hold shift + click to select a range
bd9622e
fix: multiple performance fixes for type serialization
baywet Nov 12, 2024
ba81e37
chore(deps): bump Microsoft.Extensions.Logging.Abstractions
dependabot[bot] Nov 12, 2024
0ab2350
chore(deps): bump System.Text.Json from 8.0.5 to 9.0.0 (#1920)
dependabot[bot] Nov 13, 2024
d5b11ea
chore(deps): bump System.Formats.Asn1 and Microsoft.Windows.Compatibi…
dependabot[bot] Nov 13, 2024
17f36c6
Merge pull request #1919 from microsoft/dependabot/nuget/Microsoft.Ex…
baywet Nov 13, 2024
5fef51c
Merge pull request #1915 from microsoft/fix/performance-type-serializ…
baywet Nov 13, 2024
d9fccee
chore(deps): bump Verify.Xunit from 28.2.0 to 28.2.1
dependabot[bot] Nov 13, 2024
243d680
chore(deps): bump Microsoft.Extensions.Logging and Microsoft.Extensio…
dependabot[bot] Nov 13, 2024
342e643
chore(deps): bump Microsoft.OData.Edm from 8.2.0 to 8.2.1
dependabot[bot] Nov 13, 2024
b5ebf59
chore(deps): bump Microsoft.VisualStudio.Threading.Analyzers
dependabot[bot] Nov 13, 2024
34c97e4
Merge pull request #1925 from microsoft/dependabot/nuget/Verify.Xunit…
andrueastman Nov 14, 2024
3d2681e
Merge pull request #1928 from microsoft/dependabot/nuget/Microsoft.Vi…
baywet Nov 14, 2024
a64718b
Merge pull request #1926 from microsoft/dependabot/nuget/multi-fd6639…
andrueastman Nov 14, 2024
863faee
Merge pull request #1927 from microsoft/dependabot/nuget/Microsoft.OD…
baywet Nov 14, 2024
3ca0672
chore: removes newtonsoft dependency all together
baywet Nov 14, 2024
a92dfe7
Merge pull request #1931 from microsoft/chore/newtonsoft-removal
baywet Nov 14, 2024
36752ad
chore(deps): bump Microsoft.Extensions.Logging, Microsoft.Extensions.…
dependabot[bot] Nov 14, 2024
a44e789
chore(deps): bump Verify.Xunit from 28.2.1 to 28.3.1
dependabot[bot] Nov 15, 2024
e1eafea
Fix link to OpenAPI specification
mikekistler Nov 17, 2024
83c571a
Merge pull request #1936 from microsoft/dependabot/nuget/Verify.Xunit…
andrueastman Nov 18, 2024
f243300
Merge pull request #1938 from mikekistler/mdk/fix-spec-link
andrueastman Nov 18, 2024
0cab0e7
Clean up tags serialization logic
MaggieKimani1 Nov 18, 2024
5a51460
Add test to validate
MaggieKimani1 Nov 18, 2024
262acd4
chore(deps): bump Verify.Xunit from 28.3.1 to 28.3.2
dependabot[bot] Nov 18, 2024
0bf5a42
Merge pull request #1941 from microsoft/dependabot/nuget/Verify.Xunit…
andrueastman Nov 19, 2024
6615079
Use range for STJ reference and suppress warnings
MaggieKimani1 Nov 19, 2024
c98ca28
Revert change for hidi
MaggieKimani1 Nov 19, 2024
b0a0e8e
Add const keyword and serialization logic
MaggieKimani1 Nov 19, 2024
067fbdd
Deserialize const keyword
MaggieKimani1 Nov 19, 2024
70c7d43
Add test and update API
MaggieKimani1 Nov 19, 2024
2630ebb
chore(deps): bump Microsoft.OData.Edm from 8.2.1 to 8.2.2
dependabot[bot] Nov 19, 2024
36bc990
chore(deps): bump Microsoft.NET.Test.Sdk from 17.11.1 to 17.12.0
dependabot[bot] Nov 19, 2024
537f964
Merge pull request #1944 from microsoft/dependabot/nuget/Microsoft.OD…
baywet Nov 19, 2024
687fa87
Merge pull request #1945 from microsoft/dependabot/nuget/Microsoft.NE…
baywet Nov 19, 2024
1338905
Merge pull request #1942 from microsoft/mk/add-range-for-STJ-reference
MaggieKimani1 Nov 20, 2024
12ee205
refactor to use backing fields
MaggieKimani1 Nov 20, 2024
c1d831f
Clean up tests
MaggieKimani1 Nov 20, 2024
03edbc9
Allow empty paths object as valid
MaggieKimani1 Nov 25, 2024
1af4f13
Add test to validate; clean up tests
MaggieKimani1 Nov 25, 2024
cbc99c1
Use the selected format label
MaggieKimani1 Nov 25, 2024
9b237c6
Suppress warnings
MaggieKimani1 Nov 25, 2024
171241e
make property and method static
MaggieKimani1 Nov 25, 2024
506ef1f
clean up code
MaggieKimani1 Nov 25, 2024
5ceb174
Merge pull request #1956 from microsoft/mk/fix-workbench-format-bug
MaggieKimani1 Nov 26, 2024
98b01e0
Merge pull request #1943 from microsoft/mk/add-json-schema-const-keyword
MaggieKimani1 Nov 26, 2024
6a830b8
Merge remote-tracking branch 'origin/vnext' into mk/fix-empty-paths-f…
MaggieKimani1 Nov 26, 2024
e6ab1cd
Merge pull request #1955 from microsoft/mk/fix-empty-paths-failing
MaggieKimani1 Nov 26, 2024
f0f0a05
Merge remote-tracking branch 'origin/vnext' into mk/fix-tags-serializ…
MaggieKimani1 Nov 26, 2024
fe77796
chore(deps): bump Verify.Xunit from 28.3.2 to 28.4.0
dependabot[bot] Nov 28, 2024
3ae2f91
Merge pull request #1976 from microsoft/dependabot/nuget/Verify.Xunit…
andrueastman Dec 2, 2024
36df13d
chore(deps): bump docker/build-push-action from 6.9.0 to 6.10.0
dependabot[bot] Dec 2, 2024
f64202b
Merge pull request #1977 from microsoft/dependabot/github_actions/doc…
andrueastman Dec 3, 2024
76d581b
Adds required pipeline metadata
MaggieKimani1 Dec 3, 2024
7f6432f
Merge pull request #1978 from microsoft/mk/add-security-metadata
MaggieKimani1 Dec 3, 2024
ef765f1
chore(deps): bump FluentAssertions from 6.12.2 to 7.0.0
dependabot[bot] Dec 3, 2024
47bf1eb
Merge pull request #1979 from microsoft/dependabot/nuget/FluentAssert…
andrueastman Dec 4, 2024
f1ec813
Rename Read Result properties
MaggieKimani1 Dec 9, 2024
07237af
Implement serialization and deserialization logic for unrecognized JS…
MaggieKimani1 Dec 10, 2024
e3310f5
Rename method
MaggieKimani1 Dec 10, 2024
208d0fd
Add tests to validate
MaggieKimani1 Dec 10, 2024
b91c13e
Clean up
MaggieKimani1 Dec 10, 2024
d7064c4
Remove code smells
MaggieKimani1 Dec 11, 2024
f27415d
Reduce redundancy and use LINQ statement
MaggieKimani1 Dec 11, 2024
4bc34b1
chore(deps): bump PublicApiGenerator from 11.1.0 to 11.2.0
dependabot[bot] Dec 11, 2024
1caaaaa
chore(deps): bump Microsoft.OData.Edm from 8.2.2 to 8.2.3
dependabot[bot] Dec 12, 2024
1beb8af
Merge pull request #1986 from microsoft/dependabot/nuget/Microsoft.OD…
baywet Dec 13, 2024
bea3b4f
Merge pull request #1984 from microsoft/dependabot/nuget/PublicApiGen…
andrueastman Dec 13, 2024
7e9b952
Bump preview versions
MaggieKimani1 Dec 13, 2024
bd29345
Merge pull request #1988 from microsoft/mk/bump-preview-version
MaggieKimani1 Dec 13, 2024
b1265fc
chore(deps): bump Verify.Xunit from 28.4.0 to 28.5.0
dependabot[bot] Dec 13, 2024
06767a2
Merge pull request #1990 from microsoft/dependabot/nuget/Verify.Xunit…
andrueastman Dec 16, 2024
f0ac82d
chore(deps): bump xunit.runner.visualstudio from 2.8.2 to 3.0.0
dependabot[bot] Dec 16, 2024
7db6469
Merge pull request #1992 from microsoft/dependabot/nuget/xunit.runner…
andrueastman Dec 17, 2024
7556ba5
Merge pull request #1939 from microsoft/mk/fix-tags-serialization
MaggieKimani1 Dec 17, 2024
5e9bb19
chore(deps): bump Verify.Xunit from 28.5.0 to 28.6.0
dependabot[bot] Dec 17, 2024
5c958f8
chore(deps): bump PublicApiGenerator from 11.2.0 to 11.3.0
dependabot[bot] Dec 17, 2024
7df6194
Merge pull request #1994 from microsoft/dependabot/nuget/PublicApiGen…
andrueastman Dec 18, 2024
d9a2481
Merge pull request #1993 from microsoft/dependabot/nuget/Verify.Xunit…
andrueastman Dec 18, 2024
8305982
chore: adds baywet to code owners
baywet Dec 19, 2024
97f125d
Merge pull request #1996 from microsoft/chore/baywet-code-owner
baywet Dec 19, 2024
6899424
Merge pull request #1981 from microsoft/mk/rename-read-result-props
MaggieKimani1 Dec 19, 2024
09158e2
chore: uses backing fields
baywet Dec 19, 2024
7d297be
chore: code linting
baywet Dec 19, 2024
146b44f
Update src/Microsoft.OpenApi/Reader/V31/OpenApiSchemaDeserializer.cs
baywet Dec 19, 2024
7be32fc
Revert "Update src/Microsoft.OpenApi/Reader/V31/OpenApiSchemaDeserial…
baywet Dec 19, 2024
2443fa0
fix: missing property rename
baywet Dec 19, 2024
8bf3fbe
Merge pull request #1982 from microsoft/mk/support-unrecognized-keywords
baywet Dec 19, 2024
4f55597
chore: exposes unused property so consumers can read the information
baywet Dec 19, 2024
b00b557
chore: aligns parameter names with base definition
baywet Dec 19, 2024
f9f7766
chore: aligns parameter names
baywet Dec 19, 2024
a72c5c2
chore: linting
baywet Dec 19, 2024
b9ef21d
chore: removes conflicting overload
baywet Dec 19, 2024
84e83f4
chore: reduces loops
baywet Dec 19, 2024
4f28b65
fix: extensions collection initialization
baywet Dec 19, 2024
778184f
fix: restores default constructor for ISerializable implementation
baywet Dec 19, 2024
e86df13
chore: makes regex internal
baywet Dec 19, 2024
28b226e
Merge pull request #1997 from microsoft/chore/linting
baywet Dec 19, 2024
329df70
chore: fixes extraneous master references
baywet Dec 19, 2024
8999336
fix: sets hidi version to a preview
baywet Dec 19, 2024
975b1bf
Merge pull request #2000 from microsoft/fix/hidi-preview
baywet Dec 19, 2024
fbe390b
Merge pull request #1999 from microsoft/chore/master-linting
baywet Dec 19, 2024
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
36 changes: 21 additions & 15 deletions .azure-pipelines/ci-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,13 @@ extends:
dependsOn: build
jobs:
- deployment: deploy_hidi
templateContext:
type: releaseJob
isProduction: true
inputs:
- input: pipelineArtifact
artifactName: Nugets
targetPath: '$(Pipeline.Workspace)'
dependsOn: []
environment: nuget-org
strategy:
Expand All @@ -218,11 +225,6 @@ extends:
pool:
vmImage: ubuntu-latest
steps:
- task: DownloadPipelineArtifact@2
displayName: Download nupkg from artifacts
inputs:
artifact: Nugets
source: current
- task: DownloadPipelineArtifact@2
displayName: Download hidi executable from artifacts
inputs:
Expand Down Expand Up @@ -264,6 +266,13 @@ extends:
]'

- deployment: deploy_lib
templateContext:
type: releaseJob
isProduction: true
inputs:
- input: pipelineArtifact
artifactName: Nugets
targetPath: '$(Pipeline.Workspace)'
dependsOn: []
environment: nuget-org
strategy:
Expand All @@ -272,11 +281,6 @@ extends:
pool:
vmImage: ubuntu-latest
steps:
- task: DownloadPipelineArtifact@2
displayName: Download nupkg from artifacts
inputs:
artifact: Nugets
source: current
- powershell: |
$fileNames = "$(Pipeline.Workspace)/Nugets/Microsoft.OpenApi.Hidi.*.nupkg", "$(Pipeline.Workspace)/Nugets/Microsoft.OpenApi.Readers.*.nupkg", "$(Pipeline.Workspace)/Nugets/Microsoft.OpenApi.Workbench.*.nupkg"
foreach($fileName in $fileNames) {
Expand All @@ -294,6 +298,13 @@ extends:
publishFeedCredentials: 'OpenAPI Nuget Connection'

- deployment: deploy_readers
templateContext:
type: releaseJob
isProduction: true
inputs:
- input: pipelineArtifact
artifactName: Nugets
targetPath: '$(Pipeline.Workspace)'
dependsOn: deploy_lib
environment: nuget-org
strategy:
Expand All @@ -302,11 +313,6 @@ extends:
pool:
vmImage: ubuntu-latest
steps:
- task: DownloadPipelineArtifact@2
displayName: Download nupkg from artifacts
inputs:
artifact: Nugets
source: current
- task: 1ES.PublishNuget@1
displayName: 'NuGet push'
inputs:
Expand Down
2 changes: 1 addition & 1 deletion .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -1 +1 @@
* @irvinesunday @darrelmiller @gavinbarron @millicentachieng @MaggieKimani1 @andrueastman
* @irvinesunday @darrelmiller @gavinbarron @millicentachieng @MaggieKimani1 @andrueastman @baywet
4 changes: 2 additions & 2 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ jobs:
id: getversion
- name: Push to GitHub Packages - Nightly
if: ${{ github.ref == 'refs/heads/vnext' }}
uses: docker/build-push-action@v6.9.0
uses: docker/build-push-action@v6.10.0
with:
push: true
tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:nightly
- name: Push to GitHub Packages - Release
if: ${{ github.ref == 'refs/heads/master' }}
uses: docker/build-push-action@v6.9.0
uses: docker/build-push-action@v6.10.0
with:
push: true
tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest,${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.getversion.outputs.version }}
12 changes: 6 additions & 6 deletions src/Microsoft.OpenApi.Hidi/Microsoft.OpenApi.Hidi.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -29,23 +29,23 @@

<ItemGroup>
<PackageReference Include="Humanizer.Core" Version="2.14.1" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.1" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.2" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="8.0.1" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="9.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="9.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="9.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="8.0.1" />
<PackageReference Include="Microsoft.VisualStudio.Threading.Analyzers" Version="17.11.20">
<PackageReference Include="Microsoft.VisualStudio.Threading.Analyzers" Version="17.12.19">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="System.CommandLine" Version="2.0.0-beta4.22272.1" />
<PackageReference Include="Microsoft.OData.Edm" Version="8.2.0" />
<PackageReference Include="Microsoft.OData.Edm" Version="8.2.3" />
<PackageReference Include="Microsoft.OpenApi.OData" Version="2.0.0-preview.7" />
<PackageReference Include="Microsoft.OpenApi.ApiManifest" Version="0.5.0-preview" />
<PackageReference Include="System.CommandLine.Hosting" Version="0.4.0-alpha.22272.1" />
<!--STJ
required until Microsoft.Extensions.Logging.Console and Microsoft.Extensions.Configuration.Json
update their dependencies -->
<PackageReference Include="System.Text.Json" Version="8.0.5" />
<PackageReference Include="System.Text.Json" Version="9.0.0" />
</ItemGroup>

<ItemGroup>
Expand Down
10 changes: 5 additions & 5 deletions src/Microsoft.OpenApi.Hidi/OpenApiService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ private static async Task<OpenApiDocument> GetOpenApiAsync(HidiOptions options,
{
stream = await GetStreamAsync(options.OpenApi, logger, cancellationToken).ConfigureAwait(false);
var result = await ParseOpenApiAsync(options.OpenApi, options.InlineExternal, logger, stream, cancellationToken).ConfigureAwait(false);
document = result.OpenApiDocument;
document = result.Document;
}
else throw new InvalidOperationException("No input file path or URL provided");

Expand Down Expand Up @@ -358,7 +358,7 @@ private static MemoryStream ApplyFilterToCsdl(Stream csdlStream, string entitySe
{
var statsVisitor = new StatsVisitor();
var walker = new OpenApiWalker(statsVisitor);
walker.Walk(result.OpenApiDocument);
walker.Walk(result.Document);

logger.LogTrace("Finished walking through the OpenApi document. Generating a statistics report..");
#pragma warning disable CA2254
Expand All @@ -377,7 +377,7 @@ private static MemoryStream ApplyFilterToCsdl(Stream csdlStream, string entitySe

if (result is null) return null;

return result.OpenApiDiagnostic.Errors.Count == 0;
return result.Diagnostic.Errors.Count == 0;
}

private static async Task<ReadResult> ParseOpenApiAsync(string openApiFile, bool inlineExternal, ILogger logger, Stream stream, CancellationToken cancellationToken = default)
Expand Down Expand Up @@ -439,7 +439,7 @@ public static OpenApiDocument FixReferences(OpenApiDocument document, string for
var sb = new StringBuilder();
document.SerializeAsV3(new OpenApiYamlWriter(new StringWriter(sb)));

var doc = OpenApiDocument.Parse(sb.ToString(), format).OpenApiDocument;
var doc = OpenApiDocument.Parse(sb.ToString(), format).Document;

return doc;
}
Expand Down Expand Up @@ -649,7 +649,7 @@ private static string GetInputPathExtension(string? openapi = null, string? csdl

private static void LogErrors(ILogger logger, ReadResult result)
{
var context = result.OpenApiDiagnostic;
var context = result.Diagnostic;
if (context.Errors.Count != 0)
{
using (logger.BeginScope("Detected errors"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<TargetFramework>netstandard2.0</TargetFramework>
<LangVersion>latest</LangVersion>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Version>2.0.0-preview2</Version>
<Version>2.0.0-preview3</Version>
<Description>OpenAPI.NET Readers for JSON and YAML documents</Description>
<SignAssembly>true</SignAssembly>
<!-- https://github.com/dotnet/sourcelink/blob/main/docs/README.md#embeduntrackedsources -->
Expand All @@ -25,13 +25,15 @@

<ItemGroup>

<PackageReference Include="Microsoft.VisualStudio.Threading.Analyzers" Version="17.11.20">
<PackageReference Include="Microsoft.VisualStudio.Threading.Analyzers" Version="17.12.19">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>

<PackageReference Include="SharpYaml" Version="2.1.1" />
<PackageReference Include="System.Text.Json" Version="8.0.5" />
<PackageReference Include="System.Text.Json" Version="[8.0,)" />
<NuGetAuditSuppress Include="https://github.com/advisories/GHSA-hh2w-p6rv-4g7w" />
<NuGetAuditSuppress Include="https://github.com/advisories/GHSA-8g4q-xg66-9fp4" />
</ItemGroup>

<ItemGroup>
Expand Down
6 changes: 3 additions & 3 deletions src/Microsoft.OpenApi.Readers/OpenApiYamlReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ public async Task<ReadResult> ReadAsync(TextReader input,
diagnostic.Errors.Add(new($"#line={ex.LineNumber}", ex.Message));
return new()
{
OpenApiDocument = null,
OpenApiDiagnostic = diagnostic
Document = null,
Diagnostic = diagnostic
};
}

Expand Down Expand Up @@ -77,7 +77,7 @@ static JsonNode LoadJsonNodesFromYamlDocument(TextReader input)
{
var yamlStream = new YamlStream();
yamlStream.Load(input);
var yamlDocument = yamlStream.Documents.First();
var yamlDocument = yamlStream.Documents[0];
return yamlDocument.ToJsonNode();
}

Expand Down
44 changes: 15 additions & 29 deletions src/Microsoft.OpenApi.Workbench/MainModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public class MainModel : INotifyPropertyChanged
/// </summary>
private OpenApiSpecVersion _version = OpenApiSpecVersion.OpenApi3_0;

private HttpClient _httpClient = new();
private static readonly HttpClient _httpClient = new();

public string Input
{
Expand Down Expand Up @@ -166,31 +166,31 @@ public OpenApiSpecVersion Version
public bool IsYaml
{
get => Format == OpenApiFormat.Yaml;
set => Format = OpenApiFormat.Yaml;
set => Format = value ? OpenApiFormat.Yaml : Format;
}

public bool IsJson
{
get => Format == OpenApiFormat.Json;
set => Format = OpenApiFormat.Json;
set => Format = value ? OpenApiFormat.Json : Format;
}

public bool IsV2_0
{
get => Version == OpenApiSpecVersion.OpenApi2_0;
set => Version = OpenApiSpecVersion.OpenApi2_0;
set => Version = value ? OpenApiSpecVersion.OpenApi2_0 : Version;
}

public bool IsV3_0
{
get => Version == OpenApiSpecVersion.OpenApi3_0;
set => Version = OpenApiSpecVersion.OpenApi3_0;
set => Version = value ? OpenApiSpecVersion.OpenApi3_0 : Version;
}

public bool IsV3_1
{
get => Version == OpenApiSpecVersion.OpenApi3_1;
set => Version = OpenApiSpecVersion.OpenApi3_1;
set => Version = value ? OpenApiSpecVersion.OpenApi3_1 : Version;
}

/// <summary>
Expand Down Expand Up @@ -219,14 +219,8 @@ internal async Task ParseDocumentAsync()
{
if (!string.IsNullOrWhiteSpace(_inputFile))
{
if (_inputFile.StartsWith("http"))
{
stream = await _httpClient.GetStreamAsync(_inputFile);
}
else
{
stream = new FileStream(_inputFile, FileMode.Open);
}
stream = _inputFile.StartsWith("http") ? await _httpClient.GetStreamAsync(_inputFile)
: new FileStream(_inputFile, FileMode.Open);
}
else
{
Expand All @@ -245,22 +239,15 @@ internal async Task ParseDocumentAsync()
ReferenceResolution = ResolveExternal ? ReferenceResolutionSetting.ResolveAllReferences : ReferenceResolutionSetting.ResolveLocalReferences,
RuleSet = ValidationRuleSet.GetDefaultRuleSet()
};
if (ResolveExternal)
if (ResolveExternal && !string.IsNullOrWhiteSpace(_inputFile))
{
if (_inputFile.StartsWith("http"))
{
settings.BaseUrl = new(_inputFile);
}
else
{
settings.BaseUrl = new("file://" + Path.GetDirectoryName(_inputFile) + "/");
}
settings.BaseUrl = _inputFile.StartsWith("http") ? new(_inputFile)
: new("file://" + Path.GetDirectoryName(_inputFile) + "/");
}

var format = OpenApiModelFactory.GetFormat(_inputFile);
var readResult = await OpenApiDocument.LoadAsync(stream, format);
var document = readResult.OpenApiDocument;
var context = readResult.OpenApiDiagnostic;
var readResult = await OpenApiDocument.LoadAsync(stream, Format.GetDisplayName());
var document = readResult.Document;
var context = readResult.Diagnostic;

stopwatch.Stop();
ParseTime = $"{stopwatch.ElapsedMilliseconds} ms";
Expand Down Expand Up @@ -306,7 +293,6 @@ internal async Task ParseDocumentAsync()
stream.Close();
await stream.DisposeAsync();
}

}
}

Expand All @@ -332,7 +318,7 @@ private string WriteContents(OpenApiDocument document)
return new StreamReader(outputStream).ReadToEnd();
}

private MemoryStream CreateStream(string text)
private static MemoryStream CreateStream(string text)
{
var stream = new MemoryStream();
var writer = new StreamWriter(stream);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,16 @@
<UseWPF>true</UseWPF>
<ImportWindowsDesktopTargets>true</ImportWindowsDesktopTargets>
<EnableWindowsTargeting>true</EnableWindowsTargeting>
<NoWarn>NU1903</NoWarn>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.VisualStudio.Threading.Analyzers" Version="17.11.20">
<PackageReference Include="Microsoft.VisualStudio.Threading.Analyzers" Version="17.12.19">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.Windows.Compatibility" Version="8.0.10" />
<PackageReference Include="Microsoft.Windows.Compatibility" Version="9.0.0" />
<!-- Microsoft.Windows.Compatibility 8.0.8 depends on 8.0.0 this dependency can be removed once they update theirs -->
<PackageReference Include="System.Formats.Asn1" Version="8.0.1" />
<PackageReference Include="System.Formats.Asn1" Version="9.0.0" />
</ItemGroup>
<ItemGroup>
<Resource Include="Themes\Metro\HowToApplyTheme.txt" />
Expand Down
18 changes: 17 additions & 1 deletion src/Microsoft.OpenApi/Extensions/OpenApiTypeMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,41 @@
/// </summary>
public static class OpenApiTypeMapper
{
#nullable enable
/// <summary>
/// Maps a JsonSchema data type to an identifier.
/// </summary>
/// <param name="schemaType"></param>
/// <returns></returns>
public static string ToIdentifier(this JsonSchemaType? schemaType)
public static string? ToIdentifier(this JsonSchemaType? schemaType)
{
if (schemaType is null)
{
return null;
}
return schemaType.Value.ToIdentifier();
}

/// <summary>
/// Maps a JsonSchema data type to an identifier.
/// </summary>
/// <param name="schemaType"></param>
/// <returns></returns>
public static string? ToIdentifier(this JsonSchemaType schemaType)
{
return schemaType switch
{
JsonSchemaType.Null => "null",
JsonSchemaType.Boolean => "boolean",

Check warning on line 41 in src/Microsoft.OpenApi/Extensions/OpenApiTypeMapper.cs

View workflow job for this annotation

GitHub Actions / Build

Define a constant instead of using this literal 'boolean' 4 times. (https://rules.sonarsource.com/csharp/RSPEC-1192)
JsonSchemaType.Integer => "integer",

Check warning on line 42 in src/Microsoft.OpenApi/Extensions/OpenApiTypeMapper.cs

View workflow job for this annotation

GitHub Actions / Build

Define a constant instead of using this literal 'integer' 8 times. (https://rules.sonarsource.com/csharp/RSPEC-1192)
JsonSchemaType.Number => "number",

Check warning on line 43 in src/Microsoft.OpenApi/Extensions/OpenApiTypeMapper.cs

View workflow job for this annotation

GitHub Actions / Build

Define a constant instead of using this literal 'number' 14 times. (https://rules.sonarsource.com/csharp/RSPEC-1192)
JsonSchemaType.String => "string",

Check warning on line 44 in src/Microsoft.OpenApi/Extensions/OpenApiTypeMapper.cs

View workflow job for this annotation

GitHub Actions / Build

Define a constant instead of using this literal 'string' 13 times. (https://rules.sonarsource.com/csharp/RSPEC-1192)
JsonSchemaType.Array => "array",
JsonSchemaType.Object => "object",
_ => null,
};
}
#nullable restore

/// <summary>
/// Converts a schema type's identifier into the enum equivalent
Expand Down
Loading
Loading