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
11 changes: 9 additions & 2 deletions src/Microsoft.OpenApi/Reader/ParseNodes/PropertyNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

public ParseNode Value { get; set; }

public void ParseField<T>(

Check warning on line 24 in src/Microsoft.OpenApi/Reader/ParseNodes/PropertyNode.cs

View workflow job for this annotation

GitHub Actions / Build

Refactor this method to reduce its Cognitive Complexity from 19 to the 15 allowed. (https://rules.sonarsource.com/csharp/RSPEC-3776)

Check warning on line 24 in src/Microsoft.OpenApi/Reader/ParseNodes/PropertyNode.cs

View workflow job for this annotation

GitHub Actions / Build

Refactor this method to reduce its Cognitive Complexity from 19 to the 15 allowed. (https://rules.sonarsource.com/csharp/RSPEC-3776)

Check warning on line 24 in src/Microsoft.OpenApi/Reader/ParseNodes/PropertyNode.cs

View workflow job for this annotation

GitHub Actions / Build

Refactor this method to reduce its Cognitive Complexity from 19 to the 15 allowed. (https://rules.sonarsource.com/csharp/RSPEC-3776)

Check warning on line 24 in src/Microsoft.OpenApi/Reader/ParseNodes/PropertyNode.cs

View workflow job for this annotation

GitHub Actions / Build

Refactor this method to reduce its Cognitive Complexity from 19 to the 15 allowed. (https://rules.sonarsource.com/csharp/RSPEC-3776)
T parentInstance,
Dictionary<string, Action<T, ParseNode, OpenApiDocument>> fixedFields,
Dictionary<Func<string, bool>, Action<T, string, ParseNode, OpenApiDocument>> patternFields,
Expand Down Expand Up @@ -74,8 +74,15 @@
}
else
{
Context.Diagnostic.Errors.Add(
new("", $"{Name} is not a valid property at {Context.GetLocation()}"));
var error = new OpenApiError("", $"{Name} is not a valid property at {Context.GetLocation()}");
if ("$schema".Equals(Name, StringComparison.OrdinalIgnoreCase))
{
Context.Diagnostic.Warnings.Add(error);
}
else
{
Context.Diagnostic.Errors.Add(error);
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -579,6 +579,17 @@ public async Task ParseDocumentWithEmptyTagsWorks()

doc.Paths["/groups"].Operations[HttpMethod.Get].Tags.Should().BeNull("Empty tags are ignored, so we should not have any tags");
}
[Fact]
public async Task DocumentWithSchemaResultsInWarning()
{
var path = Path.Combine(SampleFolderPath, "documentWithSchema.json");
var (doc, diag) = await OpenApiDocument.LoadAsync(path, SettingsFixture.ReaderSettings);
Assert.NotNull(doc);
Assert.NotNull(diag);
Assert.Empty(diag.Errors);
Assert.Single(diag.Warnings);
Assert.StartsWith("$schema is not a valid property", diag.Warnings[0].Message);
}

[Fact]
public void ParseEmptyMemoryStreamThrowsAnArgumentException()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"$schema": "https://spec.openapis.org/oas/3.1/schema/2025-02-13",
"openapi": "3.1.0",
"info": {
"title": "Sample API",
"version": "1.0.0"
},
"paths": {
"/example": {
"get": {
"summary": "Example operation",
"responses": {
"200": {
"description": "Successful response",
"content": {
"application/json": {
"schema": {
"type": "string"
}
}
}
}
}
}
}
}
}
Loading