Skip to content

Commit

Permalink
Add test to validate
Browse files Browse the repository at this point in the history
  • Loading branch information
MaggieKimani1 committed Sep 26, 2023
1 parent 0720231 commit f359565
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@
<EmbeddedResource Include="V2Tests\Samples\basic.v3.yaml">
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
</EmbeddedResource>
<EmbeddedResource Include="V2Tests\Samples\ComponentRootReference.json">
<EmbeddedResource Include="V2Tests\Samples\docWithEmptyProduces.yaml">
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
</EmbeddedResource>
<EmbeddedResource Include="V2Tests\Samples\ComponentRootReference.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</EmbeddedResource>
<EmbeddedResource Include="V2Tests\Samples\minimal.v2.yaml">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -409,19 +409,27 @@ public void ShouldAssignSchemaToAllResponses()
[Fact]
public void ShouldAllowComponentsThatJustContainAReference()
{
using (var stream = Resources.GetStream(Path.Combine(SampleFolderPath, "ComponentRootReference.json")))
using var stream = Resources.GetStream(Path.Combine(SampleFolderPath, "ComponentRootReference.json"));
OpenApiStreamReader reader = new OpenApiStreamReader();
OpenApiDocument doc = reader.Read(stream, out OpenApiDiagnostic diags);
OpenApiSchema schema1 = doc.Components.Schemas["AllPets"];
Assert.False(schema1.UnresolvedReference);
OpenApiSchema schema2 = doc.ResolveReferenceTo<OpenApiSchema>(schema1.Reference);
if (schema2.UnresolvedReference && schema1.Reference.Id == schema2.Reference.Id)
{
OpenApiStreamReader reader = new OpenApiStreamReader();
OpenApiDocument doc = reader.Read(stream, out OpenApiDiagnostic diags);
OpenApiSchema schema1 = doc.Components.Schemas["AllPets"];
Assert.False(schema1.UnresolvedReference);
OpenApiSchema schema2 = doc.ResolveReferenceTo<OpenApiSchema>(schema1.Reference);
if (schema2.UnresolvedReference && schema1.Reference.Id == schema2.Reference.Id)
{
// detected a cycle - this code gets triggered
Assert.Fail("A cycle should not be detected");
}
// detected a cycle - this code gets triggered
Assert.Fail("A cycle should not be detected");
}
}

[Fact]
public void ParseDocumentWithDefaultContentTypeSettingShouldSucceed()
{
using var stream = Resources.GetStream(Path.Combine(SampleFolderPath, "docWithEmptyProduces.yaml"));
var doc = new OpenApiStreamReader(new OpenApiReaderSettings { DefaultContentType = new List<string> { "application/json" } })
.Read(stream, out OpenApiDiagnostic diags);
var mediaType = doc.Paths["/example"].Operations[OperationType.Get].Responses["200"].Content;
Assert.Contains("application/json", mediaType);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
swagger: '2.0'
info:
title: Sample API
version: 1.0.0
paths:
/example:
get:
summary: Get Example
description: Retrieves an example resource.
produces: []
responses:
200:
description: Successful response
schema:
format: binary,
description: The content of the file.,
type: string,
x-ms-summary: File Content
components: {}

0 comments on commit f359565

Please sign in to comment.