Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions src/Microsoft.OpenApi/Reader/ParsingContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -271,9 +271,9 @@ public void PopLoop(string loopid)

private void ValidateRequiredFields(OpenApiDocument doc, string version)
{
if ((version.is2_0() || version.is3_0()) && (doc.Paths == null || !doc.Paths.Any()))
if ((version.is2_0() || version.is3_0()) && (doc.Paths == null))
{
// paths is a required field in OpenAPI 3.0 but optional in 3.1
// paths is a required field in OpenAPI 2.0 and 3.0 but optional in 3.1
RootNode.Context.Diagnostic.Errors.Add(new OpenApiError("", $"Paths is a REQUIRED field at {RootNode.Context.GetLocation()}"));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,7 @@ public async Task DiagnosticReportMergedForExternalReferenceAsync()

Assert.NotNull(result);
Assert.NotNull(result.OpenApiDocument.Workspace);
result.OpenApiDiagnostic.Errors.Should().BeEquivalentTo(new List<OpenApiError>
{
new OpenApiError("", "[File: ./TodoReference.yaml] Paths is a REQUIRED field at #/")
});
result.OpenApiDiagnostic.Errors.Should().BeEmpty();
}
}

Expand Down
3 changes: 1 addition & 2 deletions test/Microsoft.OpenApi.Readers.Tests/ParseNodeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ public void BrokenSimpleList()
var result = OpenApiDocument.Parse(input, "yaml");

result.OpenApiDiagnostic.Errors.Should().BeEquivalentTo(new List<OpenApiError>() {
new OpenApiError(new OpenApiReaderException("Expected a value.")),
new OpenApiError("", "Paths is a REQUIRED field at #/")
new OpenApiError(new OpenApiReaderException("Expected a value."))
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,16 +96,7 @@ public void ParseDocumentWithDifferentCultureShouldSucceed(string culture)
.Excluding((IMemberInfo memberInfo) =>
memberInfo.Path.EndsWith("Parent"))
.Excluding((IMemberInfo memberInfo) =>
memberInfo.Path.EndsWith("Root")));

result.OpenApiDiagnostic.Should().BeEquivalentTo(
new OpenApiDiagnostic {
SpecificationVersion = OpenApiSpecVersion.OpenApi2_0,
Errors = new List<OpenApiError>()
{
new OpenApiError("", "Paths is a REQUIRED field at #/")
}
});
memberInfo.Path.EndsWith("Root")));;
}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -310,8 +310,7 @@ public void InvalidHostShouldYieldError()
{
Errors =
{
new OpenApiError("#/", "Invalid host"),
new OpenApiError("", "Paths is a REQUIRED field at #/")
new OpenApiError("#/", "Invalid host")
},
SpecificationVersion = OpenApiSpecVersion.OpenApi2_0
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,7 @@ public void ParseDocumentFromInlineStringShouldSucceed()
result.OpenApiDiagnostic.Should().BeEquivalentTo(
new OpenApiDiagnostic()
{
SpecificationVersion = OpenApiSpecVersion.OpenApi3_0,
Errors = new List<OpenApiError>()
{
new OpenApiError("", "Paths is a REQUIRED field at #/")
}
SpecificationVersion = OpenApiSpecVersion.OpenApi3_0
});
}

Expand All @@ -115,16 +111,7 @@ public void ParseBasicDocumentWithMultipleServersShouldSucceed()
var path = System.IO.Path.Combine(SampleFolderPath, "basicDocumentWithMultipleServers.yaml");
var result = OpenApiDocument.Load(path);

result.OpenApiDiagnostic.Should().BeEquivalentTo(
new OpenApiDiagnostic()
{
SpecificationVersion = OpenApiSpecVersion.OpenApi3_0,
Errors = new List<OpenApiError>()
{
new OpenApiError("", "Paths is a REQUIRED field at #/")
}
});

result.OpenApiDiagnostic.Errors.Should().BeEmpty();
result.OpenApiDocument.Should().BeEquivalentTo(
new OpenApiDocument
{
Expand Down Expand Up @@ -170,7 +157,6 @@ public void ParseBrokenMinimalDocumentShouldYieldExpectedDiagnostic()
{
Errors =
{
new OpenApiError("", "Paths is a REQUIRED field at #/"),
new OpenApiValidatorError(nameof(OpenApiInfoRules.InfoRequiredFields),"#/info/title", "The field 'title' in 'info' object is REQUIRED.")
},
SpecificationVersion = OpenApiSpecVersion.OpenApi3_0
Expand All @@ -196,11 +182,7 @@ public void ParseMinimalDocumentShouldSucceed()
result.OpenApiDiagnostic.Should().BeEquivalentTo(
new OpenApiDiagnostic()
{
SpecificationVersion = OpenApiSpecVersion.OpenApi3_0,
Errors = new List<OpenApiError>()
{
new OpenApiError("", "Paths is a REQUIRED field at #/")
}
SpecificationVersion = OpenApiSpecVersion.OpenApi3_0
});
}

Expand Down Expand Up @@ -1388,11 +1370,7 @@ public void ParseBasicDocumentWithServerVariableShouldSucceed()
result.OpenApiDiagnostic.Should().BeEquivalentTo(
new OpenApiDiagnostic
{
SpecificationVersion = OpenApiSpecVersion.OpenApi3_0,
Errors = new List<OpenApiError>()
{
new OpenApiError("", "Paths is a REQUIRED field at #/")
}
SpecificationVersion = OpenApiSpecVersion.OpenApi3_0
});

result.OpenApiDocument.Should().BeEquivalentTo(expected, options => options.Excluding(x => x.BaseUri));
Expand All @@ -1417,5 +1395,12 @@ public void ParseBasicDocumentWithServerVariableAndNoDefaultShouldFail()

result.OpenApiDiagnostic.Errors.Should().NotBeEmpty();
}

[Fact]
public void ParseDocumentWithEmptyPathsSucceeds()
{
var result = OpenApiDocument.Load(System.IO.Path.Combine(SampleFolderPath, "docWithEmptyPaths.yaml"));
result.OpenApiDiagnostic.Errors.Should().BeEmpty();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -241,11 +241,7 @@ public void ParseBasicSchemaWithReferenceShouldSucceed()
result.OpenApiDiagnostic.Should().BeEquivalentTo(
new OpenApiDiagnostic()
{
SpecificationVersion = OpenApiSpecVersion.OpenApi3_0,
Errors = new List<OpenApiError>()
{
new OpenApiError("", "Paths is a REQUIRED field at #/")
}
SpecificationVersion = OpenApiSpecVersion.OpenApi3_0
});

var expectedComponents = new OpenApiComponents
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
openapi: 3.0.0
info:
title: Sample API
version: 1.0.0
paths: {}
Loading