From 56bb53290b785cc06d4530d2274307b2ba240eb8 Mon Sep 17 00:00:00 2001 From: Maggiekimani1 Date: Thu, 13 Feb 2025 14:42:26 +0300 Subject: [PATCH 1/7] feat: enable NRT --- .../Extensions/OpenApiExtensibleExtensions.cs | 2 +- .../Formatters/PowerShellFormatter.cs | 9 +- src/Microsoft.OpenApi.Hidi/OpenApiService.cs | 36 ++-- .../Microsoft.OpenApi.Readers.csproj | 1 + .../OpenApiYamlReader.cs | 6 +- src/Microsoft.OpenApi/Any/OpenApiAny.cs | 6 +- .../Attributes/DisplayAttribute.cs | 4 +- .../Exceptions/OpenApiException.cs | 4 +- .../Exceptions/OpenApiReaderException.cs | 4 +- .../OpenApiUnsupportedSpecVersionException.cs | 4 +- .../Exceptions/OpenApiWriterException.cs | 2 +- .../Expressions/BodyExpression.cs | 4 +- .../Expressions/HeaderExpression.cs | 2 +- .../Expressions/PathExpression.cs | 2 +- .../Expressions/QueryExpression.cs | 2 +- .../Expressions/RuntimeExpression.cs | 4 +- .../Expressions/SourceExpression.cs | 4 +- .../Extensions/EnumExtensions.cs | 11 +- .../Extensions/OpenApiExtensibleExtensions.cs | 5 +- .../OpenApiReferencableExtensions.cs | 18 +- .../OpenApiSerializableExtensions.cs | 12 +- .../Extensions/OpenApiServerExtensions.cs | 50 ++--- .../Extensions/StringExtensions.cs | 17 +- .../Helpers/JsonNodeCloneHelper.cs | 4 +- .../Interfaces/IOpenApiAnnotatable.cs | 4 +- .../Interfaces/IOpenApiExtensible.cs | 2 +- .../Interfaces/IOpenApiReadOnlyExtensible.cs | 4 +- .../Interfaces/IOpenApiReader.cs | 2 +- .../Interfaces/IOpenApiReferenceHolder.cs | 6 +- .../Interfaces/IOpenApiVersionService.cs | 6 +- .../Interfaces/IShallowCopyable.cs | 2 +- src/Microsoft.OpenApi/JsonPointer.cs | 2 +- .../Microsoft.OpenApi.csproj | 1 + .../OpenApiDeprecationExtension.cs | 2 +- .../OpenApiEnumValuesDescriptionExtension.cs | 2 +- .../OpenApiPagingExtension.cs | 2 +- .../OpenApiPrimaryErrorMessageExtension.cs | 2 +- .../OpenApiReservedParameterExtension.cs | 2 +- .../Models/Interfaces/IOpenApiCallback.cs | 4 +- .../Interfaces/IOpenApiDescribedElement.cs | 6 +- .../Models/Interfaces/IOpenApiExample.cs | 6 +- .../Models/Interfaces/IOpenApiHeader.cs | 10 +- .../Models/Interfaces/IOpenApiLink.cs | 12 +- .../Models/Interfaces/IOpenApiParameter.cs | 12 +- .../Models/Interfaces/IOpenApiPathItem.cs | 8 +- .../Models/Interfaces/IOpenApiRequestBody.cs | 8 +- .../Models/Interfaces/IOpenApiResponse.cs | 8 +- .../Models/Interfaces/IOpenApiSchema.cs | 60 +++--- .../Interfaces/IOpenApiSecurityScheme.cs | 12 +- .../Interfaces/IOpenApiSummarizedElement.cs | 4 +- .../Models/Interfaces/IOpenApiTag.cs | 6 +- .../Models/OpenApiCallback.cs | 13 +- .../Models/OpenApiContact.cs | 8 +- .../Models/OpenApiDiscriminator.cs | 6 +- .../Models/OpenApiDocument.cs | 148 +++++++------ .../Models/OpenApiEncoding.cs | 6 +- src/Microsoft.OpenApi/Models/OpenApiError.cs | 4 +- .../Models/OpenApiExample.cs | 10 +- .../Models/OpenApiExtensibleDictionary.cs | 6 +- .../Models/OpenApiExternalDocs.cs | 8 +- src/Microsoft.OpenApi/Models/OpenApiHeader.cs | 16 +- src/Microsoft.OpenApi/Models/OpenApiInfo.cs | 24 +-- .../Models/OpenApiLicense.cs | 10 +- src/Microsoft.OpenApi/Models/OpenApiLink.cs | 14 +- .../Models/OpenApiOAuthFlow.cs | 12 +- .../Models/OpenApiOAuthFlows.cs | 20 +- .../Models/OpenApiOperation.cs | 16 +- .../Models/OpenApiParameter.cs | 22 +- .../Models/OpenApiPathItem.cs | 45 ++-- .../Models/OpenApiReference.cs | 32 +-- .../Models/OpenApiRequestBody.cs | 74 ++++--- .../Models/OpenApiResponse.cs | 31 +-- src/Microsoft.OpenApi/Models/OpenApiSchema.cs | 70 +++--- .../Models/OpenApiSecurityRequirement.cs | 9 +- .../Models/OpenApiSecurityScheme.cs | 22 +- src/Microsoft.OpenApi/Models/OpenApiServer.cs | 10 +- .../Models/OpenApiServerVariable.cs | 14 +- src/Microsoft.OpenApi/Models/OpenApiTag.cs | 8 +- src/Microsoft.OpenApi/Models/OpenApiXml.cs | 10 +- .../References/BaseOpenApiReferenceHolder.cs | 26 +-- .../References/OpenApiCallbackReference.cs | 10 +- .../References/OpenApiExampleReference.cs | 20 +- .../References/OpenApiHeaderReference.cs | 18 +- .../Models/References/OpenApiLinkReference.cs | 20 +- .../References/OpenApiParameterReference.cs | 20 +- .../References/OpenApiPathItemReference.cs | 22 +- .../References/OpenApiRequestBodyReference.cs | 33 +-- .../References/OpenApiResponseReference.cs | 16 +- .../References/OpenApiSchemaReference.cs | 80 +++---- .../OpenApiSecuritySchemeReference.cs | 20 +- .../Models/References/OpenApiTagReference.cs | 18 +- .../Models/RuntimeExpressionAnyWrapper.cs | 8 +- .../Reader/JsonNodeHelper.cs | 2 +- .../Reader/OpenApiDiagnostic.cs | 2 +- .../Reader/OpenApiJsonReader.cs | 56 ++--- .../Reader/OpenApiModelFactory.cs | 56 +++-- .../Reader/OpenApiReaderSettings.cs | 35 +-- .../Reader/ParseNodes/AnyFieldMapParameter.cs | 12 +- .../ParseNodes/AnyListFieldMapParameter.cs | 4 +- .../ParseNodes/AnyMapFieldMapParameter.cs | 12 +- .../ParseNodes/JsonPointerExtensions.cs | 4 +- .../Reader/ParseNodes/ListNode.cs | 3 +- .../Reader/ParseNodes/MapNode.cs | 48 ++--- .../Reader/ParseNodes/ParseNode.cs | 8 +- .../Reader/ParseNodes/PropertyNode.cs | 8 +- .../Reader/ParseNodes/RootNode.cs | 4 +- .../Reader/ParseNodes/ValueNode.cs | 7 +- .../Reader/ParsingContext.cs | 28 +-- src/Microsoft.OpenApi/Reader/ReadResult.cs | 6 +- .../OpenApiRemoteReferenceCollector.cs | 9 +- .../Reader/Services/OpenApiWorkspaceLoader.cs | 19 +- .../Reader/V2/OpenApiContactDeserializer.cs | 9 +- .../Reader/V2/OpenApiDocumentDeserializer.cs | 53 +++-- .../V2/OpenApiExternalDocsDeserializer.cs | 18 +- .../Reader/V2/OpenApiHeaderDeserializer.cs | 110 ++++++++-- .../Reader/V2/OpenApiInfoDeserializer.cs | 9 +- .../Reader/V2/OpenApiLicenseDeserializer.cs | 9 +- .../Reader/V2/OpenApiOperationDeserializer.cs | 56 +++-- .../Reader/V2/OpenApiParameterDeserializer.cs | 102 +++++++-- .../Reader/V2/OpenApiPathItemDeserializer.cs | 10 +- .../Reader/V2/OpenApiResponseDeserializer.cs | 10 +- .../Reader/V2/OpenApiSchemaDeserializer.cs | 143 +++++++++++-- .../OpenApiSecurityRequirementDeserializer.cs | 6 +- .../V2/OpenApiSecuritySchemeDeserializer.cs | 37 +++- .../Reader/V2/OpenApiV2Deserializer.cs | 18 +- .../Reader/V2/OpenApiV2VersionService.cs | 8 +- .../Reader/V2/OpenApiXmlDeserializer.cs | 23 +- .../Reader/V3/OpenApiContactDeserializer.cs | 9 +- .../V3/OpenApiDiscriminatorDeserializer.cs | 3 +- .../Reader/V3/OpenApiDocumentDeserializer.cs | 2 +- .../Reader/V3/OpenApiEncodingDeserializer.cs | 18 +- .../V3/OpenApiExternalDocsDeserializer.cs | 11 +- .../Reader/V3/OpenApiHeaderDeserializer.cs | 45 +++- .../Reader/V3/OpenApiInfoDeserializer.cs | 9 +- .../Reader/V3/OpenApiLicenseDeserializer.cs | 9 +- .../Reader/V3/OpenApiMediaTypeDeserializer.cs | 4 +- .../Reader/V3/OpenApiOAuthFlowDeserializer.cs | 30 ++- .../Reader/V3/OpenApiOperationDeserializer.cs | 11 +- .../Reader/V3/OpenApiParameterDeserializer.cs | 45 +++- .../V3/OpenApiRequestBodyDeserializer.cs | 9 +- .../Reader/V3/OpenApiSchemaDeserializer.cs | 148 +++++++++++-- .../OpenApiSecurityRequirementDeserializer.cs | 6 +- .../V3/OpenApiSecuritySchemeDeserializer.cs | 11 +- .../V3/OpenApiServerVariableDeserializer.cs | 3 +- .../Reader/V3/OpenApiV3Deserializer.cs | 75 ++----- .../Reader/V3/OpenApiV3VersionService.cs | 6 +- .../Reader/V3/OpenApiXmlDeserializer.cs | 27 ++- .../Reader/V31/OpenApiContactDeserializer.cs | 9 +- .../V31/OpenApiDiscriminatorDeserializer.cs | 3 +- .../Reader/V31/OpenApiDocumentDeserializer.cs | 2 +- .../Reader/V31/OpenApiEncodingDeserializer.cs | 12 +- .../V31/OpenApiExternalDocsDeserializer.cs | 9 +- .../Reader/V31/OpenApiHeaderDeserializer.cs | 45 +++- .../Reader/V31/OpenApiInfoDeserializer.cs | 9 +- .../Reader/V31/OpenApiLicenseDeserializer.cs | 11 +- .../V31/OpenApiOAuthFlowDeserializer.cs | 30 ++- .../V31/OpenApiOperationDeserializer.cs | 11 +- .../V31/OpenApiParameterDeserializer.cs | 42 +++- .../V31/OpenApiRequestBodyDeserializer.cs | 6 +- .../Reader/V31/OpenApiSchemaDeserializer.cs | 184 +++++++++++++--- .../OpenApiSecurityRequirementDeserializer.cs | 9 +- .../V31/OpenApiSecuritySchemeDeserializer.cs | 8 +- .../V31/OpenApiServerVariableDeserializer.cs | 3 +- .../Reader/V31/OpenApiV31Deserializer.cs | 38 ++-- .../Reader/V31/OpenApiV31VersionService.cs | 10 +- .../Reader/V31/OpenApiXmlDeserializer.cs | 35 ++- .../Services/CopyReferences.cs | 112 ++++++---- .../Services/LoopDetector.cs | 7 +- .../Services/OpenApiFilterService.cs | 201 ++++++++++-------- .../Services/OpenApiReferenceError.cs | 2 +- .../Services/OpenApiUrlTreeNode.cs | 10 +- .../Services/OpenApiVisitorBase.cs | 4 +- .../Services/OpenApiWalker.cs | 74 +++---- .../Services/OpenApiWorkspace.cs | 153 ++++++++----- .../Services/OperationSearch.cs | 25 ++- .../Services/SearchResult.cs | 6 +- src/Microsoft.OpenApi/Utils.cs | 6 +- .../Validations/IValidationContext.cs | 2 +- .../Validations/OpenApiValidator.cs | 19 +- .../Rules/OpenApiComponentsRules.cs | 2 +- .../Rules/OpenApiExtensionRules.cs | 13 +- .../Rules/OpenApiNonDefaultRules.cs | 6 +- .../Validations/Rules/OpenApiSchemaRules.cs | 60 +++--- .../Validations/Rules/OpenApiServerRules.cs | 13 +- .../Validations/Rules/RuleHelpers.cs | 8 +- .../Validations/ValidationRuleSet.cs | 12 +- .../Writers/IOpenApiWriter.cs | 4 +- .../Writers/OpenApiJsonWriter.cs | 25 ++- .../Writers/OpenApiWriterAnyExtensions.cs | 29 +-- .../Writers/OpenApiWriterBase.cs | 12 +- .../Writers/OpenApiWriterExtensions.cs | 26 +-- .../Writers/OpenApiYamlWriter.cs | 72 ++++--- .../OpenApiCallbackReferenceTests.cs | 4 +- 193 files changed, 2663 insertions(+), 1532 deletions(-) diff --git a/src/Microsoft.OpenApi.Hidi/Extensions/OpenApiExtensibleExtensions.cs b/src/Microsoft.OpenApi.Hidi/Extensions/OpenApiExtensibleExtensions.cs index ee57125dd..d7a891501 100644 --- a/src/Microsoft.OpenApi.Hidi/Extensions/OpenApiExtensibleExtensions.cs +++ b/src/Microsoft.OpenApi.Hidi/Extensions/OpenApiExtensibleExtensions.cs @@ -14,7 +14,7 @@ internal static class OpenApiExtensibleExtensions /// A value matching the provided extensionKey. Return null when extensionKey is not found. internal static string GetExtension(this IDictionary extensions, string extensionKey) { - if (extensions.TryGetValue(extensionKey, out var value) && value is OpenApiAny castValue) + if (extensions.TryGetValue(extensionKey, out var value) && value is OpenApiAny castValue && castValue.Node is not null) { return castValue.Node.GetValue(); } diff --git a/src/Microsoft.OpenApi.Hidi/Formatters/PowerShellFormatter.cs b/src/Microsoft.OpenApi.Hidi/Formatters/PowerShellFormatter.cs index df632b78a..959a4345e 100644 --- a/src/Microsoft.OpenApi.Hidi/Formatters/PowerShellFormatter.cs +++ b/src/Microsoft.OpenApi.Hidi/Formatters/PowerShellFormatter.cs @@ -53,7 +53,7 @@ public override void Visit(IOpenApiSchema schema) public override void Visit(IOpenApiPathItem pathItem) { - if (pathItem.Operations.TryGetValue(OperationType.Put, out var value) && + if (pathItem.Operations is not null && pathItem.Operations.TryGetValue(OperationType.Put, out var value) && value.OperationId != null) { var operationId = value.OperationId; @@ -149,7 +149,7 @@ private static string RemoveKeyTypeSegment(string operationId, IList parameter private void AddAdditionalPropertiesToSchema(IOpenApiSchema schema) { - if (schema is OpenApiSchema openApiSchema && !_schemaLoop.Contains(schema) && schema.Type.Equals(JsonSchemaType.Object)) + if (schema is OpenApiSchema openApiSchema + && !_schemaLoop.Contains(schema) + && schema.Type.Equals(JsonSchemaType.Object) + && schema.AdditionalProperties is not null) { openApiSchema.AdditionalProperties = new OpenApiSchema() { Type = JsonSchemaType.Object }; diff --git a/src/Microsoft.OpenApi.Hidi/OpenApiService.cs b/src/Microsoft.OpenApi.Hidi/OpenApiService.cs index c757f4031..f61cb637d 100644 --- a/src/Microsoft.OpenApi.Hidi/OpenApiService.cs +++ b/src/Microsoft.OpenApi.Hidi/OpenApiService.cs @@ -155,7 +155,7 @@ public static async Task TransformOpenApiDocumentAsync(HidiOptions options, ILog return apiDependency; } - private static OpenApiDocument ApplyFilters(HidiOptions options, ILogger logger, ApiDependency? apiDependency, JsonDocument? postmanCollection, OpenApiDocument document) + private static OpenApiDocument? ApplyFilters(HidiOptions options, ILogger logger, ApiDependency? apiDependency, JsonDocument? postmanCollection, OpenApiDocument? document) { Dictionary> requestUrls; if (apiDependency != null) @@ -191,7 +191,7 @@ private static OpenApiDocument ApplyFilters(HidiOptions options, ILogger logger, return document; } - private static async Task WriteOpenApiAsync(HidiOptions options, OpenApiFormat openApiFormat, OpenApiSpecVersion openApiVersion, OpenApiDocument document, ILogger logger, CancellationToken cancellationToken) + private static async Task WriteOpenApiAsync(HidiOptions options, OpenApiFormat openApiFormat, OpenApiSpecVersion openApiVersion, OpenApiDocument? document, ILogger logger, CancellationToken cancellationToken) { using (logger.BeginScope("Output")) { @@ -225,9 +225,9 @@ private static async Task WriteOpenApiAsync(HidiOptions options, OpenApiFormat o } // Get OpenAPI document either from OpenAPI or CSDL - private static async Task GetOpenApiAsync(HidiOptions options, string format, ILogger logger, string? metadataVersion = null, CancellationToken cancellationToken = default) + private static async Task GetOpenApiAsync(HidiOptions options, string format, ILogger logger, string? metadataVersion = null, CancellationToken cancellationToken = default) { - OpenApiDocument document; + OpenApiDocument? document; Stream stream; if (!string.IsNullOrEmpty(options.Csdl)) @@ -248,7 +248,7 @@ private static async Task GetOpenApiAsync(HidiOptions options, document = await ConvertCsdlToOpenApiAsync(filteredStream ?? stream, format, metadataVersion, options.SettingsConfig, cancellationToken).ConfigureAwait(false); stopwatch.Stop(); - logger.LogTrace("{Timestamp}ms: Generated OpenAPI with {Paths} paths.", stopwatch.ElapsedMilliseconds, document.Paths.Count); + logger.LogTrace("{Timestamp}ms: Generated OpenAPI with {Paths} paths.", stopwatch.ElapsedMilliseconds, document?.Paths.Count); } } else if (!string.IsNullOrEmpty(options.OpenApi)) @@ -262,7 +262,7 @@ private static async Task GetOpenApiAsync(HidiOptions options, return document; } - private static Func? FilterOpenApiDocument(string? filterByOperationIds, string? filterByTags, Dictionary> requestUrls, OpenApiDocument document, ILogger logger) + private static Func? FilterOpenApiDocument(string? filterByOperationIds, string? filterByTags, Dictionary> requestUrls, OpenApiDocument? document, ILogger logger) { Func? predicate = null; @@ -376,7 +376,7 @@ private static MemoryStream ApplyFilterToCsdl(Stream csdlStream, string entitySe if (result is null) return null; - return result.Diagnostic.Errors.Count == 0; + return result.Diagnostic?.Errors.Count == 0; } private static async Task ParseOpenApiAsync(string openApiFile, bool inlineExternal, ILogger logger, Stream stream, CancellationToken cancellationToken = default) @@ -411,7 +411,7 @@ private static async Task ParseOpenApiAsync(string openApiFile, bool /// /// The CSDL stream. /// An OpenAPI document. - public static async Task ConvertCsdlToOpenApiAsync(Stream csdl, string format, string? metadataVersion = null, IConfiguration? settings = null, CancellationToken token = default) + public static async Task ConvertCsdlToOpenApiAsync(Stream csdl, string format, string? metadataVersion = null, IConfiguration? settings = null, CancellationToken token = default) { using var reader = new StreamReader(csdl); var csdlText = await reader.ReadToEndAsync(token).ConfigureAwait(false); @@ -429,7 +429,7 @@ public static async Task ConvertCsdlToOpenApiAsync(Stream csdl, /// /// The converted OpenApiDocument. /// A valid OpenApiDocument instance. - public static OpenApiDocument FixReferences(OpenApiDocument document, string format) + public static OpenApiDocument? FixReferences(OpenApiDocument document, string format) { // This method is only needed because the output of ConvertToOpenApi isn't quite a valid OpenApiDocument instance. // So we write it out, and read it back in again to fix it up. @@ -648,7 +648,7 @@ private static string GetInputPathExtension(string? openapi = null, string? csdl private static void LogErrors(ILogger logger, ReadResult result) { var context = result.Diagnostic; - if (context.Errors.Count != 0) + if (context is not null && context.Errors.Count != 0) { using (logger.BeginScope("Detected errors")) { @@ -660,11 +660,11 @@ private static void LogErrors(ILogger logger, ReadResult result) } } - internal static void WriteTreeDocumentAsMarkdown(string openapiUrl, OpenApiDocument document, StreamWriter writer) + internal static void WriteTreeDocumentAsMarkdown(string openapiUrl, OpenApiDocument? document, StreamWriter writer) { var rootNode = OpenApiUrlTreeNode.Create(document, "main"); - writer.WriteLine("# " + document.Info.Title); + writer.WriteLine("# " + document?.Info.Title); writer.WriteLine(); writer.WriteLine("API Description: " + openapiUrl); @@ -681,7 +681,7 @@ internal static void WriteTreeDocumentAsMarkdown(string openapiUrl, OpenApiDocum writer.WriteLine("```"); } - internal static void WriteTreeDocumentAsHtml(string sourceUrl, OpenApiDocument document, StreamWriter writer, bool asHtmlFile = false) + internal static void WriteTreeDocumentAsHtml(string sourceUrl, OpenApiDocument? document, StreamWriter writer, bool asHtmlFile = false) { var rootNode = OpenApiUrlTreeNode.Create(document, "main"); @@ -700,7 +700,7 @@ internal static void WriteTreeDocumentAsHtml(string sourceUrl, OpenApiDocument d """); - writer.WriteLine("

" + document.Info.Title + "

"); + writer.WriteLine("

" + document?.Info.Title + "

"); writer.WriteLine(); writer.WriteLine($"

API Description: {sourceUrl}

"); @@ -771,9 +771,13 @@ internal static async Task PluginManifestAsync(HidiOptions options, ILogger logg await WriteOpenApiAsync(options, OpenApiFormat.Json, OpenApiSpecVersion.OpenApi3_1, document, logger, cancellationToken).ConfigureAwait(false); // Create OpenAIPluginManifest from ApiDependency and OpenAPI document - var manifest = new OpenAIPluginManifest(document.Info?.Title ?? "Title", document.Info?.Title ?? "Title", "https://go.microsoft.com/fwlink/?LinkID=288890", document.Info?.Contact?.Email ?? "placeholder@contoso.com", document.Info?.License?.Url.ToString() ?? "https://placeholderlicenseurl.com") + var manifest = new OpenAIPluginManifest(document?.Info.Title ?? "Title", + document?.Info.Title ?? "Title", + "https://go.microsoft.com/fwlink/?LinkID=288890", + document?.Info?.Contact?.Email ?? "placeholder@contoso.com", + document?.Info?.License?.Url?.ToString() ?? "https://placeholderlicenseurl.com") { - DescriptionForHuman = document.Info?.Description ?? "Description placeholder", + DescriptionForHuman = document?.Info.Description ?? "Description placeholder", Api = new("openapi", "./openapi.json"), Auth = new ManifestNoAuth(), }; diff --git a/src/Microsoft.OpenApi.Readers/Microsoft.OpenApi.Readers.csproj b/src/Microsoft.OpenApi.Readers/Microsoft.OpenApi.Readers.csproj index 13c50aefd..23ff12866 100644 --- a/src/Microsoft.OpenApi.Readers/Microsoft.OpenApi.Readers.csproj +++ b/src/Microsoft.OpenApi.Readers/Microsoft.OpenApi.Readers.csproj @@ -11,6 +11,7 @@ true NU5048 + enable README.md diff --git a/src/Microsoft.OpenApi.Readers/OpenApiYamlReader.cs b/src/Microsoft.OpenApi.Readers/OpenApiYamlReader.cs index eba4fd248..4452acb85 100644 --- a/src/Microsoft.OpenApi.Readers/OpenApiYamlReader.cs +++ b/src/Microsoft.OpenApi.Readers/OpenApiYamlReader.cs @@ -84,11 +84,11 @@ public static ReadResult Read(JsonNode jsonNode, OpenApiReaderSettings settings) } /// - public T ReadFragment(MemoryStream input, + public T? ReadFragment(MemoryStream input, OpenApiSpecVersion version, OpenApiDocument openApiDocument, out OpenApiDiagnostic diagnostic, - OpenApiReaderSettings settings = null) where T : IOpenApiElement + OpenApiReaderSettings? settings = null) where T : IOpenApiElement { if (input is null) throw new ArgumentNullException(nameof(input)); JsonNode jsonNode; @@ -110,7 +110,7 @@ public T ReadFragment(MemoryStream input, } /// - public static T ReadFragment(JsonNode input, OpenApiSpecVersion version, OpenApiDocument openApiDocument, out OpenApiDiagnostic diagnostic, OpenApiReaderSettings settings = null) where T : IOpenApiElement + public static T ReadFragment(JsonNode input, OpenApiSpecVersion version, OpenApiDocument openApiDocument, out OpenApiDiagnostic diagnostic, OpenApiReaderSettings? settings = null) where T : IOpenApiElement { return _jsonReader.ReadFragment(input, version, openApiDocument, out diagnostic, settings); } diff --git a/src/Microsoft.OpenApi/Any/OpenApiAny.cs b/src/Microsoft.OpenApi/Any/OpenApiAny.cs index 54bddf326..ca9f1b100 100644 --- a/src/Microsoft.OpenApi/Any/OpenApiAny.cs +++ b/src/Microsoft.OpenApi/Any/OpenApiAny.cs @@ -12,13 +12,13 @@ namespace Microsoft.OpenApi.Any /// public class OpenApiAny : IOpenApiElement, IOpenApiExtension { - private readonly JsonNode jsonNode; + private readonly JsonNode? jsonNode; /// /// Initializes the class. /// /// - public OpenApiAny(JsonNode jsonNode) + public OpenApiAny(JsonNode? jsonNode) { this.jsonNode = jsonNode; } @@ -26,7 +26,7 @@ public OpenApiAny(JsonNode jsonNode) /// /// Gets the underlying JsonNode. /// - public JsonNode Node { get { return jsonNode; } } + public JsonNode? Node { get { return jsonNode; } } /// /// Writes out the OpenApiAny type. diff --git a/src/Microsoft.OpenApi/Attributes/DisplayAttribute.cs b/src/Microsoft.OpenApi/Attributes/DisplayAttribute.cs index 30670456d..8973ac1f3 100644 --- a/src/Microsoft.OpenApi/Attributes/DisplayAttribute.cs +++ b/src/Microsoft.OpenApi/Attributes/DisplayAttribute.cs @@ -15,7 +15,7 @@ public class DisplayAttribute : Attribute /// Initializes a new instance of the class. /// /// The display name. - public DisplayAttribute(string name) + public DisplayAttribute(string? name) { Name = Utils.CheckArgumentNullOrEmpty(name); } @@ -23,6 +23,6 @@ public DisplayAttribute(string name) /// /// The display Name. /// - public string Name { get; } + public string? Name { get; } } } diff --git a/src/Microsoft.OpenApi/Exceptions/OpenApiException.cs b/src/Microsoft.OpenApi/Exceptions/OpenApiException.cs index 9c1f4233f..cb7eaecf0 100644 --- a/src/Microsoft.OpenApi/Exceptions/OpenApiException.cs +++ b/src/Microsoft.OpenApi/Exceptions/OpenApiException.cs @@ -33,7 +33,7 @@ public OpenApiException(string message) /// /// The plain text error message for this exception. /// The inner exception that is the cause of this exception to be thrown. - public OpenApiException(string message, Exception innerException) + public OpenApiException(string message, Exception? innerException) : base(message, innerException) { } @@ -46,6 +46,6 @@ public OpenApiException(string message, Exception innerException) /// a text/plain pointer as defined in https://tools.ietf.org/html/rfc5147 /// Currently only line= is provided because using char= causes tests to break due to CR/LF and LF differences /// - public string Pointer { get; set; } + public string? Pointer { get; set; } } } diff --git a/src/Microsoft.OpenApi/Exceptions/OpenApiReaderException.cs b/src/Microsoft.OpenApi/Exceptions/OpenApiReaderException.cs index 257b0e9a4..dbf16820a 100644 --- a/src/Microsoft.OpenApi/Exceptions/OpenApiReaderException.cs +++ b/src/Microsoft.OpenApi/Exceptions/OpenApiReaderException.cs @@ -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; @@ -39,7 +39,7 @@ public OpenApiReaderException(string message, ParsingContext context) : base(mes /// /// Plain text error message for this exception. /// Parsing node where error occured - public OpenApiReaderException(string message, JsonNode node) : base(message) + public OpenApiReaderException(string message, JsonNode? node) : base(message) { // This only includes line because using a char range causes tests to break due to CR/LF & LF differences // See https://tools.ietf.org/html/rfc5147 for syntax diff --git a/src/Microsoft.OpenApi/Exceptions/OpenApiUnsupportedSpecVersionException.cs b/src/Microsoft.OpenApi/Exceptions/OpenApiUnsupportedSpecVersionException.cs index f9be8bd63..8df7ad0d8 100644 --- a/src/Microsoft.OpenApi/Exceptions/OpenApiUnsupportedSpecVersionException.cs +++ b/src/Microsoft.OpenApi/Exceptions/OpenApiUnsupportedSpecVersionException.cs @@ -18,7 +18,7 @@ public class OpenApiUnsupportedSpecVersionException : Exception /// Initializes the class with a specification version. /// /// Version that caused this exception to be thrown. - public OpenApiUnsupportedSpecVersionException(string specificationVersion) + public OpenApiUnsupportedSpecVersionException(string? specificationVersion) : base(string.Format(CultureInfo.InvariantCulture, messagePattern, specificationVersion)) { this.SpecificationVersion = specificationVersion; @@ -39,6 +39,6 @@ public OpenApiUnsupportedSpecVersionException(string specificationVersion, Excep /// /// The unsupported specification version. /// - public string SpecificationVersion { get; } + public string? SpecificationVersion { get; } } } diff --git a/src/Microsoft.OpenApi/Exceptions/OpenApiWriterException.cs b/src/Microsoft.OpenApi/Exceptions/OpenApiWriterException.cs index 9e0540c53..af19269f8 100644 --- a/src/Microsoft.OpenApi/Exceptions/OpenApiWriterException.cs +++ b/src/Microsoft.OpenApi/Exceptions/OpenApiWriterException.cs @@ -33,7 +33,7 @@ public OpenApiWriterException(string message) /// /// The plain text error message for this exception. /// The inner exception that is the cause of this exception to be thrown. - public OpenApiWriterException(string message, Exception innerException) + public OpenApiWriterException(string message, Exception? innerException) : base(message, innerException) { } diff --git a/src/Microsoft.OpenApi/Expressions/BodyExpression.cs b/src/Microsoft.OpenApi/Expressions/BodyExpression.cs index c63b1bc58..a6743e715 100644 --- a/src/Microsoft.OpenApi/Expressions/BodyExpression.cs +++ b/src/Microsoft.OpenApi/Expressions/BodyExpression.cs @@ -30,7 +30,7 @@ public BodyExpression() /// Initializes a new instance of the class. /// /// a JSON Pointer [RFC 6901](https://tools.ietf.org/html/rfc6901). - public BodyExpression(JsonPointer pointer) + public BodyExpression(JsonPointer? pointer) : base(pointer?.ToString()) { Utils.CheckArgumentNull(pointer); @@ -55,6 +55,6 @@ public override string Expression /// /// Gets the fragment string. /// - public string Fragment { get => Value; } + public string? Fragment { get => Value; } } } diff --git a/src/Microsoft.OpenApi/Expressions/HeaderExpression.cs b/src/Microsoft.OpenApi/Expressions/HeaderExpression.cs index 99bbf2a96..f373960d5 100644 --- a/src/Microsoft.OpenApi/Expressions/HeaderExpression.cs +++ b/src/Microsoft.OpenApi/Expressions/HeaderExpression.cs @@ -31,6 +31,6 @@ public HeaderExpression(string token) /// /// Gets the token string. /// - public string Token { get => Value; } + public string? Token { get => Value; } } } diff --git a/src/Microsoft.OpenApi/Expressions/PathExpression.cs b/src/Microsoft.OpenApi/Expressions/PathExpression.cs index 1d43b9b21..9922b6b1f 100644 --- a/src/Microsoft.OpenApi/Expressions/PathExpression.cs +++ b/src/Microsoft.OpenApi/Expressions/PathExpression.cs @@ -31,6 +31,6 @@ public PathExpression(string name) /// /// Gets the name string. /// - public string Name { get => Value; } + public string? Name { get => Value; } } } diff --git a/src/Microsoft.OpenApi/Expressions/QueryExpression.cs b/src/Microsoft.OpenApi/Expressions/QueryExpression.cs index 55016d82a..d33f3bff6 100644 --- a/src/Microsoft.OpenApi/Expressions/QueryExpression.cs +++ b/src/Microsoft.OpenApi/Expressions/QueryExpression.cs @@ -31,6 +31,6 @@ public QueryExpression(string name) /// /// Gets the name string. /// - public string Name { get => Value; } + public string? Name { get => Value; } } } diff --git a/src/Microsoft.OpenApi/Expressions/RuntimeExpression.cs b/src/Microsoft.OpenApi/Expressions/RuntimeExpression.cs index 69aecfd37..b6104e1b3 100644 --- a/src/Microsoft.OpenApi/Expressions/RuntimeExpression.cs +++ b/src/Microsoft.OpenApi/Expressions/RuntimeExpression.cs @@ -84,7 +84,7 @@ public override int GetHashCode() /// /// Equals implementation for IEquatable. /// - public override bool Equals(object obj) + public override bool Equals(object? obj) { return Equals(obj as RuntimeExpression); } @@ -92,7 +92,7 @@ public override bool Equals(object obj) /// /// Equals implementation for object of the same type. /// - public bool Equals(RuntimeExpression obj) + public bool Equals(RuntimeExpression? obj) { return obj != null && obj.Expression == Expression; } diff --git a/src/Microsoft.OpenApi/Expressions/SourceExpression.cs b/src/Microsoft.OpenApi/Expressions/SourceExpression.cs index 76a22f97d..36eec56f7 100644 --- a/src/Microsoft.OpenApi/Expressions/SourceExpression.cs +++ b/src/Microsoft.OpenApi/Expressions/SourceExpression.cs @@ -16,7 +16,7 @@ public abstract class SourceExpression : RuntimeExpression /// Initializes a new instance of the class. /// /// The value string. - protected SourceExpression(string value) + protected SourceExpression(string? value) { Value = value; } @@ -24,7 +24,7 @@ protected SourceExpression(string value) /// /// Gets the expression string. /// - protected string Value { get; } + protected string? Value { get; } /// /// Build the source expression from input string. diff --git a/src/Microsoft.OpenApi/Extensions/EnumExtensions.cs b/src/Microsoft.OpenApi/Extensions/EnumExtensions.cs index bc4e86783..a3ddb0bcd 100644 --- a/src/Microsoft.OpenApi/Extensions/EnumExtensions.cs +++ b/src/Microsoft.OpenApi/Extensions/EnumExtensions.cs @@ -27,7 +27,7 @@ public static class EnumExtensions /// The attribute of the specified type or null. /// [UnconditionalSuppressMessage("Trimming", "IL2075", Justification = "Fields are never trimmed for enum types.")] - public static T GetAttributeOfType(this Enum enumValue) where T : Attribute + public static T? GetAttributeOfType(this Enum enumValue) where T : Attribute { var type = enumValue.GetType(); // Use GetField to get the field info for the enum value @@ -58,7 +58,14 @@ public static string GetDisplayName(this Enum enumValue) var attribute = e.GetAttributeOfType(); // Return the DisplayAttribute name if it exists, otherwise return the enum's string representation - return attribute == null ? e.ToString() : attribute.Name; + if (attribute?.Name is not null) + { + return attribute.Name; + } + else + { + return e.ToString(); + } }); } } diff --git a/src/Microsoft.OpenApi/Extensions/OpenApiExtensibleExtensions.cs b/src/Microsoft.OpenApi/Extensions/OpenApiExtensibleExtensions.cs index c8c3b2a48..01fc02020 100644 --- a/src/Microsoft.OpenApi/Extensions/OpenApiExtensibleExtensions.cs +++ b/src/Microsoft.OpenApi/Extensions/OpenApiExtensibleExtensions.cs @@ -32,7 +32,10 @@ public static void AddExtension(this T element, string name, IOpenApiExtensio throw new OpenApiException(string.Format(SRResource.ExtensionFieldNameMustBeginWithXDash, name)); } - element.Extensions[name] = Utils.CheckArgumentNull(any); + if (element.Extensions is not null) + { + element.Extensions[name] = Utils.CheckArgumentNull(any); + } } } } diff --git a/src/Microsoft.OpenApi/Extensions/OpenApiReferencableExtensions.cs b/src/Microsoft.OpenApi/Extensions/OpenApiReferencableExtensions.cs index da51f3b55..eb94bbfa0 100644 --- a/src/Microsoft.OpenApi/Extensions/OpenApiReferencableExtensions.cs +++ b/src/Microsoft.OpenApi/Extensions/OpenApiReferencableExtensions.cs @@ -54,12 +54,12 @@ public static IOpenApiReferenceable ResolveReference(this IOpenApiReferenceable private static IOpenApiReferenceable ResolveReferenceOnHeaderElement( OpenApiHeader headerElement, - string propertyName, - string mapKey, + string? propertyName, + string? mapKey, JsonPointer pointer) { if (OpenApiConstants.Examples.Equals(propertyName, StringComparison.Ordinal) && - !string.IsNullOrEmpty(mapKey) && + mapKey is not null && headerElement?.Examples != null && headerElement.Examples.TryGetValue(mapKey, out var exampleElement) && exampleElement is IOpenApiReferenceable referenceable) @@ -71,12 +71,12 @@ private static IOpenApiReferenceable ResolveReferenceOnHeaderElement( private static IOpenApiReferenceable ResolveReferenceOnParameterElement( OpenApiParameter parameterElement, - string propertyName, - string mapKey, + string? propertyName, + string? mapKey, JsonPointer pointer) { if (OpenApiConstants.Examples.Equals(propertyName, StringComparison.Ordinal) && - !string.IsNullOrEmpty(mapKey) && + mapKey is not null && parameterElement?.Examples != null && parameterElement.Examples.TryGetValue(mapKey, out var exampleElement) && exampleElement is IOpenApiReferenceable referenceable) @@ -88,11 +88,11 @@ private static IOpenApiReferenceable ResolveReferenceOnParameterElement( private static IOpenApiReferenceable ResolveReferenceOnResponseElement( OpenApiResponse responseElement, - string propertyName, - string mapKey, + string? propertyName, + string? mapKey, JsonPointer pointer) { - if (!string.IsNullOrEmpty(mapKey)) + if (mapKey is not null) { if (OpenApiConstants.Headers.Equals(propertyName, StringComparison.Ordinal) && responseElement?.Headers != null && diff --git a/src/Microsoft.OpenApi/Extensions/OpenApiSerializableExtensions.cs b/src/Microsoft.OpenApi/Extensions/OpenApiSerializableExtensions.cs index 9d284db1a..1180d2e48 100755 --- a/src/Microsoft.OpenApi/Extensions/OpenApiSerializableExtensions.cs +++ b/src/Microsoft.OpenApi/Extensions/OpenApiSerializableExtensions.cs @@ -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.Globalization; @@ -82,7 +82,7 @@ public static Task SerializeAsync( Stream stream, OpenApiSpecVersion specVersion, OpenApiFormat format, - OpenApiWriterSettings settings, + OpenApiWriterSettings? settings, CancellationToken cancellationToken = default) where T : IOpenApiSerializable { @@ -107,7 +107,7 @@ public static Task SerializeAsync( /// The output writer. /// Version of the specification the output should conform to /// The cancellation token. - public static Task SerializeAsync(this T element, IOpenApiWriter writer, OpenApiSpecVersion specVersion, CancellationToken cancellationToken = default) + public static Task SerializeAsync(this T? element, IOpenApiWriter writer, OpenApiSpecVersion specVersion, CancellationToken cancellationToken = default) where T : IOpenApiSerializable { Utils.CheckArgumentNull(element); @@ -116,15 +116,15 @@ public static Task SerializeAsync(this T element, IOpenApiWriter writer, Open switch (specVersion) { case OpenApiSpecVersion.OpenApi3_1: - element.SerializeAsV31(writer); + element?.SerializeAsV31(writer); break; case OpenApiSpecVersion.OpenApi3_0: - element.SerializeAsV3(writer); + element?.SerializeAsV3(writer); break; case OpenApiSpecVersion.OpenApi2_0: - element.SerializeAsV2(writer); + element?.SerializeAsV2(writer); break; default: diff --git a/src/Microsoft.OpenApi/Extensions/OpenApiServerExtensions.cs b/src/Microsoft.OpenApi/Extensions/OpenApiServerExtensions.cs index b885cb235..5276876ce 100644 --- a/src/Microsoft.OpenApi/Extensions/OpenApiServerExtensions.cs +++ b/src/Microsoft.OpenApi/Extensions/OpenApiServerExtensions.cs @@ -21,37 +21,39 @@ public static class OpenApiServerExtensions /// 1. A substitution has no valid value in both the supplied dictionary and the default /// 2. A substitution's value is not available in the enum provided /// - public static string ReplaceServerUrlVariables(this OpenApiServer server, IDictionary values = null) + public static string? ReplaceServerUrlVariables(this OpenApiServer server, IDictionary? values = null) { var parsedUrl = server.Url; - foreach (var variable in server.Variables) + if (server.Variables is not null && parsedUrl is not null) { - // Try to get the value from the provided values - if (values is not { } v || !v.TryGetValue(variable.Key, out var value) || string.IsNullOrEmpty(value)) + foreach (var variable in server.Variables) { - // Fall back to the default value - value = variable.Value.Default; - } + // Try to get the value from the provided values + if (values is not { } v || !v.TryGetValue(variable.Key, out var value) || string.IsNullOrEmpty(value)) + { + // Fall back to the default value + value = variable.Value.Default; + } - // Validate value - if (string.IsNullOrEmpty(value)) - { - // According to the spec, the variable's default value is required. - // This code path should be hit when a value isn't provided & a default value isn't available - throw new ArgumentException( - string.Format(SRResource.ParseServerUrlDefaultValueNotAvailable, variable.Key), nameof(server)); - } + // Validate value + if (string.IsNullOrEmpty(value)) + { + // According to the spec, the variable's default value is required. + // This code path should be hit when a value isn't provided & a default value isn't available + throw new ArgumentException( + string.Format(SRResource.ParseServerUrlDefaultValueNotAvailable, variable.Key), nameof(server)); + } - // If an enum is provided, the array should not be empty & the value should exist in the enum - if (variable.Value.Enum is {} e && (e.Count == 0 || !e.Contains(value))) - { - throw new ArgumentException( - string.Format(SRResource.ParseServerUrlValueNotValid, value, variable.Key), nameof(values)); - } - - parsedUrl = parsedUrl.Replace($"{{{variable.Key}}}", value); - } + // If an enum is provided, the array should not be empty & the value should exist in the enum + if (value is not null && variable.Value.Enum is { } e && (e.Count == 0 || !e.Contains(value))) + { + throw new ArgumentException( + string.Format(SRResource.ParseServerUrlValueNotValid, value, variable.Key), nameof(values)); + } + parsedUrl = parsedUrl?.Replace($"{{{variable.Key}}}", value); + } + } return parsedUrl; } } diff --git a/src/Microsoft.OpenApi/Extensions/StringExtensions.cs b/src/Microsoft.OpenApi/Extensions/StringExtensions.cs index b644050ab..b7d21c011 100644 --- a/src/Microsoft.OpenApi/Extensions/StringExtensions.cs +++ b/src/Microsoft.OpenApi/Extensions/StringExtensions.cs @@ -19,7 +19,7 @@ internal static class StringExtensions { private static readonly ConcurrentDictionary> EnumDisplayCache = new(); - internal static bool TryGetEnumFromDisplayName<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicFields)] T>(this string displayName, ParsingContext parsingContext, out T result) where T : Enum + internal static bool TryGetEnumFromDisplayName<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicFields)] T>(this string? displayName, ParsingContext parsingContext, out T result) where T : Enum { if (TryGetEnumFromDisplayName(displayName, out result)) { @@ -30,19 +30,19 @@ internal static class StringExtensions return false; } - internal static bool TryGetEnumFromDisplayName<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicFields)] T>(this string displayName, out T result) where T : Enum + internal static bool TryGetEnumFromDisplayName<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicFields)] T>(this string? displayName, out T result) where T : Enum { var type = typeof(T); - var displayMap = EnumDisplayCache.GetOrAdd(type, _=> GetEnumValues(type)); + var displayMap = EnumDisplayCache.GetOrAdd(type, _ => GetEnumValues(type)); - if (displayMap.TryGetValue(displayName, out var cachedValue)) + if (displayName is not null && displayMap.TryGetValue(displayName, out var cachedValue)) { result = (T)cachedValue; return true; } - result = default; + result = default!; return false; } private static ReadOnlyDictionary GetEnumValues([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicFields)] Type enumType) where T : Enum @@ -52,8 +52,11 @@ private static ReadOnlyDictionary GetEnumValues([DynamicallyA { if (field.GetCustomAttribute() is {} displayAttribute) { - var enumValue = (T)field.GetValue(null); - result.Add(displayAttribute.Name, enumValue); + var value = field.GetValue(null); + if (value is T enumValue && displayAttribute.Name is not null) + { + result.Add(displayAttribute.Name, enumValue); + } } } return new ReadOnlyDictionary(result); diff --git a/src/Microsoft.OpenApi/Helpers/JsonNodeCloneHelper.cs b/src/Microsoft.OpenApi/Helpers/JsonNodeCloneHelper.cs index caab84e7b..5daed4b39 100644 --- a/src/Microsoft.OpenApi/Helpers/JsonNodeCloneHelper.cs +++ b/src/Microsoft.OpenApi/Helpers/JsonNodeCloneHelper.cs @@ -7,9 +7,9 @@ namespace Microsoft.OpenApi.Helpers { internal static class JsonNodeCloneHelper { - internal static JsonNode Clone(JsonNode value) + internal static JsonNode? Clone(JsonNode? value) { - return value.DeepClone(); + return value?.DeepClone(); } } } diff --git a/src/Microsoft.OpenApi/Interfaces/IOpenApiAnnotatable.cs b/src/Microsoft.OpenApi/Interfaces/IOpenApiAnnotatable.cs index dc1ee84a0..61c334390 100644 --- a/src/Microsoft.OpenApi/Interfaces/IOpenApiAnnotatable.cs +++ b/src/Microsoft.OpenApi/Interfaces/IOpenApiAnnotatable.cs @@ -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.Collections.Generic; @@ -14,6 +14,6 @@ public interface IOpenApiAnnotatable /// /// A collection of properties associated with the current OpenAPI element. /// - IDictionary Annotations { get; set; } + IDictionary? Annotations { get; set; } } } diff --git a/src/Microsoft.OpenApi/Interfaces/IOpenApiExtensible.cs b/src/Microsoft.OpenApi/Interfaces/IOpenApiExtensible.cs index 5531b1809..fabd1a177 100644 --- a/src/Microsoft.OpenApi/Interfaces/IOpenApiExtensible.cs +++ b/src/Microsoft.OpenApi/Interfaces/IOpenApiExtensible.cs @@ -13,6 +13,6 @@ public interface IOpenApiExtensible : IOpenApiElement /// /// Specification extensions. /// - IDictionary Extensions { get; set; } + IDictionary? Extensions { get; set; } } } diff --git a/src/Microsoft.OpenApi/Interfaces/IOpenApiReadOnlyExtensible.cs b/src/Microsoft.OpenApi/Interfaces/IOpenApiReadOnlyExtensible.cs index 367c84a96..db451d843 100644 --- a/src/Microsoft.OpenApi/Interfaces/IOpenApiReadOnlyExtensible.cs +++ b/src/Microsoft.OpenApi/Interfaces/IOpenApiReadOnlyExtensible.cs @@ -1,4 +1,4 @@ -using System.Collections.Generic; +using System.Collections.Generic; namespace Microsoft.OpenApi.Interfaces; @@ -10,6 +10,6 @@ public interface IOpenApiReadOnlyExtensible /// /// Specification extensions. /// - IDictionary Extensions { get; } + IDictionary? Extensions { get; } } diff --git a/src/Microsoft.OpenApi/Interfaces/IOpenApiReader.cs b/src/Microsoft.OpenApi/Interfaces/IOpenApiReader.cs index 3b9c85d2f..687599caa 100644 --- a/src/Microsoft.OpenApi/Interfaces/IOpenApiReader.cs +++ b/src/Microsoft.OpenApi/Interfaces/IOpenApiReader.cs @@ -40,6 +40,6 @@ public interface IOpenApiReader /// Returns diagnostic object containing errors detected during parsing. /// The OpenApiReader settings. /// Instance of newly created IOpenApiElement. - T ReadFragment(MemoryStream input, OpenApiSpecVersion version, OpenApiDocument openApiDocument, out OpenApiDiagnostic diagnostic, OpenApiReaderSettings settings = null) where T : IOpenApiElement; + T? ReadFragment(MemoryStream input, OpenApiSpecVersion version, OpenApiDocument openApiDocument, out OpenApiDiagnostic diagnostic, OpenApiReaderSettings? settings = null) where T : IOpenApiElement; } } diff --git a/src/Microsoft.OpenApi/Interfaces/IOpenApiReferenceHolder.cs b/src/Microsoft.OpenApi/Interfaces/IOpenApiReferenceHolder.cs index 8883a90f5..bd334c582 100644 --- a/src/Microsoft.OpenApi/Interfaces/IOpenApiReferenceHolder.cs +++ b/src/Microsoft.OpenApi/Interfaces/IOpenApiReferenceHolder.cs @@ -15,11 +15,11 @@ public interface IOpenApiReferenceHolder : IOpenApiReferenceHolder whe /// /// Gets the resolved target object. /// - T Target { get; } + T? Target { get; } /// /// Copy the reference as a target element with overrides. /// - V CopyReferenceAsTargetElementWithOverrides(V source); + V? CopyReferenceAsTargetElementWithOverrides(V? source); } /// /// A generic interface for OpenApiReferenceable objects that have a target. @@ -34,6 +34,6 @@ public interface IOpenApiReferenceHolder : IOpenApiSerializable /// /// Reference object. /// - OpenApiReference Reference { get; init; } + OpenApiReference? Reference { get; init; } } } diff --git a/src/Microsoft.OpenApi/Interfaces/IOpenApiVersionService.cs b/src/Microsoft.OpenApi/Interfaces/IOpenApiVersionService.cs index 073962a35..8b7af38d8 100644 --- a/src/Microsoft.OpenApi/Interfaces/IOpenApiVersionService.cs +++ b/src/Microsoft.OpenApi/Interfaces/IOpenApiVersionService.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. +// Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. using Microsoft.OpenApi.Models; @@ -19,7 +19,7 @@ internal interface IOpenApiVersionService /// The summary of the reference. /// A reference description /// The object or null. - OpenApiReference ConvertToOpenApiReference(string reference, ReferenceType? type, string summary = null, string description = null); + OpenApiReference? ConvertToOpenApiReference(string reference, ReferenceType? type, string? summary = null, string? description = null); /// /// Loads an OpenAPI Element from a document fragment @@ -43,6 +43,6 @@ internal interface IOpenApiVersionService /// A YamlMappingNode. /// The scalar value we're parsing. /// The resulting node value. - string GetReferenceScalarValues(MapNode mapNode, string scalarValue); + string? GetReferenceScalarValues(MapNode mapNode, string scalarValue); } } diff --git a/src/Microsoft.OpenApi/Interfaces/IShallowCopyable.cs b/src/Microsoft.OpenApi/Interfaces/IShallowCopyable.cs index c1327bf0f..ecffde715 100644 --- a/src/Microsoft.OpenApi/Interfaces/IShallowCopyable.cs +++ b/src/Microsoft.OpenApi/Interfaces/IShallowCopyable.cs @@ -1,4 +1,4 @@ -namespace Microsoft.OpenApi.Interfaces; +namespace Microsoft.OpenApi.Interfaces; /// /// Interface for shallow copyable objects. /// diff --git a/src/Microsoft.OpenApi/JsonPointer.cs b/src/Microsoft.OpenApi/JsonPointer.cs index 110cca81e..627520c3b 100644 --- a/src/Microsoft.OpenApi/JsonPointer.cs +++ b/src/Microsoft.OpenApi/JsonPointer.cs @@ -39,7 +39,7 @@ private JsonPointer(string[] tokens) /// /// Gets the parent pointer. /// - public JsonPointer ParentPointer + public JsonPointer? ParentPointer { get { diff --git a/src/Microsoft.OpenApi/Microsoft.OpenApi.csproj b/src/Microsoft.OpenApi/Microsoft.OpenApi.csproj index 6a402478f..468a895e1 100644 --- a/src/Microsoft.OpenApi/Microsoft.OpenApi.csproj +++ b/src/Microsoft.OpenApi/Microsoft.OpenApi.csproj @@ -10,6 +10,7 @@ true NU5048 + enable README.md diff --git a/src/Microsoft.OpenApi/MicrosoftExtensions/OpenApiDeprecationExtension.cs b/src/Microsoft.OpenApi/MicrosoftExtensions/OpenApiDeprecationExtension.cs index a5bae9fa9..715585485 100644 --- a/src/Microsoft.OpenApi/MicrosoftExtensions/OpenApiDeprecationExtension.cs +++ b/src/Microsoft.OpenApi/MicrosoftExtensions/OpenApiDeprecationExtension.cs @@ -79,7 +79,7 @@ public void Write(IOpenApiWriter writer, OpenApiSpecVersion specVersion) /// When the source element is not an object public static OpenApiDeprecationExtension Parse(JsonNode source) { - if (source is not JsonObject rawObject) return null; + if (source is not JsonObject rawObject) throw new ArgumentOutOfRangeException(nameof(source)); var extension = new OpenApiDeprecationExtension(); if (rawObject.TryGetPropertyValue(nameof(RemovalDate).ToFirstCharacterLowerCase(), out var removalDate) && removalDate is JsonNode removalDateValue) extension.RemovalDate = removalDateValue.GetValue(); diff --git a/src/Microsoft.OpenApi/MicrosoftExtensions/OpenApiEnumValuesDescriptionExtension.cs b/src/Microsoft.OpenApi/MicrosoftExtensions/OpenApiEnumValuesDescriptionExtension.cs index df1e664e1..74cbe2c44 100644 --- a/src/Microsoft.OpenApi/MicrosoftExtensions/OpenApiEnumValuesDescriptionExtension.cs +++ b/src/Microsoft.OpenApi/MicrosoftExtensions/OpenApiEnumValuesDescriptionExtension.cs @@ -65,7 +65,7 @@ public void Write(IOpenApiWriter writer, OpenApiSpecVersion specVersion) /// When the source element is not an object public static OpenApiEnumValuesDescriptionExtension Parse(JsonNode source) { - if (source is not JsonObject rawObject) return null; + if (source is not JsonObject rawObject) throw new ArgumentOutOfRangeException(nameof(source)); var extension = new OpenApiEnumValuesDescriptionExtension(); if (rawObject.TryGetPropertyValue("values", out var values) && values is JsonArray valuesArray) { diff --git a/src/Microsoft.OpenApi/MicrosoftExtensions/OpenApiPagingExtension.cs b/src/Microsoft.OpenApi/MicrosoftExtensions/OpenApiPagingExtension.cs index 57d057e59..0ffe238bd 100644 --- a/src/Microsoft.OpenApi/MicrosoftExtensions/OpenApiPagingExtension.cs +++ b/src/Microsoft.OpenApi/MicrosoftExtensions/OpenApiPagingExtension.cs @@ -73,7 +73,7 @@ public void Write(IOpenApiWriter writer, OpenApiSpecVersion specVersion) /// When the source element is not an object public static OpenApiPagingExtension Parse(JsonNode source) { - if (source is not JsonObject rawObject) return null; + if (source is not JsonObject rawObject) throw new ArgumentOutOfRangeException(nameof(source)); var extension = new OpenApiPagingExtension(); if (rawObject.TryGetPropertyValue(nameof(NextLinkName).ToFirstCharacterLowerCase(), out var nextLinkName) && nextLinkName is JsonNode nextLinkNameStr) { diff --git a/src/Microsoft.OpenApi/MicrosoftExtensions/OpenApiPrimaryErrorMessageExtension.cs b/src/Microsoft.OpenApi/MicrosoftExtensions/OpenApiPrimaryErrorMessageExtension.cs index ad47db39b..84afc0024 100644 --- a/src/Microsoft.OpenApi/MicrosoftExtensions/OpenApiPrimaryErrorMessageExtension.cs +++ b/src/Microsoft.OpenApi/MicrosoftExtensions/OpenApiPrimaryErrorMessageExtension.cs @@ -40,7 +40,7 @@ public void Write(IOpenApiWriter writer, OpenApiSpecVersion specVersion) /// The . public static OpenApiPrimaryErrorMessageExtension Parse(JsonNode source) { - if (source is not JsonNode rawObject) return null; + if (source is not JsonNode rawObject) throw new ArgumentOutOfRangeException(nameof(source)); return new() { IsPrimaryErrorMessage = rawObject.GetValue() diff --git a/src/Microsoft.OpenApi/MicrosoftExtensions/OpenApiReservedParameterExtension.cs b/src/Microsoft.OpenApi/MicrosoftExtensions/OpenApiReservedParameterExtension.cs index 2d3a8c117..a04cd1d82 100644 --- a/src/Microsoft.OpenApi/MicrosoftExtensions/OpenApiReservedParameterExtension.cs +++ b/src/Microsoft.OpenApi/MicrosoftExtensions/OpenApiReservedParameterExtension.cs @@ -42,7 +42,7 @@ public bool? IsReserved /// public static OpenApiReservedParameterExtension Parse(JsonNode source) { - if (source is not JsonNode rawBoolean) return null; + if (source is not JsonNode rawBoolean) throw new ArgumentOutOfRangeException(nameof(source)); return new() { IsReserved = rawBoolean.GetValue() diff --git a/src/Microsoft.OpenApi/Models/Interfaces/IOpenApiCallback.cs b/src/Microsoft.OpenApi/Models/Interfaces/IOpenApiCallback.cs index a8a818d33..d98b7f705 100644 --- a/src/Microsoft.OpenApi/Models/Interfaces/IOpenApiCallback.cs +++ b/src/Microsoft.OpenApi/Models/Interfaces/IOpenApiCallback.cs @@ -1,4 +1,4 @@ - + using System.Collections.Generic; using Microsoft.OpenApi.Expressions; using Microsoft.OpenApi.Interfaces; @@ -14,5 +14,5 @@ public interface IOpenApiCallback : IOpenApiSerializable, IOpenApiReadOnlyExtens /// /// A Path Item Object used to define a callback request and expected responses. /// - public Dictionary PathItems { get; } + public Dictionary? PathItems { get; } } diff --git a/src/Microsoft.OpenApi/Models/Interfaces/IOpenApiDescribedElement.cs b/src/Microsoft.OpenApi/Models/Interfaces/IOpenApiDescribedElement.cs index 3deee3d3c..e41e7d6a6 100644 --- a/src/Microsoft.OpenApi/Models/Interfaces/IOpenApiDescribedElement.cs +++ b/src/Microsoft.OpenApi/Models/Interfaces/IOpenApiDescribedElement.cs @@ -1,4 +1,4 @@ -using Microsoft.OpenApi.Interfaces; +using Microsoft.OpenApi.Interfaces; namespace Microsoft.OpenApi.Models.Interfaces; @@ -11,7 +11,7 @@ public interface IOpenApiDescribedElement : IOpenApiElement /// Long description for the example. /// CommonMark syntax MAY be used for rich text representation. /// - public string Description { get; set; } + public string? Description { get; set; } } /// @@ -23,5 +23,5 @@ public interface IOpenApiReadOnlyDescribedElement : IOpenApiElement /// Long description for the example. /// CommonMark syntax MAY be used for rich text representation. /// - public string Description { get; } + public string? Description { get; } } diff --git a/src/Microsoft.OpenApi/Models/Interfaces/IOpenApiExample.cs b/src/Microsoft.OpenApi/Models/Interfaces/IOpenApiExample.cs index ece8b48ad..389652dbc 100644 --- a/src/Microsoft.OpenApi/Models/Interfaces/IOpenApiExample.cs +++ b/src/Microsoft.OpenApi/Models/Interfaces/IOpenApiExample.cs @@ -1,4 +1,4 @@ -using System.Text.Json.Nodes; +using System.Text.Json.Nodes; using Microsoft.OpenApi.Interfaces; namespace Microsoft.OpenApi.Models.Interfaces; @@ -14,7 +14,7 @@ public interface IOpenApiExample : IOpenApiDescribedElement, IOpenApiSummarizedE /// exclusive. To represent examples of media types that cannot naturally represented /// in JSON or YAML, use a string value to contain the example, escaping where necessary. /// - public JsonNode Value { get; } + public JsonNode? Value { get; } /// /// A URL that points to the literal example. @@ -22,5 +22,5 @@ public interface IOpenApiExample : IOpenApiDescribedElement, IOpenApiSummarizedE /// included in JSON or YAML documents. /// The value field and externalValue field are mutually exclusive. /// - public string ExternalValue { get; } + public string? ExternalValue { get; } } diff --git a/src/Microsoft.OpenApi/Models/Interfaces/IOpenApiHeader.cs b/src/Microsoft.OpenApi/Models/Interfaces/IOpenApiHeader.cs index 35b6cdfe9..9fdef7b37 100644 --- a/src/Microsoft.OpenApi/Models/Interfaces/IOpenApiHeader.cs +++ b/src/Microsoft.OpenApi/Models/Interfaces/IOpenApiHeader.cs @@ -1,4 +1,4 @@ - + using System.Collections.Generic; using System.Text.Json.Nodes; using Microsoft.OpenApi.Interfaces; @@ -45,21 +45,21 @@ public interface IOpenApiHeader : IOpenApiDescribedElement, IOpenApiSerializable /// /// The schema defining the type used for the request body. /// - public IOpenApiSchema Schema { get; } + public IOpenApiSchema? Schema { get; } /// /// Example of the media type. /// - public JsonNode Example { get; } + public JsonNode? Example { get; } /// /// Examples of the media type. /// - public IDictionary Examples { get; } + public IDictionary? Examples { get; } /// /// A map containing the representations for the header. /// - public IDictionary Content { get; } + public IDictionary? Content { get; } } diff --git a/src/Microsoft.OpenApi/Models/Interfaces/IOpenApiLink.cs b/src/Microsoft.OpenApi/Models/Interfaces/IOpenApiLink.cs index 66e8b5e3b..eb9699857 100644 --- a/src/Microsoft.OpenApi/Models/Interfaces/IOpenApiLink.cs +++ b/src/Microsoft.OpenApi/Models/Interfaces/IOpenApiLink.cs @@ -1,4 +1,4 @@ -using System.Collections.Generic; +using System.Collections.Generic; using Microsoft.OpenApi.Interfaces; namespace Microsoft.OpenApi.Models.Interfaces; @@ -13,25 +13,25 @@ public interface IOpenApiLink : IOpenApiDescribedElement, IOpenApiSerializable, /// A relative or absolute reference to an OAS operation. /// This field is mutually exclusive of the operationId field, and MUST point to an Operation Object. /// - public string OperationRef { get; } + public string? OperationRef { get; } /// /// The name of an existing, resolvable OAS operation, as defined with a unique operationId. /// This field is mutually exclusive of the operationRef field. /// - public string OperationId { get; } + public string? OperationId { get; } /// /// A map representing parameters to pass to an operation as specified with operationId or identified via operationRef. /// - public IDictionary Parameters { get; } + public IDictionary? Parameters { get; } /// /// A literal value or {expression} to use as a request body when calling the target operation. /// - public RuntimeExpressionAnyWrapper RequestBody { get; } + public RuntimeExpressionAnyWrapper? RequestBody { get; } /// /// A server object to be used by the target operation. /// - public OpenApiServer Server { get; } + public OpenApiServer? Server { get; } } diff --git a/src/Microsoft.OpenApi/Models/Interfaces/IOpenApiParameter.cs b/src/Microsoft.OpenApi/Models/Interfaces/IOpenApiParameter.cs index 465078e43..1aedaa7d8 100644 --- a/src/Microsoft.OpenApi/Models/Interfaces/IOpenApiParameter.cs +++ b/src/Microsoft.OpenApi/Models/Interfaces/IOpenApiParameter.cs @@ -1,4 +1,4 @@ -using System.Collections.Generic; +using System.Collections.Generic; using System.Text.Json.Nodes; using Microsoft.OpenApi.Interfaces; @@ -16,7 +16,7 @@ public interface IOpenApiParameter : IOpenApiDescribedElement, IOpenApiSerializa /// If in is "header" and the name field is "Accept", "Content-Type" or "Authorization", the parameter definition SHALL be ignored. /// For all other cases, the name corresponds to the parameter name used by the in property. /// - public string Name { get; } + public string? Name { get; } /// /// REQUIRED. The location of the parameter. @@ -72,7 +72,7 @@ public interface IOpenApiParameter : IOpenApiDescribedElement, IOpenApiSerializa /// /// The schema defining the type used for the parameter. /// - public IOpenApiSchema Schema { get; } + public IOpenApiSchema? Schema { get; } /// /// Examples of the media type. Each example SHOULD contain a value @@ -81,7 +81,7 @@ public interface IOpenApiParameter : IOpenApiDescribedElement, IOpenApiSerializa /// Furthermore, if referencing a schema which contains an example, /// the examples value SHALL override the example provided by the schema. /// - public IDictionary Examples { get; } + public IDictionary? Examples { get; } /// /// Example of the media type. The example SHOULD match the specified schema and encoding properties @@ -91,7 +91,7 @@ public interface IOpenApiParameter : IOpenApiDescribedElement, IOpenApiSerializa /// To represent examples of media types that cannot naturally be represented in JSON or YAML, /// a string value can contain the example with escaping where necessary. /// - public JsonNode Example { get; } + public JsonNode? Example { get; } /// /// A map containing the representations for the parameter. @@ -102,5 +102,5 @@ public interface IOpenApiParameter : IOpenApiDescribedElement, IOpenApiSerializa /// When example or examples are provided in conjunction with the schema object, /// the example MUST follow the prescribed serialization strategy for the parameter. /// - public IDictionary Content { get; } + public IDictionary? Content { get; } } diff --git a/src/Microsoft.OpenApi/Models/Interfaces/IOpenApiPathItem.cs b/src/Microsoft.OpenApi/Models/Interfaces/IOpenApiPathItem.cs index bbc316a14..46c183b0d 100644 --- a/src/Microsoft.OpenApi/Models/Interfaces/IOpenApiPathItem.cs +++ b/src/Microsoft.OpenApi/Models/Interfaces/IOpenApiPathItem.cs @@ -1,4 +1,4 @@ - + using System.Collections.Generic; using Microsoft.OpenApi.Interfaces; @@ -13,16 +13,16 @@ public interface IOpenApiPathItem : IOpenApiDescribedElement, IOpenApiSummarized /// /// Gets the definition of operations on this path. /// - public IDictionary Operations { get; } + public IDictionary? Operations { get; } /// /// An alternative server array to service all operations in this path. /// - public IList Servers { get; } + public IList? Servers { get; } /// /// A list of parameters that are applicable for all the operations described under this path. /// These parameters can be overridden at the operation level, but cannot be removed there. /// - public IList Parameters { get; } + public IList? Parameters { get; } } diff --git a/src/Microsoft.OpenApi/Models/Interfaces/IOpenApiRequestBody.cs b/src/Microsoft.OpenApi/Models/Interfaces/IOpenApiRequestBody.cs index 84afff156..706cdc5dc 100644 --- a/src/Microsoft.OpenApi/Models/Interfaces/IOpenApiRequestBody.cs +++ b/src/Microsoft.OpenApi/Models/Interfaces/IOpenApiRequestBody.cs @@ -1,4 +1,4 @@ -using System.Collections.Generic; +using System.Collections.Generic; using Microsoft.OpenApi.Interfaces; using Microsoft.OpenApi.Writers; @@ -19,17 +19,17 @@ public interface IOpenApiRequestBody : IOpenApiDescribedElement, IOpenApiSeriali /// REQUIRED. The content of the request body. The key is a media type or media type range and the value describes it. /// For requests that match multiple keys, only the most specific key is applicable. e.g. text/plain overrides text/* /// - public IDictionary Content { get; } + public IDictionary? Content { get; } /// /// Converts the request body to a body parameter in preparation for a v2 serialization. /// /// The writer to use to read settings from. /// The converted OpenAPI parameter - IOpenApiParameter ConvertToBodyParameter(IOpenApiWriter writer); + IOpenApiParameter? ConvertToBodyParameter(IOpenApiWriter writer); /// /// Converts the request body to a set of form data parameters in preparation for a v2 serialization. /// /// The writer to use to read settings from /// The converted OpenAPI parameters - IEnumerable ConvertToFormDataParameters(IOpenApiWriter writer); + IEnumerable? ConvertToFormDataParameters(IOpenApiWriter writer); } diff --git a/src/Microsoft.OpenApi/Models/Interfaces/IOpenApiResponse.cs b/src/Microsoft.OpenApi/Models/Interfaces/IOpenApiResponse.cs index 3df66eec0..54994ce5c 100644 --- a/src/Microsoft.OpenApi/Models/Interfaces/IOpenApiResponse.cs +++ b/src/Microsoft.OpenApi/Models/Interfaces/IOpenApiResponse.cs @@ -1,4 +1,4 @@ -using System.Collections.Generic; +using System.Collections.Generic; using Microsoft.OpenApi.Interfaces; namespace Microsoft.OpenApi.Models.Interfaces; @@ -12,18 +12,18 @@ public interface IOpenApiResponse : IOpenApiDescribedElement, IOpenApiSerializab /// /// Maps a header name to its definition. /// - public IDictionary Headers { get; } + public IDictionary? Headers { get; } /// /// A map containing descriptions of potential response payloads. /// The key is a media type or media type range and the value describes it. /// - public IDictionary Content { get; } + public IDictionary? Content { get; } /// /// A map of operations links that can be followed from the response. /// The key of the map is a short name for the link, /// following the naming constraints of the names for Component Objects. /// - public IDictionary Links { get; } + public IDictionary? Links { get; } } diff --git a/src/Microsoft.OpenApi/Models/Interfaces/IOpenApiSchema.cs b/src/Microsoft.OpenApi/Models/Interfaces/IOpenApiSchema.cs index 9ff8e8389..76e082944 100644 --- a/src/Microsoft.OpenApi/Models/Interfaces/IOpenApiSchema.cs +++ b/src/Microsoft.OpenApi/Models/Interfaces/IOpenApiSchema.cs @@ -1,4 +1,4 @@ -using System.Collections.Generic; +using System.Collections.Generic; using System.Text.Json.Nodes; using Microsoft.OpenApi.Interfaces; @@ -14,43 +14,43 @@ public interface IOpenApiSchema : IOpenApiDescribedElement, IOpenApiSerializable /// /// Follow JSON Schema definition. Short text providing information about the data. /// - public string Title { get; } + public string? Title { get; } /// /// $schema, a JSON Schema dialect identifier. Value must be a URI /// - public string Schema { get; } + public string? Schema { get; } /// /// $id - Identifies a schema resource with its canonical URI. /// - public string Id { get; } + public string? Id { get; } /// /// $comment - reserves a location for comments from schema authors to readers or maintainers of the schema. /// - public string Comment { get; } + public string? Comment { get; } /// /// $vocabulary- used in meta-schemas to identify the vocabularies available for use in schemas described by that meta-schema. /// - public IDictionary Vocabulary { get; } + public IDictionary? Vocabulary { get; } /// /// $dynamicRef - an applicator that allows for deferring the full resolution until runtime, at which point it is resolved each time it is encountered while evaluating an instance /// - public string DynamicRef { get; } + public string? DynamicRef { get; } /// /// $dynamicAnchor - used to create plain name fragments that are not tied to any particular structural location for referencing purposes, which are taken into consideration for dynamic referencing. /// - public string DynamicAnchor { get; } + public string? DynamicAnchor { get; } /// /// $defs - reserves a location for schema authors to inline re-usable JSON Schemas into a more general schema. /// The keyword does not directly affect the validation result /// - public IDictionary Definitions { get; } + public IDictionary? Definitions { get; } /// /// Follow JSON Schema definition: https://tools.ietf.org/html/draft-fge-json-schema-validation-00 @@ -76,14 +76,14 @@ public interface IOpenApiSchema : IOpenApiDescribedElement, IOpenApiSerializable /// /// Follow JSON Schema definition: https://json-schema.org/draft/2020-12/json-schema-validation /// - public string Const { get; } + public string? Const { get; } /// /// Follow JSON Schema definition: https://tools.ietf.org/html/draft-fge-json-schema-validation-00 /// While relying on JSON Schema's defined formats, /// the OAS offers a few additional predefined formats. /// - public string Format { get; } + public string? Format { get; } /// /// Follow JSON Schema definition: https://tools.ietf.org/html/draft-fge-json-schema-validation-00 @@ -119,7 +119,7 @@ public interface IOpenApiSchema : IOpenApiDescribedElement, IOpenApiSerializable /// Follow JSON Schema definition: https://tools.ietf.org/html/draft-fge-json-schema-validation-00 /// This string SHOULD be a valid regular expression, according to the ECMA 262 regular expression dialect /// - public string Pattern { get; } + public string? Pattern { get; } /// /// Follow JSON Schema definition: https://tools.ietf.org/html/draft-fge-json-schema-validation-00 @@ -132,7 +132,7 @@ public interface IOpenApiSchema : IOpenApiDescribedElement, IOpenApiSerializable /// Unlike JSON Schema, the value MUST conform to the defined type for the Schema Object defined at the same level. /// For example, if type is string, then default can be "foo" but cannot be 1. /// - public JsonNode Default { get; } + public JsonNode? Default { get; } /// /// Relevant only for Schema "properties" definitions. Declares the property as "read only". @@ -158,37 +158,37 @@ public interface IOpenApiSchema : IOpenApiDescribedElement, IOpenApiSerializable /// Follow JSON Schema definition: https://tools.ietf.org/html/draft-fge-json-schema-validation-00 /// Inline or referenced schema MUST be of a Schema Object and not a standard JSON Schema. /// - public IList AllOf { get; } + public IList? AllOf { get; } /// /// Follow JSON Schema definition: https://tools.ietf.org/html/draft-fge-json-schema-validation-00 /// Inline or referenced schema MUST be of a Schema Object and not a standard JSON Schema. /// - public IList OneOf { get; } + public IList? OneOf { get; } /// /// Follow JSON Schema definition: https://tools.ietf.org/html/draft-fge-json-schema-validation-00 /// Inline or referenced schema MUST be of a Schema Object and not a standard JSON Schema. /// - public IList AnyOf { get; } + public IList? AnyOf { get; } /// /// Follow JSON Schema definition: https://tools.ietf.org/html/draft-fge-json-schema-validation-00 /// Inline or referenced schema MUST be of a Schema Object and not a standard JSON Schema. /// - public IOpenApiSchema Not { get; } + public IOpenApiSchema? Not { get; } /// /// Follow JSON Schema definition: https://tools.ietf.org/html/draft-fge-json-schema-validation-00 /// - public ISet Required { get; } + public ISet? Required { get; } /// /// Follow JSON Schema definition: https://tools.ietf.org/html/draft-fge-json-schema-validation-00 /// Value MUST be an object and not an array. Inline or referenced schema MUST be of a Schema Object /// and not a standard JSON Schema. items MUST be present if the type is array. /// - public IOpenApiSchema Items { get; } + public IOpenApiSchema? Items { get; } /// /// Follow JSON Schema definition: https://tools.ietf.org/html/draft-fge-json-schema-validation-00 @@ -209,7 +209,7 @@ public interface IOpenApiSchema : IOpenApiDescribedElement, IOpenApiSerializable /// Follow JSON Schema definition: https://tools.ietf.org/html/draft-fge-json-schema-validation-00 /// Property definitions MUST be a Schema Object and not a standard JSON Schema (inline or referenced). /// - public IDictionary Properties { get; } + public IDictionary? Properties { get; } /// /// Follow JSON Schema definition: https://tools.ietf.org/html/draft-fge-json-schema-validation-00 @@ -218,7 +218,7 @@ public interface IOpenApiSchema : IOpenApiDescribedElement, IOpenApiSerializable /// egular expression dialect. Each property value of this object MUST be an object, and each object MUST /// be a valid Schema Object not a standard JSON Schema. /// - public IDictionary PatternProperties { get; } + public IDictionary? PatternProperties { get; } /// /// Follow JSON Schema definition: https://tools.ietf.org/html/draft-fge-json-schema-validation-00 @@ -240,32 +240,32 @@ public interface IOpenApiSchema : IOpenApiDescribedElement, IOpenApiSerializable /// Value can be boolean or object. Inline or referenced schema /// MUST be of a Schema Object and not a standard JSON Schema. /// - public IOpenApiSchema AdditionalProperties { get; } + public IOpenApiSchema? AdditionalProperties { get; } /// /// Adds support for polymorphism. The discriminator is an object name that is used to differentiate /// between other schemas which may satisfy the payload description. /// - public OpenApiDiscriminator Discriminator { get; } + public OpenApiDiscriminator? Discriminator { get; } /// /// A free-form property to include an example of an instance for this schema. /// To represent examples that cannot be naturally represented in JSON or YAML, /// a string value can be used to contain the example with escaping where necessary. /// - public JsonNode Example { get; } + public JsonNode? Example { get; } /// /// A free-form property to include examples of an instance for this schema. /// To represent examples that cannot be naturally represented in JSON or YAML, /// a list of values can be used to contain the examples with escaping where necessary. /// - public IList Examples { get; } + public IList? Examples { get; } /// /// Follow JSON Schema definition: https://tools.ietf.org/html/draft-fge-json-schema-validation-00 /// - public IList Enum { get; } + public IList? Enum { get; } /// /// Follow JSON Schema definition: https://tools.ietf.org/html/draft-fge-json-schema-validation-00 @@ -275,7 +275,7 @@ public interface IOpenApiSchema : IOpenApiDescribedElement, IOpenApiSerializable /// /// Additional external documentation for this schema. /// - public OpenApiExternalDocs ExternalDocs { get; } + public OpenApiExternalDocs? ExternalDocs { get; } /// /// Specifies that a schema is deprecated and SHOULD be transitioned out of usage. @@ -287,16 +287,16 @@ public interface IOpenApiSchema : IOpenApiDescribedElement, IOpenApiSerializable /// This MAY be used only on properties schemas. It has no effect on root schemas. /// Adds additional metadata to describe the XML representation of this property. /// - public OpenApiXml Xml { get; } + public OpenApiXml? Xml { get; } /// /// This object stores any unrecognized keywords found in the schema. /// - public IDictionary UnrecognizedKeywords { get; } + public IDictionary? UnrecognizedKeywords { get; } /// /// Any annotation to attach to the schema to be used by the application. /// Annotations are NOT (de)serialized with the schema and can be used for custom properties. /// - public IDictionary Annotations { get; } + public IDictionary? Annotations { get; } } diff --git a/src/Microsoft.OpenApi/Models/Interfaces/IOpenApiSecurityScheme.cs b/src/Microsoft.OpenApi/Models/Interfaces/IOpenApiSecurityScheme.cs index 9580a3dad..d33c01f6f 100644 --- a/src/Microsoft.OpenApi/Models/Interfaces/IOpenApiSecurityScheme.cs +++ b/src/Microsoft.OpenApi/Models/Interfaces/IOpenApiSecurityScheme.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using Microsoft.OpenApi.Interfaces; @@ -18,7 +18,7 @@ public interface IOpenApiSecurityScheme : IOpenApiDescribedElement, IOpenApiSeri /// /// REQUIRED. The name of the header, query or cookie parameter to be used. /// - public string Name { get; } + public string? Name { get; } /// /// REQUIRED. The location of the API key. Valid values are "query", "header" or "cookie". @@ -29,22 +29,22 @@ public interface IOpenApiSecurityScheme : IOpenApiDescribedElement, IOpenApiSeri /// REQUIRED. The name of the HTTP Authorization scheme to be used /// in the Authorization header as defined in RFC7235. /// - public string Scheme { get; } + public string? Scheme { get; } /// /// A hint to the client to identify how the bearer token is formatted. /// Bearer tokens are usually generated by an authorization server, /// so this information is primarily for documentation purposes. /// - public string BearerFormat { get; } + public string? BearerFormat { get; } /// /// REQUIRED. An object containing configuration information for the flow types supported. /// - public OpenApiOAuthFlows Flows { get; } + public OpenApiOAuthFlows? Flows { get; } /// /// REQUIRED. OpenId Connect URL to discover OAuth2 configuration values. /// - public Uri OpenIdConnectUrl { get; } + public Uri? OpenIdConnectUrl { get; } } diff --git a/src/Microsoft.OpenApi/Models/Interfaces/IOpenApiSummarizedElement.cs b/src/Microsoft.OpenApi/Models/Interfaces/IOpenApiSummarizedElement.cs index 3273b03f5..e3595bf69 100644 --- a/src/Microsoft.OpenApi/Models/Interfaces/IOpenApiSummarizedElement.cs +++ b/src/Microsoft.OpenApi/Models/Interfaces/IOpenApiSummarizedElement.cs @@ -1,4 +1,4 @@ -using Microsoft.OpenApi.Interfaces; +using Microsoft.OpenApi.Interfaces; namespace Microsoft.OpenApi.Models.Interfaces; /// @@ -9,5 +9,5 @@ public interface IOpenApiSummarizedElement : IOpenApiElement /// /// Short description for the example. /// - public string Summary { get; set; } + public string? Summary { get; set; } } diff --git a/src/Microsoft.OpenApi/Models/Interfaces/IOpenApiTag.cs b/src/Microsoft.OpenApi/Models/Interfaces/IOpenApiTag.cs index c2a6d8523..5f2fc21b0 100644 --- a/src/Microsoft.OpenApi/Models/Interfaces/IOpenApiTag.cs +++ b/src/Microsoft.OpenApi/Models/Interfaces/IOpenApiTag.cs @@ -1,4 +1,4 @@ -using Microsoft.OpenApi.Interfaces; +using Microsoft.OpenApi.Interfaces; namespace Microsoft.OpenApi.Models.Interfaces; @@ -11,10 +11,10 @@ public interface IOpenApiTag : IOpenApiSerializable, IOpenApiReadOnlyExtensible, /// /// The name of the tag. /// - public string Name { get; } + public string? Name { get; } /// /// Additional external documentation for this tag. /// - public OpenApiExternalDocs ExternalDocs { get; } + public OpenApiExternalDocs? ExternalDocs { get; } } diff --git a/src/Microsoft.OpenApi/Models/OpenApiCallback.cs b/src/Microsoft.OpenApi/Models/OpenApiCallback.cs index 96f5c5cf4..435d9155e 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiCallback.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiCallback.cs @@ -16,14 +16,14 @@ namespace Microsoft.OpenApi.Models public class OpenApiCallback : IOpenApiReferenceable, IOpenApiExtensible, IOpenApiCallback { /// - public Dictionary PathItems { get; set; } + public Dictionary? PathItems { get; set; } = []; /// /// This object MAY be extended with Specification Extensions. /// - public IDictionary Extensions { get; set; } = new Dictionary(); + public IDictionary? Extensions { get; set; } = new Dictionary(); /// /// Parameter-less constructor @@ -36,7 +36,7 @@ public OpenApiCallback() { } internal OpenApiCallback(IOpenApiCallback callback) { Utils.CheckArgumentNull(callback); - PathItems = callback?.PathItems != null ? new(callback?.PathItems) : null; + PathItems = callback?.PathItems != null ? new(callback.PathItems) : null; Extensions = callback?.Extensions != null ? new Dictionary(callback.Extensions) : null; } @@ -81,9 +81,12 @@ internal void SerializeInternal(IOpenApiWriter writer, OpenApiSpecVersion versio writer.WriteStartObject(); // path items - foreach (var item in PathItems) + if (PathItems != null) { - writer.WriteRequiredObject(item.Key.Expression, item.Value, callback); + foreach (var item in PathItems) + { + writer.WriteRequiredObject(item.Key.Expression, item.Value, callback); + } } // extensions diff --git a/src/Microsoft.OpenApi/Models/OpenApiContact.cs b/src/Microsoft.OpenApi/Models/OpenApiContact.cs index 15d67cc76..940388887 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiContact.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiContact.cs @@ -16,23 +16,23 @@ public class OpenApiContact : IOpenApiSerializable, IOpenApiExtensible /// /// The identifying name of the contact person/organization. /// - public string Name { get; set; } + public string? Name { get; set; } /// /// The URL pointing to the contact information. MUST be in the format of a URL. /// - public Uri Url { get; set; } + public Uri? Url { get; set; } /// /// The email address of the contact person/organization. /// MUST be in the format of an email address. /// - public string Email { get; set; } + public string? Email { get; set; } /// /// This object MAY be extended with Specification Extensions. /// - public IDictionary Extensions { get; set; } = new Dictionary(); + public IDictionary? Extensions { get; set; } = new Dictionary(); /// /// Parameter-less constructor diff --git a/src/Microsoft.OpenApi/Models/OpenApiDiscriminator.cs b/src/Microsoft.OpenApi/Models/OpenApiDiscriminator.cs index 342025f9f..3bbae4561 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiDiscriminator.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiDiscriminator.cs @@ -15,17 +15,17 @@ public class OpenApiDiscriminator : IOpenApiSerializable, IOpenApiExtensible /// /// REQUIRED. The name of the property in the payload that will hold the discriminator value. /// - public string PropertyName { get; set; } + public string? PropertyName { get; set; } /// /// An object to hold mappings between payload values and schema names or references. /// - public IDictionary Mapping { get; set; } = new Dictionary(); + public IDictionary? Mapping { get; set; } = new Dictionary(); /// /// This object MAY be extended with Specification Extensions. /// - public IDictionary Extensions { get; set; } = new Dictionary(); + public IDictionary? Extensions { get; set; } = new Dictionary(); /// /// Parameter-less constructor diff --git a/src/Microsoft.OpenApi/Models/OpenApiDocument.cs b/src/Microsoft.OpenApi/Models/OpenApiDocument.cs index 7820a6f8e..af5839058 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiDocument.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiDocument.cs @@ -115,16 +115,16 @@ public OpenApiDocument() /// public OpenApiDocument(OpenApiDocument? document) { - Workspace = document?.Workspace != null ? new(document?.Workspace) : null; - Info = document?.Info != null ? new(document?.Info) : new OpenApiInfo(); + Workspace = document?.Workspace != null ? new(document.Workspace) : null; + Info = document?.Info != null ? new(document.Info) : new OpenApiInfo(); JsonSchemaDialect = document?.JsonSchemaDialect ?? JsonSchemaDialect; Servers = document?.Servers != null ? new List(document.Servers) : null; - Paths = document?.Paths != null ? new(document?.Paths) : new OpenApiPaths(); + Paths = document?.Paths != null ? new(document.Paths) : new OpenApiPaths(); Webhooks = document?.Webhooks != null ? new Dictionary(document.Webhooks) : null; Components = document?.Components != null ? new(document?.Components) : null; SecurityRequirements = document?.SecurityRequirements != null ? new List(document.SecurityRequirements) : null; Tags = document?.Tags != null ? new List(document.Tags) : null; - ExternalDocs = document?.ExternalDocs != null ? new(document?.ExternalDocs) : null; + ExternalDocs = document?.ExternalDocs != null ? new(document.ExternalDocs) : null; Extensions = document?.Extensions != null ? new Dictionary(document.Extensions) : null; Annotations = document?.Annotations != null ? new Dictionary(document.Annotations) : null; BaseUri = document?.BaseUri != null ? document.BaseUri : new(OpenApiConstants.BaseRegistryUri + Guid.NewGuid()); @@ -248,12 +248,19 @@ public void SerializeAsV2(IOpenApiWriter writer) if (loops.TryGetValue(typeof(IOpenApiSchema), out var schemas)) { - var openApiSchemas = schemas.Cast().Distinct().OfType() - .ToDictionary(k => k.Reference.Id, v => v); + var openApiSchemas = schemas.Cast() + .Distinct() + .OfType() + .Where(k => k.Reference?.Id is not null) + .ToDictionary( + k => k.Reference?.Id!, + v => v + ); + foreach (var schema in openApiSchemas.Values.ToList()) { - FindSchemaReferences.ResolveSchemas(Components, openApiSchemas); + FindSchemaReferences.ResolveSchemas(Components, openApiSchemas!); } writer.WriteOptionalMap( @@ -291,7 +298,9 @@ public void SerializeAsV2(IOpenApiWriter writer) { foreach (var requestBody in Components.RequestBodies.Where(b => !parameters.ContainsKey(b.Key))) { - parameters.Add(requestBody.Key, requestBody.Value.ConvertToBodyParameter(writer)); + var paramValue = requestBody.Value.ConvertToBodyParameter(writer); + if (paramValue is not null) + parameters.Add(requestBody.Key, paramValue); } } writer.WriteOptionalMap( @@ -360,7 +369,7 @@ public void SerializeAsV2(IOpenApiWriter writer) } } - private static string ParseServerUrl(OpenApiServer server) + private static string? ParseServerUrl(OpenApiServer server) { return server.ReplaceServerUrlVariables(new Dictionary(0)); } @@ -376,61 +385,64 @@ private static void WriteHostInfoV2(IOpenApiWriter writer, IList? // one host, port, and base path. var serverUrl = ParseServerUrl(servers[0]); - // Divide the URL in the Url property into host and basePath required in OpenAPI V2 - // The Url property cannot contain path templating to be valid for V2 serialization. - var firstServerUrl = new Uri(serverUrl, UriKind.RelativeOrAbsolute); - - // host - if (firstServerUrl.IsAbsoluteUri) + if (serverUrl != null) { - writer.WriteProperty( - OpenApiConstants.Host, - firstServerUrl.GetComponents(UriComponents.Host | UriComponents.Port, UriFormat.SafeUnescaped)); + // Divide the URL in the Url property into host and basePath required in OpenAPI V2 + // The Url property cannot contain path templating to be valid for V2 serialization. + var firstServerUrl = new Uri(serverUrl, UriKind.RelativeOrAbsolute); - // basePath - if (firstServerUrl.AbsolutePath != "/") + // host + if (firstServerUrl.IsAbsoluteUri) { - writer.WriteProperty(OpenApiConstants.BasePath, firstServerUrl.AbsolutePath); - } - } - else - { - var relativeUrl = firstServerUrl.OriginalString; - if (relativeUrl.StartsWith("//", StringComparison.OrdinalIgnoreCase)) - { - var pathPosition = relativeUrl.IndexOf('/', 3); - writer.WriteProperty(OpenApiConstants.Host, relativeUrl.Substring(0, pathPosition)); - relativeUrl = relativeUrl.Substring(pathPosition); + writer.WriteProperty( + OpenApiConstants.Host, + firstServerUrl.GetComponents(UriComponents.Host | UriComponents.Port, UriFormat.SafeUnescaped)); + + // basePath + if (firstServerUrl.AbsolutePath != "/") + { + writer.WriteProperty(OpenApiConstants.BasePath, firstServerUrl.AbsolutePath); + } } - if (!String.IsNullOrEmpty(relativeUrl) && relativeUrl != "/") + else { - writer.WriteProperty(OpenApiConstants.BasePath, relativeUrl); + var relativeUrl = firstServerUrl.OriginalString; + if (relativeUrl.StartsWith("//", StringComparison.OrdinalIgnoreCase)) + { + var pathPosition = relativeUrl.IndexOf('/', 3); + writer.WriteProperty(OpenApiConstants.Host, relativeUrl.Substring(0, pathPosition)); + relativeUrl = relativeUrl.Substring(pathPosition); + } + if (!String.IsNullOrEmpty(relativeUrl) && relativeUrl != "/") + { + writer.WriteProperty(OpenApiConstants.BasePath, relativeUrl); + } } - } - // Consider all schemes of the URLs in the server list that have the same - // host, port, and base path as the first server. - var schemes = servers.Select( - s => - { - Uri.TryCreate(ParseServerUrl(s), UriKind.RelativeOrAbsolute, out var url); - return url; - }) - .Where( - u => u is not null && - Uri.Compare( - u, - firstServerUrl, - UriComponents.Host | UriComponents.Port | UriComponents.Path, - UriFormat.SafeUnescaped, - StringComparison.OrdinalIgnoreCase) == - 0 && u.IsAbsoluteUri) - .Select(u => u!.Scheme) - .Distinct() - .ToList(); - - // schemes - writer.WriteOptionalCollection(OpenApiConstants.Schemes, schemes, (w, s) => w.WriteValue(s)); + // Consider all schemes of the URLs in the server list that have the same + // host, port, and base path as the first server. + var schemes = servers.Select( + s => + { + Uri.TryCreate(ParseServerUrl(s), UriKind.RelativeOrAbsolute, out var url); + return url; + }) + .Where( + u => u is not null && + Uri.Compare( + u, + firstServerUrl, + UriComponents.Host | UriComponents.Port | UriComponents.Path, + UriFormat.SafeUnescaped, + StringComparison.OrdinalIgnoreCase) == + 0 && u.IsAbsoluteUri) + .Select(u => u!.Scheme) + .Distinct() + .ToList(); + + // schemes + writer.WriteOptionalCollection(OpenApiConstants.Schemes, schemes, (w, s) => w.WriteValue(s)); + } } /// @@ -510,13 +522,14 @@ private static string ConvertByteArrayToString(byte[] hash) } string uriLocation; - if (reference.Id.Contains("/")) // this means its a URL reference + var id = reference.Id; + if (!string.IsNullOrEmpty(id) && id!.Contains("/")) // this means its a URL reference { - uriLocation = reference.Id; + uriLocation = id; } else { - string relativePath = OpenApiConstants.ComponentsSegment + reference.Type.GetDisplayName() + "/" + reference.Id; + string relativePath = OpenApiConstants.ComponentsSegment + reference.Type.GetDisplayName() + "/" + id; uriLocation = useExternal ? Workspace?.GetDocumentId(reference.ExternalResource)?.OriginalString + relativePath @@ -659,9 +672,10 @@ public override void Visit(IOpenApiReferenceHolder referenceHolder) switch (referenceHolder) { case OpenApiSchemaReference schema: - if (!Schemas.ContainsKey(schema.Reference.Id)) + var id = schema.Reference?.Id; + if (id is not null && Schemas is not null && !Schemas.ContainsKey(id)) { - Schemas.Add(schema.Reference.Id, schema); + Schemas.Add(id, schema); } break; @@ -674,10 +688,14 @@ public override void Visit(IOpenApiReferenceHolder referenceHolder) public override void Visit(IOpenApiSchema schema) { // This is needed to handle schemas used in Responses in components - if (schema is OpenApiSchemaReference {Reference: not null} schemaReference && !Schemas.ContainsKey(schemaReference.Reference.Id)) + if (schema is OpenApiSchemaReference { Reference: not null } schemaReference) { - Schemas.Add(schemaReference.Reference.Id, schema); - } + var id = schemaReference.Reference?.Id; + if (id is not null && Schemas is not null && !Schemas.ContainsKey(id)) + { + Schemas.Add(id, schema); + } + } base.Visit(schema); } } diff --git a/src/Microsoft.OpenApi/Models/OpenApiEncoding.cs b/src/Microsoft.OpenApi/Models/OpenApiEncoding.cs index bb8bfab17..4eae8e6ce 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiEncoding.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiEncoding.cs @@ -20,12 +20,12 @@ public class OpenApiEncoding : IOpenApiSerializable, IOpenApiExtensible /// The value can be a specific media type (e.g. application/json), /// a wildcard media type (e.g. image/*), or a comma-separated list of the two types. /// - public string ContentType { get; set; } + public string? ContentType { get; set; } /// /// A map allowing additional information to be provided as headers. /// - public IDictionary Headers { get; set; } = new Dictionary(); + public IDictionary? Headers { get; set; } = new Dictionary(); /// /// Describes how a specific property value will be serialized depending on its type. @@ -52,7 +52,7 @@ public class OpenApiEncoding : IOpenApiSerializable, IOpenApiExtensible /// /// This object MAY be extended with Specification Extensions. /// - public IDictionary Extensions { get; set; } = new Dictionary(); + public IDictionary? Extensions { get; set; } = new Dictionary(); /// /// Parameter-less constructor diff --git a/src/Microsoft.OpenApi/Models/OpenApiError.cs b/src/Microsoft.OpenApi/Models/OpenApiError.cs index 54b98a067..8a42cb38a 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiError.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiError.cs @@ -20,7 +20,7 @@ public OpenApiError(OpenApiException exception) : this(exception.Pointer, except /// /// Initializes the class. /// - public OpenApiError(string pointer, string message) + public OpenApiError(string? pointer, string message) { Pointer = pointer; Message = message; @@ -43,7 +43,7 @@ public OpenApiError(OpenApiError error) /// /// Pointer to the location of the error. /// - public string Pointer { get; set; } + public string? Pointer { get; set; } /// /// Gets the string representation of . diff --git a/src/Microsoft.OpenApi/Models/OpenApiExample.cs b/src/Microsoft.OpenApi/Models/OpenApiExample.cs index bdfd42f4e..1470ca51a 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiExample.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiExample.cs @@ -16,19 +16,19 @@ namespace Microsoft.OpenApi.Models public class OpenApiExample : IOpenApiReferenceable, IOpenApiExtensible, IOpenApiExample { /// - public string Summary { get; set; } + public string? Summary { get; set; } /// - public string Description { get; set; } + public string? Description { get; set; } /// - public string ExternalValue { get; set; } + public string? ExternalValue { get; set; } /// - public JsonNode Value { get; set; } + public JsonNode? Value { get; set; } /// - public IDictionary Extensions { get; set; } = new Dictionary(); + public IDictionary? Extensions { get; set; } = new Dictionary(); /// /// Parameter-less constructor diff --git a/src/Microsoft.OpenApi/Models/OpenApiExtensibleDictionary.cs b/src/Microsoft.OpenApi/Models/OpenApiExtensibleDictionary.cs index 86fe7ea73..b1ad0a39c 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiExtensibleDictionary.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiExtensibleDictionary.cs @@ -27,8 +27,8 @@ protected OpenApiExtensibleDictionary():this(null) { } /// The generic dictionary. /// The dictionary of . protected OpenApiExtensibleDictionary( - Dictionary dictionary, - IDictionary extensions = null) : base(dictionary is null ? [] : dictionary) + Dictionary? dictionary, + IDictionary? extensions = null) : base(dictionary is null ? [] : dictionary) { Extensions = extensions != null ? new Dictionary(extensions) : []; } @@ -36,7 +36,7 @@ protected OpenApiExtensibleDictionary( /// /// This object MAY be extended with Specification Extensions. /// - public IDictionary Extensions { get; set; } + public IDictionary? Extensions { get; set; } /// diff --git a/src/Microsoft.OpenApi/Models/OpenApiExternalDocs.cs b/src/Microsoft.OpenApi/Models/OpenApiExternalDocs.cs index cceace01d..2694aa26a 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiExternalDocs.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiExternalDocs.cs @@ -16,17 +16,17 @@ public class OpenApiExternalDocs : IOpenApiSerializable, IOpenApiExtensible /// /// A short description of the target documentation. /// - public string Description { get; set; } + public string? Description { get; set; } /// /// REQUIRED. The URL for the target documentation. Value MUST be in the format of a URL. /// - public Uri Url { get; set; } + public Uri? Url { get; set; } /// /// This object MAY be extended with Specification Extensions. /// - public IDictionary Extensions { get; set; } = new Dictionary(); + public IDictionary? Extensions { get; set; } = new Dictionary(); /// /// Parameter-less constructor @@ -69,7 +69,7 @@ public void SerializeAsV2(IOpenApiWriter writer) private void WriteInternal(IOpenApiWriter writer, OpenApiSpecVersion specVersion) { - Utils.CheckArgumentNull(writer);; + Utils.CheckArgumentNull(writer); writer.WriteStartObject(); diff --git a/src/Microsoft.OpenApi/Models/OpenApiHeader.cs b/src/Microsoft.OpenApi/Models/OpenApiHeader.cs index dd7a0ec84..ab116a6e1 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiHeader.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiHeader.cs @@ -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; @@ -20,7 +20,7 @@ namespace Microsoft.OpenApi.Models public class OpenApiHeader : IOpenApiHeader, IOpenApiReferenceable, IOpenApiExtensible { /// - public string Description { get; set; } + public string? Description { get; set; } /// public bool Required { get; set; } @@ -41,19 +41,19 @@ public class OpenApiHeader : IOpenApiHeader, IOpenApiReferenceable, IOpenApiExte public bool AllowReserved { get; set; } /// - public IOpenApiSchema Schema { get; set; } + public IOpenApiSchema? Schema { get; set; } /// - public JsonNode Example { get; set; } + public JsonNode? Example { get; set; } /// - public IDictionary Examples { get; set; } = new Dictionary(); + public IDictionary? Examples { get; set; } = new Dictionary(); /// - public IDictionary Content { get; set; } = new Dictionary(); + public IDictionary? Content { get; set; } = new Dictionary(); /// - public IDictionary Extensions { get; set; } = new Dictionary(); + public IDictionary? Extensions { get; set; } = new Dictionary(); /// /// Parameter-less constructor @@ -73,7 +73,7 @@ internal OpenApiHeader(IOpenApiHeader header) Style = header.Style ?? Style; Explode = header.Explode; AllowReserved = header.AllowReserved; - Schema = header.Schema.CreateShallowCopy(); + Schema = header.Schema?.CreateShallowCopy(); Example = header.Example != null ? JsonNodeCloneHelper.Clone(header.Example) : null; Examples = header.Examples != null ? new Dictionary(header.Examples) : null; Content = header.Content != null ? new Dictionary(header.Content) : null; diff --git a/src/Microsoft.OpenApi/Models/OpenApiInfo.cs b/src/Microsoft.OpenApi/Models/OpenApiInfo.cs index 68e37ee20..93e89438c 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiInfo.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiInfo.cs @@ -16,42 +16,42 @@ public class OpenApiInfo : IOpenApiSerializable, IOpenApiExtensible /// /// REQUIRED. The title of the application. /// - public string Title { get; set; } + public string? Title { get; set; } /// /// A short summary of the API. /// - public string Summary { get; set; } + public string? Summary { get; set; } /// /// A short description of the application. /// - public string Description { get; set; } + public string? Description { get; set; } /// /// REQUIRED. The version of the OpenAPI document. /// - public string Version { get; set; } + public string? Version { get; set; } /// /// A URL to the Terms of Service for the API. MUST be in the format of a URL. /// - public Uri TermsOfService { get; set; } + public Uri? TermsOfService { get; set; } /// /// The contact information for the exposed API. /// - public OpenApiContact Contact { get; set; } + public OpenApiContact? Contact { get; set; } /// /// The license information for the exposed API. /// - public OpenApiLicense License { get; set; } + public OpenApiLicense? License { get; set; } /// /// This object MAY be extended with Specification Extensions. /// - public IDictionary Extensions { get; set; } = new Dictionary(); + public IDictionary? Extensions { get; set; } = new Dictionary(); /// /// Parameter-less constructor @@ -68,8 +68,8 @@ public OpenApiInfo(OpenApiInfo info) Description = info?.Description ?? Description; Version = info?.Version ?? Version; TermsOfService = info?.TermsOfService ?? TermsOfService; - Contact = info?.Contact != null ? new(info?.Contact) : null; - License = info?.License != null ? new(info?.License) : null; + Contact = info?.Contact != null ? new(info.Contact) : null; + License = info?.License != null ? new(info.License) : null; Extensions = info?.Extensions != null ? new Dictionary(info.Extensions) : null; } @@ -100,7 +100,7 @@ public void SerializeAsV3(IOpenApiWriter writer) /// private void SerializeInternal(IOpenApiWriter writer, OpenApiSpecVersion version, Action callback) { - Utils.CheckArgumentNull(writer);; + Utils.CheckArgumentNull(writer); writer.WriteStartObject(); // title @@ -130,7 +130,7 @@ private void SerializeInternal(IOpenApiWriter writer, OpenApiSpecVersion version /// public void SerializeAsV2(IOpenApiWriter writer) { - Utils.CheckArgumentNull(writer);; + Utils.CheckArgumentNull(writer); writer.WriteStartObject(); diff --git a/src/Microsoft.OpenApi/Models/OpenApiLicense.cs b/src/Microsoft.OpenApi/Models/OpenApiLicense.cs index 6a8d4bcf7..8aea264e6 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiLicense.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiLicense.cs @@ -16,22 +16,22 @@ public class OpenApiLicense : IOpenApiSerializable, IOpenApiExtensible /// /// REQUIRED. The license name used for the API. /// - public string Name { get; set; } + public string? Name { get; set; } /// /// An SPDX license expression for the API. The identifier field is mutually exclusive of the url field. /// - public string Identifier { get; set; } + public string? Identifier { get; set; } /// /// The URL pointing to the contact information. MUST be in the format of a URL. /// - public Uri Url { get; set; } + public Uri? Url { get; set; } /// /// This object MAY be extended with Specification Extensions. /// - public IDictionary Extensions { get; set; } = new Dictionary(); + public IDictionary? Extensions { get; set; } = new Dictionary(); /// /// Parameterless constructor @@ -79,7 +79,7 @@ public void SerializeAsV2(IOpenApiWriter writer) private void WriteInternal(IOpenApiWriter writer, OpenApiSpecVersion specVersion) { - Utils.CheckArgumentNull(writer);; + Utils.CheckArgumentNull(writer); writer.WriteStartObject(); // name diff --git a/src/Microsoft.OpenApi/Models/OpenApiLink.cs b/src/Microsoft.OpenApi/Models/OpenApiLink.cs index 09883b4a2..412577580 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiLink.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiLink.cs @@ -15,25 +15,25 @@ namespace Microsoft.OpenApi.Models public class OpenApiLink : IOpenApiReferenceable, IOpenApiExtensible, IOpenApiLink { /// - public string OperationRef { get; set; } + public string? OperationRef { get; set; } /// - public string OperationId { get; set; } + public string? OperationId { get; set; } /// - public IDictionary Parameters { get; set; } = new Dictionary(); + public IDictionary? Parameters { get; set; } = new Dictionary(); /// - public RuntimeExpressionAnyWrapper RequestBody { get; set; } + public RuntimeExpressionAnyWrapper? RequestBody { get; set; } /// - public string Description { get; set; } + public string? Description { get; set; } /// - public OpenApiServer Server { get; set; } + public OpenApiServer? Server { get; set; } /// - public IDictionary Extensions { get; set; } = new Dictionary(); + public IDictionary? Extensions { get; set; } = new Dictionary(); /// /// Parameterless constructor diff --git a/src/Microsoft.OpenApi/Models/OpenApiOAuthFlow.cs b/src/Microsoft.OpenApi/Models/OpenApiOAuthFlow.cs index 2385a4c55..d84417cef 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiOAuthFlow.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiOAuthFlow.cs @@ -17,28 +17,28 @@ public class OpenApiOAuthFlow : IOpenApiSerializable, IOpenApiExtensible /// REQUIRED. The authorization URL to be used for this flow. /// Applies to implicit and authorizationCode OAuthFlow. /// - public Uri AuthorizationUrl { get; set; } + public Uri? AuthorizationUrl { get; set; } /// /// REQUIRED. The token URL to be used for this flow. /// Applies to password, clientCredentials, and authorizationCode OAuthFlow. /// - public Uri TokenUrl { get; set; } + public Uri? TokenUrl { get; set; } /// /// The URL to be used for obtaining refresh tokens. /// - public Uri RefreshUrl { get; set; } + public Uri? RefreshUrl { get; set; } /// /// REQUIRED. A map between the scope name and a short description for it. /// - public IDictionary Scopes { get; set; } = new Dictionary(); + public IDictionary? Scopes { get; set; } = new Dictionary(); /// /// Specification Extensions. /// - public IDictionary Extensions { get; set; } = new Dictionary(); + public IDictionary? Extensions { get; set; } = new Dictionary(); /// /// Parameterless constructor @@ -78,7 +78,7 @@ public void SerializeAsV3(IOpenApiWriter writer) /// private void SerializeInternal(IOpenApiWriter writer, OpenApiSpecVersion version) { - Utils.CheckArgumentNull(writer);; + Utils.CheckArgumentNull(writer); writer.WriteStartObject(); diff --git a/src/Microsoft.OpenApi/Models/OpenApiOAuthFlows.cs b/src/Microsoft.OpenApi/Models/OpenApiOAuthFlows.cs index 5211159a4..758e1e02d 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiOAuthFlows.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiOAuthFlows.cs @@ -16,27 +16,27 @@ public class OpenApiOAuthFlows : IOpenApiSerializable, IOpenApiExtensible /// /// Configuration for the OAuth Implicit flow /// - public OpenApiOAuthFlow Implicit { get; set; } + public OpenApiOAuthFlow? Implicit { get; set; } /// /// Configuration for the OAuth Resource Owner Password flow. /// - public OpenApiOAuthFlow Password { get; set; } + public OpenApiOAuthFlow? Password { get; set; } /// /// Configuration for the OAuth Client Credentials flow. /// - public OpenApiOAuthFlow ClientCredentials { get; set; } + public OpenApiOAuthFlow? ClientCredentials { get; set; } /// /// Configuration for the OAuth Authorization Code flow. /// - public OpenApiOAuthFlow AuthorizationCode { get; set; } + public OpenApiOAuthFlow? AuthorizationCode { get; set; } /// /// Specification Extensions. /// - public IDictionary Extensions { get; set; } = new Dictionary(); + public IDictionary? Extensions { get; set; } = new Dictionary(); /// /// Parameterless constructor @@ -49,10 +49,10 @@ public OpenApiOAuthFlows() { } /// public OpenApiOAuthFlows(OpenApiOAuthFlows oAuthFlows) { - Implicit = oAuthFlows?.Implicit != null ? new(oAuthFlows?.Implicit) : null; - Password = oAuthFlows?.Password != null ? new(oAuthFlows?.Password) : null; - ClientCredentials = oAuthFlows?.ClientCredentials != null ? new(oAuthFlows?.ClientCredentials) : null; - AuthorizationCode = oAuthFlows?.AuthorizationCode != null ? new(oAuthFlows?.AuthorizationCode) : null; + Implicit = oAuthFlows?.Implicit != null ? new(oAuthFlows.Implicit) : null; + Password = oAuthFlows?.Password != null ? new(oAuthFlows.Password) : null; + ClientCredentials = oAuthFlows?.ClientCredentials != null ? new(oAuthFlows.ClientCredentials) : null; + AuthorizationCode = oAuthFlows?.AuthorizationCode != null ? new(oAuthFlows.AuthorizationCode) : null; Extensions = oAuthFlows?.Extensions != null ? new Dictionary(oAuthFlows.Extensions) : null; } @@ -78,7 +78,7 @@ public void SerializeAsV3(IOpenApiWriter writer) private void SerializeInternal(IOpenApiWriter writer, OpenApiSpecVersion version, Action callback) { - Utils.CheckArgumentNull(writer);; + Utils.CheckArgumentNull(writer); writer.WriteStartObject(); diff --git a/src/Microsoft.OpenApi/Models/OpenApiOperation.cs b/src/Microsoft.OpenApi/Models/OpenApiOperation.cs index 3acbd05ab..f664fd483 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiOperation.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiOperation.cs @@ -248,17 +248,25 @@ public void SerializeAsV2(IOpenApiWriter writer) if (consumes.Contains("application/x-www-form-urlencoded") || consumes.Contains("multipart/form-data")) { - parameters.AddRange(RequestBody.ConvertToFormDataParameters(writer)); + var formDataParameters = RequestBody.ConvertToFormDataParameters(writer); + if (formDataParameters != null) + { + parameters.AddRange(formDataParameters); + } } else { - parameters.Add(RequestBody.ConvertToBodyParameter(writer)); + var bodyParameter = RequestBody.ConvertToBodyParameter(writer); + if (bodyParameter != null) + { + parameters.Add(bodyParameter); + } } } else if (RequestBody is OpenApiRequestBodyReference requestBodyReference) { parameters.Add( - new OpenApiParameterReference(requestBodyReference.Reference.Id, requestBodyReference.Reference.HostDocument)); + new OpenApiParameterReference(requestBodyReference.Reference?.Id, requestBodyReference.Reference?.HostDocument)); } if (consumes.Count > 0) @@ -319,7 +327,7 @@ public void SerializeAsV2(IOpenApiWriter writer) .Distinct() .ToList(); - writer.WriteOptionalCollection(OpenApiConstants.Schemes, schemes, (w, s) => w.WriteValue(s)); + writer.WriteOptionalCollection(OpenApiConstants.Schemes, schemes.Where(scheme => scheme is not null).ToString(), (w, s) => w.WriteValue(s)); } // deprecated diff --git a/src/Microsoft.OpenApi/Models/OpenApiParameter.cs b/src/Microsoft.OpenApi/Models/OpenApiParameter.cs index 0f1d7c03a..37bce50c2 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiParameter.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiParameter.cs @@ -23,13 +23,13 @@ public class OpenApiParameter : IOpenApiReferenceable, IOpenApiExtensible, IOpen private ParameterStyle? _style; /// - public string Name { get; set; } + public string? Name { get; set; } /// public ParameterLocation? In { get; set; } /// - public string Description { get; set; } + public string? Description { get; set; } /// public bool Required { get; set; } @@ -58,19 +58,19 @@ public bool Explode public bool AllowReserved { get; set; } /// - public IOpenApiSchema Schema { get; set; } + public IOpenApiSchema? Schema { get; set; } /// - public IDictionary Examples { get; set; } = new Dictionary(); + public IDictionary? Examples { get; set; } = new Dictionary(); /// - public JsonNode Example { get; set; } + public JsonNode? Example { get; set; } /// - public IDictionary Content { get; set; } = new Dictionary(); + public IDictionary? Content { get; set; } = new Dictionary(); /// - public IDictionary Extensions { get; set; } = new Dictionary(); + public IDictionary? Extensions { get; set; } = new Dictionary(); /// /// A parameterless constructor @@ -90,7 +90,7 @@ internal OpenApiParameter(IOpenApiParameter parameter) Style = parameter.Style ?? Style; Explode = parameter.Explode; AllowReserved = parameter.AllowReserved; - Schema = parameter.Schema.CreateShallowCopy(); + Schema = parameter.Schema?.CreateShallowCopy(); Examples = parameter.Examples != null ? new Dictionary(parameter.Examples) : null; Example = parameter.Example != null ? JsonNodeCloneHelper.Clone(parameter.Example) : null; Content = parameter.Content != null ? new Dictionary(parameter.Content) : null; @@ -199,7 +199,7 @@ public void SerializeAsV2(IOpenApiWriter writer) // deprecated writer.WriteProperty(OpenApiConstants.Deprecated, Deprecated, false); - var extensionsClone = new Dictionary(Extensions); + var extensionsClone = Extensions is not null ? new Dictionary(Extensions) : null; // schema if (this is OpenApiBodyParameter) @@ -239,14 +239,14 @@ public void SerializeAsV2(IOpenApiWriter writer) if (targetSchema is not null) { targetSchema.WriteAsItemsProperties(writer); - var extensions = Schema.Extensions; + var extensions = Schema?.Extensions; if (extensions != null) { foreach (var key in extensions.Keys) { // The extension will already have been serialized as part of the call to WriteAsItemsProperties above, // so remove it from the cloned collection so we don't write it again. - extensionsClone.Remove(key); + extensionsClone?.Remove(key); } } } diff --git a/src/Microsoft.OpenApi/Models/OpenApiPathItem.cs b/src/Microsoft.OpenApi/Models/OpenApiPathItem.cs index f3baa5743..aa219bcbb 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiPathItem.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiPathItem.cs @@ -16,23 +16,23 @@ namespace Microsoft.OpenApi.Models public class OpenApiPathItem : IOpenApiExtensible, IOpenApiReferenceable, IOpenApiPathItem { /// - public string Summary { get; set; } + public string? Summary { get; set; } /// - public string Description { get; set; } + public string? Description { get; set; } /// - public IDictionary Operations { get; set; } + public IDictionary? Operations { get; set; } = new Dictionary(); /// - public IList Servers { get; set; } = []; + public IList? Servers { get; set; } = []; /// - public IList Parameters { get; set; } = []; + public IList? Parameters { get; set; } = []; /// - public IDictionary Extensions { get; set; } = new Dictionary(); + public IDictionary? Extensions { get; set; } = new Dictionary(); /// /// Add one operation into this path item. @@ -41,7 +41,10 @@ public class OpenApiPathItem : IOpenApiExtensible, IOpenApiReferenceable, IOpenA /// The operation item. public void AddOperation(OperationType operationType, OpenApiOperation operation) { - Operations[operationType] = operation; + if (Operations is not null) + { + Operations[operationType] = operation; + } } /// @@ -90,14 +93,17 @@ public void SerializeAsV2(IOpenApiWriter writer) writer.WriteStartObject(); // operations except "trace" - foreach (var operation in Operations) + if (Operations != null) { - if (operation.Key != OperationType.Trace) + foreach (var operation in Operations) { - writer.WriteOptionalObject( - operation.Key.GetDisplayName(), - operation.Value, - (w, o) => o.SerializeAsV2(w)); + if (operation.Key != OperationType.Trace) + { + writer.WriteOptionalObject( + operation.Key.GetDisplayName(), + operation.Value, + (w, o) => o.SerializeAsV2(w)); + } } } @@ -132,12 +138,15 @@ internal virtual void SerializeInternal(IOpenApiWriter writer, OpenApiSpecVersio writer.WriteProperty(OpenApiConstants.Description, Description); // operations - foreach (var operation in Operations) + if (Operations != null) { - writer.WriteOptionalObject( - operation.Key.GetDisplayName(), - operation.Value, - callback); + foreach (var operation in Operations) + { + writer.WriteOptionalObject( + operation.Key.GetDisplayName(), + operation.Value, + callback); + } } // servers diff --git a/src/Microsoft.OpenApi/Models/OpenApiReference.cs b/src/Microsoft.OpenApi/Models/OpenApiReference.cs index 43d307fad..d07aa2288 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiReference.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiReference.cs @@ -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; @@ -18,14 +18,14 @@ public class OpenApiReference : IOpenApiSerializable, IOpenApiDescribedElement, /// A short summary which by default SHOULD override that of the referenced component. /// If the referenced object-type does not allow a summary field, then this field has no effect. /// - public string Summary { get; set; } + public string? Summary { get; set; } /// /// A description which by default SHOULD override that of the referenced component. /// CommonMark syntax MAY be used for rich text representation. /// If the referenced object-type does not allow a description field, then this field has no effect. /// - public string Description { get; set; } + public string? Description { get; set; } /// /// External resource in the reference. @@ -33,8 +33,8 @@ public class OpenApiReference : IOpenApiSerializable, IOpenApiDescribedElement, /// 1. a absolute/relative file path, for example: ../commons/pet.json /// 2. a Url, for example: http://localhost/pet.json /// - public string ExternalResource { get; init; } - + public string? ExternalResource { get; init; } + /// /// The element type referenced. /// @@ -48,7 +48,7 @@ public class OpenApiReference : IOpenApiSerializable, IOpenApiDescribedElement, /// If ExternalResource is not present, this is the name of the component without the reference type name. /// For example, if the reference is '#/components/schemas/componentName', the Id is 'componentName'. /// - public string Id { get; init; } + public string? Id { get; init; } /// /// Gets a flag indicating whether this reference is an external reference. @@ -65,16 +65,16 @@ public class OpenApiReference : IOpenApiSerializable, IOpenApiDescribedElement, /// public bool IsFragment { get; init; } - private OpenApiDocument hostDocument; + private OpenApiDocument? hostDocument; /// /// The OpenApiDocument that is hosting the OpenApiReference instance. This is used to enable dereferencing the reference. /// - public OpenApiDocument HostDocument { get => hostDocument; init => hostDocument = value; } + public OpenApiDocument? HostDocument { get => hostDocument; init => hostDocument = value; } /// /// Gets the full reference string for v3.0. /// - public string ReferenceV3 + public string? ReferenceV3 { get { @@ -97,7 +97,7 @@ public string ReferenceV3 { return Id; } - if (Id.StartsWith("http", StringComparison.OrdinalIgnoreCase)) + if (Id is not null && Id.StartsWith("http", StringComparison.OrdinalIgnoreCase)) { return Id; } @@ -109,7 +109,7 @@ public string ReferenceV3 /// /// Gets the full reference string for V2.0 /// - public string ReferenceV2 + public string? ReferenceV2 { get { @@ -180,7 +180,7 @@ public void SerializeAsV3(IOpenApiWriter writer) /// /// Serialize /// - private void SerializeInternal(IOpenApiWriter writer, Action callback = null) + private void SerializeInternal(IOpenApiWriter writer, Action? callback = null) { Utils.CheckArgumentNull(writer); @@ -232,7 +232,7 @@ public void SerializeAsV2(IOpenApiWriter writer) writer.WriteEndObject(); } - private string GetExternalReferenceV3() + private string? GetExternalReferenceV3() { if (Id != null) { @@ -255,9 +255,9 @@ private string GetExternalReferenceV3() return ExternalResource; } - private string GetExternalReferenceV2() + private string? GetExternalReferenceV2() { - if (Id != null) + if (Id is not null && Type is not null) { return ExternalResource + "#/" + GetReferenceTypeNameAsV2((ReferenceType)Type) + "/" + Id; } @@ -265,7 +265,7 @@ private string GetExternalReferenceV2() return ExternalResource; } - private string GetReferenceTypeNameAsV2(ReferenceType type) + private static string? GetReferenceTypeNameAsV2(ReferenceType type) { return type switch { diff --git a/src/Microsoft.OpenApi/Models/OpenApiRequestBody.cs b/src/Microsoft.OpenApi/Models/OpenApiRequestBody.cs index 95f86dba3..232d96034 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiRequestBody.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiRequestBody.cs @@ -19,16 +19,16 @@ namespace Microsoft.OpenApi.Models public class OpenApiRequestBody : IOpenApiReferenceable, IOpenApiExtensible, IOpenApiRequestBody { /// - public string Description { get; set; } + public string? Description { get; set; } /// public bool Required { get; set; } /// - public IDictionary Content { get; set; } = new Dictionary(); + public IDictionary? Content { get; set; } = new Dictionary(); /// - public IDictionary Extensions { get; set; } = new Dictionary(); + public IDictionary? Extensions { get; set; } = new Dictionary(); /// /// Parameter-less constructor @@ -102,15 +102,16 @@ public IOpenApiParameter ConvertToBodyParameter(IOpenApiWriter writer) // V2 spec actually allows the body to have custom name. // To allow round-tripping we use an extension to hold the name Name = "body", - Schema = Content.Values.FirstOrDefault()?.Schema ?? new OpenApiSchema(), - Examples = Content.Values.FirstOrDefault()?.Examples, + Schema = Content?.Values.FirstOrDefault()?.Schema ?? new OpenApiSchema(), + Examples = Content?.Values.FirstOrDefault()?.Examples, Required = Required, - Extensions = Extensions.ToDictionary(static k => k.Key, static v => v.Value) // Clone extensions so we can remove the x-bodyName extensions from the output V2 model. + Extensions = Extensions?.ToDictionary(static k => k.Key, static v => v.Value) }; - if (bodyParameter.Extensions.ContainsKey(OpenApiConstants.BodyName)) + // Clone extensions so we can remove the x-bodyName extensions from the output V2 model. + if (bodyParameter.Extensions != null && bodyParameter.Extensions.TryGetValue(OpenApiConstants.BodyName, out var bodyNameExtension)) { - var bodyName = bodyParameter.Extensions[OpenApiConstants.BodyName] as OpenApiAny; - bodyParameter.Name = string.IsNullOrEmpty(bodyName?.Node.ToString()) ? "body" : bodyName?.Node.ToString(); + var bodyName = bodyNameExtension as OpenApiAny; + bodyParameter.Name = string.IsNullOrEmpty(bodyName?.Node?.ToString()) ? "body" : bodyName?.Node?.ToString(); bodyParameter.Extensions.Remove(OpenApiConstants.BodyName); } return bodyParameter; @@ -121,34 +122,41 @@ public IEnumerable ConvertToFormDataParameters(IOpenApiWriter { if (Content == null || !Content.Any()) yield break; - - foreach (var property in Content.First().Value.Schema.Properties) + var properties = Content.First().Value.Schema?.Properties; + if(properties != null) { - var paramSchema = property.Value.CreateShallowCopy(); - if ((paramSchema.Type & JsonSchemaType.String) == JsonSchemaType.String - && ("binary".Equals(paramSchema.Format, StringComparison.OrdinalIgnoreCase) - || "base64".Equals(paramSchema.Format, StringComparison.OrdinalIgnoreCase))) + foreach (var property in properties) { - var updatedSchema = paramSchema switch { - OpenApiSchema s => s, // we already have a copy - // we have a copy of a reference but don't want to mutate the source schema - // TODO might need recursive resolution of references here - OpenApiSchemaReference r => (OpenApiSchema)r.Target.CreateShallowCopy(), - _ => throw new InvalidOperationException("Unexpected schema type") + var paramSchema = property.Value.CreateShallowCopy(); + if ((paramSchema.Type & JsonSchemaType.String) == JsonSchemaType.String + && ("binary".Equals(paramSchema.Format, StringComparison.OrdinalIgnoreCase) + || "base64".Equals(paramSchema.Format, StringComparison.OrdinalIgnoreCase))) + { + var updatedSchema = paramSchema switch + { + OpenApiSchema s => s, // we already have a copy + // we have a copy of a reference but don't want to mutate the source schema + // TODO might need recursive resolution of references here + OpenApiSchemaReference r => (OpenApiSchema?)r.Target?.CreateShallowCopy(), + _ => throw new InvalidOperationException("Unexpected schema type") + }; + if (updatedSchema is not null) + { + updatedSchema.Type = "file".ToJsonSchemaType(); + updatedSchema.Format = null; + paramSchema = updatedSchema; + } + } + yield return new OpenApiFormDataParameter() + { + Description = paramSchema.Description, + Name = property.Key, + Schema = paramSchema, + Examples = Content.Values.FirstOrDefault()?.Examples, + Required = Content.First().Value.Schema?.Required?.Contains(property.Key) ?? false }; - updatedSchema.Type = "file".ToJsonSchemaType(); - updatedSchema.Format = null; - paramSchema = updatedSchema; } - yield return new OpenApiFormDataParameter() - { - Description = paramSchema.Description, - Name = property.Key, - Schema = paramSchema, - Examples = Content.Values.FirstOrDefault()?.Examples, - Required = Content.First().Value.Schema.Required?.Contains(property.Key) ?? false - }; - } + } } /// diff --git a/src/Microsoft.OpenApi/Models/OpenApiResponse.cs b/src/Microsoft.OpenApi/Models/OpenApiResponse.cs index 0ec6cbb84..6be68e55b 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiResponse.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiResponse.cs @@ -16,19 +16,19 @@ namespace Microsoft.OpenApi.Models public class OpenApiResponse : IOpenApiReferenceable, IOpenApiExtensible, IOpenApiResponse { /// - public string Description { get; set; } + public string? Description { get; set; } /// - public IDictionary Headers { get; set; } = new Dictionary(); + public IDictionary? Headers { get; set; } = new Dictionary(); /// - public IDictionary Content { get; set; } = new Dictionary(); + public IDictionary? Content { get; set; } = new Dictionary(); /// - public IDictionary Links { get; set; } = new Dictionary(); + public IDictionary? Links { get; set; } = new Dictionary(); /// - public IDictionary Extensions { get; set; } = new Dictionary(); + public IDictionary? Extensions { get; set; } = new Dictionary(); /// /// Parameterless constructor @@ -101,7 +101,11 @@ public void SerializeAsV2(IOpenApiWriter writer) // description writer.WriteRequiredProperty(OpenApiConstants.Description, Description); - var extensionsClone = new Dictionary(Extensions); + Dictionary? extensionsClone = null; + if (Extensions is not null) + { + extensionsClone = new Dictionary(Extensions); + } if (Content != null) { @@ -136,7 +140,7 @@ public void SerializeAsV2(IOpenApiWriter writer) foreach (var example in Content .Where(mediaTypePair => mediaTypePair.Value.Examples != null && mediaTypePair.Value.Examples.Any()) - .SelectMany(mediaTypePair => mediaTypePair.Value.Examples)) + .SelectMany(mediaTypePair => mediaTypePair.Value.Examples!)) { writer.WritePropertyName(example.Key); example.Value.SerializeAsV2(writer); @@ -147,12 +151,15 @@ public void SerializeAsV2(IOpenApiWriter writer) writer.WriteExtensions(mediatype.Value.Extensions, OpenApiSpecVersion.OpenApi2_0); - foreach (var key in mediatype.Value.Extensions.Keys) + if (mediatype.Value.Extensions is not null) { - // The extension will already have been serialized as part of the call above, - // so remove it from the cloned collection so we don't write it again. - extensionsClone.Remove(key); - } + foreach (var key in mediatype.Value.Extensions.Keys) + { + // The extension will already have been serialized as part of the call above, + // so remove it from the cloned collection so we don't write it again. + extensionsClone?.Remove(key); + } + } } } diff --git a/src/Microsoft.OpenApi/Models/OpenApiSchema.cs b/src/Microsoft.OpenApi/Models/OpenApiSchema.cs index cfed33744..5361fc7f0 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiSchema.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiSchema.cs @@ -21,28 +21,28 @@ namespace Microsoft.OpenApi.Models public class OpenApiSchema : IOpenApiReferenceable, IOpenApiExtensible, IOpenApiSchema { /// - public string Title { get; set; } + public string? Title { get; set; } /// - public string Schema { get; set; } + public string? Schema { get; set; } /// - public string Id { get; set; } + public string? Id { get; set; } /// - public string Comment { get; set; } + public string? Comment { get; set; } /// - public IDictionary Vocabulary { get; set; } + public IDictionary? Vocabulary { get; set; } /// - public string DynamicRef { get; set; } + public string? DynamicRef { get; set; } /// - public string DynamicAnchor { get; set; } + public string? DynamicAnchor { get; set; } /// - public IDictionary Definitions { get; set; } + public IDictionary? Definitions { get; set; } /// public decimal? V31ExclusiveMaximum { get; set; } @@ -57,13 +57,13 @@ public class OpenApiSchema : IOpenApiReferenceable, IOpenApiExtensible, IOpenApi public JsonSchemaType? Type { get; set; } /// - public string Const { get; set; } + public string? Const { get; set; } /// - public string Format { get; set; } + public string? Format { get; set; } /// - public string Description { get; set; } + public string? Description { get; set; } /// public decimal? Maximum { get; set; } @@ -84,13 +84,13 @@ public class OpenApiSchema : IOpenApiReferenceable, IOpenApiExtensible, IOpenApi public int? MinLength { get; set; } /// - public string Pattern { get; set; } + public string? Pattern { get; set; } /// public decimal? MultipleOf { get; set; } /// - public JsonNode Default { get; set; } + public JsonNode? Default { get; set; } /// public bool ReadOnly { get; set; } @@ -99,22 +99,22 @@ public class OpenApiSchema : IOpenApiReferenceable, IOpenApiExtensible, IOpenApi public bool WriteOnly { get; set; } /// - public IList AllOf { get; set; } = []; + public IList? AllOf { get; set; } = []; /// - public IList OneOf { get; set; } = []; + public IList? OneOf { get; set; } = []; /// - public IList AnyOf { get; set; } = []; + public IList? AnyOf { get; set; } = []; /// - public IOpenApiSchema Not { get; set; } + public IOpenApiSchema? Not { get; set; } /// - public ISet Required { get; set; } = new HashSet(); + public ISet? Required { get; set; } = new HashSet(); /// - public IOpenApiSchema Items { get; set; } + public IOpenApiSchema? Items { get; set; } /// public int? MaxItems { get; set; } @@ -126,10 +126,10 @@ public class OpenApiSchema : IOpenApiReferenceable, IOpenApiExtensible, IOpenApi public bool? UniqueItems { get; set; } /// - public IDictionary Properties { get; set; } = new Dictionary(StringComparer.Ordinal); + public IDictionary? Properties { get; set; } = new Dictionary(StringComparer.Ordinal); /// - public IDictionary PatternProperties { get; set; } = new Dictionary(StringComparer.Ordinal); + public IDictionary? PatternProperties { get; set; } = new Dictionary(StringComparer.Ordinal); /// public int? MaxProperties { get; set; } @@ -141,40 +141,40 @@ public class OpenApiSchema : IOpenApiReferenceable, IOpenApiExtensible, IOpenApi public bool AdditionalPropertiesAllowed { get; set; } = true; /// - public IOpenApiSchema AdditionalProperties { get; set; } + public IOpenApiSchema? AdditionalProperties { get; set; } /// - public OpenApiDiscriminator Discriminator { get; set; } + public OpenApiDiscriminator? Discriminator { get; set; } /// - public JsonNode Example { get; set; } + public JsonNode? Example { get; set; } /// - public IList Examples { get; set; } + public IList? Examples { get; set; } /// - public IList Enum { get; set; } = new List(); + public IList? Enum { get; set; } = new List(); /// public bool UnevaluatedProperties { get; set;} /// - public OpenApiExternalDocs ExternalDocs { get; set; } + public OpenApiExternalDocs? ExternalDocs { get; set; } /// public bool Deprecated { get; set; } /// - public OpenApiXml Xml { get; set; } + public OpenApiXml? Xml { get; set; } /// - public IDictionary Extensions { get; set; } = new Dictionary(); + public IDictionary? Extensions { get; set; } = new Dictionary(); /// - public IDictionary UnrecognizedKeywords { get; set; } = new Dictionary(); + public IDictionary? UnrecognizedKeywords { get; set; } = new Dictionary(); /// - public IDictionary Annotations { get; set; } + public IDictionary? Annotations { get; set; } /// /// Parameterless constructor @@ -379,7 +379,7 @@ private void SerializeInternal(IOpenApiWriter writer, OpenApiSpecVersion version writer.WriteExtensions(Extensions, version); // Unrecognized keywords - if (UnrecognizedKeywords.Any()) + if (UnrecognizedKeywords is not null && UnrecognizedKeywords.Any()) { writer.WriteOptionalMap(OpenApiConstants.UnrecognizedKeywords, UnrecognizedKeywords, (w,s) => w.WriteAny(s)); } @@ -491,8 +491,8 @@ private void WriteFormatProperty(IOpenApiWriter writer) /// The property name that will be serialized. private void SerializeAsV2( IOpenApiWriter writer, - ISet parentRequiredProperties, - string propertyName) + ISet? parentRequiredProperties, + string? propertyName) { parentRequiredProperties ??= new HashSet(); @@ -606,7 +606,7 @@ private void SerializeAsV2( // readOnly // In V2 schema if a property is part of required properties of parent schema, // it cannot be marked as readonly. - if (!parentRequiredProperties.Contains(propertyName)) + if (propertyName is not null && !parentRequiredProperties.Contains(propertyName)) { writer.WriteProperty(name: OpenApiConstants.ReadOnly, value: ReadOnly, defaultValue: false); } diff --git a/src/Microsoft.OpenApi/Models/OpenApiSecurityRequirement.cs b/src/Microsoft.OpenApi/Models/OpenApiSecurityRequirement.cs index 193d648df..34df6ca79 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiSecurityRequirement.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiSecurityRequirement.cs @@ -37,7 +37,7 @@ public OpenApiSecurityRequirement() /// public void SerializeAsV31(IOpenApiWriter writer) { - SerializeInternal(writer, (w, s) => w.WritePropertyName(s.Reference.ReferenceV3)); + SerializeInternal(writer, (w, s) => w.WritePropertyName(s.Reference?.ReferenceV3)); } /// @@ -45,7 +45,7 @@ public void SerializeAsV31(IOpenApiWriter writer) /// public void SerializeAsV3(IOpenApiWriter writer) { - SerializeInternal(writer, (w, s) => w.WritePropertyName(s.Reference.ReferenceV3)); + SerializeInternal(writer, (w, s) => w.WritePropertyName(s.Reference?.ReferenceV3)); } /// @@ -98,7 +98,7 @@ private sealed class OpenApiSecuritySchemeReferenceEqualityComparer : IEqualityC /// /// Determines whether the specified objects are equal. /// - public bool Equals(OpenApiSecuritySchemeReference x, OpenApiSecuritySchemeReference y) + public bool Equals(OpenApiSecuritySchemeReference? x, OpenApiSecuritySchemeReference? y) { if (x == null && y == null) { @@ -122,7 +122,8 @@ public int GetHashCode(OpenApiSecuritySchemeReference obj) { return 0; } - return string.IsNullOrEmpty(obj?.Reference?.Id) ? 0 : obj.Reference.Id.GetHashCode(); + var id = obj.Reference?.Id; + return string.IsNullOrEmpty(id) ? 0 : id!.GetHashCode(); } } } diff --git a/src/Microsoft.OpenApi/Models/OpenApiSecurityScheme.cs b/src/Microsoft.OpenApi/Models/OpenApiSecurityScheme.cs index dddbbffec..7d254a3d2 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiSecurityScheme.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiSecurityScheme.cs @@ -19,28 +19,28 @@ public class OpenApiSecurityScheme : IOpenApiExtensible, IOpenApiReferenceable, public SecuritySchemeType? Type { get; set; } /// - public string Description { get; set; } + public string? Description { get; set; } /// - public string Name { get; set; } + public string? Name { get; set; } /// public ParameterLocation? In { get; set; } /// - public string Scheme { get; set; } + public string? Scheme { get; set; } /// - public string BearerFormat { get; set; } + public string? BearerFormat { get; set; } /// - public OpenApiOAuthFlows Flows { get; set; } + public OpenApiOAuthFlows? Flows { get; set; } /// - public Uri OpenIdConnectUrl { get; set; } + public Uri? OpenIdConnectUrl { get; set; } /// - public IDictionary Extensions { get; set; } = new Dictionary(); + public IDictionary? Extensions { get; set; } = new Dictionary(); /// /// Parameterless constructor @@ -88,7 +88,7 @@ private void SerializeInternal(IOpenApiWriter writer, OpenApiSpecVersion version writer.WriteStartObject(); // type - writer.WriteProperty(OpenApiConstants.Type, Type.GetDisplayName()); + writer.WriteProperty(OpenApiConstants.Type, Type?.GetDisplayName()); // description writer.WriteProperty(OpenApiConstants.Description, Description); @@ -100,7 +100,7 @@ private void SerializeInternal(IOpenApiWriter writer, OpenApiSpecVersion version // name // in writer.WriteProperty(OpenApiConstants.Name, Name); - writer.WriteProperty(OpenApiConstants.In, In.GetDisplayName()); + writer.WriteProperty(OpenApiConstants.In, In?.GetDisplayName()); break; case SecuritySchemeType.Http: // These properties apply to http type only. @@ -175,7 +175,7 @@ public void SerializeAsV2(IOpenApiWriter writer) // in writer.WriteProperty(OpenApiConstants.Type, Type.GetDisplayName()); writer.WriteProperty(OpenApiConstants.Name, Name); - writer.WriteProperty(OpenApiConstants.In, In.GetDisplayName()); + writer.WriteProperty(OpenApiConstants.In, In?.GetDisplayName()); break; } @@ -192,7 +192,7 @@ public void SerializeAsV2(IOpenApiWriter writer) /// Arbitrarily chooses one object from the /// to populate in V2 security scheme. /// - private static void WriteOAuthFlowForV2(IOpenApiWriter writer, OpenApiOAuthFlows flows) + private static void WriteOAuthFlowForV2(IOpenApiWriter writer, OpenApiOAuthFlows? flows) { if (flows != null) { diff --git a/src/Microsoft.OpenApi/Models/OpenApiServer.cs b/src/Microsoft.OpenApi/Models/OpenApiServer.cs index b580f7fbb..a15c6068e 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiServer.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiServer.cs @@ -16,25 +16,25 @@ public class OpenApiServer : IOpenApiSerializable, IOpenApiExtensible /// /// An optional string describing the host designated by the URL. CommonMark syntax MAY be used for rich text representation. /// - public string Description { get; set; } + public string? Description { get; set; } /// /// REQUIRED. A URL to the target host. This URL supports Server Variables and MAY be relative, /// to indicate that the host location is relative to the location where the OpenAPI document is being served. /// Variable substitutions will be made when a variable is named in {brackets}. /// - public string Url { get; set; } + public string? Url { get; set; } /// /// A map between a variable name and its value. The value is used for substitution in the server's URL template. /// - public IDictionary Variables { get; set; } = + public IDictionary? Variables { get; set; } = new Dictionary(); /// /// This object MAY be extended with Specification Extensions. /// - public IDictionary Extensions { get; set; } = new Dictionary(); + public IDictionary? Extensions { get; set; } = new Dictionary(); /// /// Parameterless constructor @@ -74,7 +74,7 @@ public void SerializeAsV3(IOpenApiWriter writer) private void SerializeInternal(IOpenApiWriter writer, OpenApiSpecVersion version, Action callback) { - Utils.CheckArgumentNull(writer);; + Utils.CheckArgumentNull(writer); writer.WriteStartObject(); diff --git a/src/Microsoft.OpenApi/Models/OpenApiServerVariable.cs b/src/Microsoft.OpenApi/Models/OpenApiServerVariable.cs index 615b8dc37..c68af8432 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiServerVariable.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiServerVariable.cs @@ -15,13 +15,13 @@ public class OpenApiServerVariable : IOpenApiSerializable, IOpenApiExtensible /// /// An optional description for the server variable. CommonMark syntax MAY be used for rich text representation. /// - public string Description { get; set; } + public string? Description { get; set; } /// /// REQUIRED. The default value to use for substitution, and to send, if an alternate value is not supplied. /// Unlike the Schema Object's default, this value MUST be provided by the consumer. /// - public string Default { get; set; } + public string? Default { get; set; } /// /// An enumeration of string values to be used if the substitution options are from a limited set. @@ -29,12 +29,12 @@ public class OpenApiServerVariable : IOpenApiSerializable, IOpenApiExtensible /// /// If the server variable in the OpenAPI document has no enum member, this property will be null. /// - public List Enum { get; set; } + public List? Enum { get; set; } /// /// This object MAY be extended with Specification Extensions. /// - public IDictionary Extensions { get; set; } = new Dictionary(); + public IDictionary? Extensions { get; set; } = new Dictionary(); /// /// Parameterless constructor @@ -48,8 +48,8 @@ public OpenApiServerVariable(OpenApiServerVariable serverVariable) { Description = serverVariable?.Description; Default = serverVariable?.Default; - Enum = serverVariable?.Enum != null ? new(serverVariable?.Enum) : serverVariable?.Enum; - Extensions = serverVariable?.Extensions != null ? new Dictionary(serverVariable?.Extensions) : serverVariable?.Extensions; + Enum = serverVariable?.Enum != null ? new(serverVariable.Enum) : serverVariable?.Enum; + Extensions = serverVariable?.Extensions != null ? new Dictionary(serverVariable.Extensions) : serverVariable?.Extensions; } /// @@ -73,7 +73,7 @@ public void SerializeAsV3(IOpenApiWriter writer) /// private void SerializeInternal(IOpenApiWriter writer, OpenApiSpecVersion version) { - Utils.CheckArgumentNull(writer);; + Utils.CheckArgumentNull(writer); writer.WriteStartObject(); diff --git a/src/Microsoft.OpenApi/Models/OpenApiTag.cs b/src/Microsoft.OpenApi/Models/OpenApiTag.cs index 91e3aac68..48ac2960c 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiTag.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiTag.cs @@ -15,16 +15,16 @@ namespace Microsoft.OpenApi.Models public class OpenApiTag : IOpenApiExtensible, IOpenApiReferenceable, IOpenApiTag, IOpenApiDescribedElement { /// - public string Name { get; set; } + public string? Name { get; set; } /// - public string Description { get; set; } + public string? Description { get; set; } /// - public OpenApiExternalDocs ExternalDocs { get; set; } + public OpenApiExternalDocs? ExternalDocs { get; set; } /// - public IDictionary Extensions { get; set; } = new Dictionary(); + public IDictionary? Extensions { get; set; } = new Dictionary(); /// /// Parameterless constructor diff --git a/src/Microsoft.OpenApi/Models/OpenApiXml.cs b/src/Microsoft.OpenApi/Models/OpenApiXml.cs index d0ee6a00b..c0503e14d 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiXml.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiXml.cs @@ -16,17 +16,17 @@ public class OpenApiXml : IOpenApiSerializable, IOpenApiExtensible /// /// Replaces the name of the element/attribute used for the described schema property. /// - public string Name { get; set; } + public string? Name { get; set; } /// /// The URI of the namespace definition. Value MUST be in the form of an absolute URI. /// - public Uri Namespace { get; set; } + public Uri? Namespace { get; set; } /// /// The prefix to be used for the name /// - public string Prefix { get; set; } + public string? Prefix { get; set; } /// /// Declares whether the property definition translates to an attribute instead of an element. @@ -43,7 +43,7 @@ public class OpenApiXml : IOpenApiSerializable, IOpenApiExtensible /// /// Specification Extensions. /// - public IDictionary Extensions { get; set; } = new Dictionary(); + public IDictionary? Extensions { get; set; } = new Dictionary(); /// /// Parameterless constructor @@ -89,7 +89,7 @@ public void SerializeAsV2(IOpenApiWriter writer) private void Write(IOpenApiWriter writer, OpenApiSpecVersion specVersion) { - Utils.CheckArgumentNull(writer);; + Utils.CheckArgumentNull(writer); writer.WriteStartObject(); diff --git a/src/Microsoft.OpenApi/Models/References/BaseOpenApiReferenceHolder.cs b/src/Microsoft.OpenApi/Models/References/BaseOpenApiReferenceHolder.cs index e01545c61..cc11a510f 100644 --- a/src/Microsoft.OpenApi/Models/References/BaseOpenApiReferenceHolder.cs +++ b/src/Microsoft.OpenApi/Models/References/BaseOpenApiReferenceHolder.cs @@ -1,4 +1,4 @@ -using System; +using System; using Microsoft.OpenApi.Interfaces; using Microsoft.OpenApi.Writers; @@ -11,11 +11,11 @@ namespace Microsoft.OpenApi.Models.References; public abstract class BaseOpenApiReferenceHolder : IOpenApiReferenceHolder where T : class, IOpenApiReferenceable, V where V : IOpenApiSerializable { /// - public virtual T Target + public virtual T? Target { get { - return Reference.HostDocument?.ResolveReferenceTo(Reference); + return Reference?.HostDocument?.ResolveReferenceTo(Reference); } } /// @@ -40,7 +40,7 @@ protected BaseOpenApiReferenceHolder(BaseOpenApiReferenceHolder source) /// 1. a absolute/relative file path, for example: ../commons/pet.json /// 2. a Url, for example: http://localhost/pet.json /// - protected BaseOpenApiReferenceHolder(string referenceId, OpenApiDocument hostDocument, ReferenceType referenceType, string externalResource) + protected BaseOpenApiReferenceHolder(string? referenceId, OpenApiDocument? hostDocument, ReferenceType referenceType, string? externalResource) { Utils.CheckArgumentNullOrEmpty(referenceId); // we're not checking for null hostDocument as it's optional and can be set via additional methods by a walker @@ -57,45 +57,45 @@ protected BaseOpenApiReferenceHolder(string referenceId, OpenApiDocument hostDoc /// public bool UnresolvedReference { get => Reference is null || Target is null; } /// - public OpenApiReference Reference { get; init; } + public OpenApiReference? Reference { get; init; } /// - public abstract V CopyReferenceAsTargetElementWithOverrides(V source); + public abstract V? CopyReferenceAsTargetElementWithOverrides(V? source); /// public virtual void SerializeAsV3(IOpenApiWriter writer) { - if (!writer.GetSettings().ShouldInlineReference(Reference)) + if (Reference is not null && !writer.GetSettings().ShouldInlineReference(Reference)) { Reference.SerializeAsV3(writer); } else { - SerializeInternal(writer, (writer, element) => element.SerializeAsV3(writer)); + SerializeInternal(writer, (writer, element) => element?.SerializeAsV3(writer)); } } /// public virtual void SerializeAsV31(IOpenApiWriter writer) { - if (!writer.GetSettings().ShouldInlineReference(Reference)) + if (Reference is not null && !writer.GetSettings().ShouldInlineReference(Reference)) { Reference.SerializeAsV31(writer); } else { - SerializeInternal(writer, (writer, element) => CopyReferenceAsTargetElementWithOverrides(element).SerializeAsV31(writer)); + SerializeInternal(writer, (writer, element) => CopyReferenceAsTargetElementWithOverrides(element)?.SerializeAsV31(writer)); } } /// public virtual void SerializeAsV2(IOpenApiWriter writer) { - if (!writer.GetSettings().ShouldInlineReference(Reference)) + if (Reference is not null && !writer.GetSettings().ShouldInlineReference(Reference)) { Reference.SerializeAsV2(writer); } else { - SerializeInternal(writer, (writer, element) => element.SerializeAsV2(writer)); + SerializeInternal(writer, (writer, element) => element?.SerializeAsV2(writer)); } } @@ -106,7 +106,7 @@ public virtual void SerializeAsV2(IOpenApiWriter writer) /// The OpenApiWriter. /// The action to serialize the target object. private protected void SerializeInternal(IOpenApiWriter writer, - Action action) + Action action) { Utils.CheckArgumentNull(writer); action(writer, Target); diff --git a/src/Microsoft.OpenApi/Models/References/OpenApiCallbackReference.cs b/src/Microsoft.OpenApi/Models/References/OpenApiCallbackReference.cs index 4c30328d4..76fefbcd8 100644 --- a/src/Microsoft.OpenApi/Models/References/OpenApiCallbackReference.cs +++ b/src/Microsoft.OpenApi/Models/References/OpenApiCallbackReference.cs @@ -25,7 +25,7 @@ public class OpenApiCallbackReference : BaseOpenApiReferenceHolder - public OpenApiCallbackReference(string referenceId, OpenApiDocument hostDocument = null, string externalResource = null):base(referenceId, hostDocument, ReferenceType.Callback, externalResource) + public OpenApiCallbackReference(string referenceId, OpenApiDocument? hostDocument = null, string? externalResource = null):base(referenceId, hostDocument, ReferenceType.Callback, externalResource) { } /// @@ -38,13 +38,13 @@ private OpenApiCallbackReference(OpenApiCallbackReference callback):base(callbac } /// - public Dictionary PathItems { get => Target?.PathItems; } + public Dictionary? PathItems { get => Target?.PathItems; } /// - public IDictionary Extensions { get => Target?.Extensions; } + public IDictionary? Extensions { get => Target?.Extensions; } /// - public override IOpenApiCallback CopyReferenceAsTargetElementWithOverrides(IOpenApiCallback source) + public override IOpenApiCallback? CopyReferenceAsTargetElementWithOverrides(IOpenApiCallback? source) { return source is OpenApiCallback ? new OpenApiCallback(this) : source; } @@ -53,7 +53,7 @@ public override IOpenApiCallback CopyReferenceAsTargetElementWithOverrides(IOpen public override void SerializeAsV2(IOpenApiWriter writer) { // examples components are not supported in OAS 2.0 - Reference.SerializeAsV2(writer); + Reference?.SerializeAsV2(writer); } /// diff --git a/src/Microsoft.OpenApi/Models/References/OpenApiExampleReference.cs b/src/Microsoft.OpenApi/Models/References/OpenApiExampleReference.cs index edfe27b61..ca8554ee9 100644 --- a/src/Microsoft.OpenApi/Models/References/OpenApiExampleReference.cs +++ b/src/Microsoft.OpenApi/Models/References/OpenApiExampleReference.cs @@ -25,7 +25,7 @@ public class OpenApiExampleReference : BaseOpenApiReferenceHolder - public OpenApiExampleReference(string referenceId, OpenApiDocument hostDocument = null, string externalResource = null):base(referenceId, hostDocument, ReferenceType.Example, externalResource) + public OpenApiExampleReference(string referenceId, OpenApiDocument? hostDocument = null, string? externalResource = null):base(referenceId, hostDocument, ReferenceType.Example, externalResource) { } /// @@ -37,9 +37,9 @@ private OpenApiExampleReference(OpenApiExampleReference example):base(example) } /// - public string Description + public string? Description { - get => string.IsNullOrEmpty(Reference?.Description) ? Target?.Description : Reference.Description; + get => string.IsNullOrEmpty(Reference?.Description) ? Target?.Description : Reference?.Description; set { if (Reference is not null) @@ -50,9 +50,9 @@ public string Description } /// - public string Summary + public string? Summary { - get => string.IsNullOrEmpty(Reference?.Summary) ? Target?.Summary : Reference.Summary; + get => string.IsNullOrEmpty(Reference?.Summary) ? Target?.Summary : Reference?.Summary; set { if (Reference is not null) @@ -63,16 +63,16 @@ public string Summary } /// - public IDictionary Extensions { get => Target?.Extensions; } + public IDictionary? Extensions { get => Target?.Extensions; } /// - public string ExternalValue { get => Target?.ExternalValue; } + public string? ExternalValue { get => Target?.ExternalValue; } /// - public JsonNode Value { get => Target?.Value; } + public JsonNode? Value { get => Target?.Value; } /// - public override IOpenApiExample CopyReferenceAsTargetElementWithOverrides(IOpenApiExample source) + public override IOpenApiExample? CopyReferenceAsTargetElementWithOverrides(IOpenApiExample? source) { return source is OpenApiExample ? new OpenApiExample(this) : source; } @@ -81,7 +81,7 @@ public override IOpenApiExample CopyReferenceAsTargetElementWithOverrides(IOpenA public override void SerializeAsV2(IOpenApiWriter writer) { // examples components are not supported in OAS 2.0 - Reference.SerializeAsV2(writer); + Reference?.SerializeAsV2(writer); } /// diff --git a/src/Microsoft.OpenApi/Models/References/OpenApiHeaderReference.cs b/src/Microsoft.OpenApi/Models/References/OpenApiHeaderReference.cs index 719cdce3a..731efc8f4 100644 --- a/src/Microsoft.OpenApi/Models/References/OpenApiHeaderReference.cs +++ b/src/Microsoft.OpenApi/Models/References/OpenApiHeaderReference.cs @@ -24,7 +24,7 @@ public class OpenApiHeaderReference : BaseOpenApiReferenceHolder - public OpenApiHeaderReference(string referenceId, OpenApiDocument hostDocument = null, string externalResource = null):base(referenceId, hostDocument, ReferenceType.Header, externalResource) + public OpenApiHeaderReference(string referenceId, OpenApiDocument? hostDocument = null, string? externalResource = null):base(referenceId, hostDocument, ReferenceType.Header, externalResource) { } @@ -37,9 +37,9 @@ private OpenApiHeaderReference(OpenApiHeaderReference header):base(header) } /// - public string Description + public string? Description { - get => string.IsNullOrEmpty(Reference?.Description) ? Target?.Description : Reference.Description; + get => string.IsNullOrEmpty(Reference?.Description) ? Target?.Description : Reference?.Description; set { if (Reference is not null) @@ -59,7 +59,7 @@ public string Description public bool AllowEmptyValue { get => Target?.AllowEmptyValue ?? default; } /// - public IOpenApiSchema Schema { get => Target?.Schema; } + public IOpenApiSchema? Schema { get => Target?.Schema; } /// public ParameterStyle? Style { get => Target?.Style; } @@ -71,19 +71,19 @@ public string Description public bool AllowReserved { get => Target?.AllowReserved ?? default; } /// - public JsonNode Example { get => Target?.Example; } + public JsonNode? Example { get => Target?.Example; } /// - public IDictionary Examples { get => Target?.Examples; } + public IDictionary? Examples { get => Target?.Examples; } /// - public IDictionary Content { get => Target?.Content; } + public IDictionary? Content { get => Target?.Content; } /// - public IDictionary Extensions { get => Target?.Extensions; } + public IDictionary? Extensions { get => Target?.Extensions; } /// - public override IOpenApiHeader CopyReferenceAsTargetElementWithOverrides(IOpenApiHeader source) + public override IOpenApiHeader? CopyReferenceAsTargetElementWithOverrides(IOpenApiHeader? source) { return source is OpenApiHeader ? new OpenApiHeader(this) : source; } diff --git a/src/Microsoft.OpenApi/Models/References/OpenApiLinkReference.cs b/src/Microsoft.OpenApi/Models/References/OpenApiLinkReference.cs index f91b5711b..5cd7295ba 100644 --- a/src/Microsoft.OpenApi/Models/References/OpenApiLinkReference.cs +++ b/src/Microsoft.OpenApi/Models/References/OpenApiLinkReference.cs @@ -24,7 +24,7 @@ public class OpenApiLinkReference : BaseOpenApiReferenceHolder - public OpenApiLinkReference(string referenceId, OpenApiDocument hostDocument = null, string externalResource = null):base(referenceId, hostDocument, ReferenceType.Link, externalResource) + public OpenApiLinkReference(string referenceId, OpenApiDocument? hostDocument = null, string? externalResource = null):base(referenceId, hostDocument, ReferenceType.Link, externalResource) { } /// @@ -36,9 +36,9 @@ private OpenApiLinkReference(OpenApiLinkReference reference):base(reference) } /// - public string Description + public string? Description { - get => string.IsNullOrEmpty(Reference?.Description) ? Target?.Description : Reference.Description; + get => string.IsNullOrEmpty(Reference?.Description) ? Target?.Description : Reference?.Description; set { if (Reference is not null) @@ -49,22 +49,22 @@ public string Description } /// - public string OperationRef { get => Target?.OperationRef; } + public string? OperationRef { get => Target?.OperationRef; } /// - public string OperationId { get => Target?.OperationId; } + public string? OperationId { get => Target?.OperationId; } /// - public OpenApiServer Server { get => Target?.Server; } + public OpenApiServer? Server { get => Target?.Server; } /// - public IDictionary Parameters { get => Target?.Parameters; } + public IDictionary? Parameters { get => Target?.Parameters; } /// - public RuntimeExpressionAnyWrapper RequestBody { get => Target?.RequestBody; } + public RuntimeExpressionAnyWrapper? RequestBody { get => Target?.RequestBody; } /// - public IDictionary Extensions { get => Target?.Extensions; } + public IDictionary? Extensions { get => Target?.Extensions; } /// public override void SerializeAsV2(IOpenApiWriter writer) @@ -73,7 +73,7 @@ public override void SerializeAsV2(IOpenApiWriter writer) } /// - public override IOpenApiLink CopyReferenceAsTargetElementWithOverrides(IOpenApiLink source) + public override IOpenApiLink? CopyReferenceAsTargetElementWithOverrides(IOpenApiLink? source) { return source is OpenApiLink ? new OpenApiLink(this) : source; } diff --git a/src/Microsoft.OpenApi/Models/References/OpenApiParameterReference.cs b/src/Microsoft.OpenApi/Models/References/OpenApiParameterReference.cs index d337b841e..bb7094a1f 100644 --- a/src/Microsoft.OpenApi/Models/References/OpenApiParameterReference.cs +++ b/src/Microsoft.OpenApi/Models/References/OpenApiParameterReference.cs @@ -23,7 +23,7 @@ public class OpenApiParameterReference : BaseOpenApiReferenceHolder - public OpenApiParameterReference(string referenceId, OpenApiDocument hostDocument = null, string externalResource = null):base(referenceId, hostDocument, ReferenceType.Parameter, externalResource) + public OpenApiParameterReference(string? referenceId, OpenApiDocument? hostDocument = null, string? externalResource = null):base(referenceId, hostDocument, ReferenceType.Parameter, externalResource) { } @@ -36,12 +36,12 @@ private OpenApiParameterReference(OpenApiParameterReference parameter):base(para } /// - public string Name { get => Target?.Name; } + public string? Name { get => Target?.Name; } /// - public string Description + public string? Description { - get => string.IsNullOrEmpty(Reference?.Description) ? Target?.Description : Reference.Description; + get => string.IsNullOrEmpty(Reference?.Description) ? Target?.Description : Reference?.Description; set { if (Reference is not null) @@ -64,13 +64,13 @@ public string Description public bool AllowReserved { get => Target?.AllowReserved ?? default; } /// - public IOpenApiSchema Schema { get => Target?.Schema; } + public IOpenApiSchema? Schema { get => Target?.Schema; } /// - public IDictionary Examples { get => Target?.Examples; } + public IDictionary? Examples { get => Target?.Examples; } /// - public JsonNode Example { get => Target?.Example; } + public JsonNode? Example { get => Target?.Example; } /// public ParameterLocation? In { get => Target?.In; } @@ -82,13 +82,13 @@ public string Description public bool Explode { get => Target?.Explode ?? default; } /// - public IDictionary Content { get => Target?.Content; } + public IDictionary? Content { get => Target?.Content; } /// - public IDictionary Extensions { get => Target?.Extensions; } + public IDictionary? Extensions { get => Target?.Extensions; } /// - public override IOpenApiParameter CopyReferenceAsTargetElementWithOverrides(IOpenApiParameter source) + public override IOpenApiParameter? CopyReferenceAsTargetElementWithOverrides(IOpenApiParameter? source) { return source is OpenApiParameter ? new OpenApiParameter(this) : source; } diff --git a/src/Microsoft.OpenApi/Models/References/OpenApiPathItemReference.cs b/src/Microsoft.OpenApi/Models/References/OpenApiPathItemReference.cs index 038e1cb13..927f5c063 100644 --- a/src/Microsoft.OpenApi/Models/References/OpenApiPathItemReference.cs +++ b/src/Microsoft.OpenApi/Models/References/OpenApiPathItemReference.cs @@ -24,7 +24,7 @@ public class OpenApiPathItemReference : BaseOpenApiReferenceHolder - public OpenApiPathItemReference(string referenceId, OpenApiDocument hostDocument = null, string externalResource = null): base(referenceId, hostDocument, ReferenceType.PathItem, externalResource) + public OpenApiPathItemReference(string referenceId, OpenApiDocument? hostDocument = null, string? externalResource = null): base(referenceId, hostDocument, ReferenceType.PathItem, externalResource) { } @@ -38,9 +38,9 @@ private OpenApiPathItemReference(OpenApiPathItemReference pathItem):base(pathIte } /// - public string Summary + public string? Summary { - get => string.IsNullOrEmpty(Reference?.Summary) ? Target?.Summary : Reference.Summary; + get => string.IsNullOrEmpty(Reference?.Summary) ? Target?.Summary : Reference?.Summary; set { if (Reference is not null) @@ -51,9 +51,9 @@ public string Summary } /// - public string Description + public string? Description { - get => string.IsNullOrEmpty(Reference?.Description) ? Target?.Description : Reference.Description; + get => string.IsNullOrEmpty(Reference?.Description) ? Target?.Description : Reference?.Description; set { if (Reference is not null) @@ -64,19 +64,19 @@ public string Description } /// - public IDictionary Operations { get => Target?.Operations; } + public IDictionary? Operations { get => Target?.Operations; } /// - public IList Servers { get => Target?.Servers; } + public IList? Servers { get => Target?.Servers; } /// - public IList Parameters { get => Target?.Parameters; } + public IList? Parameters { get => Target?.Parameters; } /// - public IDictionary Extensions { get => Target?.Extensions; } + public IDictionary? Extensions { get => Target?.Extensions; } /// - public override IOpenApiPathItem CopyReferenceAsTargetElementWithOverrides(IOpenApiPathItem source) + public override IOpenApiPathItem? CopyReferenceAsTargetElementWithOverrides(IOpenApiPathItem? source) { return source is OpenApiPathItem ? new OpenApiPathItem(this) : source; } @@ -90,7 +90,7 @@ public IOpenApiPathItem CreateShallowCopy() /// public override void SerializeAsV2(IOpenApiWriter writer) { - Reference.SerializeAsV2(writer); + Reference?.SerializeAsV2(writer); } } } diff --git a/src/Microsoft.OpenApi/Models/References/OpenApiRequestBodyReference.cs b/src/Microsoft.OpenApi/Models/References/OpenApiRequestBodyReference.cs index 966d3aad1..8e292f236 100644 --- a/src/Microsoft.OpenApi/Models/References/OpenApiRequestBodyReference.cs +++ b/src/Microsoft.OpenApi/Models/References/OpenApiRequestBodyReference.cs @@ -25,7 +25,7 @@ public class OpenApiRequestBodyReference : BaseOpenApiReferenceHolder - public OpenApiRequestBodyReference(string referenceId, OpenApiDocument hostDocument = null, string externalResource = null):base(referenceId, hostDocument, ReferenceType.RequestBody, externalResource) + public OpenApiRequestBodyReference(string referenceId, OpenApiDocument? hostDocument = null, string? externalResource = null):base(referenceId, hostDocument, ReferenceType.RequestBody, externalResource) { } /// @@ -38,9 +38,9 @@ private OpenApiRequestBodyReference(OpenApiRequestBodyReference openApiRequestBo } /// - public string Description + public string? Description { - get => string.IsNullOrEmpty(Reference?.Description) ? Target?.Description : Reference.Description; + get => string.IsNullOrEmpty(Reference?.Description) ? Target?.Description : Reference?.Description; set { if (Reference is not null) @@ -51,16 +51,16 @@ public string Description } /// - public IDictionary Content { get => Target?.Content; } + public IDictionary? Content { get => Target?.Content; } /// public bool Required { get => Target?.Required ?? false; } /// - public IDictionary Extensions { get => Target?.Extensions; } + public IDictionary? Extensions { get => Target?.Extensions; } /// - public override IOpenApiRequestBody CopyReferenceAsTargetElementWithOverrides(IOpenApiRequestBody source) + public override IOpenApiRequestBody? CopyReferenceAsTargetElementWithOverrides(IOpenApiRequestBody? source) { return source is OpenApiRequestBody ? new OpenApiRequestBody(this) : source; } @@ -70,29 +70,34 @@ public override void SerializeAsV2(IOpenApiWriter writer) // doesn't exist in v2 } /// - public IOpenApiParameter ConvertToBodyParameter(IOpenApiWriter writer) + public IOpenApiParameter? ConvertToBodyParameter(IOpenApiWriter writer) { - if (writer.GetSettings().ShouldInlineReference(Reference)) + if (Reference is not null && writer.GetSettings().ShouldInlineReference(Reference)) { - return Target.ConvertToBodyParameter(writer); + return Target?.ConvertToBodyParameter(writer); } else { - return new OpenApiParameterReference(Reference.Id, Reference.HostDocument); + var id = Reference?.Id; + if (id is not null) + { + return new OpenApiParameterReference(id, Reference?.HostDocument); + } } + return null; } /// - public IEnumerable ConvertToFormDataParameters(IOpenApiWriter writer) + public IEnumerable? ConvertToFormDataParameters(IOpenApiWriter writer) { - if (writer.GetSettings().ShouldInlineReference(Reference)) + if (Reference is not null && writer.GetSettings().ShouldInlineReference(Reference)) { - return Target.ConvertToFormDataParameters(writer); + return Target?.ConvertToFormDataParameters(writer); } if (Content == null || !Content.Any()) return []; - return Content.First().Value.Schema.Properties.Select(x => new OpenApiParameterReference(x.Key, Reference.HostDocument)); + return Content.First().Value.Schema?.Properties?.Select(x => new OpenApiParameterReference(x.Key, Reference?.HostDocument)); } /// diff --git a/src/Microsoft.OpenApi/Models/References/OpenApiResponseReference.cs b/src/Microsoft.OpenApi/Models/References/OpenApiResponseReference.cs index 9fbfb47a0..26c527c52 100644 --- a/src/Microsoft.OpenApi/Models/References/OpenApiResponseReference.cs +++ b/src/Microsoft.OpenApi/Models/References/OpenApiResponseReference.cs @@ -23,7 +23,7 @@ public class OpenApiResponseReference : BaseOpenApiReferenceHolder - public OpenApiResponseReference(string referenceId, OpenApiDocument hostDocument = null, string externalResource = null):base(referenceId, hostDocument, ReferenceType.Response, externalResource) + public OpenApiResponseReference(string referenceId, OpenApiDocument? hostDocument = null, string? externalResource = null):base(referenceId, hostDocument, ReferenceType.Response, externalResource) { } /// @@ -36,9 +36,9 @@ private OpenApiResponseReference(OpenApiResponseReference openApiResponseReferen } /// - public string Description + public string? Description { - get => string.IsNullOrEmpty(Reference?.Description) ? Target?.Description : Reference.Description; + get => string.IsNullOrEmpty(Reference?.Description) ? Target?.Description : Reference?.Description; set { if (Reference is not null) @@ -49,19 +49,19 @@ public string Description } /// - public IDictionary Content { get => Target?.Content; } + public IDictionary? Content { get => Target?.Content; } /// - public IDictionary Headers { get => Target?.Headers; } + public IDictionary? Headers { get => Target?.Headers; } /// - public IDictionary Links { get => Target?.Links; } + public IDictionary? Links { get => Target?.Links; } /// - public IDictionary Extensions { get => Target?.Extensions; } + public IDictionary? Extensions { get => Target?.Extensions; } /// - public override IOpenApiResponse CopyReferenceAsTargetElementWithOverrides(IOpenApiResponse source) + public override IOpenApiResponse? CopyReferenceAsTargetElementWithOverrides(IOpenApiResponse? source) { return source is OpenApiResponse ? new OpenApiResponse(this) : source; } diff --git a/src/Microsoft.OpenApi/Models/References/OpenApiSchemaReference.cs b/src/Microsoft.OpenApi/Models/References/OpenApiSchemaReference.cs index 9252d6b89..305d25558 100644 --- a/src/Microsoft.OpenApi/Models/References/OpenApiSchemaReference.cs +++ b/src/Microsoft.OpenApi/Models/References/OpenApiSchemaReference.cs @@ -25,7 +25,7 @@ public class OpenApiSchemaReference : BaseOpenApiReferenceHolder - public OpenApiSchemaReference(string referenceId, OpenApiDocument hostDocument = null, string externalResource = null):base(referenceId, hostDocument, ReferenceType.Schema, externalResource) + public OpenApiSchemaReference(string referenceId, OpenApiDocument? hostDocument = null, string? externalResource = null):base(referenceId, hostDocument, ReferenceType.Schema, externalResource) { } /// @@ -37,12 +37,12 @@ private OpenApiSchemaReference(OpenApiSchemaReference schema):base(schema) } /// - public string Description + public string? Description { - get => string.IsNullOrEmpty(Reference?.Description) ? Target?.Description : Reference.Description; + get => string.IsNullOrEmpty(Reference?.Description) ? Target?.Description : Reference?.Description; set { - if (Reference is not null) + if (Reference is not null && value is not null) { Reference.Description = value; } @@ -50,21 +50,21 @@ public string Description } /// - public string Title { get => Target?.Title; } + public string? Title { get => Target?.Title; } /// - public string Schema { get => Target?.Schema; } + public string? Schema { get => Target?.Schema; } /// - public string Id { get => Target?.Id; } + public string? Id { get => Target?.Id; } /// - public string Comment { get => Target?.Comment; } + public string? Comment { get => Target?.Comment; } /// - public IDictionary Vocabulary { get => Target?.Vocabulary; } + public IDictionary? Vocabulary { get => Target?.Vocabulary; } /// - public string DynamicRef { get => Target?.DynamicRef; } + public string? DynamicRef { get => Target?.DynamicRef; } /// - public string DynamicAnchor { get => Target?.DynamicAnchor; } + public string? DynamicAnchor { get => Target?.DynamicAnchor; } /// - public IDictionary Definitions { get => Target?.Definitions; } + public IDictionary? Definitions { get => Target?.Definitions; } /// public decimal? V31ExclusiveMaximum { get => Target?.V31ExclusiveMaximum; } /// @@ -74,9 +74,9 @@ public string Description /// public JsonSchemaType? Type { get => Target?.Type; } /// - public string Const { get => Target?.Const; } + public string? Const { get => Target?.Const; } /// - public string Format { get => Target?.Format; } + public string? Format { get => Target?.Format; } /// public decimal? Maximum { get => Target?.Maximum; } /// @@ -90,27 +90,27 @@ public string Description /// public int? MinLength { get => Target?.MinLength; } /// - public string Pattern { get => Target?.Pattern; } + public string? Pattern { get => Target?.Pattern; } /// public decimal? MultipleOf { get => Target?.MultipleOf; } /// - public JsonNode Default { get => Target?.Default; } + public JsonNode? Default { get => Target?.Default; } /// public bool ReadOnly { get => Target?.ReadOnly ?? false; } /// public bool WriteOnly { get => Target?.WriteOnly ?? false; } /// - public IList AllOf { get => Target?.AllOf; } + public IList? AllOf { get => Target?.AllOf; } /// - public IList OneOf { get => Target?.OneOf; } + public IList? OneOf { get => Target?.OneOf; } /// - public IList AnyOf { get => Target?.AnyOf; } + public IList? AnyOf { get => Target?.AnyOf; } /// - public IOpenApiSchema Not { get => Target?.Not; } + public IOpenApiSchema? Not { get => Target?.Not; } /// - public ISet Required { get => Target?.Required; } + public ISet? Required { get => Target?.Required; } /// - public IOpenApiSchema Items { get => Target?.Items; } + public IOpenApiSchema? Items { get => Target?.Items; } /// public int? MaxItems { get => Target?.MaxItems; } /// @@ -118,9 +118,9 @@ public string Description /// public bool? UniqueItems { get => Target?.UniqueItems; } /// - public IDictionary Properties { get => Target?.Properties; } + public IDictionary? Properties { get => Target?.Properties; } /// - public IDictionary PatternProperties { get => Target?.PatternProperties; } + public IDictionary? PatternProperties { get => Target?.PatternProperties; } /// public int? MaxProperties { get => Target?.MaxProperties; } /// @@ -128,51 +128,51 @@ public string Description /// public bool AdditionalPropertiesAllowed { get => Target?.AdditionalPropertiesAllowed ?? true; } /// - public IOpenApiSchema AdditionalProperties { get => Target?.AdditionalProperties; } + public IOpenApiSchema? AdditionalProperties { get => Target?.AdditionalProperties; } /// - public OpenApiDiscriminator Discriminator { get => Target?.Discriminator; } + public OpenApiDiscriminator? Discriminator { get => Target?.Discriminator; } /// - public JsonNode Example { get => Target?.Example; } + public JsonNode? Example { get => Target?.Example; } /// - public IList Examples { get => Target?.Examples; } + public IList? Examples { get => Target?.Examples; } /// - public IList Enum { get => Target?.Enum; } + public IList? Enum { get => Target?.Enum; } /// public bool UnevaluatedProperties { get => Target?.UnevaluatedProperties ?? false; } /// - public OpenApiExternalDocs ExternalDocs { get => Target?.ExternalDocs; } + public OpenApiExternalDocs? ExternalDocs { get => Target?.ExternalDocs; } /// public bool Deprecated { get => Target?.Deprecated ?? false; } /// - public OpenApiXml Xml { get => Target?.Xml; } + public OpenApiXml? Xml { get => Target?.Xml; } /// - public IDictionary Extensions { get => Target?.Extensions; } + public IDictionary? Extensions { get => Target?.Extensions; } /// - public IDictionary UnrecognizedKeywords { get => Target?.UnrecognizedKeywords; } + public IDictionary? UnrecognizedKeywords { get => Target?.UnrecognizedKeywords; } /// - public IDictionary Annotations { get => Target?.Annotations; } + public IDictionary? Annotations { get => Target?.Annotations; } /// public override void SerializeAsV31(IOpenApiWriter writer) { - SerializeAsWithoutLoops(writer, (w, element) => (element is IOpenApiSchema s ? CopyReferenceAsTargetElementWithOverrides(s) : element).SerializeAsV3(w)); + SerializeAsWithoutLoops(writer, (w, element) => (element is IOpenApiSchema s ? CopyReferenceAsTargetElementWithOverrides(s) : element)?.SerializeAsV3(w)); } /// public override void SerializeAsV3(IOpenApiWriter writer) { - SerializeAsWithoutLoops(writer, (w, element) => element.SerializeAsV3(w)); + SerializeAsWithoutLoops(writer, (w, element) => element?.SerializeAsV3(w)); } /// public override void SerializeAsV2(IOpenApiWriter writer) { - SerializeAsWithoutLoops(writer, (w, element) => element.SerializeAsV2(w)); + SerializeAsWithoutLoops(writer, (w, element) => element?.SerializeAsV2(w)); } - private void SerializeAsWithoutLoops(IOpenApiWriter writer, Action action) + private void SerializeAsWithoutLoops(IOpenApiWriter writer, Action action) { - if (!writer.GetSettings().ShouldInlineReference(Reference)) + if (Reference is not null && !writer.GetSettings().ShouldInlineReference(Reference)) { action(writer, Reference); } @@ -190,7 +190,7 @@ private void SerializeAsWithoutLoops(IOpenApiWriter writer, Action - public override IOpenApiSchema CopyReferenceAsTargetElementWithOverrides(IOpenApiSchema source) + public override IOpenApiSchema? CopyReferenceAsTargetElementWithOverrides(IOpenApiSchema? source) { return source is OpenApiSchema ? new OpenApiSchema(this) : source; } diff --git a/src/Microsoft.OpenApi/Models/References/OpenApiSecuritySchemeReference.cs b/src/Microsoft.OpenApi/Models/References/OpenApiSecuritySchemeReference.cs index 75ca30573..2f3afeb46 100644 --- a/src/Microsoft.OpenApi/Models/References/OpenApiSecuritySchemeReference.cs +++ b/src/Microsoft.OpenApi/Models/References/OpenApiSecuritySchemeReference.cs @@ -19,7 +19,7 @@ public class OpenApiSecuritySchemeReference : BaseOpenApiReferenceHolderThe reference Id. /// The host OpenAPI document. /// The externally referenced file. - public OpenApiSecuritySchemeReference(string referenceId, OpenApiDocument hostDocument = null, string externalResource = null):base(referenceId, hostDocument, ReferenceType.SecurityScheme, externalResource) + public OpenApiSecuritySchemeReference(string referenceId, OpenApiDocument? hostDocument = null, string? externalResource = null):base(referenceId, hostDocument, ReferenceType.SecurityScheme, externalResource) { } /// @@ -32,9 +32,9 @@ private OpenApiSecuritySchemeReference(OpenApiSecuritySchemeReference openApiSec } /// - public string Description + public string? Description { - get => string.IsNullOrEmpty(Reference?.Description) ? Target?.Description : Reference.Description; + get => string.IsNullOrEmpty(Reference?.Description) ? Target?.Description : Reference?.Description; set { if (Reference is not null) @@ -45,31 +45,31 @@ public string Description } /// - public string Name { get => Target?.Name; } + public string? Name { get => Target?.Name; } /// public ParameterLocation? In { get => Target?.In; } /// - public string Scheme { get => Target?.Scheme; } + public string? Scheme { get => Target?.Scheme; } /// - public string BearerFormat { get => Target?.BearerFormat; } + public string? BearerFormat { get => Target?.BearerFormat; } /// - public OpenApiOAuthFlows Flows { get => Target?.Flows; } + public OpenApiOAuthFlows? Flows { get => Target?.Flows; } /// - public Uri OpenIdConnectUrl { get => Target?.OpenIdConnectUrl; } + public Uri? OpenIdConnectUrl { get => Target?.OpenIdConnectUrl; } /// - public IDictionary Extensions { get => Target?.Extensions; } + public IDictionary? Extensions { get => Target?.Extensions; } /// public SecuritySchemeType? Type { get => Target?.Type; } /// - public override IOpenApiSecurityScheme CopyReferenceAsTargetElementWithOverrides(IOpenApiSecurityScheme source) + public override IOpenApiSecurityScheme? CopyReferenceAsTargetElementWithOverrides(IOpenApiSecurityScheme? source) { return source is OpenApiSecurityScheme ? new OpenApiSecurityScheme(this) : source; } diff --git a/src/Microsoft.OpenApi/Models/References/OpenApiTagReference.cs b/src/Microsoft.OpenApi/Models/References/OpenApiTagReference.cs index 6f218fc13..c7580e9e3 100644 --- a/src/Microsoft.OpenApi/Models/References/OpenApiTagReference.cs +++ b/src/Microsoft.OpenApi/Models/References/OpenApiTagReference.cs @@ -17,11 +17,11 @@ public class OpenApiTagReference : BaseOpenApiReferenceHolder /// Resolved target of the reference. /// - public override OpenApiTag Target + public override OpenApiTag? Target { get { - return Reference.HostDocument?.Tags.FirstOrDefault(t => StringComparer.Ordinal.Equals(t.Name, Reference.Id)); + return Reference?.HostDocument?.Tags?.FirstOrDefault(t => StringComparer.Ordinal.Equals(t.Name, Reference.Id)); } } @@ -35,7 +35,7 @@ public override OpenApiTag Target /// 1. a absolute/relative file path, for example: ../commons/pet.json /// 2. a Url, for example: http://localhost/pet.json /// - public OpenApiTagReference(string referenceId, OpenApiDocument hostDocument = null, string externalResource = null):base(referenceId, hostDocument, ReferenceType.Tag, externalResource) + public OpenApiTagReference(string? referenceId, OpenApiDocument? hostDocument = null, string? externalResource = null):base(referenceId, hostDocument, ReferenceType.Tag, externalResource) { } /// @@ -48,21 +48,21 @@ private OpenApiTagReference(OpenApiTagReference openApiTagReference):base(openAp } /// - public string Description + public string? Description { - get => string.IsNullOrEmpty(Reference?.Description) ? Target?.Description : Reference.Description; + get => string.IsNullOrEmpty(Reference?.Description) ? Target?.Description : Reference?.Description; } /// - public OpenApiExternalDocs ExternalDocs { get => Target?.ExternalDocs; } + public OpenApiExternalDocs? ExternalDocs { get => Target?.ExternalDocs; } /// - public IDictionary Extensions { get => Target?.Extensions; } + public IDictionary? Extensions { get => Target?.Extensions; } /// - public string Name { get => Target?.Name; } + public string? Name { get => Target?.Name; } /// - public override IOpenApiTag CopyReferenceAsTargetElementWithOverrides(IOpenApiTag source) + public override IOpenApiTag? CopyReferenceAsTargetElementWithOverrides(IOpenApiTag? source) { return source is OpenApiTag ? new OpenApiTag(this) : source; } diff --git a/src/Microsoft.OpenApi/Models/RuntimeExpressionAnyWrapper.cs b/src/Microsoft.OpenApi/Models/RuntimeExpressionAnyWrapper.cs index 35a08a422..d998ba400 100644 --- a/src/Microsoft.OpenApi/Models/RuntimeExpressionAnyWrapper.cs +++ b/src/Microsoft.OpenApi/Models/RuntimeExpressionAnyWrapper.cs @@ -14,8 +14,8 @@ namespace Microsoft.OpenApi.Models /// public class RuntimeExpressionAnyWrapper : IOpenApiElement { - private JsonNode _any; - private RuntimeExpression _expression; + private JsonNode? _any; + private RuntimeExpression? _expression; /// /// Parameterless constructor @@ -34,7 +34,7 @@ public RuntimeExpressionAnyWrapper(RuntimeExpressionAnyWrapper runtimeExpression /// /// Gets/Sets the /// - public JsonNode Any + public JsonNode? Any { get { @@ -50,7 +50,7 @@ public JsonNode Any /// /// Gets/Set the /// - public RuntimeExpression Expression + public RuntimeExpression? Expression { get { diff --git a/src/Microsoft.OpenApi/Reader/JsonNodeHelper.cs b/src/Microsoft.OpenApi/Reader/JsonNodeHelper.cs index e8dee12d1..b64c7ea43 100644 --- a/src/Microsoft.OpenApi/Reader/JsonNodeHelper.cs +++ b/src/Microsoft.OpenApi/Reader/JsonNodeHelper.cs @@ -10,7 +10,7 @@ namespace Microsoft.OpenApi.Reader { internal static class JsonNodeHelper { - public static string GetScalarValue(this JsonNode node) + public static string? GetScalarValue(this JsonNode node) { var scalarNode = node is JsonValue value ? value : throw new OpenApiException($"Expected scalar value."); diff --git a/src/Microsoft.OpenApi/Reader/OpenApiDiagnostic.cs b/src/Microsoft.OpenApi/Reader/OpenApiDiagnostic.cs index 5340d2aef..247bb2ba8 100644 --- a/src/Microsoft.OpenApi/Reader/OpenApiDiagnostic.cs +++ b/src/Microsoft.OpenApi/Reader/OpenApiDiagnostic.cs @@ -33,7 +33,7 @@ public class OpenApiDiagnostic : IDiagnostic /// /// The diagnostic instance of which the errors and warnings are to be appended to this diagnostic's /// The originating file of the diagnostic to be appended, this is prefixed to each error and warning to indicate the originating file - public void AppendDiagnostic(OpenApiDiagnostic diagnosticToAdd, string fileNameToAdd = null) + public void AppendDiagnostic(OpenApiDiagnostic diagnosticToAdd, string? fileNameToAdd = null) { var fileNameIsSupplied = !string.IsNullOrEmpty(fileNameToAdd); foreach (var err in diagnosticToAdd.Errors) diff --git a/src/Microsoft.OpenApi/Reader/OpenApiJsonReader.cs b/src/Microsoft.OpenApi/Reader/OpenApiJsonReader.cs index bac24a51d..736ab44d0 100644 --- a/src/Microsoft.OpenApi/Reader/OpenApiJsonReader.cs +++ b/src/Microsoft.OpenApi/Reader/OpenApiJsonReader.cs @@ -33,7 +33,7 @@ public ReadResult Read(MemoryStream input, if (input is null) throw new ArgumentNullException(nameof(input)); if (settings is null) throw new ArgumentNullException(nameof(settings)); - JsonNode jsonNode; + JsonNode? jsonNode; var diagnostic = new OpenApiDiagnostic(); settings ??= new OpenApiReaderSettings(); @@ -61,7 +61,7 @@ public ReadResult Read(MemoryStream input, /// The JsonNode input. /// The Reader settings to be used during parsing. /// - public ReadResult Read(JsonNode jsonNode, + public ReadResult Read(JsonNode? jsonNode, OpenApiReaderSettings settings) { if (jsonNode is null) throw new ArgumentNullException(nameof(jsonNode)); @@ -75,7 +75,7 @@ public ReadResult Read(JsonNode jsonNode, DefaultContentType = settings.DefaultContentType }; - OpenApiDocument document = null; + OpenApiDocument? document = null; try { // Parse the OpenAPI Document @@ -90,15 +90,18 @@ public ReadResult Read(JsonNode jsonNode, // Validate the document if (settings.RuleSet != null && settings.RuleSet.Rules.Any()) { - var openApiErrors = document.Validate(settings.RuleSet); - foreach (var item in openApiErrors.OfType()) + var openApiErrors = document?.Validate(settings.RuleSet); + if(openApiErrors is not null) { - diagnostic.Errors.Add(item); - } - foreach (var item in openApiErrors.OfType()) - { - diagnostic.Warnings.Add(item); - } + foreach (var item in openApiErrors.OfType()) + { + diagnostic.Errors.Add(item); + } + foreach (var item in openApiErrors.OfType()) + { + diagnostic.Warnings.Add(item); + } + } } return new() @@ -122,7 +125,7 @@ public async Task ReadAsync(Stream input, if (input is null) throw new ArgumentNullException(nameof(input)); if (settings is null) throw new ArgumentNullException(nameof(settings)); - JsonNode jsonNode; + JsonNode? jsonNode; var diagnostic = new OpenApiDiagnostic(); // Parse the JSON text in the stream into JsonNodes @@ -144,16 +147,16 @@ public async Task ReadAsync(Stream input, } /// - public T ReadFragment(MemoryStream input, + public T? ReadFragment(MemoryStream input, OpenApiSpecVersion version, OpenApiDocument openApiDocument, out OpenApiDiagnostic diagnostic, - OpenApiReaderSettings settings = null) where T : IOpenApiElement + OpenApiReaderSettings? settings = null) where T : IOpenApiElement { Utils.CheckArgumentNull(input); Utils.CheckArgumentNull(openApiDocument); - JsonNode jsonNode; + JsonNode? jsonNode; // Parse the JSON try @@ -171,11 +174,11 @@ public T ReadFragment(MemoryStream input, } /// - public T ReadFragment(JsonNode input, - OpenApiSpecVersion version, - OpenApiDocument openApiDocument, - out OpenApiDiagnostic diagnostic, - OpenApiReaderSettings settings = null) where T : IOpenApiElement + public T ReadFragment(JsonNode? input, + OpenApiSpecVersion version, + OpenApiDocument openApiDocument, + out OpenApiDiagnostic diagnostic, + OpenApiReaderSettings? settings = null) where T : IOpenApiElement { diagnostic = new(); settings ??= new OpenApiReaderSettings(); @@ -184,7 +187,7 @@ public T ReadFragment(JsonNode input, ExtensionParsers = settings.ExtensionParsers }; - IOpenApiElement element = null; + IOpenApiElement? element = null; try { // Parse the OpenAPI element @@ -198,14 +201,17 @@ public T ReadFragment(JsonNode input, // Validate the element if (settings.RuleSet != null && settings.RuleSet.Rules.Any()) { - var errors = element.Validate(settings.RuleSet); - foreach (var item in errors) + var errors = element?.Validate(settings.RuleSet); + if (errors is not null) { - diagnostic.Errors.Add(item); + foreach (var item in errors) + { + diagnostic.Errors.Add(item); + } } } - return (T)element; + return (T?)element!; } } } diff --git a/src/Microsoft.OpenApi/Reader/OpenApiModelFactory.cs b/src/Microsoft.OpenApi/Reader/OpenApiModelFactory.cs index c86c014da..bf0fde0df 100644 --- a/src/Microsoft.OpenApi/Reader/OpenApiModelFactory.cs +++ b/src/Microsoft.OpenApi/Reader/OpenApiModelFactory.cs @@ -36,8 +36,8 @@ static OpenApiModelFactory() /// The OpenAPI format. /// An OpenAPI document instance. public static ReadResult Load(MemoryStream stream, - string format = null, - OpenApiReaderSettings settings = null) + string? format = null, + OpenApiReaderSettings? settings = null) { #if NET6_0_OR_GREATER ArgumentNullException.ThrowIfNull(stream); @@ -70,7 +70,7 @@ public static ReadResult Load(MemoryStream stream, /// The OpenApiReader settings. /// Instance of newly created IOpenApiElement. /// The OpenAPI element. - public static T Load(MemoryStream input, OpenApiSpecVersion version, string format, OpenApiDocument openApiDocument, out OpenApiDiagnostic diagnostic, OpenApiReaderSettings settings = null) where T : IOpenApiElement + public static T? Load(MemoryStream input, OpenApiSpecVersion version, string? format, OpenApiDocument openApiDocument, out OpenApiDiagnostic diagnostic, OpenApiReaderSettings? settings = null) where T : IOpenApiElement { format ??= InspectStreamFormat(input); return OpenApiReaderRegistry.GetReader(format).ReadFragment(input, version, openApiDocument, out diagnostic, settings); @@ -83,7 +83,7 @@ public static T Load(MemoryStream input, OpenApiSpecVersion version, string f /// The OpenApi reader settings. /// /// - public static async Task LoadAsync(string url, OpenApiReaderSettings settings = null, CancellationToken token = default) + public static async Task LoadAsync(string url, OpenApiReaderSettings? settings = null, CancellationToken token = default) { var (stream, format) = await RetrieveStreamAndFormatAsync(url, token).ConfigureAwait(false); return await LoadAsync(stream, format, settings, token).ConfigureAwait(false); @@ -100,7 +100,7 @@ public static async Task LoadAsync(string url, OpenApiReaderSettings /// /// Instance of newly created IOpenApiElement. /// The OpenAPI element. - public static async Task LoadAsync(string url, OpenApiSpecVersion version, OpenApiDocument openApiDocument, OpenApiReaderSettings settings = null, CancellationToken token = default) where T : IOpenApiElement + public static async Task LoadAsync(string url, OpenApiSpecVersion version, OpenApiDocument openApiDocument, OpenApiReaderSettings? settings = null, CancellationToken token = default) where T : IOpenApiElement { var (stream, format) = await RetrieveStreamAndFormatAsync(url, token).ConfigureAwait(false); return await LoadAsync(stream, version, openApiDocument, format, settings, token); @@ -114,7 +114,7 @@ public static async Task LoadAsync(string url, OpenApiSpecVersion version, /// Propagates notification that operations should be cancelled. /// The Open API format /// - public static async Task LoadAsync(Stream input, string format = null, OpenApiReaderSettings settings = null, CancellationToken cancellationToken = default) + public static async Task LoadAsync(Stream input, string? format = null, OpenApiReaderSettings? settings = null, CancellationToken cancellationToken = default) { #if NET6_0_OR_GREATER ArgumentNullException.ThrowIfNull(input); @@ -160,11 +160,11 @@ public static async Task LoadAsync(Stream input, string format = nul /// /// /// - public static async Task LoadAsync(Stream input, + public static async Task LoadAsync(Stream input, OpenApiSpecVersion version, OpenApiDocument openApiDocument, - string format = null, - OpenApiReaderSettings settings = null, + string? format = null, + OpenApiReaderSettings? settings = null, CancellationToken token = default) where T : IOpenApiElement { Utils.CheckArgumentNull(openApiDocument); @@ -194,8 +194,8 @@ public static async Task LoadAsync(Stream input, /// The OpenApi reader settings. /// An OpenAPI document instance. public static ReadResult Parse(string input, - string format = null, - OpenApiReaderSettings settings = null) + string? format = null, + OpenApiReaderSettings? settings = null) { #if NET6_0_OR_GREATER ArgumentException.ThrowIfNullOrEmpty(input); @@ -221,12 +221,12 @@ public static ReadResult Parse(string input, /// The Open API format /// The OpenApi reader settings. /// An OpenAPI document instance. - public static T Parse(string input, + public static T? Parse(string input, OpenApiSpecVersion version, OpenApiDocument openApiDocument, out OpenApiDiagnostic diagnostic, - string format = null, - OpenApiReaderSettings settings = null) where T : IOpenApiElement + string? format = null, + OpenApiReaderSettings? settings = null) where T : IOpenApiElement { #if NET6_0_OR_GREATER ArgumentException.ThrowIfNullOrEmpty(input); @@ -239,42 +239,40 @@ public static T Parse(string input, return Load(stream, version, format, openApiDocument, out diagnostic, settings); } - private static readonly OpenApiReaderSettings DefaultReaderSettings = new(); - private static async Task InternalLoadAsync(Stream input, string format, OpenApiReaderSettings settings, CancellationToken cancellationToken = default) { var reader = OpenApiReaderRegistry.GetReader(format); var readResult = await reader.ReadAsync(input, settings, cancellationToken).ConfigureAwait(false); - if (settings?.LoadExternalRefs ?? DefaultReaderSettings.LoadExternalRefs) + if (settings.LoadExternalRefs) { var diagnosticExternalRefs = await LoadExternalRefsAsync(readResult.Document, settings, format, cancellationToken).ConfigureAwait(false); // Merge diagnostics of external reference if (diagnosticExternalRefs != null) { - readResult.Diagnostic.Errors.AddRange(diagnosticExternalRefs.Errors); - readResult.Diagnostic.Warnings.AddRange(diagnosticExternalRefs.Warnings); + readResult.Diagnostic?.Errors.AddRange(diagnosticExternalRefs.Errors); + readResult.Diagnostic?.Warnings.AddRange(diagnosticExternalRefs.Warnings); } } return readResult; } - private static async Task LoadExternalRefsAsync(OpenApiDocument document, OpenApiReaderSettings settings, string format = null, CancellationToken token = default) + private static async Task LoadExternalRefsAsync(OpenApiDocument? document, OpenApiReaderSettings settings, string? format = null, CancellationToken token = default) { // Create workspace for all documents to live in. var baseUrl = settings.BaseUrl ?? new Uri(OpenApiConstants.BaseRegistryUri); var openApiWorkSpace = new OpenApiWorkspace(baseUrl); // Load this root document into the workspace - var streamLoader = new DefaultStreamLoader(settings.BaseUrl); + var streamLoader = new DefaultStreamLoader(baseUrl); var workspaceLoader = new OpenApiWorkspaceLoader(openApiWorkSpace, settings.CustomExternalLoader ?? streamLoader, settings); return await workspaceLoader.LoadAsync(new OpenApiReference() { ExternalResource = "/" }, document, format ?? OpenApiConstants.Json, null, token).ConfigureAwait(false); } private static ReadResult InternalLoad(MemoryStream input, string format, OpenApiReaderSettings settings) { - if (settings?.LoadExternalRefs ?? DefaultReaderSettings.LoadExternalRefs) + if (settings.LoadExternalRefs) { throw new InvalidOperationException("Loading external references are not supported when using synchronous methods."); } @@ -288,20 +286,20 @@ private static ReadResult InternalLoad(MemoryStream input, string format, OpenAp return readResult; } - private static async Task<(Stream, string)> RetrieveStreamAndFormatAsync(string url, CancellationToken token = default) + private static async Task<(Stream, string?)> RetrieveStreamAndFormatAsync(string url, CancellationToken token = default) { if (!string.IsNullOrEmpty(url)) { Stream stream; - string format; + string? format; if (url.StartsWith("http", StringComparison.OrdinalIgnoreCase) || url.StartsWith("https", StringComparison.OrdinalIgnoreCase)) { var response = await _httpClient.GetAsync(url, token).ConfigureAwait(false); - var mediaType = response.Content.Headers.ContentType.MediaType; - var contentType = mediaType.Split(";".ToCharArray(), StringSplitOptions.RemoveEmptyEntries)[0]; - format = contentType.Split('/').Last().Split('+').Last().Split('-').Last(); + var mediaType = response.Content.Headers.ContentType?.MediaType; + var contentType = mediaType?.Split(";".ToCharArray(), StringSplitOptions.RemoveEmptyEntries)[0]; + format = contentType?.Split('/')[0].Split('+')[0].Split('-')[0]; // for non-standard MIME types e.g. text/x-yaml used in older libs or apps #if NETSTANDARD2_0 stream = await response.Content.ReadAsStreamAsync(); @@ -335,7 +333,7 @@ SecurityException or return (stream, format); } } - return (null, null); + throw new ArgumentException($"Parameter {nameof(url)} is null or empty. Please provide the correct path or URL to the file."); } private static string InspectInputFormat(string input) @@ -370,7 +368,7 @@ private static string InspectStreamFormat(Stream stream) }; } - private static async Task<(Stream, string)> PrepareStreamForReadingAsync(Stream input, string format, CancellationToken token = default) + private static async Task<(Stream, string)> PrepareStreamForReadingAsync(Stream input, string? format, CancellationToken token = default) { Stream preparedStream = input; diff --git a/src/Microsoft.OpenApi/Reader/OpenApiReaderSettings.cs b/src/Microsoft.OpenApi/Reader/OpenApiReaderSettings.cs index 33f03eedb..6c559d11b 100644 --- a/src/Microsoft.OpenApi/Reader/OpenApiReaderSettings.cs +++ b/src/Microsoft.OpenApi/Reader/OpenApiReaderSettings.cs @@ -49,7 +49,7 @@ public class OpenApiReaderSettings /// /// Dictionary of parsers for converting extensions into strongly typed classes /// - public Dictionary> ExtensionParsers { get; set; } = new(); + public Dictionary>? ExtensionParsers { get; set; } = new(); /// /// Rules to use for validating OpenAPI specification. If none are provided a default set of rules are applied. @@ -59,12 +59,12 @@ public class OpenApiReaderSettings /// /// URL where relative references should be resolved from if the description does not contain Server definitions /// - public Uri BaseUrl { get; set; } + public Uri? BaseUrl { get; set; } /// /// Allows clients to define a custom DefaultContentType if produces array is empty /// - public List DefaultContentType { get; set; } + public List? DefaultContentType { get; set; } /// /// Function used to provide an alternative loader for accessing external references. @@ -72,7 +72,7 @@ public class OpenApiReaderSettings /// /// Default loader will attempt to dereference http(s) urls and file urls. /// - public IStreamLoader CustomExternalLoader { get; set; } + public IStreamLoader? CustomExternalLoader { get; set; } /// /// Whether to leave the object open after reading @@ -92,18 +92,21 @@ public class OpenApiReaderSettings /// public void AddMicrosoftExtensionParsers() { - if (!ExtensionParsers.ContainsKey(OpenApiPagingExtension.Name)) - ExtensionParsers.Add(OpenApiPagingExtension.Name, static (i, _) => OpenApiPagingExtension.Parse(i)); - if (!ExtensionParsers.ContainsKey(OpenApiEnumValuesDescriptionExtension.Name)) - ExtensionParsers.Add(OpenApiEnumValuesDescriptionExtension.Name, static (i, _ ) => OpenApiEnumValuesDescriptionExtension.Parse(i)); - if (!ExtensionParsers.ContainsKey(OpenApiPrimaryErrorMessageExtension.Name)) - ExtensionParsers.Add(OpenApiPrimaryErrorMessageExtension.Name, static (i, _ ) => OpenApiPrimaryErrorMessageExtension.Parse(i)); - if (!ExtensionParsers.ContainsKey(OpenApiDeprecationExtension.Name)) - ExtensionParsers.Add(OpenApiDeprecationExtension.Name, static (i, _ ) => OpenApiDeprecationExtension.Parse(i)); - if (!ExtensionParsers.ContainsKey(OpenApiReservedParameterExtension.Name)) - ExtensionParsers.Add(OpenApiReservedParameterExtension.Name, static (i, _ ) => OpenApiReservedParameterExtension.Parse(i)); - if (!ExtensionParsers.ContainsKey(OpenApiEnumFlagsExtension.Name)) - ExtensionParsers.Add(OpenApiEnumFlagsExtension.Name, static (i, _ ) => OpenApiEnumFlagsExtension.Parse(i)); + if (ExtensionParsers is not null) + { + if (!ExtensionParsers.ContainsKey(OpenApiPagingExtension.Name)) + ExtensionParsers.Add(OpenApiPagingExtension.Name, static (i, _) => OpenApiPagingExtension.Parse(i)); + if (!ExtensionParsers.ContainsKey(OpenApiEnumValuesDescriptionExtension.Name)) + ExtensionParsers.Add(OpenApiEnumValuesDescriptionExtension.Name, static (i, _) => OpenApiEnumValuesDescriptionExtension.Parse(i)); + if (!ExtensionParsers.ContainsKey(OpenApiPrimaryErrorMessageExtension.Name)) + ExtensionParsers.Add(OpenApiPrimaryErrorMessageExtension.Name, static (i, _) => OpenApiPrimaryErrorMessageExtension.Parse(i)); + if (!ExtensionParsers.ContainsKey(OpenApiDeprecationExtension.Name)) + ExtensionParsers.Add(OpenApiDeprecationExtension.Name, static (i, _) => OpenApiDeprecationExtension.Parse(i)); + if (!ExtensionParsers.ContainsKey(OpenApiReservedParameterExtension.Name)) + ExtensionParsers.Add(OpenApiReservedParameterExtension.Name, static (i, _) => OpenApiReservedParameterExtension.Parse(i)); + if (!ExtensionParsers.ContainsKey(OpenApiEnumFlagsExtension.Name)) + ExtensionParsers.Add(OpenApiEnumFlagsExtension.Name, static (i, _) => OpenApiEnumFlagsExtension.Parse(i)); + } } } } diff --git a/src/Microsoft.OpenApi/Reader/ParseNodes/AnyFieldMapParameter.cs b/src/Microsoft.OpenApi/Reader/ParseNodes/AnyFieldMapParameter.cs index 16456c400..7d37b3118 100644 --- a/src/Microsoft.OpenApi/Reader/ParseNodes/AnyFieldMapParameter.cs +++ b/src/Microsoft.OpenApi/Reader/ParseNodes/AnyFieldMapParameter.cs @@ -14,9 +14,9 @@ internal class AnyFieldMapParameter /// Constructor. /// public AnyFieldMapParameter( - Func propertyGetter, - Action propertySetter, - Func SchemaGetter = null) + Func propertyGetter, + Action propertySetter, + Func? SchemaGetter = null) { this.PropertyGetter = propertyGetter; this.PropertySetter = propertySetter; @@ -26,16 +26,16 @@ public AnyFieldMapParameter( /// /// Function to retrieve the value of the property. /// - public Func PropertyGetter { get; } + public Func PropertyGetter { get; } /// /// Function to set the value of the property. /// - public Action PropertySetter { get; } + public Action PropertySetter { get; } /// /// Function to get the schema to apply to the property. /// - public Func SchemaGetter { get; } + public Func? SchemaGetter { get; } } } diff --git a/src/Microsoft.OpenApi/Reader/ParseNodes/AnyListFieldMapParameter.cs b/src/Microsoft.OpenApi/Reader/ParseNodes/AnyListFieldMapParameter.cs index fc87a548e..873f0df15 100644 --- a/src/Microsoft.OpenApi/Reader/ParseNodes/AnyListFieldMapParameter.cs +++ b/src/Microsoft.OpenApi/Reader/ParseNodes/AnyListFieldMapParameter.cs @@ -16,7 +16,7 @@ internal class AnyListFieldMapParameter public AnyListFieldMapParameter( Func> propertyGetter, Action> propertySetter, - Func SchemaGetter = null) + Func? SchemaGetter = null) { this.PropertyGetter = propertyGetter; this.PropertySetter = propertySetter; @@ -36,6 +36,6 @@ public AnyListFieldMapParameter( /// /// Function to get the schema to apply to the property. /// - public Func SchemaGetter { get; } + public Func? SchemaGetter { get; } } } diff --git a/src/Microsoft.OpenApi/Reader/ParseNodes/AnyMapFieldMapParameter.cs b/src/Microsoft.OpenApi/Reader/ParseNodes/AnyMapFieldMapParameter.cs index 52397aed9..6a16f4e46 100644 --- a/src/Microsoft.OpenApi/Reader/ParseNodes/AnyMapFieldMapParameter.cs +++ b/src/Microsoft.OpenApi/Reader/ParseNodes/AnyMapFieldMapParameter.cs @@ -15,10 +15,10 @@ internal class AnyMapFieldMapParameter /// Constructor /// public AnyMapFieldMapParameter( - Func> propertyMapGetter, - Func propertyGetter, + Func?> propertyMapGetter, + Func propertyGetter, Action propertySetter, - Func schemaGetter) + Func schemaGetter) { this.PropertyMapGetter = propertyMapGetter; this.PropertyGetter = propertyGetter; @@ -29,12 +29,12 @@ public AnyMapFieldMapParameter( /// /// Function to retrieve the property that is a map from string to an inner element containing IOpenApiAny. /// - public Func> PropertyMapGetter { get; } + public Func?> PropertyMapGetter { get; } /// /// Function to retrieve the value of the property from an inner element. /// - public Func PropertyGetter { get; } + public Func PropertyGetter { get; } /// /// Function to set the value of the property. @@ -44,6 +44,6 @@ public AnyMapFieldMapParameter( /// /// Function to get the schema to apply to the property. /// - public Func SchemaGetter { get; } + public Func SchemaGetter { get; } } } diff --git a/src/Microsoft.OpenApi/Reader/ParseNodes/JsonPointerExtensions.cs b/src/Microsoft.OpenApi/Reader/ParseNodes/JsonPointerExtensions.cs index b349f2d5d..28c0a48fd 100644 --- a/src/Microsoft.OpenApi/Reader/ParseNodes/JsonPointerExtensions.cs +++ b/src/Microsoft.OpenApi/Reader/ParseNodes/JsonPointerExtensions.cs @@ -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; @@ -14,7 +14,7 @@ public static class JsonPointerExtensions /// /// Finds the JSON node that corresponds to this JSON pointer based on the base Json node. /// - public static JsonNode Find(this JsonPointer currentPointer, JsonNode baseJsonNode) + public static JsonNode? Find(this JsonPointer currentPointer, JsonNode baseJsonNode) { if (currentPointer.Tokens.Length == 0) { diff --git a/src/Microsoft.OpenApi/Reader/ParseNodes/ListNode.cs b/src/Microsoft.OpenApi/Reader/ParseNodes/ListNode.cs index 96235271e..d3af80945 100644 --- a/src/Microsoft.OpenApi/Reader/ParseNodes/ListNode.cs +++ b/src/Microsoft.OpenApi/Reader/ParseNodes/ListNode.cs @@ -28,9 +28,10 @@ public override List CreateList(Func map, Ope throw new OpenApiReaderException($"Expected list while parsing {typeof(T).Name}", _nodeList); } - return _nodeList?.Select(n => map(new MapNode(Context, n as JsonObject), hostDocument)) + var list = _nodeList.Select(n => map(new MapNode(Context, n as JsonObject), hostDocument)) .Where(i => i != null) .ToList(); + return list; } public override List CreateListOfAny() diff --git a/src/Microsoft.OpenApi/Reader/ParseNodes/MapNode.cs b/src/Microsoft.OpenApi/Reader/ParseNodes/MapNode.cs index b71593dca..0bafad6c2 100644 --- a/src/Microsoft.OpenApi/Reader/ParseNodes/MapNode.cs +++ b/src/Microsoft.OpenApi/Reader/ParseNodes/MapNode.cs @@ -24,7 +24,7 @@ internal class MapNode : ParseNode, IEnumerable private readonly JsonObject _node; private readonly List _nodes; - public MapNode(ParsingContext context, JsonNode node) : base( + public MapNode(ParsingContext context, JsonNode? node) : base( context, node) { if (node is not JsonObject mapNode) @@ -36,7 +36,7 @@ public MapNode(ParsingContext context, JsonNode node) : base( _nodes = _node.Select(p => new PropertyNode(Context, p.Key, p.Value)).ToList(); } - public PropertyNode this[string key] + public PropertyNode? this[string key] { get { @@ -63,7 +63,7 @@ public override Dictionary CreateMap(Func(ReferenceType referenceType, string referenceId, string summary = null, string description = null) - where T : IOpenApiReferenceHolder, new() + public string? GetReferencePointer() { - return new() - { - Reference = Context.VersionService.ConvertToOpenApiReference(referenceId, referenceType, summary, description) - }; - } - - public string GetReferencePointer() - { - if (!_node.TryGetPropertyValue("$ref", out JsonNode refNode)) + if (!_node.TryGetPropertyValue("$ref", out JsonNode? refNode)) { return null; } - return refNode.GetScalarValue(); + return refNode?.GetScalarValue(); } - public string GetSummaryValue() + public string? GetSummaryValue() { - if (!_node.TryGetPropertyValue("summary", out JsonNode summaryNode)) + if (!_node.TryGetPropertyValue("summary", out JsonNode? summaryNode)) { return null; } - return summaryNode.GetScalarValue(); + return summaryNode?.GetScalarValue(); } - public string GetDescriptionValue() + public string? GetDescriptionValue() { - if (!_node.TryGetPropertyValue("description", out JsonNode descriptionNode)) + if (!_node.TryGetPropertyValue("description", out JsonNode? descriptionNode)) { return null; } - return descriptionNode.GetScalarValue(); + return descriptionNode?.GetScalarValue(); } - public string GetScalarValue(ValueNode key) + public string? GetScalarValue(ValueNode key) { - var scalarNode = _node[key.GetScalarValue()] is JsonValue jsonValue - ? jsonValue - : throw new OpenApiReaderException($"Expected scalar while parsing {key.GetScalarValue()}", Context); + var keyValue = key.GetScalarValue(); + if (keyValue is not null) + { + var scalarNode = _node[keyValue] is JsonValue jsonValue + ? jsonValue + : throw new OpenApiReaderException($"Expected scalar while parsing {key.GetScalarValue()}", Context); - return Convert.ToString(scalarNode?.GetValue(), CultureInfo.InvariantCulture); + return Convert.ToString(scalarNode?.GetValue(), CultureInfo.InvariantCulture); + } + return null; } /// diff --git a/src/Microsoft.OpenApi/Reader/ParseNodes/ParseNode.cs b/src/Microsoft.OpenApi/Reader/ParseNodes/ParseNode.cs index 9fbf3f47a..16593d5d3 100644 --- a/src/Microsoft.OpenApi/Reader/ParseNodes/ParseNode.cs +++ b/src/Microsoft.OpenApi/Reader/ParseNodes/ParseNode.cs @@ -11,7 +11,7 @@ namespace Microsoft.OpenApi.Reader.ParseNodes { internal abstract class ParseNode { - protected ParseNode(ParsingContext parsingContext, JsonNode jsonNode) + protected ParseNode(ParsingContext parsingContext, JsonNode? jsonNode) { Context = parsingContext; JsonNode = jsonNode; @@ -19,7 +19,7 @@ protected ParseNode(ParsingContext parsingContext, JsonNode jsonNode) public ParsingContext Context { get; } - public JsonNode JsonNode { get; } + public JsonNode? JsonNode { get; } public MapNode CheckMapNode(string nodeName) { @@ -31,7 +31,7 @@ public MapNode CheckMapNode(string nodeName) return mapNode; } - public static ParseNode Create(ParsingContext context, JsonNode node) + public static ParseNode Create(ParsingContext context, JsonNode? node) { if (node is JsonArray listNode) { @@ -76,7 +76,7 @@ public virtual string GetRaw() throw new OpenApiReaderException("Cannot get raw value from this type of node.", Context); } - public virtual string GetScalarValue() + public virtual string? GetScalarValue() { throw new OpenApiReaderException("Cannot create a scalar value from this type of node.", Context); } diff --git a/src/Microsoft.OpenApi/Reader/ParseNodes/PropertyNode.cs b/src/Microsoft.OpenApi/Reader/ParseNodes/PropertyNode.cs index 9517e5363..c9aa80955 100644 --- a/src/Microsoft.OpenApi/Reader/ParseNodes/PropertyNode.cs +++ b/src/Microsoft.OpenApi/Reader/ParseNodes/PropertyNode.cs @@ -12,7 +12,7 @@ namespace Microsoft.OpenApi.Reader.ParseNodes { internal class PropertyNode : ParseNode { - public PropertyNode(ParsingContext context, string name, JsonNode node) : base( + public PropertyNode(ParsingContext context, string name, JsonNode? node) : base( context, node) { Name = name; @@ -27,9 +27,9 @@ public void ParseField( T parentInstance, IDictionary> fixedFields, IDictionary, Action> patternFields, - OpenApiDocument hostDocument) + OpenApiDocument? hostDocument) { - if (fixedFields.TryGetValue(Name, out var fixedFieldMap)) + if (fixedFields.TryGetValue(Name, out var fixedFieldMap) && hostDocument is not null) { try { @@ -53,7 +53,7 @@ public void ParseField( else { var map = patternFields.Where(p => p.Key(Name)).Select(p => p.Value).FirstOrDefault(); - if (map != null) + if (map != null && hostDocument is not null) { try { diff --git a/src/Microsoft.OpenApi/Reader/ParseNodes/RootNode.cs b/src/Microsoft.OpenApi/Reader/ParseNodes/RootNode.cs index b9e49b47d..741dccd2a 100644 --- a/src/Microsoft.OpenApi/Reader/ParseNodes/RootNode.cs +++ b/src/Microsoft.OpenApi/Reader/ParseNodes/RootNode.cs @@ -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.Text.Json.Nodes; @@ -19,7 +19,7 @@ public RootNode( _jsonNode = jsonNode; } - public ParseNode Find(JsonPointer referencePointer) + public ParseNode? Find(JsonPointer referencePointer) { if (referencePointer.Find(_jsonNode) is not JsonNode jsonNode) { diff --git a/src/Microsoft.OpenApi/Reader/ParseNodes/ValueNode.cs b/src/Microsoft.OpenApi/Reader/ParseNodes/ValueNode.cs index f83d2ba66..4b2097d88 100644 --- a/src/Microsoft.OpenApi/Reader/ParseNodes/ValueNode.cs +++ b/src/Microsoft.OpenApi/Reader/ParseNodes/ValueNode.cs @@ -12,7 +12,7 @@ internal class ValueNode : ParseNode { private readonly JsonValue _node; - public ValueNode(ParsingContext context, JsonNode node) : base( + public ValueNode(ParsingContext context, JsonNode? node) : base( context, node) { if (node is not JsonValue scalarNode) @@ -22,9 +22,10 @@ public ValueNode(ParsingContext context, JsonNode node) : base( _node = scalarNode; } - public override string GetScalarValue() + public override string? GetScalarValue() { - return Convert.ToString(_node.GetValue(), CultureInfo.InvariantCulture); + var scalarValue = _node.GetValue(); + return Convert.ToString(scalarValue, CultureInfo.InvariantCulture); } /// diff --git a/src/Microsoft.OpenApi/Reader/ParsingContext.cs b/src/Microsoft.OpenApi/Reader/ParsingContext.cs index 485686e89..74d406ce2 100644 --- a/src/Microsoft.OpenApi/Reader/ParsingContext.cs +++ b/src/Microsoft.OpenApi/Reader/ParsingContext.cs @@ -28,21 +28,21 @@ public class ParsingContext /// /// Extension parsers /// - public Dictionary> ExtensionParsers { get; set; } = + public Dictionary>? ExtensionParsers { get; set; } = new(); - internal RootNode RootNode { get; set; } + internal RootNode? RootNode { get; set; } internal List Tags { get; private set; } = new(); /// /// The base url for the document /// - public Uri BaseUrl { get; set; } + public Uri? BaseUrl { get; set; } /// /// Default content type for a response object /// - public List DefaultContentType { get; set; } + public List? DefaultContentType { get; set; } /// /// Diagnostic object that returns metadata about the parsing process. @@ -106,7 +106,7 @@ public OpenApiDocument Parse(JsonNode jsonNode) /// OpenAPI version of the fragment /// The OpenApiDocument object to which the fragment belongs, used to lookup references. /// An OpenApiDocument populated based on the passed yamlDocument - public T ParseFragment(JsonNode jsonNode, OpenApiSpecVersion version, OpenApiDocument openApiDocument) where T : IOpenApiElement + public T? ParseFragment(JsonNode? jsonNode, OpenApiSpecVersion version, OpenApiDocument openApiDocument) where T : IOpenApiElement { var node = ParseNode.Create(this, jsonNode); @@ -135,24 +135,24 @@ public T ParseFragment(JsonNode jsonNode, OpenApiSpecVersion version, OpenApi /// /// Gets the version of the Open API document. /// - private static string GetVersion(RootNode rootNode) + private static string? GetVersion(RootNode rootNode) { var versionNode = rootNode.Find(new("/openapi")); if (versionNode != null) { - return versionNode.GetScalarValue().Replace("\"", string.Empty); + return versionNode.GetScalarValue()?.Replace("\"", string.Empty); } versionNode = rootNode.Find(new("/swagger")); - return versionNode?.GetScalarValue().Replace("\"", string.Empty); + return versionNode?.GetScalarValue()?.Replace("\"", string.Empty); } /// /// Service providing all Version specific conversion functions /// - internal IOpenApiVersionService VersionService { get; set; } + internal IOpenApiVersionService? VersionService { get; set; } /// /// End the current object. @@ -173,9 +173,9 @@ public string GetLocation() /// /// Gets the value from the temporary storage matching the given key. /// - public T GetFromTempStorage(string key, object scope = null) + public T? GetFromTempStorage(string key, object? scope = null) { - Dictionary storage; + Dictionary? storage; if (scope == null) { @@ -192,9 +192,9 @@ public T GetFromTempStorage(string key, object scope = null) /// /// Sets the temporary storage for this key and value. /// - public void SetTempStorage(string key, object value, object scope = null) + public void SetTempStorage(string key, object? value, object? scope = null) { - Dictionary storage; + Dictionary? storage; if (scope == null) { @@ -274,7 +274,7 @@ private void ValidateRequiredFields(OpenApiDocument doc, string version) if ((version.is2_0() || version.is3_0()) && (doc.Paths == null)) { // 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()}")); + RootNode?.Context.Diagnostic.Errors.Add(new OpenApiError("", $"Paths is a REQUIRED field at {RootNode.Context.GetLocation()}")); } } } diff --git a/src/Microsoft.OpenApi/Reader/ReadResult.cs b/src/Microsoft.OpenApi/Reader/ReadResult.cs index aa835478a..7ae80f5da 100644 --- a/src/Microsoft.OpenApi/Reader/ReadResult.cs +++ b/src/Microsoft.OpenApi/Reader/ReadResult.cs @@ -13,15 +13,15 @@ public class ReadResult /// /// The parsed OpenApiDocument. Null will be returned if the document could not be parsed. /// - public OpenApiDocument Document { get; set; } + public OpenApiDocument? Document { get; set; } /// /// OpenApiDiagnostic contains the Errors reported while parsing /// - public OpenApiDiagnostic Diagnostic { get; set; } + public OpenApiDiagnostic? Diagnostic { get; set; } /// /// Deconstructs the result for easier assignment on the client application. /// - public void Deconstruct(out OpenApiDocument document, out OpenApiDiagnostic diagnostic) + public void Deconstruct(out OpenApiDocument? document, out OpenApiDiagnostic? diagnostic) { document = Document; diagnostic = Diagnostic; diff --git a/src/Microsoft.OpenApi/Reader/Services/OpenApiRemoteReferenceCollector.cs b/src/Microsoft.OpenApi/Reader/Services/OpenApiRemoteReferenceCollector.cs index 8690735b8..3c9301e11 100644 --- a/src/Microsoft.OpenApi/Reader/Services/OpenApiRemoteReferenceCollector.cs +++ b/src/Microsoft.OpenApi/Reader/Services/OpenApiRemoteReferenceCollector.cs @@ -35,12 +35,13 @@ public override void Visit(IOpenApiReferenceHolder referenceHolder) /// /// Collect external references /// - private void AddExternalReferences(OpenApiReference reference) + private void AddExternalReferences(OpenApiReference? reference) { - if (reference is {IsExternal: true} && - !_references.ContainsKey(reference.ExternalResource)) + var externalResource = reference?.ExternalResource; + if (reference is {IsExternal: true} && externalResource is not null && + !_references.ContainsKey(externalResource)) { - _references.Add(reference.ExternalResource, reference); + _references.Add(externalResource, reference); } } } diff --git a/src/Microsoft.OpenApi/Reader/Services/OpenApiWorkspaceLoader.cs b/src/Microsoft.OpenApi/Reader/Services/OpenApiWorkspaceLoader.cs index 06231e75c..d35d66e71 100644 --- a/src/Microsoft.OpenApi/Reader/Services/OpenApiWorkspaceLoader.cs +++ b/src/Microsoft.OpenApi/Reader/Services/OpenApiWorkspaceLoader.cs @@ -21,16 +21,19 @@ public OpenApiWorkspaceLoader(OpenApiWorkspace workspace, IStreamLoader loader, } internal async Task LoadAsync(OpenApiReference reference, - OpenApiDocument document, - string format = null, - OpenApiDiagnostic diagnostic = null, + OpenApiDocument? document, + string? format = null, + OpenApiDiagnostic? diagnostic = null, CancellationToken cancellationToken = default) { - _workspace.AddDocumentId(reference.ExternalResource, document.BaseUri); + _workspace.AddDocumentId(reference.ExternalResource, document?.BaseUri); var version = diagnostic?.SpecificationVersion ?? OpenApiSpecVersion.OpenApi3_0; - _workspace.RegisterComponents(document); - document.Workspace = _workspace; - + if (document is not null) + { + _workspace.RegisterComponents(document); + document.Workspace = _workspace; + } + // Collect remote references by walking document var referenceCollector = new OpenApiRemoteReferenceCollector(); var collectorWalker = new OpenApiWalker(referenceCollector); @@ -43,7 +46,7 @@ internal async Task LoadAsync(OpenApiReference reference, { // If not already in workspace, load it and process references - if (!_workspace.Contains(item.ExternalResource)) + if (item.ExternalResource is not null && !_workspace.Contains(item.ExternalResource)) { var input = await _loader.LoadAsync(new(item.ExternalResource, UriKind.RelativeOrAbsolute)); var result = await OpenApiDocument.LoadAsync(input, format, _readerSettings, cancellationToken); diff --git a/src/Microsoft.OpenApi/Reader/V2/OpenApiContactDeserializer.cs b/src/Microsoft.OpenApi/Reader/V2/OpenApiContactDeserializer.cs index 00bfc2d74..c55175782 100644 --- a/src/Microsoft.OpenApi/Reader/V2/OpenApiContactDeserializer.cs +++ b/src/Microsoft.OpenApi/Reader/V2/OpenApiContactDeserializer.cs @@ -22,7 +22,14 @@ internal static partial class OpenApiV2Deserializer }, { "url", - (o, n, t) => o.Url = new(n.GetScalarValue(), UriKind.RelativeOrAbsolute) + (o, n, t) => + { + var url = n.GetScalarValue(); + if (url != null) + { + o.Url = new(url, UriKind.RelativeOrAbsolute); + } + } }, { "email", diff --git a/src/Microsoft.OpenApi/Reader/V2/OpenApiDocumentDeserializer.cs b/src/Microsoft.OpenApi/Reader/V2/OpenApiDocumentDeserializer.cs index 0aa2b8093..a59894ed8 100644 --- a/src/Microsoft.OpenApi/Reader/V2/OpenApiDocumentDeserializer.cs +++ b/src/Microsoft.OpenApi/Reader/V2/OpenApiDocumentDeserializer.cs @@ -70,15 +70,18 @@ internal static partial class OpenApiV2Deserializer { o.Components ??= new(); - o.Components.Parameters = n.CreateMap(LoadParameter, o); - - o.Components.RequestBodies = n.CreateMap((p, d) => - { - var parameter = LoadParameter(node: p, loadRequestBody: true, hostDocument: d); - return parameter != null ? CreateRequestBody(p.Context, parameter) : null; - }, - doc - ); + o.Components.Parameters = n.CreateMap(LoadParameter, o) + .Where(kvp => kvp.Value != null) + .ToDictionary(kvp => kvp.Key, kvp => kvp.Value!); + + o.Components.RequestBodies = n.CreateMap((p, d) => + { + var parameter = LoadParameter(node: p, loadRequestBody: true, hostDocument: d); + return parameter != null ? CreateRequestBody(p.Context, parameter) : null; + }, + doc + ).Where(kvp => kvp.Value != null) + .ToDictionary(kvp => kvp.Key, kvp => kvp.Value!); } }, { @@ -179,14 +182,14 @@ private static void MakeServers(IList servers, ParsingContext con { // Server Urls are always appended to Paths and Paths must start with / // so removing the slash prevents a double slash. - if (server.Url.EndsWith("/")) + if (server.Url is not null && server.Url.EndsWith("/")) { server.Url = server.Url.Substring(0, server.Url.Length - 1); } } } - private static string BuildUrl(string scheme, string host, string basePath) + private static string BuildUrl(string? scheme, string? host, string? basePath) { if (string.IsNullOrEmpty(scheme) && !string.IsNullOrEmpty(host)) { @@ -201,9 +204,12 @@ private static string BuildUrl(string scheme, string host, string basePath) if (!String.IsNullOrEmpty(host) && host.Contains(':')) #endif { - var pieces = host.Split(':'); - host = pieces.First(); - port = int.Parse(pieces.Last(), CultureInfo.InvariantCulture); + var pieces = host?.Split(':'); + if (pieces is not null) + { + host = pieces[0]; + port = int.Parse(pieces[0], CultureInfo.InvariantCulture); + } } var uriBuilder = new UriBuilder @@ -252,12 +258,12 @@ public static OpenApiDocument LoadOpenApi(RootNode rootNode) FixRequestBodyReferences(openApiDoc); // Register components - openApiDoc.Workspace.RegisterComponents(openApiDoc); + openApiDoc.Workspace?.RegisterComponents(openApiDoc); return openApiDoc; } - private static void ProcessResponsesMediaTypes(MapNode mapNode, IEnumerable responses, ParsingContext context) + private static void ProcessResponsesMediaTypes(MapNode mapNode, IEnumerable? responses, ParsingContext context) { if (responses != null) { @@ -280,9 +286,9 @@ private static void FixRequestBodyReferences(OpenApiDocument doc) { // Walk all unresolved parameter references // if id matches with request body Id, change type - if (doc.Components?.RequestBodies is {Count: > 0}) + if (doc.Components?.RequestBodies != null && doc.Components?.RequestBodies is { Count: > 0 }) { - var fixer = new RequestBodyReferenceFixer(doc.Components?.RequestBodies); + var fixer = new RequestBodyReferenceFixer(doc.Components.RequestBodies); var walker = new OpenApiWalker(fixer); walker.Walk(doc); } @@ -312,14 +318,15 @@ public RequestBodyReferenceFixer(IDictionary reques public override void Visit(OpenApiOperation operation) { - var body = operation.Parameters.OfType().FirstOrDefault( + var body = operation.Parameters?.OfType().FirstOrDefault( p => p.UnresolvedReference + && p.Reference?.Id != null && _requestBodies.ContainsKey(p.Reference.Id)); - - if (body != null) + var id = body?.Reference?.Id; + if (body != null && id is not null) { - operation.Parameters.Remove(body); - operation.RequestBody = new OpenApiRequestBodyReference(body.Reference.Id, body.Reference.HostDocument); + operation.Parameters?.Remove(body); + operation.RequestBody = new OpenApiRequestBodyReference(id, body.Reference?.HostDocument); } } } diff --git a/src/Microsoft.OpenApi/Reader/V2/OpenApiExternalDocsDeserializer.cs b/src/Microsoft.OpenApi/Reader/V2/OpenApiExternalDocsDeserializer.cs index 312313585..e92bfe4f1 100644 --- a/src/Microsoft.OpenApi/Reader/V2/OpenApiExternalDocsDeserializer.cs +++ b/src/Microsoft.OpenApi/Reader/V2/OpenApiExternalDocsDeserializer.cs @@ -19,11 +19,25 @@ internal static partial class OpenApiV2Deserializer { { OpenApiConstants.Description, - (o, n, _) => o.Description = n.GetScalarValue() + (o, n, _) => + { + var description = n.GetScalarValue(); + if (description != null) + { + o.Description = n.GetScalarValue(); + } + } }, { OpenApiConstants.Url, - (o, n, _) => o.Url = new(n.GetScalarValue(), UriKind.RelativeOrAbsolute) + (o, n, _) => + { + var url = n.GetScalarValue(); + if (url != null) + { + o.Url = new(url, UriKind.RelativeOrAbsolute); + } + } }, }; diff --git a/src/Microsoft.OpenApi/Reader/V2/OpenApiHeaderDeserializer.cs b/src/Microsoft.OpenApi/Reader/V2/OpenApiHeaderDeserializer.cs index 9c712b0a3..30c60ae87 100644 --- a/src/Microsoft.OpenApi/Reader/V2/OpenApiHeaderDeserializer.cs +++ b/src/Microsoft.OpenApi/Reader/V2/OpenApiHeaderDeserializer.cs @@ -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; @@ -25,7 +25,14 @@ internal static partial class OpenApiV2Deserializer }, { "type", - (o, n, _) => GetOrCreateSchema(o).Type = n.GetScalarValue().ToJsonSchemaType() + (o, n, _) => + { + var type = n.GetScalarValue(); + if (type != null) + { + GetOrCreateSchema(o).Type = type.ToJsonSchemaType(); + } + } }, { "format", @@ -37,7 +44,14 @@ internal static partial class OpenApiV2Deserializer }, { "collectionFormat", - (o, n, _) => LoadStyle(o, n.GetScalarValue()) + (o, n, _) => + { + var collectionFormat = n.GetScalarValue(); + if (collectionFormat != null) + { + LoadStyle(o, collectionFormat); + } + } }, { "default", @@ -45,27 +59,69 @@ internal static partial class OpenApiV2Deserializer }, { "maximum", - (o, n, _) => GetOrCreateSchema(o).Maximum = ParserHelper.ParseDecimalWithFallbackOnOverflow(n.GetScalarValue(), decimal.MaxValue) + (o, n, _) => + { + var max = n.GetScalarValue(); + if (max != null) + { + GetOrCreateSchema(o).Maximum = ParserHelper.ParseDecimalWithFallbackOnOverflow(max, decimal.MaxValue); + } + } }, { "exclusiveMaximum", - (o, n, _) => GetOrCreateSchema(o).ExclusiveMaximum = bool.Parse(n.GetScalarValue()) + (o, n, _) => + { + var scalarValue = n.GetScalarValue(); + if (scalarValue is not null) + { + GetOrCreateSchema(o).ExclusiveMaximum = bool.Parse(scalarValue); + } + } }, { "minimum", - (o, n, _) => GetOrCreateSchema(o).Minimum = ParserHelper.ParseDecimalWithFallbackOnOverflow(n.GetScalarValue(), decimal.MinValue) + (o, n, _) => + { + var min = n.GetScalarValue(); + if (min != null) + { + GetOrCreateSchema(o).Minimum = ParserHelper.ParseDecimalWithFallbackOnOverflow(min, decimal.MinValue); + } + } }, { "exclusiveMinimum", - (o, n, _) => GetOrCreateSchema(o).ExclusiveMinimum = bool.Parse(n.GetScalarValue()) + (o, n, _) => + { + var exMin = n.GetScalarValue(); + if (exMin != null) + { + GetOrCreateSchema(o).ExclusiveMinimum = bool.Parse(exMin); + } + } }, { "maxLength", - (o, n, _) => GetOrCreateSchema(o).MaxLength = int.Parse(n.GetScalarValue(), CultureInfo.InvariantCulture) + (o, n, _) => + { + var maxLength = n.GetScalarValue(); + if (maxLength != null) + { + GetOrCreateSchema(o).MaxLength = int.Parse(maxLength, CultureInfo.InvariantCulture); + } + } }, { "minLength", - (o, n, _) => GetOrCreateSchema(o).MinLength = int.Parse(n.GetScalarValue(), CultureInfo.InvariantCulture) + (o, n, _) => + { + var minLength = n.GetScalarValue(); + if (minLength != null) + { + GetOrCreateSchema(o).MinLength = int.Parse(minLength, CultureInfo.InvariantCulture); + } + } }, { "pattern", @@ -73,19 +129,47 @@ internal static partial class OpenApiV2Deserializer }, { "maxItems", - (o, n, _) => GetOrCreateSchema(o).MaxItems = int.Parse(n.GetScalarValue(), CultureInfo.InvariantCulture) + (o, n, _) => + { + var maxItems = n.GetScalarValue(); + if (maxItems != null) + { + GetOrCreateSchema(o).MaxItems = int.Parse(maxItems, CultureInfo.InvariantCulture); + } + } }, { "minItems", - (o, n, _) => GetOrCreateSchema(o).MinItems = int.Parse(n.GetScalarValue(), CultureInfo.InvariantCulture) + (o, n, _) => + { + var minItems = n.GetScalarValue(); + if (minItems != null) + { + GetOrCreateSchema(o).MinItems = int.Parse(minItems, CultureInfo.InvariantCulture); + } + } }, { "uniqueItems", - (o, n, _) => GetOrCreateSchema(o).UniqueItems = bool.Parse(n.GetScalarValue()) + (o, n, _) => + { + var uniqueItems = n.GetScalarValue(); + if (uniqueItems != null) + { + GetOrCreateSchema(o).UniqueItems = bool.Parse(uniqueItems); + } + } }, { "multipleOf", - (o, n, _) => GetOrCreateSchema(o).MultipleOf = decimal.Parse(n.GetScalarValue(), CultureInfo.InvariantCulture) + (o, n, _) => + { + var multipleOf = n.GetScalarValue(); + if (multipleOf != null) + { + GetOrCreateSchema(o).MultipleOf = decimal.Parse(multipleOf, CultureInfo.InvariantCulture); + } + } }, { "enum", diff --git a/src/Microsoft.OpenApi/Reader/V2/OpenApiInfoDeserializer.cs b/src/Microsoft.OpenApi/Reader/V2/OpenApiInfoDeserializer.cs index 0d33e896c..2e5d54ed6 100644 --- a/src/Microsoft.OpenApi/Reader/V2/OpenApiInfoDeserializer.cs +++ b/src/Microsoft.OpenApi/Reader/V2/OpenApiInfoDeserializer.cs @@ -26,7 +26,14 @@ internal static partial class OpenApiV2Deserializer }, { "termsOfService", - (o, n, _) => o.TermsOfService = new(n.GetScalarValue(), UriKind.RelativeOrAbsolute) + (o, n, _) => + { + var terms = n.GetScalarValue(); + if (terms != null) + { + o.TermsOfService = new(terms, UriKind.RelativeOrAbsolute); + } + } }, { "contact", diff --git a/src/Microsoft.OpenApi/Reader/V2/OpenApiLicenseDeserializer.cs b/src/Microsoft.OpenApi/Reader/V2/OpenApiLicenseDeserializer.cs index d4a95de89..c717f7a67 100644 --- a/src/Microsoft.OpenApi/Reader/V2/OpenApiLicenseDeserializer.cs +++ b/src/Microsoft.OpenApi/Reader/V2/OpenApiLicenseDeserializer.cs @@ -22,7 +22,14 @@ internal static partial class OpenApiV2Deserializer }, { "url", - (o, n, _) => o.Url = new(n.GetScalarValue(), UriKind.RelativeOrAbsolute) + (o, n, _) => + { + var url = n.GetScalarValue(); + if (url != null) + { + o.Url = new(url, UriKind.RelativeOrAbsolute); + } + } }, }; diff --git a/src/Microsoft.OpenApi/Reader/V2/OpenApiOperationDeserializer.cs b/src/Microsoft.OpenApi/Reader/V2/OpenApiOperationDeserializer.cs index 37c95c9b2..8ae1889be 100644 --- a/src/Microsoft.OpenApi/Reader/V2/OpenApiOperationDeserializer.cs +++ b/src/Microsoft.OpenApi/Reader/V2/OpenApiOperationDeserializer.cs @@ -23,10 +23,13 @@ internal static partial class OpenApiV2Deserializer new() { { - "tags", (o, n, doc) => o.Tags = n.CreateSimpleList( + "tags", (o, n, doc) => + { + o.Tags = n.CreateSimpleList( (valueNode, doc) => LoadTagByReference( - valueNode.GetScalarValue(), doc), doc) + valueNode.GetScalarValue(), doc), doc); + } }, { "summary", @@ -47,6 +50,9 @@ internal static partial class OpenApiV2Deserializer { "parameters", (o, n, t) => o.Parameters = n.CreateList(LoadParameter, t) + .Where(p => p != null) + .Cast() + .ToList() }, { "consumes", (_, n, doc) => { @@ -70,7 +76,14 @@ internal static partial class OpenApiV2Deserializer }, { "deprecated", - (o, n, _) => o.Deprecated = bool.Parse(n.GetScalarValue()) + (o, n, _) => + { + var deprecated = n.GetScalarValue(); + if (deprecated != null) + { + o.Deprecated = bool.Parse(deprecated); + } + } }, { "security", @@ -122,10 +135,14 @@ internal static OpenApiOperation LoadOperation(ParseNode node, OpenApiDocument h } } - foreach (var response in operation.Responses.Values.OfType()) + var responses = operation.Responses; + if (responses is not null) { - ProcessProduces(node.CheckMapNode("responses"), response, node.Context); - } + foreach (var response in responses.Values.OfType()) + { + ProcessProduces(node.CheckMapNode("responses"), response, node.Context); + } + } // Reset so that it's not picked up later node.Context.SetTempStorage(TempStorageKeys.OperationProduces, null); @@ -150,11 +167,13 @@ private static OpenApiRequestBody CreateFormBody(ParsingContext context, List k.Name, - v => + Properties = formParameters + .Where(p => p.Name != null) + .ToDictionary( + k => k.Name!, + v => { - var schema = v.Schema.CreateShallowCopy(); + var schema = v.Schema!.CreateShallowCopy(); schema.Description = v.Description; if (schema is OpenApiSchema openApiSchema) { @@ -162,7 +181,7 @@ private static OpenApiRequestBody CreateFormBody(ParsingContext context, List(formParameters.Where(static p => p.Required).Select(static p => p.Name), StringComparer.Ordinal) + Required = new HashSet(formParameters.Where(static p => p.Required).Select(static p => p.Name!).Where(static name => name != null), StringComparer.Ordinal) } }; @@ -177,8 +196,14 @@ private static OpenApiRequestBody CreateFormBody(ParsingContext context, List mediaType) }; - foreach (var value in formBody.Content.Values.Where(static x => x.Schema is not null && x.Schema.Properties.Any() && x.Schema.Type == null).Select(static x => x.Schema).OfType()) + foreach (var value in formBody.Content.Values + .Where(static x => x.Schema is not null + && x.Schema.Properties is not null + && x.Schema.Properties.Any() + && x.Schema.Type == null).Select(static x => x.Schema).OfType()) + { value.Type = JsonSchemaType.Object; + } return formBody; } @@ -205,12 +230,15 @@ internal static IOpenApiRequestBody CreateRequestBody( Extensions = bodyParameter.Extensions }; - requestBody.Extensions[OpenApiConstants.BodyName] = new OpenApiAny(bodyParameter.Name); + if (requestBody.Extensions is not null) + { + requestBody.Extensions[OpenApiConstants.BodyName] = new OpenApiAny(bodyParameter.Name); + } return requestBody; } private static OpenApiTagReference LoadTagByReference( - string tagName, OpenApiDocument hostDocument) + string? tagName, OpenApiDocument hostDocument) { return new OpenApiTagReference(tagName, hostDocument); } diff --git a/src/Microsoft.OpenApi/Reader/V2/OpenApiParameterDeserializer.cs b/src/Microsoft.OpenApi/Reader/V2/OpenApiParameterDeserializer.cs index 267ba24d7..d7ce64d64 100644 --- a/src/Microsoft.OpenApi/Reader/V2/OpenApiParameterDeserializer.cs +++ b/src/Microsoft.OpenApi/Reader/V2/OpenApiParameterDeserializer.cs @@ -35,19 +35,47 @@ internal static partial class OpenApiV2Deserializer }, { "required", - (o, n, t) => o.Required = bool.Parse(n.GetScalarValue()) + (o, n, t) => + { + var required = n.GetScalarValue(); + if (required != null) + { + o.Required = bool.Parse(required); + } + } }, { "deprecated", - (o, n, t) => o.Deprecated = bool.Parse(n.GetScalarValue()) + (o, n, t) => + { + var deprecated = n.GetScalarValue(); + if (deprecated != null) + { + o.Deprecated = bool.Parse(deprecated); + } + } }, { "allowEmptyValue", - (o, n, t) => o.AllowEmptyValue = bool.Parse(n.GetScalarValue()) + (o, n, t) => + { + var allowEmptyValue = n.GetScalarValue(); + if (allowEmptyValue != null) + { + o.AllowEmptyValue = bool.Parse(allowEmptyValue); + } + } }, { "type", - (o, n, t) => GetOrCreateSchema(o).Type = n.GetScalarValue().ToJsonSchemaType() + (o, n, t) => + { + var type = n.GetScalarValue(); + if (type != null) + { + GetOrCreateSchema(o).Type = type.ToJsonSchemaType(); + } + } }, { "items", @@ -55,7 +83,14 @@ internal static partial class OpenApiV2Deserializer }, { "collectionFormat", - (o, n, t) => LoadStyle(o, n.GetScalarValue()) + (o, n, t) => + { + var collectionFormat = n.GetScalarValue(); + if (collectionFormat != null) + { + LoadStyle(o, collectionFormat); + } + } }, { "format", @@ -63,23 +98,58 @@ internal static partial class OpenApiV2Deserializer }, { "minimum", - (o, n, t) => GetOrCreateSchema(o).Minimum = ParserHelper.ParseDecimalWithFallbackOnOverflow(n.GetScalarValue(), decimal.MinValue) + (o, n, t) => + { + var min = n.GetScalarValue(); + if (min != null) + { + GetOrCreateSchema(o).Minimum = ParserHelper.ParseDecimalWithFallbackOnOverflow(min, decimal.MinValue); + } + } }, { "maximum", - (o, n, t) => GetOrCreateSchema(o).Maximum = ParserHelper.ParseDecimalWithFallbackOnOverflow(n.GetScalarValue(), decimal.MaxValue) + (o, n, t) => + { + var max = n.GetScalarValue(); + if (max != null) + { + GetOrCreateSchema(o).Maximum = ParserHelper.ParseDecimalWithFallbackOnOverflow(max, decimal.MaxValue); + } + } }, { "maxLength", - (o, n, t) => GetOrCreateSchema(o).MaxLength = int.Parse(n.GetScalarValue(), CultureInfo.InvariantCulture) + (o, n, t) => + { + var maxLength = n.GetScalarValue(); + if (maxLength != null) + { + GetOrCreateSchema(o).MaxLength = int.Parse(maxLength, CultureInfo.InvariantCulture); + } + } }, { "minLength", - (o, n, t) => GetOrCreateSchema(o).MinLength = int.Parse(n.GetScalarValue(), CultureInfo.InvariantCulture) + (o, n, t) => + { + var minLength = n.GetScalarValue(); + if (minLength != null) + { + GetOrCreateSchema(o).MinLength = int.Parse(minLength, CultureInfo.InvariantCulture); + } + } }, { "readOnly", - (o, n, t) => GetOrCreateSchema(o).ReadOnly = bool.Parse(n.GetScalarValue()) + (o, n, t) => + { + var readOnly = n.GetScalarValue(); + if (readOnly != null) + { + GetOrCreateSchema(o).ReadOnly = bool.Parse(readOnly); + } + } }, { "default", @@ -187,12 +257,12 @@ private static void ProcessIn(OpenApiParameter o, ParseNode n, OpenApiDocument h } } - public static IOpenApiParameter LoadParameter(ParseNode node, OpenApiDocument hostDocument) + public static IOpenApiParameter? LoadParameter(ParseNode node, OpenApiDocument hostDocument) { return LoadParameter(node, false, hostDocument); } - public static IOpenApiParameter LoadParameter(ParseNode node, bool loadRequestBody, OpenApiDocument hostDocument) + public static IOpenApiParameter? LoadParameter(ParseNode node, bool loadRequestBody, OpenApiDocument hostDocument) { // Reset the local variables every time this method is called. node.Context.SetTempStorage(TempStorageKeys.ParameterIsBodyOrFormData, false); @@ -226,7 +296,13 @@ public static IOpenApiParameter LoadParameter(ParseNode node, bool loadRequestBo node.Context.SetTempStorage("examples", null); } - var isBodyOrFormData = (bool)node.Context.GetFromTempStorage(TempStorageKeys.ParameterIsBodyOrFormData); + var isBodyOrFormData = false; + var paramData = node.Context.GetFromTempStorage(TempStorageKeys.ParameterIsBodyOrFormData); + if (paramData is not null) + { + isBodyOrFormData = (bool)paramData; + } + if (isBodyOrFormData && !loadRequestBody) { return null; // Don't include Form or Body parameters when normal parameters are loaded. diff --git a/src/Microsoft.OpenApi/Reader/V2/OpenApiPathItemDeserializer.cs b/src/Microsoft.OpenApi/Reader/V2/OpenApiPathItemDeserializer.cs index b1e0da7a8..c5a70563e 100644 --- a/src/Microsoft.OpenApi/Reader/V2/OpenApiPathItemDeserializer.cs +++ b/src/Microsoft.OpenApi/Reader/V2/OpenApiPathItemDeserializer.cs @@ -6,6 +6,7 @@ using System.Linq; using Microsoft.OpenApi.Extensions; using Microsoft.OpenApi.Models; +using Microsoft.OpenApi.Models.Interfaces; using Microsoft.OpenApi.Reader.ParseNodes; namespace Microsoft.OpenApi.Reader.V2 @@ -53,11 +54,14 @@ private static void LoadPathParameters(OpenApiPathItem pathItem, ParseNode node, node.Context.SetTempStorage(TempStorageKeys.BodyParameter, null); node.Context.SetTempStorage(TempStorageKeys.FormParameters, null); - pathItem.Parameters = node.CreateList(LoadParameter, hostDocument); + pathItem.Parameters = node.CreateList(LoadParameter, hostDocument) + .Where(p => p != null) + .Cast() + .ToList(); // Build request body based on information determined while parsing OpenApiOperation var bodyParameter = node.Context.GetFromTempStorage(TempStorageKeys.BodyParameter); - if (bodyParameter != null) + if (bodyParameter is not null && pathItem.Operations is not null) { var requestBody = CreateRequestBody(node.Context, bodyParameter); foreach (var opPair in pathItem.Operations.Where(x => x.Value.RequestBody is null)) @@ -75,7 +79,7 @@ private static void LoadPathParameters(OpenApiPathItem pathItem, ParseNode node, else { var formParameters = node.Context.GetFromTempStorage>(TempStorageKeys.FormParameters); - if (formParameters != null) + if (formParameters is not null && pathItem.Operations is not null) { var requestBody = CreateFormBody(node.Context, formParameters); foreach (var opPair in pathItem.Operations.Where(x => x.Value.RequestBody is null)) diff --git a/src/Microsoft.OpenApi/Reader/V2/OpenApiResponseDeserializer.cs b/src/Microsoft.OpenApi/Reader/V2/OpenApiResponseDeserializer.cs index 514ed0b44..50c569ea4 100644 --- a/src/Microsoft.OpenApi/Reader/V2/OpenApiResponseDeserializer.cs +++ b/src/Microsoft.OpenApi/Reader/V2/OpenApiResponseDeserializer.cs @@ -196,12 +196,14 @@ public static IOpenApiResponse LoadResponse(ParseNode node, OpenApiDocument host { property.ParseField(response, _responseFixedFields, _responsePatternFields, hostDocument); } - - foreach (var mediaType in response.Content.Values) + if (response.Content?.Values is not null) { - if (mediaType.Schema != null) + foreach (var mediaType in response.Content.Values) { - ProcessAnyFields(mapNode, mediaType, _mediaTypeAnyFields); + if (mediaType.Schema != null) + { + ProcessAnyFields(mapNode, mediaType, _mediaTypeAnyFields); + } } } diff --git a/src/Microsoft.OpenApi/Reader/V2/OpenApiSchemaDeserializer.cs b/src/Microsoft.OpenApi/Reader/V2/OpenApiSchemaDeserializer.cs index 42575e394..f235d33cf 100644 --- a/src/Microsoft.OpenApi/Reader/V2/OpenApiSchemaDeserializer.cs +++ b/src/Microsoft.OpenApi/Reader/V2/OpenApiSchemaDeserializer.cs @@ -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.Collections.Generic; @@ -9,6 +9,7 @@ using Microsoft.OpenApi.Models.References; using Microsoft.OpenApi.Models.Interfaces; using System; +using System.Linq; namespace Microsoft.OpenApi.Reader.V2 { @@ -26,31 +27,80 @@ internal static partial class OpenApiV2Deserializer }, { "multipleOf", - (o, n, _) => o.MultipleOf = decimal.Parse(n.GetScalarValue(), NumberStyles.Float, CultureInfo.InvariantCulture) + (o, n, _) => + { + var multipleOf = n.GetScalarValue(); + if (multipleOf != null) + { + o.MultipleOf = decimal.Parse(multipleOf, NumberStyles.Float, CultureInfo.InvariantCulture); + } + } }, { "maximum", - (o, n,_) => o.Maximum = ParserHelper.ParseDecimalWithFallbackOnOverflow(n.GetScalarValue(), decimal.MaxValue) + (o, n,_) => + { + var max = n.GetScalarValue(); + if (max != null) + { + o.Maximum = ParserHelper.ParseDecimalWithFallbackOnOverflow(max, decimal.MaxValue); + } + } }, { "exclusiveMaximum", - (o, n, _) => o.ExclusiveMaximum = bool.Parse(n.GetScalarValue()) + (o, n, _) => + { + var exMax = n.GetScalarValue(); + if (exMax != null) + { + o.ExclusiveMaximum = bool.Parse(exMax); + } + } }, { "minimum", - (o, n, _) => o.Minimum = ParserHelper.ParseDecimalWithFallbackOnOverflow(n.GetScalarValue(), decimal.MinValue) + (o, n, _) => + { + var min = n.GetScalarValue(); + if (min != null) + { + o.Minimum = ParserHelper.ParseDecimalWithFallbackOnOverflow(min, decimal.MinValue); + } + } }, { "exclusiveMinimum", - (o, n, _) => o.ExclusiveMinimum = bool.Parse(n.GetScalarValue()) + (o, n, _) => + { + var exMin = n.GetScalarValue(); + if (exMin != null) + { + o.ExclusiveMinimum = bool.Parse(exMin); + } + } }, { "maxLength", - (o, n, _) => o.MaxLength = int.Parse(n.GetScalarValue(), CultureInfo.InvariantCulture) + (o, n, _) => + { + var maxLength = n.GetScalarValue(); + if (maxLength != null) + { + o.MaxLength = int.Parse(maxLength, CultureInfo.InvariantCulture); + } + } }, { "minLength", - (o, n, _) => o.MinLength = int.Parse(n.GetScalarValue(), CultureInfo.InvariantCulture) + (o, n, _) => + { + var minLength = n.GetScalarValue(); + if (minLength != null) + { + o.MinLength = int.Parse(minLength, CultureInfo.InvariantCulture); + } + } }, { "pattern", @@ -58,27 +108,68 @@ internal static partial class OpenApiV2Deserializer }, { "maxItems", - (o, n, _) => o.MaxItems = int.Parse(n.GetScalarValue(), CultureInfo.InvariantCulture) + (o, n, _) => + { + var maxItems = n.GetScalarValue(); + if (maxItems != null) + { + o.MaxItems = int.Parse(maxItems, CultureInfo.InvariantCulture); + } + } }, { "minItems", - (o, n, _) => o.MinItems = int.Parse(n.GetScalarValue(), CultureInfo.InvariantCulture) + (o, n, _) => + { + var minItems = n.GetScalarValue(); + if (minItems != null) + { + o.MinItems = int.Parse(minItems, CultureInfo.InvariantCulture); + } + } }, { "uniqueItems", - (o, n, _) => o.UniqueItems = bool.Parse(n.GetScalarValue()) + (o, n, _) => + { + var uniqueItems = n.GetScalarValue(); + if (uniqueItems != null) + { + o.UniqueItems = bool.Parse(uniqueItems); + } + } }, { "maxProperties", - (o, n, _) => o.MaxProperties = int.Parse(n.GetScalarValue(), CultureInfo.InvariantCulture) + (o, n, _) => + { + var maxProps = n.GetScalarValue(); + if (maxProps != null) + { + o.MaxProperties = int.Parse(maxProps, CultureInfo.InvariantCulture); + } + } }, { "minProperties", - (o, n, _) => o.MinProperties = int.Parse(n.GetScalarValue(), CultureInfo.InvariantCulture) + (o, n, _) => + { + var minProps = n.GetScalarValue(); + if (minProps != null) + { + o.MinProperties = int.Parse(minProps, CultureInfo.InvariantCulture); + } + } }, { "required", - (o, n, doc) => o.Required = new HashSet(n.CreateSimpleList((n2, p) => n2.GetScalarValue(), doc)) + (o, n, doc) => + { + o.Required = new HashSet( + n.CreateSimpleList((n2, p) => + n2.GetScalarValue(), doc) + .Where(s => s != null)!); + } }, { "enum", @@ -87,7 +178,14 @@ internal static partial class OpenApiV2Deserializer { "type", - (o, n, _) => o.Type = n.GetScalarValue().ToJsonSchemaType() + (o, n, _) => + { + var type = n.GetScalarValue(); + if (type != null) + { + o.Type = type.ToJsonSchemaType(); + } + } }, { "allOf", @@ -106,7 +204,11 @@ internal static partial class OpenApiV2Deserializer { if (n is ValueNode) { - o.AdditionalPropertiesAllowed = bool.Parse(n.GetScalarValue()); + var value = n.GetScalarValue(); + if (value is not null) + { + o.AdditionalPropertiesAllowed = bool.Parse(value); + } } else { @@ -137,7 +239,14 @@ internal static partial class OpenApiV2Deserializer }, { "readOnly", - (o, n, _) => o.ReadOnly = bool.Parse(n.GetScalarValue()) + (o, n, _) => + { + var readOnly = n.GetScalarValue(); + if (readOnly is not null) + { + o.ReadOnly = bool.Parse(readOnly); + } + } }, { "xml", diff --git a/src/Microsoft.OpenApi/Reader/V2/OpenApiSecurityRequirementDeserializer.cs b/src/Microsoft.OpenApi/Reader/V2/OpenApiSecurityRequirementDeserializer.cs index 7b47ff6c5..214b26769 100644 --- a/src/Microsoft.OpenApi/Reader/V2/OpenApiSecurityRequirementDeserializer.cs +++ b/src/Microsoft.OpenApi/Reader/V2/OpenApiSecurityRequirementDeserializer.cs @@ -1,6 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. +using System.Linq; using Microsoft.OpenApi.Models; using Microsoft.OpenApi.Models.Interfaces; using Microsoft.OpenApi.Models.References; @@ -26,7 +27,10 @@ public static OpenApiSecurityRequirement LoadSecurityRequirement(ParseNode node, hostDocument, property.Name); - var scopes = property.Value.CreateSimpleList((n2, p) => n2.GetScalarValue(), hostDocument); + var scopes = property.Value.CreateSimpleList((n2, p) => n2.GetScalarValue(), hostDocument) + .Where(scope => scope != null) + .Cast() + .ToList(); if (scheme != null) { diff --git a/src/Microsoft.OpenApi/Reader/V2/OpenApiSecuritySchemeDeserializer.cs b/src/Microsoft.OpenApi/Reader/V2/OpenApiSecuritySchemeDeserializer.cs index 0dc329f43..af9ff89f9 100644 --- a/src/Microsoft.OpenApi/Reader/V2/OpenApiSecuritySchemeDeserializer.cs +++ b/src/Microsoft.OpenApi/Reader/V2/OpenApiSecuritySchemeDeserializer.cs @@ -1,7 +1,8 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. +// Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. using System; +using System.Linq; using Microsoft.OpenApi.Extensions; using Microsoft.OpenApi.Models; using Microsoft.OpenApi.Models.Interfaces; @@ -15,9 +16,9 @@ namespace Microsoft.OpenApi.Reader.V2 /// internal static partial class OpenApiV2Deserializer { - private static string _flowValue; + private static string? _flowValue; - private static OpenApiOAuthFlow _flow; + private static OpenApiOAuthFlow? _flow; private static readonly FixedFieldMap _securitySchemeFixedFields = new() @@ -50,7 +51,7 @@ internal static partial class OpenApiV2Deserializer }, {"description", (o, n, _) => o.Description = n.GetScalarValue()}, {"name", (o, n, _) => o.Name = n.GetScalarValue()}, - {"in", (o, n, _) => + {"in", (o, n, _) => { if (!n.GetScalarValue().TryGetEnumFromDisplayName(n.Context, out var _in)) { @@ -64,14 +65,36 @@ internal static partial class OpenApiV2Deserializer }, { "authorizationUrl", - (_, n, _) => _flow.AuthorizationUrl = new(n.GetScalarValue(), UriKind.RelativeOrAbsolute) + (_, n, _) => + { + var scalarValue = n.GetScalarValue(); + if (_flow is not null && scalarValue is not null) + { + _flow.AuthorizationUrl = new(scalarValue, UriKind.RelativeOrAbsolute); + } + } }, { "tokenUrl", - (_, n, _) => _flow.TokenUrl = new(n.GetScalarValue(), UriKind.RelativeOrAbsolute) + (_, n, _) => + { + var scalarValue = n.GetScalarValue(); + if (_flow is not null && scalarValue is not null) + { + _flow.TokenUrl = new(scalarValue, UriKind.RelativeOrAbsolute); + } + } }, { - "scopes", (_, n, _) => _flow.Scopes = n.CreateSimpleMap(LoadString) + "scopes", (_, n, _) => + { + if (_flow is not null) + { + _flow.Scopes = n.CreateSimpleMap(LoadString) + .Where(kv => kv.Value != null) + .ToDictionary(kv => kv.Key, kv => kv.Value!); + } + } } }; diff --git a/src/Microsoft.OpenApi/Reader/V2/OpenApiV2Deserializer.cs b/src/Microsoft.OpenApi/Reader/V2/OpenApiV2Deserializer.cs index 83505670d..692c5c81e 100644 --- a/src/Microsoft.OpenApi/Reader/V2/OpenApiV2Deserializer.cs +++ b/src/Microsoft.OpenApi/Reader/V2/OpenApiV2Deserializer.cs @@ -20,12 +20,12 @@ namespace Microsoft.OpenApi.Reader.V2 internal static partial class OpenApiV2Deserializer { private static void ParseMap( - MapNode mapNode, + MapNode? mapNode, T domainObject, FixedFieldMap fixedFieldMap, PatternFieldMap patternFieldMap, - List requiredFields = null, - OpenApiDocument doc = null) + List? requiredFields = null, + OpenApiDocument? doc = null) { if (mapNode == null) { @@ -80,7 +80,7 @@ public static JsonNode LoadAny(ParseNode node, OpenApiDocument hostDocument) private static IOpenApiExtension LoadExtension(string name, ParseNode node) { - if (node.Context.ExtensionParsers.TryGetValue(name, out var parser)) + if (node.Context.ExtensionParsers is not null && node.Context.ExtensionParsers.TryGetValue(name, out var parser)) { return parser(node.CreateAny(), OpenApiSpecVersion.OpenApi2_0); } @@ -90,18 +90,18 @@ private static IOpenApiExtension LoadExtension(string name, ParseNode node) } } - private static string LoadString(ParseNode node) + private static string? LoadString(ParseNode node) { return node.GetScalarValue(); } - private static (string, string) GetReferenceIdAndExternalResource(string pointer) + private static (string, string?) GetReferenceIdAndExternalResource(string pointer) { var refSegments = pointer.Split('/'); - var refId = refSegments.Last(); - var isExternalResource = !refSegments.First().StartsWith("#", StringComparison.OrdinalIgnoreCase); + var refId = refSegments[refSegments.Count() -1]; + var isExternalResource = !refSegments[0].StartsWith("#", StringComparison.OrdinalIgnoreCase); - string externalResource = isExternalResource ? $"{refSegments.First()}/{refSegments[1].TrimEnd('#')}" : null; + string? externalResource = isExternalResource ? $"{refSegments[0]}/{refSegments[1].TrimEnd('#')}" : null; return (refId, externalResource); } diff --git a/src/Microsoft.OpenApi/Reader/V2/OpenApiV2VersionService.cs b/src/Microsoft.OpenApi/Reader/V2/OpenApiV2VersionService.cs index c4186bb25..15dfaa4cb 100644 --- a/src/Microsoft.OpenApi/Reader/V2/OpenApiV2VersionService.cs +++ b/src/Microsoft.OpenApi/Reader/V2/OpenApiV2VersionService.cs @@ -29,7 +29,7 @@ public OpenApiV2VersionService(OpenApiDiagnostic diagnostic) Diagnostic = diagnostic; } - private readonly Dictionary> _loaders = new() + private readonly Dictionary> _loaders = new() { [typeof(OpenApiAny)] = OpenApiV2Deserializer.LoadAny, [typeof(OpenApiContact)] = OpenApiV2Deserializer.LoadContact, @@ -125,14 +125,14 @@ private static ReferenceType GetReferenceTypeV2FromName(string referenceType) return ReferenceType.SecurityScheme; default: - throw new ArgumentException(); + throw new ArgumentException(nameof(referenceType)); } } /// /// Parse the string to a object. /// - public OpenApiReference ConvertToOpenApiReference(string reference, ReferenceType? type, string summary = null, string description = null) + public OpenApiReference? ConvertToOpenApiReference(string reference, ReferenceType? type, string? summary = null, string? description = null) { if (!string.IsNullOrWhiteSpace(reference)) { @@ -216,7 +216,7 @@ public OpenApiDocument LoadDocument(RootNode rootNode) public T LoadElement(ParseNode node, OpenApiDocument doc) where T : IOpenApiElement { - return (T)_loaders[typeof(T)](node, doc); + return (T)_loaders[typeof(T)](node, doc)!; } /// diff --git a/src/Microsoft.OpenApi/Reader/V2/OpenApiXmlDeserializer.cs b/src/Microsoft.OpenApi/Reader/V2/OpenApiXmlDeserializer.cs index 38acf840d..a1eb9ba9f 100644 --- a/src/Microsoft.OpenApi/Reader/V2/OpenApiXmlDeserializer.cs +++ b/src/Microsoft.OpenApi/Reader/V2/OpenApiXmlDeserializer.cs @@ -24,9 +24,10 @@ internal static partial class OpenApiV2Deserializer { "namespace", (o, n, _) => { - if (Uri.IsWellFormedUriString(n.GetScalarValue(), UriKind.Absolute)) + var scalarValue = n.GetScalarValue(); + if (Uri.IsWellFormedUriString(scalarValue, UriKind.Absolute) && scalarValue is not null) { - o.Namespace = new(n.GetScalarValue(), UriKind.Absolute); + o.Namespace = new(scalarValue, UriKind.Absolute); } else { @@ -40,11 +41,25 @@ internal static partial class OpenApiV2Deserializer }, { "attribute", - (o, n, _) => o.Attribute = bool.Parse(n.GetScalarValue()) + (o, n, _) => + { + var attribute = n.GetScalarValue(); + if (attribute is not null) + { + o.Attribute = bool.Parse(attribute); + } + } }, { "wrapped", - (o, n, _) => o.Wrapped = bool.Parse(n.GetScalarValue()) + (o, n, _) => + { + var wrapped = n.GetScalarValue(); + if (wrapped is not null) + { + o.Wrapped = bool.Parse(wrapped); + } + } }, }; diff --git a/src/Microsoft.OpenApi/Reader/V3/OpenApiContactDeserializer.cs b/src/Microsoft.OpenApi/Reader/V3/OpenApiContactDeserializer.cs index 7eab275c8..21b11b794 100644 --- a/src/Microsoft.OpenApi/Reader/V3/OpenApiContactDeserializer.cs +++ b/src/Microsoft.OpenApi/Reader/V3/OpenApiContactDeserializer.cs @@ -26,7 +26,14 @@ internal static partial class OpenApiV3Deserializer }, { "url", - (o, n, _) => o.Url = new(n.GetScalarValue(), UriKind.RelativeOrAbsolute) + (o, n, t) => + { + var url = n.GetScalarValue(); + if (url != null) + { + o.Url = new(url, UriKind.RelativeOrAbsolute); + } + } }, }; diff --git a/src/Microsoft.OpenApi/Reader/V3/OpenApiDiscriminatorDeserializer.cs b/src/Microsoft.OpenApi/Reader/V3/OpenApiDiscriminatorDeserializer.cs index 5f9db648e..1493283c0 100644 --- a/src/Microsoft.OpenApi/Reader/V3/OpenApiDiscriminatorDeserializer.cs +++ b/src/Microsoft.OpenApi/Reader/V3/OpenApiDiscriminatorDeserializer.cs @@ -1,6 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. +using System.Linq; using Microsoft.OpenApi.Models; using Microsoft.OpenApi.Reader.ParseNodes; @@ -21,7 +22,7 @@ internal static partial class OpenApiV3Deserializer }, { "mapping", - (o, n, _) => o.Mapping = n.CreateSimpleMap(LoadString) + (o, n, _) => o.Mapping = n.CreateSimpleMap(LoadString).Where(kv => kv.Value is not null).ToDictionary(kv => kv.Key, kv => kv.Value!) } }; diff --git a/src/Microsoft.OpenApi/Reader/V3/OpenApiDocumentDeserializer.cs b/src/Microsoft.OpenApi/Reader/V3/OpenApiDocumentDeserializer.cs index c07d28d46..1187f8cf9 100644 --- a/src/Microsoft.OpenApi/Reader/V3/OpenApiDocumentDeserializer.cs +++ b/src/Microsoft.OpenApi/Reader/V3/OpenApiDocumentDeserializer.cs @@ -45,7 +45,7 @@ public static OpenApiDocument LoadOpenApi(RootNode rootNode) ParseMap(openApiNode, openApiDoc, _openApiFixedFields, _openApiPatternFields, openApiDoc); // Register components - openApiDoc.Workspace.RegisterComponents(openApiDoc); + openApiDoc.Workspace?.RegisterComponents(openApiDoc); return openApiDoc; } diff --git a/src/Microsoft.OpenApi/Reader/V3/OpenApiEncodingDeserializer.cs b/src/Microsoft.OpenApi/Reader/V3/OpenApiEncodingDeserializer.cs index 2d324745d..c2d88936f 100644 --- a/src/Microsoft.OpenApi/Reader/V3/OpenApiEncodingDeserializer.cs +++ b/src/Microsoft.OpenApi/Reader/V3/OpenApiEncodingDeserializer.cs @@ -37,11 +37,25 @@ internal static partial class OpenApiV3Deserializer }, { "explode", - (o, n, _) => o.Explode = bool.Parse(n.GetScalarValue()) + (o, n, _) => + { + var explode = n.GetScalarValue(); + if (explode != null) + { + o.Explode = bool.Parse(explode); + } + } }, { "allowedReserved", - (o, n, _) => o.AllowReserved = bool.Parse(n.GetScalarValue()) + (o, n, _) => + { + var allowReserved = n.GetScalarValue(); + if (allowReserved != null) + { + o.AllowReserved = bool.Parse(allowReserved); + } + } }, }; diff --git a/src/Microsoft.OpenApi/Reader/V3/OpenApiExternalDocsDeserializer.cs b/src/Microsoft.OpenApi/Reader/V3/OpenApiExternalDocsDeserializer.cs index 0d8c25b05..7f357b947 100644 --- a/src/Microsoft.OpenApi/Reader/V3/OpenApiExternalDocsDeserializer.cs +++ b/src/Microsoft.OpenApi/Reader/V3/OpenApiExternalDocsDeserializer.cs @@ -24,8 +24,15 @@ internal static partial class OpenApiV3Deserializer }, { "url", - (o, n, _) => o.Url = new(n.GetScalarValue(), UriKind.RelativeOrAbsolute) - }, + (o, n, _) => + { + var url = n.GetScalarValue(); + if (url != null) + { + o.Url = new(url, UriKind.RelativeOrAbsolute); + } + } + } }; private static readonly PatternFieldMap _externalDocsPatternFields = diff --git a/src/Microsoft.OpenApi/Reader/V3/OpenApiHeaderDeserializer.cs b/src/Microsoft.OpenApi/Reader/V3/OpenApiHeaderDeserializer.cs index 94350d429..4b3318357 100644 --- a/src/Microsoft.OpenApi/Reader/V3/OpenApiHeaderDeserializer.cs +++ b/src/Microsoft.OpenApi/Reader/V3/OpenApiHeaderDeserializer.cs @@ -24,19 +24,47 @@ internal static partial class OpenApiV3Deserializer }, { "required", - (o, n, _) => o.Required = bool.Parse(n.GetScalarValue()) + (o, n, _) => + { + var required = n.GetScalarValue(); + if (required != null) + { + o.Required = bool.Parse(required); + } + } }, { "deprecated", - (o, n, _) => o.Deprecated = bool.Parse(n.GetScalarValue()) + (o, n, _) => + { + var deprecated = n.GetScalarValue(); + if (deprecated != null) + { + o.Deprecated = bool.Parse(deprecated); + } + } }, { "allowEmptyValue", - (o, n, _) => o.AllowEmptyValue = bool.Parse(n.GetScalarValue()) + (o, n, _) => + { + var allowEmptyVal = n.GetScalarValue(); + if (allowEmptyVal != null) + { + o.AllowEmptyValue = bool.Parse(allowEmptyVal); + } + } }, { "allowReserved", - (o, n, _) => o.AllowReserved = bool.Parse(n.GetScalarValue()) + (o, n, _) => + { + var allowReserved = n.GetScalarValue(); + if (allowReserved != null) + { + o.AllowReserved = bool.Parse(allowReserved); + } + } }, { "style", @@ -51,7 +79,14 @@ internal static partial class OpenApiV3Deserializer }, { "explode", - (o, n, _) => o.Explode = bool.Parse(n.GetScalarValue()) + (o, n, _) => + { + var explode = n.GetScalarValue(); + if (explode != null) + { + o.Explode = bool.Parse(explode); + } + } }, { "schema", diff --git a/src/Microsoft.OpenApi/Reader/V3/OpenApiInfoDeserializer.cs b/src/Microsoft.OpenApi/Reader/V3/OpenApiInfoDeserializer.cs index 48979439d..2686e5d1a 100644 --- a/src/Microsoft.OpenApi/Reader/V3/OpenApiInfoDeserializer.cs +++ b/src/Microsoft.OpenApi/Reader/V3/OpenApiInfoDeserializer.cs @@ -30,7 +30,14 @@ internal static partial class OpenApiV3Deserializer }, { "termsOfService", - (o, n, _) => o.TermsOfService = new(n.GetScalarValue(), UriKind.RelativeOrAbsolute) + (o, n, _) => + { + var terms = n.GetScalarValue(); + if (terms != null) + { + o.TermsOfService = new(terms, UriKind.RelativeOrAbsolute); + } + } }, { "contact", diff --git a/src/Microsoft.OpenApi/Reader/V3/OpenApiLicenseDeserializer.cs b/src/Microsoft.OpenApi/Reader/V3/OpenApiLicenseDeserializer.cs index 4ecdce151..eaf9ba24f 100644 --- a/src/Microsoft.OpenApi/Reader/V3/OpenApiLicenseDeserializer.cs +++ b/src/Microsoft.OpenApi/Reader/V3/OpenApiLicenseDeserializer.cs @@ -22,7 +22,14 @@ internal static partial class OpenApiV3Deserializer }, { "url", - (o, n, _) => o.Url = new(n.GetScalarValue(), UriKind.RelativeOrAbsolute) + (o, n, _) => + { + var url = n.GetScalarValue(); + if (url != null) + { + o.Url = new(url, UriKind.RelativeOrAbsolute); + } + } }, }; diff --git a/src/Microsoft.OpenApi/Reader/V3/OpenApiMediaTypeDeserializer.cs b/src/Microsoft.OpenApi/Reader/V3/OpenApiMediaTypeDeserializer.cs index 6fd96b38d..b0e99bd44 100644 --- a/src/Microsoft.OpenApi/Reader/V3/OpenApiMediaTypeDeserializer.cs +++ b/src/Microsoft.OpenApi/Reader/V3/OpenApiMediaTypeDeserializer.cs @@ -54,8 +54,8 @@ internal static partial class OpenApiV3Deserializer }; private static readonly AnyMapFieldMap _mediaTypeAnyMapOpenApiExampleFields = - new() - { + new() + { { OpenApiConstants.Examples, new( diff --git a/src/Microsoft.OpenApi/Reader/V3/OpenApiOAuthFlowDeserializer.cs b/src/Microsoft.OpenApi/Reader/V3/OpenApiOAuthFlowDeserializer.cs index d60cf0aa5..1771f1407 100644 --- a/src/Microsoft.OpenApi/Reader/V3/OpenApiOAuthFlowDeserializer.cs +++ b/src/Microsoft.OpenApi/Reader/V3/OpenApiOAuthFlowDeserializer.cs @@ -2,6 +2,7 @@ // Licensed under the MIT license. using System; +using System.Linq; using Microsoft.OpenApi.Extensions; using Microsoft.OpenApi.Models; using Microsoft.OpenApi.Reader.ParseNodes; @@ -19,17 +20,38 @@ internal static partial class OpenApiV3Deserializer { { "authorizationUrl", - (o, n, _) => o.AuthorizationUrl = new(n.GetScalarValue(), UriKind.RelativeOrAbsolute) + (o, n, _) => + { + var url = n.GetScalarValue(); + if (url != null) + { + o.AuthorizationUrl = new(url, UriKind.RelativeOrAbsolute); + } + } }, { "tokenUrl", - (o, n, _) => o.TokenUrl = new(n.GetScalarValue(), UriKind.RelativeOrAbsolute) + (o, n, _) => + { + var url = n.GetScalarValue(); + if (url != null) + { + o.TokenUrl = new(url, UriKind.RelativeOrAbsolute); + } + } }, { "refreshUrl", - (o, n, _) => o.RefreshUrl = new(n.GetScalarValue(), UriKind.RelativeOrAbsolute) + (o, n, _) => + { + var url = n.GetScalarValue(); + if (url != null) + { + o.RefreshUrl = new(url, UriKind.RelativeOrAbsolute); + } + } }, - {"scopes", (o, n, _) => o.Scopes = n.CreateSimpleMap(LoadString)} + {"scopes", (o, n, _) => o.Scopes = n.CreateSimpleMap(LoadString).Where(kv => kv.Value is not null).ToDictionary(kv => kv.Key, kv => kv.Value!)} }; private static readonly PatternFieldMap _oAuthFlowPatternFields = diff --git a/src/Microsoft.OpenApi/Reader/V3/OpenApiOperationDeserializer.cs b/src/Microsoft.OpenApi/Reader/V3/OpenApiOperationDeserializer.cs index e9712da98..56276ea10 100644 --- a/src/Microsoft.OpenApi/Reader/V3/OpenApiOperationDeserializer.cs +++ b/src/Microsoft.OpenApi/Reader/V3/OpenApiOperationDeserializer.cs @@ -58,7 +58,14 @@ internal static partial class OpenApiV3Deserializer }, { "deprecated", - (o, n, _) => o.Deprecated = bool.Parse(n.GetScalarValue()) + (o, n, _) => + { + var deprecated = n.GetScalarValue(); + if (deprecated != null) + { + o.Deprecated = bool.Parse(deprecated); + } + } }, { "security", @@ -88,7 +95,7 @@ internal static OpenApiOperation LoadOperation(ParseNode node, OpenApiDocument h } private static OpenApiTagReference LoadTagByReference( - string tagName, OpenApiDocument hostDocument) + string? tagName, OpenApiDocument hostDocument) { return new OpenApiTagReference(tagName, hostDocument); } diff --git a/src/Microsoft.OpenApi/Reader/V3/OpenApiParameterDeserializer.cs b/src/Microsoft.OpenApi/Reader/V3/OpenApiParameterDeserializer.cs index 7d2c5074b..33e67b953 100644 --- a/src/Microsoft.OpenApi/Reader/V3/OpenApiParameterDeserializer.cs +++ b/src/Microsoft.OpenApi/Reader/V3/OpenApiParameterDeserializer.cs @@ -39,19 +39,47 @@ internal static partial class OpenApiV3Deserializer }, { "required", - (o, n, _) => o.Required = bool.Parse(n.GetScalarValue()) + (o, n, t) => + { + var required = n.GetScalarValue(); + if (required != null) + { + o.Required = bool.Parse(required); + } + } }, { "deprecated", - (o, n, _) => o.Deprecated = bool.Parse(n.GetScalarValue()) + (o, n, t) => + { + var deprecated = n.GetScalarValue(); + if (deprecated != null) + { + o.Deprecated = bool.Parse(deprecated); + } + } }, { "allowEmptyValue", - (o, n, _) => o.AllowEmptyValue = bool.Parse(n.GetScalarValue()) + (o, n, t) => + { + var allowEmptyValue = n.GetScalarValue(); + if (allowEmptyValue != null) + { + o.AllowEmptyValue = bool.Parse(allowEmptyValue); + } + } }, { "allowReserved", - (o, n, _) => o.AllowReserved = bool.Parse(n.GetScalarValue()) + (o, n, _) => + { + var allowReserved = n.GetScalarValue(); + if (allowReserved != null) + { + o.AllowReserved = bool.Parse(allowReserved); + } + } }, { "style", @@ -66,7 +94,14 @@ internal static partial class OpenApiV3Deserializer }, { "explode", - (o, n, _) => o.Explode = bool.Parse(n.GetScalarValue()) + (o, n, _) => + { + var explode = n.GetScalarValue(); + if (explode != null) + { + o.Explode = bool.Parse(explode); + } + } }, { "schema", diff --git a/src/Microsoft.OpenApi/Reader/V3/OpenApiRequestBodyDeserializer.cs b/src/Microsoft.OpenApi/Reader/V3/OpenApiRequestBodyDeserializer.cs index ac007d813..339ca437e 100644 --- a/src/Microsoft.OpenApi/Reader/V3/OpenApiRequestBodyDeserializer.cs +++ b/src/Microsoft.OpenApi/Reader/V3/OpenApiRequestBodyDeserializer.cs @@ -29,7 +29,14 @@ internal static partial class OpenApiV3Deserializer }, { "required", - (o, n, _) => o.Required = bool.Parse(n.GetScalarValue()) + (o, n, _) => + { + var required = n.GetScalarValue(); + if (required != null) + { + o.Required = bool.Parse(required); + } + } }, }; diff --git a/src/Microsoft.OpenApi/Reader/V3/OpenApiSchemaDeserializer.cs b/src/Microsoft.OpenApi/Reader/V3/OpenApiSchemaDeserializer.cs index 25d68b477..f413d1dc2 100644 --- a/src/Microsoft.OpenApi/Reader/V3/OpenApiSchemaDeserializer.cs +++ b/src/Microsoft.OpenApi/Reader/V3/OpenApiSchemaDeserializer.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. +// Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. using Microsoft.OpenApi.Extensions; @@ -9,6 +9,7 @@ using System; using System.Collections.Generic; using System.Globalization; +using System.Linq; namespace Microsoft.OpenApi.Reader.V3 { @@ -26,31 +27,80 @@ internal static partial class OpenApiV3Deserializer }, { "multipleOf", - (o, n, _) => o.MultipleOf = decimal.Parse(n.GetScalarValue(), NumberStyles.Float, CultureInfo.InvariantCulture) + (o, n, _) => + { + var multipleOf = n.GetScalarValue(); + if (multipleOf != null) + { + o.MultipleOf = decimal.Parse(multipleOf, NumberStyles.Float, CultureInfo.InvariantCulture); + } + } }, { "maximum", - (o, n, _) => o.Maximum = ParserHelper.ParseDecimalWithFallbackOnOverflow(n.GetScalarValue(), decimal.MaxValue) + (o, n,_) => + { + var max = n.GetScalarValue(); + if (max != null) + { + o.Maximum = ParserHelper.ParseDecimalWithFallbackOnOverflow(max, decimal.MaxValue); + } + } }, { "exclusiveMaximum", - (o, n, _) => o.ExclusiveMaximum = bool.Parse(n.GetScalarValue()) + (o, n, _) => + { + var exMax = n.GetScalarValue(); + if (exMax != null) + { + o.ExclusiveMaximum = bool.Parse(exMax); + } + } }, { "minimum", - (o, n, _) => o.Minimum = ParserHelper.ParseDecimalWithFallbackOnOverflow(n.GetScalarValue(), decimal.MinValue) + (o, n, _) => + { + var min = n.GetScalarValue(); + if (min != null) + { + o.Minimum = ParserHelper.ParseDecimalWithFallbackOnOverflow(min, decimal.MinValue); + } + } }, { "exclusiveMinimum", - (o, n, _) => o.ExclusiveMinimum = bool.Parse(n.GetScalarValue()) + (o, n, _) => + { + var exMin = n.GetScalarValue(); + if (exMin != null) + { + o.ExclusiveMinimum = bool.Parse(exMin); + } + } }, { "maxLength", - (o, n, _) => o.MaxLength = int.Parse(n.GetScalarValue(), CultureInfo.InvariantCulture) + (o, n, _) => + { + var maxLength = n.GetScalarValue(); + if (maxLength != null) + { + o.MaxLength = int.Parse(maxLength, CultureInfo.InvariantCulture); + } + } }, { "minLength", - (o, n, _) => o.MinLength = int.Parse(n.GetScalarValue(), CultureInfo.InvariantCulture) + (o, n, _) => + { + var minLength = n.GetScalarValue(); + if (minLength != null) + { + o.MinLength = int.Parse(minLength, CultureInfo.InvariantCulture); + } + } }, { "pattern", @@ -58,27 +108,62 @@ internal static partial class OpenApiV3Deserializer }, { "maxItems", - (o, n, _) => o.MaxItems = int.Parse(n.GetScalarValue(), CultureInfo.InvariantCulture) + (o, n, _) => + { + var maxItems = n.GetScalarValue(); + if (maxItems != null) + { + o.MaxItems = int.Parse(maxItems, CultureInfo.InvariantCulture); + } + } }, { "minItems", - (o, n, _) => o.MinItems = int.Parse(n.GetScalarValue(), CultureInfo.InvariantCulture) + (o, n, _) => + { + var minItems = n.GetScalarValue(); + if (minItems != null) + { + o.MinItems = int.Parse(minItems, CultureInfo.InvariantCulture); + } + } }, { "uniqueItems", - (o, n, _) => o.UniqueItems = bool.Parse(n.GetScalarValue()) + (o, n, _) => + { + var uniqueItems = n.GetScalarValue(); + if (uniqueItems != null) + { + o.UniqueItems = bool.Parse(uniqueItems); + } + } }, { "maxProperties", - (o, n, _) => o.MaxProperties = int.Parse(n.GetScalarValue(), CultureInfo.InvariantCulture) + (o, n, _) => + { + var maxProps = n.GetScalarValue(); + if (maxProps != null) + { + o.MaxProperties = int.Parse(maxProps, CultureInfo.InvariantCulture); + } + } }, { "minProperties", - (o, n, _) => o.MinProperties = int.Parse(n.GetScalarValue(), CultureInfo.InvariantCulture) + (o, n, _) => + { + var minProps = n.GetScalarValue(); + if (minProps != null) + { + o.MinProperties = int.Parse(minProps, CultureInfo.InvariantCulture); + } + } }, { "required", - (o, n, doc) => o.Required = new HashSet(n.CreateSimpleList((n2, p) => n2.GetScalarValue(), doc)) + (o, n, doc) => o.Required = new HashSet(n.CreateSimpleList((n2, p) => n2.GetScalarValue(), doc).Where(s => s != null)!) }, { "enum", @@ -87,7 +172,7 @@ internal static partial class OpenApiV3Deserializer { "type", (o, n, _) => { - var type = n.GetScalarValue().ToJsonSchemaType(); + var type = n.GetScalarValue()?.ToJsonSchemaType(); // so we don't loose the value from nullable if (o.Type.HasValue) o.Type |= type; @@ -124,7 +209,11 @@ internal static partial class OpenApiV3Deserializer { if (n is ValueNode) { - o.AdditionalPropertiesAllowed = bool.Parse(n.GetScalarValue()); + var value = n.GetScalarValue(); + if (value is not null) + { + o.AdditionalPropertiesAllowed = bool.Parse(value); + } } else { @@ -163,11 +252,25 @@ internal static partial class OpenApiV3Deserializer }, { "readOnly", - (o, n, _) => o.ReadOnly = bool.Parse(n.GetScalarValue()) + (o, n, _) => + { + var readOnly = n.GetScalarValue(); + if (readOnly != null) + { + o.ReadOnly = bool.Parse(readOnly); + } + } }, { "writeOnly", - (o, n, _) => o.WriteOnly = bool.Parse(n.GetScalarValue()) + (o, n, _) => + { + var writeOnly = n.GetScalarValue(); + if (writeOnly != null) + { + o.WriteOnly = bool.Parse(writeOnly); + } + } }, { "xml", @@ -183,7 +286,14 @@ internal static partial class OpenApiV3Deserializer }, { "deprecated", - (o, n, _) => o.Deprecated = bool.Parse(n.GetScalarValue()) + (o, n, t) => + { + var deprecated = n.GetScalarValue(); + if (deprecated != null) + { + o.Deprecated = bool.Parse(deprecated); + } + } }, }; diff --git a/src/Microsoft.OpenApi/Reader/V3/OpenApiSecurityRequirementDeserializer.cs b/src/Microsoft.OpenApi/Reader/V3/OpenApiSecurityRequirementDeserializer.cs index 030f2ef34..0250adcc1 100644 --- a/src/Microsoft.OpenApi/Reader/V3/OpenApiSecurityRequirementDeserializer.cs +++ b/src/Microsoft.OpenApi/Reader/V3/OpenApiSecurityRequirementDeserializer.cs @@ -1,6 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. +using System.Linq; using Microsoft.OpenApi.Models; using Microsoft.OpenApi.Models.Interfaces; using Microsoft.OpenApi.Models.References; @@ -24,7 +25,10 @@ public static OpenApiSecurityRequirement LoadSecurityRequirement(ParseNode node, { var scheme = LoadSecuritySchemeByReference(hostDocument, property.Name); - var scopes = property.Value.CreateSimpleList((value, p) => value.GetScalarValue(), hostDocument); + var scopes = property.Value.CreateSimpleList((n2, p) => n2.GetScalarValue(), hostDocument) + .Where(scope => scope != null) + .Cast() + .ToList(); if (scheme != null) { diff --git a/src/Microsoft.OpenApi/Reader/V3/OpenApiSecuritySchemeDeserializer.cs b/src/Microsoft.OpenApi/Reader/V3/OpenApiSecuritySchemeDeserializer.cs index 993279f1e..b01ece23f 100644 --- a/src/Microsoft.OpenApi/Reader/V3/OpenApiSecuritySchemeDeserializer.cs +++ b/src/Microsoft.OpenApi/Reader/V3/OpenApiSecuritySchemeDeserializer.cs @@ -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; @@ -59,7 +59,14 @@ internal static partial class OpenApiV3Deserializer }, { "openIdConnectUrl", - (o, n, _) => o.OpenIdConnectUrl = new(n.GetScalarValue(), UriKind.RelativeOrAbsolute) + (o, n, _) => + { + var connectUrl = n.GetScalarValue(); + if (connectUrl != null) + { + o.OpenIdConnectUrl = new(connectUrl, UriKind.RelativeOrAbsolute); + } + } }, { "flows", diff --git a/src/Microsoft.OpenApi/Reader/V3/OpenApiServerVariableDeserializer.cs b/src/Microsoft.OpenApi/Reader/V3/OpenApiServerVariableDeserializer.cs index 3579a40b7..606dce0cf 100644 --- a/src/Microsoft.OpenApi/Reader/V3/OpenApiServerVariableDeserializer.cs +++ b/src/Microsoft.OpenApi/Reader/V3/OpenApiServerVariableDeserializer.cs @@ -2,6 +2,7 @@ // Licensed under the MIT license. using System; +using System.Linq; using Microsoft.OpenApi.Extensions; using Microsoft.OpenApi.Models; using Microsoft.OpenApi.Reader.ParseNodes; @@ -19,7 +20,7 @@ internal static partial class OpenApiV3Deserializer { { "enum", - (o, n, doc) => o.Enum = n.CreateSimpleList((s, p) => s.GetScalarValue(), doc) + (o, n, doc) => o.Enum = n.CreateSimpleList((s, p) => s.GetScalarValue(), doc).Where(e => e != null).Cast().ToList() }, { "default", diff --git a/src/Microsoft.OpenApi/Reader/V3/OpenApiV3Deserializer.cs b/src/Microsoft.OpenApi/Reader/V3/OpenApiV3Deserializer.cs index 67a9b0495..17836ce00 100644 --- a/src/Microsoft.OpenApi/Reader/V3/OpenApiV3Deserializer.cs +++ b/src/Microsoft.OpenApi/Reader/V3/OpenApiV3Deserializer.cs @@ -21,7 +21,7 @@ namespace Microsoft.OpenApi.Reader.V3 internal static partial class OpenApiV3Deserializer { private static void ParseMap( - MapNode mapNode, + MapNode? mapNode, T domainObject, FixedFieldMap fixedFieldMap, PatternFieldMap patternFieldMap, @@ -72,38 +72,6 @@ private static void ProcessAnyFields( } } - private static void ProcessAnyListFields( - MapNode mapNode, - T domainObject, - AnyListFieldMap anyListFieldMap) - { - foreach (var anyListFieldName in anyListFieldMap.Keys.ToList()) - { - try - { - var newProperty = new List(); - - mapNode.Context.StartObject(anyListFieldName); - - foreach (var propertyElement in anyListFieldMap[anyListFieldName].PropertyGetter(domainObject)) - { - newProperty.Add(propertyElement); - } - - anyListFieldMap[anyListFieldName].PropertySetter(domainObject, newProperty); - } - catch (OpenApiException exception) - { - exception.Pointer = mapNode.Context.GetLocation(); - mapNode.Context.Diagnostic.Errors.Add(new(exception)); - } - finally - { - mapNode.Context.EndObject(); - } - } - } - private static void ProcessAnyMapFields( MapNode mapNode, T domainObject, @@ -114,18 +82,23 @@ private static void ProcessAnyMapFields( try { mapNode.Context.StartObject(anyMapFieldName); - - foreach (var propertyMapElement in anyMapFieldMap[anyMapFieldName].PropertyMapGetter(domainObject)) + var mapElements = anyMapFieldMap[anyMapFieldName].PropertyMapGetter(domainObject); + if (mapElements is not null) { - mapNode.Context.StartObject(propertyMapElement.Key); - - if (propertyMapElement.Value != null) + foreach (var propertyMapElement in mapElements) { - var any = anyMapFieldMap[anyMapFieldName].PropertyGetter(propertyMapElement.Value); - - anyMapFieldMap[anyMapFieldName].PropertySetter(propertyMapElement.Value, any); + mapNode.Context.StartObject(propertyMapElement.Key); + + if (propertyMapElement.Value != null) + { + var any = anyMapFieldMap[anyMapFieldName].PropertyGetter(propertyMapElement.Value); + if (any is not null) + { + anyMapFieldMap[anyMapFieldName].PropertySetter(propertyMapElement.Value, any); + } + } } - } + } } catch (OpenApiException exception) { @@ -139,12 +112,6 @@ private static void ProcessAnyMapFields( } } - private static RuntimeExpression LoadRuntimeExpression(ParseNode node) - { - var value = node.GetScalarValue(); - return RuntimeExpression.Build(value); - } - private static RuntimeExpressionAnyWrapper LoadRuntimeExpressionAnyWrapper(ParseNode node) { var value = node.GetScalarValue(); @@ -171,7 +138,7 @@ public static OpenApiAny LoadAny(ParseNode node, OpenApiDocument hostDocument) private static IOpenApiExtension LoadExtension(string name, ParseNode node) { - if (node.Context.ExtensionParsers.TryGetValue(name, out var parser) && parser( + if (node.Context.ExtensionParsers is not null && node.Context.ExtensionParsers.TryGetValue(name, out var parser) && parser( node.CreateAny(), OpenApiSpecVersion.OpenApi3_0) is { } result) { return result; @@ -182,18 +149,18 @@ private static IOpenApiExtension LoadExtension(string name, ParseNode node) } } - private static string LoadString(ParseNode node) + private static string? LoadString(ParseNode node) { return node.GetScalarValue(); } - private static (string, string) GetReferenceIdAndExternalResource(string pointer) + private static (string, string?) GetReferenceIdAndExternalResource(string pointer) { var refSegments = pointer.Split('/'); - var refId = refSegments.Last(); - var isExternalResource = !refSegments.First().StartsWith("#", StringComparison.OrdinalIgnoreCase); + var refId = refSegments[refSegments.Count() -1]; + var isExternalResource = !refSegments[0].StartsWith("#", StringComparison.OrdinalIgnoreCase); - string externalResource = isExternalResource ? $"{refSegments.First()}/{refSegments[1].TrimEnd('#')}" : null; + string? externalResource = isExternalResource ? $"{refSegments[0]}/{refSegments[1].TrimEnd('#')}" : null; return (refId, externalResource); } diff --git a/src/Microsoft.OpenApi/Reader/V3/OpenApiV3VersionService.cs b/src/Microsoft.OpenApi/Reader/V3/OpenApiV3VersionService.cs index 612c59dfb..d2fa8e8c0 100644 --- a/src/Microsoft.OpenApi/Reader/V3/OpenApiV3VersionService.cs +++ b/src/Microsoft.OpenApi/Reader/V3/OpenApiV3VersionService.cs @@ -75,8 +75,8 @@ public OpenApiV3VersionService(OpenApiDiagnostic diagnostic) public OpenApiReference ConvertToOpenApiReference( string reference, ReferenceType? type, - string summary = null, - string description = null) + string? summary = null, + string? description = null) { if (!string.IsNullOrWhiteSpace(reference)) { @@ -181,7 +181,7 @@ public T LoadElement(ParseNode node, OpenApiDocument doc) where T : IOpenApiE } /// - public string GetReferenceScalarValues(MapNode mapNode, string scalarValue) + public string? GetReferenceScalarValues(MapNode mapNode, string scalarValue) { if (mapNode.Any(static x => !"$ref".Equals(x.Name, StringComparison.OrdinalIgnoreCase)) && mapNode diff --git a/src/Microsoft.OpenApi/Reader/V3/OpenApiXmlDeserializer.cs b/src/Microsoft.OpenApi/Reader/V3/OpenApiXmlDeserializer.cs index 43245338d..e6bc2c836 100644 --- a/src/Microsoft.OpenApi/Reader/V3/OpenApiXmlDeserializer.cs +++ b/src/Microsoft.OpenApi/Reader/V3/OpenApiXmlDeserializer.cs @@ -22,7 +22,14 @@ internal static partial class OpenApiV3Deserializer }, { "namespace", - (o, n, _) => o.Namespace = new(n.GetScalarValue(), UriKind.Absolute) + (o, n, _) => + { + var value = n.GetScalarValue(); + if (value != null) + { + o.Namespace = new(value, UriKind.Absolute); + } + } }, { "prefix", @@ -30,11 +37,25 @@ internal static partial class OpenApiV3Deserializer }, { "attribute", - (o, n, _) => o.Attribute = bool.Parse(n.GetScalarValue()) + (o, n, _) => + { + var attribute = n.GetScalarValue(); + if (attribute is not null) + { + o.Attribute = bool.Parse(attribute); + } + } }, { "wrapped", - (o, n, _) => o.Wrapped = bool.Parse(n.GetScalarValue()) + (o, n, _) => + { + var wrapped = n.GetScalarValue(); + if (wrapped is not null) + { + o.Wrapped = bool.Parse(wrapped); + } + } }, }; diff --git a/src/Microsoft.OpenApi/Reader/V31/OpenApiContactDeserializer.cs b/src/Microsoft.OpenApi/Reader/V31/OpenApiContactDeserializer.cs index be487e434..138eafe70 100644 --- a/src/Microsoft.OpenApi/Reader/V31/OpenApiContactDeserializer.cs +++ b/src/Microsoft.OpenApi/Reader/V31/OpenApiContactDeserializer.cs @@ -26,9 +26,14 @@ internal static partial class OpenApiV31Deserializer } }, { - "url", (o, n, _) => + "url", + (o, n, t) => { - o.Url = new Uri(n.GetScalarValue(), UriKind.RelativeOrAbsolute); + var url = n.GetScalarValue(); + if (url != null) + { + o.Url = new(url, UriKind.RelativeOrAbsolute); + } } }, }; diff --git a/src/Microsoft.OpenApi/Reader/V31/OpenApiDiscriminatorDeserializer.cs b/src/Microsoft.OpenApi/Reader/V31/OpenApiDiscriminatorDeserializer.cs index 0302149f6..e94f408d2 100644 --- a/src/Microsoft.OpenApi/Reader/V31/OpenApiDiscriminatorDeserializer.cs +++ b/src/Microsoft.OpenApi/Reader/V31/OpenApiDiscriminatorDeserializer.cs @@ -1,4 +1,5 @@ using System; +using System.Linq; using Microsoft.OpenApi.Extensions; using Microsoft.OpenApi.Models; using Microsoft.OpenApi.Reader.ParseNodes; @@ -23,7 +24,7 @@ internal static partial class OpenApiV31Deserializer { "mapping", (o, n, _) => { - o.Mapping = n.CreateSimpleMap(LoadString); + o.Mapping = n.CreateSimpleMap(LoadString).Where(kv => kv.Value is not null).ToDictionary(kv => kv.Key, kv => kv.Value!); } } }; diff --git a/src/Microsoft.OpenApi/Reader/V31/OpenApiDocumentDeserializer.cs b/src/Microsoft.OpenApi/Reader/V31/OpenApiDocumentDeserializer.cs index 4f3a05fcc..95eea0009 100644 --- a/src/Microsoft.OpenApi/Reader/V31/OpenApiDocumentDeserializer.cs +++ b/src/Microsoft.OpenApi/Reader/V31/OpenApiDocumentDeserializer.cs @@ -43,7 +43,7 @@ public static OpenApiDocument LoadOpenApi(RootNode rootNode) ParseMap(openApiNode, openApiDoc, _openApiFixedFields, _openApiPatternFields, openApiDoc); // Register components - openApiDoc.Workspace.RegisterComponents(openApiDoc); + openApiDoc.Workspace?.RegisterComponents(openApiDoc); return openApiDoc; } diff --git a/src/Microsoft.OpenApi/Reader/V31/OpenApiEncodingDeserializer.cs b/src/Microsoft.OpenApi/Reader/V31/OpenApiEncodingDeserializer.cs index d571a42d0..5272f6495 100644 --- a/src/Microsoft.OpenApi/Reader/V31/OpenApiEncodingDeserializer.cs +++ b/src/Microsoft.OpenApi/Reader/V31/OpenApiEncodingDeserializer.cs @@ -38,13 +38,21 @@ internal static partial class OpenApiV31Deserializer { "explode", (o, n, _) => { - o.Explode = bool.Parse(n.GetScalarValue()); + var explode = n.GetScalarValue(); + if (explode is not null) + { + o.Explode = bool.Parse(explode); + } } }, { "allowedReserved", (o, n, _) => { - o.AllowReserved = bool.Parse(n.GetScalarValue()); + var allowReserved = n.GetScalarValue(); + if (allowReserved is not null) + { + o.AllowReserved = bool.Parse(allowReserved); + } } }, }; diff --git a/src/Microsoft.OpenApi/Reader/V31/OpenApiExternalDocsDeserializer.cs b/src/Microsoft.OpenApi/Reader/V31/OpenApiExternalDocsDeserializer.cs index a5b06efff..75d9c89a1 100644 --- a/src/Microsoft.OpenApi/Reader/V31/OpenApiExternalDocsDeserializer.cs +++ b/src/Microsoft.OpenApi/Reader/V31/OpenApiExternalDocsDeserializer.cs @@ -22,9 +22,14 @@ internal static partial class OpenApiV31Deserializer } }, { - "url", (o, n, _) => + "url", + (o, n, t) => { - o.Url = new Uri(n.GetScalarValue(), UriKind.RelativeOrAbsolute); + var url = n.GetScalarValue(); + if (url != null) + { + o.Url = new(url, UriKind.RelativeOrAbsolute); + } } }, }; diff --git a/src/Microsoft.OpenApi/Reader/V31/OpenApiHeaderDeserializer.cs b/src/Microsoft.OpenApi/Reader/V31/OpenApiHeaderDeserializer.cs index 2c23c70a4..3c01a56a2 100644 --- a/src/Microsoft.OpenApi/Reader/V31/OpenApiHeaderDeserializer.cs +++ b/src/Microsoft.OpenApi/Reader/V31/OpenApiHeaderDeserializer.cs @@ -22,27 +22,47 @@ internal static partial class OpenApiV31Deserializer } }, { - "required", (o, n, _) => + "required", + (o, n, _) => { - o.Required = bool.Parse(n.GetScalarValue()); + var required = n.GetScalarValue(); + if (required != null) + { + o.Required = bool.Parse(required); + } } }, { - "deprecated", (o, n, _) => + "deprecated", + (o, n, _) => { - o.Deprecated = bool.Parse(n.GetScalarValue()); + var deprecated = n.GetScalarValue(); + if (deprecated != null) + { + o.Deprecated = bool.Parse(deprecated); + } } }, { - "allowEmptyValue", (o, n, _) => + "allowEmptyValue", + (o, n, _) => { - o.AllowEmptyValue = bool.Parse(n.GetScalarValue()); + var allowEmptyVal = n.GetScalarValue(); + if (allowEmptyVal != null) + { + o.AllowEmptyValue = bool.Parse(allowEmptyVal); + } } }, { - "allowReserved", (o, n, _) => + "allowReserved", + (o, n, _) => { - o.AllowReserved = bool.Parse(n.GetScalarValue()); + var allowReserved = n.GetScalarValue(); + if (allowReserved != null) + { + o.AllowReserved = bool.Parse(allowReserved); + } } }, { @@ -56,9 +76,14 @@ internal static partial class OpenApiV31Deserializer } }, { - "explode", (o, n, _) => + "explode", + (o, n, _) => { - o.Explode = bool.Parse(n.GetScalarValue()); + var explode = n.GetScalarValue(); + if (explode != null) + { + o.Explode = bool.Parse(explode); + } } }, { diff --git a/src/Microsoft.OpenApi/Reader/V31/OpenApiInfoDeserializer.cs b/src/Microsoft.OpenApi/Reader/V31/OpenApiInfoDeserializer.cs index 86597b421..49a700683 100644 --- a/src/Microsoft.OpenApi/Reader/V31/OpenApiInfoDeserializer.cs +++ b/src/Microsoft.OpenApi/Reader/V31/OpenApiInfoDeserializer.cs @@ -38,9 +38,14 @@ internal static partial class OpenApiV31Deserializer } }, { - "termsOfService", (o, n, _) => + "termsOfService", + (o, n, _) => { - o.TermsOfService = new Uri(n.GetScalarValue(), UriKind.RelativeOrAbsolute); + var terms = n.GetScalarValue(); + if (terms != null) + { + o.TermsOfService = new(terms, UriKind.RelativeOrAbsolute); + } } }, { diff --git a/src/Microsoft.OpenApi/Reader/V31/OpenApiLicenseDeserializer.cs b/src/Microsoft.OpenApi/Reader/V31/OpenApiLicenseDeserializer.cs index 7ef705095..1f874d21e 100644 --- a/src/Microsoft.OpenApi/Reader/V31/OpenApiLicenseDeserializer.cs +++ b/src/Microsoft.OpenApi/Reader/V31/OpenApiLicenseDeserializer.cs @@ -26,11 +26,16 @@ internal static partial class OpenApiV31Deserializer } }, { - "url", (o, n, _) => + "url", + (o, n, _) => { - o.Url = new Uri(n.GetScalarValue(), UriKind.RelativeOrAbsolute); + var url = n.GetScalarValue(); + if (url != null) + { + o.Url = new(url, UriKind.RelativeOrAbsolute); + } } - }, + } }; private static readonly PatternFieldMap _licensePatternFields = new() diff --git a/src/Microsoft.OpenApi/Reader/V31/OpenApiOAuthFlowDeserializer.cs b/src/Microsoft.OpenApi/Reader/V31/OpenApiOAuthFlowDeserializer.cs index 3efc3ef5a..ab5f29350 100644 --- a/src/Microsoft.OpenApi/Reader/V31/OpenApiOAuthFlowDeserializer.cs +++ b/src/Microsoft.OpenApi/Reader/V31/OpenApiOAuthFlowDeserializer.cs @@ -1,4 +1,5 @@ using System; +using System.Linq; using Microsoft.OpenApi.Extensions; using Microsoft.OpenApi.Models; using Microsoft.OpenApi.Reader.ParseNodes; @@ -15,24 +16,39 @@ internal static partial class OpenApiV31Deserializer new() { { - "authorizationUrl", (o, n, _) => + "authorizationUrl", + (o, n, _) => { - o.AuthorizationUrl = new Uri(n.GetScalarValue(), UriKind.RelativeOrAbsolute); + var url = n.GetScalarValue(); + if (url != null) + { + o.AuthorizationUrl = new(url, UriKind.RelativeOrAbsolute); + } } }, { - "tokenUrl", (o, n, _) => + "tokenUrl", + (o, n, _) => { - o.TokenUrl = new Uri(n.GetScalarValue(), UriKind.RelativeOrAbsolute); + var url = n.GetScalarValue(); + if (url != null) + { + o.TokenUrl = new(url, UriKind.RelativeOrAbsolute); + } } }, { - "refreshUrl", (o, n, _) => + "refreshUrl", + (o, n, _) => { - o.RefreshUrl = new Uri(n.GetScalarValue(), UriKind.RelativeOrAbsolute); + var url = n.GetScalarValue(); + if (url != null) + { + o.RefreshUrl = new(url, UriKind.RelativeOrAbsolute); + } } }, - {"scopes", (o, n, _) => o.Scopes = n.CreateSimpleMap(LoadString)} + {"scopes", (o, n, _) => o.Scopes = n.CreateSimpleMap(LoadString).Where(kv => kv.Value is not null).ToDictionary(kv => kv.Key, kv => kv.Value!)} }; private static readonly PatternFieldMap _oAuthFlowPatternFields = diff --git a/src/Microsoft.OpenApi/Reader/V31/OpenApiOperationDeserializer.cs b/src/Microsoft.OpenApi/Reader/V31/OpenApiOperationDeserializer.cs index cb44bb438..0f55299df 100644 --- a/src/Microsoft.OpenApi/Reader/V31/OpenApiOperationDeserializer.cs +++ b/src/Microsoft.OpenApi/Reader/V31/OpenApiOperationDeserializer.cs @@ -69,9 +69,14 @@ internal static partial class OpenApiV31Deserializer } }, { - "deprecated", (o, n, _) => + "deprecated", + (o, n, _) => { - o.Deprecated = bool.Parse(n.GetScalarValue()); + var deprecated = n.GetScalarValue(); + if (deprecated != null) + { + o.Deprecated = bool.Parse(deprecated); + } } }, { @@ -105,7 +110,7 @@ internal static OpenApiOperation LoadOperation(ParseNode node, OpenApiDocument h return operation; } - private static OpenApiTagReference LoadTagByReference(string tagName, OpenApiDocument hostDocument) + private static OpenApiTagReference LoadTagByReference(string? tagName, OpenApiDocument hostDocument) { var tagObject = new OpenApiTagReference(tagName, hostDocument); return tagObject; diff --git a/src/Microsoft.OpenApi/Reader/V31/OpenApiParameterDeserializer.cs b/src/Microsoft.OpenApi/Reader/V31/OpenApiParameterDeserializer.cs index 35e1308cb..eae4e4993 100644 --- a/src/Microsoft.OpenApi/Reader/V31/OpenApiParameterDeserializer.cs +++ b/src/Microsoft.OpenApi/Reader/V31/OpenApiParameterDeserializer.cs @@ -39,27 +39,47 @@ internal static partial class OpenApiV31Deserializer } }, { - "required", (o, n, _) => + "required", + (o, n, t) => { - o.Required = bool.Parse(n.GetScalarValue()); + var required = n.GetScalarValue(); + if (required != null) + { + o.Required = bool.Parse(required); + } } }, { - "deprecated", (o, n, _) => + "deprecated", + (o, n, t) => { - o.Deprecated = bool.Parse(n.GetScalarValue()); + var deprecated = n.GetScalarValue(); + if (deprecated != null) + { + o.Deprecated = bool.Parse(deprecated); + } } }, { - "allowEmptyValue", (o, n, _) => + "allowEmptyValue", + (o, n, t) => { - o.AllowEmptyValue = bool.Parse(n.GetScalarValue()); + var allowEmptyValue = n.GetScalarValue(); + if (allowEmptyValue != null) + { + o.AllowEmptyValue = bool.Parse(allowEmptyValue); + } } }, { - "allowReserved", (o, n, _) => + "allowReserved", + (o, n, _) => { - o.AllowReserved = bool.Parse(n.GetScalarValue()); + var allowReserved = n.GetScalarValue(); + if (allowReserved != null) + { + o.AllowReserved = bool.Parse(allowReserved); + } } }, { @@ -75,7 +95,11 @@ internal static partial class OpenApiV31Deserializer { "explode", (o, n, _) => { - o.Explode = bool.Parse(n.GetScalarValue()); + var explode = n.GetScalarValue(); + if (explode != null) + { + o.Explode = bool.Parse(explode); + } } }, { diff --git a/src/Microsoft.OpenApi/Reader/V31/OpenApiRequestBodyDeserializer.cs b/src/Microsoft.OpenApi/Reader/V31/OpenApiRequestBodyDeserializer.cs index fe786aa44..ef08b1b2b 100644 --- a/src/Microsoft.OpenApi/Reader/V31/OpenApiRequestBodyDeserializer.cs +++ b/src/Microsoft.OpenApi/Reader/V31/OpenApiRequestBodyDeserializer.cs @@ -31,7 +31,11 @@ internal static partial class OpenApiV31Deserializer { "required", (o, n, _) => { - o.Required = bool.Parse(n.GetScalarValue()); + var required = n.GetScalarValue(); + if (required != null) + { + o.Required = bool.Parse(required); + } } }, }; diff --git a/src/Microsoft.OpenApi/Reader/V31/OpenApiSchemaDeserializer.cs b/src/Microsoft.OpenApi/Reader/V31/OpenApiSchemaDeserializer.cs index fcd97fca2..a65626f34 100644 --- a/src/Microsoft.OpenApi/Reader/V31/OpenApiSchemaDeserializer.cs +++ b/src/Microsoft.OpenApi/Reader/V31/OpenApiSchemaDeserializer.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. +// Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. using Microsoft.OpenApi.Extensions; @@ -35,7 +35,7 @@ internal static partial class OpenApiV31Deserializer }, { "$vocabulary", - (o, n, _) => o.Vocabulary = n.CreateSimpleMap(LoadBool) + (o, n, _) => o.Vocabulary = n.CreateSimpleMap(LoadBool).ToDictionary(kvp => kvp.Key, kvp => kvp.Value ?? false) }, { "$dynamicRef", @@ -49,33 +49,82 @@ internal static partial class OpenApiV31Deserializer "$defs", (o, n, t) => o.Definitions = n.CreateMap(LoadSchema, t) }, - { + { "multipleOf", - (o, n, _) => o.MultipleOf = decimal.Parse(n.GetScalarValue(), NumberStyles.Float, CultureInfo.InvariantCulture) + (o, n, _) => + { + var multipleOf = n.GetScalarValue(); + if (multipleOf != null) + { + o.MultipleOf = decimal.Parse(multipleOf, NumberStyles.Float, CultureInfo.InvariantCulture); + } + } }, { "maximum", - (o, n, _) => o.Maximum = ParserHelper.ParseDecimalWithFallbackOnOverflow(n.GetScalarValue(), decimal.MaxValue) + (o, n,_) => + { + var max = n.GetScalarValue(); + if (max != null) + { + o.Maximum = ParserHelper.ParseDecimalWithFallbackOnOverflow(max, decimal.MaxValue); + } + } }, { "exclusiveMaximum", - (o, n, _) => o.V31ExclusiveMaximum = ParserHelper.ParseDecimalWithFallbackOnOverflow(n.GetScalarValue(), decimal.MaxValue) + (o, n, _) => + { + var exMax = n.GetScalarValue(); + if (exMax != null) + { + o.V31ExclusiveMaximum = ParserHelper.ParseDecimalWithFallbackOnOverflow(exMax, decimal.MaxValue); + } + } }, { "minimum", - (o, n, _) => o.Minimum = ParserHelper.ParseDecimalWithFallbackOnOverflow(n.GetScalarValue(), decimal.MinValue) + (o, n, _) => + { + var min = n.GetScalarValue(); + if (min != null) + { + o.Minimum = ParserHelper.ParseDecimalWithFallbackOnOverflow(min, decimal.MinValue); + } + } }, { "exclusiveMinimum", - (o, n, _) => o.V31ExclusiveMinimum = ParserHelper.ParseDecimalWithFallbackOnOverflow(n.GetScalarValue(), decimal.MaxValue) + (o, n, _) => + { + var exMin = n.GetScalarValue(); + if (exMin != null) + { + o.V31ExclusiveMinimum = ParserHelper.ParseDecimalWithFallbackOnOverflow(exMin, decimal.MaxValue); + } + } }, { "maxLength", - (o, n, _) => o.MaxLength = int.Parse(n.GetScalarValue(), CultureInfo.InvariantCulture) + (o, n, _) => + { + var maxLength = n.GetScalarValue(); + if (maxLength != null) + { + o.MaxLength = int.Parse(maxLength, CultureInfo.InvariantCulture); + } + } }, { "minLength", - (o, n, _) => o.MinLength = int.Parse(n.GetScalarValue(), CultureInfo.InvariantCulture) + (o, n, _) => + { + var minLength = n.GetScalarValue(); + if (minLength != null) + { + o.MinLength = int.Parse(minLength, CultureInfo.InvariantCulture); + } + } }, { "pattern", @@ -83,31 +132,73 @@ internal static partial class OpenApiV31Deserializer }, { "maxItems", - (o, n, _) => o.MaxItems = int.Parse(n.GetScalarValue(), CultureInfo.InvariantCulture) + (o, n, _) => + { + var maxItems = n.GetScalarValue(); + if (maxItems != null) + { + o.MaxItems = int.Parse(maxItems, CultureInfo.InvariantCulture); + } + } }, { "minItems", - (o, n, _) => o.MinItems = int.Parse(n.GetScalarValue(), CultureInfo.InvariantCulture) + (o, n, _) => + { + var minItems = n.GetScalarValue(); + if (minItems != null) + { + o.MinItems = int.Parse(minItems, CultureInfo.InvariantCulture); + } + } }, { "uniqueItems", - (o, n, _) => o.UniqueItems = bool.Parse(n.GetScalarValue()) + (o, n, _) => + { + var uniqueItems = n.GetScalarValue(); + if (uniqueItems != null) + { + o.UniqueItems = bool.Parse(uniqueItems); + } + } }, { "unevaluatedProperties", - (o, n, _) => o.UnevaluatedProperties = bool.Parse(n.GetScalarValue()) + (o, n, _) => + { + var unevaluatedProps = n.GetScalarValue(); + if (unevaluatedProps != null) + { + o.UnevaluatedProperties = bool.Parse(unevaluatedProps); + } + } }, { "maxProperties", - (o, n, _) => o.MaxProperties = int.Parse(n.GetScalarValue(), CultureInfo.InvariantCulture) + (o, n, _) => + { + var maxProps = n.GetScalarValue(); + if (maxProps != null) + { + o.MaxProperties = int.Parse(maxProps, CultureInfo.InvariantCulture); + } + } }, { "minProperties", - (o, n, _) => o.MinProperties = int.Parse(n.GetScalarValue(), CultureInfo.InvariantCulture) + (o, n, _) => + { + var minProps = n.GetScalarValue(); + if (minProps != null) + { + o.MinProperties = int.Parse(minProps, CultureInfo.InvariantCulture); + } + } }, { "required", - (o, n, doc) => o.Required = new HashSet(n.CreateSimpleList((n2, p) => n2.GetScalarValue(), doc)) + (o, n, doc) => o.Required = new HashSet(n.CreateSimpleList((n2, p) => n2.GetScalarValue(), doc).Where(s => s != null)!) }, { "enum", @@ -117,9 +208,10 @@ internal static partial class OpenApiV31Deserializer "type", (o, n, doc) => { - if (n is ValueNode) + var typeValue = n.GetScalarValue(); + if (n is ValueNode && typeValue is not null) { - o.Type = n.GetScalarValue().ToJsonSchemaType(); + o.Type = typeValue.ToJsonSchemaType(); } else { @@ -127,8 +219,11 @@ internal static partial class OpenApiV31Deserializer JsonSchemaType combinedType = 0; foreach(var type in list) { - var schemaType = type.ToJsonSchemaType(); - combinedType |= schemaType; + if (type is not null) + { + var schemaType = type.ToJsonSchemaType(); + combinedType |= schemaType; + } } o.Type = combinedType; } @@ -171,7 +266,11 @@ internal static partial class OpenApiV31Deserializer { if (n is ValueNode) { - o.AdditionalPropertiesAllowed = bool.Parse(n.GetScalarValue()); + var value = n.GetScalarValue(); + if (value is not null) + { + o.AdditionalPropertiesAllowed = bool.Parse(value); + } } else { @@ -195,10 +294,14 @@ internal static partial class OpenApiV31Deserializer "nullable", (o, n, _) => { - var nullable = bool.Parse(n.GetScalarValue()); - if (nullable) // if nullable, convert type into an array of type(s) and null + var value = n.GetScalarValue(); + if (value is not null) { - o.Type |= JsonSchemaType.Null; + var nullable = bool.Parse(value); + if (nullable) // if nullable, convert type into an array of type(s) and null + { + o.Type |= JsonSchemaType.Null; + } } } }, @@ -208,11 +311,25 @@ internal static partial class OpenApiV31Deserializer }, { "readOnly", - (o, n, _) => o.ReadOnly = bool.Parse(n.GetScalarValue()) + (o, n, _) => + { + var readOnly = n.GetScalarValue(); + if (readOnly != null) + { + o.ReadOnly = bool.Parse(readOnly); + } + } }, { "writeOnly", - (o, n, _) => o.WriteOnly = bool.Parse(n.GetScalarValue()) + (o, n, _) => + { + var writeOnly = n.GetScalarValue(); + if (writeOnly != null) + { + o.WriteOnly = bool.Parse(writeOnly); + } + } }, { "xml", @@ -232,7 +349,14 @@ internal static partial class OpenApiV31Deserializer }, { "deprecated", - (o, n, _) => o.Deprecated = bool.Parse(n.GetScalarValue()) + (o, n, t) => + { + var deprecated = n.GetScalarValue(); + if (deprecated != null) + { + o.Deprecated = bool.Parse(deprecated); + } + } }, }; @@ -264,13 +388,13 @@ public static IOpenApiSchema LoadSchema(ParseNode node, OpenApiDocument hostDocu { propertyNode.ParseField(schema, _openApiSchemaFixedFields, _openApiSchemaPatternFields, hostDocument); } - else + else if (schema.UnrecognizedKeywords is not null && propertyNode.JsonNode is not null) { schema.UnrecognizedKeywords[propertyNode.Name] = propertyNode.JsonNode; } } - if (schema.Extensions.ContainsKey(OpenApiConstants.NullableExtension)) + if (schema.Extensions is not null && schema.Extensions.ContainsKey(OpenApiConstants.NullableExtension)) { var type = schema.Type; schema.Type = type | JsonSchemaType.Null; diff --git a/src/Microsoft.OpenApi/Reader/V31/OpenApiSecurityRequirementDeserializer.cs b/src/Microsoft.OpenApi/Reader/V31/OpenApiSecurityRequirementDeserializer.cs index cddb97699..8f87ebf92 100644 --- a/src/Microsoft.OpenApi/Reader/V31/OpenApiSecurityRequirementDeserializer.cs +++ b/src/Microsoft.OpenApi/Reader/V31/OpenApiSecurityRequirementDeserializer.cs @@ -1,6 +1,7 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. +// Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. +using System.Linq; using Microsoft.OpenApi.Models; using Microsoft.OpenApi.Models.Interfaces; using Microsoft.OpenApi.Models.References; @@ -24,8 +25,10 @@ public static OpenApiSecurityRequirement LoadSecurityRequirement(ParseNode node, { var scheme = LoadSecuritySchemeByReference(property.Name, hostDocument); - var scopes = property.Value.CreateSimpleList((value, p) => value.GetScalarValue(), hostDocument); - + var scopes = property.Value.CreateSimpleList((n2, p) => n2.GetScalarValue(), hostDocument) + .Where(scope => scope != null) + .Cast() + .ToList(); if (scheme != null) { securityRequirement.Add(scheme, scopes); diff --git a/src/Microsoft.OpenApi/Reader/V31/OpenApiSecuritySchemeDeserializer.cs b/src/Microsoft.OpenApi/Reader/V31/OpenApiSecuritySchemeDeserializer.cs index 2189f1179..54136f669 100644 --- a/src/Microsoft.OpenApi/Reader/V31/OpenApiSecuritySchemeDeserializer.cs +++ b/src/Microsoft.OpenApi/Reader/V31/OpenApiSecuritySchemeDeserializer.cs @@ -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; @@ -66,7 +66,11 @@ internal static partial class OpenApiV31Deserializer { "openIdConnectUrl", (o, n, _) => { - o.OpenIdConnectUrl = new Uri(n.GetScalarValue(), UriKind.RelativeOrAbsolute); + var connectUrl = n.GetScalarValue(); + if (connectUrl != null) + { + o.OpenIdConnectUrl = new(connectUrl, UriKind.RelativeOrAbsolute); + } } }, { diff --git a/src/Microsoft.OpenApi/Reader/V31/OpenApiServerVariableDeserializer.cs b/src/Microsoft.OpenApi/Reader/V31/OpenApiServerVariableDeserializer.cs index a3aaa141a..cec3618b5 100644 --- a/src/Microsoft.OpenApi/Reader/V31/OpenApiServerVariableDeserializer.cs +++ b/src/Microsoft.OpenApi/Reader/V31/OpenApiServerVariableDeserializer.cs @@ -2,6 +2,7 @@ // Licensed under the MIT license. using System; +using System.Linq; using Microsoft.OpenApi.Extensions; using Microsoft.OpenApi.Models; using Microsoft.OpenApi.Reader.ParseNodes; @@ -20,7 +21,7 @@ internal static partial class OpenApiV31Deserializer { "enum", (o, n, doc) => { - o.Enum = n.CreateSimpleList((s, p) => s.GetScalarValue(), doc); + o.Enum = n.CreateSimpleList((s, p) => s.GetScalarValue(), doc).Where(e => e != null).Cast().ToList(); } }, { diff --git a/src/Microsoft.OpenApi/Reader/V31/OpenApiV31Deserializer.cs b/src/Microsoft.OpenApi/Reader/V31/OpenApiV31Deserializer.cs index 92e7770df..7f13a0492 100644 --- a/src/Microsoft.OpenApi/Reader/V31/OpenApiV31Deserializer.cs +++ b/src/Microsoft.OpenApi/Reader/V31/OpenApiV31Deserializer.cs @@ -20,11 +20,11 @@ namespace Microsoft.OpenApi.Reader.V31 internal static partial class OpenApiV31Deserializer { private static void ParseMap( - MapNode mapNode, + MapNode? mapNode, T domainObject, FixedFieldMap fixedFieldMap, PatternFieldMap patternFieldMap, - OpenApiDocument doc = null) + OpenApiDocument? doc = null) { if (mapNode == null) { @@ -92,8 +92,10 @@ private static void ProcessAnyMapFields( if (propertyMapElement.Value != null) { var any = anyMapFieldMap[anyMapFieldName].PropertyGetter(propertyMapElement.Value); - - anyMapFieldMap[anyMapFieldName].PropertySetter(propertyMapElement.Value, any); + if (any is not null) + { + anyMapFieldMap[anyMapFieldName].PropertySetter(propertyMapElement.Value, any); + } } } } @@ -135,22 +137,28 @@ public static JsonNode LoadAny(ParseNode node, OpenApiDocument hostDocument) private static IOpenApiExtension LoadExtension(string name, ParseNode node) { - return node.Context.ExtensionParsers.TryGetValue(name, out var parser) - ? parser(node.CreateAny(), OpenApiSpecVersion.OpenApi3_1) - : new OpenApiAny(node.CreateAny()); + if (node.Context.ExtensionParsers is not null && node.Context.ExtensionParsers.TryGetValue(name, out var parser)) + { + return parser(node.CreateAny(), OpenApiSpecVersion.OpenApi3_1); + } + else + { + return new OpenApiAny(node.CreateAny()); + } } - private static string LoadString(ParseNode node) + private static string? LoadString(ParseNode node) { return node.GetScalarValue(); } - private static bool LoadBool(ParseNode node) + private static bool? LoadBool(ParseNode node) { - return bool.Parse(node.GetScalarValue()); + var value = node.GetScalarValue(); + return value is not null ? bool.Parse(value) : null; } - private static (string, string) GetReferenceIdAndExternalResource(string pointer) + private static (string, string?) GetReferenceIdAndExternalResource(string pointer) { /* Check whether the reference pointer is a URL * (id keyword allows you to supply a URL for the schema as a target for referencing) @@ -159,13 +167,13 @@ private static (string, string) GetReferenceIdAndExternalResource(string pointer * E.g. $ref: '#/components/schemas/pet' */ var refSegments = pointer.Split('/'); - string refId = !pointer.Contains('#') ? pointer : refSegments.Last(); + string refId = !pointer.Contains('#') ? pointer : refSegments[refSegments.Count()-1]; - var isExternalResource = !refSegments.First().StartsWith("#", StringComparison.OrdinalIgnoreCase); - string externalResource = null; + var isExternalResource = !refSegments[0].StartsWith("#", StringComparison.OrdinalIgnoreCase); + string? externalResource = null; if (isExternalResource && pointer.Contains('#')) { - externalResource = $"{refSegments.First()}/{refSegments[1].TrimEnd('#')}"; + externalResource = $"{refSegments[0]}/{refSegments[1].TrimEnd('#')}"; } return (refId, externalResource); diff --git a/src/Microsoft.OpenApi/Reader/V31/OpenApiV31VersionService.cs b/src/Microsoft.OpenApi/Reader/V31/OpenApiV31VersionService.cs index bfaa82051..38bfe53a5 100644 --- a/src/Microsoft.OpenApi/Reader/V31/OpenApiV31VersionService.cs +++ b/src/Microsoft.OpenApi/Reader/V31/OpenApiV31VersionService.cs @@ -71,11 +71,11 @@ public OpenApiV31VersionService(OpenApiDiagnostic diagnostic) /// The type of object refefenced based on the context of the reference /// The summary of the reference /// A reference description - public OpenApiReference ConvertToOpenApiReference( + public OpenApiReference? ConvertToOpenApiReference( string reference, ReferenceType? type, - string summary = null, - string description = null) + string? summary = null, + string? description = null) { if (!string.IsNullOrWhiteSpace(reference)) { @@ -164,7 +164,7 @@ public T LoadElement(ParseNode node, OpenApiDocument doc) where T : IOpenApiE } /// - public string GetReferenceScalarValues(MapNode mapNode, string scalarValue) + public string? GetReferenceScalarValues(MapNode mapNode, string scalarValue) { if (mapNode.Any(static x => !"$ref".Equals(x.Name, StringComparison.OrdinalIgnoreCase))) { @@ -177,7 +177,7 @@ public string GetReferenceScalarValues(MapNode mapNode, string scalarValue) return null; } - private OpenApiReference ParseLocalReference(string localReference, string summary = null, string description = null) + private OpenApiReference ParseLocalReference(string localReference, string? summary = null, string? description = null) { if (string.IsNullOrWhiteSpace(localReference)) { diff --git a/src/Microsoft.OpenApi/Reader/V31/OpenApiXmlDeserializer.cs b/src/Microsoft.OpenApi/Reader/V31/OpenApiXmlDeserializer.cs index 0f821e9d2..c2776c52a 100644 --- a/src/Microsoft.OpenApi/Reader/V31/OpenApiXmlDeserializer.cs +++ b/src/Microsoft.OpenApi/Reader/V31/OpenApiXmlDeserializer.cs @@ -23,29 +23,42 @@ internal static partial class OpenApiV31Deserializer } }, { - "namespace", (o, n, _) => + "namespace", + (o, n, _) => { - o.Namespace = new Uri(n.GetScalarValue(), UriKind.Absolute); + var value = n.GetScalarValue(); + if (value != null) + { + o.Namespace = new(value, UriKind.Absolute); + } } }, { - "prefix", (o, n, _) => - { - o.Prefix = n.GetScalarValue(); - } + "prefix", + (o, n, _) => o.Prefix = n.GetScalarValue() }, { - "attribute", (o, n, _) => + "attribute", + (o, n, _) => { - o.Attribute = bool.Parse(n.GetScalarValue()); + var attribute = n.GetScalarValue(); + if (attribute is not null) + { + o.Attribute = bool.Parse(attribute); + } } }, { - "wrapped", (o, n, _) => + "wrapped", + (o, n, _) => { - o.Wrapped = bool.Parse(n.GetScalarValue()); + var wrapped = n.GetScalarValue(); + if (wrapped is not null) + { + o.Wrapped = bool.Parse(wrapped); + } } - }, + } }; private static readonly PatternFieldMap _xmlPatternFields = diff --git a/src/Microsoft.OpenApi/Services/CopyReferences.cs b/src/Microsoft.OpenApi/Services/CopyReferences.cs index 980aafb56..6577e237f 100644 --- a/src/Microsoft.OpenApi/Services/CopyReferences.cs +++ b/src/Microsoft.OpenApi/Services/CopyReferences.cs @@ -19,61 +19,61 @@ public override void Visit(IOpenApiReferenceHolder referenceHolder) switch (referenceHolder) { case OpenApiSchemaReference openApiSchemaReference: - AddSchemaToComponents(openApiSchemaReference.Target, openApiSchemaReference.Reference.Id); + AddSchemaToComponents(openApiSchemaReference.Target, openApiSchemaReference.Reference?.Id); break; case OpenApiSchema schema: AddSchemaToComponents(schema); break; case OpenApiParameterReference openApiParameterReference: - AddParameterToComponents(openApiParameterReference.Target, openApiParameterReference.Reference.Id); + AddParameterToComponents(openApiParameterReference.Target, openApiParameterReference.Reference?.Id); break; case OpenApiParameter parameter: AddParameterToComponents(parameter); break; case OpenApiResponseReference openApiResponseReference: - AddResponseToComponents(openApiResponseReference.Target, openApiResponseReference.Reference.Id); + AddResponseToComponents(openApiResponseReference.Target, openApiResponseReference.Reference?.Id); break; case OpenApiResponse response: AddResponseToComponents(response); break; case OpenApiRequestBodyReference openApiRequestBodyReference: - AddRequestBodyToComponents(openApiRequestBodyReference.Target, openApiRequestBodyReference.Reference.Id); + AddRequestBodyToComponents(openApiRequestBodyReference.Target, openApiRequestBodyReference.Reference?.Id); break; case OpenApiRequestBody requestBody: AddRequestBodyToComponents(requestBody); break; case OpenApiExampleReference openApiExampleReference: - AddExampleToComponents(openApiExampleReference.Target, openApiExampleReference.Reference.Id); + AddExampleToComponents(openApiExampleReference.Target, openApiExampleReference.Reference?.Id); break; case OpenApiExample example: AddExampleToComponents(example); break; case OpenApiHeaderReference openApiHeaderReference: - AddHeaderToComponents(openApiHeaderReference.Target, openApiHeaderReference.Reference.Id); + AddHeaderToComponents(openApiHeaderReference.Target, openApiHeaderReference.Reference?.Id); break; case OpenApiHeader header: AddHeaderToComponents(header); break; case OpenApiCallbackReference openApiCallbackReference: - AddCallbackToComponents(openApiCallbackReference.Target, openApiCallbackReference.Reference.Id); + AddCallbackToComponents(openApiCallbackReference.Target, openApiCallbackReference.Reference?.Id); break; case OpenApiCallback callback: AddCallbackToComponents(callback); break; case OpenApiLinkReference openApiLinkReference: - AddLinkToComponents(openApiLinkReference.Target, openApiLinkReference.Reference.Id); + AddLinkToComponents(openApiLinkReference.Target, openApiLinkReference.Reference?.Id); break; case OpenApiLink link: AddLinkToComponents(link); break; case OpenApiSecuritySchemeReference openApiSecuritySchemeReference: - AddSecuritySchemeToComponents(openApiSecuritySchemeReference.Target, openApiSecuritySchemeReference.Reference.Id); + AddSecuritySchemeToComponents(openApiSecuritySchemeReference.Target, openApiSecuritySchemeReference.Reference?.Id); break; case OpenApiSecurityScheme securityScheme: AddSecuritySchemeToComponents(securityScheme); break; case OpenApiPathItemReference openApiPathItemReference: - AddPathItemToComponents(openApiPathItemReference.Target, openApiPathItemReference.Reference.Id); + AddPathItemToComponents(openApiPathItemReference.Target, openApiPathItemReference.Reference?.Id); break; case OpenApiPathItem pathItem: AddPathItemToComponents(pathItem); @@ -85,94 +85,94 @@ public override void Visit(IOpenApiReferenceHolder referenceHolder) base.Visit(referenceHolder); } - private void AddSchemaToComponents(OpenApiSchema schema, string referenceId = null) + private void AddSchemaToComponents(OpenApiSchema? schema, string? referenceId = null) { EnsureComponentsExist(); EnsureSchemasExist(); - if (!Components.Schemas.ContainsKey(referenceId)) + if (Components.Schemas is not null && referenceId is not null && schema is not null && !Components.Schemas.ContainsKey(referenceId)) { Components.Schemas.Add(referenceId, schema); } } - private void AddParameterToComponents(OpenApiParameter parameter, string referenceId = null) + private void AddParameterToComponents(OpenApiParameter? parameter, string? referenceId = null) { EnsureComponentsExist(); EnsureParametersExist(); - if (!Components.Parameters.ContainsKey(referenceId)) + if (Components.Parameters is not null && parameter is not null && referenceId is not null && !Components.Parameters.ContainsKey(referenceId)) { Components.Parameters.Add(referenceId, parameter); } } - private void AddResponseToComponents(OpenApiResponse response, string referenceId = null) + private void AddResponseToComponents(OpenApiResponse? response, string? referenceId = null) { EnsureComponentsExist(); EnsureResponsesExist(); - if (!Components.Responses.ContainsKey(referenceId)) + if (Components.Responses is not null && referenceId is not null && response is not null && !Components.Responses.ContainsKey(referenceId)) { Components.Responses.Add(referenceId, response); } } - private void AddRequestBodyToComponents(OpenApiRequestBody requestBody, string referenceId = null) + private void AddRequestBodyToComponents(OpenApiRequestBody? requestBody, string? referenceId = null) { EnsureComponentsExist(); EnsureRequestBodiesExist(); - if (!Components.RequestBodies.ContainsKey(referenceId)) + if (Components.RequestBodies is not null && requestBody is not null && referenceId is not null && !Components.RequestBodies.ContainsKey(referenceId)) { Components.RequestBodies.Add(referenceId, requestBody); } } - private void AddLinkToComponents(OpenApiLink link, string referenceId = null) + private void AddLinkToComponents(OpenApiLink? link, string? referenceId = null) { EnsureComponentsExist(); EnsureLinksExist(); - if (!Components.Links.ContainsKey(referenceId)) + if (Components.Links is not null && link is not null && referenceId is not null && !Components.Links.ContainsKey(referenceId)) { Components.Links.Add(referenceId, link); } } - private void AddCallbackToComponents(OpenApiCallback callback, string referenceId = null) + private void AddCallbackToComponents(OpenApiCallback? callback, string? referenceId = null) { EnsureComponentsExist(); EnsureCallbacksExist(); - if (!Components.Callbacks.ContainsKey(referenceId)) + if (Components.Callbacks is not null && callback is not null && referenceId is not null && !Components.Callbacks.ContainsKey(referenceId)) { Components.Callbacks.Add(referenceId, callback); } } - private void AddHeaderToComponents(OpenApiHeader header, string referenceId = null) + private void AddHeaderToComponents(OpenApiHeader? header, string? referenceId = null) { EnsureComponentsExist(); EnsureHeadersExist(); - if (!Components.Headers.ContainsKey(referenceId)) + if (Components.Headers is not null && header is not null && referenceId is not null && !Components.Headers.ContainsKey(referenceId)) { Components.Headers.Add(referenceId, header); } } - private void AddExampleToComponents(OpenApiExample example, string referenceId = null) + private void AddExampleToComponents(OpenApiExample? example, string? referenceId = null) { EnsureComponentsExist(); EnsureExamplesExist(); - if (!Components.Examples.ContainsKey(referenceId)) + if (Components.Examples is not null && example is not null && referenceId is not null && !Components.Examples.ContainsKey(referenceId)) { Components.Examples.Add(referenceId, example); } } - private void AddPathItemToComponents(OpenApiPathItem pathItem, string referenceId = null) + private void AddPathItemToComponents(OpenApiPathItem? pathItem, string? referenceId = null) { EnsureComponentsExist(); EnsurePathItemsExist(); - if (!Components.PathItems.ContainsKey(referenceId)) + if (Components.PathItems is not null && pathItem is not null && referenceId is not null && !Components.PathItems.ContainsKey(referenceId)) { Components.PathItems.Add(referenceId, pathItem); } } - private void AddSecuritySchemeToComponents(OpenApiSecurityScheme securityScheme, string referenceId = null) + private void AddSecuritySchemeToComponents(OpenApiSecurityScheme? securityScheme, string? referenceId = null) { EnsureComponentsExist(); EnsureSecuritySchemesExist(); - if (!Components.SecuritySchemes.ContainsKey(referenceId)) + if (Components.SecuritySchemes is not null && securityScheme is not null && referenceId is not null && !Components.SecuritySchemes.ContainsKey(referenceId)) { Components.SecuritySchemes.Add(referenceId, securityScheme); } @@ -184,7 +184,7 @@ public override void Visit(IOpenApiSchema schema) // This is needed to handle schemas used in Responses in components if (schema is OpenApiSchemaReference openApiSchemaReference) { - AddSchemaToComponents(openApiSchemaReference.Target, openApiSchemaReference.Reference.Id); + AddSchemaToComponents(openApiSchemaReference.Target, openApiSchemaReference.Reference?.Id); } base.Visit(schema); } @@ -196,50 +196,80 @@ private void EnsureComponentsExist() private void EnsureSchemasExist() { - _target.Components.Schemas ??= new Dictionary(); + if (_target.Components is not null && _target.Components.Schemas is null) + { + _target.Components.Schemas ??= new Dictionary(); + } } private void EnsureParametersExist() { - _target.Components.Parameters ??= new Dictionary(); + if (_target.Components is not null && _target.Components.Parameters is null) + { + _target.Components.Parameters ??= new Dictionary(); + } } private void EnsureResponsesExist() { - _target.Components.Responses ??= new Dictionary(); + if (_target.Components is not null && _target.Components.Responses is null) + { + _target.Components.Responses ??= new Dictionary(); + } } private void EnsureRequestBodiesExist() { - _target.Components.RequestBodies ??= new Dictionary(); + if (_target.Components is not null && _target.Components.RequestBodies is null) + { + _target.Components.RequestBodies ??= new Dictionary(); + } } private void EnsureExamplesExist() { - _target.Components.Examples ??= new Dictionary(); + if (_target.Components is not null && _target.Components.Examples is null) + { + _target.Components.Examples ??= new Dictionary(); + } } private void EnsureHeadersExist() { - _target.Components.Headers ??= new Dictionary(); + if (_target.Components is not null && _target.Components.Headers is null) + { + _target.Components.Headers ??= new Dictionary(); + } } private void EnsureCallbacksExist() { - _target.Components.Callbacks ??= new Dictionary(); + if (_target.Components is not null && _target.Components.Callbacks is null) + { + _target.Components.Callbacks ??= new Dictionary(); + } } private void EnsureLinksExist() { - _target.Components.Links ??= new Dictionary(); + if (_target.Components is not null && _target.Components.Links is null) + { + _target.Components.Links ??= new Dictionary(); + } } private void EnsureSecuritySchemesExist() { - _target.Components.SecuritySchemes ??= new Dictionary(); + if (_target.Components is not null && _target.Components.SecuritySchemes is null) + { + _target.Components.SecuritySchemes ??= new Dictionary(); + } } private void EnsurePathItemsExist() { - _target.Components.PathItems ??= new Dictionary(); + if (_target.Components is not null && _target.Components.PathItems is null) + { + _target.Components.PathItems = new Dictionary(); + } } } diff --git a/src/Microsoft.OpenApi/Services/LoopDetector.cs b/src/Microsoft.OpenApi/Services/LoopDetector.cs index 904361f97..dd9c0919f 100644 --- a/src/Microsoft.OpenApi/Services/LoopDetector.cs +++ b/src/Microsoft.OpenApi/Services/LoopDetector.cs @@ -20,7 +20,7 @@ public bool PushLoop(T key) _loopStacks.Add(typeof(T), stack); } - if (!stack.Contains(key)) + if (key is not null && !stack.Contains(key)) { stack.Push(key); return true; @@ -48,7 +48,10 @@ public void SaveLoop(T loop) { Loops[typeof(T)] = new(); } - Loops[typeof(T)].Add(loop); + if (loop is not null) + { + Loops[typeof(T)].Add(loop); + } } /// diff --git a/src/Microsoft.OpenApi/Services/OpenApiFilterService.cs b/src/Microsoft.OpenApi/Services/OpenApiFilterService.cs index 20fa54839..b6b51993d 100644 --- a/src/Microsoft.OpenApi/Services/OpenApiFilterService.cs +++ b/src/Microsoft.OpenApi/Services/OpenApiFilterService.cs @@ -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; @@ -26,10 +26,10 @@ public static class OpenApiFilterService /// The input OpenAPI document. /// A predicate. public static Func CreatePredicate( - string operationIds = null, - string tags = null, - Dictionary> requestUrls = null, - OpenApiDocument source = null) + string? operationIds = null, + string? tags = null, + Dictionary>? requestUrls = null, + OpenApiDocument? source = null) { Func predicate; ValidateFilters(requestUrls, operationIds, tags); @@ -59,10 +59,10 @@ public static class OpenApiFilterService /// The target . /// A predicate function. /// A partial OpenAPI document. - public static OpenApiDocument CreateFilteredDocument(OpenApiDocument source, Func predicate) + public static OpenApiDocument CreateFilteredDocument(OpenApiDocument? source, Func predicate) { // Fetch and copy title, graphVersion and server info from OpenApiDoc - var components = source.Components is null + var components = source?.Components is null ? null : new OpenApiComponents() { SecuritySchemes = source.Components.SecuritySchemes }; @@ -70,53 +70,56 @@ public static OpenApiDocument CreateFilteredDocument(OpenApiDocument source, Fun { Info = new() { - Title = source.Info.Title + " - Subset", - Description = source.Info.Description, - TermsOfService = source.Info.TermsOfService, - Contact = source.Info.Contact, - License = source.Info.License, - Version = source.Info.Version, - Extensions = source.Info.Extensions + Title = source?.Info.Title + " - Subset", + Description = source?.Info.Description, + TermsOfService = source?.Info.TermsOfService, + Contact = source?.Info.Contact, + License = source?.Info.License, + Version = source?.Info.Version, + Extensions = source?.Info.Extensions }, Components = components, - SecurityRequirements = source.SecurityRequirements, - Servers = source.Servers + SecurityRequirements = source?.SecurityRequirements, + Servers = source?.Servers }; var results = FindOperations(source, predicate); foreach (var result in results) { - IOpenApiPathItem pathItem; - var pathKey = result.CurrentKeys.Path; + IOpenApiPathItem? pathItem = null; + var pathKey = result.CurrentKeys?.Path; if (subset.Paths == null) { subset.Paths = new(); pathItem = new OpenApiPathItem(); - subset.Paths.Add(pathKey, pathItem); + if (pathKey is not null) + { + subset.Paths.Add(pathKey, pathItem); + } } else { - if (!subset.Paths.TryGetValue(pathKey, out pathItem)) + if (pathKey is not null && !subset.Paths.TryGetValue(pathKey, out pathItem)) { pathItem = new OpenApiPathItem(); subset.Paths.Add(pathKey, pathItem); } } - if (result.CurrentKeys.Operation != null) + if (result.CurrentKeys?.Operation != null && result.Operation != null) { - pathItem.Operations.Add((OperationType)result.CurrentKeys.Operation, result.Operation); + pathItem?.Operations?.Add((OperationType)result.CurrentKeys.Operation, result.Operation); if (result.Parameters?.Any() ?? false) { foreach (var parameter in result.Parameters) { - if (!pathItem.Parameters.Contains(parameter)) + if (pathItem?.Parameters is not null && !pathItem.Parameters.Contains(parameter)) { pathItem.Parameters.Add(parameter); - } + } } } } @@ -147,7 +150,7 @@ public static OpenApiUrlTreeNode CreateOpenApiUrlTreeNode(Dictionary GetOpenApiOperations(OpenApiUrlTreeNode rootNode, string relativeUrl, string label) + private static IDictionary? GetOpenApiOperations(OpenApiUrlTreeNode rootNode, string relativeUrl, string label) { if (relativeUrl.Equals("/", StringComparison.Ordinal) && rootNode.HasOperations(label)) { @@ -156,7 +159,7 @@ private static IDictionary GetOpenApiOperations var urlSegments = relativeUrl.Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries); - IDictionary operations = null; + IDictionary? operations = null; var targetChild = rootNode; @@ -224,7 +227,7 @@ private static IDictionary GetOpenApiOperations return operations; } - private static IList FindOperations(OpenApiDocument sourceDocument, Func predicate) + private static IList FindOperations(OpenApiDocument? sourceDocument, Func predicate) { var search = new OperationSearch(predicate); var walker = new OpenApiWalker(search); @@ -246,93 +249,120 @@ private static void CopyReferences(OpenApiDocument target) } while (morestuff); } - private static bool AddReferences(OpenApiComponents newComponents, OpenApiComponents target) + private static bool AddReferences(OpenApiComponents newComponents, OpenApiComponents? target) { var moreStuff = false; - foreach (var item in newComponents.Schemas) + if (newComponents.Schemas is not null) { - if (!target.Schemas.ContainsKey(item.Key)) + foreach (var item in newComponents.Schemas) { - moreStuff = true; - target.Schemas.Add(item); + if (target?.Schemas is not null && !target.Schemas.ContainsKey(item.Key)) + { + moreStuff = true; + target.Schemas.Add(item); + } } } - foreach (var item in newComponents.Parameters) + if (newComponents.Parameters is not null) { - if (!target.Parameters.ContainsKey(item.Key)) + foreach (var item in newComponents.Parameters) { - moreStuff = true; - target.Parameters.Add(item); + if (target?.Parameters is not null && !target.Parameters.ContainsKey(item.Key)) + { + moreStuff = true; + target.Parameters.Add(item); + } } } - foreach (var item in newComponents.Responses) + if (newComponents.Responses is not null) { - if (!target.Responses.ContainsKey(item.Key)) + foreach (var item in newComponents.Responses) { - moreStuff = true; - target.Responses.Add(item); + if (target?.Responses is not null && !target.Responses.ContainsKey(item.Key)) + { + moreStuff = true; + target.Responses.Add(item); + } } } - foreach (var item in newComponents.RequestBodies - .Where(item => !target.RequestBodies.ContainsKey(item.Key))) + if (newComponents.RequestBodies is not null) { - moreStuff = true; - target.RequestBodies.Add(item); + foreach (var item in newComponents.RequestBodies + .Where(item => target?.RequestBodies is not null && !target.RequestBodies.ContainsKey(item.Key))) + { + moreStuff = true; + target?.RequestBodies?.Add(item); + } } - foreach (var item in newComponents.Headers - .Where(item => !target.Headers.ContainsKey(item.Key))) + if (newComponents.Headers is not null) { - moreStuff = true; - target.Headers.Add(item); + foreach (var item in newComponents.Headers + .Where(item => target?.Headers is not null && !target.Headers.ContainsKey(item.Key))) + { + moreStuff = true; + target?.Headers?.Add(item); + } } - foreach (var item in newComponents.Links - .Where(item => !target.Links.ContainsKey(item.Key))) + if (newComponents.Links is not null) { - moreStuff = true; - target.Links.Add(item); + foreach (var item in newComponents.Links + .Where(item => target?.Links is not null && !target.Links.ContainsKey(item.Key))) + { + moreStuff = true; + target?.Links?.Add(item); + } } - foreach (var item in newComponents.Callbacks - .Where(item => !target.Callbacks.ContainsKey(item.Key))) + if (newComponents.Callbacks is not null) { - moreStuff = true; - target.Callbacks.Add(item); + foreach (var item in newComponents.Callbacks + .Where(item => target?.Callbacks is not null && !target.Callbacks.ContainsKey(item.Key))) + { + moreStuff = true; + target?.Callbacks?.Add(item); + } } - foreach (var item in newComponents.Examples - .Where(item => !target.Examples.ContainsKey(item.Key))) + if (newComponents.Examples is not null) { - moreStuff = true; - target.Examples.Add(item); + foreach (var item in newComponents.Examples + .Where(item => target?.Examples is not null && !target.Examples.ContainsKey(item.Key))) + { + moreStuff = true; + target?.Examples?.Add(item); + } } - foreach (var item in newComponents.SecuritySchemes - .Where(item => !target.SecuritySchemes.ContainsKey(item.Key))) + if (newComponents.SecuritySchemes is not null) { - moreStuff = true; - target.SecuritySchemes.Add(item); + foreach (var item in newComponents.SecuritySchemes + .Where(item => target?.SecuritySchemes is not null && !target.SecuritySchemes.ContainsKey(item.Key))) + { + moreStuff = true; + target?.SecuritySchemes?.Add(item); + } } return moreStuff; } - private static string ExtractPath(string url, IList serverList) + private static string ExtractPath(string url, IList? serverList) { // if OpenAPI has servers, then see if the url matches one of them - var baseUrl = serverList.Select(s => s.Url.TrimEnd('/')) - .FirstOrDefault(c => url.Contains(c)); + var baseUrl = serverList?.Select(s => s.Url?.TrimEnd('/')) + .FirstOrDefault(c => c != null && url.Contains(c)); return baseUrl == null ? new Uri(new(SRResource.DefaultBaseUri), url).GetComponents(UriComponents.Path | UriComponents.KeepDelimiter, UriFormat.Unescaped) : url.Split(new[] { baseUrl }, StringSplitOptions.None)[1]; } - private static void ValidateFilters(IDictionary> requestUrls, string operationIds, string tags) + private static void ValidateFilters(IDictionary>? requestUrls, string? operationIds, string? tags) { if (requestUrls != null && (operationIds != null || tags != null)) { @@ -363,36 +393,39 @@ private static void ValidateFilters(IDictionary> requestUrl if (tagsArray.Length == 1) { var regex = new Regex(tagsArray[0]); - return (_, _, operation) => operation.Tags.Any(tag => regex.IsMatch(tag.Name)); + return (_, _, operation) => operation.Tags?.Any(tag => tag.Name != null && regex.IsMatch(tag.Name)) ?? false; } else { - return (_, _, operation) => operation.Tags.Any(tag => tagsArray.Contains(tag.Name)); + return (_, _, operation) => operation.Tags?.Any(tag => tagsArray.Contains(tag.Name)) ?? false; } } - private static Func GetRequestUrlsPredicate(Dictionary> requestUrls, OpenApiDocument source) + private static Func GetRequestUrlsPredicate(Dictionary> requestUrls, OpenApiDocument? source) { var operationTypes = new List(); if (source != null) { var apiVersion = source.Info.Version; - var sources = new Dictionary { { apiVersion, source } }; - var rootNode = CreateOpenApiUrlTreeNode(sources); - - // Iterate through urls dictionary and fetch operations for each url - foreach (var url in requestUrls) + if (apiVersion is not null) { - var serverList = source.Servers; - var path = ExtractPath(url.Key, serverList); - var openApiOperations = GetOpenApiOperations(rootNode, path, apiVersion); - if (openApiOperations == null) + var sources = new Dictionary { { apiVersion, source } }; + var rootNode = CreateOpenApiUrlTreeNode(sources); + + // Iterate through urls dictionary and fetch operations for each url + foreach (var url in requestUrls) { - Debug.WriteLine($"The url {url.Key} could not be found in the OpenApi description"); - continue; + var serverList = source.Servers; + var path = ExtractPath(url.Key, serverList); + var openApiOperations = GetOpenApiOperations(rootNode, path, apiVersion); + if (openApiOperations == null) + { + Debug.WriteLine($"The url {url.Key} could not be found in the OpenApi description"); + continue; + } + operationTypes.AddRange(GetOperationTypes(openApiOperations, url.Value, path)); } - operationTypes.AddRange(GetOperationTypes(openApiOperations, url.Value, path)); - } + } } if (!operationTypes.Any()) diff --git a/src/Microsoft.OpenApi/Services/OpenApiReferenceError.cs b/src/Microsoft.OpenApi/Services/OpenApiReferenceError.cs index 6dfd066ff..c9e3eda78 100644 --- a/src/Microsoft.OpenApi/Services/OpenApiReferenceError.cs +++ b/src/Microsoft.OpenApi/Services/OpenApiReferenceError.cs @@ -14,7 +14,7 @@ public class OpenApiReferenceError : OpenApiError /// /// The reference that caused the error. /// - public readonly OpenApiReference Reference; + public readonly OpenApiReference? Reference; /// /// Initializes the class using the message and pointer from the given exception. /// diff --git a/src/Microsoft.OpenApi/Services/OpenApiUrlTreeNode.cs b/src/Microsoft.OpenApi/Services/OpenApiUrlTreeNode.cs index 8a61772dd..9a6b356e2 100644 --- a/src/Microsoft.OpenApi/Services/OpenApiUrlTreeNode.cs +++ b/src/Microsoft.OpenApi/Services/OpenApiUrlTreeNode.cs @@ -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; @@ -86,14 +86,14 @@ public static OpenApiUrlTreeNode Create() /// The OpenAPI document. /// Name tag for labelling the nodes in the directory structure. /// The root node of the created directory structure. - public static OpenApiUrlTreeNode Create(OpenApiDocument doc, string label) + public static OpenApiUrlTreeNode Create(OpenApiDocument? doc, string label) { Utils.CheckArgumentNull(doc); Utils.CheckArgumentNullOrEmpty(label); var root = Create(); - var paths = doc.Paths; + var paths = doc?.Paths; if (paths != null) { foreach (var path in paths) @@ -283,7 +283,9 @@ private static void ProcessNode(OpenApiUrlTreeNode node, TextWriter writer) private static string GetMethods(OpenApiUrlTreeNode node) { - return String.Join("_", node.PathItems.SelectMany(p => p.Value.Operations.Select(o => o.Key)) + return String.Join("_", node.PathItems + .Where(p => p.Value.Operations != null) + .SelectMany(p => p.Value.Operations!.Select(o => o.Key)) .Distinct() .Select(o => o.ToString().ToUpper()) .OrderBy(o => o) diff --git a/src/Microsoft.OpenApi/Services/OpenApiVisitorBase.cs b/src/Microsoft.OpenApi/Services/OpenApiVisitorBase.cs index 254528b41..26ae2c396 100644 --- a/src/Microsoft.OpenApi/Services/OpenApiVisitorBase.cs +++ b/src/Microsoft.OpenApi/Services/OpenApiVisitorBase.cs @@ -225,7 +225,7 @@ public virtual void Visit(OpenApiComponents components) /// /// Visits /// - public virtual void Visit(OpenApiExternalDocs externalDocs) + public virtual void Visit(OpenApiExternalDocs? externalDocs) { } @@ -330,7 +330,7 @@ public virtual void Visit(IList openApiSecurityRequi /// /// Visits /// - public virtual void Visit(IOpenApiExtensible openApiExtensible) + public virtual void Visit(IOpenApiExtensible? openApiExtensible) { } diff --git a/src/Microsoft.OpenApi/Services/OpenApiWalker.cs b/src/Microsoft.OpenApi/Services/OpenApiWalker.cs index ae4430067..9103dbbeb 100644 --- a/src/Microsoft.OpenApi/Services/OpenApiWalker.cs +++ b/src/Microsoft.OpenApi/Services/OpenApiWalker.cs @@ -34,7 +34,7 @@ public OpenApiWalker(OpenApiVisitorBase visitor) /// Visits list of and child objects /// /// OpenApiDocument to be walked - public void Walk(OpenApiDocument doc) + public void Walk(OpenApiDocument? doc) { if (doc == null) { @@ -60,7 +60,7 @@ public void Walk(OpenApiDocument doc) /// /// Visits list of and child objects /// - internal void Walk(IList tags) + internal void Walk(IList? tags) { if (tags == null) { @@ -82,7 +82,7 @@ internal void Walk(IList tags) /// /// Visits list of and child objects /// - internal void Walk(IList tags) + internal void Walk(IList? tags) { if (tags == null) { @@ -117,7 +117,7 @@ internal void Walk(string externalDocs) /// /// Visits and child objects /// - internal void Walk(OpenApiExternalDocs externalDocs) + internal void Walk(OpenApiExternalDocs? externalDocs) { if (externalDocs == null) { @@ -281,7 +281,7 @@ internal void Walk(OpenApiPaths paths) /// /// Visits Webhooks and child objects /// - internal void Walk(IDictionary webhooks) + internal void Walk(IDictionary? webhooks) { if (webhooks == null) { @@ -299,13 +299,13 @@ internal void Walk(IDictionary webhooks) Walk(pathItem.Key, () => Walk(pathItem.Value));// JSON Pointer uses ~1 as an escape character for / _visitor.CurrentKeys.Path = null; } - }; + } } /// /// Visits list of and child objects /// - internal void Walk(IList servers) + internal void Walk(IList? servers) { if (servers == null) { @@ -346,7 +346,7 @@ internal void Walk(OpenApiInfo info) /// /// Visits dictionary of extensions /// - internal void Walk(IOpenApiExtensible openApiExtensible) + internal void Walk(IOpenApiExtensible? openApiExtensible) { if (openApiExtensible == null) { @@ -382,7 +382,7 @@ internal void Walk(IOpenApiExtension extension) /// /// Visits and child objects /// - internal void Walk(OpenApiLicense license) + internal void Walk(OpenApiLicense? license) { if (license == null) { @@ -395,7 +395,7 @@ internal void Walk(OpenApiLicense license) /// /// Visits and child objects /// - internal void Walk(OpenApiContact contact) + internal void Walk(OpenApiContact? contact) { if (contact == null) { @@ -423,7 +423,7 @@ internal void Walk(IOpenApiCallback callback, bool isComponent = false) _visitor.Visit(callback); - if (callback != null) + if (callback.PathItems != null) { foreach (var item in callback.PathItems) { @@ -469,7 +469,7 @@ internal void Walk(OpenApiTagReference tag) /// /// Visits and child objects /// - internal void Walk(OpenApiServer server) + internal void Walk(OpenApiServer? server) { if (server == null) { @@ -477,14 +477,14 @@ internal void Walk(OpenApiServer server) } _visitor.Visit(server); - Walk(OpenApiConstants.Variables, () => Walk(server.Variables)); + Walk(OpenApiConstants.Variables, () => Walk(server?.Variables)); _visitor.Visit(server as IOpenApiExtensible); } /// /// Visits dictionary of /// - internal void Walk(IDictionary serverVariables) + internal void Walk(IDictionary? serverVariables) { if (serverVariables == null) { @@ -558,7 +558,7 @@ internal void Walk(IOpenApiPathItem pathItem, bool isComponent = false) /// /// Visits dictionary of /// - internal void Walk(IDictionary operations) + internal void Walk(IDictionary? operations) { if (operations == null) { @@ -602,7 +602,7 @@ internal void Walk(OpenApiOperation operation) /// /// Visits list of /// - internal void Walk(IList securityRequirements) + internal void Walk(IList? securityRequirements) { if (securityRequirements == null) { @@ -623,7 +623,7 @@ internal void Walk(IList securityRequirements) /// /// Visits list of /// - internal void Walk(IList parameters) + internal void Walk(IList? parameters) { if (parameters == null) { @@ -668,7 +668,7 @@ internal void Walk(IOpenApiParameter parameter, bool isComponent = false) /// /// Visits and child objects /// - internal void Walk(OpenApiResponses responses) + internal void Walk(OpenApiResponses? responses) { if (responses == null) { @@ -715,7 +715,7 @@ internal void Walk(IOpenApiResponse response, bool isComponent = false) /// /// Visits and child objects /// - internal void Walk(IOpenApiRequestBody requestBody, bool isComponent = false) + internal void Walk(IOpenApiRequestBody? requestBody, bool isComponent = false) { if (requestBody == null) { @@ -740,7 +740,7 @@ internal void Walk(IOpenApiRequestBody requestBody, bool isComponent = false) /// /// Visits dictionary of /// - internal void Walk(IDictionary headers) + internal void Walk(IDictionary? headers) { if (headers == null) { @@ -762,7 +762,7 @@ internal void Walk(IDictionary headers) /// /// Visits dictionary of /// - internal void Walk(IDictionary callbacks) + internal void Walk(IDictionary? callbacks) { if (callbacks == null) { @@ -784,7 +784,7 @@ internal void Walk(IDictionary callbacks) /// /// Visits dictionary of /// - internal void Walk(IDictionary content) + internal void Walk(IDictionary? content) { if (content == null) { @@ -824,7 +824,7 @@ internal void Walk(OpenApiMediaType mediaType) /// /// Visits dictionary of /// - internal void Walk(IDictionary encodings) + internal void Walk(IDictionary? encodings) { if (encodings == null) { @@ -866,7 +866,7 @@ internal void Walk(OpenApiEncoding encoding) /// /// Visits and child objects /// - internal void Walk(IOpenApiSchema schema, bool isComponent = false) + internal void Walk(IOpenApiSchema? schema, bool isComponent = false) { if (schema == null || schema is IOpenApiReferenceHolder holder && ProcessAsReference(holder, isComponent)) { @@ -936,7 +936,7 @@ internal void Walk(IOpenApiSchema schema, bool isComponent = false) /// /// Visits dictionary of /// - internal void Walk(IDictionary examples) + internal void Walk(IDictionary? examples) { if (examples == null) { @@ -959,7 +959,7 @@ internal void Walk(IDictionary examples) /// /// Visits and child objects /// - internal void Walk(JsonNode example) + internal void Walk(JsonNode? example) { if (example == null) { @@ -1061,7 +1061,7 @@ internal void Walk(OpenApiOAuthFlow oAuthFlow) /// /// Visits dictionary of and child objects /// - internal void Walk(IDictionary links) + internal void Walk(IDictionary? links) { if (links == null) { @@ -1254,7 +1254,7 @@ public class CurrentKeys /// /// Current Path key /// - public string Path { get; set; } + public string? Path { get; set; } /// /// Current Operation Type @@ -1264,46 +1264,46 @@ public class CurrentKeys /// /// Current Response Status Code /// - public string Response { get; set; } + public string? Response { get; set; } /// /// Current Content Media Type /// - public string Content { get; set; } + public string? Content { get; set; } /// /// Current Callback Key /// - public string Callback { get; set; } + public string? Callback { get; set; } /// /// Current Link Key /// - public string Link { get; set; } + public string? Link { get; set; } /// /// Current Header Key /// - public string Header { get; internal set; } + public string? Header { get; internal set; } /// /// Current Encoding Key /// - public string Encoding { get; internal set; } + public string? Encoding { get; internal set; } /// /// Current Example Key /// - public string Example { get; internal set; } + public string? Example { get; internal set; } /// /// Current Extension Key /// - public string Extension { get; internal set; } + public string? Extension { get; internal set; } /// /// Current ServerVariable /// - public string ServerVariable { get; internal set; } + public string? ServerVariable { get; internal set; } } } diff --git a/src/Microsoft.OpenApi/Services/OpenApiWorkspace.cs b/src/Microsoft.OpenApi/Services/OpenApiWorkspace.cs index ec368a6c0..21710fcbf 100644 --- a/src/Microsoft.OpenApi/Services/OpenApiWorkspace.cs +++ b/src/Microsoft.OpenApi/Services/OpenApiWorkspace.cs @@ -23,7 +23,7 @@ public class OpenApiWorkspace /// /// The base location from where all relative references are resolved /// - public Uri BaseUrl { get; } + public Uri? BaseUrl { get; } /// /// Initialize workspace pointing to a base URL to allow resolving relative document locations. Use a file:// url to point to a folder @@ -69,78 +69,107 @@ public void RegisterComponents(OpenApiDocument document) string location; // Register Schema - foreach (var item in document.Components.Schemas) + if (document.Components.Schemas != null) { - location = item.Value.Id ?? baseUri + ReferenceType.Schema.GetDisplayName() + ComponentSegmentSeparator + item.Key; - - RegisterComponent(location, item.Value); + foreach (var item in document.Components.Schemas) + { + location = item.Value.Id ?? baseUri + ReferenceType.Schema.GetDisplayName() + ComponentSegmentSeparator + item.Key; + RegisterComponent(location, item.Value); + } } // Register Parameters - foreach (var item in document.Components.Parameters) + if (document.Components.Parameters != null) { - location = baseUri + ReferenceType.Parameter.GetDisplayName() + ComponentSegmentSeparator + item.Key; - RegisterComponent(location, item.Value); + foreach (var item in document.Components.Parameters) + { + location = baseUri + ReferenceType.Parameter.GetDisplayName() + ComponentSegmentSeparator + item.Key; + RegisterComponent(location, item.Value); + } } // Register Responses - foreach (var item in document.Components.Responses) + if (document.Components.Responses != null) { - location = baseUri + ReferenceType.Response.GetDisplayName() + ComponentSegmentSeparator + item.Key; - RegisterComponent(location, item.Value); + foreach (var item in document.Components.Responses) + { + location = baseUri + ReferenceType.Response.GetDisplayName() + ComponentSegmentSeparator + item.Key; + RegisterComponent(location, item.Value); + } } // Register RequestBodies - foreach (var item in document.Components.RequestBodies) + if (document.Components.RequestBodies != null) { - location = baseUri + ReferenceType.RequestBody.GetDisplayName() + ComponentSegmentSeparator + item.Key; - RegisterComponent(location, item.Value); + foreach (var item in document.Components.RequestBodies) + { + location = baseUri + ReferenceType.RequestBody.GetDisplayName() + ComponentSegmentSeparator + item.Key; + RegisterComponent(location, item.Value); + } } // Register Links - foreach (var item in document.Components.Links) + if (document.Components.Links != null) { - location = baseUri + ReferenceType.Link.GetDisplayName() + ComponentSegmentSeparator + item.Key; - RegisterComponent(location, item.Value); + foreach (var item in document.Components.Links) + { + location = baseUri + ReferenceType.Link.GetDisplayName() + ComponentSegmentSeparator + item.Key; + RegisterComponent(location, item.Value); + } } // Register Callbacks - foreach (var item in document.Components.Callbacks) + if (document.Components.Callbacks != null) { - location = baseUri + ReferenceType.Callback.GetDisplayName() + ComponentSegmentSeparator + item.Key; - RegisterComponent(location, item.Value); + foreach (var item in document.Components.Callbacks) + { + location = baseUri + ReferenceType.Callback.GetDisplayName() + ComponentSegmentSeparator + item.Key; + RegisterComponent(location, item.Value); + } } // Register PathItems - foreach (var item in document.Components.PathItems) + if (document.Components.PathItems != null) { - location = baseUri + ReferenceType.PathItem.GetDisplayName() + ComponentSegmentSeparator + item.Key; - RegisterComponent(location, item.Value); + foreach (var item in document.Components.PathItems) + { + location = baseUri + ReferenceType.PathItem.GetDisplayName() + ComponentSegmentSeparator + item.Key; + RegisterComponent(location, item.Value); + } } // Register Examples - foreach (var item in document.Components.Examples) + if (document.Components.Examples != null) { - location = baseUri + ReferenceType.Example.GetDisplayName() + ComponentSegmentSeparator + item.Key; - RegisterComponent(location, item.Value); + foreach (var item in document.Components.Examples) + { + location = baseUri + ReferenceType.Example.GetDisplayName() + ComponentSegmentSeparator + item.Key; + RegisterComponent(location, item.Value); + } } // Register Headers - foreach (var item in document.Components.Headers) + if (document.Components.Headers != null) { - location = baseUri + ReferenceType.Header.GetDisplayName() + ComponentSegmentSeparator + item.Key; - RegisterComponent(location, item.Value); + foreach (var item in document.Components.Headers) + { + location = baseUri + ReferenceType.Header.GetDisplayName() + ComponentSegmentSeparator + item.Key; + RegisterComponent(location, item.Value); + } } // Register SecuritySchemes - foreach (var item in document.Components.SecuritySchemes) + if (document.Components.SecuritySchemes != null) { - location = baseUri + ReferenceType.SecurityScheme.GetDisplayName() + ComponentSegmentSeparator + item.Key; - RegisterComponent(location, item.Value); + foreach (var item in document.Components.SecuritySchemes) + { + location = baseUri + ReferenceType.SecurityScheme.GetDisplayName() + ComponentSegmentSeparator + item.Key; + RegisterComponent(location, item.Value); + } } } - private string getBaseUri(OpenApiDocument openApiDocument) + private static string getBaseUri(OpenApiDocument openApiDocument) { return openApiDocument.BaseUri + OpenApiConstants.ComponentsSegment; } @@ -176,7 +205,7 @@ public bool RegisterComponentForDocument(OpenApiDocument openApiDocument, T c IOpenApiExample => baseUri + ReferenceType.Example.GetDisplayName() + ComponentSegmentSeparator + id, IOpenApiHeader => baseUri + ReferenceType.Header.GetDisplayName() + ComponentSegmentSeparator + id, IOpenApiSecurityScheme => baseUri + ReferenceType.SecurityScheme.GetDisplayName() + ComponentSegmentSeparator + id, - _ => throw new ArgumentException($"Invalid component type {componentToRegister.GetType().Name}"), + _ => throw new ArgumentException($"Invalid component type {componentToRegister?.GetType().Name}"), }; return RegisterComponent(location, componentToRegister); @@ -191,22 +220,23 @@ public bool RegisterComponentForDocument(OpenApiDocument openApiDocument, T c internal bool RegisterComponent(string location, T component) { var uri = ToLocationUrl(location); - if (component is IOpenApiReferenceable referenceable) + if (uri is not null) { - if (!_IOpenApiReferenceableRegistry.ContainsKey(uri)) + if (component is IOpenApiReferenceable referenceable) { - _IOpenApiReferenceableRegistry[uri] = referenceable; - return true; + if (!_IOpenApiReferenceableRegistry.ContainsKey(uri)) + { + _IOpenApiReferenceableRegistry[uri] = referenceable; + return true; + } } - } - else if (component is Stream stream) - { - if (!_artifactsRegistry.ContainsKey(uri)) + else if (component is Stream stream && !_artifactsRegistry.ContainsKey(uri)) { _artifactsRegistry[uri] = stream; return true; } - } + return false; + } return false; } @@ -216,9 +246,9 @@ internal bool RegisterComponent(string location, T component) /// /// /// - public void AddDocumentId(string key, Uri value) + public void AddDocumentId(string? key, Uri? value) { - if (!_documentsIdRegistry.ContainsKey(key)) + if (key is not null && value is not null && !_documentsIdRegistry.ContainsKey(key)) { _documentsIdRegistry[key] = value; } @@ -229,12 +259,13 @@ public void AddDocumentId(string key, Uri value) /// /// /// The document id of the given key. - public Uri GetDocumentId(string key) + public Uri? GetDocumentId(string? key) { - if (_documentsIdRegistry.TryGetValue(key, out var id)) + if (key is not null && _documentsIdRegistry.TryGetValue(key, out var id)) { return id; } + return null; } @@ -246,6 +277,7 @@ public Uri GetDocumentId(string key) public bool Contains(string location) { var key = ToLocationUrl(location); + if (key is null) return false; return _IOpenApiReferenceableRegistry.ContainsKey(key) || _artifactsRegistry.ContainsKey(key); } @@ -260,23 +292,30 @@ public bool Contains(string location) { if (string.IsNullOrEmpty(location)) return default; - var uri = ToLocationUrl(location); - if (_IOpenApiReferenceableRegistry.TryGetValue(uri, out var referenceableValue)) - { - return (T)referenceableValue; - } - else if (_artifactsRegistry.TryGetValue(uri, out var artifact)) + var uri = ToLocationUrl(location); + if (uri is not null) { - return (T)(object)artifact; - } + if (_IOpenApiReferenceableRegistry.TryGetValue(uri, out var referenceableValue)) + { + return (T)referenceableValue; + } + else if (_artifactsRegistry.TryGetValue(uri, out var artifact)) + { + return (T)(object)artifact; + } + } return default; } #nullable restore - private Uri ToLocationUrl(string location) + private Uri? ToLocationUrl(string location) { - return new(BaseUrl, location); + if (BaseUrl is not null) + { + return new(BaseUrl, location); + } + return null; } } } diff --git a/src/Microsoft.OpenApi/Services/OperationSearch.cs b/src/Microsoft.OpenApi/Services/OperationSearch.cs index c726ac966..1b6379cff 100644 --- a/src/Microsoft.OpenApi/Services/OperationSearch.cs +++ b/src/Microsoft.OpenApi/Services/OperationSearch.cs @@ -34,21 +34,24 @@ public OperationSearch(Func pred /// public override void Visit(IOpenApiPathItem pathItem) { - foreach (var item in pathItem.Operations) + if (pathItem.Operations is not null) { - var operation = item.Value; - var operationType = item.Key; - - if (_predicate(CurrentKeys.Path, operationType, operation)) + foreach (var item in pathItem.Operations) { - _searchResults.Add(new() + var operation = item.Value; + var operationType = item.Key; + + if (CurrentKeys.Path is not null && _predicate(CurrentKeys.Path, operationType, operation)) { - Operation = operation, - Parameters = pathItem.Parameters, - CurrentKeys = CopyCurrentKeys(CurrentKeys, operationType) - }); + _searchResults.Add(new() + { + Operation = operation, + Parameters = pathItem.Parameters, + CurrentKeys = CopyCurrentKeys(CurrentKeys, operationType) + }); + } } - } + } } /// diff --git a/src/Microsoft.OpenApi/Services/SearchResult.cs b/src/Microsoft.OpenApi/Services/SearchResult.cs index 6bbeed27a..2fea9e03d 100644 --- a/src/Microsoft.OpenApi/Services/SearchResult.cs +++ b/src/Microsoft.OpenApi/Services/SearchResult.cs @@ -15,16 +15,16 @@ public class SearchResult /// /// An object containing contextual information based on where the walker is currently referencing in an OpenApiDocument. /// - public CurrentKeys CurrentKeys { get; set; } + public CurrentKeys? CurrentKeys { get; set; } /// /// An Operation object. /// - public OpenApiOperation Operation { get; set; } + public OpenApiOperation? Operation { get; set; } /// /// Parameters object /// - public IList Parameters { get; set; } + public IList? Parameters { get; set; } } } diff --git a/src/Microsoft.OpenApi/Utils.cs b/src/Microsoft.OpenApi/Utils.cs index 094361bb9..22596b0e8 100644 --- a/src/Microsoft.OpenApi/Utils.cs +++ b/src/Microsoft.OpenApi/Utils.cs @@ -36,11 +36,11 @@ internal static T CheckArgumentNull( /// The input string value. /// The input parameter name. /// The input value. - internal static string CheckArgumentNullOrEmpty( + internal static string? CheckArgumentNullOrEmpty( #if NET5_0_OR_GREATER - [NotNull] string value, + [NotNull] string? value, #else - string value, + string? value, #endif [CallerArgumentExpression(nameof(value))] string parameterName = "") { diff --git a/src/Microsoft.OpenApi/Validations/IValidationContext.cs b/src/Microsoft.OpenApi/Validations/IValidationContext.cs index 36c26baa6..9ad715976 100644 --- a/src/Microsoft.OpenApi/Validations/IValidationContext.cs +++ b/src/Microsoft.OpenApi/Validations/IValidationContext.cs @@ -41,6 +41,6 @@ public interface IValidationContext /// /// /// - OpenApiDocument HostDocument { get; } + OpenApiDocument? HostDocument { get; } } } diff --git a/src/Microsoft.OpenApi/Validations/OpenApiValidator.cs b/src/Microsoft.OpenApi/Validations/OpenApiValidator.cs index 784f06172..fce244aa4 100644 --- a/src/Microsoft.OpenApi/Validations/OpenApiValidator.cs +++ b/src/Microsoft.OpenApi/Validations/OpenApiValidator.cs @@ -25,7 +25,7 @@ public class OpenApiValidator : OpenApiVisitorBase, IValidationContext /// /// /// - public OpenApiValidator(ValidationRuleSet ruleSet, OpenApiDocument hostDocument = null) + public OpenApiValidator(ValidationRuleSet ruleSet, OpenApiDocument? hostDocument = null) { _ruleSet = ruleSet; HostDocument = hostDocument; @@ -44,7 +44,7 @@ public OpenApiValidator(ValidationRuleSet ruleSet, OpenApiDocument hostDocument /// /// The host document used for validation. /// - public OpenApiDocument HostDocument { get; set; } + public OpenApiDocument? HostDocument { get; set; } /// /// Register an error with the validation context. @@ -93,7 +93,7 @@ public void AddWarning(OpenApiValidatorWarning warning) public override void Visit(OpenApiResponses response) => Validate(response); /// - public override void Visit(OpenApiExternalDocs externalDocs) => Validate(externalDocs); + public override void Visit(OpenApiExternalDocs? externalDocs) => Validate(externalDocs); /// public override void Visit(OpenApiLicense license) => Validate(license); @@ -120,7 +120,7 @@ public void AddWarning(OpenApiValidatorWarning warning) public override void Visit(IOpenApiCallback callback) => Validate(callback); /// - public override void Visit(IOpenApiExtensible openApiExtensible) => Validate(openApiExtensible); + public override void Visit(IOpenApiExtensible? openApiExtensible) => Validate(openApiExtensible); /// public override void Visit(IOpenApiExtension openApiExtension) => Validate(openApiExtension, openApiExtension.GetType()); @@ -182,7 +182,7 @@ private void Validate(T item) /// This overload allows applying rules based on actual object type, rather than matched interface. This is /// needed for validating extensions. /// - private void Validate(object item, Type type) + private void Validate(object? item, Type type) { if (item == null) { @@ -196,10 +196,13 @@ private void Validate(object item, Type type) } var rules = _ruleSet.FindRules(type); - foreach (var rule in rules) + if (rules is not null) { - rule.Evaluate(this, item); - } + foreach (var rule in rules) + { + rule.Evaluate(this, item); + } + } } } } diff --git a/src/Microsoft.OpenApi/Validations/Rules/OpenApiComponentsRules.cs b/src/Microsoft.OpenApi/Validations/Rules/OpenApiComponentsRules.cs index bd14f93ed..80ab4e9ab 100644 --- a/src/Microsoft.OpenApi/Validations/Rules/OpenApiComponentsRules.cs +++ b/src/Microsoft.OpenApi/Validations/Rules/OpenApiComponentsRules.cs @@ -46,7 +46,7 @@ public static class OpenApiComponentsRules ValidateKeys(context, components.Callbacks?.Keys, "callbacks"); }); - private static void ValidateKeys(IValidationContext context, IEnumerable keys, string component) + private static void ValidateKeys(IValidationContext context, IEnumerable? keys, string component) { if (keys == null) { diff --git a/src/Microsoft.OpenApi/Validations/Rules/OpenApiExtensionRules.cs b/src/Microsoft.OpenApi/Validations/Rules/OpenApiExtensionRules.cs index 545f68f85..9853acb37 100644 --- a/src/Microsoft.OpenApi/Validations/Rules/OpenApiExtensionRules.cs +++ b/src/Microsoft.OpenApi/Validations/Rules/OpenApiExtensionRules.cs @@ -23,12 +23,15 @@ public static class OpenApiExtensibleRules (context, item) => { context.Enter("extensions"); - foreach (var extensible in item.Extensions.Keys.Where(static x => !x.StartsWith(OpenApiConstants.ExtensionFieldNamePrefix, StringComparison.OrdinalIgnoreCase))) + if (item.Extensions is not null) { - context.CreateError(nameof(ExtensionNameMustStartWithXDash), - string.Format(SRResource.Validation_ExtensionNameMustBeginWithXDash, extensible, context.PathString)); - } - context.Exit(); + foreach (var extensible in item.Extensions.Keys.Where(static x => !x.StartsWith(OpenApiConstants.ExtensionFieldNamePrefix, StringComparison.OrdinalIgnoreCase))) + { + context.CreateError(nameof(ExtensionNameMustStartWithXDash), + string.Format(SRResource.Validation_ExtensionNameMustBeginWithXDash, extensible, context.PathString)); + } + context.Exit(); + } }); } } diff --git a/src/Microsoft.OpenApi/Validations/Rules/OpenApiNonDefaultRules.cs b/src/Microsoft.OpenApi/Validations/Rules/OpenApiNonDefaultRules.cs index 03661401c..70dc7396a 100644 --- a/src/Microsoft.OpenApi/Validations/Rules/OpenApiNonDefaultRules.cs +++ b/src/Microsoft.OpenApi/Validations/Rules/OpenApiNonDefaultRules.cs @@ -89,9 +89,9 @@ public static class OpenApiNonDefaultRules private static void ValidateMismatchedDataType(IValidationContext context, string ruleName, - JsonNode example, - IDictionary examples, - IOpenApiSchema schema) + JsonNode? example, + IDictionary? examples, + IOpenApiSchema? schema) { // example context.Enter("example"); diff --git a/src/Microsoft.OpenApi/Validations/Rules/OpenApiSchemaRules.cs b/src/Microsoft.OpenApi/Validations/Rules/OpenApiSchemaRules.cs index b954c96b6..9884d54dd 100644 --- a/src/Microsoft.OpenApi/Validations/Rules/OpenApiSchemaRules.cs +++ b/src/Microsoft.OpenApi/Validations/Rules/OpenApiSchemaRules.cs @@ -46,28 +46,32 @@ public static class OpenApiSchemaRules /// The parent schema. /// Adds support for polymorphism. The discriminator is an object name that is used to differentiate /// between other schemas which may satisfy the payload description. - public static bool ValidateChildSchemaAgainstDiscriminator(IOpenApiSchema schema, string discriminatorName) + public static bool ValidateChildSchemaAgainstDiscriminator(IOpenApiSchema schema, string? discriminatorName) { - if (!schema.Required?.Contains(discriminatorName) ?? false) + if (discriminatorName is not null) { - // recursively check nested schema.OneOf, schema.AnyOf or schema.AllOf and their required fields for the discriminator - if (schema.OneOf.Count != 0) + if (!schema.Required?.Contains(discriminatorName) ?? false) { - return TraverseSchemaElements(discriminatorName, schema.OneOf); - } - if (schema.AnyOf.Count != 0) - { - return TraverseSchemaElements(discriminatorName, schema.AnyOf); + // recursively check nested schema.OneOf, schema.AnyOf or schema.AllOf and their required fields for the discriminator + if (schema.OneOf?.Count != 0) + { + return TraverseSchemaElements(discriminatorName, schema.OneOf); + } + if (schema.AnyOf?.Count != 0) + { + return TraverseSchemaElements(discriminatorName, schema.AnyOf); + } + if (schema.AllOf?.Count != 0) + { + return TraverseSchemaElements(discriminatorName, schema.AllOf); + } } - if (schema.AllOf.Count != 0) + else { - return TraverseSchemaElements(discriminatorName, schema.AllOf); + return true; } - } - else - { - return true; - } + return false; + } return false; } @@ -79,20 +83,24 @@ public static bool ValidateChildSchemaAgainstDiscriminator(IOpenApiSchema schema /// between other schemas which may satisfy the payload description. /// The child schema. /// - public static bool TraverseSchemaElements(string discriminatorName, IList childSchema) + public static bool TraverseSchemaElements(string discriminatorName, IList? childSchema) { - foreach (var childItem in childSchema) + if (childSchema is not null) { - if ((!childItem.Properties?.ContainsKey(discriminatorName) ?? false) && - (!childItem.Required?.Contains(discriminatorName) ?? false)) + foreach (var childItem in childSchema) { - return ValidateChildSchemaAgainstDiscriminator(childItem, discriminatorName); - } - else - { - return true; + if ((!childItem.Properties?.ContainsKey(discriminatorName) ?? false) && + (!childItem.Required?.Contains(discriminatorName) ?? false)) + { + return ValidateChildSchemaAgainstDiscriminator(childItem, discriminatorName); + } + else + { + return true; + } } - } + return false; + } return false; } diff --git a/src/Microsoft.OpenApi/Validations/Rules/OpenApiServerRules.cs b/src/Microsoft.OpenApi/Validations/Rules/OpenApiServerRules.cs index 35d4b9a25..d4ffc5429 100644 --- a/src/Microsoft.OpenApi/Validations/Rules/OpenApiServerRules.cs +++ b/src/Microsoft.OpenApi/Validations/Rules/OpenApiServerRules.cs @@ -29,13 +29,16 @@ public static class OpenApiServerRules context.Exit(); context.Enter("variables"); - foreach (var variable in server.Variables) + if (server.Variables is not null) { - context.Enter(variable.Key); - ValidateServerVariableRequiredFields(context, variable.Key, variable.Value); + foreach (var variable in server.Variables) + { + context.Enter(variable.Key); + ValidateServerVariableRequiredFields(context, variable.Key, variable.Value); + context.Exit(); + } context.Exit(); - } - context.Exit(); + } }); // add more rules diff --git a/src/Microsoft.OpenApi/Validations/Rules/RuleHelpers.cs b/src/Microsoft.OpenApi/Validations/Rules/RuleHelpers.cs index 63ca4d05e..64f46b5fd 100644 --- a/src/Microsoft.OpenApi/Validations/Rules/RuleHelpers.cs +++ b/src/Microsoft.OpenApi/Validations/Rules/RuleHelpers.cs @@ -44,8 +44,8 @@ public static bool IsEmailAddress(this string input) public static void ValidateDataTypeMismatch( IValidationContext context, string ruleName, - JsonNode value, - IOpenApiSchema schema) + JsonNode? value, + IOpenApiSchema? schema) { if (schema == null) { @@ -53,14 +53,14 @@ public static void ValidateDataTypeMismatch( } // convert value to JsonElement and access the ValueKind property to determine the type. - var valueKind = value.GetValueKind(); + var valueKind = value?.GetValueKind(); var type = schema.Type.ToIdentifier(); var format = schema.Format; // Before checking the type, check first if the schema allows null. // If so and the data given is also null, this is allowed for any type. - if ((schema.Type.Value & JsonSchemaType.Null) is JsonSchemaType.Null && valueKind is JsonValueKind.Null) + if (schema.Type is not null && (schema.Type.Value & JsonSchemaType.Null) is JsonSchemaType.Null && valueKind is JsonValueKind.Null) { return; } diff --git a/src/Microsoft.OpenApi/Validations/ValidationRuleSet.cs b/src/Microsoft.OpenApi/Validations/ValidationRuleSet.cs index 3e38d65b2..4a0720773 100644 --- a/src/Microsoft.OpenApi/Validations/ValidationRuleSet.cs +++ b/src/Microsoft.OpenApi/Validations/ValidationRuleSet.cs @@ -18,9 +18,9 @@ public sealed class ValidationRuleSet { private Dictionary> _rulesDictionary = new(); - private static ValidationRuleSet _defaultRuleSet; + private static ValidationRuleSet? _defaultRuleSet; - private List _emptyRules = new(); + private readonly List? _emptyRules = new(); /// @@ -45,7 +45,7 @@ public ValidationRuleSet() /// /// The type that is to be validated /// Either the rules related to the type, or an empty list. - public IList FindRules(Type type) + public IList? FindRules(Type type) { _rulesDictionary.TryGetValue(type, out var results); return results ?? _emptyRules; @@ -219,7 +219,7 @@ public void Remove(string ruleName) /// true if the rule is successfully removed; otherwise, false. public bool Remove(Type key, ValidationRule rule) { - if (_rulesDictionary.TryGetValue(key, out IList validationRules)) + if (_rulesDictionary.TryGetValue(key, out IList? validationRules)) { return validationRules.Remove(rule); } @@ -263,7 +263,7 @@ public bool ContainsKey(Type key) /// public bool Contains(Type key, ValidationRule rule) { - return _rulesDictionary.TryGetValue(key, out IList validationRules) && validationRules.Contains(rule); + return _rulesDictionary.TryGetValue(key, out IList? validationRules) && validationRules.Contains(rule); } /// @@ -274,7 +274,7 @@ public bool Contains(Type key, ValidationRule rule) /// key is found; otherwise, an empty object. /// This parameter is passed uninitialized. /// true if the specified key has rules. - public bool TryGetValue(Type key, out IList rules) + public bool TryGetValue(Type key, out IList? rules) { return _rulesDictionary.TryGetValue(key, out rules); } diff --git a/src/Microsoft.OpenApi/Writers/IOpenApiWriter.cs b/src/Microsoft.OpenApi/Writers/IOpenApiWriter.cs index 78be4e37f..b1b1681b5 100644 --- a/src/Microsoft.OpenApi/Writers/IOpenApiWriter.cs +++ b/src/Microsoft.OpenApi/Writers/IOpenApiWriter.cs @@ -34,12 +34,12 @@ public interface IOpenApiWriter /// /// Write the property name. /// - void WritePropertyName(string name); + void WritePropertyName(string? name); /// /// Write the string value. /// - void WriteValue(string value); + void WriteValue(string? value); /// /// Write the decimal value. diff --git a/src/Microsoft.OpenApi/Writers/OpenApiJsonWriter.cs b/src/Microsoft.OpenApi/Writers/OpenApiJsonWriter.cs index 15b7b07f7..3226dda25 100644 --- a/src/Microsoft.OpenApi/Writers/OpenApiJsonWriter.cs +++ b/src/Microsoft.OpenApi/Writers/OpenApiJsonWriter.cs @@ -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; @@ -34,7 +34,7 @@ public OpenApiJsonWriter(TextWriter textWriter, OpenApiJsonWriterSettings settin /// The text writer. /// Settings for controlling how the OpenAPI document will be written out. /// Setting for allowing the JSON emitted to be in terse format. - public OpenApiJsonWriter(TextWriter textWriter, OpenApiWriterSettings settings, bool terseOutput = false) : base(textWriter, settings) + public OpenApiJsonWriter(TextWriter textWriter, OpenApiWriterSettings? settings, bool terseOutput = false) : base(textWriter, settings) { _produceTerseOutput = terseOutput; } @@ -153,23 +153,26 @@ public override void WriteEndArray() /// /// The property name. /// public override void WritePropertyName(string name) - public override void WritePropertyName(string name) + public override void WritePropertyName(string? name) { VerifyCanWritePropertyName(name); var currentScope = CurrentScope(); - if (currentScope.ObjectCount != 0) + if (currentScope is not null) { - Writer.Write(WriterConstants.ObjectMemberSeparator); - } + if (currentScope.ObjectCount != 0) + { + Writer.Write(WriterConstants.ObjectMemberSeparator); + } - WriteLine(); + WriteLine(); - currentScope.ObjectCount++; + currentScope.ObjectCount++; + } WriteIndentation(); - name = name.GetJsonCompatibleString(); + name = name?.GetJsonCompatibleString(); Writer.Write(name); @@ -185,11 +188,11 @@ public override void WritePropertyName(string name) /// Write string value. /// /// The string value. - public override void WriteValue(string value) + public override void WriteValue(string? value) { WriteValueSeparator(); - value = value.GetJsonCompatibleString(); + value = value?.GetJsonCompatibleString(); Writer.Write(value); } diff --git a/src/Microsoft.OpenApi/Writers/OpenApiWriterAnyExtensions.cs b/src/Microsoft.OpenApi/Writers/OpenApiWriterAnyExtensions.cs index fd2ff1387..931a660e3 100644 --- a/src/Microsoft.OpenApi/Writers/OpenApiWriterAnyExtensions.cs +++ b/src/Microsoft.OpenApi/Writers/OpenApiWriterAnyExtensions.cs @@ -22,7 +22,7 @@ public static class OpenApiWriterAnyExtensions /// The Open API writer. /// The specification extensions. /// Version of the OpenAPI specification that that will be output. - public static void WriteExtensions(this IOpenApiWriter writer, IDictionary extensions, OpenApiSpecVersion specVersion) + public static void WriteExtensions(this IOpenApiWriter writer, IDictionary? extensions, OpenApiSpecVersion specVersion) { Utils.CheckArgumentNull(writer); @@ -49,7 +49,7 @@ public static void WriteExtensions(this IOpenApiWriter writer, IDictionary /// The Open API writer. /// The JsonNode value - public static void WriteAny(this IOpenApiWriter writer, JsonNode node) + public static void WriteAny(this IOpenApiWriter writer, JsonNode? node) { Utils.CheckArgumentNull(writer); @@ -84,28 +84,31 @@ public static void WriteAny(this IOpenApiWriter writer, JsonNode node) } } - private static void WriteArray(this IOpenApiWriter writer, JsonArray array) + private static void WriteArray(this IOpenApiWriter writer, JsonArray? array) { writer.WriteStartArray(); - - foreach (var item in array) + if (array is not null) { - writer.WriteAny(item); - } + foreach (var item in array) + { + writer.WriteAny(item); + } + } writer.WriteEndArray(); } - private static void WriteObject(this IOpenApiWriter writer, JsonObject entity) + private static void WriteObject(this IOpenApiWriter writer, JsonObject? entity) { writer.WriteStartObject(); - - foreach (var item in entity) + if (entity is not null) { - writer.WritePropertyName(item.Key); - writer.WriteAny(item.Value); + foreach (var item in entity) + { + writer.WritePropertyName(item.Key); + writer.WriteAny(item.Value); + } } - writer.WriteEndObject(); } diff --git a/src/Microsoft.OpenApi/Writers/OpenApiWriterBase.cs b/src/Microsoft.OpenApi/Writers/OpenApiWriterBase.cs index 7626f5908..18ba14300 100644 --- a/src/Microsoft.OpenApi/Writers/OpenApiWriterBase.cs +++ b/src/Microsoft.OpenApi/Writers/OpenApiWriterBase.cs @@ -52,7 +52,7 @@ protected OpenApiWriterBase(TextWriter textWriter) : this(textWriter, null) /// /// /// - protected OpenApiWriterBase(TextWriter textWriter, OpenApiWriterSettings settings) + protected OpenApiWriterBase(TextWriter textWriter, OpenApiWriterSettings? settings) { Writer = textWriter; Writer.NewLine = "\n"; @@ -99,7 +99,7 @@ protected OpenApiWriterBase(TextWriter textWriter, OpenApiWriterSettings setting /// /// Write the start property. /// - public abstract void WritePropertyName(string name); + public abstract void WritePropertyName(string? name); /// /// Writes a separator of a value if it's needed for the next value to be written. @@ -130,7 +130,7 @@ public Task FlushAsync(CancellationToken cancellationToken = default) /// Write string value. /// /// The string value. - public abstract void WriteValue(string value); + public abstract void WriteValue(string? value); /// /// Write float value. @@ -313,7 +313,7 @@ public virtual void WriteIndentation() /// Get current scope. /// /// - protected Scope CurrentScope() + protected Scope? CurrentScope() { return Scopes.Count == 0 ? null : Scopes.Peek(); } @@ -400,7 +400,7 @@ private bool IsScopeType(ScopeType type) /// the property name is a valid string and whether the current scope is an object scope. /// /// property name - protected void VerifyCanWritePropertyName(string name) + protected void VerifyCanWritePropertyName(string? name) { Utils.CheckArgumentNull(name); @@ -418,7 +418,7 @@ protected void VerifyCanWritePropertyName(string name) } /// - public void WriteV2Examples(IOpenApiWriter writer, OpenApiExample example, OpenApiSpecVersion version) + public static void WriteV2Examples(IOpenApiWriter writer, OpenApiExample example, OpenApiSpecVersion version) { writer.WriteStartObject(); diff --git a/src/Microsoft.OpenApi/Writers/OpenApiWriterExtensions.cs b/src/Microsoft.OpenApi/Writers/OpenApiWriterExtensions.cs index 8c49a2960..e8a4e2de0 100644 --- a/src/Microsoft.OpenApi/Writers/OpenApiWriterExtensions.cs +++ b/src/Microsoft.OpenApi/Writers/OpenApiWriterExtensions.cs @@ -21,7 +21,7 @@ public static class OpenApiWriterExtensions /// The writer. /// The property name. /// The property value. - public static void WriteProperty(this IOpenApiWriter writer, string name, string value) + public static void WriteProperty(this IOpenApiWriter writer, string name, string? value) { if (value == null) { @@ -39,7 +39,7 @@ public static void WriteProperty(this IOpenApiWriter writer, string name, string /// The writer. /// The property name. /// The property value. - public static void WriteRequiredProperty(this IOpenApiWriter writer, string name, string value) + public static void WriteRequiredProperty(this IOpenApiWriter writer, string name, string? value) { Utils.CheckArgumentNullOrEmpty(name); writer.WritePropertyName(name); @@ -191,7 +191,7 @@ public static void WriteRequiredObject( public static void WriteOptionalCollection( this IOpenApiWriter writer, string name, - IEnumerable elements, + IEnumerable? elements, Action action) { if (elements != null && elements.Any()) @@ -211,7 +211,7 @@ public static void WriteOptionalCollection( public static void WriteOptionalCollection( this IOpenApiWriter writer, string name, - IEnumerable elements, + IEnumerable? elements, Action action) { if (elements != null && elements.Any()) @@ -248,7 +248,7 @@ public static void WriteRequiredCollection( public static void WriteRequiredMap( this IOpenApiWriter writer, string name, - IDictionary elements, + IDictionary? elements, Action action) { writer.WriteMapInternal(name, elements, action); @@ -264,7 +264,7 @@ public static void WriteRequiredMap( public static void WriteOptionalMap( this IOpenApiWriter writer, string name, - IDictionary elements, + IDictionary? elements, Action action) { if (elements != null && elements.Any()) @@ -283,7 +283,7 @@ public static void WriteOptionalMap( public static void WriteOptionalMap( this IOpenApiWriter writer, string name, - IDictionary elements, + IDictionary? elements, Action action) { if (elements != null && elements.Any()) @@ -302,7 +302,7 @@ public static void WriteOptionalMap( public static void WriteOptionalMap( this IOpenApiWriter writer, string name, - IDictionary elements, + IDictionary? elements, Action action) { if (elements != null && elements.Any()) @@ -322,7 +322,7 @@ public static void WriteOptionalMap( public static void WriteOptionalMap( this IOpenApiWriter writer, string name, - IDictionary elements, + IDictionary? elements, Action action) where T : IOpenApiElement { @@ -343,7 +343,7 @@ public static void WriteOptionalMap( public static void WriteOptionalMap( this IOpenApiWriter writer, string name, - IDictionary elements, + IDictionary? elements, Action action) where T : IOpenApiElement { @@ -364,7 +364,7 @@ public static void WriteOptionalMap( public static void WriteRequiredMap( this IOpenApiWriter writer, string name, - IDictionary elements, + IDictionary? elements, Action action) where T : IOpenApiElement { @@ -402,7 +402,7 @@ private static void WriteCollectionInternal( private static void WriteMapInternal( this IOpenApiWriter writer, string name, - IDictionary elements, + IDictionary? elements, Action action) { WriteMapInternal(writer, name, elements, (w, _, s) => action(w, s)); @@ -411,7 +411,7 @@ private static void WriteMapInternal( private static void WriteMapInternal( this IOpenApiWriter writer, string name, - IDictionary elements, + IDictionary? elements, Action action) { Utils.CheckArgumentNull(action); diff --git a/src/Microsoft.OpenApi/Writers/OpenApiYamlWriter.cs b/src/Microsoft.OpenApi/Writers/OpenApiYamlWriter.cs index aaa160548..132021993 100644 --- a/src/Microsoft.OpenApi/Writers/OpenApiYamlWriter.cs +++ b/src/Microsoft.OpenApi/Writers/OpenApiYamlWriter.cs @@ -24,7 +24,7 @@ public OpenApiYamlWriter(TextWriter textWriter) : this(textWriter, null) /// /// The text writer. /// - public OpenApiYamlWriter(TextWriter textWriter, OpenApiWriterSettings settings) : base(textWriter, settings) + public OpenApiYamlWriter(TextWriter textWriter, OpenApiWriterSettings? settings) : base(textWriter, settings) { } @@ -135,46 +135,48 @@ public override void WriteEndArray() /// /// Write the property name and the delimiter. /// - public override void WritePropertyName(string name) + public override void WritePropertyName(string? name) { VerifyCanWritePropertyName(name); var currentScope = CurrentScope(); - - // If this is NOT the first property in the object, always start a new line and add indentation. - if (currentScope.ObjectCount != 0) - { - Writer.WriteLine(); - WriteIndentation(); - } - // Only add newline and indentation when this object is not in the top level scope and not in an array. - // The top level scope should have no indentation and it is already in its own line. - // The first property of an object inside array can go after the array prefix (-) directly. - else if (!IsTopLevelScope() && !currentScope.IsInArray) + if (currentScope is not null) { - Writer.WriteLine(); - WriteIndentation(); - } + // If this is NOT the first property in the object, always start a new line and add indentation. + if (currentScope.ObjectCount != 0) + { + Writer.WriteLine(); + WriteIndentation(); + } + // Only add newline and indentation when this object is not in the top level scope and not in an array. + // The top level scope should have no indentation and it is already in its own line. + // The first property of an object inside array can go after the array prefix (-) directly. + else if (!IsTopLevelScope() && !currentScope.IsInArray) + { + Writer.WriteLine(); + WriteIndentation(); + } - name = name.GetYamlCompatibleString(); + name = name?.GetYamlCompatibleString(); - Writer.Write(name); - Writer.Write(":"); + Writer.Write(name); + Writer.Write(":"); - currentScope.ObjectCount++; + currentScope.ObjectCount++; + } } /// /// Write string value. /// /// The string value. - public override void WriteValue(string value) + public override void WriteValue(string? value) { - if (!UseLiteralStyle || value.IndexOfAny(new[] { '\n', '\r' }) == -1) + if (!UseLiteralStyle || value?.IndexOfAny(new[] { '\n', '\r' }) == -1) { WriteValueSeparator(); - value = value.GetYamlCompatibleString(); + value = value?.GetYamlCompatibleString(); Writer.Write(value); } @@ -190,7 +192,7 @@ public override void WriteValue(string value) WriteChompingIndicator(value); // Write indentation indicator when it starts with spaces - if (value.StartsWith(" ", StringComparison.OrdinalIgnoreCase)) + if (value is not null && value.StartsWith(" ", StringComparison.OrdinalIgnoreCase)) { Writer.Write(IndentationString.Length); } @@ -199,8 +201,9 @@ public override void WriteValue(string value) IncreaseIndentation(); - using (var reader = new StringReader(value)) + if (value is not null) { + using var reader = new StringReader(value); var firstLine = true; while (reader.ReadLine() is var line && line != null) { @@ -217,32 +220,32 @@ public override void WriteValue(string value) Writer.Write(line); } - } + } DecreaseIndentation(); } } - private void WriteChompingIndicator(string value) + private void WriteChompingIndicator(string? value) { var trailingNewlines = 0; - var end = value.Length - 1; + var end = value?.Length - 1; // We only need to know whether there are 0, 1, or more trailing newlines while (end >= 0 && trailingNewlines < 2) { - var found = value.LastIndexOfAny(new[] { '\n', '\r' }, end, 2); + var found = value?.LastIndexOfAny(new[] { '\n', '\r' }, end.Value, 2); if (found == -1 || found != end) { // does not ends with newline break; } - if (value[end] == '\r') + if (value?[end.Value] == '\r') { // ends with \r end--; } - else if (end > 0 && value[end - 1] == '\r') + else if (end > 0 && value?[end.Value - 1] == '\r') { // ends with \r\n end -= 2; @@ -286,10 +289,11 @@ public override void WriteNull() /// protected override void WriteValueSeparator() { - if (IsArrayScope()) + var currentScopeCount = CurrentScope()?.ObjectCount; + if (currentScopeCount is not null && IsArrayScope()) { // If array is the outermost scope and this is the first item, there is no need to insert a newline. - if (!IsTopLevelScope() || CurrentScope().ObjectCount != 0) + if (!IsTopLevelScope() || currentScopeCount != 0) { Writer.WriteLine(); } @@ -297,7 +301,7 @@ protected override void WriteValueSeparator() WriteIndentation(); Writer.Write(WriterConstants.PrefixOfArrayItem); - CurrentScope().ObjectCount++; + currentScopeCount++; } else { diff --git a/test/Microsoft.OpenApi.Tests/Models/References/OpenApiCallbackReferenceTests.cs b/test/Microsoft.OpenApi.Tests/Models/References/OpenApiCallbackReferenceTests.cs index 34284b9bd..178c10eb5 100644 --- a/test/Microsoft.OpenApi.Tests/Models/References/OpenApiCallbackReferenceTests.cs +++ b/test/Microsoft.OpenApi.Tests/Models/References/OpenApiCallbackReferenceTests.cs @@ -149,13 +149,13 @@ public void CallbackReferenceResolutionWorks() Assert.NotEmpty(_externalCallbackReference.PathItems); Assert.Single(_externalCallbackReference.PathItems); Assert.Equal("{$request.body#/callbackUrl}", _externalCallbackReference.PathItems.First().Key.Expression); - Assert.Equal(OperationType.Post, _externalCallbackReference.PathItems.FirstOrDefault().Value.Operations.FirstOrDefault().Key);; + Assert.Equal(OperationType.Post, _externalCallbackReference.PathItems.FirstOrDefault().Value.Operations.FirstOrDefault().Key); // Local reference resolution works Assert.NotEmpty(_localCallbackReference.PathItems); Assert.Single(_localCallbackReference.PathItems); Assert.Equal("{$request.body#/callbackUrl}", _localCallbackReference.PathItems.First().Key.Expression); - Assert.Equal(OperationType.Post, _localCallbackReference.PathItems.FirstOrDefault().Value.Operations.FirstOrDefault().Key); ; + Assert.Equal(OperationType.Post, _localCallbackReference.PathItems.FirstOrDefault().Value.Operations.FirstOrDefault().Key); } [Theory] From b3b5663a37261911eb83b171c2de7803fac8da48 Mon Sep 17 00:00:00 2001 From: Maggiekimani1 Date: Thu, 13 Feb 2025 15:02:52 +0300 Subject: [PATCH 2/7] fix: dereference of a possible null reference --- .../Formatters/PowerShellFormatterTests.cs | 22 ++++++------ .../Services/OpenApiFilterServiceTests.cs | 20 +++++------ .../UtilityFiles/OpenApiDocumentMock.cs | 34 +++++++++---------- 3 files changed, 38 insertions(+), 38 deletions(-) diff --git a/test/Microsoft.OpenApi.Hidi.Tests/Formatters/PowerShellFormatterTests.cs b/test/Microsoft.OpenApi.Hidi.Tests/Formatters/PowerShellFormatterTests.cs index da6d8c61e..79a6c06ff 100644 --- a/test/Microsoft.OpenApi.Hidi.Tests/Formatters/PowerShellFormatterTests.cs +++ b/test/Microsoft.OpenApi.Hidi.Tests/Formatters/PowerShellFormatterTests.cs @@ -44,7 +44,7 @@ public void FormatOperationIdsInOpenAPIDocument(string operationId, string expec walker.Walk(openApiDocument); // Assert - Assert.Equal(expectedOperationId, openApiDocument.Paths[path].Operations[operationType].OperationId); + Assert.Equal(expectedOperationId, openApiDocument.Paths[path].Operations?[operationType].OperationId); } [Fact] @@ -61,20 +61,20 @@ public void RemoveAnyOfAndOneOfFromSchema() Assert.NotNull(openApiDocument.Components); Assert.NotNull(openApiDocument.Components.Schemas); var testSchema = openApiDocument.Components.Schemas["TestSchema"]; - var averageAudioDegradationProperty = testSchema.Properties["averageAudioDegradation"]; - var defaultPriceProperty = testSchema.Properties["defaultPrice"]; + var averageAudioDegradationProperty = testSchema.Properties?["averageAudioDegradation"]; + var defaultPriceProperty = testSchema.Properties?["defaultPrice"]; // Assert Assert.NotNull(openApiDocument.Components); Assert.NotNull(openApiDocument.Components.Schemas); Assert.NotNull(testSchema); - Assert.Null(averageAudioDegradationProperty.AnyOf); - Assert.Equal(JsonSchemaType.Number | JsonSchemaType.Null, averageAudioDegradationProperty.Type); - Assert.Equal("float", averageAudioDegradationProperty.Format); - Assert.Equal(JsonSchemaType.Null, averageAudioDegradationProperty.Type & JsonSchemaType.Null); - Assert.Null(defaultPriceProperty.OneOf); - Assert.Equal(JsonSchemaType.Number, defaultPriceProperty.Type); - Assert.Equal("double", defaultPriceProperty.Format); + Assert.Null(averageAudioDegradationProperty?.AnyOf); + Assert.Equal(JsonSchemaType.Number | JsonSchemaType.Null, averageAudioDegradationProperty?.Type); + Assert.Equal("float", averageAudioDegradationProperty?.Format); + Assert.Equal(JsonSchemaType.Null, averageAudioDegradationProperty?.Type & JsonSchemaType.Null); + Assert.Null(defaultPriceProperty?.OneOf); + Assert.Equal(JsonSchemaType.Number, defaultPriceProperty?.Type); + Assert.Equal("double", defaultPriceProperty?.Format); Assert.NotNull(testSchema.AdditionalProperties); } @@ -89,7 +89,7 @@ public void ResolveFunctionParameters() var walker = new OpenApiWalker(powerShellFormatter); walker.Walk(openApiDocument); - var idsParameter = openApiDocument.Paths["/foo"].Operations[OperationType.Get].Parameters?.Where(static p => p.Name == "ids").FirstOrDefault(); + var idsParameter = openApiDocument.Paths["/foo"].Operations?[OperationType.Get].Parameters?.Where(static p => p.Name == "ids").FirstOrDefault(); // Assert Assert.Null(idsParameter?.Content); diff --git a/test/Microsoft.OpenApi.Hidi.Tests/Services/OpenApiFilterServiceTests.cs b/test/Microsoft.OpenApi.Hidi.Tests/Services/OpenApiFilterServiceTests.cs index a3494ba13..ffc198911 100644 --- a/test/Microsoft.OpenApi.Hidi.Tests/Services/OpenApiFilterServiceTests.cs +++ b/test/Microsoft.OpenApi.Hidi.Tests/Services/OpenApiFilterServiceTests.cs @@ -100,9 +100,9 @@ public void TestPredicateFiltersUsingRelativeRequestUrls() var predicate = OpenApiFilterService.CreatePredicate(requestUrls: requestUrls, source: openApiDocument); // Then - Assert.True(predicate("/foo", OperationType.Get, null)); - Assert.True(predicate("/foo", OperationType.Post, null)); - Assert.False(predicate("/foo", OperationType.Patch, null)); + Assert.True(predicate("/foo", OperationType.Get, null!)); + Assert.True(predicate("/foo", OperationType.Post, null!)); + Assert.False(predicate("/foo", OperationType.Patch, null!)); } [Fact] @@ -153,7 +153,7 @@ public void CreateFilteredDocumentUsingPredicateFromRequestUrl() // Assert that there's only 1 parameter in the subset document Assert.NotNull(subsetDoc); Assert.NotEmpty(subsetDoc.Paths); - Assert.Single(subsetDoc.Paths.First().Value.Parameters); + Assert.Single(subsetDoc.Paths.First().Value.Parameters!); } [Fact] @@ -236,14 +236,14 @@ public async Task CopiesOverAllReferencedComponentsToTheSubsetDocumentCorrectly( var predicate = OpenApiFilterService.CreatePredicate(operationIds: operationIds); var subsetOpenApiDocument = OpenApiFilterService.CreateFilteredDocument(doc, predicate); - var response = subsetOpenApiDocument.Paths["/items"].Operations[OperationType.Get]?.Responses?["200"]; - var responseHeader = response?.Headers["x-custom-header"]; - var mediaTypeExample = response?.Content["application/json"]?.Examples?.First().Value; + var response = subsetOpenApiDocument.Paths["/items"].Operations?[OperationType.Get]?.Responses?["200"]; + var responseHeader = response?.Headers?["x-custom-header"]; + var mediaTypeExample = response?.Content?["application/json"]?.Examples?.First().Value; var targetHeaders = subsetOpenApiDocument.Components?.Headers; var targetExamples = subsetOpenApiDocument.Components?.Examples; // Assert - Assert.Same(doc.Servers, subsetOpenApiDocument.Servers); + Assert.Same(doc?.Servers, subsetOpenApiDocument.Servers); var headerReference = Assert.IsType(responseHeader); Assert.False(headerReference.UnresolvedReference); var exampleReference = Assert.IsType(mediaTypeExample); @@ -266,8 +266,8 @@ public void ReturnsPathParametersOnSlicingBasedOnOperationIdsOrTags(string? oper // Assert foreach (var pathItem in subsetOpenApiDocument.Paths) { - Assert.True(pathItem.Value.Parameters.Any()); - Assert.Single(pathItem.Value.Parameters); + Assert.True(pathItem.Value.Parameters!.Any()); + Assert.Single(pathItem.Value.Parameters!); } } } diff --git a/test/Microsoft.OpenApi.Hidi.Tests/UtilityFiles/OpenApiDocumentMock.cs b/test/Microsoft.OpenApi.Hidi.Tests/UtilityFiles/OpenApiDocumentMock.cs index 3f81c71a3..127bfe681 100644 --- a/test/Microsoft.OpenApi.Hidi.Tests/UtilityFiles/OpenApiDocumentMock.cs +++ b/test/Microsoft.OpenApi.Hidi.Tests/UtilityFiles/OpenApiDocumentMock.cs @@ -678,23 +678,23 @@ public static OpenApiDocument CreateOpenApiDocument() } } }; - document.Paths[getTeamsActivityByPeriodPath].Operations[OperationType.Get].Tags!.Add(new OpenApiTagReference("reports.Functions", document)); - document.Paths[getTeamsActivityByDatePath].Operations[OperationType.Get].Tags!.Add(new OpenApiTagReference("reports.Functions", document)); - document.Paths[usersPath].Operations[OperationType.Get].Tags!.Add(new OpenApiTagReference("users.user", document)); - document.Paths[usersByIdPath].Operations[OperationType.Get].Tags!.Add(new OpenApiTagReference("users.user", document)); - document.Paths[usersByIdPath].Operations[OperationType.Patch].Tags!.Add(new OpenApiTagReference("users.user", document)); - document.Paths[messagesByIdPath].Operations[OperationType.Get].Tags!.Add(new OpenApiTagReference("users.message", document)); - document.Paths[administrativeUnitRestorePath].Operations[OperationType.Post].Tags!.Add(new OpenApiTagReference("administrativeUnits.Actions", document)); - document.Paths[logoPath].Operations[OperationType.Put].Tags!.Add(new OpenApiTagReference("applications.application", document)); - document.Paths[securityProfilesPath].Operations[OperationType.Get].Tags!.Add(new OpenApiTagReference("security.hostSecurityProfile", document)); - document.Paths[communicationsCallsKeepAlivePath].Operations[OperationType.Post].Tags!.Add(new OpenApiTagReference("communications.Actions", document)); - document.Paths[eventsDeltaPath].Operations[OperationType.Get].Tags!.Add(new OpenApiTagReference("groups.Functions", document)); - document.Paths[refPath].Operations[OperationType.Get].Tags!.Add(new OpenApiTagReference("applications.directoryObject", document)); - ((OpenApiSchema)document.Paths[usersPath].Operations[OperationType.Get].Responses!["200"].Content[applicationJsonMediaType].Schema!.Properties["value"]).Items = new OpenApiSchemaReference("microsoft.graph.user", document); - document.Paths[usersByIdPath].Operations[OperationType.Get].Responses!["200"].Content[applicationJsonMediaType].Schema = new OpenApiSchemaReference("microsoft.graph.user", document); - document.Paths[messagesByIdPath].Operations[OperationType.Get].Responses!["200"].Content[applicationJsonMediaType].Schema = new OpenApiSchemaReference("microsoft.graph.message", document); - ((OpenApiSchema)document.Paths[securityProfilesPath].Operations[OperationType.Get].Responses!["200"].Content[applicationJsonMediaType].Schema!.Properties["value"]).Items = new OpenApiSchemaReference("microsoft.graph.networkInterface", document); - ((OpenApiSchema)document.Paths[eventsDeltaPath].Operations[OperationType.Get].Responses!["200"].Content[applicationJsonMediaType].Schema!.Properties["value"]).Items = new OpenApiSchemaReference("microsoft.graph.event", document); + document.Paths[getTeamsActivityByPeriodPath].Operations?[OperationType.Get].Tags!.Add(new OpenApiTagReference("reports.Functions", document)); + document.Paths[getTeamsActivityByDatePath].Operations?[OperationType.Get].Tags!.Add(new OpenApiTagReference("reports.Functions", document)); + document.Paths[usersPath].Operations?[OperationType.Get].Tags!.Add(new OpenApiTagReference("users.user", document)); + document.Paths[usersByIdPath].Operations?[OperationType.Get].Tags!.Add(new OpenApiTagReference("users.user", document)); + document.Paths[usersByIdPath].Operations?[OperationType.Patch].Tags!.Add(new OpenApiTagReference("users.user", document)); + document.Paths[messagesByIdPath].Operations?[OperationType.Get].Tags!.Add(new OpenApiTagReference("users.message", document)); + document.Paths[administrativeUnitRestorePath].Operations?[OperationType.Post].Tags!.Add(new OpenApiTagReference("administrativeUnits.Actions", document)); + document.Paths[logoPath].Operations?[OperationType.Put].Tags!.Add(new OpenApiTagReference("applications.application", document)); + document.Paths[securityProfilesPath].Operations?[OperationType.Get].Tags!.Add(new OpenApiTagReference("security.hostSecurityProfile", document)); + document.Paths[communicationsCallsKeepAlivePath].Operations?[OperationType.Post].Tags!.Add(new OpenApiTagReference("communications.Actions", document)); + document.Paths[eventsDeltaPath].Operations?[OperationType.Get].Tags!.Add(new OpenApiTagReference("groups.Functions", document)); + document.Paths[refPath].Operations?[OperationType.Get].Tags!.Add(new OpenApiTagReference("applications.directoryObject", document)); + ((OpenApiSchema)document.Paths[usersPath].Operations![OperationType.Get].Responses!["200"].Content![applicationJsonMediaType].Schema!.Properties!["value"]).Items = new OpenApiSchemaReference("microsoft.graph.user", document); + document.Paths[usersByIdPath].Operations![OperationType.Get].Responses!["200"].Content![applicationJsonMediaType].Schema = new OpenApiSchemaReference("microsoft.graph.user", document); + document.Paths[messagesByIdPath].Operations![OperationType.Get].Responses!["200"].Content![applicationJsonMediaType].Schema = new OpenApiSchemaReference("microsoft.graph.message", document); + ((OpenApiSchema)document.Paths[securityProfilesPath].Operations![OperationType.Get].Responses!["200"].Content![applicationJsonMediaType].Schema!.Properties!["value"]).Items = new OpenApiSchemaReference("microsoft.graph.networkInterface", document); + ((OpenApiSchema)document.Paths[eventsDeltaPath].Operations![OperationType.Get].Responses!["200"].Content![applicationJsonMediaType].Schema!.Properties!["value"]).Items = new OpenApiSchemaReference("microsoft.graph.event", document); return document; } } From 489fa4dc6059f62af02a8a639e932fad383dfeda Mon Sep 17 00:00:00 2001 From: Maggiekimani1 Date: Fri, 14 Feb 2025 15:47:23 +0300 Subject: [PATCH 3/7] chore: code cleanup --- .../Formatters/PowerShellFormatter.cs | 8 +- .../Models/OpenApiOperation.cs | 2 +- .../Reader/OpenApiModelFactory.cs | 2 +- .../Reader/ParseNodes/FixedFieldMap.cs | 2 +- .../Reader/ParseNodes/ListNode.cs | 4 +- .../Reader/ParseNodes/MapNode.cs | 2 +- .../Reader/ParseNodes/ParseNode.cs | 6 +- .../Reader/ParseNodes/PatternFieldMap.cs | 2 +- .../Reader/ParseNodes/PropertyNode.cs | 8 +- .../Reader/V2/OpenApiContactDeserializer.cs | 2 +- .../Reader/V2/OpenApiDocumentDeserializer.cs | 2 +- .../V2/OpenApiExternalDocsDeserializer.cs | 2 +- .../Reader/V2/OpenApiHeaderDeserializer.cs | 2 +- .../Reader/V2/OpenApiInfoDeserializer.cs | 2 +- .../Reader/V2/OpenApiLicenseDeserializer.cs | 2 +- .../Reader/V2/OpenApiOperationDeserializer.cs | 6 +- .../Reader/V2/OpenApiParameterDeserializer.cs | 8 +- .../Reader/V2/OpenApiPathItemDeserializer.cs | 4 +- .../Reader/V2/OpenApiPathsDeserializer.cs | 2 +- .../Reader/V2/OpenApiResponseDeserializer.cs | 6 +- .../Reader/V2/OpenApiSchemaDeserializer.cs | 2 +- .../OpenApiSecurityRequirementDeserializer.cs | 4 +- .../V2/OpenApiSecuritySchemeDeserializer.cs | 2 +- .../Reader/V2/OpenApiTagDeserializer.cs | 2 +- .../Reader/V2/OpenApiXmlDeserializer.cs | 2 +- .../Reader/V3/OpenApiCallbackDeserializer.cs | 2 +- .../V3/OpenApiComponentsDeserializer.cs | 2 +- .../Reader/V3/OpenApiContactDeserializer.cs | 2 +- .../V3/OpenApiDiscriminatorDeserializer.cs | 2 +- .../Reader/V3/OpenApiEncodingDeserializer.cs | 2 +- .../Reader/V3/OpenApiExampleDeserializer.cs | 2 +- .../V3/OpenApiExternalDocsDeserializer.cs | 2 +- .../Reader/V3/OpenApiHeaderDeserializer.cs | 2 +- .../Reader/V3/OpenApiInfoDeserializer.cs | 2 +- .../Reader/V3/OpenApiLicenseDeserializer.cs | 2 +- .../Reader/V3/OpenApiLinkDeserializer.cs | 2 +- .../Reader/V3/OpenApiMediaTypeDeserializer.cs | 2 +- .../Reader/V3/OpenApiOAuthFlowDeserializer.cs | 2 +- .../V3/OpenApiOAuthFlowsDeserializer.cs | 2 +- .../Reader/V3/OpenApiOperationDeserializer.cs | 4 +- .../Reader/V3/OpenApiParameterDeserializer.cs | 2 +- .../Reader/V3/OpenApiPathItemDeserializer.cs | 2 +- .../Reader/V3/OpenApiPathsDeserializer.cs | 2 +- .../V3/OpenApiRequestBodyDeserializer.cs | 2 +- .../Reader/V3/OpenApiResponseDeserializer.cs | 2 +- .../Reader/V3/OpenApiResponsesDeserializer.cs | 2 +- .../Reader/V3/OpenApiSchemaDeserializer.cs | 2 +- .../OpenApiSecurityRequirementDeserializer.cs | 4 +- .../V3/OpenApiSecuritySchemeDeserializer.cs | 2 +- .../Reader/V3/OpenApiServerDeserializer.cs | 2 +- .../V3/OpenApiServerVariableDeserializer.cs | 2 +- .../Reader/V3/OpenApiTagDeserializer.cs | 2 +- .../Reader/V3/OpenApiV3Deserializer.cs | 2 +- .../Reader/V3/OpenApiXmlDeserializer.cs | 2 +- .../Reader/V31/OpenApiCallbackDeserializer.cs | 2 +- .../V31/OpenApiComponentsDeserializer.cs | 2 +- .../Reader/V31/OpenApiContactDeserializer.cs | 2 +- .../V31/OpenApiDiscriminatorDeserializer.cs | 2 +- .../Reader/V31/OpenApiEncodingDeserializer.cs | 2 +- .../Reader/V31/OpenApiExampleDeserializer.cs | 2 +- .../V31/OpenApiExternalDocsDeserializer.cs | 2 +- .../Reader/V31/OpenApiHeaderDeserializer.cs | 2 +- .../Reader/V31/OpenApiInfoDeserializer.cs | 2 +- .../Reader/V31/OpenApiLicenseDeserializer.cs | 2 +- .../Reader/V31/OpenApiLinkDeserializer.cs | 2 +- .../V31/OpenApiMediaTypeDeserializer.cs | 2 +- .../V31/OpenApiOAuthFlowDeserializer.cs | 2 +- .../V31/OpenApiOAuthFlowsDeserializer.cs | 2 +- .../V31/OpenApiOperationDeserializer.cs | 4 +- .../V31/OpenApiParameterDeserializer.cs | 2 +- .../Reader/V31/OpenApiPathItemDeserializer.cs | 2 +- .../Reader/V31/OpenApiPathsDeserializer.cs | 2 +- .../V31/OpenApiRequestBodyDeserializer.cs | 2 +- .../Reader/V31/OpenApiResponseDeserializer.cs | 2 +- .../V31/OpenApiResponsesDeserializer.cs | 2 +- .../Reader/V31/OpenApiSchemaDeserializer.cs | 7 +- .../OpenApiSecurityRequirementDeserializer.cs | 4 +- .../V31/OpenApiSecuritySchemeDeserializer.cs | 2 +- .../Reader/V31/OpenApiServerDeserializer.cs | 2 +- .../V31/OpenApiServerVariableDeserializer.cs | 2 +- .../Reader/V31/OpenApiTagDeserializer.cs | 2 +- .../Reader/V31/OpenApiXmlDeserializer.cs | 2 +- .../Writers/OpenApiJsonWriter.cs | 17 +- .../Writers/OpenApiWriterExtensions.cs | 4 +- .../Writers/OpenApiYamlWriter.cs | 67 +- .../PublicApi/PublicApi.approved.txt | 868 +++++++++--------- 86 files changed, 582 insertions(+), 587 deletions(-) diff --git a/src/Microsoft.OpenApi.Hidi/Formatters/PowerShellFormatter.cs b/src/Microsoft.OpenApi.Hidi/Formatters/PowerShellFormatter.cs index 959a4345e..e4e193775 100644 --- a/src/Microsoft.OpenApi.Hidi/Formatters/PowerShellFormatter.cs +++ b/src/Microsoft.OpenApi.Hidi/Formatters/PowerShellFormatter.cs @@ -180,8 +180,7 @@ private void AddAdditionalPropertiesToSchema(IOpenApiSchema schema) { if (schema is OpenApiSchema openApiSchema && !_schemaLoop.Contains(schema) - && schema.Type.Equals(JsonSchemaType.Object) - && schema.AdditionalProperties is not null) + && schema.Type.Equals(JsonSchemaType.Object)) { openApiSchema.AdditionalProperties = new OpenApiSchema() { Type = JsonSchemaType.Object }; @@ -189,7 +188,10 @@ private void AddAdditionalPropertiesToSchema(IOpenApiSchema schema) * we need a way to keep track of visited schemas to avoid * endlessly creating and walking them in an infinite recursion. */ - _schemaLoop.Push(schema.AdditionalProperties); + if (schema.AdditionalProperties is not null) + { + _schemaLoop.Push(schema.AdditionalProperties); + } } } diff --git a/src/Microsoft.OpenApi/Models/OpenApiOperation.cs b/src/Microsoft.OpenApi/Models/OpenApiOperation.cs index f664fd483..f1781889f 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiOperation.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiOperation.cs @@ -327,7 +327,7 @@ public void SerializeAsV2(IOpenApiWriter writer) .Distinct() .ToList(); - writer.WriteOptionalCollection(OpenApiConstants.Schemes, schemes.Where(scheme => scheme is not null).ToString(), (w, s) => w.WriteValue(s)); + writer.WriteOptionalCollection(OpenApiConstants.Schemes, schemes, (w, s) => w.WriteValue(s)); } // deprecated diff --git a/src/Microsoft.OpenApi/Reader/OpenApiModelFactory.cs b/src/Microsoft.OpenApi/Reader/OpenApiModelFactory.cs index bf0fde0df..3234d4f13 100644 --- a/src/Microsoft.OpenApi/Reader/OpenApiModelFactory.cs +++ b/src/Microsoft.OpenApi/Reader/OpenApiModelFactory.cs @@ -299,7 +299,7 @@ private static ReadResult InternalLoad(MemoryStream input, string format, OpenAp var response = await _httpClient.GetAsync(url, token).ConfigureAwait(false); var mediaType = response.Content.Headers.ContentType?.MediaType; var contentType = mediaType?.Split(";".ToCharArray(), StringSplitOptions.RemoveEmptyEntries)[0]; - format = contentType?.Split('/')[0].Split('+')[0].Split('-')[0]; + format = contentType?.Split('/').Last().Split('+').Last().Split('-').Last(); // for non-standard MIME types e.g. text/x-yaml used in older libs or apps #if NETSTANDARD2_0 stream = await response.Content.ReadAsStreamAsync(); diff --git a/src/Microsoft.OpenApi/Reader/ParseNodes/FixedFieldMap.cs b/src/Microsoft.OpenApi/Reader/ParseNodes/FixedFieldMap.cs index 139f38c6a..980638112 100644 --- a/src/Microsoft.OpenApi/Reader/ParseNodes/FixedFieldMap.cs +++ b/src/Microsoft.OpenApi/Reader/ParseNodes/FixedFieldMap.cs @@ -7,7 +7,7 @@ namespace Microsoft.OpenApi.Reader.ParseNodes { - internal class FixedFieldMap : Dictionary> + internal class FixedFieldMap : Dictionary> { } } diff --git a/src/Microsoft.OpenApi/Reader/ParseNodes/ListNode.cs b/src/Microsoft.OpenApi/Reader/ParseNodes/ListNode.cs index d3af80945..aa03524cf 100644 --- a/src/Microsoft.OpenApi/Reader/ParseNodes/ListNode.cs +++ b/src/Microsoft.OpenApi/Reader/ParseNodes/ListNode.cs @@ -21,7 +21,7 @@ public ListNode(ParsingContext context, JsonArray jsonArray) : base( _nodeList = jsonArray; } - public override List CreateList(Func map, OpenApiDocument hostDocument) + public override List CreateList(Func map, OpenApiDocument? hostDocument) { if (_nodeList == null) { @@ -44,7 +44,7 @@ public override List CreateListOfAny() return list; } - public override List CreateSimpleList(Func map, OpenApiDocument openApiDocument) + public override List CreateSimpleList(Func map, OpenApiDocument? openApiDocument) { if (_nodeList == null) { diff --git a/src/Microsoft.OpenApi/Reader/ParseNodes/MapNode.cs b/src/Microsoft.OpenApi/Reader/ParseNodes/MapNode.cs index 0bafad6c2..ea7225d79 100644 --- a/src/Microsoft.OpenApi/Reader/ParseNodes/MapNode.cs +++ b/src/Microsoft.OpenApi/Reader/ParseNodes/MapNode.cs @@ -49,7 +49,7 @@ public PropertyNode? this[string key] } } - public override Dictionary CreateMap(Func map, OpenApiDocument hostDocument) + public override Dictionary CreateMap(Func map, OpenApiDocument? hostDocument) { var jsonMap = _node ?? throw new OpenApiReaderException($"Expected map while parsing {typeof(T).Name}", Context); var nodes = jsonMap.Select( diff --git a/src/Microsoft.OpenApi/Reader/ParseNodes/ParseNode.cs b/src/Microsoft.OpenApi/Reader/ParseNodes/ParseNode.cs index 16593d5d3..9629e5e7d 100644 --- a/src/Microsoft.OpenApi/Reader/ParseNodes/ParseNode.cs +++ b/src/Microsoft.OpenApi/Reader/ParseNodes/ParseNode.cs @@ -46,17 +46,17 @@ public static ParseNode Create(ParsingContext context, JsonNode? node) return new ValueNode(context, node as JsonValue); } - public virtual List CreateList(Func map, OpenApiDocument hostDocument) + public virtual List CreateList(Func map, OpenApiDocument? hostDocument) { throw new OpenApiReaderException("Cannot create list from this type of node.", Context); } - public virtual Dictionary CreateMap(Func map, OpenApiDocument hostDocument) + public virtual Dictionary CreateMap(Func map, OpenApiDocument? hostDocument) { throw new OpenApiReaderException("Cannot create map from this type of node.", Context); } - public virtual List CreateSimpleList(Func map, OpenApiDocument openApiDocument) + public virtual List CreateSimpleList(Func map, OpenApiDocument? openApiDocument) { throw new OpenApiReaderException("Cannot create simple list from this type of node.", Context); } diff --git a/src/Microsoft.OpenApi/Reader/ParseNodes/PatternFieldMap.cs b/src/Microsoft.OpenApi/Reader/ParseNodes/PatternFieldMap.cs index 79caf3221..ef9c4a9d9 100644 --- a/src/Microsoft.OpenApi/Reader/ParseNodes/PatternFieldMap.cs +++ b/src/Microsoft.OpenApi/Reader/ParseNodes/PatternFieldMap.cs @@ -7,7 +7,7 @@ namespace Microsoft.OpenApi.Reader.ParseNodes { - internal class PatternFieldMap : Dictionary, Action> + internal class PatternFieldMap : Dictionary, Action> { } } diff --git a/src/Microsoft.OpenApi/Reader/ParseNodes/PropertyNode.cs b/src/Microsoft.OpenApi/Reader/ParseNodes/PropertyNode.cs index c9aa80955..7917d599d 100644 --- a/src/Microsoft.OpenApi/Reader/ParseNodes/PropertyNode.cs +++ b/src/Microsoft.OpenApi/Reader/ParseNodes/PropertyNode.cs @@ -25,11 +25,11 @@ public PropertyNode(ParsingContext context, string name, JsonNode? node) : base( public void ParseField( T parentInstance, - IDictionary> fixedFields, - IDictionary, Action> patternFields, + IDictionary> fixedFields, + IDictionary, Action> patternFields, OpenApiDocument? hostDocument) { - if (fixedFields.TryGetValue(Name, out var fixedFieldMap) && hostDocument is not null) + if (fixedFields.TryGetValue(Name, out var fixedFieldMap)) { try { @@ -53,7 +53,7 @@ public void ParseField( else { var map = patternFields.Where(p => p.Key(Name)).Select(p => p.Value).FirstOrDefault(); - if (map != null && hostDocument is not null) + if (map != null) { try { diff --git a/src/Microsoft.OpenApi/Reader/V2/OpenApiContactDeserializer.cs b/src/Microsoft.OpenApi/Reader/V2/OpenApiContactDeserializer.cs index c55175782..ac2de2a52 100644 --- a/src/Microsoft.OpenApi/Reader/V2/OpenApiContactDeserializer.cs +++ b/src/Microsoft.OpenApi/Reader/V2/OpenApiContactDeserializer.cs @@ -42,7 +42,7 @@ internal static partial class OpenApiV2Deserializer {s => s.StartsWith(OpenApiConstants.ExtensionFieldNamePrefix, StringComparison.OrdinalIgnoreCase), (o, p, n, _) => o.AddExtension(p, LoadExtension(p, n))} }; - public static OpenApiContact LoadContact(ParseNode node, OpenApiDocument hostDocument) + public static OpenApiContact LoadContact(ParseNode node, OpenApiDocument? hostDocument) { var mapNode = node as MapNode; var contact = new OpenApiContact(); diff --git a/src/Microsoft.OpenApi/Reader/V2/OpenApiDocumentDeserializer.cs b/src/Microsoft.OpenApi/Reader/V2/OpenApiDocumentDeserializer.cs index a59894ed8..ffab4f6fd 100644 --- a/src/Microsoft.OpenApi/Reader/V2/OpenApiDocumentDeserializer.cs +++ b/src/Microsoft.OpenApi/Reader/V2/OpenApiDocumentDeserializer.cs @@ -208,7 +208,7 @@ private static string BuildUrl(string? scheme, string? host, string? basePath) if (pieces is not null) { host = pieces[0]; - port = int.Parse(pieces[0], CultureInfo.InvariantCulture); + port = int.Parse(pieces[pieces.Count() -1], CultureInfo.InvariantCulture); } } diff --git a/src/Microsoft.OpenApi/Reader/V2/OpenApiExternalDocsDeserializer.cs b/src/Microsoft.OpenApi/Reader/V2/OpenApiExternalDocsDeserializer.cs index e92bfe4f1..4cbbc3ce1 100644 --- a/src/Microsoft.OpenApi/Reader/V2/OpenApiExternalDocsDeserializer.cs +++ b/src/Microsoft.OpenApi/Reader/V2/OpenApiExternalDocsDeserializer.cs @@ -47,7 +47,7 @@ internal static partial class OpenApiV2Deserializer {s => s.StartsWith(OpenApiConstants.ExtensionFieldNamePrefix, StringComparison.OrdinalIgnoreCase), (o, p, n, _) => o.AddExtension(p, LoadExtension(p, n))} }; - public static OpenApiExternalDocs LoadExternalDocs(ParseNode node, OpenApiDocument hostDocument) + public static OpenApiExternalDocs LoadExternalDocs(ParseNode node, OpenApiDocument? hostDocument) { var mapNode = node.CheckMapNode("externalDocs"); diff --git a/src/Microsoft.OpenApi/Reader/V2/OpenApiHeaderDeserializer.cs b/src/Microsoft.OpenApi/Reader/V2/OpenApiHeaderDeserializer.cs index 30c60ae87..51a9d4984 100644 --- a/src/Microsoft.OpenApi/Reader/V2/OpenApiHeaderDeserializer.cs +++ b/src/Microsoft.OpenApi/Reader/V2/OpenApiHeaderDeserializer.cs @@ -190,7 +190,7 @@ private static OpenApiSchema GetOrCreateSchema(OpenApiHeader p) }; } - public static IOpenApiHeader LoadHeader(ParseNode node, OpenApiDocument hostDocument) + public static IOpenApiHeader LoadHeader(ParseNode node, OpenApiDocument? hostDocument) { var mapNode = node.CheckMapNode("header"); var header = new OpenApiHeader(); diff --git a/src/Microsoft.OpenApi/Reader/V2/OpenApiInfoDeserializer.cs b/src/Microsoft.OpenApi/Reader/V2/OpenApiInfoDeserializer.cs index 2e5d54ed6..ef542ea51 100644 --- a/src/Microsoft.OpenApi/Reader/V2/OpenApiInfoDeserializer.cs +++ b/src/Microsoft.OpenApi/Reader/V2/OpenApiInfoDeserializer.cs @@ -54,7 +54,7 @@ internal static partial class OpenApiV2Deserializer {s => s.StartsWith(OpenApiConstants.ExtensionFieldNamePrefix, StringComparison.OrdinalIgnoreCase), (o, p, n, _) => o.AddExtension(p, LoadExtension(p, n))} }; - public static OpenApiInfo LoadInfo(ParseNode node, OpenApiDocument hostDocument) + public static OpenApiInfo LoadInfo(ParseNode node, OpenApiDocument? hostDocument) { var mapNode = node.CheckMapNode("Info"); diff --git a/src/Microsoft.OpenApi/Reader/V2/OpenApiLicenseDeserializer.cs b/src/Microsoft.OpenApi/Reader/V2/OpenApiLicenseDeserializer.cs index c717f7a67..99645e3f1 100644 --- a/src/Microsoft.OpenApi/Reader/V2/OpenApiLicenseDeserializer.cs +++ b/src/Microsoft.OpenApi/Reader/V2/OpenApiLicenseDeserializer.cs @@ -38,7 +38,7 @@ internal static partial class OpenApiV2Deserializer {s => s.StartsWith(OpenApiConstants.ExtensionFieldNamePrefix, StringComparison.OrdinalIgnoreCase), (o, p, n, _) => o.AddExtension(p, LoadExtension(p, n))} }; - public static OpenApiLicense LoadLicense(ParseNode node, OpenApiDocument hostDocument) + public static OpenApiLicense LoadLicense(ParseNode node, OpenApiDocument? hostDocument) { var mapNode = node.CheckMapNode("OpenApiLicense"); diff --git a/src/Microsoft.OpenApi/Reader/V2/OpenApiOperationDeserializer.cs b/src/Microsoft.OpenApi/Reader/V2/OpenApiOperationDeserializer.cs index 8ae1889be..ff117bc4c 100644 --- a/src/Microsoft.OpenApi/Reader/V2/OpenApiOperationDeserializer.cs +++ b/src/Microsoft.OpenApi/Reader/V2/OpenApiOperationDeserializer.cs @@ -106,7 +106,7 @@ internal static partial class OpenApiV2Deserializer {s => s.StartsWith(OpenApiConstants.ExtensionFieldNamePrefix, StringComparison.OrdinalIgnoreCase), (o, p, n, _) => o.AddExtension(p, LoadExtension(p, n))} }; - internal static OpenApiOperation LoadOperation(ParseNode node, OpenApiDocument hostDocument) + internal static OpenApiOperation LoadOperation(ParseNode node, OpenApiDocument? hostDocument) { // Reset these temp storage parameters for each operation. node.Context.SetTempStorage(TempStorageKeys.BodyParameter, null); @@ -150,7 +150,7 @@ internal static OpenApiOperation LoadOperation(ParseNode node, OpenApiDocument h return operation; } - public static OpenApiResponses LoadResponses(ParseNode node, OpenApiDocument hostDocument) + public static OpenApiResponses LoadResponses(ParseNode node, OpenApiDocument? hostDocument) { var mapNode = node.CheckMapNode("Responses"); @@ -238,7 +238,7 @@ internal static IOpenApiRequestBody CreateRequestBody( } private static OpenApiTagReference LoadTagByReference( - string? tagName, OpenApiDocument hostDocument) + string? tagName, OpenApiDocument? hostDocument) { return new OpenApiTagReference(tagName, hostDocument); } diff --git a/src/Microsoft.OpenApi/Reader/V2/OpenApiParameterDeserializer.cs b/src/Microsoft.OpenApi/Reader/V2/OpenApiParameterDeserializer.cs index d7ce64d64..48cee0c04 100644 --- a/src/Microsoft.OpenApi/Reader/V2/OpenApiParameterDeserializer.cs +++ b/src/Microsoft.OpenApi/Reader/V2/OpenApiParameterDeserializer.cs @@ -209,7 +209,7 @@ private static void LoadStyle(OpenApiParameter p, string v) } } - private static void LoadParameterExamplesExtension(OpenApiParameter parameter, ParseNode node, OpenApiDocument hostDocument) + private static void LoadParameterExamplesExtension(OpenApiParameter parameter, ParseNode node, OpenApiDocument? hostDocument) { var examples = LoadExamplesExtension(node); node.Context.SetTempStorage(TempStorageKeys.Examples, examples, parameter); @@ -223,7 +223,7 @@ private static OpenApiSchema GetOrCreateSchema(OpenApiParameter p) }; } - private static void ProcessIn(OpenApiParameter o, ParseNode n, OpenApiDocument hostDocument) + private static void ProcessIn(OpenApiParameter o, ParseNode n, OpenApiDocument? hostDocument) { var value = n.GetScalarValue(); switch (value) @@ -257,12 +257,12 @@ private static void ProcessIn(OpenApiParameter o, ParseNode n, OpenApiDocument h } } - public static IOpenApiParameter? LoadParameter(ParseNode node, OpenApiDocument hostDocument) + public static IOpenApiParameter? LoadParameter(ParseNode node, OpenApiDocument? hostDocument) { return LoadParameter(node, false, hostDocument); } - public static IOpenApiParameter? LoadParameter(ParseNode node, bool loadRequestBody, OpenApiDocument hostDocument) + public static IOpenApiParameter? LoadParameter(ParseNode node, bool loadRequestBody, OpenApiDocument? hostDocument) { // Reset the local variables every time this method is called. node.Context.SetTempStorage(TempStorageKeys.ParameterIsBodyOrFormData, false); diff --git a/src/Microsoft.OpenApi/Reader/V2/OpenApiPathItemDeserializer.cs b/src/Microsoft.OpenApi/Reader/V2/OpenApiPathItemDeserializer.cs index c5a70563e..b84ac74f8 100644 --- a/src/Microsoft.OpenApi/Reader/V2/OpenApiPathItemDeserializer.cs +++ b/src/Microsoft.OpenApi/Reader/V2/OpenApiPathItemDeserializer.cs @@ -38,7 +38,7 @@ internal static partial class OpenApiV2Deserializer {s => s.StartsWith(OpenApiConstants.ExtensionFieldNamePrefix, StringComparison.OrdinalIgnoreCase), (o, p, n, _) => o.AddExtension(p, LoadExtension(p, n))}, }; - public static OpenApiPathItem LoadPathItem(ParseNode node, OpenApiDocument hostDocument) + public static OpenApiPathItem LoadPathItem(ParseNode node, OpenApiDocument? hostDocument) { var mapNode = node.CheckMapNode("PathItem"); @@ -49,7 +49,7 @@ public static OpenApiPathItem LoadPathItem(ParseNode node, OpenApiDocument hostD return pathItem; } - private static void LoadPathParameters(OpenApiPathItem pathItem, ParseNode node, OpenApiDocument hostDocument) + private static void LoadPathParameters(OpenApiPathItem pathItem, ParseNode node, OpenApiDocument? hostDocument) { node.Context.SetTempStorage(TempStorageKeys.BodyParameter, null); node.Context.SetTempStorage(TempStorageKeys.FormParameters, null); diff --git a/src/Microsoft.OpenApi/Reader/V2/OpenApiPathsDeserializer.cs b/src/Microsoft.OpenApi/Reader/V2/OpenApiPathsDeserializer.cs index 30d1df8a9..8ef372b75 100644 --- a/src/Microsoft.OpenApi/Reader/V2/OpenApiPathsDeserializer.cs +++ b/src/Microsoft.OpenApi/Reader/V2/OpenApiPathsDeserializer.cs @@ -22,7 +22,7 @@ internal static partial class OpenApiV2Deserializer {s => s.StartsWith(OpenApiConstants.ExtensionFieldNamePrefix, StringComparison.OrdinalIgnoreCase), (o, p, n, _) => o.AddExtension(p, LoadExtension(p, n))} }; - public static OpenApiPaths LoadPaths(ParseNode node, OpenApiDocument hostDocument) + public static OpenApiPaths LoadPaths(ParseNode node, OpenApiDocument? hostDocument) { var mapNode = node.CheckMapNode("Paths"); diff --git a/src/Microsoft.OpenApi/Reader/V2/OpenApiResponseDeserializer.cs b/src/Microsoft.OpenApi/Reader/V2/OpenApiResponseDeserializer.cs index 50c569ea4..1364a9729 100644 --- a/src/Microsoft.OpenApi/Reader/V2/OpenApiResponseDeserializer.cs +++ b/src/Microsoft.OpenApi/Reader/V2/OpenApiResponseDeserializer.cs @@ -105,7 +105,7 @@ private static void ProcessProduces(MapNode mapNode, OpenApiResponse response, P context.SetTempStorage(TempStorageKeys.ResponseProducesSet, true, response); } - private static void LoadResponseExamplesExtension(OpenApiResponse response, ParseNode node, OpenApiDocument hostDocument) + private static void LoadResponseExamplesExtension(OpenApiResponse response, ParseNode node, OpenApiDocument? hostDocument) { var examples = LoadExamplesExtension(node); node.Context.SetTempStorage(TempStorageKeys.Examples, examples, response); @@ -146,7 +146,7 @@ private static Dictionary LoadExamplesExtension(ParseNo return examples; } - private static void LoadExamples(OpenApiResponse response, ParseNode node, OpenApiDocument hostDocument) + private static void LoadExamples(OpenApiResponse response, ParseNode node, OpenApiDocument? hostDocument) { var mapNode = node.CheckMapNode("examples"); @@ -179,7 +179,7 @@ private static void LoadExample(OpenApiResponse response, string mediaType, Pars mediaTypeObject.Example = exampleNode; } - public static IOpenApiResponse LoadResponse(ParseNode node, OpenApiDocument hostDocument) + public static IOpenApiResponse LoadResponse(ParseNode node, OpenApiDocument? hostDocument) { var mapNode = node.CheckMapNode("response"); diff --git a/src/Microsoft.OpenApi/Reader/V2/OpenApiSchemaDeserializer.cs b/src/Microsoft.OpenApi/Reader/V2/OpenApiSchemaDeserializer.cs index f235d33cf..453e3e24e 100644 --- a/src/Microsoft.OpenApi/Reader/V2/OpenApiSchemaDeserializer.cs +++ b/src/Microsoft.OpenApi/Reader/V2/OpenApiSchemaDeserializer.cs @@ -267,7 +267,7 @@ internal static partial class OpenApiV2Deserializer {s => s.StartsWith(OpenApiConstants.ExtensionFieldNamePrefix, StringComparison.OrdinalIgnoreCase), (o, p, n, _) => o.AddExtension(p, LoadExtension(p, n))} }; - public static IOpenApiSchema LoadSchema(ParseNode node, OpenApiDocument hostDocument) + public static IOpenApiSchema LoadSchema(ParseNode node, OpenApiDocument? hostDocument) { var mapNode = node.CheckMapNode("schema"); diff --git a/src/Microsoft.OpenApi/Reader/V2/OpenApiSecurityRequirementDeserializer.cs b/src/Microsoft.OpenApi/Reader/V2/OpenApiSecurityRequirementDeserializer.cs index 214b26769..e95b1f2e7 100644 --- a/src/Microsoft.OpenApi/Reader/V2/OpenApiSecurityRequirementDeserializer.cs +++ b/src/Microsoft.OpenApi/Reader/V2/OpenApiSecurityRequirementDeserializer.cs @@ -15,7 +15,7 @@ namespace Microsoft.OpenApi.Reader.V2 /// internal static partial class OpenApiV2Deserializer { - public static OpenApiSecurityRequirement LoadSecurityRequirement(ParseNode node, OpenApiDocument hostDocument) + public static OpenApiSecurityRequirement LoadSecurityRequirement(ParseNode node, OpenApiDocument? hostDocument) { var mapNode = node.CheckMapNode("security"); @@ -48,7 +48,7 @@ public static OpenApiSecurityRequirement LoadSecurityRequirement(ParseNode node, } private static OpenApiSecuritySchemeReference LoadSecuritySchemeByReference( - OpenApiDocument openApiDocument, + OpenApiDocument? openApiDocument, string schemeName) { return new OpenApiSecuritySchemeReference(schemeName, openApiDocument); diff --git a/src/Microsoft.OpenApi/Reader/V2/OpenApiSecuritySchemeDeserializer.cs b/src/Microsoft.OpenApi/Reader/V2/OpenApiSecuritySchemeDeserializer.cs index af9ff89f9..a70301f77 100644 --- a/src/Microsoft.OpenApi/Reader/V2/OpenApiSecuritySchemeDeserializer.cs +++ b/src/Microsoft.OpenApi/Reader/V2/OpenApiSecuritySchemeDeserializer.cs @@ -104,7 +104,7 @@ internal static partial class OpenApiV2Deserializer {s => s.StartsWith(OpenApiConstants.ExtensionFieldNamePrefix, StringComparison.OrdinalIgnoreCase), (o, p, n, _) => o.AddExtension(p, LoadExtension(p, n))} }; - public static IOpenApiSecurityScheme LoadSecurityScheme(ParseNode node, OpenApiDocument hostDocument) + public static IOpenApiSecurityScheme LoadSecurityScheme(ParseNode node, OpenApiDocument? hostDocument) { // Reset the local variables every time this method is called. // TODO: Change _flow to a tempStorage variable to make the deserializer thread-safe. diff --git a/src/Microsoft.OpenApi/Reader/V2/OpenApiTagDeserializer.cs b/src/Microsoft.OpenApi/Reader/V2/OpenApiTagDeserializer.cs index 809dccacd..f96d87426 100644 --- a/src/Microsoft.OpenApi/Reader/V2/OpenApiTagDeserializer.cs +++ b/src/Microsoft.OpenApi/Reader/V2/OpenApiTagDeserializer.cs @@ -35,7 +35,7 @@ internal static partial class OpenApiV2Deserializer {s => s.StartsWith(OpenApiConstants.ExtensionFieldNamePrefix, StringComparison.OrdinalIgnoreCase), (o, p, n, _) => o.AddExtension(p, LoadExtension(p, n))} }; - public static OpenApiTag LoadTag(ParseNode n, OpenApiDocument hostDocument) + public static OpenApiTag LoadTag(ParseNode n, OpenApiDocument? hostDocument) { var mapNode = n.CheckMapNode("tag"); diff --git a/src/Microsoft.OpenApi/Reader/V2/OpenApiXmlDeserializer.cs b/src/Microsoft.OpenApi/Reader/V2/OpenApiXmlDeserializer.cs index a1eb9ba9f..12cce356d 100644 --- a/src/Microsoft.OpenApi/Reader/V2/OpenApiXmlDeserializer.cs +++ b/src/Microsoft.OpenApi/Reader/V2/OpenApiXmlDeserializer.cs @@ -69,7 +69,7 @@ internal static partial class OpenApiV2Deserializer {s => s.StartsWith(OpenApiConstants.ExtensionFieldNamePrefix, StringComparison.OrdinalIgnoreCase), (o, p, n, _) => o.AddExtension(p, LoadExtension(p,n))} }; - public static OpenApiXml LoadXml(ParseNode node, OpenApiDocument hostDocument) + public static OpenApiXml LoadXml(ParseNode node, OpenApiDocument? hostDocument) { var mapNode = node.CheckMapNode("xml"); diff --git a/src/Microsoft.OpenApi/Reader/V3/OpenApiCallbackDeserializer.cs b/src/Microsoft.OpenApi/Reader/V3/OpenApiCallbackDeserializer.cs index 4ec9bfa3a..937aa149b 100644 --- a/src/Microsoft.OpenApi/Reader/V3/OpenApiCallbackDeserializer.cs +++ b/src/Microsoft.OpenApi/Reader/V3/OpenApiCallbackDeserializer.cs @@ -26,7 +26,7 @@ internal static partial class OpenApiV3Deserializer {s => s.StartsWith(OpenApiConstants.ExtensionFieldNamePrefix, StringComparison.OrdinalIgnoreCase), (o, p, n, _) => o.AddExtension(p, LoadExtension(p,n))}, }; - public static IOpenApiCallback LoadCallback(ParseNode node, OpenApiDocument hostDocument) + public static IOpenApiCallback LoadCallback(ParseNode node, OpenApiDocument? hostDocument) { var mapNode = node.CheckMapNode("callback"); diff --git a/src/Microsoft.OpenApi/Reader/V3/OpenApiComponentsDeserializer.cs b/src/Microsoft.OpenApi/Reader/V3/OpenApiComponentsDeserializer.cs index 76cfc96d7..4bfbebfc1 100644 --- a/src/Microsoft.OpenApi/Reader/V3/OpenApiComponentsDeserializer.cs +++ b/src/Microsoft.OpenApi/Reader/V3/OpenApiComponentsDeserializer.cs @@ -33,7 +33,7 @@ internal static partial class OpenApiV3Deserializer {s => s.StartsWith(OpenApiConstants.ExtensionFieldNamePrefix, StringComparison.OrdinalIgnoreCase), (o, p, n, _) => o.AddExtension(p, LoadExtension(p, n))} }; - public static OpenApiComponents LoadComponents(ParseNode node, OpenApiDocument hostDocument) + public static OpenApiComponents LoadComponents(ParseNode node, OpenApiDocument? hostDocument) { var mapNode = node.CheckMapNode("components"); var components = new OpenApiComponents(); diff --git a/src/Microsoft.OpenApi/Reader/V3/OpenApiContactDeserializer.cs b/src/Microsoft.OpenApi/Reader/V3/OpenApiContactDeserializer.cs index 21b11b794..107453e82 100644 --- a/src/Microsoft.OpenApi/Reader/V3/OpenApiContactDeserializer.cs +++ b/src/Microsoft.OpenApi/Reader/V3/OpenApiContactDeserializer.cs @@ -42,7 +42,7 @@ internal static partial class OpenApiV3Deserializer {s => s.StartsWith(OpenApiConstants.ExtensionFieldNamePrefix, StringComparison.OrdinalIgnoreCase), (o, p, n, _) => o.AddExtension(p, LoadExtension(p,n))} }; - public static OpenApiContact LoadContact(ParseNode node, OpenApiDocument hostDocument) + public static OpenApiContact LoadContact(ParseNode node, OpenApiDocument? hostDocument) { var mapNode = node as MapNode; var contact = new OpenApiContact(); diff --git a/src/Microsoft.OpenApi/Reader/V3/OpenApiDiscriminatorDeserializer.cs b/src/Microsoft.OpenApi/Reader/V3/OpenApiDiscriminatorDeserializer.cs index 1493283c0..fb5ab3907 100644 --- a/src/Microsoft.OpenApi/Reader/V3/OpenApiDiscriminatorDeserializer.cs +++ b/src/Microsoft.OpenApi/Reader/V3/OpenApiDiscriminatorDeserializer.cs @@ -28,7 +28,7 @@ internal static partial class OpenApiV3Deserializer private static readonly PatternFieldMap _discriminatorPatternFields = new(); - public static OpenApiDiscriminator LoadDiscriminator(ParseNode node, OpenApiDocument hostDocument) + public static OpenApiDiscriminator LoadDiscriminator(ParseNode node, OpenApiDocument? hostDocument) { var mapNode = node.CheckMapNode("discriminator"); diff --git a/src/Microsoft.OpenApi/Reader/V3/OpenApiEncodingDeserializer.cs b/src/Microsoft.OpenApi/Reader/V3/OpenApiEncodingDeserializer.cs index c2d88936f..1426a590c 100644 --- a/src/Microsoft.OpenApi/Reader/V3/OpenApiEncodingDeserializer.cs +++ b/src/Microsoft.OpenApi/Reader/V3/OpenApiEncodingDeserializer.cs @@ -65,7 +65,7 @@ internal static partial class OpenApiV3Deserializer {s => s.StartsWith(OpenApiConstants.ExtensionFieldNamePrefix, StringComparison.OrdinalIgnoreCase), (o, p, n, _) => o.AddExtension(p, LoadExtension(p,n))} }; - public static OpenApiEncoding LoadEncoding(ParseNode node, OpenApiDocument hostDocument) + public static OpenApiEncoding LoadEncoding(ParseNode node, OpenApiDocument? hostDocument) { var mapNode = node.CheckMapNode("encoding"); diff --git a/src/Microsoft.OpenApi/Reader/V3/OpenApiExampleDeserializer.cs b/src/Microsoft.OpenApi/Reader/V3/OpenApiExampleDeserializer.cs index 5ec2665a0..7fb96b543 100644 --- a/src/Microsoft.OpenApi/Reader/V3/OpenApiExampleDeserializer.cs +++ b/src/Microsoft.OpenApi/Reader/V3/OpenApiExampleDeserializer.cs @@ -42,7 +42,7 @@ internal static partial class OpenApiV3Deserializer {s => s.StartsWith(OpenApiConstants.ExtensionFieldNamePrefix, StringComparison.OrdinalIgnoreCase), (o, p, n, _) => o.AddExtension(p, LoadExtension(p,n))} }; - public static IOpenApiExample LoadExample(ParseNode node, OpenApiDocument hostDocument) + public static IOpenApiExample LoadExample(ParseNode node, OpenApiDocument? hostDocument) { var mapNode = node.CheckMapNode("example"); diff --git a/src/Microsoft.OpenApi/Reader/V3/OpenApiExternalDocsDeserializer.cs b/src/Microsoft.OpenApi/Reader/V3/OpenApiExternalDocsDeserializer.cs index 7f357b947..f6e5f77b9 100644 --- a/src/Microsoft.OpenApi/Reader/V3/OpenApiExternalDocsDeserializer.cs +++ b/src/Microsoft.OpenApi/Reader/V3/OpenApiExternalDocsDeserializer.cs @@ -41,7 +41,7 @@ internal static partial class OpenApiV3Deserializer {s => s.StartsWith(OpenApiConstants.ExtensionFieldNamePrefix, StringComparison.OrdinalIgnoreCase), (o, p, n, _) => o.AddExtension(p, LoadExtension(p, n))} }; - public static OpenApiExternalDocs LoadExternalDocs(ParseNode node, OpenApiDocument hostDocument) + public static OpenApiExternalDocs LoadExternalDocs(ParseNode node, OpenApiDocument? hostDocument) { var mapNode = node.CheckMapNode("externalDocs"); diff --git a/src/Microsoft.OpenApi/Reader/V3/OpenApiHeaderDeserializer.cs b/src/Microsoft.OpenApi/Reader/V3/OpenApiHeaderDeserializer.cs index 4b3318357..dc25d003b 100644 --- a/src/Microsoft.OpenApi/Reader/V3/OpenApiHeaderDeserializer.cs +++ b/src/Microsoft.OpenApi/Reader/V3/OpenApiHeaderDeserializer.cs @@ -107,7 +107,7 @@ internal static partial class OpenApiV3Deserializer {s => s.StartsWith(OpenApiConstants.ExtensionFieldNamePrefix, StringComparison.OrdinalIgnoreCase), (o, p, n, _) => o.AddExtension(p, LoadExtension(p,n))} }; - public static IOpenApiHeader LoadHeader(ParseNode node, OpenApiDocument hostDocument) + public static IOpenApiHeader LoadHeader(ParseNode node, OpenApiDocument? hostDocument) { var mapNode = node.CheckMapNode("header"); diff --git a/src/Microsoft.OpenApi/Reader/V3/OpenApiInfoDeserializer.cs b/src/Microsoft.OpenApi/Reader/V3/OpenApiInfoDeserializer.cs index 2686e5d1a..7cc479449 100644 --- a/src/Microsoft.OpenApi/Reader/V3/OpenApiInfoDeserializer.cs +++ b/src/Microsoft.OpenApi/Reader/V3/OpenApiInfoDeserializer.cs @@ -54,7 +54,7 @@ internal static partial class OpenApiV3Deserializer {s => s.StartsWith(OpenApiConstants.ExtensionFieldNamePrefix, StringComparison.OrdinalIgnoreCase), (o, k, n, _) => o.AddExtension(k,LoadExtension(k, n))} }; - public static OpenApiInfo LoadInfo(ParseNode node, OpenApiDocument hostDocument) + public static OpenApiInfo LoadInfo(ParseNode node, OpenApiDocument? hostDocument) { var mapNode = node.CheckMapNode("Info"); var info = new OpenApiInfo(); diff --git a/src/Microsoft.OpenApi/Reader/V3/OpenApiLicenseDeserializer.cs b/src/Microsoft.OpenApi/Reader/V3/OpenApiLicenseDeserializer.cs index eaf9ba24f..aed9ce56d 100644 --- a/src/Microsoft.OpenApi/Reader/V3/OpenApiLicenseDeserializer.cs +++ b/src/Microsoft.OpenApi/Reader/V3/OpenApiLicenseDeserializer.cs @@ -38,7 +38,7 @@ internal static partial class OpenApiV3Deserializer {s => s.StartsWith(OpenApiConstants.ExtensionFieldNamePrefix, StringComparison.OrdinalIgnoreCase), (o, p, n, _) => o.AddExtension(p, LoadExtension(p,n))} }; - internal static OpenApiLicense LoadLicense(ParseNode node, OpenApiDocument hostDocument) + internal static OpenApiLicense LoadLicense(ParseNode node, OpenApiDocument? hostDocument) { var mapNode = node.CheckMapNode("License"); diff --git a/src/Microsoft.OpenApi/Reader/V3/OpenApiLinkDeserializer.cs b/src/Microsoft.OpenApi/Reader/V3/OpenApiLinkDeserializer.cs index f85fb0328..8ae74913d 100644 --- a/src/Microsoft.OpenApi/Reader/V3/OpenApiLinkDeserializer.cs +++ b/src/Microsoft.OpenApi/Reader/V3/OpenApiLinkDeserializer.cs @@ -46,7 +46,7 @@ internal static partial class OpenApiV3Deserializer {s => s.StartsWith(OpenApiConstants.ExtensionFieldNamePrefix, StringComparison.OrdinalIgnoreCase), (o, p, n, _) => o.AddExtension(p, LoadExtension(p,n))}, }; - public static IOpenApiLink LoadLink(ParseNode node, OpenApiDocument hostDocument) + public static IOpenApiLink LoadLink(ParseNode node, OpenApiDocument? hostDocument) { var mapNode = node.CheckMapNode("link"); var link = new OpenApiLink(); diff --git a/src/Microsoft.OpenApi/Reader/V3/OpenApiMediaTypeDeserializer.cs b/src/Microsoft.OpenApi/Reader/V3/OpenApiMediaTypeDeserializer.cs index b0e99bd44..5f761cef7 100644 --- a/src/Microsoft.OpenApi/Reader/V3/OpenApiMediaTypeDeserializer.cs +++ b/src/Microsoft.OpenApi/Reader/V3/OpenApiMediaTypeDeserializer.cs @@ -66,7 +66,7 @@ internal static partial class OpenApiV3Deserializer } }; - public static OpenApiMediaType LoadMediaType(ParseNode node, OpenApiDocument hostDocument) + public static OpenApiMediaType LoadMediaType(ParseNode node, OpenApiDocument? hostDocument) { var mapNode = node.CheckMapNode(OpenApiConstants.Content); diff --git a/src/Microsoft.OpenApi/Reader/V3/OpenApiOAuthFlowDeserializer.cs b/src/Microsoft.OpenApi/Reader/V3/OpenApiOAuthFlowDeserializer.cs index 1771f1407..0da48a664 100644 --- a/src/Microsoft.OpenApi/Reader/V3/OpenApiOAuthFlowDeserializer.cs +++ b/src/Microsoft.OpenApi/Reader/V3/OpenApiOAuthFlowDeserializer.cs @@ -60,7 +60,7 @@ internal static partial class OpenApiV3Deserializer {s => s.StartsWith(OpenApiConstants.ExtensionFieldNamePrefix, StringComparison.OrdinalIgnoreCase), (o, p, n, _) => o.AddExtension(p, LoadExtension(p,n))} }; - public static OpenApiOAuthFlow LoadOAuthFlow(ParseNode node, OpenApiDocument hostDocument) + public static OpenApiOAuthFlow LoadOAuthFlow(ParseNode node, OpenApiDocument? hostDocument) { var mapNode = node.CheckMapNode("OAuthFlow"); diff --git a/src/Microsoft.OpenApi/Reader/V3/OpenApiOAuthFlowsDeserializer.cs b/src/Microsoft.OpenApi/Reader/V3/OpenApiOAuthFlowsDeserializer.cs index 892ec4701..1c541181f 100644 --- a/src/Microsoft.OpenApi/Reader/V3/OpenApiOAuthFlowsDeserializer.cs +++ b/src/Microsoft.OpenApi/Reader/V3/OpenApiOAuthFlowsDeserializer.cs @@ -29,7 +29,7 @@ internal static partial class OpenApiV3Deserializer {s => s.StartsWith(OpenApiConstants.ExtensionFieldNamePrefix, StringComparison.OrdinalIgnoreCase), (o, p, n, _) => o.AddExtension(p, LoadExtension(p,n))} }; - public static OpenApiOAuthFlows LoadOAuthFlows(ParseNode node, OpenApiDocument hostDocument) + public static OpenApiOAuthFlows LoadOAuthFlows(ParseNode node, OpenApiDocument? hostDocument) { var mapNode = node.CheckMapNode("OAuthFlows"); diff --git a/src/Microsoft.OpenApi/Reader/V3/OpenApiOperationDeserializer.cs b/src/Microsoft.OpenApi/Reader/V3/OpenApiOperationDeserializer.cs index 56276ea10..d48b2e6a6 100644 --- a/src/Microsoft.OpenApi/Reader/V3/OpenApiOperationDeserializer.cs +++ b/src/Microsoft.OpenApi/Reader/V3/OpenApiOperationDeserializer.cs @@ -83,7 +83,7 @@ internal static partial class OpenApiV3Deserializer {s => s.StartsWith(OpenApiConstants.ExtensionFieldNamePrefix, StringComparison.OrdinalIgnoreCase), (o, p, n, _) => o.AddExtension(p, LoadExtension(p,n))}, }; - internal static OpenApiOperation LoadOperation(ParseNode node, OpenApiDocument hostDocument) + internal static OpenApiOperation LoadOperation(ParseNode node, OpenApiDocument? hostDocument) { var mapNode = node.CheckMapNode("Operation"); @@ -95,7 +95,7 @@ internal static OpenApiOperation LoadOperation(ParseNode node, OpenApiDocument h } private static OpenApiTagReference LoadTagByReference( - string? tagName, OpenApiDocument hostDocument) + string? tagName, OpenApiDocument? hostDocument) { return new OpenApiTagReference(tagName, hostDocument); } diff --git a/src/Microsoft.OpenApi/Reader/V3/OpenApiParameterDeserializer.cs b/src/Microsoft.OpenApi/Reader/V3/OpenApiParameterDeserializer.cs index 33e67b953..a4e3aa1bb 100644 --- a/src/Microsoft.OpenApi/Reader/V3/OpenApiParameterDeserializer.cs +++ b/src/Microsoft.OpenApi/Reader/V3/OpenApiParameterDeserializer.cs @@ -151,7 +151,7 @@ internal static partial class OpenApiV3Deserializer } }; - public static IOpenApiParameter LoadParameter(ParseNode node, OpenApiDocument hostDocument) + public static IOpenApiParameter LoadParameter(ParseNode node, OpenApiDocument? hostDocument) { var mapNode = node.CheckMapNode("parameter"); diff --git a/src/Microsoft.OpenApi/Reader/V3/OpenApiPathItemDeserializer.cs b/src/Microsoft.OpenApi/Reader/V3/OpenApiPathItemDeserializer.cs index baaf5babc..438bca7d2 100644 --- a/src/Microsoft.OpenApi/Reader/V3/OpenApiPathItemDeserializer.cs +++ b/src/Microsoft.OpenApi/Reader/V3/OpenApiPathItemDeserializer.cs @@ -44,7 +44,7 @@ internal static partial class OpenApiV3Deserializer {s => s.StartsWith(OpenApiConstants.ExtensionFieldNamePrefix, StringComparison.OrdinalIgnoreCase), (o, p, n, _) => o.AddExtension(p, LoadExtension(p,n))} }; - public static IOpenApiPathItem LoadPathItem(ParseNode node, OpenApiDocument hostDocument) + public static IOpenApiPathItem LoadPathItem(ParseNode node, OpenApiDocument? hostDocument) { var mapNode = node.CheckMapNode("PathItem"); diff --git a/src/Microsoft.OpenApi/Reader/V3/OpenApiPathsDeserializer.cs b/src/Microsoft.OpenApi/Reader/V3/OpenApiPathsDeserializer.cs index ef27f5d94..2ac915430 100644 --- a/src/Microsoft.OpenApi/Reader/V3/OpenApiPathsDeserializer.cs +++ b/src/Microsoft.OpenApi/Reader/V3/OpenApiPathsDeserializer.cs @@ -22,7 +22,7 @@ internal static partial class OpenApiV3Deserializer {s => s.StartsWith(OpenApiConstants.ExtensionFieldNamePrefix, StringComparison.OrdinalIgnoreCase), (o, p, n, _) => o.AddExtension(p, LoadExtension(p,n))} }; - public static OpenApiPaths LoadPaths(ParseNode node, OpenApiDocument hostDocument) + public static OpenApiPaths LoadPaths(ParseNode node, OpenApiDocument? hostDocument) { var mapNode = node.CheckMapNode("Paths"); diff --git a/src/Microsoft.OpenApi/Reader/V3/OpenApiRequestBodyDeserializer.cs b/src/Microsoft.OpenApi/Reader/V3/OpenApiRequestBodyDeserializer.cs index 339ca437e..268af5a9e 100644 --- a/src/Microsoft.OpenApi/Reader/V3/OpenApiRequestBodyDeserializer.cs +++ b/src/Microsoft.OpenApi/Reader/V3/OpenApiRequestBodyDeserializer.cs @@ -46,7 +46,7 @@ internal static partial class OpenApiV3Deserializer {s => s.StartsWith(OpenApiConstants.ExtensionFieldNamePrefix, StringComparison.OrdinalIgnoreCase), (o, p, n, _) => o.AddExtension(p, LoadExtension(p,n))} }; - public static IOpenApiRequestBody LoadRequestBody(ParseNode node, OpenApiDocument hostDocument) + public static IOpenApiRequestBody LoadRequestBody(ParseNode node, OpenApiDocument? hostDocument) { var mapNode = node.CheckMapNode("requestBody"); diff --git a/src/Microsoft.OpenApi/Reader/V3/OpenApiResponseDeserializer.cs b/src/Microsoft.OpenApi/Reader/V3/OpenApiResponseDeserializer.cs index 8e10c2e79..ef1c8297d 100644 --- a/src/Microsoft.OpenApi/Reader/V3/OpenApiResponseDeserializer.cs +++ b/src/Microsoft.OpenApi/Reader/V3/OpenApiResponseDeserializer.cs @@ -42,7 +42,7 @@ internal static partial class OpenApiV3Deserializer {s => s.StartsWith(OpenApiConstants.ExtensionFieldNamePrefix, StringComparison.OrdinalIgnoreCase), (o, p, n, _) => o.AddExtension(p, LoadExtension(p,n))} }; - public static IOpenApiResponse LoadResponse(ParseNode node, OpenApiDocument hostDocument) + public static IOpenApiResponse LoadResponse(ParseNode node, OpenApiDocument? hostDocument) { var mapNode = node.CheckMapNode("response"); diff --git a/src/Microsoft.OpenApi/Reader/V3/OpenApiResponsesDeserializer.cs b/src/Microsoft.OpenApi/Reader/V3/OpenApiResponsesDeserializer.cs index 379811dda..d90aa90c7 100644 --- a/src/Microsoft.OpenApi/Reader/V3/OpenApiResponsesDeserializer.cs +++ b/src/Microsoft.OpenApi/Reader/V3/OpenApiResponsesDeserializer.cs @@ -22,7 +22,7 @@ internal static partial class OpenApiV3Deserializer {s => s.StartsWith(OpenApiConstants.ExtensionFieldNamePrefix, StringComparison.OrdinalIgnoreCase), (o, p, n, _) => o.AddExtension(p, LoadExtension(p,n))} }; - public static OpenApiResponses LoadResponses(ParseNode node, OpenApiDocument hostDocument) + public static OpenApiResponses LoadResponses(ParseNode node, OpenApiDocument? hostDocument) { var mapNode = node.CheckMapNode("Responses"); diff --git a/src/Microsoft.OpenApi/Reader/V3/OpenApiSchemaDeserializer.cs b/src/Microsoft.OpenApi/Reader/V3/OpenApiSchemaDeserializer.cs index f413d1dc2..cf8b8fe71 100644 --- a/src/Microsoft.OpenApi/Reader/V3/OpenApiSchemaDeserializer.cs +++ b/src/Microsoft.OpenApi/Reader/V3/OpenApiSchemaDeserializer.cs @@ -302,7 +302,7 @@ internal static partial class OpenApiV3Deserializer {s => s.StartsWith(OpenApiConstants.ExtensionFieldNamePrefix, StringComparison.OrdinalIgnoreCase), (o, p, n, _) => o.AddExtension(p, LoadExtension(p,n))} }; - public static IOpenApiSchema LoadSchema(ParseNode node, OpenApiDocument hostDocument) + public static IOpenApiSchema LoadSchema(ParseNode node, OpenApiDocument? hostDocument) { var mapNode = node.CheckMapNode(OpenApiConstants.Schema); diff --git a/src/Microsoft.OpenApi/Reader/V3/OpenApiSecurityRequirementDeserializer.cs b/src/Microsoft.OpenApi/Reader/V3/OpenApiSecurityRequirementDeserializer.cs index 0250adcc1..81143ab2c 100644 --- a/src/Microsoft.OpenApi/Reader/V3/OpenApiSecurityRequirementDeserializer.cs +++ b/src/Microsoft.OpenApi/Reader/V3/OpenApiSecurityRequirementDeserializer.cs @@ -15,7 +15,7 @@ namespace Microsoft.OpenApi.Reader.V3 /// internal static partial class OpenApiV3Deserializer { - public static OpenApiSecurityRequirement LoadSecurityRequirement(ParseNode node, OpenApiDocument hostDocument) + public static OpenApiSecurityRequirement LoadSecurityRequirement(ParseNode node, OpenApiDocument? hostDocument) { var mapNode = node.CheckMapNode("security"); @@ -45,7 +45,7 @@ public static OpenApiSecurityRequirement LoadSecurityRequirement(ParseNode node, } private static OpenApiSecuritySchemeReference LoadSecuritySchemeByReference( - OpenApiDocument openApiDocument, + OpenApiDocument? openApiDocument, string schemeName) { return new OpenApiSecuritySchemeReference(schemeName, openApiDocument); diff --git a/src/Microsoft.OpenApi/Reader/V3/OpenApiSecuritySchemeDeserializer.cs b/src/Microsoft.OpenApi/Reader/V3/OpenApiSecuritySchemeDeserializer.cs index b01ece23f..c0acb4993 100644 --- a/src/Microsoft.OpenApi/Reader/V3/OpenApiSecuritySchemeDeserializer.cs +++ b/src/Microsoft.OpenApi/Reader/V3/OpenApiSecuritySchemeDeserializer.cs @@ -80,7 +80,7 @@ internal static partial class OpenApiV3Deserializer {s => s.StartsWith(OpenApiConstants.ExtensionFieldNamePrefix, StringComparison.OrdinalIgnoreCase), (o, p, n, _) => o.AddExtension(p, LoadExtension(p,n))} }; - public static IOpenApiSecurityScheme LoadSecurityScheme(ParseNode node, OpenApiDocument hostDocument) + public static IOpenApiSecurityScheme LoadSecurityScheme(ParseNode node, OpenApiDocument? hostDocument) { var mapNode = node.CheckMapNode("securityScheme"); var pointer = mapNode.GetReferencePointer(); diff --git a/src/Microsoft.OpenApi/Reader/V3/OpenApiServerDeserializer.cs b/src/Microsoft.OpenApi/Reader/V3/OpenApiServerDeserializer.cs index 4e4411625..3460d910a 100644 --- a/src/Microsoft.OpenApi/Reader/V3/OpenApiServerDeserializer.cs +++ b/src/Microsoft.OpenApi/Reader/V3/OpenApiServerDeserializer.cs @@ -35,7 +35,7 @@ internal static partial class OpenApiV3Deserializer {s => s.StartsWith(OpenApiConstants.ExtensionFieldNamePrefix, StringComparison.OrdinalIgnoreCase), (o, p, n, _) => o.AddExtension(p, LoadExtension(p,n))} }; - public static OpenApiServer LoadServer(ParseNode node, OpenApiDocument hostDocument) + public static OpenApiServer LoadServer(ParseNode node, OpenApiDocument? hostDocument) { var mapNode = node.CheckMapNode("server"); diff --git a/src/Microsoft.OpenApi/Reader/V3/OpenApiServerVariableDeserializer.cs b/src/Microsoft.OpenApi/Reader/V3/OpenApiServerVariableDeserializer.cs index 606dce0cf..0b256b4d0 100644 --- a/src/Microsoft.OpenApi/Reader/V3/OpenApiServerVariableDeserializer.cs +++ b/src/Microsoft.OpenApi/Reader/V3/OpenApiServerVariableDeserializer.cs @@ -38,7 +38,7 @@ internal static partial class OpenApiV3Deserializer {s => s.StartsWith(OpenApiConstants.ExtensionFieldNamePrefix, StringComparison.OrdinalIgnoreCase), (o, p, n, _) => o.AddExtension(p, LoadExtension(p,n))} }; - public static OpenApiServerVariable LoadServerVariable(ParseNode node, OpenApiDocument hostDocument) + public static OpenApiServerVariable LoadServerVariable(ParseNode node, OpenApiDocument? hostDocument) { var mapNode = node.CheckMapNode("serverVariable"); diff --git a/src/Microsoft.OpenApi/Reader/V3/OpenApiTagDeserializer.cs b/src/Microsoft.OpenApi/Reader/V3/OpenApiTagDeserializer.cs index d67d54d7c..3ca1801e8 100644 --- a/src/Microsoft.OpenApi/Reader/V3/OpenApiTagDeserializer.cs +++ b/src/Microsoft.OpenApi/Reader/V3/OpenApiTagDeserializer.cs @@ -35,7 +35,7 @@ internal static partial class OpenApiV3Deserializer {s => s.StartsWith(OpenApiConstants.ExtensionFieldNamePrefix, StringComparison.OrdinalIgnoreCase), (o, p, n, _) => o.AddExtension(p, LoadExtension(p,n))} }; - public static OpenApiTag LoadTag(ParseNode n, OpenApiDocument hostDocument) + public static OpenApiTag LoadTag(ParseNode n, OpenApiDocument? hostDocument) { var mapNode = n.CheckMapNode("tag"); diff --git a/src/Microsoft.OpenApi/Reader/V3/OpenApiV3Deserializer.cs b/src/Microsoft.OpenApi/Reader/V3/OpenApiV3Deserializer.cs index 29eb3db70..512b343f2 100644 --- a/src/Microsoft.OpenApi/Reader/V3/OpenApiV3Deserializer.cs +++ b/src/Microsoft.OpenApi/Reader/V3/OpenApiV3Deserializer.cs @@ -25,7 +25,7 @@ private static void ParseMap( T domainObject, FixedFieldMap fixedFieldMap, PatternFieldMap patternFieldMap, - OpenApiDocument hostDocument) + OpenApiDocument? hostDocument) { if (mapNode == null) { diff --git a/src/Microsoft.OpenApi/Reader/V3/OpenApiXmlDeserializer.cs b/src/Microsoft.OpenApi/Reader/V3/OpenApiXmlDeserializer.cs index e6bc2c836..ec1fe9703 100644 --- a/src/Microsoft.OpenApi/Reader/V3/OpenApiXmlDeserializer.cs +++ b/src/Microsoft.OpenApi/Reader/V3/OpenApiXmlDeserializer.cs @@ -65,7 +65,7 @@ internal static partial class OpenApiV3Deserializer {s => s.StartsWith(OpenApiConstants.ExtensionFieldNamePrefix, StringComparison.OrdinalIgnoreCase), (o, p, n, _) => o.AddExtension(p, LoadExtension(p,n))} }; - public static OpenApiXml LoadXml(ParseNode node, OpenApiDocument hostDocument) + public static OpenApiXml LoadXml(ParseNode node, OpenApiDocument? hostDocument) { var mapNode = node.CheckMapNode("xml"); diff --git a/src/Microsoft.OpenApi/Reader/V31/OpenApiCallbackDeserializer.cs b/src/Microsoft.OpenApi/Reader/V31/OpenApiCallbackDeserializer.cs index ac1a43998..b5f9d29b9 100644 --- a/src/Microsoft.OpenApi/Reader/V31/OpenApiCallbackDeserializer.cs +++ b/src/Microsoft.OpenApi/Reader/V31/OpenApiCallbackDeserializer.cs @@ -24,7 +24,7 @@ internal static partial class OpenApiV31Deserializer {s => s.StartsWith(OpenApiConstants.ExtensionFieldNamePrefix, StringComparison.OrdinalIgnoreCase), (o, p, n, _) => o.AddExtension(p, LoadExtension(p,n))}, }; - public static IOpenApiCallback LoadCallback(ParseNode node, OpenApiDocument hostDocument) + public static IOpenApiCallback LoadCallback(ParseNode node, OpenApiDocument? hostDocument) { var mapNode = node.CheckMapNode("callback"); diff --git a/src/Microsoft.OpenApi/Reader/V31/OpenApiComponentsDeserializer.cs b/src/Microsoft.OpenApi/Reader/V31/OpenApiComponentsDeserializer.cs index 2520692cd..eef62bbe9 100644 --- a/src/Microsoft.OpenApi/Reader/V31/OpenApiComponentsDeserializer.cs +++ b/src/Microsoft.OpenApi/Reader/V31/OpenApiComponentsDeserializer.cs @@ -34,7 +34,7 @@ internal static partial class OpenApiV31Deserializer {s => s.StartsWith(OpenApiConstants.ExtensionFieldNamePrefix, StringComparison.OrdinalIgnoreCase), (o, p, n, _) => o.AddExtension(p, LoadExtension(p, n))} }; - public static OpenApiComponents LoadComponents(ParseNode node, OpenApiDocument hostDocument) + public static OpenApiComponents LoadComponents(ParseNode node, OpenApiDocument? hostDocument) { var mapNode = node.CheckMapNode("components"); var components = new OpenApiComponents(); diff --git a/src/Microsoft.OpenApi/Reader/V31/OpenApiContactDeserializer.cs b/src/Microsoft.OpenApi/Reader/V31/OpenApiContactDeserializer.cs index 138eafe70..73e8e448f 100644 --- a/src/Microsoft.OpenApi/Reader/V31/OpenApiContactDeserializer.cs +++ b/src/Microsoft.OpenApi/Reader/V31/OpenApiContactDeserializer.cs @@ -43,7 +43,7 @@ internal static partial class OpenApiV31Deserializer {s => s.StartsWith(OpenApiConstants.ExtensionFieldNamePrefix, StringComparison.OrdinalIgnoreCase), (o, p, n, _) => o.AddExtension(p, LoadExtension(p,n))} }; - public static OpenApiContact LoadContact(ParseNode node, OpenApiDocument hostDocument) + public static OpenApiContact LoadContact(ParseNode node, OpenApiDocument? hostDocument) { var mapNode = node as MapNode; var contact = new OpenApiContact(); diff --git a/src/Microsoft.OpenApi/Reader/V31/OpenApiDiscriminatorDeserializer.cs b/src/Microsoft.OpenApi/Reader/V31/OpenApiDiscriminatorDeserializer.cs index e94f408d2..f7248ade9 100644 --- a/src/Microsoft.OpenApi/Reader/V31/OpenApiDiscriminatorDeserializer.cs +++ b/src/Microsoft.OpenApi/Reader/V31/OpenApiDiscriminatorDeserializer.cs @@ -35,7 +35,7 @@ internal static partial class OpenApiV31Deserializer {s => s.StartsWith(OpenApiConstants.ExtensionFieldNamePrefix, StringComparison.OrdinalIgnoreCase), (o, p, n, _) => o.AddExtension(p, LoadExtension(p,n))} }; - public static OpenApiDiscriminator LoadDiscriminator(ParseNode node, OpenApiDocument hostDocument) + public static OpenApiDiscriminator LoadDiscriminator(ParseNode node, OpenApiDocument? hostDocument) { var mapNode = node.CheckMapNode("discriminator"); diff --git a/src/Microsoft.OpenApi/Reader/V31/OpenApiEncodingDeserializer.cs b/src/Microsoft.OpenApi/Reader/V31/OpenApiEncodingDeserializer.cs index 5272f6495..2a88749d8 100644 --- a/src/Microsoft.OpenApi/Reader/V31/OpenApiEncodingDeserializer.cs +++ b/src/Microsoft.OpenApi/Reader/V31/OpenApiEncodingDeserializer.cs @@ -63,7 +63,7 @@ internal static partial class OpenApiV31Deserializer {s => s.StartsWith(OpenApiConstants.ExtensionFieldNamePrefix, StringComparison.OrdinalIgnoreCase), (o, p, n, _) => o.AddExtension(p, LoadExtension(p,n))} }; - public static OpenApiEncoding LoadEncoding(ParseNode node, OpenApiDocument hostDocument) + public static OpenApiEncoding LoadEncoding(ParseNode node, OpenApiDocument? hostDocument) { var mapNode = node.CheckMapNode("encoding"); diff --git a/src/Microsoft.OpenApi/Reader/V31/OpenApiExampleDeserializer.cs b/src/Microsoft.OpenApi/Reader/V31/OpenApiExampleDeserializer.cs index 49f7c3fd0..37413c474 100644 --- a/src/Microsoft.OpenApi/Reader/V31/OpenApiExampleDeserializer.cs +++ b/src/Microsoft.OpenApi/Reader/V31/OpenApiExampleDeserializer.cs @@ -48,7 +48,7 @@ internal static partial class OpenApiV31Deserializer {s => s.StartsWith(OpenApiConstants.ExtensionFieldNamePrefix, StringComparison.OrdinalIgnoreCase), (o, p, n, _) => o.AddExtension(p, LoadExtension(p,n))} }; - public static IOpenApiExample LoadExample(ParseNode node, OpenApiDocument hostDocument) + public static IOpenApiExample LoadExample(ParseNode node, OpenApiDocument? hostDocument) { var mapNode = node.CheckMapNode("example"); diff --git a/src/Microsoft.OpenApi/Reader/V31/OpenApiExternalDocsDeserializer.cs b/src/Microsoft.OpenApi/Reader/V31/OpenApiExternalDocsDeserializer.cs index 75d9c89a1..90d18f061 100644 --- a/src/Microsoft.OpenApi/Reader/V31/OpenApiExternalDocsDeserializer.cs +++ b/src/Microsoft.OpenApi/Reader/V31/OpenApiExternalDocsDeserializer.cs @@ -41,7 +41,7 @@ internal static partial class OpenApiV31Deserializer {s => s.StartsWith(OpenApiConstants.ExtensionFieldNamePrefix, StringComparison.OrdinalIgnoreCase), (o, p, n, _) => o.AddExtension(p, LoadExtension(p, n))} }; - public static OpenApiExternalDocs LoadExternalDocs(ParseNode node, OpenApiDocument hostDocument) + public static OpenApiExternalDocs LoadExternalDocs(ParseNode node, OpenApiDocument? hostDocument) { var mapNode = node.CheckMapNode("externalDocs"); diff --git a/src/Microsoft.OpenApi/Reader/V31/OpenApiHeaderDeserializer.cs b/src/Microsoft.OpenApi/Reader/V31/OpenApiHeaderDeserializer.cs index 3c01a56a2..d7cd56e75 100644 --- a/src/Microsoft.OpenApi/Reader/V31/OpenApiHeaderDeserializer.cs +++ b/src/Microsoft.OpenApi/Reader/V31/OpenApiHeaderDeserializer.cs @@ -111,7 +111,7 @@ internal static partial class OpenApiV31Deserializer {s => s.StartsWith(OpenApiConstants.ExtensionFieldNamePrefix, StringComparison.OrdinalIgnoreCase), (o, p, n, _) => o.AddExtension(p, LoadExtension(p,n))} }; - public static IOpenApiHeader LoadHeader(ParseNode node, OpenApiDocument hostDocument) + public static IOpenApiHeader LoadHeader(ParseNode node, OpenApiDocument? hostDocument) { var mapNode = node.CheckMapNode("header"); diff --git a/src/Microsoft.OpenApi/Reader/V31/OpenApiInfoDeserializer.cs b/src/Microsoft.OpenApi/Reader/V31/OpenApiInfoDeserializer.cs index 49a700683..2ea6a1f37 100644 --- a/src/Microsoft.OpenApi/Reader/V31/OpenApiInfoDeserializer.cs +++ b/src/Microsoft.OpenApi/Reader/V31/OpenApiInfoDeserializer.cs @@ -67,7 +67,7 @@ internal static partial class OpenApiV31Deserializer {s => s.StartsWith(OpenApiConstants.ExtensionFieldNamePrefix, StringComparison.OrdinalIgnoreCase), (o, k, n, _) => o.AddExtension(k,LoadExtension(k, n))} }; - public static OpenApiInfo LoadInfo(ParseNode node, OpenApiDocument hostDocument) + public static OpenApiInfo LoadInfo(ParseNode node, OpenApiDocument? hostDocument) { var mapNode = node.CheckMapNode("Info"); var info = new OpenApiInfo(); diff --git a/src/Microsoft.OpenApi/Reader/V31/OpenApiLicenseDeserializer.cs b/src/Microsoft.OpenApi/Reader/V31/OpenApiLicenseDeserializer.cs index 1f874d21e..84114937f 100644 --- a/src/Microsoft.OpenApi/Reader/V31/OpenApiLicenseDeserializer.cs +++ b/src/Microsoft.OpenApi/Reader/V31/OpenApiLicenseDeserializer.cs @@ -43,7 +43,7 @@ internal static partial class OpenApiV31Deserializer {s => s.StartsWith(OpenApiConstants.ExtensionFieldNamePrefix, StringComparison.OrdinalIgnoreCase), (o, p, n, _) => o.AddExtension(p, LoadExtension(p,n))} }; - internal static OpenApiLicense LoadLicense(ParseNode node, OpenApiDocument hostDocument) + internal static OpenApiLicense LoadLicense(ParseNode node, OpenApiDocument? hostDocument) { var mapNode = node.CheckMapNode("License"); diff --git a/src/Microsoft.OpenApi/Reader/V31/OpenApiLinkDeserializer.cs b/src/Microsoft.OpenApi/Reader/V31/OpenApiLinkDeserializer.cs index 9fdea6e29..66f352982 100644 --- a/src/Microsoft.OpenApi/Reader/V31/OpenApiLinkDeserializer.cs +++ b/src/Microsoft.OpenApi/Reader/V31/OpenApiLinkDeserializer.cs @@ -53,7 +53,7 @@ internal static partial class OpenApiV31Deserializer {s => s.StartsWith(OpenApiConstants.ExtensionFieldNamePrefix, StringComparison.OrdinalIgnoreCase), (o, p, n, _) => o.AddExtension(p, LoadExtension(p,n))}, }; - public static IOpenApiLink LoadLink(ParseNode node, OpenApiDocument hostDocument) + public static IOpenApiLink LoadLink(ParseNode node, OpenApiDocument? hostDocument) { var mapNode = node.CheckMapNode("link"); var link = new OpenApiLink(); diff --git a/src/Microsoft.OpenApi/Reader/V31/OpenApiMediaTypeDeserializer.cs b/src/Microsoft.OpenApi/Reader/V31/OpenApiMediaTypeDeserializer.cs index 2a46b4412..b5169582d 100644 --- a/src/Microsoft.OpenApi/Reader/V31/OpenApiMediaTypeDeserializer.cs +++ b/src/Microsoft.OpenApi/Reader/V31/OpenApiMediaTypeDeserializer.cs @@ -72,7 +72,7 @@ internal static partial class OpenApiV31Deserializer } }; - public static OpenApiMediaType LoadMediaType(ParseNode node, OpenApiDocument hostDocument) + public static OpenApiMediaType LoadMediaType(ParseNode node, OpenApiDocument? hostDocument) { var mapNode = node.CheckMapNode(OpenApiConstants.Content); diff --git a/src/Microsoft.OpenApi/Reader/V31/OpenApiOAuthFlowDeserializer.cs b/src/Microsoft.OpenApi/Reader/V31/OpenApiOAuthFlowDeserializer.cs index ab5f29350..238fe8e90 100644 --- a/src/Microsoft.OpenApi/Reader/V31/OpenApiOAuthFlowDeserializer.cs +++ b/src/Microsoft.OpenApi/Reader/V31/OpenApiOAuthFlowDeserializer.cs @@ -57,7 +57,7 @@ internal static partial class OpenApiV31Deserializer {s => s.StartsWith(OpenApiConstants.ExtensionFieldNamePrefix, StringComparison.OrdinalIgnoreCase), (o, p, n, _) => o.AddExtension(p, LoadExtension(p,n))} }; - public static OpenApiOAuthFlow LoadOAuthFlow(ParseNode node, OpenApiDocument hostDocument) + public static OpenApiOAuthFlow LoadOAuthFlow(ParseNode node, OpenApiDocument? hostDocument) { var mapNode = node.CheckMapNode("OAuthFlow"); diff --git a/src/Microsoft.OpenApi/Reader/V31/OpenApiOAuthFlowsDeserializer.cs b/src/Microsoft.OpenApi/Reader/V31/OpenApiOAuthFlowsDeserializer.cs index d472748f8..9fd96c950 100644 --- a/src/Microsoft.OpenApi/Reader/V31/OpenApiOAuthFlowsDeserializer.cs +++ b/src/Microsoft.OpenApi/Reader/V31/OpenApiOAuthFlowsDeserializer.cs @@ -26,7 +26,7 @@ internal static partial class OpenApiV31Deserializer {s => s.StartsWith(OpenApiConstants.ExtensionFieldNamePrefix, StringComparison.OrdinalIgnoreCase), (o, p, n, _) => o.AddExtension(p, LoadExtension(p,n))} }; - public static OpenApiOAuthFlows LoadOAuthFlows(ParseNode node, OpenApiDocument hostDocument) + public static OpenApiOAuthFlows LoadOAuthFlows(ParseNode node, OpenApiDocument? hostDocument) { var mapNode = node.CheckMapNode("OAuthFlows"); diff --git a/src/Microsoft.OpenApi/Reader/V31/OpenApiOperationDeserializer.cs b/src/Microsoft.OpenApi/Reader/V31/OpenApiOperationDeserializer.cs index 0f55299df..98865016a 100644 --- a/src/Microsoft.OpenApi/Reader/V31/OpenApiOperationDeserializer.cs +++ b/src/Microsoft.OpenApi/Reader/V31/OpenApiOperationDeserializer.cs @@ -99,7 +99,7 @@ internal static partial class OpenApiV31Deserializer {s => s.StartsWith(OpenApiConstants.ExtensionFieldNamePrefix, StringComparison.OrdinalIgnoreCase), (o, p, n, _) => o.AddExtension(p, LoadExtension(p,n))}, }; - internal static OpenApiOperation LoadOperation(ParseNode node, OpenApiDocument hostDocument) + internal static OpenApiOperation LoadOperation(ParseNode node, OpenApiDocument? hostDocument) { var mapNode = node.CheckMapNode("Operation"); @@ -110,7 +110,7 @@ internal static OpenApiOperation LoadOperation(ParseNode node, OpenApiDocument h return operation; } - private static OpenApiTagReference LoadTagByReference(string? tagName, OpenApiDocument hostDocument) + private static OpenApiTagReference LoadTagByReference(string? tagName, OpenApiDocument? hostDocument) { var tagObject = new OpenApiTagReference(tagName, hostDocument); return tagObject; diff --git a/src/Microsoft.OpenApi/Reader/V31/OpenApiParameterDeserializer.cs b/src/Microsoft.OpenApi/Reader/V31/OpenApiParameterDeserializer.cs index eae4e4993..3a70d9ac5 100644 --- a/src/Microsoft.OpenApi/Reader/V31/OpenApiParameterDeserializer.cs +++ b/src/Microsoft.OpenApi/Reader/V31/OpenApiParameterDeserializer.cs @@ -158,7 +158,7 @@ internal static partial class OpenApiV31Deserializer } }; - public static IOpenApiParameter LoadParameter(ParseNode node, OpenApiDocument hostDocument) + public static IOpenApiParameter LoadParameter(ParseNode node, OpenApiDocument? hostDocument) { var mapNode = node.CheckMapNode("parameter"); diff --git a/src/Microsoft.OpenApi/Reader/V31/OpenApiPathItemDeserializer.cs b/src/Microsoft.OpenApi/Reader/V31/OpenApiPathItemDeserializer.cs index 391a34bf6..ede615085 100644 --- a/src/Microsoft.OpenApi/Reader/V31/OpenApiPathItemDeserializer.cs +++ b/src/Microsoft.OpenApi/Reader/V31/OpenApiPathItemDeserializer.cs @@ -46,7 +46,7 @@ internal static partial class OpenApiV31Deserializer {s => s.StartsWith(OpenApiConstants.ExtensionFieldNamePrefix, StringComparison.OrdinalIgnoreCase), (o, p, n, _) => o.AddExtension(p, LoadExtension(p,n))} }; - public static IOpenApiPathItem LoadPathItem(ParseNode node, OpenApiDocument hostDocument) + public static IOpenApiPathItem LoadPathItem(ParseNode node, OpenApiDocument? hostDocument) { var mapNode = node.CheckMapNode("PathItem"); diff --git a/src/Microsoft.OpenApi/Reader/V31/OpenApiPathsDeserializer.cs b/src/Microsoft.OpenApi/Reader/V31/OpenApiPathsDeserializer.cs index 6e97b41ac..84d0571af 100644 --- a/src/Microsoft.OpenApi/Reader/V31/OpenApiPathsDeserializer.cs +++ b/src/Microsoft.OpenApi/Reader/V31/OpenApiPathsDeserializer.cs @@ -19,7 +19,7 @@ internal static partial class OpenApiV31Deserializer {s => s.StartsWith(OpenApiConstants.ExtensionFieldNamePrefix, StringComparison.OrdinalIgnoreCase), (o, p, n, _) => o.AddExtension(p, LoadExtension(p,n))} }; - public static OpenApiPaths LoadPaths(ParseNode node, OpenApiDocument hostDocument) + public static OpenApiPaths LoadPaths(ParseNode node, OpenApiDocument? hostDocument) { var mapNode = node.CheckMapNode("Paths"); diff --git a/src/Microsoft.OpenApi/Reader/V31/OpenApiRequestBodyDeserializer.cs b/src/Microsoft.OpenApi/Reader/V31/OpenApiRequestBodyDeserializer.cs index ef08b1b2b..1509319f9 100644 --- a/src/Microsoft.OpenApi/Reader/V31/OpenApiRequestBodyDeserializer.cs +++ b/src/Microsoft.OpenApi/Reader/V31/OpenApiRequestBodyDeserializer.cs @@ -46,7 +46,7 @@ internal static partial class OpenApiV31Deserializer {s => s.StartsWith(OpenApiConstants.ExtensionFieldNamePrefix, StringComparison.OrdinalIgnoreCase), (o, p, n, _) => o.AddExtension(p, LoadExtension(p,n))} }; - public static IOpenApiRequestBody LoadRequestBody(ParseNode node, OpenApiDocument hostDocument) + public static IOpenApiRequestBody LoadRequestBody(ParseNode node, OpenApiDocument? hostDocument) { var mapNode = node.CheckMapNode("requestBody"); diff --git a/src/Microsoft.OpenApi/Reader/V31/OpenApiResponseDeserializer.cs b/src/Microsoft.OpenApi/Reader/V31/OpenApiResponseDeserializer.cs index 6d910761c..9938abdd6 100644 --- a/src/Microsoft.OpenApi/Reader/V31/OpenApiResponseDeserializer.cs +++ b/src/Microsoft.OpenApi/Reader/V31/OpenApiResponseDeserializer.cs @@ -47,7 +47,7 @@ internal static partial class OpenApiV31Deserializer {s => s.StartsWith(OpenApiConstants.ExtensionFieldNamePrefix, StringComparison.OrdinalIgnoreCase), (o, p, n, _) => o.AddExtension(p, LoadExtension(p,n))} }; - public static IOpenApiResponse LoadResponse(ParseNode node, OpenApiDocument hostDocument) + public static IOpenApiResponse LoadResponse(ParseNode node, OpenApiDocument? hostDocument) { var mapNode = node.CheckMapNode("response"); diff --git a/src/Microsoft.OpenApi/Reader/V31/OpenApiResponsesDeserializer.cs b/src/Microsoft.OpenApi/Reader/V31/OpenApiResponsesDeserializer.cs index 50aad0d9a..cb8f084e1 100644 --- a/src/Microsoft.OpenApi/Reader/V31/OpenApiResponsesDeserializer.cs +++ b/src/Microsoft.OpenApi/Reader/V31/OpenApiResponsesDeserializer.cs @@ -22,7 +22,7 @@ internal static partial class OpenApiV31Deserializer {s => s.StartsWith(OpenApiConstants.ExtensionFieldNamePrefix, StringComparison.OrdinalIgnoreCase), (o, p, n, _) => o.AddExtension(p, LoadExtension(p,n))} }; - public static OpenApiResponses LoadResponses(ParseNode node, OpenApiDocument hostDocument) + public static OpenApiResponses LoadResponses(ParseNode node, OpenApiDocument? hostDocument) { var mapNode = node.CheckMapNode("Responses"); diff --git a/src/Microsoft.OpenApi/Reader/V31/OpenApiSchemaDeserializer.cs b/src/Microsoft.OpenApi/Reader/V31/OpenApiSchemaDeserializer.cs index a65626f34..c1a5a6816 100644 --- a/src/Microsoft.OpenApi/Reader/V31/OpenApiSchemaDeserializer.cs +++ b/src/Microsoft.OpenApi/Reader/V31/OpenApiSchemaDeserializer.cs @@ -208,10 +208,9 @@ internal static partial class OpenApiV31Deserializer "type", (o, n, doc) => { - var typeValue = n.GetScalarValue(); - if (n is ValueNode && typeValue is not null) + if (n is ValueNode) { - o.Type = typeValue.ToJsonSchemaType(); + o.Type = n.GetScalarValue()?.ToJsonSchemaType(); } else { @@ -365,7 +364,7 @@ internal static partial class OpenApiV31Deserializer {s => s.StartsWith(OpenApiConstants.ExtensionFieldNamePrefix, StringComparison.OrdinalIgnoreCase), (o, p, n, _) => o.AddExtension(p, LoadExtension(p,n))} }; - public static IOpenApiSchema LoadSchema(ParseNode node, OpenApiDocument hostDocument) + public static IOpenApiSchema LoadSchema(ParseNode node, OpenApiDocument? hostDocument) { var mapNode = node.CheckMapNode(OpenApiConstants.Schema); diff --git a/src/Microsoft.OpenApi/Reader/V31/OpenApiSecurityRequirementDeserializer.cs b/src/Microsoft.OpenApi/Reader/V31/OpenApiSecurityRequirementDeserializer.cs index 8f87ebf92..a46e8de7d 100644 --- a/src/Microsoft.OpenApi/Reader/V31/OpenApiSecurityRequirementDeserializer.cs +++ b/src/Microsoft.OpenApi/Reader/V31/OpenApiSecurityRequirementDeserializer.cs @@ -15,7 +15,7 @@ namespace Microsoft.OpenApi.Reader.V31 /// internal static partial class OpenApiV31Deserializer { - public static OpenApiSecurityRequirement LoadSecurityRequirement(ParseNode node, OpenApiDocument hostDocument) + public static OpenApiSecurityRequirement LoadSecurityRequirement(ParseNode node, OpenApiDocument? hostDocument) { var mapNode = node.CheckMapNode("security"); @@ -43,7 +43,7 @@ public static OpenApiSecurityRequirement LoadSecurityRequirement(ParseNode node, return securityRequirement; } - private static OpenApiSecuritySchemeReference LoadSecuritySchemeByReference(string schemeName, OpenApiDocument hostDocument) + private static OpenApiSecuritySchemeReference LoadSecuritySchemeByReference(string schemeName, OpenApiDocument? hostDocument) { return new OpenApiSecuritySchemeReference(schemeName, hostDocument); } diff --git a/src/Microsoft.OpenApi/Reader/V31/OpenApiSecuritySchemeDeserializer.cs b/src/Microsoft.OpenApi/Reader/V31/OpenApiSecuritySchemeDeserializer.cs index 54136f669..b79134330 100644 --- a/src/Microsoft.OpenApi/Reader/V31/OpenApiSecuritySchemeDeserializer.cs +++ b/src/Microsoft.OpenApi/Reader/V31/OpenApiSecuritySchemeDeserializer.cs @@ -87,7 +87,7 @@ internal static partial class OpenApiV31Deserializer {s => s.StartsWith(OpenApiConstants.ExtensionFieldNamePrefix, StringComparison.OrdinalIgnoreCase), (o, p, n, _) => o.AddExtension(p, LoadExtension(p,n))} }; - public static IOpenApiSecurityScheme LoadSecurityScheme(ParseNode node, OpenApiDocument hostDocument) + public static IOpenApiSecurityScheme LoadSecurityScheme(ParseNode node, OpenApiDocument? hostDocument) { var mapNode = node.CheckMapNode("securityScheme"); diff --git a/src/Microsoft.OpenApi/Reader/V31/OpenApiServerDeserializer.cs b/src/Microsoft.OpenApi/Reader/V31/OpenApiServerDeserializer.cs index b51a16f5d..edcff4cf1 100644 --- a/src/Microsoft.OpenApi/Reader/V31/OpenApiServerDeserializer.cs +++ b/src/Microsoft.OpenApi/Reader/V31/OpenApiServerDeserializer.cs @@ -41,7 +41,7 @@ internal static partial class OpenApiV31Deserializer {s => s.StartsWith(OpenApiConstants.ExtensionFieldNamePrefix, StringComparison.OrdinalIgnoreCase), (o, p, n, _) => o.AddExtension(p, LoadExtension(p,n))} }; - public static OpenApiServer LoadServer(ParseNode node, OpenApiDocument hostDocument) + public static OpenApiServer LoadServer(ParseNode node, OpenApiDocument? hostDocument) { var mapNode = node.CheckMapNode("server"); diff --git a/src/Microsoft.OpenApi/Reader/V31/OpenApiServerVariableDeserializer.cs b/src/Microsoft.OpenApi/Reader/V31/OpenApiServerVariableDeserializer.cs index cec3618b5..e157e12e7 100644 --- a/src/Microsoft.OpenApi/Reader/V31/OpenApiServerVariableDeserializer.cs +++ b/src/Microsoft.OpenApi/Reader/V31/OpenApiServerVariableDeserializer.cs @@ -44,7 +44,7 @@ internal static partial class OpenApiV31Deserializer {s => s.StartsWith(OpenApiConstants.ExtensionFieldNamePrefix, StringComparison.OrdinalIgnoreCase), (o, p, n, _) => o.AddExtension(p, LoadExtension(p,n))} }; - public static OpenApiServerVariable LoadServerVariable(ParseNode node, OpenApiDocument hostDocument) + public static OpenApiServerVariable LoadServerVariable(ParseNode node, OpenApiDocument? hostDocument) { var mapNode = node.CheckMapNode("serverVariable"); diff --git a/src/Microsoft.OpenApi/Reader/V31/OpenApiTagDeserializer.cs b/src/Microsoft.OpenApi/Reader/V31/OpenApiTagDeserializer.cs index aea4c9c43..892182f5b 100644 --- a/src/Microsoft.OpenApi/Reader/V31/OpenApiTagDeserializer.cs +++ b/src/Microsoft.OpenApi/Reader/V31/OpenApiTagDeserializer.cs @@ -41,7 +41,7 @@ internal static partial class OpenApiV31Deserializer {s => s.StartsWith(OpenApiConstants.ExtensionFieldNamePrefix, StringComparison.OrdinalIgnoreCase), (o, p, n, _) => o.AddExtension(p, LoadExtension(p,n))} }; - public static OpenApiTag LoadTag(ParseNode n, OpenApiDocument hostDocument) + public static OpenApiTag LoadTag(ParseNode n, OpenApiDocument? hostDocument) { var mapNode = n.CheckMapNode("tag"); diff --git a/src/Microsoft.OpenApi/Reader/V31/OpenApiXmlDeserializer.cs b/src/Microsoft.OpenApi/Reader/V31/OpenApiXmlDeserializer.cs index c2776c52a..fc2ba03c0 100644 --- a/src/Microsoft.OpenApi/Reader/V31/OpenApiXmlDeserializer.cs +++ b/src/Microsoft.OpenApi/Reader/V31/OpenApiXmlDeserializer.cs @@ -67,7 +67,7 @@ internal static partial class OpenApiV31Deserializer {s => s.StartsWith(OpenApiConstants.ExtensionFieldNamePrefix, StringComparison.OrdinalIgnoreCase), (o, p, n, _) => o.AddExtension(p, LoadExtension(p,n))} }; - public static OpenApiXml LoadXml(ParseNode node, OpenApiDocument hostDocument) + public static OpenApiXml LoadXml(ParseNode node, OpenApiDocument? hostDocument) { var mapNode = node.CheckMapNode("xml"); diff --git a/src/Microsoft.OpenApi/Writers/OpenApiJsonWriter.cs b/src/Microsoft.OpenApi/Writers/OpenApiJsonWriter.cs index 3226dda25..1222a2be6 100644 --- a/src/Microsoft.OpenApi/Writers/OpenApiJsonWriter.cs +++ b/src/Microsoft.OpenApi/Writers/OpenApiJsonWriter.cs @@ -59,7 +59,7 @@ public override void WriteStartObject() var currentScope = StartScope(ScopeType.Object); - if (previousScope is {Type: ScopeType.Array}) + if (previousScope is { Type: ScopeType.Array }) { currentScope.IsInArray = true; @@ -110,7 +110,7 @@ public override void WriteStartArray() var currentScope = StartScope(ScopeType.Array); - if (previousScope is {Type: ScopeType.Array}) + if (previousScope is { Type: ScopeType.Array }) { currentScope.IsInArray = true; @@ -158,17 +158,14 @@ public override void WritePropertyName(string? name) VerifyCanWritePropertyName(name); var currentScope = CurrentScope(); - if (currentScope is not null) + if (currentScope?.ObjectCount != 0) { - if (currentScope.ObjectCount != 0) - { - Writer.Write(WriterConstants.ObjectMemberSeparator); - } + Writer.Write(WriterConstants.ObjectMemberSeparator); + } - WriteLine(); + WriteLine(); - currentScope.ObjectCount++; - } + currentScope!.ObjectCount++; WriteIndentation(); diff --git a/src/Microsoft.OpenApi/Writers/OpenApiWriterExtensions.cs b/src/Microsoft.OpenApi/Writers/OpenApiWriterExtensions.cs index e8a4e2de0..28e9a14bc 100644 --- a/src/Microsoft.OpenApi/Writers/OpenApiWriterExtensions.cs +++ b/src/Microsoft.OpenApi/Writers/OpenApiWriterExtensions.cs @@ -191,8 +191,8 @@ public static void WriteRequiredObject( public static void WriteOptionalCollection( this IOpenApiWriter writer, string name, - IEnumerable? elements, - Action action) + IEnumerable? elements, + Action action) { if (elements != null && elements.Any()) { diff --git a/src/Microsoft.OpenApi/Writers/OpenApiYamlWriter.cs b/src/Microsoft.OpenApi/Writers/OpenApiYamlWriter.cs index 132021993..943705a30 100644 --- a/src/Microsoft.OpenApi/Writers/OpenApiYamlWriter.cs +++ b/src/Microsoft.OpenApi/Writers/OpenApiYamlWriter.cs @@ -49,7 +49,7 @@ public override void WriteStartObject() var currentScope = StartScope(ScopeType.Object); - if (previousScope is {Type: ScopeType.Array}) + if (previousScope is { Type: ScopeType.Array }) { currentScope.IsInArray = true; @@ -77,7 +77,7 @@ public override void WriteEndObject() if (previousScope.ObjectCount == 0) { // If we are in an object, write a white space preceding the braces. - if (currentScope is {Type: ScopeType.Object}) + if (currentScope is { Type: ScopeType.Object }) { Writer.Write(" "); } @@ -95,7 +95,7 @@ public override void WriteStartArray() var currentScope = StartScope(ScopeType.Array); - if (previousScope is {Type: ScopeType.Array}) + if (previousScope is { Type: ScopeType.Array }) { currentScope.IsInArray = true; @@ -123,7 +123,7 @@ public override void WriteEndArray() if (previousScope.ObjectCount == 0) { // If we are in an object, write a white space preceding the braces. - if (currentScope is {Type: ScopeType.Object}) + if (currentScope is { Type: ScopeType.Object }) { Writer.Write(" "); } @@ -140,30 +140,28 @@ public override void WritePropertyName(string? name) VerifyCanWritePropertyName(name); var currentScope = CurrentScope(); - if (currentScope is not null) + + // If this is NOT the first property in the object, always start a new line and add indentation. + if (currentScope?.ObjectCount != 0) { - // If this is NOT the first property in the object, always start a new line and add indentation. - if (currentScope.ObjectCount != 0) - { - Writer.WriteLine(); - WriteIndentation(); - } - // Only add newline and indentation when this object is not in the top level scope and not in an array. - // The top level scope should have no indentation and it is already in its own line. - // The first property of an object inside array can go after the array prefix (-) directly. - else if (!IsTopLevelScope() && !currentScope.IsInArray) - { - Writer.WriteLine(); - WriteIndentation(); - } + Writer.WriteLine(); + WriteIndentation(); + } + // Only add newline and indentation when this object is not in the top level scope and not in an array. + // The top level scope should have no indentation and it is already in its own line. + // The first property of an object inside array can go after the array prefix (-) directly. + else if (!IsTopLevelScope() && !currentScope.IsInArray) + { + Writer.WriteLine(); + WriteIndentation(); + } - name = name?.GetYamlCompatibleString(); + name = name?.GetYamlCompatibleString(); - Writer.Write(name); - Writer.Write(":"); + Writer.Write(name); + Writer.Write(":"); - currentScope.ObjectCount++; - } + currentScope!.ObjectCount++; } /// @@ -201,9 +199,8 @@ public override void WriteValue(string? value) IncreaseIndentation(); - if (value is not null) + using (var reader = new StringReader(value!)) { - using var reader = new StringReader(value); var firstLine = true; while (reader.ReadLine() is var line && line != null) { @@ -220,7 +217,7 @@ public override void WriteValue(string? value) Writer.Write(line); } - } + } DecreaseIndentation(); } @@ -229,23 +226,23 @@ public override void WriteValue(string? value) private void WriteChompingIndicator(string? value) { var trailingNewlines = 0; - var end = value?.Length - 1; + var end = value!.Length - 1; // We only need to know whether there are 0, 1, or more trailing newlines while (end >= 0 && trailingNewlines < 2) { - var found = value?.LastIndexOfAny(new[] { '\n', '\r' }, end.Value, 2); + var found = value.LastIndexOfAny(new[] { '\n', '\r' }, end, 2); if (found == -1 || found != end) { // does not ends with newline break; } - if (value?[end.Value] == '\r') + if (value[end] == '\r') { // ends with \r end--; } - else if (end > 0 && value?[end.Value - 1] == '\r') + else if (end > 0 && value[end - 1] == '\r') { // ends with \r\n end -= 2; @@ -289,11 +286,11 @@ public override void WriteNull() /// protected override void WriteValueSeparator() { - var currentScopeCount = CurrentScope()?.ObjectCount; - if (currentScopeCount is not null && IsArrayScope()) + if (IsArrayScope()) { + var objectCount = CurrentScope()!.ObjectCount; // If array is the outermost scope and this is the first item, there is no need to insert a newline. - if (!IsTopLevelScope() || currentScopeCount != 0) + if (!IsTopLevelScope() || objectCount != 0) { Writer.WriteLine(); } @@ -301,7 +298,7 @@ protected override void WriteValueSeparator() WriteIndentation(); Writer.Write(WriterConstants.PrefixOfArrayItem); - currentScopeCount++; + CurrentScope()!.ObjectCount++; } else { diff --git a/test/Microsoft.OpenApi.Tests/PublicApi/PublicApi.approved.txt b/test/Microsoft.OpenApi.Tests/PublicApi/PublicApi.approved.txt index 273407001..a2e8e7d3b 100644 --- a/test/Microsoft.OpenApi.Tests/PublicApi/PublicApi.approved.txt +++ b/test/Microsoft.OpenApi.Tests/PublicApi/PublicApi.approved.txt @@ -7,8 +7,8 @@ namespace Microsoft.OpenApi.Any { public class OpenApiAny : Microsoft.OpenApi.Interfaces.IOpenApiElement, Microsoft.OpenApi.Interfaces.IOpenApiExtension { - public OpenApiAny(System.Text.Json.Nodes.JsonNode jsonNode) { } - public System.Text.Json.Nodes.JsonNode Node { get; } + public OpenApiAny(System.Text.Json.Nodes.JsonNode? jsonNode) { } + public System.Text.Json.Nodes.JsonNode? Node { get; } public void Write(Microsoft.OpenApi.Writers.IOpenApiWriter writer, Microsoft.OpenApi.OpenApiSpecVersion specVersion) { } } } @@ -17,8 +17,8 @@ namespace Microsoft.OpenApi.Attributes [System.AttributeUsage(System.AttributeTargets.Property | System.AttributeTargets.Field)] public class DisplayAttribute : System.Attribute { - public DisplayAttribute(string name) { } - public string Name { get; } + public DisplayAttribute(string? name) { } + public string? Name { get; } } } namespace Microsoft.OpenApi.Exceptions @@ -27,8 +27,8 @@ namespace Microsoft.OpenApi.Exceptions { public OpenApiException() { } public OpenApiException(string message) { } - public OpenApiException(string message, System.Exception innerException) { } - public string Pointer { get; set; } + public OpenApiException(string message, System.Exception? innerException) { } + public string? Pointer { get; set; } } [System.Serializable] public class OpenApiReaderException : Microsoft.OpenApi.Exceptions.OpenApiException @@ -37,20 +37,20 @@ namespace Microsoft.OpenApi.Exceptions public OpenApiReaderException(string message) { } public OpenApiReaderException(string message, Microsoft.OpenApi.Reader.ParsingContext context) { } public OpenApiReaderException(string message, System.Exception innerException) { } - public OpenApiReaderException(string message, System.Text.Json.Nodes.JsonNode node) { } + public OpenApiReaderException(string message, System.Text.Json.Nodes.JsonNode? node) { } } [System.Serializable] public class OpenApiUnsupportedSpecVersionException : System.Exception { - public OpenApiUnsupportedSpecVersionException(string specificationVersion) { } + public OpenApiUnsupportedSpecVersionException(string? specificationVersion) { } public OpenApiUnsupportedSpecVersionException(string specificationVersion, System.Exception innerException) { } - public string SpecificationVersion { get; } + public string? SpecificationVersion { get; } } public class OpenApiWriterException : Microsoft.OpenApi.Exceptions.OpenApiException { public OpenApiWriterException() { } public OpenApiWriterException(string message) { } - public OpenApiWriterException(string message, System.Exception innerException) { } + public OpenApiWriterException(string message, System.Exception? innerException) { } } } namespace Microsoft.OpenApi.Expressions @@ -60,9 +60,9 @@ namespace Microsoft.OpenApi.Expressions public const string Body = "body"; public const string PointerPrefix = "#"; public BodyExpression() { } - public BodyExpression(Microsoft.OpenApi.JsonPointer pointer) { } + public BodyExpression(Microsoft.OpenApi.JsonPointer? pointer) { } public override string Expression { get; } - public string Fragment { get; } + public string? Fragment { get; } } public class CompositeExpression : Microsoft.OpenApi.Expressions.RuntimeExpression { @@ -75,7 +75,7 @@ namespace Microsoft.OpenApi.Expressions public const string Header = "header."; public HeaderExpression(string token) { } public override string Expression { get; } - public string Token { get; } + public string? Token { get; } } public sealed class MethodExpression : Microsoft.OpenApi.Expressions.RuntimeExpression { @@ -88,14 +88,14 @@ namespace Microsoft.OpenApi.Expressions public const string Path = "path."; public PathExpression(string name) { } public override string Expression { get; } - public string Name { get; } + public string? Name { get; } } public sealed class QueryExpression : Microsoft.OpenApi.Expressions.SourceExpression { public const string Query = "query."; public QueryExpression(string name) { } public override string Expression { get; } - public string Name { get; } + public string? Name { get; } } public sealed class RequestExpression : Microsoft.OpenApi.Expressions.RuntimeExpression { @@ -116,16 +116,16 @@ namespace Microsoft.OpenApi.Expressions public const string Prefix = "$"; protected RuntimeExpression() { } public abstract string Expression { get; } - public bool Equals(Microsoft.OpenApi.Expressions.RuntimeExpression obj) { } - public override bool Equals(object obj) { } + public bool Equals(Microsoft.OpenApi.Expressions.RuntimeExpression? obj) { } + public override bool Equals(object? obj) { } public override int GetHashCode() { } public override string ToString() { } public static Microsoft.OpenApi.Expressions.RuntimeExpression Build(string expression) { } } public abstract class SourceExpression : Microsoft.OpenApi.Expressions.RuntimeExpression { - protected SourceExpression(string value) { } - protected string Value { get; } + protected SourceExpression(string? value) { } + protected string? Value { get; } public new static Microsoft.OpenApi.Expressions.SourceExpression Build(string expression) { } } public sealed class StatusCodeExpression : Microsoft.OpenApi.Expressions.RuntimeExpression @@ -146,7 +146,7 @@ namespace Microsoft.OpenApi.Extensions public static class EnumExtensions { [System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessage("Trimming", "IL2075", Justification="Fields are never trimmed for enum types.")] - public static T GetAttributeOfType(this System.Enum enumValue) + public static T? GetAttributeOfType(this System.Enum enumValue) where T : System.Attribute { } public static string GetDisplayName(this System.Enum enumValue) { } } @@ -175,16 +175,16 @@ namespace Microsoft.OpenApi.Extensions where T : Microsoft.OpenApi.Interfaces.IOpenApiSerializable { } public static System.Threading.Tasks.Task SerializeAsync(this T element, Microsoft.OpenApi.OpenApiSpecVersion specVersion, Microsoft.OpenApi.OpenApiFormat format, System.Threading.CancellationToken cancellationToken = default) where T : Microsoft.OpenApi.Interfaces.IOpenApiSerializable { } - public static System.Threading.Tasks.Task SerializeAsync(this T element, Microsoft.OpenApi.Writers.IOpenApiWriter writer, Microsoft.OpenApi.OpenApiSpecVersion specVersion, System.Threading.CancellationToken cancellationToken = default) + public static System.Threading.Tasks.Task SerializeAsync(this T? element, Microsoft.OpenApi.Writers.IOpenApiWriter writer, Microsoft.OpenApi.OpenApiSpecVersion specVersion, System.Threading.CancellationToken cancellationToken = default) where T : Microsoft.OpenApi.Interfaces.IOpenApiSerializable { } public static System.Threading.Tasks.Task SerializeAsync(this T element, System.IO.Stream stream, Microsoft.OpenApi.OpenApiSpecVersion specVersion, Microsoft.OpenApi.OpenApiFormat format, System.Threading.CancellationToken cancellationToken = default) where T : Microsoft.OpenApi.Interfaces.IOpenApiSerializable { } - public static System.Threading.Tasks.Task SerializeAsync(this T element, System.IO.Stream stream, Microsoft.OpenApi.OpenApiSpecVersion specVersion, Microsoft.OpenApi.OpenApiFormat format, Microsoft.OpenApi.Writers.OpenApiWriterSettings settings, System.Threading.CancellationToken cancellationToken = default) + public static System.Threading.Tasks.Task SerializeAsync(this T element, System.IO.Stream stream, Microsoft.OpenApi.OpenApiSpecVersion specVersion, Microsoft.OpenApi.OpenApiFormat format, Microsoft.OpenApi.Writers.OpenApiWriterSettings? settings, System.Threading.CancellationToken cancellationToken = default) where T : Microsoft.OpenApi.Interfaces.IOpenApiSerializable { } } public static class OpenApiServerExtensions { - public static string ReplaceServerUrlVariables(this Microsoft.OpenApi.Models.OpenApiServer server, System.Collections.Generic.IDictionary values = null) { } + public static string? ReplaceServerUrlVariables(this Microsoft.OpenApi.Models.OpenApiServer server, System.Collections.Generic.IDictionary? values = null) { } } public static class OpenApiTypeMapper { @@ -200,12 +200,12 @@ namespace Microsoft.OpenApi.Interfaces public interface IDiagnostic { } public interface IOpenApiAnnotatable { - System.Collections.Generic.IDictionary Annotations { get; set; } + System.Collections.Generic.IDictionary? Annotations { get; set; } } public interface IOpenApiElement { } public interface IOpenApiExtensible : Microsoft.OpenApi.Interfaces.IOpenApiElement { - System.Collections.Generic.IDictionary Extensions { get; set; } + System.Collections.Generic.IDictionary? Extensions { get; set; } } public interface IOpenApiExtension { @@ -213,25 +213,25 @@ namespace Microsoft.OpenApi.Interfaces } public interface IOpenApiReadOnlyExtensible { - System.Collections.Generic.IDictionary Extensions { get; } + System.Collections.Generic.IDictionary? Extensions { get; } } public interface IOpenApiReader { Microsoft.OpenApi.Reader.ReadResult Read(System.IO.MemoryStream input, Microsoft.OpenApi.Reader.OpenApiReaderSettings settings); System.Threading.Tasks.Task ReadAsync(System.IO.Stream input, Microsoft.OpenApi.Reader.OpenApiReaderSettings settings, System.Threading.CancellationToken cancellationToken = default); - T ReadFragment(System.IO.MemoryStream input, Microsoft.OpenApi.OpenApiSpecVersion version, Microsoft.OpenApi.Models.OpenApiDocument openApiDocument, out Microsoft.OpenApi.Reader.OpenApiDiagnostic diagnostic, Microsoft.OpenApi.Reader.OpenApiReaderSettings settings = null) + T? ReadFragment(System.IO.MemoryStream input, Microsoft.OpenApi.OpenApiSpecVersion version, Microsoft.OpenApi.Models.OpenApiDocument openApiDocument, out Microsoft.OpenApi.Reader.OpenApiDiagnostic diagnostic, Microsoft.OpenApi.Reader.OpenApiReaderSettings? settings = null) where T : Microsoft.OpenApi.Interfaces.IOpenApiElement; } public interface IOpenApiReferenceHolder : Microsoft.OpenApi.Interfaces.IOpenApiElement, Microsoft.OpenApi.Interfaces.IOpenApiSerializable { - Microsoft.OpenApi.Models.OpenApiReference Reference { get; init; } + Microsoft.OpenApi.Models.OpenApiReference? Reference { get; init; } bool UnresolvedReference { get; } } public interface IOpenApiReferenceHolder : Microsoft.OpenApi.Interfaces.IOpenApiElement, Microsoft.OpenApi.Interfaces.IOpenApiReferenceHolder, Microsoft.OpenApi.Interfaces.IOpenApiSerializable where out T : Microsoft.OpenApi.Interfaces.IOpenApiReferenceable, V { T Target { get; } - V CopyReferenceAsTargetElementWithOverrides(V source); + V? CopyReferenceAsTargetElementWithOverrides(V? source); } public interface IOpenApiReferenceable : Microsoft.OpenApi.Interfaces.IOpenApiElement, Microsoft.OpenApi.Interfaces.IOpenApiSerializable { } public interface IOpenApiSerializable : Microsoft.OpenApi.Interfaces.IOpenApiElement @@ -254,7 +254,7 @@ namespace Microsoft.OpenApi public class JsonPointer { public JsonPointer(string pointer) { } - public Microsoft.OpenApi.JsonPointer ParentPointer { get; } + public Microsoft.OpenApi.JsonPointer? ParentPointer { get; } public string[] Tokens { get; } public override string ToString() { } } @@ -339,100 +339,100 @@ namespace Microsoft.OpenApi.Models.Interfaces { public interface IOpenApiCallback : Microsoft.OpenApi.Interfaces.IOpenApiElement, Microsoft.OpenApi.Interfaces.IOpenApiReadOnlyExtensible, Microsoft.OpenApi.Interfaces.IOpenApiSerializable, Microsoft.OpenApi.Interfaces.IShallowCopyable { - System.Collections.Generic.Dictionary PathItems { get; } + System.Collections.Generic.Dictionary? PathItems { get; } } public interface IOpenApiDescribedElement : Microsoft.OpenApi.Interfaces.IOpenApiElement { - string Description { get; set; } + string? Description { get; set; } } public interface IOpenApiExample : Microsoft.OpenApi.Interfaces.IOpenApiElement, Microsoft.OpenApi.Interfaces.IOpenApiReadOnlyExtensible, Microsoft.OpenApi.Interfaces.IOpenApiSerializable, Microsoft.OpenApi.Interfaces.IShallowCopyable, Microsoft.OpenApi.Models.Interfaces.IOpenApiDescribedElement, Microsoft.OpenApi.Models.Interfaces.IOpenApiSummarizedElement { - string ExternalValue { get; } - System.Text.Json.Nodes.JsonNode Value { get; } + string? ExternalValue { get; } + System.Text.Json.Nodes.JsonNode? Value { get; } } public interface IOpenApiHeader : Microsoft.OpenApi.Interfaces.IOpenApiElement, Microsoft.OpenApi.Interfaces.IOpenApiReadOnlyExtensible, Microsoft.OpenApi.Interfaces.IOpenApiSerializable, Microsoft.OpenApi.Interfaces.IShallowCopyable, Microsoft.OpenApi.Models.Interfaces.IOpenApiDescribedElement { bool AllowEmptyValue { get; } bool AllowReserved { get; } - System.Collections.Generic.IDictionary Content { get; } + System.Collections.Generic.IDictionary? Content { get; } bool Deprecated { get; } - System.Text.Json.Nodes.JsonNode Example { get; } - System.Collections.Generic.IDictionary Examples { get; } + System.Text.Json.Nodes.JsonNode? Example { get; } + System.Collections.Generic.IDictionary? Examples { get; } bool Explode { get; } bool Required { get; } - Microsoft.OpenApi.Models.Interfaces.IOpenApiSchema Schema { get; } + Microsoft.OpenApi.Models.Interfaces.IOpenApiSchema? Schema { get; } Microsoft.OpenApi.Models.ParameterStyle? Style { get; } } public interface IOpenApiLink : Microsoft.OpenApi.Interfaces.IOpenApiElement, Microsoft.OpenApi.Interfaces.IOpenApiReadOnlyExtensible, Microsoft.OpenApi.Interfaces.IOpenApiSerializable, Microsoft.OpenApi.Interfaces.IShallowCopyable, Microsoft.OpenApi.Models.Interfaces.IOpenApiDescribedElement { - string OperationId { get; } - string OperationRef { get; } - System.Collections.Generic.IDictionary Parameters { get; } - Microsoft.OpenApi.Models.RuntimeExpressionAnyWrapper RequestBody { get; } - Microsoft.OpenApi.Models.OpenApiServer Server { get; } + string? OperationId { get; } + string? OperationRef { get; } + System.Collections.Generic.IDictionary? Parameters { get; } + Microsoft.OpenApi.Models.RuntimeExpressionAnyWrapper? RequestBody { get; } + Microsoft.OpenApi.Models.OpenApiServer? Server { get; } } public interface IOpenApiParameter : Microsoft.OpenApi.Interfaces.IOpenApiElement, Microsoft.OpenApi.Interfaces.IOpenApiReadOnlyExtensible, Microsoft.OpenApi.Interfaces.IOpenApiSerializable, Microsoft.OpenApi.Interfaces.IShallowCopyable, Microsoft.OpenApi.Models.Interfaces.IOpenApiDescribedElement { bool AllowEmptyValue { get; } bool AllowReserved { get; } - System.Collections.Generic.IDictionary Content { get; } + System.Collections.Generic.IDictionary? Content { get; } bool Deprecated { get; } - System.Text.Json.Nodes.JsonNode Example { get; } - System.Collections.Generic.IDictionary Examples { get; } + System.Text.Json.Nodes.JsonNode? Example { get; } + System.Collections.Generic.IDictionary? Examples { get; } bool Explode { get; } Microsoft.OpenApi.Models.ParameterLocation? In { get; } - string Name { get; } + string? Name { get; } bool Required { get; } - Microsoft.OpenApi.Models.Interfaces.IOpenApiSchema Schema { get; } + Microsoft.OpenApi.Models.Interfaces.IOpenApiSchema? Schema { get; } Microsoft.OpenApi.Models.ParameterStyle? Style { get; } } public interface IOpenApiPathItem : Microsoft.OpenApi.Interfaces.IOpenApiElement, Microsoft.OpenApi.Interfaces.IOpenApiReadOnlyExtensible, Microsoft.OpenApi.Interfaces.IOpenApiSerializable, Microsoft.OpenApi.Interfaces.IShallowCopyable, Microsoft.OpenApi.Models.Interfaces.IOpenApiDescribedElement, Microsoft.OpenApi.Models.Interfaces.IOpenApiSummarizedElement { - System.Collections.Generic.IDictionary Operations { get; } - System.Collections.Generic.IList Parameters { get; } - System.Collections.Generic.IList Servers { get; } + System.Collections.Generic.IDictionary? Operations { get; } + System.Collections.Generic.IList? Parameters { get; } + System.Collections.Generic.IList? Servers { get; } } public interface IOpenApiReadOnlyDescribedElement : Microsoft.OpenApi.Interfaces.IOpenApiElement { - string Description { get; } + string? Description { get; } } public interface IOpenApiRequestBody : Microsoft.OpenApi.Interfaces.IOpenApiElement, Microsoft.OpenApi.Interfaces.IOpenApiReadOnlyExtensible, Microsoft.OpenApi.Interfaces.IOpenApiSerializable, Microsoft.OpenApi.Interfaces.IShallowCopyable, Microsoft.OpenApi.Models.Interfaces.IOpenApiDescribedElement { - System.Collections.Generic.IDictionary Content { get; } + System.Collections.Generic.IDictionary? Content { get; } bool Required { get; } - Microsoft.OpenApi.Models.Interfaces.IOpenApiParameter ConvertToBodyParameter(Microsoft.OpenApi.Writers.IOpenApiWriter writer); - System.Collections.Generic.IEnumerable ConvertToFormDataParameters(Microsoft.OpenApi.Writers.IOpenApiWriter writer); + Microsoft.OpenApi.Models.Interfaces.IOpenApiParameter? ConvertToBodyParameter(Microsoft.OpenApi.Writers.IOpenApiWriter writer); + System.Collections.Generic.IEnumerable? ConvertToFormDataParameters(Microsoft.OpenApi.Writers.IOpenApiWriter writer); } public interface IOpenApiResponse : Microsoft.OpenApi.Interfaces.IOpenApiElement, Microsoft.OpenApi.Interfaces.IOpenApiReadOnlyExtensible, Microsoft.OpenApi.Interfaces.IOpenApiSerializable, Microsoft.OpenApi.Interfaces.IShallowCopyable, Microsoft.OpenApi.Models.Interfaces.IOpenApiDescribedElement { - System.Collections.Generic.IDictionary Content { get; } - System.Collections.Generic.IDictionary Headers { get; } - System.Collections.Generic.IDictionary Links { get; } + System.Collections.Generic.IDictionary? Content { get; } + System.Collections.Generic.IDictionary? Headers { get; } + System.Collections.Generic.IDictionary? Links { get; } } public interface IOpenApiSchema : Microsoft.OpenApi.Interfaces.IOpenApiElement, Microsoft.OpenApi.Interfaces.IOpenApiReadOnlyExtensible, Microsoft.OpenApi.Interfaces.IOpenApiSerializable, Microsoft.OpenApi.Interfaces.IShallowCopyable, Microsoft.OpenApi.Models.Interfaces.IOpenApiDescribedElement { - Microsoft.OpenApi.Models.Interfaces.IOpenApiSchema AdditionalProperties { get; } + Microsoft.OpenApi.Models.Interfaces.IOpenApiSchema? AdditionalProperties { get; } bool AdditionalPropertiesAllowed { get; } - System.Collections.Generic.IList AllOf { get; } - System.Collections.Generic.IDictionary Annotations { get; } - System.Collections.Generic.IList AnyOf { get; } - string Comment { get; } - string Const { get; } - System.Text.Json.Nodes.JsonNode Default { get; } - System.Collections.Generic.IDictionary Definitions { get; } + System.Collections.Generic.IList? AllOf { get; } + System.Collections.Generic.IDictionary? Annotations { get; } + System.Collections.Generic.IList? AnyOf { get; } + string? Comment { get; } + string? Const { get; } + System.Text.Json.Nodes.JsonNode? Default { get; } + System.Collections.Generic.IDictionary? Definitions { get; } bool Deprecated { get; } - Microsoft.OpenApi.Models.OpenApiDiscriminator Discriminator { get; } - string DynamicAnchor { get; } - string DynamicRef { get; } - System.Collections.Generic.IList Enum { get; } - System.Text.Json.Nodes.JsonNode Example { get; } - System.Collections.Generic.IList Examples { get; } + Microsoft.OpenApi.Models.OpenApiDiscriminator? Discriminator { get; } + string? DynamicAnchor { get; } + string? DynamicRef { get; } + System.Collections.Generic.IList? Enum { get; } + System.Text.Json.Nodes.JsonNode? Example { get; } + System.Collections.Generic.IList? Examples { get; } bool? ExclusiveMaximum { get; } bool? ExclusiveMinimum { get; } - Microsoft.OpenApi.Models.OpenApiExternalDocs ExternalDocs { get; } - string Format { get; } - string Id { get; } - Microsoft.OpenApi.Models.Interfaces.IOpenApiSchema Items { get; } + Microsoft.OpenApi.Models.OpenApiExternalDocs? ExternalDocs { get; } + string? Format { get; } + string? Id { get; } + Microsoft.OpenApi.Models.Interfaces.IOpenApiSchema? Items { get; } int? MaxItems { get; } int? MaxLength { get; } int? MaxProperties { get; } @@ -442,44 +442,44 @@ namespace Microsoft.OpenApi.Models.Interfaces int? MinProperties { get; } decimal? Minimum { get; } decimal? MultipleOf { get; } - Microsoft.OpenApi.Models.Interfaces.IOpenApiSchema Not { get; } - System.Collections.Generic.IList OneOf { get; } - string Pattern { get; } - System.Collections.Generic.IDictionary PatternProperties { get; } - System.Collections.Generic.IDictionary Properties { get; } + Microsoft.OpenApi.Models.Interfaces.IOpenApiSchema? Not { get; } + System.Collections.Generic.IList? OneOf { get; } + string? Pattern { get; } + System.Collections.Generic.IDictionary? PatternProperties { get; } + System.Collections.Generic.IDictionary? Properties { get; } bool ReadOnly { get; } - System.Collections.Generic.ISet Required { get; } - string Schema { get; } - string Title { get; } + System.Collections.Generic.ISet? Required { get; } + string? Schema { get; } + string? Title { get; } Microsoft.OpenApi.Models.JsonSchemaType? Type { get; } bool UnEvaluatedProperties { get; } bool UnevaluatedProperties { get; } bool? UniqueItems { get; } - System.Collections.Generic.IDictionary UnrecognizedKeywords { get; } + System.Collections.Generic.IDictionary? UnrecognizedKeywords { get; } decimal? V31ExclusiveMaximum { get; } decimal? V31ExclusiveMinimum { get; } - System.Collections.Generic.IDictionary Vocabulary { get; } + System.Collections.Generic.IDictionary? Vocabulary { get; } bool WriteOnly { get; } - Microsoft.OpenApi.Models.OpenApiXml Xml { get; } + Microsoft.OpenApi.Models.OpenApiXml? Xml { get; } } public interface IOpenApiSecurityScheme : Microsoft.OpenApi.Interfaces.IOpenApiElement, Microsoft.OpenApi.Interfaces.IOpenApiReadOnlyExtensible, Microsoft.OpenApi.Interfaces.IOpenApiSerializable, Microsoft.OpenApi.Interfaces.IShallowCopyable, Microsoft.OpenApi.Models.Interfaces.IOpenApiDescribedElement { - string BearerFormat { get; } - Microsoft.OpenApi.Models.OpenApiOAuthFlows Flows { get; } + string? BearerFormat { get; } + Microsoft.OpenApi.Models.OpenApiOAuthFlows? Flows { get; } Microsoft.OpenApi.Models.ParameterLocation? In { get; } - string Name { get; } - System.Uri OpenIdConnectUrl { get; } - string Scheme { get; } + string? Name { get; } + System.Uri? OpenIdConnectUrl { get; } + string? Scheme { get; } Microsoft.OpenApi.Models.SecuritySchemeType? Type { get; } } public interface IOpenApiSummarizedElement : Microsoft.OpenApi.Interfaces.IOpenApiElement { - string Summary { get; set; } + string? Summary { get; set; } } public interface IOpenApiTag : Microsoft.OpenApi.Interfaces.IOpenApiElement, Microsoft.OpenApi.Interfaces.IOpenApiReadOnlyExtensible, Microsoft.OpenApi.Interfaces.IOpenApiSerializable, Microsoft.OpenApi.Interfaces.IShallowCopyable, Microsoft.OpenApi.Models.Interfaces.IOpenApiReadOnlyDescribedElement { - Microsoft.OpenApi.Models.OpenApiExternalDocs ExternalDocs { get; } - string Name { get; } + Microsoft.OpenApi.Models.OpenApiExternalDocs? ExternalDocs { get; } + string? Name { get; } } } namespace Microsoft.OpenApi.Models @@ -498,8 +498,8 @@ namespace Microsoft.OpenApi.Models public class OpenApiCallback : Microsoft.OpenApi.Interfaces.IOpenApiElement, Microsoft.OpenApi.Interfaces.IOpenApiExtensible, Microsoft.OpenApi.Interfaces.IOpenApiReadOnlyExtensible, Microsoft.OpenApi.Interfaces.IOpenApiReferenceable, Microsoft.OpenApi.Interfaces.IOpenApiSerializable, Microsoft.OpenApi.Interfaces.IShallowCopyable, Microsoft.OpenApi.Models.Interfaces.IOpenApiCallback { public OpenApiCallback() { } - public System.Collections.Generic.IDictionary Extensions { get; set; } - public System.Collections.Generic.Dictionary PathItems { get; set; } + public System.Collections.Generic.IDictionary? Extensions { get; set; } + public System.Collections.Generic.Dictionary? PathItems { get; set; } public void AddPathItem(Microsoft.OpenApi.Expressions.RuntimeExpression expression, Microsoft.OpenApi.Models.Interfaces.IOpenApiPathItem pathItem) { } public Microsoft.OpenApi.Models.Interfaces.IOpenApiCallback CreateShallowCopy() { } public void SerializeAsV2(Microsoft.OpenApi.Writers.IOpenApiWriter writer) { } @@ -686,10 +686,10 @@ namespace Microsoft.OpenApi.Models { public OpenApiContact() { } public OpenApiContact(Microsoft.OpenApi.Models.OpenApiContact contact) { } - public string Email { get; set; } - public System.Collections.Generic.IDictionary Extensions { get; set; } - public string Name { get; set; } - public System.Uri Url { get; set; } + public string? Email { get; set; } + public System.Collections.Generic.IDictionary? Extensions { get; set; } + public string? Name { get; set; } + public System.Uri? Url { get; set; } public void SerializeAsV2(Microsoft.OpenApi.Writers.IOpenApiWriter writer) { } public void SerializeAsV3(Microsoft.OpenApi.Writers.IOpenApiWriter writer) { } public void SerializeAsV31(Microsoft.OpenApi.Writers.IOpenApiWriter writer) { } @@ -698,9 +698,9 @@ namespace Microsoft.OpenApi.Models { public OpenApiDiscriminator() { } public OpenApiDiscriminator(Microsoft.OpenApi.Models.OpenApiDiscriminator discriminator) { } - public System.Collections.Generic.IDictionary Extensions { get; set; } - public System.Collections.Generic.IDictionary Mapping { get; set; } - public string PropertyName { get; set; } + public System.Collections.Generic.IDictionary? Extensions { get; set; } + public System.Collections.Generic.IDictionary? Mapping { get; set; } + public string? PropertyName { get; set; } public void SerializeAsV2(Microsoft.OpenApi.Writers.IOpenApiWriter writer) { } public void SerializeAsV3(Microsoft.OpenApi.Writers.IOpenApiWriter writer) { } public void SerializeAsV31(Microsoft.OpenApi.Writers.IOpenApiWriter writer) { } @@ -739,10 +739,10 @@ namespace Microsoft.OpenApi.Models public OpenApiEncoding() { } public OpenApiEncoding(Microsoft.OpenApi.Models.OpenApiEncoding encoding) { } public bool? AllowReserved { get; set; } - public string ContentType { get; set; } + public string? ContentType { get; set; } public bool? Explode { get; set; } - public System.Collections.Generic.IDictionary Extensions { get; set; } - public System.Collections.Generic.IDictionary Headers { get; set; } + public System.Collections.Generic.IDictionary? Extensions { get; set; } + public System.Collections.Generic.IDictionary? Headers { get; set; } public Microsoft.OpenApi.Models.ParameterStyle? Style { get; set; } public void SerializeAsV2(Microsoft.OpenApi.Writers.IOpenApiWriter writer) { } public void SerializeAsV3(Microsoft.OpenApi.Writers.IOpenApiWriter writer) { } @@ -752,19 +752,19 @@ namespace Microsoft.OpenApi.Models { public OpenApiError(Microsoft.OpenApi.Exceptions.OpenApiException exception) { } public OpenApiError(Microsoft.OpenApi.Models.OpenApiError error) { } - public OpenApiError(string pointer, string message) { } + public OpenApiError(string? pointer, string message) { } public string Message { get; set; } - public string Pointer { get; set; } + public string? Pointer { get; set; } public override string ToString() { } } public class OpenApiExample : Microsoft.OpenApi.Interfaces.IOpenApiElement, Microsoft.OpenApi.Interfaces.IOpenApiExtensible, Microsoft.OpenApi.Interfaces.IOpenApiReadOnlyExtensible, Microsoft.OpenApi.Interfaces.IOpenApiReferenceable, Microsoft.OpenApi.Interfaces.IOpenApiSerializable, Microsoft.OpenApi.Interfaces.IShallowCopyable, Microsoft.OpenApi.Models.Interfaces.IOpenApiDescribedElement, Microsoft.OpenApi.Models.Interfaces.IOpenApiExample, Microsoft.OpenApi.Models.Interfaces.IOpenApiSummarizedElement { public OpenApiExample() { } - public string Description { get; set; } - public System.Collections.Generic.IDictionary Extensions { get; set; } - public string ExternalValue { get; set; } - public string Summary { get; set; } - public System.Text.Json.Nodes.JsonNode Value { get; set; } + public string? Description { get; set; } + public System.Collections.Generic.IDictionary? Extensions { get; set; } + public string? ExternalValue { get; set; } + public string? Summary { get; set; } + public System.Text.Json.Nodes.JsonNode? Value { get; set; } public Microsoft.OpenApi.Models.Interfaces.IOpenApiExample CreateShallowCopy() { } public void SerializeAsV2(Microsoft.OpenApi.Writers.IOpenApiWriter writer) { } public void SerializeAsV3(Microsoft.OpenApi.Writers.IOpenApiWriter writer) { } @@ -774,8 +774,8 @@ namespace Microsoft.OpenApi.Models where T : Microsoft.OpenApi.Interfaces.IOpenApiSerializable { protected OpenApiExtensibleDictionary() { } - protected OpenApiExtensibleDictionary(System.Collections.Generic.Dictionary dictionary, System.Collections.Generic.IDictionary extensions = null) { } - public System.Collections.Generic.IDictionary Extensions { get; set; } + protected OpenApiExtensibleDictionary(System.Collections.Generic.Dictionary? dictionary, System.Collections.Generic.IDictionary? extensions = null) { } + public System.Collections.Generic.IDictionary? Extensions { get; set; } public void SerializeAsV2(Microsoft.OpenApi.Writers.IOpenApiWriter writer) { } public void SerializeAsV3(Microsoft.OpenApi.Writers.IOpenApiWriter writer) { } public void SerializeAsV31(Microsoft.OpenApi.Writers.IOpenApiWriter writer) { } @@ -784,9 +784,9 @@ namespace Microsoft.OpenApi.Models { public OpenApiExternalDocs() { } public OpenApiExternalDocs(Microsoft.OpenApi.Models.OpenApiExternalDocs externalDocs) { } - public string Description { get; set; } - public System.Collections.Generic.IDictionary Extensions { get; set; } - public System.Uri Url { get; set; } + public string? Description { get; set; } + public System.Collections.Generic.IDictionary? Extensions { get; set; } + public System.Uri? Url { get; set; } public void SerializeAsV2(Microsoft.OpenApi.Writers.IOpenApiWriter writer) { } public void SerializeAsV3(Microsoft.OpenApi.Writers.IOpenApiWriter writer) { } public void SerializeAsV31(Microsoft.OpenApi.Writers.IOpenApiWriter writer) { } @@ -796,15 +796,15 @@ namespace Microsoft.OpenApi.Models public OpenApiHeader() { } public bool AllowEmptyValue { get; set; } public bool AllowReserved { get; set; } - public System.Collections.Generic.IDictionary Content { get; set; } + public System.Collections.Generic.IDictionary? Content { get; set; } public bool Deprecated { get; set; } - public string Description { get; set; } - public System.Text.Json.Nodes.JsonNode Example { get; set; } - public System.Collections.Generic.IDictionary Examples { get; set; } + public string? Description { get; set; } + public System.Text.Json.Nodes.JsonNode? Example { get; set; } + public System.Collections.Generic.IDictionary? Examples { get; set; } public bool Explode { get; set; } - public System.Collections.Generic.IDictionary Extensions { get; set; } + public System.Collections.Generic.IDictionary? Extensions { get; set; } public bool Required { get; set; } - public Microsoft.OpenApi.Models.Interfaces.IOpenApiSchema Schema { get; set; } + public Microsoft.OpenApi.Models.Interfaces.IOpenApiSchema? Schema { get; set; } public Microsoft.OpenApi.Models.ParameterStyle? Style { get; set; } public Microsoft.OpenApi.Models.Interfaces.IOpenApiHeader CreateShallowCopy() { } public void SerializeAsV2(Microsoft.OpenApi.Writers.IOpenApiWriter writer) { } @@ -815,14 +815,14 @@ namespace Microsoft.OpenApi.Models { public OpenApiInfo() { } public OpenApiInfo(Microsoft.OpenApi.Models.OpenApiInfo info) { } - public Microsoft.OpenApi.Models.OpenApiContact Contact { get; set; } - public string Description { get; set; } - public System.Collections.Generic.IDictionary Extensions { get; set; } - public Microsoft.OpenApi.Models.OpenApiLicense License { get; set; } - public string Summary { get; set; } - public System.Uri TermsOfService { get; set; } - public string Title { get; set; } - public string Version { get; set; } + public Microsoft.OpenApi.Models.OpenApiContact? Contact { get; set; } + public string? Description { get; set; } + public System.Collections.Generic.IDictionary? Extensions { get; set; } + public Microsoft.OpenApi.Models.OpenApiLicense? License { get; set; } + public string? Summary { get; set; } + public System.Uri? TermsOfService { get; set; } + public string? Title { get; set; } + public string? Version { get; set; } public void SerializeAsV2(Microsoft.OpenApi.Writers.IOpenApiWriter writer) { } public void SerializeAsV3(Microsoft.OpenApi.Writers.IOpenApiWriter writer) { } public void SerializeAsV31(Microsoft.OpenApi.Writers.IOpenApiWriter writer) { } @@ -831,10 +831,10 @@ namespace Microsoft.OpenApi.Models { public OpenApiLicense() { } public OpenApiLicense(Microsoft.OpenApi.Models.OpenApiLicense license) { } - public System.Collections.Generic.IDictionary Extensions { get; set; } - public string Identifier { get; set; } - public string Name { get; set; } - public System.Uri Url { get; set; } + public System.Collections.Generic.IDictionary? Extensions { get; set; } + public string? Identifier { get; set; } + public string? Name { get; set; } + public System.Uri? Url { get; set; } public void SerializeAsV2(Microsoft.OpenApi.Writers.IOpenApiWriter writer) { } public void SerializeAsV3(Microsoft.OpenApi.Writers.IOpenApiWriter writer) { } public void SerializeAsV31(Microsoft.OpenApi.Writers.IOpenApiWriter writer) { } @@ -842,13 +842,13 @@ namespace Microsoft.OpenApi.Models public class OpenApiLink : Microsoft.OpenApi.Interfaces.IOpenApiElement, Microsoft.OpenApi.Interfaces.IOpenApiExtensible, Microsoft.OpenApi.Interfaces.IOpenApiReadOnlyExtensible, Microsoft.OpenApi.Interfaces.IOpenApiReferenceable, Microsoft.OpenApi.Interfaces.IOpenApiSerializable, Microsoft.OpenApi.Interfaces.IShallowCopyable, Microsoft.OpenApi.Models.Interfaces.IOpenApiDescribedElement, Microsoft.OpenApi.Models.Interfaces.IOpenApiLink { public OpenApiLink() { } - public string Description { get; set; } - public System.Collections.Generic.IDictionary Extensions { get; set; } - public string OperationId { get; set; } - public string OperationRef { get; set; } - public System.Collections.Generic.IDictionary Parameters { get; set; } - public Microsoft.OpenApi.Models.RuntimeExpressionAnyWrapper RequestBody { get; set; } - public Microsoft.OpenApi.Models.OpenApiServer Server { get; set; } + public string? Description { get; set; } + public System.Collections.Generic.IDictionary? Extensions { get; set; } + public string? OperationId { get; set; } + public string? OperationRef { get; set; } + public System.Collections.Generic.IDictionary? Parameters { get; set; } + public Microsoft.OpenApi.Models.RuntimeExpressionAnyWrapper? RequestBody { get; set; } + public Microsoft.OpenApi.Models.OpenApiServer? Server { get; set; } public Microsoft.OpenApi.Models.Interfaces.IOpenApiLink CreateShallowCopy() { } public void SerializeAsV2(Microsoft.OpenApi.Writers.IOpenApiWriter writer) { } public void SerializeAsV3(Microsoft.OpenApi.Writers.IOpenApiWriter writer) { } @@ -871,11 +871,11 @@ namespace Microsoft.OpenApi.Models { public OpenApiOAuthFlow() { } public OpenApiOAuthFlow(Microsoft.OpenApi.Models.OpenApiOAuthFlow oAuthFlow) { } - public System.Uri AuthorizationUrl { get; set; } - public System.Collections.Generic.IDictionary Extensions { get; set; } - public System.Uri RefreshUrl { get; set; } - public System.Collections.Generic.IDictionary Scopes { get; set; } - public System.Uri TokenUrl { get; set; } + public System.Uri? AuthorizationUrl { get; set; } + public System.Collections.Generic.IDictionary? Extensions { get; set; } + public System.Uri? RefreshUrl { get; set; } + public System.Collections.Generic.IDictionary? Scopes { get; set; } + public System.Uri? TokenUrl { get; set; } public void SerializeAsV2(Microsoft.OpenApi.Writers.IOpenApiWriter writer) { } public void SerializeAsV3(Microsoft.OpenApi.Writers.IOpenApiWriter writer) { } public void SerializeAsV31(Microsoft.OpenApi.Writers.IOpenApiWriter writer) { } @@ -884,11 +884,11 @@ namespace Microsoft.OpenApi.Models { public OpenApiOAuthFlows() { } public OpenApiOAuthFlows(Microsoft.OpenApi.Models.OpenApiOAuthFlows oAuthFlows) { } - public Microsoft.OpenApi.Models.OpenApiOAuthFlow AuthorizationCode { get; set; } - public Microsoft.OpenApi.Models.OpenApiOAuthFlow ClientCredentials { get; set; } - public System.Collections.Generic.IDictionary Extensions { get; set; } - public Microsoft.OpenApi.Models.OpenApiOAuthFlow Implicit { get; set; } - public Microsoft.OpenApi.Models.OpenApiOAuthFlow Password { get; set; } + public Microsoft.OpenApi.Models.OpenApiOAuthFlow? AuthorizationCode { get; set; } + public Microsoft.OpenApi.Models.OpenApiOAuthFlow? ClientCredentials { get; set; } + public System.Collections.Generic.IDictionary? Extensions { get; set; } + public Microsoft.OpenApi.Models.OpenApiOAuthFlow? Implicit { get; set; } + public Microsoft.OpenApi.Models.OpenApiOAuthFlow? Password { get; set; } public void SerializeAsV2(Microsoft.OpenApi.Writers.IOpenApiWriter writer) { } public void SerializeAsV3(Microsoft.OpenApi.Writers.IOpenApiWriter writer) { } public void SerializeAsV31(Microsoft.OpenApi.Writers.IOpenApiWriter writer) { } @@ -921,17 +921,17 @@ namespace Microsoft.OpenApi.Models public OpenApiParameter() { } public bool AllowEmptyValue { get; set; } public bool AllowReserved { get; set; } - public System.Collections.Generic.IDictionary Content { get; set; } + public System.Collections.Generic.IDictionary? Content { get; set; } public bool Deprecated { get; set; } - public string Description { get; set; } - public System.Text.Json.Nodes.JsonNode Example { get; set; } - public System.Collections.Generic.IDictionary Examples { get; set; } + public string? Description { get; set; } + public System.Text.Json.Nodes.JsonNode? Example { get; set; } + public System.Collections.Generic.IDictionary? Examples { get; set; } public bool Explode { get; set; } - public System.Collections.Generic.IDictionary Extensions { get; set; } + public System.Collections.Generic.IDictionary? Extensions { get; set; } public Microsoft.OpenApi.Models.ParameterLocation? In { get; set; } - public string Name { get; set; } + public string? Name { get; set; } public bool Required { get; set; } - public Microsoft.OpenApi.Models.Interfaces.IOpenApiSchema Schema { get; set; } + public Microsoft.OpenApi.Models.Interfaces.IOpenApiSchema? Schema { get; set; } public Microsoft.OpenApi.Models.ParameterStyle? Style { get; set; } public Microsoft.OpenApi.Models.Interfaces.IOpenApiParameter CreateShallowCopy() { } public void SerializeAsV2(Microsoft.OpenApi.Writers.IOpenApiWriter writer) { } @@ -941,12 +941,12 @@ namespace Microsoft.OpenApi.Models public class OpenApiPathItem : Microsoft.OpenApi.Interfaces.IOpenApiElement, Microsoft.OpenApi.Interfaces.IOpenApiExtensible, Microsoft.OpenApi.Interfaces.IOpenApiReadOnlyExtensible, Microsoft.OpenApi.Interfaces.IOpenApiReferenceable, Microsoft.OpenApi.Interfaces.IOpenApiSerializable, Microsoft.OpenApi.Interfaces.IShallowCopyable, Microsoft.OpenApi.Models.Interfaces.IOpenApiDescribedElement, Microsoft.OpenApi.Models.Interfaces.IOpenApiPathItem, Microsoft.OpenApi.Models.Interfaces.IOpenApiSummarizedElement { public OpenApiPathItem() { } - public string Description { get; set; } - public System.Collections.Generic.IDictionary Extensions { get; set; } - public System.Collections.Generic.IDictionary Operations { get; set; } - public System.Collections.Generic.IList Parameters { get; set; } - public System.Collections.Generic.IList Servers { get; set; } - public string Summary { get; set; } + public string? Description { get; set; } + public System.Collections.Generic.IDictionary? Extensions { get; set; } + public System.Collections.Generic.IDictionary? Operations { get; set; } + public System.Collections.Generic.IList? Parameters { get; set; } + public System.Collections.Generic.IList? Servers { get; set; } + public string? Summary { get; set; } public void AddOperation(Microsoft.OpenApi.Models.OperationType operationType, Microsoft.OpenApi.Models.OpenApiOperation operation) { } public Microsoft.OpenApi.Models.Interfaces.IOpenApiPathItem CreateShallowCopy() { } public void SerializeAsV2(Microsoft.OpenApi.Writers.IOpenApiWriter writer) { } @@ -962,16 +962,16 @@ namespace Microsoft.OpenApi.Models { public OpenApiReference() { } public OpenApiReference(Microsoft.OpenApi.Models.OpenApiReference reference) { } - public string Description { get; set; } - public string ExternalResource { get; init; } - public Microsoft.OpenApi.Models.OpenApiDocument HostDocument { get; init; } - public string Id { get; init; } + public string? Description { get; set; } + public string? ExternalResource { get; init; } + public Microsoft.OpenApi.Models.OpenApiDocument? HostDocument { get; init; } + public string? Id { get; init; } public bool IsExternal { get; } public bool IsFragment { get; init; } public bool IsLocal { get; } - public string ReferenceV2 { get; } - public string ReferenceV3 { get; } - public string Summary { get; set; } + public string? ReferenceV2 { get; } + public string? ReferenceV3 { get; } + public string? Summary { get; set; } public Microsoft.OpenApi.Models.ReferenceType? Type { get; init; } public void SerializeAsV2(Microsoft.OpenApi.Writers.IOpenApiWriter writer) { } public void SerializeAsV3(Microsoft.OpenApi.Writers.IOpenApiWriter writer) { } @@ -980,9 +980,9 @@ namespace Microsoft.OpenApi.Models public class OpenApiRequestBody : Microsoft.OpenApi.Interfaces.IOpenApiElement, Microsoft.OpenApi.Interfaces.IOpenApiExtensible, Microsoft.OpenApi.Interfaces.IOpenApiReadOnlyExtensible, Microsoft.OpenApi.Interfaces.IOpenApiReferenceable, Microsoft.OpenApi.Interfaces.IOpenApiSerializable, Microsoft.OpenApi.Interfaces.IShallowCopyable, Microsoft.OpenApi.Models.Interfaces.IOpenApiDescribedElement, Microsoft.OpenApi.Models.Interfaces.IOpenApiRequestBody { public OpenApiRequestBody() { } - public System.Collections.Generic.IDictionary Content { get; set; } - public string Description { get; set; } - public System.Collections.Generic.IDictionary Extensions { get; set; } + public System.Collections.Generic.IDictionary? Content { get; set; } + public string? Description { get; set; } + public System.Collections.Generic.IDictionary? Extensions { get; set; } public bool Required { get; set; } public Microsoft.OpenApi.Models.Interfaces.IOpenApiParameter ConvertToBodyParameter(Microsoft.OpenApi.Writers.IOpenApiWriter writer) { } public System.Collections.Generic.IEnumerable ConvertToFormDataParameters(Microsoft.OpenApi.Writers.IOpenApiWriter writer) { } @@ -994,11 +994,11 @@ namespace Microsoft.OpenApi.Models public class OpenApiResponse : Microsoft.OpenApi.Interfaces.IOpenApiElement, Microsoft.OpenApi.Interfaces.IOpenApiExtensible, Microsoft.OpenApi.Interfaces.IOpenApiReadOnlyExtensible, Microsoft.OpenApi.Interfaces.IOpenApiReferenceable, Microsoft.OpenApi.Interfaces.IOpenApiSerializable, Microsoft.OpenApi.Interfaces.IShallowCopyable, Microsoft.OpenApi.Models.Interfaces.IOpenApiDescribedElement, Microsoft.OpenApi.Models.Interfaces.IOpenApiResponse { public OpenApiResponse() { } - public System.Collections.Generic.IDictionary Content { get; set; } - public string Description { get; set; } - public System.Collections.Generic.IDictionary Extensions { get; set; } - public System.Collections.Generic.IDictionary Headers { get; set; } - public System.Collections.Generic.IDictionary Links { get; set; } + public System.Collections.Generic.IDictionary? Content { get; set; } + public string? Description { get; set; } + public System.Collections.Generic.IDictionary? Extensions { get; set; } + public System.Collections.Generic.IDictionary? Headers { get; set; } + public System.Collections.Generic.IDictionary? Links { get; set; } public Microsoft.OpenApi.Models.Interfaces.IOpenApiResponse CreateShallowCopy() { } public void SerializeAsV2(Microsoft.OpenApi.Writers.IOpenApiWriter writer) { } public void SerializeAsV3(Microsoft.OpenApi.Writers.IOpenApiWriter writer) { } @@ -1012,30 +1012,30 @@ namespace Microsoft.OpenApi.Models public class OpenApiSchema : Microsoft.OpenApi.Interfaces.IOpenApiElement, Microsoft.OpenApi.Interfaces.IOpenApiExtensible, Microsoft.OpenApi.Interfaces.IOpenApiReadOnlyExtensible, Microsoft.OpenApi.Interfaces.IOpenApiReferenceable, Microsoft.OpenApi.Interfaces.IOpenApiSerializable, Microsoft.OpenApi.Interfaces.IShallowCopyable, Microsoft.OpenApi.Models.Interfaces.IOpenApiDescribedElement, Microsoft.OpenApi.Models.Interfaces.IOpenApiSchema { public OpenApiSchema() { } - public Microsoft.OpenApi.Models.Interfaces.IOpenApiSchema AdditionalProperties { get; set; } + public Microsoft.OpenApi.Models.Interfaces.IOpenApiSchema? AdditionalProperties { get; set; } public bool AdditionalPropertiesAllowed { get; set; } - public System.Collections.Generic.IList AllOf { get; set; } - public System.Collections.Generic.IDictionary Annotations { get; set; } - public System.Collections.Generic.IList AnyOf { get; set; } - public string Comment { get; set; } - public string Const { get; set; } - public System.Text.Json.Nodes.JsonNode Default { get; set; } - public System.Collections.Generic.IDictionary Definitions { get; set; } + public System.Collections.Generic.IList? AllOf { get; set; } + public System.Collections.Generic.IDictionary? Annotations { get; set; } + public System.Collections.Generic.IList? AnyOf { get; set; } + public string? Comment { get; set; } + public string? Const { get; set; } + public System.Text.Json.Nodes.JsonNode? Default { get; set; } + public System.Collections.Generic.IDictionary? Definitions { get; set; } public bool Deprecated { get; set; } - public string Description { get; set; } - public Microsoft.OpenApi.Models.OpenApiDiscriminator Discriminator { get; set; } - public string DynamicAnchor { get; set; } - public string DynamicRef { get; set; } - public System.Collections.Generic.IList Enum { get; set; } - public System.Text.Json.Nodes.JsonNode Example { get; set; } - public System.Collections.Generic.IList Examples { get; set; } + public string? Description { get; set; } + public Microsoft.OpenApi.Models.OpenApiDiscriminator? Discriminator { get; set; } + public string? DynamicAnchor { get; set; } + public string? DynamicRef { get; set; } + public System.Collections.Generic.IList? Enum { get; set; } + public System.Text.Json.Nodes.JsonNode? Example { get; set; } + public System.Collections.Generic.IList? Examples { get; set; } public bool? ExclusiveMaximum { get; set; } public bool? ExclusiveMinimum { get; set; } - public System.Collections.Generic.IDictionary Extensions { get; set; } - public Microsoft.OpenApi.Models.OpenApiExternalDocs ExternalDocs { get; set; } - public string Format { get; set; } - public string Id { get; set; } - public Microsoft.OpenApi.Models.Interfaces.IOpenApiSchema Items { get; set; } + public System.Collections.Generic.IDictionary? Extensions { get; set; } + public Microsoft.OpenApi.Models.OpenApiExternalDocs? ExternalDocs { get; set; } + public string? Format { get; set; } + public string? Id { get; set; } + public Microsoft.OpenApi.Models.Interfaces.IOpenApiSchema? Items { get; set; } public int? MaxItems { get; set; } public int? MaxLength { get; set; } public int? MaxProperties { get; set; } @@ -1045,25 +1045,25 @@ namespace Microsoft.OpenApi.Models public int? MinProperties { get; set; } public decimal? Minimum { get; set; } public decimal? MultipleOf { get; set; } - public Microsoft.OpenApi.Models.Interfaces.IOpenApiSchema Not { get; set; } - public System.Collections.Generic.IList OneOf { get; set; } - public string Pattern { get; set; } - public System.Collections.Generic.IDictionary PatternProperties { get; set; } - public System.Collections.Generic.IDictionary Properties { get; set; } + public Microsoft.OpenApi.Models.Interfaces.IOpenApiSchema? Not { get; set; } + public System.Collections.Generic.IList? OneOf { get; set; } + public string? Pattern { get; set; } + public System.Collections.Generic.IDictionary? PatternProperties { get; set; } + public System.Collections.Generic.IDictionary? Properties { get; set; } public bool ReadOnly { get; set; } - public System.Collections.Generic.ISet Required { get; set; } - public string Schema { get; set; } - public string Title { get; set; } + public System.Collections.Generic.ISet? Required { get; set; } + public string? Schema { get; set; } + public string? Title { get; set; } public Microsoft.OpenApi.Models.JsonSchemaType? Type { get; set; } public bool UnEvaluatedProperties { get; set; } public bool UnevaluatedProperties { get; set; } public bool? UniqueItems { get; set; } - public System.Collections.Generic.IDictionary UnrecognizedKeywords { get; set; } + public System.Collections.Generic.IDictionary? UnrecognizedKeywords { get; set; } public decimal? V31ExclusiveMaximum { get; set; } public decimal? V31ExclusiveMinimum { get; set; } - public System.Collections.Generic.IDictionary Vocabulary { get; set; } + public System.Collections.Generic.IDictionary? Vocabulary { get; set; } public bool WriteOnly { get; set; } - public Microsoft.OpenApi.Models.OpenApiXml Xml { get; set; } + public Microsoft.OpenApi.Models.OpenApiXml? Xml { get; set; } public Microsoft.OpenApi.Models.Interfaces.IOpenApiSchema CreateShallowCopy() { } public void SerializeAsV2(Microsoft.OpenApi.Writers.IOpenApiWriter writer) { } public void SerializeAsV3(Microsoft.OpenApi.Writers.IOpenApiWriter writer) { } @@ -1079,14 +1079,14 @@ namespace Microsoft.OpenApi.Models public class OpenApiSecurityScheme : Microsoft.OpenApi.Interfaces.IOpenApiElement, Microsoft.OpenApi.Interfaces.IOpenApiExtensible, Microsoft.OpenApi.Interfaces.IOpenApiReadOnlyExtensible, Microsoft.OpenApi.Interfaces.IOpenApiReferenceable, Microsoft.OpenApi.Interfaces.IOpenApiSerializable, Microsoft.OpenApi.Interfaces.IShallowCopyable, Microsoft.OpenApi.Models.Interfaces.IOpenApiDescribedElement, Microsoft.OpenApi.Models.Interfaces.IOpenApiSecurityScheme { public OpenApiSecurityScheme() { } - public string BearerFormat { get; set; } - public string Description { get; set; } - public System.Collections.Generic.IDictionary Extensions { get; set; } - public Microsoft.OpenApi.Models.OpenApiOAuthFlows Flows { get; set; } + public string? BearerFormat { get; set; } + public string? Description { get; set; } + public System.Collections.Generic.IDictionary? Extensions { get; set; } + public Microsoft.OpenApi.Models.OpenApiOAuthFlows? Flows { get; set; } public Microsoft.OpenApi.Models.ParameterLocation? In { get; set; } - public string Name { get; set; } - public System.Uri OpenIdConnectUrl { get; set; } - public string Scheme { get; set; } + public string? Name { get; set; } + public System.Uri? OpenIdConnectUrl { get; set; } + public string? Scheme { get; set; } public Microsoft.OpenApi.Models.SecuritySchemeType? Type { get; set; } public Microsoft.OpenApi.Models.Interfaces.IOpenApiSecurityScheme CreateShallowCopy() { } public void SerializeAsV2(Microsoft.OpenApi.Writers.IOpenApiWriter writer) { } @@ -1097,10 +1097,10 @@ namespace Microsoft.OpenApi.Models { public OpenApiServer() { } public OpenApiServer(Microsoft.OpenApi.Models.OpenApiServer server) { } - public string Description { get; set; } - public System.Collections.Generic.IDictionary Extensions { get; set; } - public string Url { get; set; } - public System.Collections.Generic.IDictionary Variables { get; set; } + public string? Description { get; set; } + public System.Collections.Generic.IDictionary? Extensions { get; set; } + public string? Url { get; set; } + public System.Collections.Generic.IDictionary? Variables { get; set; } public void SerializeAsV2(Microsoft.OpenApi.Writers.IOpenApiWriter writer) { } public void SerializeAsV3(Microsoft.OpenApi.Writers.IOpenApiWriter writer) { } public void SerializeAsV31(Microsoft.OpenApi.Writers.IOpenApiWriter writer) { } @@ -1109,10 +1109,10 @@ namespace Microsoft.OpenApi.Models { public OpenApiServerVariable() { } public OpenApiServerVariable(Microsoft.OpenApi.Models.OpenApiServerVariable serverVariable) { } - public string Default { get; set; } - public string Description { get; set; } - public System.Collections.Generic.List Enum { get; set; } - public System.Collections.Generic.IDictionary Extensions { get; set; } + public string? Default { get; set; } + public string? Description { get; set; } + public System.Collections.Generic.List? Enum { get; set; } + public System.Collections.Generic.IDictionary? Extensions { get; set; } public void SerializeAsV2(Microsoft.OpenApi.Writers.IOpenApiWriter writer) { } public void SerializeAsV3(Microsoft.OpenApi.Writers.IOpenApiWriter writer) { } public void SerializeAsV31(Microsoft.OpenApi.Writers.IOpenApiWriter writer) { } @@ -1120,10 +1120,10 @@ namespace Microsoft.OpenApi.Models public class OpenApiTag : Microsoft.OpenApi.Interfaces.IOpenApiElement, Microsoft.OpenApi.Interfaces.IOpenApiExtensible, Microsoft.OpenApi.Interfaces.IOpenApiReadOnlyExtensible, Microsoft.OpenApi.Interfaces.IOpenApiReferenceable, Microsoft.OpenApi.Interfaces.IOpenApiSerializable, Microsoft.OpenApi.Interfaces.IShallowCopyable, Microsoft.OpenApi.Models.Interfaces.IOpenApiDescribedElement, Microsoft.OpenApi.Models.Interfaces.IOpenApiReadOnlyDescribedElement, Microsoft.OpenApi.Models.Interfaces.IOpenApiTag { public OpenApiTag() { } - public string Description { get; set; } - public System.Collections.Generic.IDictionary Extensions { get; set; } - public Microsoft.OpenApi.Models.OpenApiExternalDocs ExternalDocs { get; set; } - public string Name { get; set; } + public string? Description { get; set; } + public System.Collections.Generic.IDictionary? Extensions { get; set; } + public Microsoft.OpenApi.Models.OpenApiExternalDocs? ExternalDocs { get; set; } + public string? Name { get; set; } public Microsoft.OpenApi.Models.Interfaces.IOpenApiTag CreateShallowCopy() { } public void SerializeAsV2(Microsoft.OpenApi.Writers.IOpenApiWriter writer) { } public void SerializeAsV3(Microsoft.OpenApi.Writers.IOpenApiWriter writer) { } @@ -1134,10 +1134,10 @@ namespace Microsoft.OpenApi.Models public OpenApiXml() { } public OpenApiXml(Microsoft.OpenApi.Models.OpenApiXml xml) { } public bool Attribute { get; set; } - public System.Collections.Generic.IDictionary Extensions { get; set; } - public string Name { get; set; } - public System.Uri Namespace { get; set; } - public string Prefix { get; set; } + public System.Collections.Generic.IDictionary? Extensions { get; set; } + public string? Name { get; set; } + public System.Uri? Namespace { get; set; } + public string? Prefix { get; set; } public bool Wrapped { get; set; } public void SerializeAsV2(Microsoft.OpenApi.Writers.IOpenApiWriter writer) { } public void SerializeAsV3(Microsoft.OpenApi.Writers.IOpenApiWriter writer) { } @@ -1219,8 +1219,8 @@ namespace Microsoft.OpenApi.Models { public RuntimeExpressionAnyWrapper() { } public RuntimeExpressionAnyWrapper(Microsoft.OpenApi.Models.RuntimeExpressionAnyWrapper runtimeExpressionAnyWrapper) { } - public System.Text.Json.Nodes.JsonNode Any { get; set; } - public Microsoft.OpenApi.Expressions.RuntimeExpression Expression { get; set; } + public System.Text.Json.Nodes.JsonNode? Any { get; set; } + public Microsoft.OpenApi.Expressions.RuntimeExpression? Expression { get; set; } public void WriteValue(Microsoft.OpenApi.Writers.IOpenApiWriter writer) { } } public enum SecuritySchemeType @@ -1242,152 +1242,152 @@ namespace Microsoft.OpenApi.Models.References where V : Microsoft.OpenApi.Interfaces.IOpenApiSerializable { protected BaseOpenApiReferenceHolder(Microsoft.OpenApi.Models.References.BaseOpenApiReferenceHolder source) { } - protected BaseOpenApiReferenceHolder(string referenceId, Microsoft.OpenApi.Models.OpenApiDocument hostDocument, Microsoft.OpenApi.Models.ReferenceType referenceType, string externalResource) { } - public Microsoft.OpenApi.Models.OpenApiReference Reference { get; init; } + protected BaseOpenApiReferenceHolder(string? referenceId, Microsoft.OpenApi.Models.OpenApiDocument? hostDocument, Microsoft.OpenApi.Models.ReferenceType referenceType, string? externalResource) { } + public Microsoft.OpenApi.Models.OpenApiReference? Reference { get; init; } public virtual T Target { get; } public bool UnresolvedReference { get; } - public abstract V CopyReferenceAsTargetElementWithOverrides(V source); + public abstract V? CopyReferenceAsTargetElementWithOverrides(V? source); public virtual void SerializeAsV2(Microsoft.OpenApi.Writers.IOpenApiWriter writer) { } public virtual void SerializeAsV3(Microsoft.OpenApi.Writers.IOpenApiWriter writer) { } public virtual void SerializeAsV31(Microsoft.OpenApi.Writers.IOpenApiWriter writer) { } } public class OpenApiCallbackReference : Microsoft.OpenApi.Models.References.BaseOpenApiReferenceHolder, Microsoft.OpenApi.Interfaces.IOpenApiElement, Microsoft.OpenApi.Interfaces.IOpenApiReadOnlyExtensible, Microsoft.OpenApi.Interfaces.IOpenApiSerializable, Microsoft.OpenApi.Interfaces.IShallowCopyable, Microsoft.OpenApi.Models.Interfaces.IOpenApiCallback { - public OpenApiCallbackReference(string referenceId, Microsoft.OpenApi.Models.OpenApiDocument hostDocument = null, string externalResource = null) { } - public System.Collections.Generic.IDictionary Extensions { get; } - public System.Collections.Generic.Dictionary PathItems { get; } - public override Microsoft.OpenApi.Models.Interfaces.IOpenApiCallback CopyReferenceAsTargetElementWithOverrides(Microsoft.OpenApi.Models.Interfaces.IOpenApiCallback source) { } + public OpenApiCallbackReference(string referenceId, Microsoft.OpenApi.Models.OpenApiDocument? hostDocument = null, string? externalResource = null) { } + public System.Collections.Generic.IDictionary? Extensions { get; } + public System.Collections.Generic.Dictionary? PathItems { get; } + public override Microsoft.OpenApi.Models.Interfaces.IOpenApiCallback? CopyReferenceAsTargetElementWithOverrides(Microsoft.OpenApi.Models.Interfaces.IOpenApiCallback? source) { } public Microsoft.OpenApi.Models.Interfaces.IOpenApiCallback CreateShallowCopy() { } public override void SerializeAsV2(Microsoft.OpenApi.Writers.IOpenApiWriter writer) { } } public class OpenApiExampleReference : Microsoft.OpenApi.Models.References.BaseOpenApiReferenceHolder, Microsoft.OpenApi.Interfaces.IOpenApiElement, Microsoft.OpenApi.Interfaces.IOpenApiReadOnlyExtensible, Microsoft.OpenApi.Interfaces.IOpenApiSerializable, Microsoft.OpenApi.Interfaces.IShallowCopyable, Microsoft.OpenApi.Models.Interfaces.IOpenApiDescribedElement, Microsoft.OpenApi.Models.Interfaces.IOpenApiExample, Microsoft.OpenApi.Models.Interfaces.IOpenApiSummarizedElement { - public OpenApiExampleReference(string referenceId, Microsoft.OpenApi.Models.OpenApiDocument hostDocument = null, string externalResource = null) { } - public string Description { get; set; } - public System.Collections.Generic.IDictionary Extensions { get; } - public string ExternalValue { get; } - public string Summary { get; set; } - public System.Text.Json.Nodes.JsonNode Value { get; } - public override Microsoft.OpenApi.Models.Interfaces.IOpenApiExample CopyReferenceAsTargetElementWithOverrides(Microsoft.OpenApi.Models.Interfaces.IOpenApiExample source) { } + public OpenApiExampleReference(string referenceId, Microsoft.OpenApi.Models.OpenApiDocument? hostDocument = null, string? externalResource = null) { } + public string? Description { get; set; } + public System.Collections.Generic.IDictionary? Extensions { get; } + public string? ExternalValue { get; } + public string? Summary { get; set; } + public System.Text.Json.Nodes.JsonNode? Value { get; } + public override Microsoft.OpenApi.Models.Interfaces.IOpenApiExample? CopyReferenceAsTargetElementWithOverrides(Microsoft.OpenApi.Models.Interfaces.IOpenApiExample? source) { } public Microsoft.OpenApi.Models.Interfaces.IOpenApiExample CreateShallowCopy() { } public override void SerializeAsV2(Microsoft.OpenApi.Writers.IOpenApiWriter writer) { } } public class OpenApiHeaderReference : Microsoft.OpenApi.Models.References.BaseOpenApiReferenceHolder, Microsoft.OpenApi.Interfaces.IOpenApiElement, Microsoft.OpenApi.Interfaces.IOpenApiReadOnlyExtensible, Microsoft.OpenApi.Interfaces.IOpenApiSerializable, Microsoft.OpenApi.Interfaces.IShallowCopyable, Microsoft.OpenApi.Models.Interfaces.IOpenApiDescribedElement, Microsoft.OpenApi.Models.Interfaces.IOpenApiHeader { - public OpenApiHeaderReference(string referenceId, Microsoft.OpenApi.Models.OpenApiDocument hostDocument = null, string externalResource = null) { } + public OpenApiHeaderReference(string referenceId, Microsoft.OpenApi.Models.OpenApiDocument? hostDocument = null, string? externalResource = null) { } public bool AllowEmptyValue { get; } public bool AllowReserved { get; } - public System.Collections.Generic.IDictionary Content { get; } + public System.Collections.Generic.IDictionary? Content { get; } public bool Deprecated { get; } - public string Description { get; set; } - public System.Text.Json.Nodes.JsonNode Example { get; } - public System.Collections.Generic.IDictionary Examples { get; } + public string? Description { get; set; } + public System.Text.Json.Nodes.JsonNode? Example { get; } + public System.Collections.Generic.IDictionary? Examples { get; } public bool Explode { get; } - public System.Collections.Generic.IDictionary Extensions { get; } + public System.Collections.Generic.IDictionary? Extensions { get; } public bool Required { get; } - public Microsoft.OpenApi.Models.Interfaces.IOpenApiSchema Schema { get; } + public Microsoft.OpenApi.Models.Interfaces.IOpenApiSchema? Schema { get; } public Microsoft.OpenApi.Models.ParameterStyle? Style { get; } - public override Microsoft.OpenApi.Models.Interfaces.IOpenApiHeader CopyReferenceAsTargetElementWithOverrides(Microsoft.OpenApi.Models.Interfaces.IOpenApiHeader source) { } + public override Microsoft.OpenApi.Models.Interfaces.IOpenApiHeader? CopyReferenceAsTargetElementWithOverrides(Microsoft.OpenApi.Models.Interfaces.IOpenApiHeader? source) { } public Microsoft.OpenApi.Models.Interfaces.IOpenApiHeader CreateShallowCopy() { } } public class OpenApiLinkReference : Microsoft.OpenApi.Models.References.BaseOpenApiReferenceHolder, Microsoft.OpenApi.Interfaces.IOpenApiElement, Microsoft.OpenApi.Interfaces.IOpenApiReadOnlyExtensible, Microsoft.OpenApi.Interfaces.IOpenApiSerializable, Microsoft.OpenApi.Interfaces.IShallowCopyable, Microsoft.OpenApi.Models.Interfaces.IOpenApiDescribedElement, Microsoft.OpenApi.Models.Interfaces.IOpenApiLink { - public OpenApiLinkReference(string referenceId, Microsoft.OpenApi.Models.OpenApiDocument hostDocument = null, string externalResource = null) { } - public string Description { get; set; } - public System.Collections.Generic.IDictionary Extensions { get; } - public string OperationId { get; } - public string OperationRef { get; } - public System.Collections.Generic.IDictionary Parameters { get; } - public Microsoft.OpenApi.Models.RuntimeExpressionAnyWrapper RequestBody { get; } - public Microsoft.OpenApi.Models.OpenApiServer Server { get; } - public override Microsoft.OpenApi.Models.Interfaces.IOpenApiLink CopyReferenceAsTargetElementWithOverrides(Microsoft.OpenApi.Models.Interfaces.IOpenApiLink source) { } + public OpenApiLinkReference(string referenceId, Microsoft.OpenApi.Models.OpenApiDocument? hostDocument = null, string? externalResource = null) { } + public string? Description { get; set; } + public System.Collections.Generic.IDictionary? Extensions { get; } + public string? OperationId { get; } + public string? OperationRef { get; } + public System.Collections.Generic.IDictionary? Parameters { get; } + public Microsoft.OpenApi.Models.RuntimeExpressionAnyWrapper? RequestBody { get; } + public Microsoft.OpenApi.Models.OpenApiServer? Server { get; } + public override Microsoft.OpenApi.Models.Interfaces.IOpenApiLink? CopyReferenceAsTargetElementWithOverrides(Microsoft.OpenApi.Models.Interfaces.IOpenApiLink? source) { } public Microsoft.OpenApi.Models.Interfaces.IOpenApiLink CreateShallowCopy() { } public override void SerializeAsV2(Microsoft.OpenApi.Writers.IOpenApiWriter writer) { } } public class OpenApiParameterReference : Microsoft.OpenApi.Models.References.BaseOpenApiReferenceHolder, Microsoft.OpenApi.Interfaces.IOpenApiElement, Microsoft.OpenApi.Interfaces.IOpenApiReadOnlyExtensible, Microsoft.OpenApi.Interfaces.IOpenApiSerializable, Microsoft.OpenApi.Interfaces.IShallowCopyable, Microsoft.OpenApi.Models.Interfaces.IOpenApiDescribedElement, Microsoft.OpenApi.Models.Interfaces.IOpenApiParameter { - public OpenApiParameterReference(string referenceId, Microsoft.OpenApi.Models.OpenApiDocument hostDocument = null, string externalResource = null) { } + public OpenApiParameterReference(string? referenceId, Microsoft.OpenApi.Models.OpenApiDocument? hostDocument = null, string? externalResource = null) { } public bool AllowEmptyValue { get; } public bool AllowReserved { get; } - public System.Collections.Generic.IDictionary Content { get; } + public System.Collections.Generic.IDictionary? Content { get; } public bool Deprecated { get; } - public string Description { get; set; } - public System.Text.Json.Nodes.JsonNode Example { get; } - public System.Collections.Generic.IDictionary Examples { get; } + public string? Description { get; set; } + public System.Text.Json.Nodes.JsonNode? Example { get; } + public System.Collections.Generic.IDictionary? Examples { get; } public bool Explode { get; } - public System.Collections.Generic.IDictionary Extensions { get; } + public System.Collections.Generic.IDictionary? Extensions { get; } public Microsoft.OpenApi.Models.ParameterLocation? In { get; } - public string Name { get; } + public string? Name { get; } public bool Required { get; } - public Microsoft.OpenApi.Models.Interfaces.IOpenApiSchema Schema { get; } + public Microsoft.OpenApi.Models.Interfaces.IOpenApiSchema? Schema { get; } public Microsoft.OpenApi.Models.ParameterStyle? Style { get; } - public override Microsoft.OpenApi.Models.Interfaces.IOpenApiParameter CopyReferenceAsTargetElementWithOverrides(Microsoft.OpenApi.Models.Interfaces.IOpenApiParameter source) { } + public override Microsoft.OpenApi.Models.Interfaces.IOpenApiParameter? CopyReferenceAsTargetElementWithOverrides(Microsoft.OpenApi.Models.Interfaces.IOpenApiParameter? source) { } public Microsoft.OpenApi.Models.Interfaces.IOpenApiParameter CreateShallowCopy() { } } public class OpenApiPathItemReference : Microsoft.OpenApi.Models.References.BaseOpenApiReferenceHolder, Microsoft.OpenApi.Interfaces.IOpenApiElement, Microsoft.OpenApi.Interfaces.IOpenApiReadOnlyExtensible, Microsoft.OpenApi.Interfaces.IOpenApiSerializable, Microsoft.OpenApi.Interfaces.IShallowCopyable, Microsoft.OpenApi.Models.Interfaces.IOpenApiDescribedElement, Microsoft.OpenApi.Models.Interfaces.IOpenApiPathItem, Microsoft.OpenApi.Models.Interfaces.IOpenApiSummarizedElement { - public OpenApiPathItemReference(string referenceId, Microsoft.OpenApi.Models.OpenApiDocument hostDocument = null, string externalResource = null) { } - public string Description { get; set; } - public System.Collections.Generic.IDictionary Extensions { get; } - public System.Collections.Generic.IDictionary Operations { get; } - public System.Collections.Generic.IList Parameters { get; } - public System.Collections.Generic.IList Servers { get; } - public string Summary { get; set; } - public override Microsoft.OpenApi.Models.Interfaces.IOpenApiPathItem CopyReferenceAsTargetElementWithOverrides(Microsoft.OpenApi.Models.Interfaces.IOpenApiPathItem source) { } + public OpenApiPathItemReference(string referenceId, Microsoft.OpenApi.Models.OpenApiDocument? hostDocument = null, string? externalResource = null) { } + public string? Description { get; set; } + public System.Collections.Generic.IDictionary? Extensions { get; } + public System.Collections.Generic.IDictionary? Operations { get; } + public System.Collections.Generic.IList? Parameters { get; } + public System.Collections.Generic.IList? Servers { get; } + public string? Summary { get; set; } + public override Microsoft.OpenApi.Models.Interfaces.IOpenApiPathItem? CopyReferenceAsTargetElementWithOverrides(Microsoft.OpenApi.Models.Interfaces.IOpenApiPathItem? source) { } public Microsoft.OpenApi.Models.Interfaces.IOpenApiPathItem CreateShallowCopy() { } public override void SerializeAsV2(Microsoft.OpenApi.Writers.IOpenApiWriter writer) { } } public class OpenApiRequestBodyReference : Microsoft.OpenApi.Models.References.BaseOpenApiReferenceHolder, Microsoft.OpenApi.Interfaces.IOpenApiElement, Microsoft.OpenApi.Interfaces.IOpenApiReadOnlyExtensible, Microsoft.OpenApi.Interfaces.IOpenApiSerializable, Microsoft.OpenApi.Interfaces.IShallowCopyable, Microsoft.OpenApi.Models.Interfaces.IOpenApiDescribedElement, Microsoft.OpenApi.Models.Interfaces.IOpenApiRequestBody { - public OpenApiRequestBodyReference(string referenceId, Microsoft.OpenApi.Models.OpenApiDocument hostDocument = null, string externalResource = null) { } - public System.Collections.Generic.IDictionary Content { get; } - public string Description { get; set; } - public System.Collections.Generic.IDictionary Extensions { get; } + public OpenApiRequestBodyReference(string referenceId, Microsoft.OpenApi.Models.OpenApiDocument? hostDocument = null, string? externalResource = null) { } + public System.Collections.Generic.IDictionary? Content { get; } + public string? Description { get; set; } + public System.Collections.Generic.IDictionary? Extensions { get; } public bool Required { get; } - public Microsoft.OpenApi.Models.Interfaces.IOpenApiParameter ConvertToBodyParameter(Microsoft.OpenApi.Writers.IOpenApiWriter writer) { } - public System.Collections.Generic.IEnumerable ConvertToFormDataParameters(Microsoft.OpenApi.Writers.IOpenApiWriter writer) { } - public override Microsoft.OpenApi.Models.Interfaces.IOpenApiRequestBody CopyReferenceAsTargetElementWithOverrides(Microsoft.OpenApi.Models.Interfaces.IOpenApiRequestBody source) { } + public Microsoft.OpenApi.Models.Interfaces.IOpenApiParameter? ConvertToBodyParameter(Microsoft.OpenApi.Writers.IOpenApiWriter writer) { } + public System.Collections.Generic.IEnumerable? ConvertToFormDataParameters(Microsoft.OpenApi.Writers.IOpenApiWriter writer) { } + public override Microsoft.OpenApi.Models.Interfaces.IOpenApiRequestBody? CopyReferenceAsTargetElementWithOverrides(Microsoft.OpenApi.Models.Interfaces.IOpenApiRequestBody? source) { } public Microsoft.OpenApi.Models.Interfaces.IOpenApiRequestBody CreateShallowCopy() { } public override void SerializeAsV2(Microsoft.OpenApi.Writers.IOpenApiWriter writer) { } } public class OpenApiResponseReference : Microsoft.OpenApi.Models.References.BaseOpenApiReferenceHolder, Microsoft.OpenApi.Interfaces.IOpenApiElement, Microsoft.OpenApi.Interfaces.IOpenApiReadOnlyExtensible, Microsoft.OpenApi.Interfaces.IOpenApiSerializable, Microsoft.OpenApi.Interfaces.IShallowCopyable, Microsoft.OpenApi.Models.Interfaces.IOpenApiDescribedElement, Microsoft.OpenApi.Models.Interfaces.IOpenApiResponse { - public OpenApiResponseReference(string referenceId, Microsoft.OpenApi.Models.OpenApiDocument hostDocument = null, string externalResource = null) { } - public System.Collections.Generic.IDictionary Content { get; } - public string Description { get; set; } - public System.Collections.Generic.IDictionary Extensions { get; } - public System.Collections.Generic.IDictionary Headers { get; } - public System.Collections.Generic.IDictionary Links { get; } - public override Microsoft.OpenApi.Models.Interfaces.IOpenApiResponse CopyReferenceAsTargetElementWithOverrides(Microsoft.OpenApi.Models.Interfaces.IOpenApiResponse source) { } + public OpenApiResponseReference(string referenceId, Microsoft.OpenApi.Models.OpenApiDocument? hostDocument = null, string? externalResource = null) { } + public System.Collections.Generic.IDictionary? Content { get; } + public string? Description { get; set; } + public System.Collections.Generic.IDictionary? Extensions { get; } + public System.Collections.Generic.IDictionary? Headers { get; } + public System.Collections.Generic.IDictionary? Links { get; } + public override Microsoft.OpenApi.Models.Interfaces.IOpenApiResponse? CopyReferenceAsTargetElementWithOverrides(Microsoft.OpenApi.Models.Interfaces.IOpenApiResponse? source) { } public Microsoft.OpenApi.Models.Interfaces.IOpenApiResponse CreateShallowCopy() { } } public class OpenApiSchemaReference : Microsoft.OpenApi.Models.References.BaseOpenApiReferenceHolder, Microsoft.OpenApi.Interfaces.IOpenApiElement, Microsoft.OpenApi.Interfaces.IOpenApiReadOnlyExtensible, Microsoft.OpenApi.Interfaces.IOpenApiSerializable, Microsoft.OpenApi.Interfaces.IShallowCopyable, Microsoft.OpenApi.Models.Interfaces.IOpenApiDescribedElement, Microsoft.OpenApi.Models.Interfaces.IOpenApiSchema { - public OpenApiSchemaReference(string referenceId, Microsoft.OpenApi.Models.OpenApiDocument hostDocument = null, string externalResource = null) { } - public Microsoft.OpenApi.Models.Interfaces.IOpenApiSchema AdditionalProperties { get; } + public OpenApiSchemaReference(string referenceId, Microsoft.OpenApi.Models.OpenApiDocument? hostDocument = null, string? externalResource = null) { } + public Microsoft.OpenApi.Models.Interfaces.IOpenApiSchema? AdditionalProperties { get; } public bool AdditionalPropertiesAllowed { get; } - public System.Collections.Generic.IList AllOf { get; } - public System.Collections.Generic.IDictionary Annotations { get; } - public System.Collections.Generic.IList AnyOf { get; } - public string Comment { get; } - public string Const { get; } - public System.Text.Json.Nodes.JsonNode Default { get; } - public System.Collections.Generic.IDictionary Definitions { get; } + public System.Collections.Generic.IList? AllOf { get; } + public System.Collections.Generic.IDictionary? Annotations { get; } + public System.Collections.Generic.IList? AnyOf { get; } + public string? Comment { get; } + public string? Const { get; } + public System.Text.Json.Nodes.JsonNode? Default { get; } + public System.Collections.Generic.IDictionary? Definitions { get; } public bool Deprecated { get; } - public string Description { get; set; } - public Microsoft.OpenApi.Models.OpenApiDiscriminator Discriminator { get; } - public string DynamicAnchor { get; } - public string DynamicRef { get; } - public System.Collections.Generic.IList Enum { get; } - public System.Text.Json.Nodes.JsonNode Example { get; } - public System.Collections.Generic.IList Examples { get; } + public string? Description { get; set; } + public Microsoft.OpenApi.Models.OpenApiDiscriminator? Discriminator { get; } + public string? DynamicAnchor { get; } + public string? DynamicRef { get; } + public System.Collections.Generic.IList? Enum { get; } + public System.Text.Json.Nodes.JsonNode? Example { get; } + public System.Collections.Generic.IList? Examples { get; } public bool? ExclusiveMaximum { get; } public bool? ExclusiveMinimum { get; } - public System.Collections.Generic.IDictionary Extensions { get; } - public Microsoft.OpenApi.Models.OpenApiExternalDocs ExternalDocs { get; } - public string Format { get; } - public string Id { get; } - public Microsoft.OpenApi.Models.Interfaces.IOpenApiSchema Items { get; } + public System.Collections.Generic.IDictionary? Extensions { get; } + public Microsoft.OpenApi.Models.OpenApiExternalDocs? ExternalDocs { get; } + public string? Format { get; } + public string? Id { get; } + public Microsoft.OpenApi.Models.Interfaces.IOpenApiSchema? Items { get; } public int? MaxItems { get; } public int? MaxLength { get; } public int? MaxProperties { get; } @@ -1397,26 +1397,26 @@ namespace Microsoft.OpenApi.Models.References public int? MinProperties { get; } public decimal? Minimum { get; } public decimal? MultipleOf { get; } - public Microsoft.OpenApi.Models.Interfaces.IOpenApiSchema Not { get; } - public System.Collections.Generic.IList OneOf { get; } - public string Pattern { get; } - public System.Collections.Generic.IDictionary PatternProperties { get; } - public System.Collections.Generic.IDictionary Properties { get; } + public Microsoft.OpenApi.Models.Interfaces.IOpenApiSchema? Not { get; } + public System.Collections.Generic.IList? OneOf { get; } + public string? Pattern { get; } + public System.Collections.Generic.IDictionary? PatternProperties { get; } + public System.Collections.Generic.IDictionary? Properties { get; } public bool ReadOnly { get; } - public System.Collections.Generic.ISet Required { get; } - public string Schema { get; } - public string Title { get; } + public System.Collections.Generic.ISet? Required { get; } + public string? Schema { get; } + public string? Title { get; } public Microsoft.OpenApi.Models.JsonSchemaType? Type { get; } public bool UnEvaluatedProperties { get; } public bool UnevaluatedProperties { get; } public bool? UniqueItems { get; } - public System.Collections.Generic.IDictionary UnrecognizedKeywords { get; } + public System.Collections.Generic.IDictionary? UnrecognizedKeywords { get; } public decimal? V31ExclusiveMaximum { get; } public decimal? V31ExclusiveMinimum { get; } - public System.Collections.Generic.IDictionary Vocabulary { get; } + public System.Collections.Generic.IDictionary? Vocabulary { get; } public bool WriteOnly { get; } - public Microsoft.OpenApi.Models.OpenApiXml Xml { get; } - public override Microsoft.OpenApi.Models.Interfaces.IOpenApiSchema CopyReferenceAsTargetElementWithOverrides(Microsoft.OpenApi.Models.Interfaces.IOpenApiSchema source) { } + public Microsoft.OpenApi.Models.OpenApiXml? Xml { get; } + public override Microsoft.OpenApi.Models.Interfaces.IOpenApiSchema? CopyReferenceAsTargetElementWithOverrides(Microsoft.OpenApi.Models.Interfaces.IOpenApiSchema? source) { } public Microsoft.OpenApi.Models.Interfaces.IOpenApiSchema CreateShallowCopy() { } public override void SerializeAsV2(Microsoft.OpenApi.Writers.IOpenApiWriter writer) { } public override void SerializeAsV3(Microsoft.OpenApi.Writers.IOpenApiWriter writer) { } @@ -1424,28 +1424,28 @@ namespace Microsoft.OpenApi.Models.References } public class OpenApiSecuritySchemeReference : Microsoft.OpenApi.Models.References.BaseOpenApiReferenceHolder, Microsoft.OpenApi.Interfaces.IOpenApiElement, Microsoft.OpenApi.Interfaces.IOpenApiReadOnlyExtensible, Microsoft.OpenApi.Interfaces.IOpenApiSerializable, Microsoft.OpenApi.Interfaces.IShallowCopyable, Microsoft.OpenApi.Models.Interfaces.IOpenApiDescribedElement, Microsoft.OpenApi.Models.Interfaces.IOpenApiSecurityScheme { - public OpenApiSecuritySchemeReference(string referenceId, Microsoft.OpenApi.Models.OpenApiDocument hostDocument = null, string externalResource = null) { } - public string BearerFormat { get; } - public string Description { get; set; } - public System.Collections.Generic.IDictionary Extensions { get; } - public Microsoft.OpenApi.Models.OpenApiOAuthFlows Flows { get; } + public OpenApiSecuritySchemeReference(string referenceId, Microsoft.OpenApi.Models.OpenApiDocument? hostDocument = null, string? externalResource = null) { } + public string? BearerFormat { get; } + public string? Description { get; set; } + public System.Collections.Generic.IDictionary? Extensions { get; } + public Microsoft.OpenApi.Models.OpenApiOAuthFlows? Flows { get; } public Microsoft.OpenApi.Models.ParameterLocation? In { get; } - public string Name { get; } - public System.Uri OpenIdConnectUrl { get; } - public string Scheme { get; } + public string? Name { get; } + public System.Uri? OpenIdConnectUrl { get; } + public string? Scheme { get; } public Microsoft.OpenApi.Models.SecuritySchemeType? Type { get; } - public override Microsoft.OpenApi.Models.Interfaces.IOpenApiSecurityScheme CopyReferenceAsTargetElementWithOverrides(Microsoft.OpenApi.Models.Interfaces.IOpenApiSecurityScheme source) { } + public override Microsoft.OpenApi.Models.Interfaces.IOpenApiSecurityScheme? CopyReferenceAsTargetElementWithOverrides(Microsoft.OpenApi.Models.Interfaces.IOpenApiSecurityScheme? source) { } public Microsoft.OpenApi.Models.Interfaces.IOpenApiSecurityScheme CreateShallowCopy() { } } public class OpenApiTagReference : Microsoft.OpenApi.Models.References.BaseOpenApiReferenceHolder, Microsoft.OpenApi.Interfaces.IOpenApiElement, Microsoft.OpenApi.Interfaces.IOpenApiReadOnlyExtensible, Microsoft.OpenApi.Interfaces.IOpenApiSerializable, Microsoft.OpenApi.Interfaces.IShallowCopyable, Microsoft.OpenApi.Models.Interfaces.IOpenApiReadOnlyDescribedElement, Microsoft.OpenApi.Models.Interfaces.IOpenApiTag { - public OpenApiTagReference(string referenceId, Microsoft.OpenApi.Models.OpenApiDocument hostDocument = null, string externalResource = null) { } - public string Description { get; } - public System.Collections.Generic.IDictionary Extensions { get; } - public Microsoft.OpenApi.Models.OpenApiExternalDocs ExternalDocs { get; } - public string Name { get; } - public override Microsoft.OpenApi.Models.OpenApiTag Target { get; } - public override Microsoft.OpenApi.Models.Interfaces.IOpenApiTag CopyReferenceAsTargetElementWithOverrides(Microsoft.OpenApi.Models.Interfaces.IOpenApiTag source) { } + public OpenApiTagReference(string? referenceId, Microsoft.OpenApi.Models.OpenApiDocument? hostDocument = null, string? externalResource = null) { } + public string? Description { get; } + public System.Collections.Generic.IDictionary? Extensions { get; } + public Microsoft.OpenApi.Models.OpenApiExternalDocs? ExternalDocs { get; } + public string? Name { get; } + public override Microsoft.OpenApi.Models.OpenApiTag? Target { get; } + public override Microsoft.OpenApi.Models.Interfaces.IOpenApiTag? CopyReferenceAsTargetElementWithOverrides(Microsoft.OpenApi.Models.Interfaces.IOpenApiTag? source) { } public Microsoft.OpenApi.Models.Interfaces.IOpenApiTag CreateShallowCopy() { } } } @@ -1457,32 +1457,32 @@ namespace Microsoft.OpenApi.Reader public System.Collections.Generic.IList Errors { get; set; } public Microsoft.OpenApi.OpenApiSpecVersion SpecificationVersion { get; set; } public System.Collections.Generic.IList Warnings { get; set; } - public void AppendDiagnostic(Microsoft.OpenApi.Reader.OpenApiDiagnostic diagnosticToAdd, string fileNameToAdd = null) { } + public void AppendDiagnostic(Microsoft.OpenApi.Reader.OpenApiDiagnostic diagnosticToAdd, string? fileNameToAdd = null) { } } public class OpenApiJsonReader : Microsoft.OpenApi.Interfaces.IOpenApiReader { public OpenApiJsonReader() { } public Microsoft.OpenApi.Reader.ReadResult Read(System.IO.MemoryStream input, Microsoft.OpenApi.Reader.OpenApiReaderSettings settings) { } - public Microsoft.OpenApi.Reader.ReadResult Read(System.Text.Json.Nodes.JsonNode jsonNode, Microsoft.OpenApi.Reader.OpenApiReaderSettings settings) { } + public Microsoft.OpenApi.Reader.ReadResult Read(System.Text.Json.Nodes.JsonNode? jsonNode, Microsoft.OpenApi.Reader.OpenApiReaderSettings settings) { } public System.Threading.Tasks.Task ReadAsync(System.IO.Stream input, Microsoft.OpenApi.Reader.OpenApiReaderSettings settings, System.Threading.CancellationToken cancellationToken = default) { } - public T ReadFragment(System.IO.MemoryStream input, Microsoft.OpenApi.OpenApiSpecVersion version, Microsoft.OpenApi.Models.OpenApiDocument openApiDocument, out Microsoft.OpenApi.Reader.OpenApiDiagnostic diagnostic, Microsoft.OpenApi.Reader.OpenApiReaderSettings settings = null) + public T? ReadFragment(System.IO.MemoryStream input, Microsoft.OpenApi.OpenApiSpecVersion version, Microsoft.OpenApi.Models.OpenApiDocument openApiDocument, out Microsoft.OpenApi.Reader.OpenApiDiagnostic diagnostic, Microsoft.OpenApi.Reader.OpenApiReaderSettings? settings = null) where T : Microsoft.OpenApi.Interfaces.IOpenApiElement { } - public T ReadFragment(System.Text.Json.Nodes.JsonNode input, Microsoft.OpenApi.OpenApiSpecVersion version, Microsoft.OpenApi.Models.OpenApiDocument openApiDocument, out Microsoft.OpenApi.Reader.OpenApiDiagnostic diagnostic, Microsoft.OpenApi.Reader.OpenApiReaderSettings settings = null) + public T ReadFragment(System.Text.Json.Nodes.JsonNode? input, Microsoft.OpenApi.OpenApiSpecVersion version, Microsoft.OpenApi.Models.OpenApiDocument openApiDocument, out Microsoft.OpenApi.Reader.OpenApiDiagnostic diagnostic, Microsoft.OpenApi.Reader.OpenApiReaderSettings? settings = null) where T : Microsoft.OpenApi.Interfaces.IOpenApiElement { } } public static class OpenApiModelFactory { - public static Microsoft.OpenApi.Reader.ReadResult Load(System.IO.MemoryStream stream, string format = null, Microsoft.OpenApi.Reader.OpenApiReaderSettings settings = null) { } - public static T Load(System.IO.MemoryStream input, Microsoft.OpenApi.OpenApiSpecVersion version, string format, Microsoft.OpenApi.Models.OpenApiDocument openApiDocument, out Microsoft.OpenApi.Reader.OpenApiDiagnostic diagnostic, Microsoft.OpenApi.Reader.OpenApiReaderSettings settings = null) + public static Microsoft.OpenApi.Reader.ReadResult Load(System.IO.MemoryStream stream, string? format = null, Microsoft.OpenApi.Reader.OpenApiReaderSettings? settings = null) { } + public static T? Load(System.IO.MemoryStream input, Microsoft.OpenApi.OpenApiSpecVersion version, string? format, Microsoft.OpenApi.Models.OpenApiDocument openApiDocument, out Microsoft.OpenApi.Reader.OpenApiDiagnostic diagnostic, Microsoft.OpenApi.Reader.OpenApiReaderSettings? settings = null) where T : Microsoft.OpenApi.Interfaces.IOpenApiElement { } - public static System.Threading.Tasks.Task LoadAsync(string url, Microsoft.OpenApi.Reader.OpenApiReaderSettings settings = null, System.Threading.CancellationToken token = default) { } - public static System.Threading.Tasks.Task LoadAsync(System.IO.Stream input, string format = null, Microsoft.OpenApi.Reader.OpenApiReaderSettings settings = null, System.Threading.CancellationToken cancellationToken = default) { } - public static System.Threading.Tasks.Task LoadAsync(string url, Microsoft.OpenApi.OpenApiSpecVersion version, Microsoft.OpenApi.Models.OpenApiDocument openApiDocument, Microsoft.OpenApi.Reader.OpenApiReaderSettings settings = null, System.Threading.CancellationToken token = default) + public static System.Threading.Tasks.Task LoadAsync(string url, Microsoft.OpenApi.Reader.OpenApiReaderSettings? settings = null, System.Threading.CancellationToken token = default) { } + public static System.Threading.Tasks.Task LoadAsync(System.IO.Stream input, string? format = null, Microsoft.OpenApi.Reader.OpenApiReaderSettings? settings = null, System.Threading.CancellationToken cancellationToken = default) { } + public static System.Threading.Tasks.Task LoadAsync(string url, Microsoft.OpenApi.OpenApiSpecVersion version, Microsoft.OpenApi.Models.OpenApiDocument openApiDocument, Microsoft.OpenApi.Reader.OpenApiReaderSettings? settings = null, System.Threading.CancellationToken token = default) where T : Microsoft.OpenApi.Interfaces.IOpenApiElement { } - public static System.Threading.Tasks.Task LoadAsync(System.IO.Stream input, Microsoft.OpenApi.OpenApiSpecVersion version, Microsoft.OpenApi.Models.OpenApiDocument openApiDocument, string format = null, Microsoft.OpenApi.Reader.OpenApiReaderSettings settings = null, System.Threading.CancellationToken token = default) + public static System.Threading.Tasks.Task LoadAsync(System.IO.Stream input, Microsoft.OpenApi.OpenApiSpecVersion version, Microsoft.OpenApi.Models.OpenApiDocument openApiDocument, string? format = null, Microsoft.OpenApi.Reader.OpenApiReaderSettings? settings = null, System.Threading.CancellationToken token = default) where T : Microsoft.OpenApi.Interfaces.IOpenApiElement { } - public static Microsoft.OpenApi.Reader.ReadResult Parse(string input, string format = null, Microsoft.OpenApi.Reader.OpenApiReaderSettings settings = null) { } - public static T Parse(string input, Microsoft.OpenApi.OpenApiSpecVersion version, Microsoft.OpenApi.Models.OpenApiDocument openApiDocument, out Microsoft.OpenApi.Reader.OpenApiDiagnostic diagnostic, string format = null, Microsoft.OpenApi.Reader.OpenApiReaderSettings settings = null) + public static Microsoft.OpenApi.Reader.ReadResult Parse(string input, string? format = null, Microsoft.OpenApi.Reader.OpenApiReaderSettings? settings = null) { } + public static T? Parse(string input, Microsoft.OpenApi.OpenApiSpecVersion version, Microsoft.OpenApi.Models.OpenApiDocument openApiDocument, out Microsoft.OpenApi.Reader.OpenApiDiagnostic diagnostic, string? format = null, Microsoft.OpenApi.Reader.OpenApiReaderSettings? settings = null) where T : Microsoft.OpenApi.Interfaces.IOpenApiElement { } } public static class OpenApiReaderRegistry @@ -1494,10 +1494,10 @@ namespace Microsoft.OpenApi.Reader public class OpenApiReaderSettings { public OpenApiReaderSettings() { } - public System.Uri BaseUrl { get; set; } - public Microsoft.OpenApi.Interfaces.IStreamLoader CustomExternalLoader { get; set; } - public System.Collections.Generic.List DefaultContentType { get; set; } - public System.Collections.Generic.Dictionary> ExtensionParsers { get; set; } + public System.Uri? BaseUrl { get; set; } + public Microsoft.OpenApi.Interfaces.IStreamLoader? CustomExternalLoader { get; set; } + public System.Collections.Generic.List? DefaultContentType { get; set; } + public System.Collections.Generic.Dictionary>? ExtensionParsers { get; set; } public bool LeaveStreamOpen { get; set; } public bool LoadExternalRefs { get; set; } public Microsoft.OpenApi.Reader.ReferenceResolutionSetting ReferenceResolution { get; set; } @@ -1513,27 +1513,27 @@ namespace Microsoft.OpenApi.Reader public class ParsingContext { public ParsingContext(Microsoft.OpenApi.Reader.OpenApiDiagnostic diagnostic) { } - public System.Uri BaseUrl { get; set; } - public System.Collections.Generic.List DefaultContentType { get; set; } + public System.Uri? BaseUrl { get; set; } + public System.Collections.Generic.List? DefaultContentType { get; set; } public Microsoft.OpenApi.Reader.OpenApiDiagnostic Diagnostic { get; } - public System.Collections.Generic.Dictionary> ExtensionParsers { get; set; } + public System.Collections.Generic.Dictionary>? ExtensionParsers { get; set; } public void EndObject() { } - public T GetFromTempStorage(string key, object scope = null) { } + public T? GetFromTempStorage(string key, object? scope = null) { } public string GetLocation() { } public Microsoft.OpenApi.Models.OpenApiDocument Parse(System.Text.Json.Nodes.JsonNode jsonNode) { } - public T ParseFragment(System.Text.Json.Nodes.JsonNode jsonNode, Microsoft.OpenApi.OpenApiSpecVersion version, Microsoft.OpenApi.Models.OpenApiDocument openApiDocument) + public T? ParseFragment(System.Text.Json.Nodes.JsonNode? jsonNode, Microsoft.OpenApi.OpenApiSpecVersion version, Microsoft.OpenApi.Models.OpenApiDocument openApiDocument) where T : Microsoft.OpenApi.Interfaces.IOpenApiElement { } public void PopLoop(string loopid) { } public bool PushLoop(string loopId, string key) { } - public void SetTempStorage(string key, object value, object scope = null) { } + public void SetTempStorage(string key, object? value, object? scope = null) { } public void StartObject(string objectName) { } } public class ReadResult { public ReadResult() { } - public Microsoft.OpenApi.Reader.OpenApiDiagnostic Diagnostic { get; set; } - public Microsoft.OpenApi.Models.OpenApiDocument Document { get; set; } - public void Deconstruct(out Microsoft.OpenApi.Models.OpenApiDocument document, out Microsoft.OpenApi.Reader.OpenApiDiagnostic diagnostic) { } + public Microsoft.OpenApi.Reader.OpenApiDiagnostic? Diagnostic { get; set; } + public Microsoft.OpenApi.Models.OpenApiDocument? Document { get; set; } + public void Deconstruct(out Microsoft.OpenApi.Models.OpenApiDocument? document, out Microsoft.OpenApi.Reader.OpenApiDiagnostic? diagnostic) { } } public enum ReferenceResolutionSetting { @@ -1546,7 +1546,7 @@ namespace Microsoft.OpenApi.Reader.ParseNodes { public static class JsonPointerExtensions { - public static System.Text.Json.Nodes.JsonNode Find(this Microsoft.OpenApi.JsonPointer currentPointer, System.Text.Json.Nodes.JsonNode baseJsonNode) { } + public static System.Text.Json.Nodes.JsonNode? Find(this Microsoft.OpenApi.JsonPointer currentPointer, System.Text.Json.Nodes.JsonNode baseJsonNode) { } } } namespace Microsoft.OpenApi.Reader.Services @@ -1562,17 +1562,17 @@ namespace Microsoft.OpenApi.Services public class CurrentKeys { public CurrentKeys() { } - public string Callback { get; set; } - public string Content { get; set; } - public string Encoding { get; } - public string Example { get; } - public string Extension { get; } - public string Header { get; } - public string Link { get; set; } + public string? Callback { get; set; } + public string? Content { get; set; } + public string? Encoding { get; } + public string? Example { get; } + public string? Extension { get; } + public string? Header { get; } + public string? Link { get; set; } public Microsoft.OpenApi.Models.OperationType? Operation { get; set; } - public string Path { get; set; } - public string Response { get; set; } - public string ServerVariable { get; } + public string? Path { get; set; } + public string? Response { get; set; } + public string? ServerVariable { get; } } public enum MermaidNodeShape { @@ -1589,13 +1589,13 @@ namespace Microsoft.OpenApi.Services } public static class OpenApiFilterService { - public static Microsoft.OpenApi.Models.OpenApiDocument CreateFilteredDocument(Microsoft.OpenApi.Models.OpenApiDocument source, System.Func predicate) { } + public static Microsoft.OpenApi.Models.OpenApiDocument CreateFilteredDocument(Microsoft.OpenApi.Models.OpenApiDocument? source, System.Func predicate) { } public static Microsoft.OpenApi.Services.OpenApiUrlTreeNode CreateOpenApiUrlTreeNode(System.Collections.Generic.Dictionary sources) { } - public static System.Func CreatePredicate(string operationIds = null, string tags = null, System.Collections.Generic.Dictionary> requestUrls = null, Microsoft.OpenApi.Models.OpenApiDocument source = null) { } + public static System.Func CreatePredicate(string? operationIds = null, string? tags = null, System.Collections.Generic.Dictionary>? requestUrls = null, Microsoft.OpenApi.Models.OpenApiDocument? source = null) { } } public class OpenApiReferenceError : Microsoft.OpenApi.Models.OpenApiError { - public readonly Microsoft.OpenApi.Models.OpenApiReference Reference; + public readonly Microsoft.OpenApi.Models.OpenApiReference? Reference; public OpenApiReferenceError(Microsoft.OpenApi.Exceptions.OpenApiException exception) { } public OpenApiReferenceError(Microsoft.OpenApi.Models.OpenApiReference reference, string message) { } } @@ -1614,7 +1614,7 @@ namespace Microsoft.OpenApi.Services public bool HasOperations(string label) { } public void WriteMermaid(System.IO.TextWriter writer) { } public static Microsoft.OpenApi.Services.OpenApiUrlTreeNode Create() { } - public static Microsoft.OpenApi.Services.OpenApiUrlTreeNode Create(Microsoft.OpenApi.Models.OpenApiDocument doc, string label) { } + public static Microsoft.OpenApi.Services.OpenApiUrlTreeNode Create(Microsoft.OpenApi.Models.OpenApiDocument? doc, string label) { } } public abstract class OpenApiVisitorBase { @@ -1623,7 +1623,7 @@ namespace Microsoft.OpenApi.Services public string PathString { get; } public virtual void Enter(string segment) { } public virtual void Exit() { } - public virtual void Visit(Microsoft.OpenApi.Interfaces.IOpenApiExtensible openApiExtensible) { } + public virtual void Visit(Microsoft.OpenApi.Interfaces.IOpenApiExtensible? openApiExtensible) { } public virtual void Visit(Microsoft.OpenApi.Interfaces.IOpenApiExtension openApiExtension) { } public virtual void Visit(Microsoft.OpenApi.Interfaces.IOpenApiReferenceHolder referenceHolder) { } public virtual void Visit(Microsoft.OpenApi.Models.Interfaces.IOpenApiCallback callback) { } @@ -1640,7 +1640,7 @@ namespace Microsoft.OpenApi.Services public virtual void Visit(Microsoft.OpenApi.Models.OpenApiContact contact) { } public virtual void Visit(Microsoft.OpenApi.Models.OpenApiDocument doc) { } public virtual void Visit(Microsoft.OpenApi.Models.OpenApiEncoding encoding) { } - public virtual void Visit(Microsoft.OpenApi.Models.OpenApiExternalDocs externalDocs) { } + public virtual void Visit(Microsoft.OpenApi.Models.OpenApiExternalDocs? externalDocs) { } public virtual void Visit(Microsoft.OpenApi.Models.OpenApiInfo info) { } public virtual void Visit(Microsoft.OpenApi.Models.OpenApiLicense license) { } public virtual void Visit(Microsoft.OpenApi.Models.OpenApiMediaType mediaType) { } @@ -1673,18 +1673,18 @@ namespace Microsoft.OpenApi.Services public class OpenApiWalker { public OpenApiWalker(Microsoft.OpenApi.Services.OpenApiVisitorBase visitor) { } - public void Walk(Microsoft.OpenApi.Models.OpenApiDocument doc) { } + public void Walk(Microsoft.OpenApi.Models.OpenApiDocument? doc) { } } public class OpenApiWorkspace { public OpenApiWorkspace() { } public OpenApiWorkspace(Microsoft.OpenApi.Services.OpenApiWorkspace workspace) { } public OpenApiWorkspace(System.Uri baseUrl) { } - public System.Uri BaseUrl { get; } - public void AddDocumentId(string key, System.Uri value) { } + public System.Uri? BaseUrl { get; } + public void AddDocumentId(string? key, System.Uri? value) { } public int ComponentsCount() { } public bool Contains(string location) { } - public System.Uri GetDocumentId(string key) { } + public System.Uri? GetDocumentId(string? key) { } public bool RegisterComponentForDocument(Microsoft.OpenApi.Models.OpenApiDocument openApiDocument, T componentToRegister, string id) { } public void RegisterComponents(Microsoft.OpenApi.Models.OpenApiDocument document) { } public T? ResolveReference(string location) { } @@ -1699,16 +1699,16 @@ namespace Microsoft.OpenApi.Services public class SearchResult { public SearchResult() { } - public Microsoft.OpenApi.Services.CurrentKeys CurrentKeys { get; set; } - public Microsoft.OpenApi.Models.OpenApiOperation Operation { get; set; } - public System.Collections.Generic.IList Parameters { get; set; } + public Microsoft.OpenApi.Services.CurrentKeys? CurrentKeys { get; set; } + public Microsoft.OpenApi.Models.OpenApiOperation? Operation { get; set; } + public System.Collections.Generic.IList? Parameters { get; set; } } } namespace Microsoft.OpenApi.Validations { public interface IValidationContext { - Microsoft.OpenApi.Models.OpenApiDocument HostDocument { get; } + Microsoft.OpenApi.Models.OpenApiDocument? HostDocument { get; } string PathString { get; } void AddError(Microsoft.OpenApi.Validations.OpenApiValidatorError error); void AddWarning(Microsoft.OpenApi.Validations.OpenApiValidatorWarning warning); @@ -1717,13 +1717,13 @@ namespace Microsoft.OpenApi.Validations } public class OpenApiValidator : Microsoft.OpenApi.Services.OpenApiVisitorBase, Microsoft.OpenApi.Validations.IValidationContext { - public OpenApiValidator(Microsoft.OpenApi.Validations.ValidationRuleSet ruleSet, Microsoft.OpenApi.Models.OpenApiDocument hostDocument = null) { } + public OpenApiValidator(Microsoft.OpenApi.Validations.ValidationRuleSet ruleSet, Microsoft.OpenApi.Models.OpenApiDocument? hostDocument = null) { } public System.Collections.Generic.IEnumerable Errors { get; } - public Microsoft.OpenApi.Models.OpenApiDocument HostDocument { get; set; } + public Microsoft.OpenApi.Models.OpenApiDocument? HostDocument { get; set; } public System.Collections.Generic.IEnumerable Warnings { get; } public void AddError(Microsoft.OpenApi.Validations.OpenApiValidatorError error) { } public void AddWarning(Microsoft.OpenApi.Validations.OpenApiValidatorWarning warning) { } - public override void Visit(Microsoft.OpenApi.Interfaces.IOpenApiExtensible openApiExtensible) { } + public override void Visit(Microsoft.OpenApi.Interfaces.IOpenApiExtensible? openApiExtensible) { } public override void Visit(Microsoft.OpenApi.Interfaces.IOpenApiExtension openApiExtension) { } public override void Visit(Microsoft.OpenApi.Models.Interfaces.IOpenApiCallback callback) { } public override void Visit(Microsoft.OpenApi.Models.Interfaces.IOpenApiExample example) { } @@ -1739,7 +1739,7 @@ namespace Microsoft.OpenApi.Validations public override void Visit(Microsoft.OpenApi.Models.OpenApiContact contact) { } public override void Visit(Microsoft.OpenApi.Models.OpenApiDocument doc) { } public override void Visit(Microsoft.OpenApi.Models.OpenApiEncoding encoding) { } - public override void Visit(Microsoft.OpenApi.Models.OpenApiExternalDocs externalDocs) { } + public override void Visit(Microsoft.OpenApi.Models.OpenApiExternalDocs? externalDocs) { } public override void Visit(Microsoft.OpenApi.Models.OpenApiInfo info) { } public override void Visit(Microsoft.OpenApi.Models.OpenApiLicense license) { } public override void Visit(Microsoft.OpenApi.Models.OpenApiMediaType mediaType) { } @@ -1792,13 +1792,13 @@ namespace Microsoft.OpenApi.Validations public void Clear() { } public bool Contains(System.Type key, Microsoft.OpenApi.Validations.ValidationRule rule) { } public bool ContainsKey(System.Type key) { } - public System.Collections.Generic.IList FindRules(System.Type type) { } + public System.Collections.Generic.IList? FindRules(System.Type type) { } public System.Collections.Generic.IEnumerator GetEnumerator() { } public bool Remove(Microsoft.OpenApi.Validations.ValidationRule rule) { } public void Remove(string ruleName) { } public bool Remove(System.Type key) { } public bool Remove(System.Type key, Microsoft.OpenApi.Validations.ValidationRule rule) { } - public bool TryGetValue(System.Type key, out System.Collections.Generic.IList rules) { } + public bool TryGetValue(System.Type key, out System.Collections.Generic.IList? rules) { } public bool Update(System.Type key, Microsoft.OpenApi.Validations.ValidationRule newRule, Microsoft.OpenApi.Validations.ValidationRule oldRule) { } public static void AddValidationRules(Microsoft.OpenApi.Validations.ValidationRuleSet ruleSet, System.Collections.Generic.IDictionary> rules) { } public static Microsoft.OpenApi.Validations.ValidationRuleSet GetDefaultRuleSet() { } @@ -1891,8 +1891,8 @@ namespace Microsoft.OpenApi.Validations.Rules public static class OpenApiSchemaRules { public static Microsoft.OpenApi.Validations.ValidationRule ValidateSchemaDiscriminator { get; } - public static bool TraverseSchemaElements(string discriminatorName, System.Collections.Generic.IList childSchema) { } - public static bool ValidateChildSchemaAgainstDiscriminator(Microsoft.OpenApi.Models.Interfaces.IOpenApiSchema schema, string discriminatorName) { } + public static bool TraverseSchemaElements(string discriminatorName, System.Collections.Generic.IList? childSchema) { } + public static bool ValidateChildSchemaAgainstDiscriminator(Microsoft.OpenApi.Models.Interfaces.IOpenApiSchema schema, string? discriminatorName) { } } [Microsoft.OpenApi.Validations.Rules.OpenApiRule] public static class OpenApiServerRules @@ -1918,7 +1918,7 @@ namespace Microsoft.OpenApi.Writers void WriteEndArray(); void WriteEndObject(); void WriteNull(); - void WritePropertyName(string name); + void WritePropertyName(string? name); void WriteRaw(string value); void WriteStartArray(); void WriteStartObject(); @@ -1926,23 +1926,23 @@ namespace Microsoft.OpenApi.Writers void WriteValue(decimal value); void WriteValue(int value); void WriteValue(object value); - void WriteValue(string value); + void WriteValue(string? value); } public class OpenApiJsonWriter : Microsoft.OpenApi.Writers.OpenApiWriterBase { public OpenApiJsonWriter(System.IO.TextWriter textWriter) { } public OpenApiJsonWriter(System.IO.TextWriter textWriter, Microsoft.OpenApi.Writers.OpenApiJsonWriterSettings settings) { } - public OpenApiJsonWriter(System.IO.TextWriter textWriter, Microsoft.OpenApi.Writers.OpenApiWriterSettings settings, bool terseOutput = false) { } + public OpenApiJsonWriter(System.IO.TextWriter textWriter, Microsoft.OpenApi.Writers.OpenApiWriterSettings? settings, bool terseOutput = false) { } protected override int BaseIndentation { get; } public override void WriteEndArray() { } public override void WriteEndObject() { } public override void WriteIndentation() { } public override void WriteNull() { } - public override void WritePropertyName(string name) { } + public override void WritePropertyName(string? name) { } public override void WriteRaw(string value) { } public override void WriteStartArray() { } public override void WriteStartObject() { } - public override void WriteValue(string value) { } + public override void WriteValue(string? value) { } protected override void WriteValueSeparator() { } } public class OpenApiJsonWriterSettings : Microsoft.OpenApi.Writers.OpenApiWriterSettings @@ -1952,19 +1952,19 @@ namespace Microsoft.OpenApi.Writers } public static class OpenApiWriterAnyExtensions { - public static void WriteAny(this Microsoft.OpenApi.Writers.IOpenApiWriter writer, System.Text.Json.Nodes.JsonNode node) { } - public static void WriteExtensions(this Microsoft.OpenApi.Writers.IOpenApiWriter writer, System.Collections.Generic.IDictionary extensions, Microsoft.OpenApi.OpenApiSpecVersion specVersion) { } + public static void WriteAny(this Microsoft.OpenApi.Writers.IOpenApiWriter writer, System.Text.Json.Nodes.JsonNode? node) { } + public static void WriteExtensions(this Microsoft.OpenApi.Writers.IOpenApiWriter writer, System.Collections.Generic.IDictionary? extensions, Microsoft.OpenApi.OpenApiSpecVersion specVersion) { } } public abstract class OpenApiWriterBase : Microsoft.OpenApi.Writers.IOpenApiWriter { protected const string IndentationString = " "; protected readonly System.Collections.Generic.Stack Scopes; protected OpenApiWriterBase(System.IO.TextWriter textWriter) { } - protected OpenApiWriterBase(System.IO.TextWriter textWriter, Microsoft.OpenApi.Writers.OpenApiWriterSettings settings) { } + protected OpenApiWriterBase(System.IO.TextWriter textWriter, Microsoft.OpenApi.Writers.OpenApiWriterSettings? settings) { } protected abstract int BaseIndentation { get; } public Microsoft.OpenApi.Writers.OpenApiWriterSettings Settings { get; set; } protected System.IO.TextWriter Writer { get; } - protected Microsoft.OpenApi.Writers.Scope CurrentScope() { } + protected Microsoft.OpenApi.Writers.Scope? CurrentScope() { } public virtual void DecreaseIndentation() { } protected Microsoft.OpenApi.Writers.Scope EndScope(Microsoft.OpenApi.Writers.ScopeType type) { } public System.Threading.Tasks.Task FlushAsync(System.Threading.CancellationToken cancellationToken = default) { } @@ -1973,16 +1973,15 @@ namespace Microsoft.OpenApi.Writers protected bool IsObjectScope() { } protected bool IsTopLevelScope() { } protected Microsoft.OpenApi.Writers.Scope StartScope(Microsoft.OpenApi.Writers.ScopeType type) { } - protected void VerifyCanWritePropertyName(string name) { } + protected void VerifyCanWritePropertyName(string? name) { } public abstract void WriteEndArray(); public abstract void WriteEndObject(); public virtual void WriteIndentation() { } public abstract void WriteNull(); - public abstract void WritePropertyName(string name); + public abstract void WritePropertyName(string? name); public abstract void WriteRaw(string value); public abstract void WriteStartArray(); public abstract void WriteStartObject(); - public void WriteV2Examples(Microsoft.OpenApi.Writers.IOpenApiWriter writer, Microsoft.OpenApi.Models.OpenApiExample example, Microsoft.OpenApi.OpenApiSpecVersion version) { } public virtual void WriteValue(bool value) { } public virtual void WriteValue(System.DateTime value) { } public virtual void WriteValue(System.DateTimeOffset value) { } @@ -1992,22 +1991,23 @@ namespace Microsoft.OpenApi.Writers public virtual void WriteValue(long value) { } public virtual void WriteValue(object value) { } public virtual void WriteValue(float value) { } - public abstract void WriteValue(string value); + public abstract void WriteValue(string? value); protected abstract void WriteValueSeparator(); + public static void WriteV2Examples(Microsoft.OpenApi.Writers.IOpenApiWriter writer, Microsoft.OpenApi.Models.OpenApiExample example, Microsoft.OpenApi.OpenApiSpecVersion version) { } } public static class OpenApiWriterExtensions { - public static void WriteOptionalCollection(this Microsoft.OpenApi.Writers.IOpenApiWriter writer, string name, System.Collections.Generic.IEnumerable elements, System.Action action) { } - public static void WriteOptionalCollection(this Microsoft.OpenApi.Writers.IOpenApiWriter writer, string name, System.Collections.Generic.IEnumerable elements, System.Action action) { } - public static void WriteOptionalMap(this Microsoft.OpenApi.Writers.IOpenApiWriter writer, string name, System.Collections.Generic.IDictionary elements, System.Action action) { } - public static void WriteOptionalMap(this Microsoft.OpenApi.Writers.IOpenApiWriter writer, string name, System.Collections.Generic.IDictionary elements, System.Action action) { } - public static void WriteOptionalMap(this Microsoft.OpenApi.Writers.IOpenApiWriter writer, string name, System.Collections.Generic.IDictionary elements, System.Action action) { } - public static void WriteOptionalMap(this Microsoft.OpenApi.Writers.IOpenApiWriter writer, string name, System.Collections.Generic.IDictionary elements, System.Action action) + public static void WriteOptionalCollection(this Microsoft.OpenApi.Writers.IOpenApiWriter writer, string name, System.Collections.Generic.IEnumerable? elements, System.Action action) { } + public static void WriteOptionalCollection(this Microsoft.OpenApi.Writers.IOpenApiWriter writer, string name, System.Collections.Generic.IEnumerable? elements, System.Action action) { } + public static void WriteOptionalMap(this Microsoft.OpenApi.Writers.IOpenApiWriter writer, string name, System.Collections.Generic.IDictionary? elements, System.Action action) { } + public static void WriteOptionalMap(this Microsoft.OpenApi.Writers.IOpenApiWriter writer, string name, System.Collections.Generic.IDictionary? elements, System.Action action) { } + public static void WriteOptionalMap(this Microsoft.OpenApi.Writers.IOpenApiWriter writer, string name, System.Collections.Generic.IDictionary? elements, System.Action action) { } + public static void WriteOptionalMap(this Microsoft.OpenApi.Writers.IOpenApiWriter writer, string name, System.Collections.Generic.IDictionary? elements, System.Action action) where T : Microsoft.OpenApi.Interfaces.IOpenApiElement { } - public static void WriteOptionalMap(this Microsoft.OpenApi.Writers.IOpenApiWriter writer, string name, System.Collections.Generic.IDictionary elements, System.Action action) + public static void WriteOptionalMap(this Microsoft.OpenApi.Writers.IOpenApiWriter writer, string name, System.Collections.Generic.IDictionary? elements, System.Action action) where T : Microsoft.OpenApi.Interfaces.IOpenApiElement { } public static void WriteOptionalObject(this Microsoft.OpenApi.Writers.IOpenApiWriter writer, string name, T? value, System.Action action) { } - public static void WriteProperty(this Microsoft.OpenApi.Writers.IOpenApiWriter writer, string name, string value) { } + public static void WriteProperty(this Microsoft.OpenApi.Writers.IOpenApiWriter writer, string name, string? value) { } public static void WriteProperty(this Microsoft.OpenApi.Writers.IOpenApiWriter writer, string name, bool value, bool defaultValue = false) { } public static void WriteProperty(this Microsoft.OpenApi.Writers.IOpenApiWriter writer, string name, bool? value, bool defaultValue = false) { } public static void WriteProperty(this Microsoft.OpenApi.Writers.IOpenApiWriter writer, string name, T value) @@ -2016,11 +2016,11 @@ namespace Microsoft.OpenApi.Writers where T : struct { } public static void WriteRequiredCollection(this Microsoft.OpenApi.Writers.IOpenApiWriter writer, string name, System.Collections.Generic.IEnumerable elements, System.Action action) where T : Microsoft.OpenApi.Interfaces.IOpenApiElement { } - public static void WriteRequiredMap(this Microsoft.OpenApi.Writers.IOpenApiWriter writer, string name, System.Collections.Generic.IDictionary elements, System.Action action) { } - public static void WriteRequiredMap(this Microsoft.OpenApi.Writers.IOpenApiWriter writer, string name, System.Collections.Generic.IDictionary elements, System.Action action) + public static void WriteRequiredMap(this Microsoft.OpenApi.Writers.IOpenApiWriter writer, string name, System.Collections.Generic.IDictionary? elements, System.Action action) { } + public static void WriteRequiredMap(this Microsoft.OpenApi.Writers.IOpenApiWriter writer, string name, System.Collections.Generic.IDictionary? elements, System.Action action) where T : Microsoft.OpenApi.Interfaces.IOpenApiElement { } public static void WriteRequiredObject(this Microsoft.OpenApi.Writers.IOpenApiWriter writer, string name, T? value, System.Action action) { } - public static void WriteRequiredProperty(this Microsoft.OpenApi.Writers.IOpenApiWriter writer, string name, string value) { } + public static void WriteRequiredProperty(this Microsoft.OpenApi.Writers.IOpenApiWriter writer, string name, string? value) { } } public class OpenApiWriterSettings { @@ -2031,17 +2031,17 @@ namespace Microsoft.OpenApi.Writers public class OpenApiYamlWriter : Microsoft.OpenApi.Writers.OpenApiWriterBase { public OpenApiYamlWriter(System.IO.TextWriter textWriter) { } - public OpenApiYamlWriter(System.IO.TextWriter textWriter, Microsoft.OpenApi.Writers.OpenApiWriterSettings settings) { } + public OpenApiYamlWriter(System.IO.TextWriter textWriter, Microsoft.OpenApi.Writers.OpenApiWriterSettings? settings) { } protected override int BaseIndentation { get; } public bool UseLiteralStyle { get; set; } public override void WriteEndArray() { } public override void WriteEndObject() { } public override void WriteNull() { } - public override void WritePropertyName(string name) { } + public override void WritePropertyName(string? name) { } public override void WriteRaw(string value) { } public override void WriteStartArray() { } public override void WriteStartObject() { } - public override void WriteValue(string value) { } + public override void WriteValue(string? value) { } protected override void WriteValueSeparator() { } } public sealed class Scope From 0b6b07d4fb2cc4073a9589139610fe29fed56fc5 Mon Sep 17 00:00:00 2001 From: Maggiekimani1 Date: Fri, 14 Feb 2025 15:52:23 +0300 Subject: [PATCH 4/7] chore: convert to conditional expression --- src/Microsoft.OpenApi/Extensions/EnumExtensions.cs | 9 +-------- .../Reader/V31/OpenApiV31Deserializer.cs | 11 +++-------- 2 files changed, 4 insertions(+), 16 deletions(-) diff --git a/src/Microsoft.OpenApi/Extensions/EnumExtensions.cs b/src/Microsoft.OpenApi/Extensions/EnumExtensions.cs index a3ddb0bcd..d3ada8f1e 100644 --- a/src/Microsoft.OpenApi/Extensions/EnumExtensions.cs +++ b/src/Microsoft.OpenApi/Extensions/EnumExtensions.cs @@ -58,14 +58,7 @@ public static string GetDisplayName(this Enum enumValue) var attribute = e.GetAttributeOfType(); // Return the DisplayAttribute name if it exists, otherwise return the enum's string representation - if (attribute?.Name is not null) - { - return attribute.Name; - } - else - { - return e.ToString(); - } + return attribute?.Name is not null ? attribute.Name : e.ToString(); }); } } diff --git a/src/Microsoft.OpenApi/Reader/V31/OpenApiV31Deserializer.cs b/src/Microsoft.OpenApi/Reader/V31/OpenApiV31Deserializer.cs index 71949d866..25bf3abe8 100644 --- a/src/Microsoft.OpenApi/Reader/V31/OpenApiV31Deserializer.cs +++ b/src/Microsoft.OpenApi/Reader/V31/OpenApiV31Deserializer.cs @@ -137,14 +137,9 @@ public static JsonNode LoadAny(ParseNode node, OpenApiDocument hostDocument) private static IOpenApiExtension LoadExtension(string name, ParseNode node) { - if (node.Context.ExtensionParsers is not null && node.Context.ExtensionParsers.TryGetValue(name, out var parser)) - { - return parser(node.CreateAny(), OpenApiSpecVersion.OpenApi3_1); - } - else - { - return new OpenApiAny(node.CreateAny()); - } + return node.Context.ExtensionParsers is not null && node.Context.ExtensionParsers.TryGetValue(name, out var parser) + ? parser(node.CreateAny(), OpenApiSpecVersion.OpenApi3_1) + : new OpenApiAny(node.CreateAny()); } private static string? LoadString(ParseNode node) From f13a9e4e26deee6e88f6108794fd9991154255d1 Mon Sep 17 00:00:00 2001 From: Maggie Kimani Date: Mon, 17 Feb 2025 11:28:22 +0300 Subject: [PATCH 5/7] Update src/Microsoft.OpenApi/Models/OpenApiOperation.cs Co-authored-by: Vincent Biret --- src/Microsoft.OpenApi/Models/OpenApiOperation.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Microsoft.OpenApi/Models/OpenApiOperation.cs b/src/Microsoft.OpenApi/Models/OpenApiOperation.cs index f1781889f..85277a830 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiOperation.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiOperation.cs @@ -248,8 +248,7 @@ public void SerializeAsV2(IOpenApiWriter writer) if (consumes.Contains("application/x-www-form-urlencoded") || consumes.Contains("multipart/form-data")) { - var formDataParameters = RequestBody.ConvertToFormDataParameters(writer); - if (formDataParameters != null) + if (RequestBody.ConvertToFormDataParameters(writer) is {} formDataParameters) { parameters.AddRange(formDataParameters); } From b7b845c256e437533a5a09cd8771d456d534db79 Mon Sep 17 00:00:00 2001 From: Maggie Kimani Date: Fri, 21 Feb 2025 11:07:08 +0300 Subject: [PATCH 6/7] Update src/Microsoft.OpenApi/Models/OpenApiRequestBody.cs Co-authored-by: Vincent Biret --- src/Microsoft.OpenApi/Models/OpenApiRequestBody.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Microsoft.OpenApi/Models/OpenApiRequestBody.cs b/src/Microsoft.OpenApi/Models/OpenApiRequestBody.cs index 232d96034..7d3c9fc52 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiRequestBody.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiRequestBody.cs @@ -137,7 +137,8 @@ public IEnumerable ConvertToFormDataParameters(IOpenApiWriter OpenApiSchema s => s, // we already have a copy // we have a copy of a reference but don't want to mutate the source schema // TODO might need recursive resolution of references here - OpenApiSchemaReference r => (OpenApiSchema?)r.Target?.CreateShallowCopy(), + OpenApiSchemaReference r when r.Target is not null => (OpenApiSchema)r.Target.CreateShallowCopy(), + OpenApiSchemaReference r2 when r.Target is null => throw new InvalidOperationException("Unresolved reference target"), _ => throw new InvalidOperationException("Unexpected schema type") }; if (updatedSchema is not null) From ea5c3894c8c93e3ea89e8bffd172124aa279c9fe Mon Sep 17 00:00:00 2001 From: Maggiekimani1 Date: Fri, 21 Feb 2025 16:37:51 +0300 Subject: [PATCH 7/7] chore: PR feedback --- .../Interfaces/IOpenApiReferenceHolder.cs | 4 +-- .../Models/OpenApiRequestBody.cs | 15 +++++----- .../Models/OpenApiResponse.cs | 8 ++--- .../References/BaseOpenApiReferenceHolder.cs | 15 ++++++---- .../References/OpenApiCallbackReference.cs | 2 +- .../References/OpenApiExampleReference.cs | 2 +- .../References/OpenApiHeaderReference.cs | 2 +- .../Models/References/OpenApiLinkReference.cs | 2 +- .../References/OpenApiParameterReference.cs | 2 +- .../References/OpenApiPathItemReference.cs | 2 +- .../References/OpenApiRequestBodyReference.cs | 2 +- .../References/OpenApiResponseReference.cs | 2 +- .../References/OpenApiSchemaReference.cs | 2 +- .../OpenApiSecuritySchemeReference.cs | 2 +- .../Models/References/OpenApiTagReference.cs | 2 +- .../Reader/V3/OpenApiV3VersionService.cs | 3 +- .../PublicApi/PublicApi.approved.txt | 30 +++++++++---------- 17 files changed, 48 insertions(+), 49 deletions(-) diff --git a/src/Microsoft.OpenApi/Interfaces/IOpenApiReferenceHolder.cs b/src/Microsoft.OpenApi/Interfaces/IOpenApiReferenceHolder.cs index bd334c582..1b689fbaf 100644 --- a/src/Microsoft.OpenApi/Interfaces/IOpenApiReferenceHolder.cs +++ b/src/Microsoft.OpenApi/Interfaces/IOpenApiReferenceHolder.cs @@ -19,7 +19,7 @@ public interface IOpenApiReferenceHolder : IOpenApiReferenceHolder whe /// /// Copy the reference as a target element with overrides. /// - V? CopyReferenceAsTargetElementWithOverrides(V? source); + V CopyReferenceAsTargetElementWithOverrides(V source); } /// /// A generic interface for OpenApiReferenceable objects that have a target. @@ -34,6 +34,6 @@ public interface IOpenApiReferenceHolder : IOpenApiSerializable /// /// Reference object. /// - OpenApiReference? Reference { get; init; } + OpenApiReference Reference { get; init; } } } diff --git a/src/Microsoft.OpenApi/Models/OpenApiRequestBody.cs b/src/Microsoft.OpenApi/Models/OpenApiRequestBody.cs index 7d3c9fc52..b3aa6e9c1 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiRequestBody.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiRequestBody.cs @@ -108,7 +108,7 @@ public IOpenApiParameter ConvertToBodyParameter(IOpenApiWriter writer) Extensions = Extensions?.ToDictionary(static k => k.Key, static v => v.Value) }; // Clone extensions so we can remove the x-bodyName extensions from the output V2 model. - if (bodyParameter.Extensions != null && bodyParameter.Extensions.TryGetValue(OpenApiConstants.BodyName, out var bodyNameExtension)) + if (bodyParameter.Extensions is not null && bodyParameter.Extensions.TryGetValue(OpenApiConstants.BodyName, out var bodyNameExtension)) { var bodyName = bodyNameExtension as OpenApiAny; bodyParameter.Name = string.IsNullOrEmpty(bodyName?.Node?.ToString()) ? "body" : bodyName?.Node?.ToString(); @@ -138,15 +138,14 @@ public IEnumerable ConvertToFormDataParameters(IOpenApiWriter // we have a copy of a reference but don't want to mutate the source schema // TODO might need recursive resolution of references here OpenApiSchemaReference r when r.Target is not null => (OpenApiSchema)r.Target.CreateShallowCopy(), - OpenApiSchemaReference r2 when r.Target is null => throw new InvalidOperationException("Unresolved reference target"), + OpenApiSchemaReference r2 when r2.Target is null => throw new InvalidOperationException("Unresolved reference target"), _ => throw new InvalidOperationException("Unexpected schema type") }; - if (updatedSchema is not null) - { - updatedSchema.Type = "file".ToJsonSchemaType(); - updatedSchema.Format = null; - paramSchema = updatedSchema; - } + + updatedSchema.Type = "file".ToJsonSchemaType(); + updatedSchema.Format = null; + paramSchema = updatedSchema; + } yield return new OpenApiFormDataParameter() { diff --git a/src/Microsoft.OpenApi/Models/OpenApiResponse.cs b/src/Microsoft.OpenApi/Models/OpenApiResponse.cs index 6be68e55b..617923c5f 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiResponse.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiResponse.cs @@ -101,11 +101,7 @@ public void SerializeAsV2(IOpenApiWriter writer) // description writer.WriteRequiredProperty(OpenApiConstants.Description, Description); - Dictionary? extensionsClone = null; - if (Extensions is not null) - { - extensionsClone = new Dictionary(Extensions); - } + var extensionsClone = Extensions is not null ? new Dictionary(Extensions) : null; if (Content != null) { @@ -139,7 +135,7 @@ public void SerializeAsV2(IOpenApiWriter writer) writer.WriteStartObject(); foreach (var example in Content - .Where(mediaTypePair => mediaTypePair.Value.Examples != null && mediaTypePair.Value.Examples.Any()) + .Where(mediaTypePair => mediaTypePair.Value.Examples is not null && mediaTypePair.Value.Examples.Any()) .SelectMany(mediaTypePair => mediaTypePair.Value.Examples!)) { writer.WritePropertyName(example.Key); diff --git a/src/Microsoft.OpenApi/Models/References/BaseOpenApiReferenceHolder.cs b/src/Microsoft.OpenApi/Models/References/BaseOpenApiReferenceHolder.cs index cc11a510f..043630a7e 100644 --- a/src/Microsoft.OpenApi/Models/References/BaseOpenApiReferenceHolder.cs +++ b/src/Microsoft.OpenApi/Models/References/BaseOpenApiReferenceHolder.cs @@ -25,7 +25,7 @@ public virtual T? Target protected BaseOpenApiReferenceHolder(BaseOpenApiReferenceHolder source) { Utils.CheckArgumentNull(source); - Reference = source.Reference != null ? new(source.Reference) : null; + Reference = new(source.Reference); //no need to copy summary and description as if they are not overridden, they will be fetched from the target //if they are, the reference copy will handle it } @@ -57,9 +57,9 @@ protected BaseOpenApiReferenceHolder(string? referenceId, OpenApiDocument? hostD /// public bool UnresolvedReference { get => Reference is null || Target is null; } /// - public OpenApiReference? Reference { get; init; } + public OpenApiReference Reference { get; init; } /// - public abstract V? CopyReferenceAsTargetElementWithOverrides(V? source); + public abstract V CopyReferenceAsTargetElementWithOverrides(V source); /// public virtual void SerializeAsV3(IOpenApiWriter writer) { @@ -82,7 +82,7 @@ public virtual void SerializeAsV31(IOpenApiWriter writer) } else { - SerializeInternal(writer, (writer, element) => CopyReferenceAsTargetElementWithOverrides(element)?.SerializeAsV31(writer)); + SerializeInternal(writer, (writer, element) => CopyReferenceAsTargetElementWithOverrides(element).SerializeAsV31(writer)); } } @@ -106,9 +106,12 @@ public virtual void SerializeAsV2(IOpenApiWriter writer) /// The OpenApiWriter. /// The action to serialize the target object. private protected void SerializeInternal(IOpenApiWriter writer, - Action action) + Action action) { Utils.CheckArgumentNull(writer); - action(writer, Target); + if (Target is not null) + { + action(writer, Target); + } } } diff --git a/src/Microsoft.OpenApi/Models/References/OpenApiCallbackReference.cs b/src/Microsoft.OpenApi/Models/References/OpenApiCallbackReference.cs index 76fefbcd8..77b920d7c 100644 --- a/src/Microsoft.OpenApi/Models/References/OpenApiCallbackReference.cs +++ b/src/Microsoft.OpenApi/Models/References/OpenApiCallbackReference.cs @@ -44,7 +44,7 @@ private OpenApiCallbackReference(OpenApiCallbackReference callback):base(callbac public IDictionary? Extensions { get => Target?.Extensions; } /// - public override IOpenApiCallback? CopyReferenceAsTargetElementWithOverrides(IOpenApiCallback? source) + public override IOpenApiCallback CopyReferenceAsTargetElementWithOverrides(IOpenApiCallback source) { return source is OpenApiCallback ? new OpenApiCallback(this) : source; } diff --git a/src/Microsoft.OpenApi/Models/References/OpenApiExampleReference.cs b/src/Microsoft.OpenApi/Models/References/OpenApiExampleReference.cs index ca8554ee9..4b789fd0a 100644 --- a/src/Microsoft.OpenApi/Models/References/OpenApiExampleReference.cs +++ b/src/Microsoft.OpenApi/Models/References/OpenApiExampleReference.cs @@ -72,7 +72,7 @@ public string? Summary public JsonNode? Value { get => Target?.Value; } /// - public override IOpenApiExample? CopyReferenceAsTargetElementWithOverrides(IOpenApiExample? source) + public override IOpenApiExample CopyReferenceAsTargetElementWithOverrides(IOpenApiExample source) { return source is OpenApiExample ? new OpenApiExample(this) : source; } diff --git a/src/Microsoft.OpenApi/Models/References/OpenApiHeaderReference.cs b/src/Microsoft.OpenApi/Models/References/OpenApiHeaderReference.cs index 731efc8f4..30bb54800 100644 --- a/src/Microsoft.OpenApi/Models/References/OpenApiHeaderReference.cs +++ b/src/Microsoft.OpenApi/Models/References/OpenApiHeaderReference.cs @@ -83,7 +83,7 @@ public string? Description public IDictionary? Extensions { get => Target?.Extensions; } /// - public override IOpenApiHeader? CopyReferenceAsTargetElementWithOverrides(IOpenApiHeader? source) + public override IOpenApiHeader CopyReferenceAsTargetElementWithOverrides(IOpenApiHeader source) { return source is OpenApiHeader ? new OpenApiHeader(this) : source; } diff --git a/src/Microsoft.OpenApi/Models/References/OpenApiLinkReference.cs b/src/Microsoft.OpenApi/Models/References/OpenApiLinkReference.cs index 5cd7295ba..22eb6f803 100644 --- a/src/Microsoft.OpenApi/Models/References/OpenApiLinkReference.cs +++ b/src/Microsoft.OpenApi/Models/References/OpenApiLinkReference.cs @@ -73,7 +73,7 @@ public override void SerializeAsV2(IOpenApiWriter writer) } /// - public override IOpenApiLink? CopyReferenceAsTargetElementWithOverrides(IOpenApiLink? source) + public override IOpenApiLink CopyReferenceAsTargetElementWithOverrides(IOpenApiLink source) { return source is OpenApiLink ? new OpenApiLink(this) : source; } diff --git a/src/Microsoft.OpenApi/Models/References/OpenApiParameterReference.cs b/src/Microsoft.OpenApi/Models/References/OpenApiParameterReference.cs index bb7094a1f..38abd54ac 100644 --- a/src/Microsoft.OpenApi/Models/References/OpenApiParameterReference.cs +++ b/src/Microsoft.OpenApi/Models/References/OpenApiParameterReference.cs @@ -88,7 +88,7 @@ public string? Description public IDictionary? Extensions { get => Target?.Extensions; } /// - public override IOpenApiParameter? CopyReferenceAsTargetElementWithOverrides(IOpenApiParameter? source) + public override IOpenApiParameter CopyReferenceAsTargetElementWithOverrides(IOpenApiParameter source) { return source is OpenApiParameter ? new OpenApiParameter(this) : source; } diff --git a/src/Microsoft.OpenApi/Models/References/OpenApiPathItemReference.cs b/src/Microsoft.OpenApi/Models/References/OpenApiPathItemReference.cs index 927f5c063..2d5cbd11f 100644 --- a/src/Microsoft.OpenApi/Models/References/OpenApiPathItemReference.cs +++ b/src/Microsoft.OpenApi/Models/References/OpenApiPathItemReference.cs @@ -76,7 +76,7 @@ public string? Description public IDictionary? Extensions { get => Target?.Extensions; } /// - public override IOpenApiPathItem? CopyReferenceAsTargetElementWithOverrides(IOpenApiPathItem? source) + public override IOpenApiPathItem CopyReferenceAsTargetElementWithOverrides(IOpenApiPathItem source) { return source is OpenApiPathItem ? new OpenApiPathItem(this) : source; } diff --git a/src/Microsoft.OpenApi/Models/References/OpenApiRequestBodyReference.cs b/src/Microsoft.OpenApi/Models/References/OpenApiRequestBodyReference.cs index 8e292f236..f498a7afc 100644 --- a/src/Microsoft.OpenApi/Models/References/OpenApiRequestBodyReference.cs +++ b/src/Microsoft.OpenApi/Models/References/OpenApiRequestBodyReference.cs @@ -60,7 +60,7 @@ public string? Description public IDictionary? Extensions { get => Target?.Extensions; } /// - public override IOpenApiRequestBody? CopyReferenceAsTargetElementWithOverrides(IOpenApiRequestBody? source) + public override IOpenApiRequestBody CopyReferenceAsTargetElementWithOverrides(IOpenApiRequestBody source) { return source is OpenApiRequestBody ? new OpenApiRequestBody(this) : source; } diff --git a/src/Microsoft.OpenApi/Models/References/OpenApiResponseReference.cs b/src/Microsoft.OpenApi/Models/References/OpenApiResponseReference.cs index 26c527c52..4b7d01487 100644 --- a/src/Microsoft.OpenApi/Models/References/OpenApiResponseReference.cs +++ b/src/Microsoft.OpenApi/Models/References/OpenApiResponseReference.cs @@ -61,7 +61,7 @@ public string? Description public IDictionary? Extensions { get => Target?.Extensions; } /// - public override IOpenApiResponse? CopyReferenceAsTargetElementWithOverrides(IOpenApiResponse? source) + public override IOpenApiResponse CopyReferenceAsTargetElementWithOverrides(IOpenApiResponse source) { return source is OpenApiResponse ? new OpenApiResponse(this) : source; } diff --git a/src/Microsoft.OpenApi/Models/References/OpenApiSchemaReference.cs b/src/Microsoft.OpenApi/Models/References/OpenApiSchemaReference.cs index 305d25558..d85473f8c 100644 --- a/src/Microsoft.OpenApi/Models/References/OpenApiSchemaReference.cs +++ b/src/Microsoft.OpenApi/Models/References/OpenApiSchemaReference.cs @@ -190,7 +190,7 @@ private void SerializeAsWithoutLoops(IOpenApiWriter writer, Action - public override IOpenApiSchema? CopyReferenceAsTargetElementWithOverrides(IOpenApiSchema? source) + public override IOpenApiSchema CopyReferenceAsTargetElementWithOverrides(IOpenApiSchema source) { return source is OpenApiSchema ? new OpenApiSchema(this) : source; } diff --git a/src/Microsoft.OpenApi/Models/References/OpenApiSecuritySchemeReference.cs b/src/Microsoft.OpenApi/Models/References/OpenApiSecuritySchemeReference.cs index 2f3afeb46..36c39fcff 100644 --- a/src/Microsoft.OpenApi/Models/References/OpenApiSecuritySchemeReference.cs +++ b/src/Microsoft.OpenApi/Models/References/OpenApiSecuritySchemeReference.cs @@ -69,7 +69,7 @@ public string? Description public SecuritySchemeType? Type { get => Target?.Type; } /// - public override IOpenApiSecurityScheme? CopyReferenceAsTargetElementWithOverrides(IOpenApiSecurityScheme? source) + public override IOpenApiSecurityScheme CopyReferenceAsTargetElementWithOverrides(IOpenApiSecurityScheme source) { return source is OpenApiSecurityScheme ? new OpenApiSecurityScheme(this) : source; } diff --git a/src/Microsoft.OpenApi/Models/References/OpenApiTagReference.cs b/src/Microsoft.OpenApi/Models/References/OpenApiTagReference.cs index c7580e9e3..53ba3267c 100644 --- a/src/Microsoft.OpenApi/Models/References/OpenApiTagReference.cs +++ b/src/Microsoft.OpenApi/Models/References/OpenApiTagReference.cs @@ -62,7 +62,7 @@ public string? Description /// public string? Name { get => Target?.Name; } /// - public override IOpenApiTag? CopyReferenceAsTargetElementWithOverrides(IOpenApiTag? source) + public override IOpenApiTag CopyReferenceAsTargetElementWithOverrides(IOpenApiTag source) { return source is OpenApiTag ? new OpenApiTag(this) : source; } diff --git a/src/Microsoft.OpenApi/Reader/V3/OpenApiV3VersionService.cs b/src/Microsoft.OpenApi/Reader/V3/OpenApiV3VersionService.cs index d2fa8e8c0..7f55c99ee 100644 --- a/src/Microsoft.OpenApi/Reader/V3/OpenApiV3VersionService.cs +++ b/src/Microsoft.OpenApi/Reader/V3/OpenApiV3VersionService.cs @@ -72,7 +72,7 @@ public OpenApiV3VersionService(OpenApiDiagnostic diagnostic) /// The type of object referenced based on the context of the reference /// /// - public OpenApiReference ConvertToOpenApiReference( + public OpenApiReference? ConvertToOpenApiReference( string reference, ReferenceType? type, string? summary = null, @@ -112,6 +112,7 @@ public OpenApiReference ConvertToOpenApiReference( catch (OpenApiException ex) { Diagnostic.Errors.Add(new(ex)); + return null; } } // Where fragments point into a non-OpenAPI document, the id will be the complete fragment identifier diff --git a/test/Microsoft.OpenApi.Tests/PublicApi/PublicApi.approved.txt b/test/Microsoft.OpenApi.Tests/PublicApi/PublicApi.approved.txt index a2e8e7d3b..0bd29b01c 100644 --- a/test/Microsoft.OpenApi.Tests/PublicApi/PublicApi.approved.txt +++ b/test/Microsoft.OpenApi.Tests/PublicApi/PublicApi.approved.txt @@ -224,14 +224,14 @@ namespace Microsoft.OpenApi.Interfaces } public interface IOpenApiReferenceHolder : Microsoft.OpenApi.Interfaces.IOpenApiElement, Microsoft.OpenApi.Interfaces.IOpenApiSerializable { - Microsoft.OpenApi.Models.OpenApiReference? Reference { get; init; } + Microsoft.OpenApi.Models.OpenApiReference Reference { get; init; } bool UnresolvedReference { get; } } public interface IOpenApiReferenceHolder : Microsoft.OpenApi.Interfaces.IOpenApiElement, Microsoft.OpenApi.Interfaces.IOpenApiReferenceHolder, Microsoft.OpenApi.Interfaces.IOpenApiSerializable where out T : Microsoft.OpenApi.Interfaces.IOpenApiReferenceable, V { T Target { get; } - V? CopyReferenceAsTargetElementWithOverrides(V? source); + V CopyReferenceAsTargetElementWithOverrides(V source); } public interface IOpenApiReferenceable : Microsoft.OpenApi.Interfaces.IOpenApiElement, Microsoft.OpenApi.Interfaces.IOpenApiSerializable { } public interface IOpenApiSerializable : Microsoft.OpenApi.Interfaces.IOpenApiElement @@ -1243,10 +1243,10 @@ namespace Microsoft.OpenApi.Models.References { protected BaseOpenApiReferenceHolder(Microsoft.OpenApi.Models.References.BaseOpenApiReferenceHolder source) { } protected BaseOpenApiReferenceHolder(string? referenceId, Microsoft.OpenApi.Models.OpenApiDocument? hostDocument, Microsoft.OpenApi.Models.ReferenceType referenceType, string? externalResource) { } - public Microsoft.OpenApi.Models.OpenApiReference? Reference { get; init; } + public Microsoft.OpenApi.Models.OpenApiReference Reference { get; init; } public virtual T Target { get; } public bool UnresolvedReference { get; } - public abstract V? CopyReferenceAsTargetElementWithOverrides(V? source); + public abstract V CopyReferenceAsTargetElementWithOverrides(V source); public virtual void SerializeAsV2(Microsoft.OpenApi.Writers.IOpenApiWriter writer) { } public virtual void SerializeAsV3(Microsoft.OpenApi.Writers.IOpenApiWriter writer) { } public virtual void SerializeAsV31(Microsoft.OpenApi.Writers.IOpenApiWriter writer) { } @@ -1256,7 +1256,7 @@ namespace Microsoft.OpenApi.Models.References public OpenApiCallbackReference(string referenceId, Microsoft.OpenApi.Models.OpenApiDocument? hostDocument = null, string? externalResource = null) { } public System.Collections.Generic.IDictionary? Extensions { get; } public System.Collections.Generic.Dictionary? PathItems { get; } - public override Microsoft.OpenApi.Models.Interfaces.IOpenApiCallback? CopyReferenceAsTargetElementWithOverrides(Microsoft.OpenApi.Models.Interfaces.IOpenApiCallback? source) { } + public override Microsoft.OpenApi.Models.Interfaces.IOpenApiCallback CopyReferenceAsTargetElementWithOverrides(Microsoft.OpenApi.Models.Interfaces.IOpenApiCallback source) { } public Microsoft.OpenApi.Models.Interfaces.IOpenApiCallback CreateShallowCopy() { } public override void SerializeAsV2(Microsoft.OpenApi.Writers.IOpenApiWriter writer) { } } @@ -1268,7 +1268,7 @@ namespace Microsoft.OpenApi.Models.References public string? ExternalValue { get; } public string? Summary { get; set; } public System.Text.Json.Nodes.JsonNode? Value { get; } - public override Microsoft.OpenApi.Models.Interfaces.IOpenApiExample? CopyReferenceAsTargetElementWithOverrides(Microsoft.OpenApi.Models.Interfaces.IOpenApiExample? source) { } + public override Microsoft.OpenApi.Models.Interfaces.IOpenApiExample CopyReferenceAsTargetElementWithOverrides(Microsoft.OpenApi.Models.Interfaces.IOpenApiExample source) { } public Microsoft.OpenApi.Models.Interfaces.IOpenApiExample CreateShallowCopy() { } public override void SerializeAsV2(Microsoft.OpenApi.Writers.IOpenApiWriter writer) { } } @@ -1287,7 +1287,7 @@ namespace Microsoft.OpenApi.Models.References public bool Required { get; } public Microsoft.OpenApi.Models.Interfaces.IOpenApiSchema? Schema { get; } public Microsoft.OpenApi.Models.ParameterStyle? Style { get; } - public override Microsoft.OpenApi.Models.Interfaces.IOpenApiHeader? CopyReferenceAsTargetElementWithOverrides(Microsoft.OpenApi.Models.Interfaces.IOpenApiHeader? source) { } + public override Microsoft.OpenApi.Models.Interfaces.IOpenApiHeader CopyReferenceAsTargetElementWithOverrides(Microsoft.OpenApi.Models.Interfaces.IOpenApiHeader source) { } public Microsoft.OpenApi.Models.Interfaces.IOpenApiHeader CreateShallowCopy() { } } public class OpenApiLinkReference : Microsoft.OpenApi.Models.References.BaseOpenApiReferenceHolder, Microsoft.OpenApi.Interfaces.IOpenApiElement, Microsoft.OpenApi.Interfaces.IOpenApiReadOnlyExtensible, Microsoft.OpenApi.Interfaces.IOpenApiSerializable, Microsoft.OpenApi.Interfaces.IShallowCopyable, Microsoft.OpenApi.Models.Interfaces.IOpenApiDescribedElement, Microsoft.OpenApi.Models.Interfaces.IOpenApiLink @@ -1300,7 +1300,7 @@ namespace Microsoft.OpenApi.Models.References public System.Collections.Generic.IDictionary? Parameters { get; } public Microsoft.OpenApi.Models.RuntimeExpressionAnyWrapper? RequestBody { get; } public Microsoft.OpenApi.Models.OpenApiServer? Server { get; } - public override Microsoft.OpenApi.Models.Interfaces.IOpenApiLink? CopyReferenceAsTargetElementWithOverrides(Microsoft.OpenApi.Models.Interfaces.IOpenApiLink? source) { } + public override Microsoft.OpenApi.Models.Interfaces.IOpenApiLink CopyReferenceAsTargetElementWithOverrides(Microsoft.OpenApi.Models.Interfaces.IOpenApiLink source) { } public Microsoft.OpenApi.Models.Interfaces.IOpenApiLink CreateShallowCopy() { } public override void SerializeAsV2(Microsoft.OpenApi.Writers.IOpenApiWriter writer) { } } @@ -1321,7 +1321,7 @@ namespace Microsoft.OpenApi.Models.References public bool Required { get; } public Microsoft.OpenApi.Models.Interfaces.IOpenApiSchema? Schema { get; } public Microsoft.OpenApi.Models.ParameterStyle? Style { get; } - public override Microsoft.OpenApi.Models.Interfaces.IOpenApiParameter? CopyReferenceAsTargetElementWithOverrides(Microsoft.OpenApi.Models.Interfaces.IOpenApiParameter? source) { } + public override Microsoft.OpenApi.Models.Interfaces.IOpenApiParameter CopyReferenceAsTargetElementWithOverrides(Microsoft.OpenApi.Models.Interfaces.IOpenApiParameter source) { } public Microsoft.OpenApi.Models.Interfaces.IOpenApiParameter CreateShallowCopy() { } } public class OpenApiPathItemReference : Microsoft.OpenApi.Models.References.BaseOpenApiReferenceHolder, Microsoft.OpenApi.Interfaces.IOpenApiElement, Microsoft.OpenApi.Interfaces.IOpenApiReadOnlyExtensible, Microsoft.OpenApi.Interfaces.IOpenApiSerializable, Microsoft.OpenApi.Interfaces.IShallowCopyable, Microsoft.OpenApi.Models.Interfaces.IOpenApiDescribedElement, Microsoft.OpenApi.Models.Interfaces.IOpenApiPathItem, Microsoft.OpenApi.Models.Interfaces.IOpenApiSummarizedElement @@ -1333,7 +1333,7 @@ namespace Microsoft.OpenApi.Models.References public System.Collections.Generic.IList? Parameters { get; } public System.Collections.Generic.IList? Servers { get; } public string? Summary { get; set; } - public override Microsoft.OpenApi.Models.Interfaces.IOpenApiPathItem? CopyReferenceAsTargetElementWithOverrides(Microsoft.OpenApi.Models.Interfaces.IOpenApiPathItem? source) { } + public override Microsoft.OpenApi.Models.Interfaces.IOpenApiPathItem CopyReferenceAsTargetElementWithOverrides(Microsoft.OpenApi.Models.Interfaces.IOpenApiPathItem source) { } public Microsoft.OpenApi.Models.Interfaces.IOpenApiPathItem CreateShallowCopy() { } public override void SerializeAsV2(Microsoft.OpenApi.Writers.IOpenApiWriter writer) { } } @@ -1346,7 +1346,7 @@ namespace Microsoft.OpenApi.Models.References public bool Required { get; } public Microsoft.OpenApi.Models.Interfaces.IOpenApiParameter? ConvertToBodyParameter(Microsoft.OpenApi.Writers.IOpenApiWriter writer) { } public System.Collections.Generic.IEnumerable? ConvertToFormDataParameters(Microsoft.OpenApi.Writers.IOpenApiWriter writer) { } - public override Microsoft.OpenApi.Models.Interfaces.IOpenApiRequestBody? CopyReferenceAsTargetElementWithOverrides(Microsoft.OpenApi.Models.Interfaces.IOpenApiRequestBody? source) { } + public override Microsoft.OpenApi.Models.Interfaces.IOpenApiRequestBody CopyReferenceAsTargetElementWithOverrides(Microsoft.OpenApi.Models.Interfaces.IOpenApiRequestBody source) { } public Microsoft.OpenApi.Models.Interfaces.IOpenApiRequestBody CreateShallowCopy() { } public override void SerializeAsV2(Microsoft.OpenApi.Writers.IOpenApiWriter writer) { } } @@ -1358,7 +1358,7 @@ namespace Microsoft.OpenApi.Models.References public System.Collections.Generic.IDictionary? Extensions { get; } public System.Collections.Generic.IDictionary? Headers { get; } public System.Collections.Generic.IDictionary? Links { get; } - public override Microsoft.OpenApi.Models.Interfaces.IOpenApiResponse? CopyReferenceAsTargetElementWithOverrides(Microsoft.OpenApi.Models.Interfaces.IOpenApiResponse? source) { } + public override Microsoft.OpenApi.Models.Interfaces.IOpenApiResponse CopyReferenceAsTargetElementWithOverrides(Microsoft.OpenApi.Models.Interfaces.IOpenApiResponse source) { } public Microsoft.OpenApi.Models.Interfaces.IOpenApiResponse CreateShallowCopy() { } } public class OpenApiSchemaReference : Microsoft.OpenApi.Models.References.BaseOpenApiReferenceHolder, Microsoft.OpenApi.Interfaces.IOpenApiElement, Microsoft.OpenApi.Interfaces.IOpenApiReadOnlyExtensible, Microsoft.OpenApi.Interfaces.IOpenApiSerializable, Microsoft.OpenApi.Interfaces.IShallowCopyable, Microsoft.OpenApi.Models.Interfaces.IOpenApiDescribedElement, Microsoft.OpenApi.Models.Interfaces.IOpenApiSchema @@ -1416,7 +1416,7 @@ namespace Microsoft.OpenApi.Models.References public System.Collections.Generic.IDictionary? Vocabulary { get; } public bool WriteOnly { get; } public Microsoft.OpenApi.Models.OpenApiXml? Xml { get; } - public override Microsoft.OpenApi.Models.Interfaces.IOpenApiSchema? CopyReferenceAsTargetElementWithOverrides(Microsoft.OpenApi.Models.Interfaces.IOpenApiSchema? source) { } + public override Microsoft.OpenApi.Models.Interfaces.IOpenApiSchema CopyReferenceAsTargetElementWithOverrides(Microsoft.OpenApi.Models.Interfaces.IOpenApiSchema source) { } public Microsoft.OpenApi.Models.Interfaces.IOpenApiSchema CreateShallowCopy() { } public override void SerializeAsV2(Microsoft.OpenApi.Writers.IOpenApiWriter writer) { } public override void SerializeAsV3(Microsoft.OpenApi.Writers.IOpenApiWriter writer) { } @@ -1434,7 +1434,7 @@ namespace Microsoft.OpenApi.Models.References public System.Uri? OpenIdConnectUrl { get; } public string? Scheme { get; } public Microsoft.OpenApi.Models.SecuritySchemeType? Type { get; } - public override Microsoft.OpenApi.Models.Interfaces.IOpenApiSecurityScheme? CopyReferenceAsTargetElementWithOverrides(Microsoft.OpenApi.Models.Interfaces.IOpenApiSecurityScheme? source) { } + public override Microsoft.OpenApi.Models.Interfaces.IOpenApiSecurityScheme CopyReferenceAsTargetElementWithOverrides(Microsoft.OpenApi.Models.Interfaces.IOpenApiSecurityScheme source) { } public Microsoft.OpenApi.Models.Interfaces.IOpenApiSecurityScheme CreateShallowCopy() { } } public class OpenApiTagReference : Microsoft.OpenApi.Models.References.BaseOpenApiReferenceHolder, Microsoft.OpenApi.Interfaces.IOpenApiElement, Microsoft.OpenApi.Interfaces.IOpenApiReadOnlyExtensible, Microsoft.OpenApi.Interfaces.IOpenApiSerializable, Microsoft.OpenApi.Interfaces.IShallowCopyable, Microsoft.OpenApi.Models.Interfaces.IOpenApiReadOnlyDescribedElement, Microsoft.OpenApi.Models.Interfaces.IOpenApiTag @@ -1445,7 +1445,7 @@ namespace Microsoft.OpenApi.Models.References public Microsoft.OpenApi.Models.OpenApiExternalDocs? ExternalDocs { get; } public string? Name { get; } public override Microsoft.OpenApi.Models.OpenApiTag? Target { get; } - public override Microsoft.OpenApi.Models.Interfaces.IOpenApiTag? CopyReferenceAsTargetElementWithOverrides(Microsoft.OpenApi.Models.Interfaces.IOpenApiTag? source) { } + public override Microsoft.OpenApi.Models.Interfaces.IOpenApiTag CopyReferenceAsTargetElementWithOverrides(Microsoft.OpenApi.Models.Interfaces.IOpenApiTag source) { } public Microsoft.OpenApi.Models.Interfaces.IOpenApiTag CreateShallowCopy() { } } }