-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from christianhelle/petstore
Improve detection of external references
- Loading branch information
Showing
8 changed files
with
1,002 additions
and
127 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using System.Reflection; | ||
|
||
namespace OasReader.Tests; | ||
|
||
internal class EmbeddedResources | ||
{ | ||
public static string GetStream(string name) | ||
{ | ||
var assembly = Assembly.GetExecutingAssembly(); | ||
var resourceName = $"OasReader.Tests.Resources.{name}"; | ||
|
||
using var stream = assembly.GetManifestResourceStream(resourceName); | ||
using var reader = new StreamReader(stream ?? throw new InvalidOperationException($"Could not find the embedded resource {name}")); | ||
|
||
return reader.ReadToEnd(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
using FluentAssertions; | ||
using Microsoft.OpenApi.Models; | ||
using Microsoft.OpenApi.Readers; | ||
using Xunit; | ||
|
||
namespace OasReader.Tests; | ||
|
||
public class OpenApiDocumentExtensionsTests | ||
{ | ||
[Theory] | ||
[InlineData("bot.yaml", "bot.components.yaml")] | ||
[InlineData("petstore.yaml", "petstore.components.yaml")] | ||
public async Task Returns_NotNull(string apiFile, string componentsFile) | ||
{ | ||
var folder = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString("N")); | ||
Directory.CreateDirectory(folder); | ||
|
||
var componentsFilename = Path.Combine(folder, componentsFile); | ||
var openapiFilename = Path.Combine(folder, apiFile); | ||
|
||
var componentContents = EmbeddedResources.GetStream(componentsFile); | ||
var apiContents = EmbeddedResources.GetStream(apiFile); | ||
|
||
await File.WriteAllTextAsync(componentsFilename, componentContents); | ||
await File.WriteAllTextAsync(openapiFilename, apiContents); | ||
|
||
var file = File.OpenRead(openapiFilename); | ||
var textReader = new StreamReader(file); | ||
var reader = new OpenApiTextReaderReader(); | ||
var result = await reader.ReadAsync(textReader, CancellationToken.None); | ||
OpenApiDocument sut = result.OpenApiDocument; | ||
|
||
sut.ContainsExternalReferences().Should().BeTrue(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
Oops, something went wrong.