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
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
4 changes: 2 additions & 2 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
4 changes: 2 additions & 2 deletions src/Microsoft.OpenApi.Workbench/MainModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,8 @@ internal async Task ParseDocumentAsync()
}

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

stopwatch.Stop();
ParseTime = $"{stopwatch.ElapsedMilliseconds} ms";
Expand Down
8 changes: 4 additions & 4 deletions src/Microsoft.OpenApi/Reader/OpenApiJsonReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ public async Task<ReadResult> ReadAsync(TextReader input,
diagnostic.Errors.Add(new OpenApiError($"#line={ex.LineNumber}", $"Please provide the correct format, {ex.Message}"));
return new ReadResult
{
OpenApiDocument = null,
OpenApiDiagnostic = diagnostic
Document = null,
Diagnostic = diagnostic
};
}

Expand Down Expand Up @@ -118,8 +118,8 @@ public async Task<ReadResult> ReadAsync(JsonNode jsonNode,

return new()
{
OpenApiDocument = document,
OpenApiDiagnostic = diagnostic
Document = document,
Diagnostic = diagnostic
};
}

Expand Down
4 changes: 2 additions & 2 deletions src/Microsoft.OpenApi/Reader/ReadResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ public class ReadResult
/// <summary>
/// The parsed OpenApiDocument. Null will be returned if the document could not be parsed.
/// </summary>
public OpenApiDocument OpenApiDocument { set; get; }
public OpenApiDocument Document { get; set; }
/// <summary>
/// OpenApiDiagnostic contains the Errors reported while parsing
/// </summary>
public OpenApiDiagnostic OpenApiDiagnostic { set; get; }
public OpenApiDiagnostic Diagnostic { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,13 @@ internal async Task<OpenApiDiagnostic> LoadAsync(OpenApiReference reference,
var input = await _loader.LoadAsync(new(item.ExternalResource, UriKind.RelativeOrAbsolute));
var result = await OpenApiDocument.LoadAsync(input, format, _readerSettings, cancellationToken);
// Merge diagnostics
if (result.OpenApiDiagnostic != null)
if (result.Diagnostic != null)
{
diagnostic.AppendDiagnostic(result.OpenApiDiagnostic, item.ExternalResource);
diagnostic.AppendDiagnostic(result.Diagnostic, item.ExternalResource);
}
if (result.OpenApiDocument != null)
if (result.Document != null)
{
var loadDiagnostic = await LoadAsync(item, result.OpenApiDocument, format, diagnostic, cancellationToken);
var loadDiagnostic = await LoadAsync(item, result.Document, format, diagnostic, cancellationToken);
diagnostic = loadDiagnostic;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ public void CopiesOverAllReferencedComponentsToTheSubsetDocumentCorrectly()

// Act
using var stream = File.OpenRead(filePath);
var doc = OpenApiDocument.Load(stream, "yaml").OpenApiDocument;
var doc = OpenApiDocument.Load(stream, "yaml").Document;

var predicate = OpenApiFilterService.CreatePredicate(operationIds: operationIds);
var subsetOpenApiDocument = OpenApiFilterService.CreateFilteredDocument(doc, predicate);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,17 @@ public void DetectedSpecificationVersionShouldBeV2_0()
{
var actual = OpenApiDocument.Load("V2Tests/Samples/basic.v2.yaml");

actual.OpenApiDiagnostic.Should().NotBeNull();
actual.OpenApiDiagnostic.SpecificationVersion.Should().Be(OpenApiSpecVersion.OpenApi2_0);
actual.Diagnostic.Should().NotBeNull();
actual.Diagnostic.SpecificationVersion.Should().Be(OpenApiSpecVersion.OpenApi2_0);
}

[Fact]
public void DetectedSpecificationVersionShouldBeV3_0()
{
var actual = OpenApiDocument.Load("V3Tests/Samples/OpenApiDocument/minimalDocument.yaml");

actual.OpenApiDiagnostic.Should().NotBeNull();
actual.OpenApiDiagnostic.SpecificationVersion.Should().Be(OpenApiSpecVersion.OpenApi3_0);
actual.Diagnostic.Should().NotBeNull();
actual.Diagnostic.SpecificationVersion.Should().Be(OpenApiSpecVersion.OpenApi3_0);
}

[Fact]
Expand All @@ -55,8 +55,8 @@ public async Task DiagnosticReportMergedForExternalReferenceAsync()
result = await OpenApiDocument.LoadAsync("OpenApiReaderTests/Samples/OpenApiDiagnosticReportMerged/TodoMain.yaml", settings);

Assert.NotNull(result);
Assert.NotNull(result.OpenApiDocument.Workspace);
result.OpenApiDiagnostic.Errors.Should().BeEmpty();
Assert.NotNull(result.Document.Workspace);
result.Diagnostic.Errors.Should().BeEmpty();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public async Task StreamShouldReadWhenInitializedAsync()

// Read V3 as YAML
var result = OpenApiDocument.Load(stream, "yaml");
Assert.NotNull(result.OpenApiDocument);
Assert.NotNull(result.Document);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public async Task LoadingDocumentWithResolveAllReferencesShouldLoadDocumentIntoW

var result = await OpenApiDocument.LoadAsync(stream, OpenApiConstants.Yaml, settings: settings);

Assert.NotNull(result.OpenApiDocument.Workspace);
Assert.NotNull(result.Document.Workspace);
}

[Fact]
Expand All @@ -63,14 +63,14 @@ public async Task LoadDocumentWithExternalReferenceShouldLoadBothDocumentsIntoWo
ReadResult result;
result = await OpenApiDocument.LoadAsync("V3Tests/Samples/OpenApiWorkspace/TodoMain.yaml", settings);

var externalDocBaseUri = result.OpenApiDocument.Workspace.GetDocumentId("./TodoComponents.yaml");
var externalDocBaseUri = result.Document.Workspace.GetDocumentId("./TodoComponents.yaml");
var schemasPath = "/components/schemas/";
var parametersPath = "/components/parameters/";

Assert.NotNull(externalDocBaseUri);
Assert.True(result.OpenApiDocument.Workspace.Contains(externalDocBaseUri + schemasPath + "todo"));
Assert.True(result.OpenApiDocument.Workspace.Contains(externalDocBaseUri + schemasPath + "entity"));
Assert.True(result.OpenApiDocument.Workspace.Contains(externalDocBaseUri + parametersPath + "filter"));
Assert.True(result.Document.Workspace.Contains(externalDocBaseUri + schemasPath + "todo"));
Assert.True(result.Document.Workspace.Contains(externalDocBaseUri + schemasPath + "entity"));
Assert.True(result.Document.Workspace.Contains(externalDocBaseUri + parametersPath + "filter"));
}
}

Expand Down
4 changes: 2 additions & 2 deletions test/Microsoft.OpenApi.Readers.Tests/ParseNodeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public void BrokenSimpleList()

var result = OpenApiDocument.Parse(input, "yaml");

result.OpenApiDiagnostic.Errors.Should().BeEquivalentTo(new List<OpenApiError>() {
result.Diagnostic.Errors.Should().BeEquivalentTo(new List<OpenApiError>() {
new OpenApiError(new OpenApiReaderException("Expected a value."))
});
}
Expand All @@ -59,7 +59,7 @@ public void BadSchema()

var res= OpenApiDocument.Parse(input, "yaml");

res.OpenApiDiagnostic.Errors.Should().BeEquivalentTo(new List<OpenApiError>
res.Diagnostic.Errors.Should().BeEquivalentTo(new List<OpenApiError>
{
new(new OpenApiReaderException("schema must be a map/object") {
Pointer = "#/paths/~1foo/get/responses/200/content/application~1json/schema"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public void LoadParameterReference()
{
// Arrange
var result = OpenApiDocument.Load(Path.Combine(SampleFolderPath, "multipleReferences.v2.yaml"));
var reference = new OpenApiParameterReference("skipParam", result.OpenApiDocument);
var reference = new OpenApiParameterReference("skipParam", result.Document);

// Assert
reference.Should().BeEquivalentTo(
Expand All @@ -51,7 +51,7 @@ public void LoadSecuritySchemeReference()
{
var result = OpenApiDocument.Load(Path.Combine(SampleFolderPath, "multipleReferences.v2.yaml"));

var reference = new OpenApiSecuritySchemeReference("api_key_sample", result.OpenApiDocument);
var reference = new OpenApiSecuritySchemeReference("api_key_sample", result.Document);

// Assert
reference.Should().BeEquivalentTo(
Expand All @@ -69,7 +69,7 @@ public void LoadResponseReference()
{
var result = OpenApiDocument.Load(Path.Combine(SampleFolderPath, "multipleReferences.v2.yaml"));

var reference = new OpenApiResponseReference("NotFound", result.OpenApiDocument);
var reference = new OpenApiResponseReference("NotFound", result.Document);

// Assert
reference.Should().BeEquivalentTo(
Expand All @@ -88,7 +88,7 @@ public void LoadResponseReference()
public void LoadResponseAndSchemaReference()
{
var result = OpenApiDocument.Load(Path.Combine(SampleFolderPath, "multipleReferences.v2.yaml"));
var reference = new OpenApiResponseReference("GeneralError", result.OpenApiDocument);
var reference = new OpenApiResponseReference("GeneralError", result.Document);

// Assert
reference.Should().BeEquivalentTo(
Expand Down Expand Up @@ -118,7 +118,7 @@ public void LoadResponseAndSchemaReference()
{
Type = ReferenceType.Schema,
Id = "SampleObject2",
HostDocument = result.OpenApiDocument
HostDocument = result.Document
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public void ParseCustomExtension()
var diag = new OpenApiDiagnostic();
var actual = OpenApiDocument.Parse(description, "yaml", settings: settings);

var fooExtension = actual.OpenApiDocument.Info.Extensions["x-foo"] as FooExtension;
var fooExtension = actual.Document.Info.Extensions["x-foo"] as FooExtension;

fooExtension.Should().NotBeNull();
fooExtension.Bar.Should().Be("hey");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.

using System.IO;
Expand Down Expand Up @@ -26,10 +26,10 @@ public void EquivalentV2AndV3DocumentsShouldProduceEquivalentObjects(string file
var result1 = OpenApiDocument.Load(Path.Combine(SampleFolderPath, $"{fileName}.v2.yaml"));
var result2 = OpenApiDocument.Load(Path.Combine(SampleFolderPath, $"{fileName}.v3.yaml"));

result2.OpenApiDocument.Should().BeEquivalentTo(result1.OpenApiDocument,
result2.Document.Should().BeEquivalentTo(result1.Document,
options => options.Excluding(x => x.Workspace).Excluding(y => y.BaseUri));

result1.OpenApiDiagnostic.Errors.Should().BeEquivalentTo(result2.OpenApiDiagnostic.Errors);
result1.Diagnostic.Errors.Should().BeEquivalentTo(result2.Diagnostic.Errors);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public void ParseDocumentWithDifferentCultureShouldSucceed(string culture)
""",
"yaml");

result.OpenApiDocument.Should().BeEquivalentTo(
result.Document.Should().BeEquivalentTo(
new OpenApiDocument
{
Info = new()
Expand Down Expand Up @@ -145,16 +145,16 @@ public void ShouldParseProducesInAnyOrder()
Schema = new()
{
Type = JsonSchemaType.Array,
Items = new OpenApiSchemaReference("Item", result.OpenApiDocument)
Items = new OpenApiSchemaReference("Item", result.Document)
}
};

var errorMediaType = new OpenApiMediaType
{
Schema = new OpenApiSchemaReference("Error", result.OpenApiDocument)
Schema = new OpenApiSchemaReference("Error", result.Document)
};

result.OpenApiDocument.Should().BeEquivalentTo(new OpenApiDocument
result.Document.Should().BeEquivalentTo(new OpenApiDocument
{
Info = new()
{
Expand Down Expand Up @@ -264,16 +264,16 @@ public void ShouldAssignSchemaToAllResponses()
using var stream = Resources.GetStream(Path.Combine(SampleFolderPath, "multipleProduces.json"));
var result = OpenApiDocument.Load(stream, OpenApiConstants.Json);

Assert.Equal(OpenApiSpecVersion.OpenApi2_0, result.OpenApiDiagnostic.SpecificationVersion);
Assert.Equal(OpenApiSpecVersion.OpenApi2_0, result.Diagnostic.SpecificationVersion);

var successSchema = new OpenApiSchema
{
Type = JsonSchemaType.Array,
Items = new OpenApiSchemaReference("Item", result.OpenApiDocument)
Items = new OpenApiSchemaReference("Item", result.Document)
};
var errorSchema = new OpenApiSchemaReference("Error", result.OpenApiDocument);
var errorSchema = new OpenApiSchemaReference("Error", result.Document);

var responses = result.OpenApiDocument.Paths["/items"].Operations[OperationType.Get].Responses;
var responses = result.Document.Paths["/items"].Operations[OperationType.Get].Responses;
foreach (var response in responses)
{
var targetSchema = response.Key == "200" ? successSchema : errorSchema;
Expand All @@ -292,7 +292,7 @@ public void ShouldAssignSchemaToAllResponses()
public void ShouldAllowComponentsThatJustContainAReference()
{
// Act
var actual = OpenApiDocument.Load(Path.Combine(SampleFolderPath, "ComponentRootReference.json")).OpenApiDocument;
var actual = OpenApiDocument.Load(Path.Combine(SampleFolderPath, "ComponentRootReference.json")).Document;
var schema1 = actual.Components.Schemas["AllPets"];
Assert.False(schema1.UnresolvedReference);
var schema2 = actual.ResolveReferenceTo<OpenApiSchema>(schema1.Reference);
Expand All @@ -312,7 +312,7 @@ public void ParseDocumentWithDefaultContentTypeSettingShouldSucceed()
};

var actual = OpenApiDocument.Load(Path.Combine(SampleFolderPath, "docWithEmptyProduces.yaml"), settings);
var mediaType = actual.OpenApiDocument.Paths["/example"].Operations[OperationType.Get].Responses["200"].Content;
var mediaType = actual.Document.Paths["/example"].Operations[OperationType.Get].Responses["200"].Content;
Assert.Contains("application/json", mediaType);
}

Expand All @@ -321,7 +321,6 @@ public void testContentType()
{
var contentType = "application/json; charset = utf-8";
var res = contentType.Split(";".ToCharArray(), StringSplitOptions.RemoveEmptyEntries).First();
var expected = res.Split('/').LastOrDefault();
Assert.Equal("application/json", res);
}
}
Expand Down
Loading
Loading