diff --git a/src/Microsoft.OpenApi.Hidi/Formatters/PowerShellFormatter.cs b/src/Microsoft.OpenApi.Hidi/Formatters/PowerShellFormatter.cs index 183de1691..d473fcd58 100644 --- a/src/Microsoft.OpenApi.Hidi/Formatters/PowerShellFormatter.cs +++ b/src/Microsoft.OpenApi.Hidi/Formatters/PowerShellFormatter.cs @@ -163,10 +163,10 @@ private static IList ResolveFunctionParameters(IList options.TerseOutput ? new OpenApiJsonWriter(textWriter, settings, options.TerseOutput) : new OpenApiJsonWriter(textWriter, settings, false), + OpenApiFormat.Json => options.TerseOutput ? new(textWriter, settings, options.TerseOutput) : new OpenApiJsonWriter(textWriter, settings, false), OpenApiFormat.Yaml => new OpenApiYamlWriter(textWriter, settings), _ => throw new ArgumentException("Unknown format"), }; @@ -368,11 +368,11 @@ private static async Task ParseOpenApi(string openApiFile, bool inli { stopwatch.Start(); - result = await new OpenApiStreamReader(new OpenApiReaderSettings - { + result = await new OpenApiStreamReader(new() + { LoadExternalRefs = inlineExternal, BaseUrl = openApiFile.StartsWith("http", StringComparison.OrdinalIgnoreCase) ? - new Uri(openApiFile) : + new(openApiFile) : new Uri("file://" + new FileInfo(openApiFile).DirectoryName + Path.DirectorySeparatorChar) } ).ReadAsync(stream, cancellationToken).ConfigureAwait(false); @@ -459,7 +459,7 @@ private static Dictionary> EnumerateJsonDocument(JsonElemen } else { - paths.Add(path, new List {method}); + paths.Add(path, new() {method}); } } else @@ -741,7 +741,7 @@ internal static async Task PluginManifest(HidiOptions options, ILogger logger, C outputFolder.Create(); } // Write OpenAPI to Output folder - options.Output = new FileInfo(Path.Combine(options.OutputFolder, "openapi.json")); + options.Output = new(Path.Combine(options.OutputFolder, "openapi.json")); options.TerseOutput = true; WriteOpenApi(options, OpenApiFormat.Json, OpenApiSpecVersion.OpenApi3_0, document, logger); @@ -762,7 +762,7 @@ internal static async Task PluginManifest(HidiOptions options, ILogger logger, C // Write OpenAIPluginManifest to Output folder var manifestFile = new FileInfo(Path.Combine(options.OutputFolder, "ai-plugin.json")); using var file = new FileStream(manifestFile.FullName, FileMode.Create); - using var jsonWriter = new Utf8JsonWriter(file, new JsonWriterOptions { Indented = true }); + using var jsonWriter = new Utf8JsonWriter(file, new() { Indented = true }); manifest.Write(jsonWriter); await jsonWriter.FlushAsync(cancellationToken).ConfigureAwait(false); } diff --git a/src/Microsoft.OpenApi.Hidi/Options/HidiOptions.cs b/src/Microsoft.OpenApi.Hidi/Options/HidiOptions.cs index d2a2bfe40..fca97c87f 100644 --- a/src/Microsoft.OpenApi.Hidi/Options/HidiOptions.cs +++ b/src/Microsoft.OpenApi.Hidi/Options/HidiOptions.cs @@ -53,7 +53,7 @@ private void ParseHidiOptions(ParseResult parseResult, CommandOptions options) LogLevel = parseResult.GetValueForOption(options.LogLevelOption); InlineLocal = parseResult.GetValueForOption(options.InlineLocalOption); InlineExternal = parseResult.GetValueForOption(options.InlineExternalOption); - FilterOptions = new FilterOptions + FilterOptions = new() { FilterByOperationIds = parseResult.GetValueForOption(options.FilterByOperationIdsOption), FilterByTags = parseResult.GetValueForOption(options.FilterByTagsOption), diff --git a/src/Microsoft.OpenApi.Readers/OpenApiDiagnostic.cs b/src/Microsoft.OpenApi.Readers/OpenApiDiagnostic.cs index 1c70db887..509358174 100644 --- a/src/Microsoft.OpenApi.Readers/OpenApiDiagnostic.cs +++ b/src/Microsoft.OpenApi.Readers/OpenApiDiagnostic.cs @@ -39,12 +39,12 @@ public void AppendDiagnostic(OpenApiDiagnostic diagnosticToAdd, string fileNameT foreach (var err in diagnosticToAdd.Errors) { var errMsgWithFileName = fileNameIsSupplied ? $"[File: {fileNameToAdd}] {err.Message}" : err.Message; - Errors.Add(new OpenApiError(err.Pointer, errMsgWithFileName)); + Errors.Add(new(err.Pointer, errMsgWithFileName)); } foreach (var warn in diagnosticToAdd.Warnings) { var warnMsgWithFileName = fileNameIsSupplied ? $"[File: {fileNameToAdd}] {warn.Message}" : warn.Message; - Warnings.Add(new OpenApiError(warn.Pointer, warnMsgWithFileName)); + Warnings.Add(new(warn.Pointer, warnMsgWithFileName)); } } } diff --git a/src/Microsoft.OpenApi.Readers/OpenApiReaderSettings.cs b/src/Microsoft.OpenApi.Readers/OpenApiReaderSettings.cs index 71a18e137..5d251802f 100644 --- a/src/Microsoft.OpenApi.Readers/OpenApiReaderSettings.cs +++ b/src/Microsoft.OpenApi.Readers/OpenApiReaderSettings.cs @@ -50,7 +50,7 @@ public class OpenApiReaderSettings /// /// Dictionary of parsers for converting extensions into strongly typed classes /// - public Dictionary> ExtensionParsers { get; set; } = new Dictionary>(); + public Dictionary> ExtensionParsers { get; set; } = new(); /// /// Rules to use for validating OpenAPI specification. If none are provided a default set of rules are applied. diff --git a/src/Microsoft.OpenApi.Readers/OpenApiStreamReader.cs b/src/Microsoft.OpenApi.Readers/OpenApiStreamReader.cs index 4776fcce4..e96aa4b12 100644 --- a/src/Microsoft.OpenApi.Readers/OpenApiStreamReader.cs +++ b/src/Microsoft.OpenApi.Readers/OpenApiStreamReader.cs @@ -68,7 +68,7 @@ public async Task ReadAsync(Stream input, CancellationToken cancella { // Buffer stream so that OpenApiTextReaderReader can process it synchronously // YamlDocument doesn't support async reading. - bufferedStream = new MemoryStream(); + bufferedStream = new(); await input.CopyToAsync(bufferedStream, 81920, cancellationToken); bufferedStream.Position = 0; } diff --git a/src/Microsoft.OpenApi.Readers/OpenApiTextReaderReader.cs b/src/Microsoft.OpenApi.Readers/OpenApiTextReaderReader.cs index 68550135d..dff20fc7f 100644 --- a/src/Microsoft.OpenApi.Readers/OpenApiTextReaderReader.cs +++ b/src/Microsoft.OpenApi.Readers/OpenApiTextReaderReader.cs @@ -46,9 +46,9 @@ public OpenApiDocument Read(TextReader input, out OpenApiDiagnostic diagnostic) } catch (YamlException ex) { - diagnostic = new OpenApiDiagnostic(); - diagnostic.Errors.Add(new OpenApiError($"#line={ex.Start.Line}", ex.Message)); - return new OpenApiDocument(); + diagnostic = new(); + diagnostic.Errors.Add(new($"#line={ex.Start.Line}", ex.Message)); + return new(); } return new OpenApiYamlDocumentReader(this._settings).Read(yamlDocument, out diagnostic); @@ -72,8 +72,8 @@ public async Task ReadAsync(TextReader input, CancellationToken canc catch (YamlException ex) { var diagnostic = new OpenApiDiagnostic(); - diagnostic.Errors.Add(new OpenApiError($"#line={ex.Start.Line}", ex.Message)); - return new ReadResult + diagnostic.Errors.Add(new($"#line={ex.Start.Line}", ex.Message)); + return new() { OpenApiDocument = null, OpenApiDiagnostic = diagnostic @@ -101,8 +101,8 @@ public T ReadFragment(TextReader input, OpenApiSpecVersion version, out OpenA } catch (YamlException ex) { - diagnostic = new OpenApiDiagnostic(); - diagnostic.Errors.Add(new OpenApiError($"#line={ex.Start.Line}", ex.Message)); + diagnostic = new(); + diagnostic.Errors.Add(new($"#line={ex.Start.Line}", ex.Message)); return default; } diff --git a/src/Microsoft.OpenApi.Readers/OpenApiYamlDocumentReader.cs b/src/Microsoft.OpenApi.Readers/OpenApiYamlDocumentReader.cs index 03076d6c7..c0626aa17 100644 --- a/src/Microsoft.OpenApi.Readers/OpenApiYamlDocumentReader.cs +++ b/src/Microsoft.OpenApi.Readers/OpenApiYamlDocumentReader.cs @@ -42,7 +42,7 @@ public OpenApiYamlDocumentReader(OpenApiReaderSettings settings = null) /// Instance of newly created OpenApiDocument public OpenApiDocument Read(YamlDocument input, out OpenApiDiagnostic diagnostic) { - diagnostic = new OpenApiDiagnostic(); + diagnostic = new(); var context = new ParsingContext(diagnostic) { ExtensionParsers = _settings.ExtensionParsers, @@ -65,7 +65,7 @@ public OpenApiDocument Read(YamlDocument input, out OpenApiDiagnostic diagnostic } catch (OpenApiException ex) { - diagnostic.Errors.Add(new OpenApiError(ex)); + diagnostic.Errors.Add(new(ex)); } // Validate the document @@ -115,7 +115,7 @@ public async Task ReadAsync(YamlDocument input, CancellationToken ca } catch (OpenApiException ex) { - diagnostic.Errors.Add(new OpenApiError(ex)); + diagnostic.Errors.Add(new(ex)); } // Validate the document @@ -132,7 +132,7 @@ public async Task ReadAsync(YamlDocument input, CancellationToken ca } } - return new ReadResult + return new() { OpenApiDocument = document, OpenApiDiagnostic = diagnostic @@ -147,7 +147,7 @@ private Task LoadExternalRefs(OpenApiDocument document, Cance // Load this root document into the workspace var streamLoader = new DefaultStreamLoader(_settings.BaseUrl); var workspaceLoader = new OpenApiWorkspaceLoader(openApiWorkSpace, _settings.CustomExternalLoader ?? streamLoader, _settings); - return workspaceLoader.LoadAsync(new OpenApiReference { ExternalResource = "/" }, document, null, cancellationToken); + return workspaceLoader.LoadAsync(new() { ExternalResource = "/" }, document, null, cancellationToken); } private void ResolveReferences(OpenApiDiagnostic diagnostic, OpenApiDocument document) @@ -181,7 +181,7 @@ private void ResolveReferences(OpenApiDiagnostic diagnostic, OpenApiDocument doc /// Instance of newly created OpenApiDocument public T ReadFragment(YamlDocument input, OpenApiSpecVersion version, out OpenApiDiagnostic diagnostic) where T : IOpenApiElement { - diagnostic = new OpenApiDiagnostic(); + diagnostic = new(); var context = new ParsingContext(diagnostic) { ExtensionParsers = _settings.ExtensionParsers @@ -195,7 +195,7 @@ public T ReadFragment(YamlDocument input, OpenApiSpecVersion version, out Ope } catch (OpenApiException ex) { - diagnostic.Errors.Add(new OpenApiError(ex)); + diagnostic.Errors.Add(new(ex)); } // Validate the element diff --git a/src/Microsoft.OpenApi.Readers/ParseNodes/ListNode.cs b/src/Microsoft.OpenApi.Readers/ParseNodes/ListNode.cs index bbc9e30b8..bfb9a554f 100644 --- a/src/Microsoft.OpenApi.Readers/ParseNodes/ListNode.cs +++ b/src/Microsoft.OpenApi.Readers/ParseNodes/ListNode.cs @@ -29,7 +29,7 @@ public override List CreateList(Func map) $"Expected list at line {_nodeList.Start.Line} while parsing {typeof(T).Name}", _nodeList); } - return _nodeList.Select(n => map(new MapNode(Context, n as YamlMappingNode))) + return _nodeList.Select(n => map(new(Context, n as YamlMappingNode))) .Where(i => i != null) .ToList(); } @@ -49,7 +49,7 @@ public override List CreateSimpleList(Func map) $"Expected list at line {_nodeList.Start.Line} while parsing {typeof(T).Name}", _nodeList); } - return _nodeList.Select(n => map(new ValueNode(Context, n))).ToList(); + return _nodeList.Select(n => map(new(Context, n))).ToList(); } public IEnumerator GetEnumerator() diff --git a/src/Microsoft.OpenApi.Readers/ParseNodes/MapNode.cs b/src/Microsoft.OpenApi.Readers/ParseNodes/MapNode.cs index b5107b743..c924311d7 100644 --- a/src/Microsoft.OpenApi.Readers/ParseNodes/MapNode.cs +++ b/src/Microsoft.OpenApi.Readers/ParseNodes/MapNode.cs @@ -49,7 +49,7 @@ public PropertyNode this[string key] { if (this._node.Children.TryGetValue(new YamlScalarNode(key), out var node)) { - return new PropertyNode(Context, key, node); + return new(Context, key, node); } return null; @@ -74,7 +74,7 @@ public override Dictionary CreateMap(Func map) Context.StartObject(key); value = n.Value as YamlMappingNode == null ? default - : map(new MapNode(Context, n.Value as YamlMappingNode)); + : map(new(Context, n.Value as YamlMappingNode)); } finally { @@ -110,7 +110,7 @@ public override Dictionary CreateMapWithReference( Context.StartObject(key); entry = ( key: key, - value: map(new MapNode(Context, (YamlMappingNode)n.Value)) + value: map(new(Context, (YamlMappingNode)n.Value)) ); if (entry.value == null) { @@ -119,7 +119,7 @@ public override Dictionary CreateMapWithReference( // If the component isn't a reference to another component, then point it to itself. if (entry.value.Reference == null) { - entry.value.Reference = new OpenApiReference + entry.value.Reference = new() { Type = referenceType, Id = entry.key @@ -155,7 +155,7 @@ public override Dictionary CreateSimpleMap(Func map) { throw new OpenApiReaderException($"Expected scalar while parsing {typeof(T).Name}", Context); } - return (key, value: map(new ValueNode(Context, (YamlScalarNode)n.Value))); + return (key, value: map(new(Context, (YamlScalarNode)n.Value))); } finally { Context.EndObject(); } @@ -175,14 +175,14 @@ IEnumerator IEnumerable.GetEnumerator() public override string GetRaw() { - var x = new Serializer(new SerializerSettings(new JsonSchema()) { EmitJsonComptible = true }); + var x = new Serializer(new(new JsonSchema()) { EmitJsonComptible = true }); return x.Serialize(_node); } public T GetReferencedObject(ReferenceType referenceType, string referenceId) where T : IOpenApiReferenceable, new() { - return new T + return new() { UnresolvedReference = true, Reference = Context.VersionService.ConvertToOpenApiReference(referenceId, referenceType) diff --git a/src/Microsoft.OpenApi.Readers/ParseNodes/PropertyNode.cs b/src/Microsoft.OpenApi.Readers/ParseNodes/PropertyNode.cs index 7927520c7..6a059c348 100644 --- a/src/Microsoft.OpenApi.Readers/ParseNodes/PropertyNode.cs +++ b/src/Microsoft.OpenApi.Readers/ParseNodes/PropertyNode.cs @@ -6,7 +6,6 @@ using System.Linq; using Microsoft.OpenApi.Any; using Microsoft.OpenApi.Exceptions; -using Microsoft.OpenApi.Models; using Microsoft.OpenApi.Readers.Exceptions; using SharpYaml.Serialization; @@ -39,12 +38,12 @@ public void ParseField( } catch (OpenApiReaderException ex) { - Context.Diagnostic.Errors.Add(new OpenApiError(ex)); + Context.Diagnostic.Errors.Add(new(ex)); } catch (OpenApiException ex) { ex.Pointer = Context.GetLocation(); - Context.Diagnostic.Errors.Add(new OpenApiError(ex)); + Context.Diagnostic.Errors.Add(new(ex)); } finally { @@ -63,12 +62,12 @@ public void ParseField( } catch (OpenApiReaderException ex) { - Context.Diagnostic.Errors.Add(new OpenApiError(ex)); + Context.Diagnostic.Errors.Add(new(ex)); } catch (OpenApiException ex) { ex.Pointer = Context.GetLocation(); - Context.Diagnostic.Errors.Add(new OpenApiError(ex)); + Context.Diagnostic.Errors.Add(new(ex)); } finally { @@ -78,7 +77,7 @@ public void ParseField( else { Context.Diagnostic.Errors.Add( - new OpenApiError("", $"{Name} is not a valid property at {Context.GetLocation()}")); + new("", $"{Name} is not a valid property at {Context.GetLocation()}")); } } } diff --git a/src/Microsoft.OpenApi.Readers/ParseNodes/RootNode.cs b/src/Microsoft.OpenApi.Readers/ParseNodes/RootNode.cs index d9f18603f..f70b9ca99 100644 --- a/src/Microsoft.OpenApi.Readers/ParseNodes/RootNode.cs +++ b/src/Microsoft.OpenApi.Readers/ParseNodes/RootNode.cs @@ -32,7 +32,7 @@ public ParseNode Find(JsonPointer referencePointer) public MapNode GetMap() { - return new MapNode(Context, (YamlMappingNode)_yamlDocument.RootNode); + return new(Context, (YamlMappingNode)_yamlDocument.RootNode); } } } diff --git a/src/Microsoft.OpenApi.Readers/ParsingContext.cs b/src/Microsoft.OpenApi.Readers/ParsingContext.cs index 781a16ed8..93a7d6564 100644 --- a/src/Microsoft.OpenApi.Readers/ParsingContext.cs +++ b/src/Microsoft.OpenApi.Readers/ParsingContext.cs @@ -21,13 +21,13 @@ namespace Microsoft.OpenApi.Readers /// public class ParsingContext { - private readonly Stack _currentLocation = new Stack(); - private readonly Dictionary _tempStorage = new Dictionary(); - private readonly Dictionary> _scopedTempStorage = new Dictionary>(); - private readonly Dictionary> _loopStacks = new Dictionary>(); - internal Dictionary> ExtensionParsers { get; set; } = new Dictionary>(); + private readonly Stack _currentLocation = new(); + private readonly Dictionary _tempStorage = new(); + private readonly Dictionary> _scopedTempStorage = new(); + private readonly Dictionary> _loopStacks = new(); + internal Dictionary> ExtensionParsers { get; set; } = new(); internal RootNode RootNode { get; set; } - internal List Tags { get; private set; } = new List(); + internal List Tags { get; private set; } = new(); internal Uri BaseUrl { get; set; } internal List DefaultContentType { get; set; } @@ -52,7 +52,7 @@ public ParsingContext(OpenApiDiagnostic diagnostic) /// An OpenApiDocument populated based on the passed yamlDocument internal OpenApiDocument Parse(YamlDocument yamlDocument) { - RootNode = new RootNode(this, yamlDocument); + RootNode = new(this, yamlDocument); var inputVersion = GetVersion(RootNode); @@ -112,14 +112,14 @@ internal T ParseFragment(YamlDocument yamlDocument, OpenApiSpecVersion versio /// private static string GetVersion(RootNode rootNode) { - var versionNode = rootNode.Find(new JsonPointer("/openapi")); + var versionNode = rootNode.Find(new("/openapi")); if (versionNode != null) { return versionNode.GetScalarValue(); } - versionNode = rootNode.Find(new JsonPointer("/swagger")); + versionNode = rootNode.Find(new("/swagger")); return versionNode?.GetScalarValue(); } @@ -177,7 +177,7 @@ public void SetTempStorage(string key, object value, object scope = null) } else if (!_scopedTempStorage.TryGetValue(scope, out storage)) { - storage = _scopedTempStorage[scope] = new Dictionary(); + storage = _scopedTempStorage[scope] = new(); } if (value == null) @@ -208,7 +208,7 @@ public bool PushLoop(string loopId, string key) { if (!_loopStacks.TryGetValue(loopId, out var stack)) { - stack = new Stack(); + stack = new(); _loopStacks.Add(loopId, stack); } diff --git a/src/Microsoft.OpenApi.Readers/Services/DefaultStreamLoader.cs b/src/Microsoft.OpenApi.Readers/Services/DefaultStreamLoader.cs index 69f2a49de..5ef282156 100644 --- a/src/Microsoft.OpenApi.Readers/Services/DefaultStreamLoader.cs +++ b/src/Microsoft.OpenApi.Readers/Services/DefaultStreamLoader.cs @@ -15,7 +15,7 @@ namespace Microsoft.OpenApi.Readers.Services internal class DefaultStreamLoader : IStreamLoader { private readonly Uri baseUrl; - private HttpClient _httpClient = new HttpClient(); + private HttpClient _httpClient = new(); public DefaultStreamLoader(Uri baseUrl) { diff --git a/src/Microsoft.OpenApi.Readers/Services/OpenApiRemoteReferenceCollector.cs b/src/Microsoft.OpenApi.Readers/Services/OpenApiRemoteReferenceCollector.cs index c42d39690..90cd3632c 100644 --- a/src/Microsoft.OpenApi.Readers/Services/OpenApiRemoteReferenceCollector.cs +++ b/src/Microsoft.OpenApi.Readers/Services/OpenApiRemoteReferenceCollector.cs @@ -13,7 +13,7 @@ namespace Microsoft.OpenApi.Readers.Services /// internal class OpenApiRemoteReferenceCollector : OpenApiVisitorBase { - private Dictionary _references = new Dictionary(); + private Dictionary _references = new(); /// /// List of external references collected from OpenApiDocument diff --git a/src/Microsoft.OpenApi.Readers/Services/OpenApiWorkspaceLoader.cs b/src/Microsoft.OpenApi.Readers/Services/OpenApiWorkspaceLoader.cs index 847e73ce1..c2d1cfe3c 100644 --- a/src/Microsoft.OpenApi.Readers/Services/OpenApiWorkspaceLoader.cs +++ b/src/Microsoft.OpenApi.Readers/Services/OpenApiWorkspaceLoader.cs @@ -34,7 +34,7 @@ internal async Task LoadAsync(OpenApiReference reference, Ope if (diagnostic is null) { - diagnostic = new OpenApiDiagnostic(); + diagnostic = new(); } // Walk references @@ -43,7 +43,7 @@ internal async Task LoadAsync(OpenApiReference reference, Ope // If not already in workspace, load it and process references if (!_workspace.Contains(item.ExternalResource)) { - var input = await _loader.LoadAsync(new Uri(item.ExternalResource, UriKind.RelativeOrAbsolute)); + var input = await _loader.LoadAsync(new(item.ExternalResource, UriKind.RelativeOrAbsolute)); var result = await reader.ReadAsync(input, cancellationToken); // Merge diagnostics if (result.OpenApiDiagnostic != null) diff --git a/src/Microsoft.OpenApi.Readers/V2/OpenApiContactDeserializer.cs b/src/Microsoft.OpenApi.Readers/V2/OpenApiContactDeserializer.cs index c25f5d0c8..43824c244 100644 --- a/src/Microsoft.OpenApi.Readers/V2/OpenApiContactDeserializer.cs +++ b/src/Microsoft.OpenApi.Readers/V2/OpenApiContactDeserializer.cs @@ -14,7 +14,7 @@ namespace Microsoft.OpenApi.Readers.V2 /// internal static partial class OpenApiV2Deserializer { - private static FixedFieldMap _contactFixedFields = new FixedFieldMap + private static FixedFieldMap _contactFixedFields = new() { { "name", (o, n) => @@ -25,7 +25,7 @@ internal static partial class OpenApiV2Deserializer { "url", (o, n) => { - o.Url = new Uri(n.GetScalarValue(), UriKind.RelativeOrAbsolute); + o.Url = new(n.GetScalarValue(), UriKind.RelativeOrAbsolute); } }, { @@ -36,7 +36,7 @@ internal static partial class OpenApiV2Deserializer }, }; - private static PatternFieldMap _contactPatternFields = new PatternFieldMap + private static PatternFieldMap _contactPatternFields = new() { {s => s.StartsWith("x-"), (o, p, n) => o.AddExtension(p, LoadExtension(p, n))} }; diff --git a/src/Microsoft.OpenApi.Readers/V2/OpenApiDocumentDeserializer.cs b/src/Microsoft.OpenApi.Readers/V2/OpenApiDocumentDeserializer.cs index 05e7b77c9..beba2e815 100644 --- a/src/Microsoft.OpenApi.Readers/V2/OpenApiDocumentDeserializer.cs +++ b/src/Microsoft.OpenApi.Readers/V2/OpenApiDocumentDeserializer.cs @@ -18,7 +18,7 @@ namespace Microsoft.OpenApi.Readers.V2 /// internal static partial class OpenApiV2Deserializer { - private static FixedFieldMap _openApiFixedFields = new FixedFieldMap + private static FixedFieldMap _openApiFixedFields = new() { { "swagger", (o, n) => @@ -60,7 +60,7 @@ internal static partial class OpenApiV2Deserializer { if (o.Components == null) { - o.Components = new OpenApiComponents(); + o.Components = new(); } o.Components.Schemas = n.CreateMapWithReference( @@ -74,7 +74,7 @@ internal static partial class OpenApiV2Deserializer { if (o.Components == null) { - o.Components = new OpenApiComponents(); + o.Components = new(); } o.Components.Parameters = n.CreateMapWithReference( @@ -99,7 +99,7 @@ internal static partial class OpenApiV2Deserializer { if (o.Components == null) { - o.Components = new OpenApiComponents(); + o.Components = new(); } o.Components.Responses = n.CreateMapWithReference( @@ -112,7 +112,7 @@ internal static partial class OpenApiV2Deserializer { if (o.Components == null) { - o.Components = new OpenApiComponents(); + o.Components = new(); } o.Components.SecuritySchemes = n.CreateMapWithReference( @@ -126,7 +126,7 @@ internal static partial class OpenApiV2Deserializer {"externalDocs", (o, n) => o.ExternalDocs = LoadExternalDocs(n)} }; - private static PatternFieldMap _openApiPatternFields = new PatternFieldMap + private static PatternFieldMap _openApiPatternFields = new() { // We have no semantics to verify X- nodes, therefore treat them as just values. {s => s.StartsWith("x-"), (o, p, n) => o.AddExtension(p, LoadExtension(p, n))} @@ -154,7 +154,7 @@ private static void MakeServers(IList servers, ParsingContext con //Validate host if (host != null && !IsHostValid(host)) { - rootNode.Context.Diagnostic.Errors.Add(new OpenApiError(rootNode.Context.GetLocation(), "Invalid host")); + rootNode.Context.Diagnostic.Errors.Add(new(rootNode.Context.GetLocation(), "Invalid host")); return; } @@ -331,10 +331,10 @@ public override void Visit(OpenApiOperation operation) if (body != null) { operation.Parameters.Remove(body); - operation.RequestBody = new OpenApiRequestBody + operation.RequestBody = new() { UnresolvedReference = true, - Reference = new OpenApiReference + Reference = new() { Id = body.Reference.Id, Type = ReferenceType.RequestBody diff --git a/src/Microsoft.OpenApi.Readers/V2/OpenApiExternalDocsDeserializer.cs b/src/Microsoft.OpenApi.Readers/V2/OpenApiExternalDocsDeserializer.cs index 2636bd48b..fd2a8f07d 100644 --- a/src/Microsoft.OpenApi.Readers/V2/OpenApiExternalDocsDeserializer.cs +++ b/src/Microsoft.OpenApi.Readers/V2/OpenApiExternalDocsDeserializer.cs @@ -15,7 +15,7 @@ namespace Microsoft.OpenApi.Readers.V2 internal static partial class OpenApiV2Deserializer { private static readonly FixedFieldMap _externalDocsFixedFields = - new FixedFieldMap + new() { { OpenApiConstants.Description, (o, n) => @@ -26,13 +26,14 @@ internal static partial class OpenApiV2Deserializer { OpenApiConstants.Url, (o, n) => { - o.Url = new Uri(n.GetScalarValue(), UriKind.RelativeOrAbsolute); + o.Url = new(n.GetScalarValue(), UriKind.RelativeOrAbsolute); } }, }; private static readonly PatternFieldMap _externalDocsPatternFields = - new PatternFieldMap { + new() + { {s => s.StartsWith("x-"), (o, p, n) => o.AddExtension(p, LoadExtension(p, n))} }; diff --git a/src/Microsoft.OpenApi.Readers/V2/OpenApiHeaderDeserializer.cs b/src/Microsoft.OpenApi.Readers/V2/OpenApiHeaderDeserializer.cs index 821e08a26..d1d6dab0b 100644 --- a/src/Microsoft.OpenApi.Readers/V2/OpenApiHeaderDeserializer.cs +++ b/src/Microsoft.OpenApi.Readers/V2/OpenApiHeaderDeserializer.cs @@ -16,7 +16,7 @@ namespace Microsoft.OpenApi.Readers.V2 /// internal static partial class OpenApiV2Deserializer { - private static readonly FixedFieldMap _headerFixedFields = new FixedFieldMap + private static readonly FixedFieldMap _headerFixedFields = new() { { "description", (o, n) => @@ -128,17 +128,17 @@ internal static partial class OpenApiV2Deserializer } }; - private static readonly PatternFieldMap _headerPatternFields = new PatternFieldMap + private static readonly PatternFieldMap _headerPatternFields = new() { {s => s.StartsWith("x-"), (o, p, n) => o.AddExtension(p, LoadExtension(p, n))} }; private static readonly AnyFieldMap _headerAnyFields = - new AnyFieldMap + new() { { OpenApiConstants.Default, - new AnyFieldMapParameter( + new( p => p.Schema?.Default, (p, v) => { @@ -150,11 +150,11 @@ internal static partial class OpenApiV2Deserializer }; private static readonly AnyListFieldMap _headerAnyListFields = - new AnyListFieldMap + new() { { OpenApiConstants.Enum, - new AnyListFieldMapParameter( + new( p => p.Schema?.Enum, (p, v) => { diff --git a/src/Microsoft.OpenApi.Readers/V2/OpenApiInfoDeserializer.cs b/src/Microsoft.OpenApi.Readers/V2/OpenApiInfoDeserializer.cs index 72f347c39..ffe9045d3 100644 --- a/src/Microsoft.OpenApi.Readers/V2/OpenApiInfoDeserializer.cs +++ b/src/Microsoft.OpenApi.Readers/V2/OpenApiInfoDeserializer.cs @@ -14,7 +14,7 @@ namespace Microsoft.OpenApi.Readers.V2 /// internal static partial class OpenApiV2Deserializer { - private static FixedFieldMap _infoFixedFields = new FixedFieldMap + private static FixedFieldMap _infoFixedFields = new() { { "title", (o, n) => @@ -31,7 +31,7 @@ internal static partial class OpenApiV2Deserializer { "termsOfService", (o, n) => { - o.TermsOfService = new Uri(n.GetScalarValue(), UriKind.RelativeOrAbsolute); + o.TermsOfService = new(n.GetScalarValue(), UriKind.RelativeOrAbsolute); } }, { @@ -54,7 +54,7 @@ internal static partial class OpenApiV2Deserializer } }; - private static PatternFieldMap _infoPatternFields = new PatternFieldMap + private static PatternFieldMap _infoPatternFields = new() { {s => s.StartsWith("x-"), (o, p, n) => o.AddExtension(p, LoadExtension(p, n))} }; diff --git a/src/Microsoft.OpenApi.Readers/V2/OpenApiLicenseDeserializer.cs b/src/Microsoft.OpenApi.Readers/V2/OpenApiLicenseDeserializer.cs index 6a7445e73..965675143 100644 --- a/src/Microsoft.OpenApi.Readers/V2/OpenApiLicenseDeserializer.cs +++ b/src/Microsoft.OpenApi.Readers/V2/OpenApiLicenseDeserializer.cs @@ -14,7 +14,7 @@ namespace Microsoft.OpenApi.Readers.V2 /// internal static partial class OpenApiV2Deserializer { - private static FixedFieldMap _licenseFixedFields = new FixedFieldMap + private static FixedFieldMap _licenseFixedFields = new() { { "name", (o, n) => @@ -25,12 +25,12 @@ internal static partial class OpenApiV2Deserializer { "url", (o, n) => { - o.Url = new Uri(n.GetScalarValue(), UriKind.RelativeOrAbsolute); + o.Url = new(n.GetScalarValue(), UriKind.RelativeOrAbsolute); } }, }; - private static PatternFieldMap _licensePatternFields = new PatternFieldMap + private static PatternFieldMap _licensePatternFields = new() { {s => s.StartsWith("x-"), (o, p, n) => o.AddExtension(p, LoadExtension(p, n))} }; diff --git a/src/Microsoft.OpenApi.Readers/V2/OpenApiOperationDeserializer.cs b/src/Microsoft.OpenApi.Readers/V2/OpenApiOperationDeserializer.cs index e2be3ea6a..c7a7d723b 100644 --- a/src/Microsoft.OpenApi.Readers/V2/OpenApiOperationDeserializer.cs +++ b/src/Microsoft.OpenApi.Readers/V2/OpenApiOperationDeserializer.cs @@ -17,7 +17,7 @@ namespace Microsoft.OpenApi.Readers.V2 internal static partial class OpenApiV2Deserializer { private static readonly FixedFieldMap _operationFixedFields = - new FixedFieldMap + new() { { "tags", (o, n) => o.Tags = n.CreateSimpleList( @@ -93,16 +93,15 @@ internal static partial class OpenApiV2Deserializer }; private static readonly PatternFieldMap _operationPatternFields = - new PatternFieldMap + new() { {s => s.StartsWith("x-"), (o, p, n) => o.AddExtension(p, LoadExtension(p, n))} }; - private static readonly FixedFieldMap _responsesFixedFields = - new FixedFieldMap(); + private static readonly FixedFieldMap _responsesFixedFields = new(); private static readonly PatternFieldMap _responsesPatternFields = - new PatternFieldMap + new() { {s => !s.StartsWith("x-"), (o, p, n) => o.Add(p, LoadResponse(n))}, {s => s.StartsWith("x-"), (o, p, n) => o.AddExtension(p, LoadExtension(p, n))} @@ -163,7 +162,7 @@ private static OpenApiRequestBody CreateFormBody(ParsingContext context, List k.Name, @@ -224,7 +223,7 @@ private static OpenApiTag LoadTagByReference( var tagObject = new OpenApiTag { UnresolvedReference = true, - Reference = new OpenApiReference { Id = tagName, Type = ReferenceType.Tag } + Reference = new() { Id = tagName, Type = ReferenceType.Tag } }; return tagObject; diff --git a/src/Microsoft.OpenApi.Readers/V2/OpenApiParameterDeserializer.cs b/src/Microsoft.OpenApi.Readers/V2/OpenApiParameterDeserializer.cs index aea3b62df..b0013d9ae 100644 --- a/src/Microsoft.OpenApi.Readers/V2/OpenApiParameterDeserializer.cs +++ b/src/Microsoft.OpenApi.Readers/V2/OpenApiParameterDeserializer.cs @@ -17,7 +17,7 @@ namespace Microsoft.OpenApi.Readers.V2 internal static partial class OpenApiV2Deserializer { private static readonly FixedFieldMap _parameterFixedFields = - new FixedFieldMap + new() { { "name", (o, n) => @@ -136,17 +136,17 @@ internal static partial class OpenApiV2Deserializer }; private static readonly PatternFieldMap _parameterPatternFields = - new PatternFieldMap + new() { {s => s.StartsWith("x-"), (o, p, n) => o.AddExtension(p, LoadExtension(p, n))} }; private static readonly AnyFieldMap _parameterAnyFields = - new AnyFieldMap + new() { { OpenApiConstants.Default, - new AnyFieldMapParameter( + new( p => p.Schema?.Default, (p, v) => { if (p.Schema != null || v != null) @@ -159,11 +159,11 @@ internal static partial class OpenApiV2Deserializer }; private static readonly AnyListFieldMap _parameterAnyListFields = - new AnyListFieldMap + new() { { OpenApiConstants.Enum, - new AnyListFieldMapParameter( + new( p => p.Schema?.Enum, (p, v) => { if (p.Schema != null || v != null && v.Count > 0) @@ -208,7 +208,7 @@ private static OpenApiSchema GetOrCreateSchema(OpenApiParameter p) { if (p.Schema == null) { - p.Schema = new OpenApiSchema(); + p.Schema = new(); } return p.Schema; @@ -218,7 +218,7 @@ private static OpenApiSchema GetOrCreateSchema(OpenApiHeader p) { if (p.Schema == null) { - p.Schema = new OpenApiSchema(); + p.Schema = new(); } return p.Schema; @@ -238,7 +238,7 @@ private static void ProcessIn(OpenApiParameter o, ParseNode n) var formParameters = n.Context.GetFromTempStorage>("formParameters"); if (formParameters == null) { - formParameters = new List(); + formParameters = new(); n.Context.SetTempStorage("formParameters", formParameters); } diff --git a/src/Microsoft.OpenApi.Readers/V2/OpenApiPathItemDeserializer.cs b/src/Microsoft.OpenApi.Readers/V2/OpenApiPathItemDeserializer.cs index 2eee6719a..d0dd4af8c 100644 --- a/src/Microsoft.OpenApi.Readers/V2/OpenApiPathItemDeserializer.cs +++ b/src/Microsoft.OpenApi.Readers/V2/OpenApiPathItemDeserializer.cs @@ -15,12 +15,12 @@ namespace Microsoft.OpenApi.Readers.V2 /// internal static partial class OpenApiV2Deserializer { - private static readonly FixedFieldMap _pathItemFixedFields = new FixedFieldMap + private static readonly FixedFieldMap _pathItemFixedFields = new() { { "$ref", (o, n) => { - o.Reference = new OpenApiReference { ExternalResource = n.GetScalarValue() }; + o.Reference = new() { ExternalResource = n.GetScalarValue() }; o.UnresolvedReference =true; } }, @@ -40,7 +40,7 @@ internal static partial class OpenApiV2Deserializer }; private static readonly PatternFieldMap _pathItemPatternFields = - new PatternFieldMap + new() { {s => s.StartsWith("x-"), (o, p, n) => o.AddExtension(p, LoadExtension(p, n))}, }; diff --git a/src/Microsoft.OpenApi.Readers/V2/OpenApiPathsDeserializer.cs b/src/Microsoft.OpenApi.Readers/V2/OpenApiPathsDeserializer.cs index 611eee485..8e026b7f7 100644 --- a/src/Microsoft.OpenApi.Readers/V2/OpenApiPathsDeserializer.cs +++ b/src/Microsoft.OpenApi.Readers/V2/OpenApiPathsDeserializer.cs @@ -13,9 +13,9 @@ namespace Microsoft.OpenApi.Readers.V2 /// internal static partial class OpenApiV2Deserializer { - private static FixedFieldMap _pathsFixedFields = new FixedFieldMap(); + private static FixedFieldMap _pathsFixedFields = new(); - private static PatternFieldMap _pathsPatternFields = new PatternFieldMap + private static PatternFieldMap _pathsPatternFields = new() { {s => s.StartsWith("/"), (o, k, n) => o.Add(k, LoadPathItem(n))}, {s => s.StartsWith("x-"), (o, p, n) => o.AddExtension(p, LoadExtension(p, n))} diff --git a/src/Microsoft.OpenApi.Readers/V2/OpenApiResponseDeserializer.cs b/src/Microsoft.OpenApi.Readers/V2/OpenApiResponseDeserializer.cs index ad361222f..5c6a4ebb7 100644 --- a/src/Microsoft.OpenApi.Readers/V2/OpenApiResponseDeserializer.cs +++ b/src/Microsoft.OpenApi.Readers/V2/OpenApiResponseDeserializer.cs @@ -14,7 +14,7 @@ namespace Microsoft.OpenApi.Readers.V2 /// internal static partial class OpenApiV2Deserializer { - private static readonly FixedFieldMap _responseFixedFields = new FixedFieldMap + private static readonly FixedFieldMap _responseFixedFields = new() { { "description", (o, n) => @@ -43,17 +43,17 @@ internal static partial class OpenApiV2Deserializer }; private static readonly PatternFieldMap _responsePatternFields = - new PatternFieldMap + new() { {s => s.StartsWith("x-"), (o, p, n) => o.AddExtension(p, LoadExtension(p, n))} }; private static readonly AnyFieldMap _mediaTypeAnyFields = - new AnyFieldMap + new() { { OpenApiConstants.Example, - new AnyFieldMapParameter( + new( m => m.Example, (m, v) => m.Example = v, m => m.Schema) @@ -128,7 +128,7 @@ private static void LoadExample(OpenApiResponse response, string mediaType, Pars } else { - mediaTypeObject = new OpenApiMediaType + mediaTypeObject = new() { Schema = node.Context.GetFromTempStorage(TempStorageKeys.ResponseSchema, response) }; diff --git a/src/Microsoft.OpenApi.Readers/V2/OpenApiSchemaDeserializer.cs b/src/Microsoft.OpenApi.Readers/V2/OpenApiSchemaDeserializer.cs index 2a0c71a72..f1b787c2d 100644 --- a/src/Microsoft.OpenApi.Readers/V2/OpenApiSchemaDeserializer.cs +++ b/src/Microsoft.OpenApi.Readers/V2/OpenApiSchemaDeserializer.cs @@ -15,7 +15,7 @@ namespace Microsoft.OpenApi.Readers.V2 /// internal static partial class OpenApiV2Deserializer { - private static readonly FixedFieldMap _schemaFixedFields = new FixedFieldMap + private static readonly FixedFieldMap _schemaFixedFields = new() { { "title", (o, n) => @@ -172,7 +172,7 @@ internal static partial class OpenApiV2Deserializer { "discriminator", (o, n) => { - o.Discriminator = new OpenApiDiscriminator + o.Discriminator = new() { PropertyName = n.GetScalarValue() }; @@ -204,33 +204,33 @@ internal static partial class OpenApiV2Deserializer }, }; - private static readonly PatternFieldMap _schemaPatternFields = new PatternFieldMap + private static readonly PatternFieldMap _schemaPatternFields = new() { {s => s.StartsWith("x-"), (o, p, n) => o.AddExtension(p, LoadExtension(p, n))} }; - private static readonly AnyFieldMap _schemaAnyFields = new AnyFieldMap + private static readonly AnyFieldMap _schemaAnyFields = new() { { OpenApiConstants.Default, - new AnyFieldMapParameter( + new( s => s.Default, (s, v) => s.Default = v, s => s) }, { OpenApiConstants.Example, - new AnyFieldMapParameter( + new( s => s.Example, (s, v) => s.Example = v, s => s) } }; - private static readonly AnyListFieldMap _schemaAnyListFields = new AnyListFieldMap + private static readonly AnyListFieldMap _schemaAnyListFields = new() { { OpenApiConstants.Enum, - new AnyListFieldMapParameter( + new( s => s.Enum, (s, v) => s.Enum = v, s => s) diff --git a/src/Microsoft.OpenApi.Readers/V2/OpenApiSecurityRequirementDeserializer.cs b/src/Microsoft.OpenApi.Readers/V2/OpenApiSecurityRequirementDeserializer.cs index 5197b6e1e..b4e578aa1 100644 --- a/src/Microsoft.OpenApi.Readers/V2/OpenApiSecurityRequirementDeserializer.cs +++ b/src/Microsoft.OpenApi.Readers/V2/OpenApiSecurityRequirementDeserializer.cs @@ -33,7 +33,7 @@ public static OpenApiSecurityRequirement LoadSecurityRequirement(ParseNode node) else { mapNode.Context.Diagnostic.Errors.Add( - new OpenApiError(node.Context.GetLocation(), + new(node.Context.GetLocation(), $"Scheme {property.Name} is not found")); } } @@ -48,7 +48,7 @@ private static OpenApiSecurityScheme LoadSecuritySchemeByReference( var securitySchemeObject = new OpenApiSecurityScheme { UnresolvedReference = true, - Reference = new OpenApiReference + Reference = new() { Id = schemeName, Type = ReferenceType.SecurityScheme diff --git a/src/Microsoft.OpenApi.Readers/V2/OpenApiSecuritySchemeDeserializer.cs b/src/Microsoft.OpenApi.Readers/V2/OpenApiSecuritySchemeDeserializer.cs index 20de9c880..3cb9efe52 100644 --- a/src/Microsoft.OpenApi.Readers/V2/OpenApiSecuritySchemeDeserializer.cs +++ b/src/Microsoft.OpenApi.Readers/V2/OpenApiSecuritySchemeDeserializer.cs @@ -19,7 +19,7 @@ internal static partial class OpenApiV2Deserializer private static OpenApiOAuthFlow _flow; private static readonly FixedFieldMap _securitySchemeFixedFields = - new FixedFieldMap + new() { { "type", @@ -56,14 +56,14 @@ internal static partial class OpenApiV2Deserializer "authorizationUrl", (o, n) => { - _flow.AuthorizationUrl = new Uri(n.GetScalarValue(), UriKind.RelativeOrAbsolute); + _flow.AuthorizationUrl = new(n.GetScalarValue(), UriKind.RelativeOrAbsolute); } }, { "tokenUrl", (o, n) => { - _flow.TokenUrl = new Uri(n.GetScalarValue(), UriKind.RelativeOrAbsolute); + _flow.TokenUrl = new(n.GetScalarValue(), UriKind.RelativeOrAbsolute); } }, { @@ -75,7 +75,7 @@ internal static partial class OpenApiV2Deserializer }; private static readonly PatternFieldMap _securitySchemePatternFields = - new PatternFieldMap + new() { {s => s.StartsWith("x-"), (o, p, n) => o.AddExtension(p, LoadExtension(p, n))} }; @@ -85,7 +85,7 @@ public static OpenApiSecurityScheme LoadSecurityScheme(ParseNode node) // Reset the local variables every time this method is called. // TODO: Change _flow to a tempStorage variable to make the deserializer thread-safe. _flowValue = null; - _flow = new OpenApiOAuthFlow(); + _flow = new(); var mapNode = node.CheckMapNode("securityScheme"); @@ -98,28 +98,28 @@ public static OpenApiSecurityScheme LoadSecurityScheme(ParseNode node) // Put the Flow object in the right Flows property based on the string in "flow" if (_flowValue == OpenApiConstants.Implicit) { - securityScheme.Flows = new OpenApiOAuthFlows + securityScheme.Flows = new() { Implicit = _flow }; } else if (_flowValue == OpenApiConstants.Password) { - securityScheme.Flows = new OpenApiOAuthFlows + securityScheme.Flows = new() { Password = _flow }; } else if (_flowValue == OpenApiConstants.Application) { - securityScheme.Flows = new OpenApiOAuthFlows + securityScheme.Flows = new() { ClientCredentials = _flow }; } else if (_flowValue == OpenApiConstants.AccessCode) { - securityScheme.Flows = new OpenApiOAuthFlows + securityScheme.Flows = new() { AuthorizationCode = _flow }; diff --git a/src/Microsoft.OpenApi.Readers/V2/OpenApiTagDeserializer.cs b/src/Microsoft.OpenApi.Readers/V2/OpenApiTagDeserializer.cs index ecd6c96c3..6bdd60692 100644 --- a/src/Microsoft.OpenApi.Readers/V2/OpenApiTagDeserializer.cs +++ b/src/Microsoft.OpenApi.Readers/V2/OpenApiTagDeserializer.cs @@ -13,7 +13,7 @@ namespace Microsoft.OpenApi.Readers.V2 /// internal static partial class OpenApiV2Deserializer { - private static readonly FixedFieldMap _tagFixedFields = new FixedFieldMap + private static readonly FixedFieldMap _tagFixedFields = new() { { OpenApiConstants.Name, (o, n) => @@ -35,7 +35,7 @@ internal static partial class OpenApiV2Deserializer } }; - private static readonly PatternFieldMap _tagPatternFields = new PatternFieldMap + private static readonly PatternFieldMap _tagPatternFields = new() { {s => s.StartsWith("x-"), (o, p, n) => o.AddExtension(p, LoadExtension(p, n))} }; diff --git a/src/Microsoft.OpenApi.Readers/V2/OpenApiV2Deserializer.cs b/src/Microsoft.OpenApi.Readers/V2/OpenApiV2Deserializer.cs index 6b7aea308..8b10bb83f 100644 --- a/src/Microsoft.OpenApi.Readers/V2/OpenApiV2Deserializer.cs +++ b/src/Microsoft.OpenApi.Readers/V2/OpenApiV2Deserializer.cs @@ -6,7 +6,6 @@ using Microsoft.OpenApi.Any; using Microsoft.OpenApi.Exceptions; using Microsoft.OpenApi.Interfaces; -using Microsoft.OpenApi.Models; using Microsoft.OpenApi.Readers.ParseNodes; namespace Microsoft.OpenApi.Readers.V2 @@ -57,7 +56,7 @@ private static void ProcessAnyFields( catch (OpenApiException exception) { exception.Pointer = mapNode.Context.GetLocation(); - mapNode.Context.Diagnostic.Errors.Add(new OpenApiError(exception)); + mapNode.Context.Diagnostic.Errors.Add(new(exception)); } finally { @@ -98,7 +97,7 @@ private static void ProcessAnyListFields( catch (OpenApiException exception) { exception.Pointer = mapNode.Context.GetLocation(); - mapNode.Context.Diagnostic.Errors.Add(new OpenApiError(exception)); + mapNode.Context.Diagnostic.Errors.Add(new(exception)); } finally { diff --git a/src/Microsoft.OpenApi.Readers/V2/OpenApiV2VersionService.cs b/src/Microsoft.OpenApi.Readers/V2/OpenApiV2VersionService.cs index dfb975175..20490aca7 100644 --- a/src/Microsoft.OpenApi.Readers/V2/OpenApiV2VersionService.cs +++ b/src/Microsoft.OpenApi.Readers/V2/OpenApiV2VersionService.cs @@ -70,7 +70,7 @@ private static OpenApiReference ParseLocalReference(string localReference) var id = localReference.Substring( segments[0].Length + "/".Length + segments[1].Length + "/".Length); - return new OpenApiReference { Type = referenceType, Id = id }; + return new() { Type = referenceType, Id = id }; } throw new OpenApiException( @@ -145,7 +145,7 @@ public OpenApiReference ConvertToOpenApiReference(string reference, ReferenceTyp if (type == null) { // "$ref": "Pet.json" - return new OpenApiReference + return new() { ExternalResource = segments[0] }; @@ -153,7 +153,7 @@ public OpenApiReference ConvertToOpenApiReference(string reference, ReferenceTyp if (type is ReferenceType.Tag or ReferenceType.SecurityScheme) { - return new OpenApiReference + return new() { Type = type, Id = reference @@ -171,7 +171,7 @@ public OpenApiReference ConvertToOpenApiReference(string reference, ReferenceTyp } catch (OpenApiException ex) { - Diagnostic.Errors.Add(new OpenApiError(ex)); + Diagnostic.Errors.Add(new(ex)); return null; } } @@ -198,7 +198,7 @@ public OpenApiReference ConvertToOpenApiReference(string reference, ReferenceTyp } // $ref: externalSource.yaml#/Pet - return new OpenApiReference + return new() { ExternalResource = segments[0], Type = type, diff --git a/src/Microsoft.OpenApi.Readers/V2/OpenApiXmlDeserializer.cs b/src/Microsoft.OpenApi.Readers/V2/OpenApiXmlDeserializer.cs index c251faaf4..3be5bfe7b 100644 --- a/src/Microsoft.OpenApi.Readers/V2/OpenApiXmlDeserializer.cs +++ b/src/Microsoft.OpenApi.Readers/V2/OpenApiXmlDeserializer.cs @@ -15,7 +15,7 @@ namespace Microsoft.OpenApi.Readers.V2 /// internal static partial class OpenApiV2Deserializer { - private static readonly FixedFieldMap _xmlFixedFields = new FixedFieldMap + private static readonly FixedFieldMap _xmlFixedFields = new() { { "name", (o, n) => @@ -28,7 +28,7 @@ internal static partial class OpenApiV2Deserializer { if (Uri.IsWellFormedUriString(n.GetScalarValue(), UriKind.Absolute)) { - o.Namespace = new Uri(n.GetScalarValue(), UriKind.Absolute); + o.Namespace = new(n.GetScalarValue(), UriKind.Absolute); } else { @@ -57,7 +57,7 @@ internal static partial class OpenApiV2Deserializer }; private static readonly PatternFieldMap _xmlPatternFields = - new PatternFieldMap + new() { {s => s.StartsWith("x-"), (o, p, n) => o.AddExtension(p, LoadExtension(p,n))} }; diff --git a/src/Microsoft.OpenApi.Readers/V3/OpenApiCallbackDeserializer.cs b/src/Microsoft.OpenApi.Readers/V3/OpenApiCallbackDeserializer.cs index c400e8b5b..fc41e7daa 100644 --- a/src/Microsoft.OpenApi.Readers/V3/OpenApiCallbackDeserializer.cs +++ b/src/Microsoft.OpenApi.Readers/V3/OpenApiCallbackDeserializer.cs @@ -14,11 +14,10 @@ namespace Microsoft.OpenApi.Readers.V3 /// internal static partial class OpenApiV3Deserializer { - private static readonly FixedFieldMap _callbackFixedFields = - new FixedFieldMap(); + private static readonly FixedFieldMap _callbackFixedFields = new(); private static readonly PatternFieldMap _callbackPatternFields = - new PatternFieldMap + new() { {s => !s.StartsWith("x-"), (o, p, n) => o.AddPathItem(RuntimeExpression.Build(p), LoadPathItem(n))}, {s => s.StartsWith("x-"), (o, p, n) => o.AddExtension(p, LoadExtension(p,n))}, diff --git a/src/Microsoft.OpenApi.Readers/V3/OpenApiComponentsDeserializer.cs b/src/Microsoft.OpenApi.Readers/V3/OpenApiComponentsDeserializer.cs index cf62bc389..62ed95fda 100644 --- a/src/Microsoft.OpenApi.Readers/V3/OpenApiComponentsDeserializer.cs +++ b/src/Microsoft.OpenApi.Readers/V3/OpenApiComponentsDeserializer.cs @@ -13,7 +13,7 @@ namespace Microsoft.OpenApi.Readers.V3 /// internal static partial class OpenApiV3Deserializer { - private static FixedFieldMap _componentsFixedFields = new FixedFieldMap + private static FixedFieldMap _componentsFixedFields = new() { { "schemas", (o, n) => o.Schemas = n.CreateMapWithReference(ReferenceType.Schema, LoadSchema) @@ -29,7 +29,7 @@ internal static partial class OpenApiV3Deserializer }; private static PatternFieldMap _componentsPatternFields = - new PatternFieldMap + new() { {s => s.StartsWith("x-"), (o, p, n) => o.AddExtension(p, LoadExtension(p, n))} }; diff --git a/src/Microsoft.OpenApi.Readers/V3/OpenApiContactDeserializer.cs b/src/Microsoft.OpenApi.Readers/V3/OpenApiContactDeserializer.cs index 2dfddfb3b..7d9f469f8 100644 --- a/src/Microsoft.OpenApi.Readers/V3/OpenApiContactDeserializer.cs +++ b/src/Microsoft.OpenApi.Readers/V3/OpenApiContactDeserializer.cs @@ -14,7 +14,7 @@ namespace Microsoft.OpenApi.Readers.V3 /// internal static partial class OpenApiV3Deserializer { - private static FixedFieldMap _contactFixedFields = new FixedFieldMap + private static FixedFieldMap _contactFixedFields = new() { { "name", (o, n) => @@ -31,12 +31,12 @@ internal static partial class OpenApiV3Deserializer { "url", (o, n) => { - o.Url = new Uri(n.GetScalarValue(), UriKind.RelativeOrAbsolute); + o.Url = new(n.GetScalarValue(), UriKind.RelativeOrAbsolute); } }, }; - private static PatternFieldMap _contactPatternFields = new PatternFieldMap + private static PatternFieldMap _contactPatternFields = new() { {s => s.StartsWith("x-"), (o, p, n) => o.AddExtension(p, LoadExtension(p,n))} }; diff --git a/src/Microsoft.OpenApi.Readers/V3/OpenApiDiscriminatorDeserializer.cs b/src/Microsoft.OpenApi.Readers/V3/OpenApiDiscriminatorDeserializer.cs index ec3267883..93258cffe 100644 --- a/src/Microsoft.OpenApi.Readers/V3/OpenApiDiscriminatorDeserializer.cs +++ b/src/Microsoft.OpenApi.Readers/V3/OpenApiDiscriminatorDeserializer.cs @@ -13,7 +13,7 @@ namespace Microsoft.OpenApi.Readers.V3 internal static partial class OpenApiV3Deserializer { private static readonly FixedFieldMap _discriminatorFixedFields = - new FixedFieldMap + new() { { "propertyName", (o, n) => @@ -29,8 +29,7 @@ internal static partial class OpenApiV3Deserializer } }; - private static readonly PatternFieldMap _discriminatorPatternFields = - new PatternFieldMap(); + private static readonly PatternFieldMap _discriminatorPatternFields = new(); public static OpenApiDiscriminator LoadDiscriminator(ParseNode node) { diff --git a/src/Microsoft.OpenApi.Readers/V3/OpenApiDocumentDeserializer.cs b/src/Microsoft.OpenApi.Readers/V3/OpenApiDocumentDeserializer.cs index 70551cff3..88cd93000 100644 --- a/src/Microsoft.OpenApi.Readers/V3/OpenApiDocumentDeserializer.cs +++ b/src/Microsoft.OpenApi.Readers/V3/OpenApiDocumentDeserializer.cs @@ -13,7 +13,7 @@ namespace Microsoft.OpenApi.Readers.V3 /// internal static partial class OpenApiV3Deserializer { - private static FixedFieldMap _openApiFixedFields = new FixedFieldMap + private static FixedFieldMap _openApiFixedFields = new() { { "openapi", (o, n) => @@ -27,7 +27,7 @@ internal static partial class OpenApiV3Deserializer {"tags", (o, n) => {o.Tags = n.CreateList(LoadTag); foreach (var tag in o.Tags) { - tag.Reference = new OpenApiReference + tag.Reference = new() { Id = tag.Name, Type = ReferenceType.Tag @@ -38,7 +38,7 @@ internal static partial class OpenApiV3Deserializer {"security", (o, n) => o.SecurityRequirements = n.CreateList(LoadSecurityRequirement)} }; - private static PatternFieldMap _openApiPatternFields = new PatternFieldMap + private static PatternFieldMap _openApiPatternFields = new() { // We have no semantics to verify X- nodes, therefore treat them as just values. {s => s.StartsWith("x-"), (o, p, n) => o.AddExtension(p, LoadExtension(p, n))} diff --git a/src/Microsoft.OpenApi.Readers/V3/OpenApiEncodingDeserializer.cs b/src/Microsoft.OpenApi.Readers/V3/OpenApiEncodingDeserializer.cs index 8459f758b..6a275ff00 100644 --- a/src/Microsoft.OpenApi.Readers/V3/OpenApiEncodingDeserializer.cs +++ b/src/Microsoft.OpenApi.Readers/V3/OpenApiEncodingDeserializer.cs @@ -13,7 +13,7 @@ namespace Microsoft.OpenApi.Readers.V3 /// internal static partial class OpenApiV3Deserializer { - private static readonly FixedFieldMap _encodingFixedFields = new FixedFieldMap + private static readonly FixedFieldMap _encodingFixedFields = new() { { "contentType", (o, n) => @@ -48,7 +48,7 @@ internal static partial class OpenApiV3Deserializer }; private static readonly PatternFieldMap _encodingPatternFields = - new PatternFieldMap + new() { {s => s.StartsWith("x-"), (o, p, n) => o.AddExtension(p, LoadExtension(p,n))} }; diff --git a/src/Microsoft.OpenApi.Readers/V3/OpenApiExampleDeserializer.cs b/src/Microsoft.OpenApi.Readers/V3/OpenApiExampleDeserializer.cs index bd20f677f..ea7e44aed 100644 --- a/src/Microsoft.OpenApi.Readers/V3/OpenApiExampleDeserializer.cs +++ b/src/Microsoft.OpenApi.Readers/V3/OpenApiExampleDeserializer.cs @@ -13,7 +13,7 @@ namespace Microsoft.OpenApi.Readers.V3 /// internal static partial class OpenApiV3Deserializer { - private static readonly FixedFieldMap _exampleFixedFields = new FixedFieldMap + private static readonly FixedFieldMap _exampleFixedFields = new() { { "summary", (o, n) => @@ -42,7 +42,7 @@ internal static partial class OpenApiV3Deserializer }; private static readonly PatternFieldMap _examplePatternFields = - new PatternFieldMap + new() { {s => s.StartsWith("x-"), (o, p, n) => o.AddExtension(p, LoadExtension(p,n))} }; diff --git a/src/Microsoft.OpenApi.Readers/V3/OpenApiExternalDocsDeserializer.cs b/src/Microsoft.OpenApi.Readers/V3/OpenApiExternalDocsDeserializer.cs index 177611dff..f742fb1de 100644 --- a/src/Microsoft.OpenApi.Readers/V3/OpenApiExternalDocsDeserializer.cs +++ b/src/Microsoft.OpenApi.Readers/V3/OpenApiExternalDocsDeserializer.cs @@ -15,7 +15,7 @@ namespace Microsoft.OpenApi.Readers.V3 internal static partial class OpenApiV3Deserializer { private static readonly FixedFieldMap _externalDocsFixedFields = - new FixedFieldMap + new() { // $ref { @@ -27,13 +27,14 @@ internal static partial class OpenApiV3Deserializer { "url", (o, n) => { - o.Url = new Uri(n.GetScalarValue(), UriKind.RelativeOrAbsolute); + o.Url = new(n.GetScalarValue(), UriKind.RelativeOrAbsolute); } }, }; private static readonly PatternFieldMap _externalDocsPatternFields = - new PatternFieldMap { + new() + { {s => s.StartsWith("x-"), (o, p, n) => o.AddExtension(p, LoadExtension(p, n))} }; diff --git a/src/Microsoft.OpenApi.Readers/V3/OpenApiHeaderDeserializer.cs b/src/Microsoft.OpenApi.Readers/V3/OpenApiHeaderDeserializer.cs index f7cd90aca..4b296c046 100644 --- a/src/Microsoft.OpenApi.Readers/V3/OpenApiHeaderDeserializer.cs +++ b/src/Microsoft.OpenApi.Readers/V3/OpenApiHeaderDeserializer.cs @@ -13,7 +13,7 @@ namespace Microsoft.OpenApi.Readers.V3 /// internal static partial class OpenApiV3Deserializer { - private static readonly FixedFieldMap _headerFixedFields = new FixedFieldMap + private static readonly FixedFieldMap _headerFixedFields = new() { { "description", (o, n) => @@ -77,7 +77,7 @@ internal static partial class OpenApiV3Deserializer }, }; - private static readonly PatternFieldMap _headerPatternFields = new PatternFieldMap + private static readonly PatternFieldMap _headerPatternFields = new() { {s => s.StartsWith("x-"), (o, p, n) => o.AddExtension(p, LoadExtension(p,n))} }; diff --git a/src/Microsoft.OpenApi.Readers/V3/OpenApiInfoDeserializer.cs b/src/Microsoft.OpenApi.Readers/V3/OpenApiInfoDeserializer.cs index 8ccbf6d69..11fb88034 100644 --- a/src/Microsoft.OpenApi.Readers/V3/OpenApiInfoDeserializer.cs +++ b/src/Microsoft.OpenApi.Readers/V3/OpenApiInfoDeserializer.cs @@ -15,7 +15,7 @@ namespace Microsoft.OpenApi.Readers.V3 /// internal static partial class OpenApiV3Deserializer { - public static FixedFieldMap InfoFixedFields = new FixedFieldMap + public static FixedFieldMap InfoFixedFields = new() { { "title", (o, n) => @@ -38,7 +38,7 @@ internal static partial class OpenApiV3Deserializer { "termsOfService", (o, n) => { - o.TermsOfService = new Uri(n.GetScalarValue(), UriKind.RelativeOrAbsolute); + o.TermsOfService = new(n.GetScalarValue(), UriKind.RelativeOrAbsolute); } }, { @@ -55,7 +55,7 @@ internal static partial class OpenApiV3Deserializer } }; - public static PatternFieldMap InfoPatternFields = new PatternFieldMap + public static PatternFieldMap InfoPatternFields = new() { {s => s.StartsWith("x-"), (o, k, n) => o.AddExtension(k,LoadExtension(k, n))} }; diff --git a/src/Microsoft.OpenApi.Readers/V3/OpenApiLicenseDeserializer.cs b/src/Microsoft.OpenApi.Readers/V3/OpenApiLicenseDeserializer.cs index 6a27b1286..1582d75b2 100644 --- a/src/Microsoft.OpenApi.Readers/V3/OpenApiLicenseDeserializer.cs +++ b/src/Microsoft.OpenApi.Readers/V3/OpenApiLicenseDeserializer.cs @@ -14,7 +14,7 @@ namespace Microsoft.OpenApi.Readers.V3 /// internal static partial class OpenApiV3Deserializer { - private static FixedFieldMap _licenseFixedFields = new FixedFieldMap + private static FixedFieldMap _licenseFixedFields = new() { { "name", (o, n) => @@ -25,12 +25,12 @@ internal static partial class OpenApiV3Deserializer { "url", (o, n) => { - o.Url = new Uri(n.GetScalarValue(), UriKind.RelativeOrAbsolute); + o.Url = new(n.GetScalarValue(), UriKind.RelativeOrAbsolute); } }, }; - private static PatternFieldMap _licensePatternFields = new PatternFieldMap + private static PatternFieldMap _licensePatternFields = new() { {s => s.StartsWith("x-"), (o, p, n) => o.AddExtension(p, LoadExtension(p,n))} }; diff --git a/src/Microsoft.OpenApi.Readers/V3/OpenApiLinkDeserializer.cs b/src/Microsoft.OpenApi.Readers/V3/OpenApiLinkDeserializer.cs index 9eae96b72..6db2a82fb 100644 --- a/src/Microsoft.OpenApi.Readers/V3/OpenApiLinkDeserializer.cs +++ b/src/Microsoft.OpenApi.Readers/V3/OpenApiLinkDeserializer.cs @@ -13,7 +13,7 @@ namespace Microsoft.OpenApi.Readers.V3 /// internal static partial class OpenApiV3Deserializer { - private static readonly FixedFieldMap _linkFixedFields = new FixedFieldMap + private static readonly FixedFieldMap _linkFixedFields = new() { { "operationRef", (o, n) => @@ -48,7 +48,7 @@ internal static partial class OpenApiV3Deserializer {"server", (o, n) => o.Server = LoadServer(n)} }; - private static readonly PatternFieldMap _linkPatternFields = new PatternFieldMap + private static readonly PatternFieldMap _linkPatternFields = new() { {s => s.StartsWith("x-"), (o, p, n) => o.AddExtension(p, LoadExtension(p,n))}, }; diff --git a/src/Microsoft.OpenApi.Readers/V3/OpenApiMediaTypeDeserializer.cs b/src/Microsoft.OpenApi.Readers/V3/OpenApiMediaTypeDeserializer.cs index b0dbccd91..5ae07962d 100644 --- a/src/Microsoft.OpenApi.Readers/V3/OpenApiMediaTypeDeserializer.cs +++ b/src/Microsoft.OpenApi.Readers/V3/OpenApiMediaTypeDeserializer.cs @@ -14,7 +14,7 @@ namespace Microsoft.OpenApi.Readers.V3 internal static partial class OpenApiV3Deserializer { private static readonly FixedFieldMap _mediaTypeFixedFields = - new FixedFieldMap + new() { { OpenApiConstants.Schema, (o, n) => @@ -43,16 +43,16 @@ internal static partial class OpenApiV3Deserializer }; private static readonly PatternFieldMap _mediaTypePatternFields = - new PatternFieldMap + new() { {s => s.StartsWith("x-"), (o, p, n) => o.AddExtension(p, LoadExtension(p,n))} }; - private static readonly AnyFieldMap _mediaTypeAnyFields = new AnyFieldMap + private static readonly AnyFieldMap _mediaTypeAnyFields = new() { { OpenApiConstants.Example, - new AnyFieldMapParameter( + new( s => s.Example, (s, v) => s.Example = v, s => s.Schema) @@ -60,11 +60,11 @@ internal static partial class OpenApiV3Deserializer }; private static readonly AnyMapFieldMap _mediaTypeAnyMapOpenApiExampleFields = - new AnyMapFieldMap - { + new() + { { OpenApiConstants.Examples, - new AnyMapFieldMapParameter( + new( m => m.Examples, e => e.Value, (e, v) => e.Value = v, diff --git a/src/Microsoft.OpenApi.Readers/V3/OpenApiOAuthFlowDeserializer.cs b/src/Microsoft.OpenApi.Readers/V3/OpenApiOAuthFlowDeserializer.cs index 1679cdf75..0b5f6a3eb 100644 --- a/src/Microsoft.OpenApi.Readers/V3/OpenApiOAuthFlowDeserializer.cs +++ b/src/Microsoft.OpenApi.Readers/V3/OpenApiOAuthFlowDeserializer.cs @@ -15,31 +15,31 @@ namespace Microsoft.OpenApi.Readers.V3 internal static partial class OpenApiV3Deserializer { private static readonly FixedFieldMap _oAuthFlowFixedFileds = - new FixedFieldMap + new() { { "authorizationUrl", (o, n) => { - o.AuthorizationUrl = new Uri(n.GetScalarValue(), UriKind.RelativeOrAbsolute); + o.AuthorizationUrl = new(n.GetScalarValue(), UriKind.RelativeOrAbsolute); } }, { "tokenUrl", (o, n) => { - o.TokenUrl = new Uri(n.GetScalarValue(), UriKind.RelativeOrAbsolute); + o.TokenUrl = new(n.GetScalarValue(), UriKind.RelativeOrAbsolute); } }, { "refreshUrl", (o, n) => { - o.RefreshUrl = new Uri(n.GetScalarValue(), UriKind.RelativeOrAbsolute); + o.RefreshUrl = new(n.GetScalarValue(), UriKind.RelativeOrAbsolute); } }, {"scopes", (o, n) => o.Scopes = n.CreateSimpleMap(LoadString)} }; private static readonly PatternFieldMap _oAuthFlowPatternFields = - new PatternFieldMap + new() { {s => s.StartsWith("x-"), (o, p, n) => o.AddExtension(p, LoadExtension(p,n))} }; diff --git a/src/Microsoft.OpenApi.Readers/V3/OpenApiOAuthFlowsDeserializer.cs b/src/Microsoft.OpenApi.Readers/V3/OpenApiOAuthFlowsDeserializer.cs index 9269048aa..9a80bed88 100644 --- a/src/Microsoft.OpenApi.Readers/V3/OpenApiOAuthFlowsDeserializer.cs +++ b/src/Microsoft.OpenApi.Readers/V3/OpenApiOAuthFlowsDeserializer.cs @@ -14,7 +14,7 @@ namespace Microsoft.OpenApi.Readers.V3 internal static partial class OpenApiV3Deserializer { private static readonly FixedFieldMap _oAuthFlowsFixedFileds = - new FixedFieldMap + new() { {"implicit", (o, n) => o.Implicit = LoadOAuthFlow(n)}, {"password", (o, n) => o.Password = LoadOAuthFlow(n)}, @@ -23,7 +23,7 @@ internal static partial class OpenApiV3Deserializer }; private static readonly PatternFieldMap _oAuthFlowsPatternFields = - new PatternFieldMap + new() { {s => s.StartsWith("x-"), (o, p, n) => o.AddExtension(p, LoadExtension(p,n))} }; diff --git a/src/Microsoft.OpenApi.Readers/V3/OpenApiOperationDeserializer.cs b/src/Microsoft.OpenApi.Readers/V3/OpenApiOperationDeserializer.cs index dee61cef6..c3ac122f1 100644 --- a/src/Microsoft.OpenApi.Readers/V3/OpenApiOperationDeserializer.cs +++ b/src/Microsoft.OpenApi.Readers/V3/OpenApiOperationDeserializer.cs @@ -14,7 +14,7 @@ namespace Microsoft.OpenApi.Readers.V3 internal static partial class OpenApiV3Deserializer { private static readonly FixedFieldMap _operationFixedFields = - new FixedFieldMap + new() { { "tags", (o, n) => o.Tags = n.CreateSimpleList( @@ -92,7 +92,7 @@ internal static partial class OpenApiV3Deserializer }; private static readonly PatternFieldMap _operationPatternFields = - new PatternFieldMap + new() { {s => s.StartsWith("x-"), (o, p, n) => o.AddExtension(p, LoadExtension(p,n))}, }; @@ -115,7 +115,7 @@ private static OpenApiTag LoadTagByReference( var tagObject = new OpenApiTag { UnresolvedReference = true, - Reference = new OpenApiReference + Reference = new() { Type = ReferenceType.Tag, Id = tagName diff --git a/src/Microsoft.OpenApi.Readers/V3/OpenApiParameterDeserializer.cs b/src/Microsoft.OpenApi.Readers/V3/OpenApiParameterDeserializer.cs index c291132ca..c502d38b0 100644 --- a/src/Microsoft.OpenApi.Readers/V3/OpenApiParameterDeserializer.cs +++ b/src/Microsoft.OpenApi.Readers/V3/OpenApiParameterDeserializer.cs @@ -16,7 +16,7 @@ namespace Microsoft.OpenApi.Readers.V3 internal static partial class OpenApiV3Deserializer { private static readonly FixedFieldMap _parameterFixedFields = - new FixedFieldMap + new() { { "name", (o, n) => @@ -110,16 +110,16 @@ internal static partial class OpenApiV3Deserializer }; private static readonly PatternFieldMap _parameterPatternFields = - new PatternFieldMap + new() { {s => s.StartsWith("x-"), (o, p, n) => o.AddExtension(p, LoadExtension(p,n))} }; - private static readonly AnyFieldMap _parameterAnyFields = new AnyFieldMap + private static readonly AnyFieldMap _parameterAnyFields = new() { { OpenApiConstants.Example, - new AnyFieldMapParameter( + new( s => s.Example, (s, v) => s.Example = v, s => s.Schema) @@ -127,11 +127,11 @@ internal static partial class OpenApiV3Deserializer }; private static readonly AnyMapFieldMap _parameterAnyMapOpenApiExampleFields = - new AnyMapFieldMap - { + new() + { { OpenApiConstants.Examples, - new AnyMapFieldMapParameter( + new( m => m.Examples, e => e.Value, (e, v) => e.Value = v, diff --git a/src/Microsoft.OpenApi.Readers/V3/OpenApiPathItemDeserializer.cs b/src/Microsoft.OpenApi.Readers/V3/OpenApiPathItemDeserializer.cs index dd5a071f3..fcafcc786 100644 --- a/src/Microsoft.OpenApi.Readers/V3/OpenApiPathItemDeserializer.cs +++ b/src/Microsoft.OpenApi.Readers/V3/OpenApiPathItemDeserializer.cs @@ -13,11 +13,11 @@ namespace Microsoft.OpenApi.Readers.V3 /// internal static partial class OpenApiV3Deserializer { - private static readonly FixedFieldMap _pathItemFixedFields = new FixedFieldMap + private static readonly FixedFieldMap _pathItemFixedFields = new() { { "$ref", (o,n) => { - o.Reference = new OpenApiReference { ExternalResource = n.GetScalarValue() }; + o.Reference = new() { ExternalResource = n.GetScalarValue() }; o.UnresolvedReference =true; } }, @@ -46,7 +46,7 @@ internal static partial class OpenApiV3Deserializer }; private static readonly PatternFieldMap _pathItemPatternFields = - new PatternFieldMap + new() { {s => s.StartsWith("x-"), (o, p, n) => o.AddExtension(p, LoadExtension(p,n))} }; diff --git a/src/Microsoft.OpenApi.Readers/V3/OpenApiPathsDeserializer.cs b/src/Microsoft.OpenApi.Readers/V3/OpenApiPathsDeserializer.cs index 5b0b9485b..8104cde7f 100644 --- a/src/Microsoft.OpenApi.Readers/V3/OpenApiPathsDeserializer.cs +++ b/src/Microsoft.OpenApi.Readers/V3/OpenApiPathsDeserializer.cs @@ -13,9 +13,9 @@ namespace Microsoft.OpenApi.Readers.V3 /// internal static partial class OpenApiV3Deserializer { - private static FixedFieldMap _pathsFixedFields = new FixedFieldMap(); + private static FixedFieldMap _pathsFixedFields = new(); - private static PatternFieldMap _pathsPatternFields = new PatternFieldMap + private static PatternFieldMap _pathsPatternFields = new() { {s => s.StartsWith("/"), (o, k, n) => o.Add(k, LoadPathItem(n))}, {s => s.StartsWith("x-"), (o, p, n) => o.AddExtension(p, LoadExtension(p,n))} diff --git a/src/Microsoft.OpenApi.Readers/V3/OpenApiRequestBodyDeserializer.cs b/src/Microsoft.OpenApi.Readers/V3/OpenApiRequestBodyDeserializer.cs index c5c2fab91..d65279788 100644 --- a/src/Microsoft.OpenApi.Readers/V3/OpenApiRequestBodyDeserializer.cs +++ b/src/Microsoft.OpenApi.Readers/V3/OpenApiRequestBodyDeserializer.cs @@ -14,7 +14,7 @@ namespace Microsoft.OpenApi.Readers.V3 internal static partial class OpenApiV3Deserializer { private static readonly FixedFieldMap _requestBodyFixedFields = - new FixedFieldMap + new() { { "description", (o, n) => @@ -37,7 +37,7 @@ internal static partial class OpenApiV3Deserializer }; private static readonly PatternFieldMap _requestBodyPatternFields = - new PatternFieldMap + new() { {s => s.StartsWith("x-"), (o, p, n) => o.AddExtension(p, LoadExtension(p,n))} }; diff --git a/src/Microsoft.OpenApi.Readers/V3/OpenApiResponseDeserializer.cs b/src/Microsoft.OpenApi.Readers/V3/OpenApiResponseDeserializer.cs index 73f20791a..64515dc3b 100644 --- a/src/Microsoft.OpenApi.Readers/V3/OpenApiResponseDeserializer.cs +++ b/src/Microsoft.OpenApi.Readers/V3/OpenApiResponseDeserializer.cs @@ -14,7 +14,7 @@ namespace Microsoft.OpenApi.Readers.V3 /// internal static partial class OpenApiV3Deserializer { - private static readonly FixedFieldMap _responseFixedFields = new FixedFieldMap + private static readonly FixedFieldMap _responseFixedFields = new() { { "description", (o, n) => @@ -43,7 +43,7 @@ internal static partial class OpenApiV3Deserializer }; private static readonly PatternFieldMap _responsePatternFields = - new PatternFieldMap + new() { {s => s.StartsWith("x-"), (o, p, n) => o.AddExtension(p, LoadExtension(p,n))} }; diff --git a/src/Microsoft.OpenApi.Readers/V3/OpenApiResponsesDeserializer.cs b/src/Microsoft.OpenApi.Readers/V3/OpenApiResponsesDeserializer.cs index 597e8a4b6..437553160 100644 --- a/src/Microsoft.OpenApi.Readers/V3/OpenApiResponsesDeserializer.cs +++ b/src/Microsoft.OpenApi.Readers/V3/OpenApiResponsesDeserializer.cs @@ -13,9 +13,9 @@ namespace Microsoft.OpenApi.Readers.V3 /// internal static partial class OpenApiV3Deserializer { - public static FixedFieldMap ResponsesFixedFields = new FixedFieldMap(); + public static FixedFieldMap ResponsesFixedFields = new(); - public static PatternFieldMap ResponsesPatternFields = new PatternFieldMap + public static PatternFieldMap ResponsesPatternFields = new() { {s => !s.StartsWith("x-"), (o, p, n) => o.Add(p, LoadResponse(n))}, {s => s.StartsWith("x-"), (o, p, n) => o.AddExtension(p, LoadExtension(p,n))} diff --git a/src/Microsoft.OpenApi.Readers/V3/OpenApiSchemaDeserializer.cs b/src/Microsoft.OpenApi.Readers/V3/OpenApiSchemaDeserializer.cs index 3a961255f..fd375bfdf 100644 --- a/src/Microsoft.OpenApi.Readers/V3/OpenApiSchemaDeserializer.cs +++ b/src/Microsoft.OpenApi.Readers/V3/OpenApiSchemaDeserializer.cs @@ -15,7 +15,7 @@ namespace Microsoft.OpenApi.Readers.V3 /// internal static partial class OpenApiV3Deserializer { - private static readonly FixedFieldMap _schemaFixedFields = new FixedFieldMap + private static readonly FixedFieldMap _schemaFixedFields = new() { { "title", (o, n) => @@ -237,34 +237,34 @@ internal static partial class OpenApiV3Deserializer }, }; - private static readonly PatternFieldMap _schemaPatternFields = new PatternFieldMap + private static readonly PatternFieldMap _schemaPatternFields = new() { {s => s.StartsWith("x-"), (o, p, n) => o.AddExtension(p, LoadExtension(p,n))} }; - private static readonly AnyFieldMap _schemaAnyFields = new AnyFieldMap + private static readonly AnyFieldMap _schemaAnyFields = new() { { OpenApiConstants.Default, - new AnyFieldMapParameter( + new( s => s.Default, (s, v) => s.Default = v, s => s) }, { OpenApiConstants.Example, - new AnyFieldMapParameter( + new( s => s.Example, (s, v) => s.Example = v, s => s) } }; - private static readonly AnyListFieldMap _schemaAnyListFields = new AnyListFieldMap + private static readonly AnyListFieldMap _schemaAnyListFields = new() { { OpenApiConstants.Enum, - new AnyListFieldMapParameter( + new( s => s.Enum, (s, v) => s.Enum = v, s => s) @@ -279,7 +279,7 @@ public static OpenApiSchema LoadSchema(ParseNode node) if (pointer != null) { - return new OpenApiSchema + return new() { UnresolvedReference = true, Reference = node.Context.VersionService.ConvertToOpenApiReference(pointer, ReferenceType.Schema) diff --git a/src/Microsoft.OpenApi.Readers/V3/OpenApiSecurityRequirementDeserializer.cs b/src/Microsoft.OpenApi.Readers/V3/OpenApiSecurityRequirementDeserializer.cs index 4a609125e..fec3ec401 100644 --- a/src/Microsoft.OpenApi.Readers/V3/OpenApiSecurityRequirementDeserializer.cs +++ b/src/Microsoft.OpenApi.Readers/V3/OpenApiSecurityRequirementDeserializer.cs @@ -33,7 +33,7 @@ public static OpenApiSecurityRequirement LoadSecurityRequirement(ParseNode node) else { mapNode.Context.Diagnostic.Errors.Add( - new OpenApiError(node.Context.GetLocation(), $"Scheme {property.Name} is not found")); + new(node.Context.GetLocation(), $"Scheme {property.Name} is not found")); } } @@ -47,7 +47,7 @@ private static OpenApiSecurityScheme LoadSecuritySchemeByReference( var securitySchemeObject = new OpenApiSecurityScheme { UnresolvedReference = true, - Reference = new OpenApiReference + Reference = new() { Id = schemeName, Type = ReferenceType.SecurityScheme diff --git a/src/Microsoft.OpenApi.Readers/V3/OpenApiSecuritySchemeDeserializer.cs b/src/Microsoft.OpenApi.Readers/V3/OpenApiSecuritySchemeDeserializer.cs index a5f50eb3f..e2ea91abe 100644 --- a/src/Microsoft.OpenApi.Readers/V3/OpenApiSecuritySchemeDeserializer.cs +++ b/src/Microsoft.OpenApi.Readers/V3/OpenApiSecuritySchemeDeserializer.cs @@ -15,7 +15,7 @@ namespace Microsoft.OpenApi.Readers.V3 internal static partial class OpenApiV3Deserializer { private static readonly FixedFieldMap _securitySchemeFixedFields = - new FixedFieldMap + new() { { "type", (o, n) => @@ -56,7 +56,7 @@ internal static partial class OpenApiV3Deserializer { "openIdConnectUrl", (o, n) => { - o.OpenIdConnectUrl = new Uri(n.GetScalarValue(), UriKind.RelativeOrAbsolute); + o.OpenIdConnectUrl = new(n.GetScalarValue(), UriKind.RelativeOrAbsolute); } }, { @@ -68,7 +68,7 @@ internal static partial class OpenApiV3Deserializer }; private static readonly PatternFieldMap _securitySchemePatternFields = - new PatternFieldMap + new() { {s => s.StartsWith("x-"), (o, p, n) => o.AddExtension(p, LoadExtension(p,n))} }; diff --git a/src/Microsoft.OpenApi.Readers/V3/OpenApiServerDeserializer.cs b/src/Microsoft.OpenApi.Readers/V3/OpenApiServerDeserializer.cs index 81e92b979..b29c3b0bf 100644 --- a/src/Microsoft.OpenApi.Readers/V3/OpenApiServerDeserializer.cs +++ b/src/Microsoft.OpenApi.Readers/V3/OpenApiServerDeserializer.cs @@ -13,7 +13,7 @@ namespace Microsoft.OpenApi.Readers.V3 /// internal static partial class OpenApiV3Deserializer { - private static readonly FixedFieldMap _serverFixedFields = new FixedFieldMap + private static readonly FixedFieldMap _serverFixedFields = new() { { "url", (o, n) => @@ -35,7 +35,7 @@ internal static partial class OpenApiV3Deserializer } }; - private static readonly PatternFieldMap _serverPatternFields = new PatternFieldMap + private static readonly PatternFieldMap _serverPatternFields = new() { {s => s.StartsWith("x-"), (o, p, n) => o.AddExtension(p, LoadExtension(p,n))} }; diff --git a/src/Microsoft.OpenApi.Readers/V3/OpenApiServerVariableDeserializer.cs b/src/Microsoft.OpenApi.Readers/V3/OpenApiServerVariableDeserializer.cs index fa4d07d72..c506930d3 100644 --- a/src/Microsoft.OpenApi.Readers/V3/OpenApiServerVariableDeserializer.cs +++ b/src/Microsoft.OpenApi.Readers/V3/OpenApiServerVariableDeserializer.cs @@ -14,7 +14,7 @@ namespace Microsoft.OpenApi.Readers.V3 internal static partial class OpenApiV3Deserializer { private static readonly FixedFieldMap _serverVariableFixedFields = - new FixedFieldMap + new() { { "enum", (o, n) => @@ -37,7 +37,7 @@ internal static partial class OpenApiV3Deserializer }; private static readonly PatternFieldMap _serverVariablePatternFields = - new PatternFieldMap + new() { {s => s.StartsWith("x-"), (o, p, n) => o.AddExtension(p, LoadExtension(p,n))} }; diff --git a/src/Microsoft.OpenApi.Readers/V3/OpenApiTagDeserializer.cs b/src/Microsoft.OpenApi.Readers/V3/OpenApiTagDeserializer.cs index 9de8bf610..b78cdfc60 100644 --- a/src/Microsoft.OpenApi.Readers/V3/OpenApiTagDeserializer.cs +++ b/src/Microsoft.OpenApi.Readers/V3/OpenApiTagDeserializer.cs @@ -13,7 +13,7 @@ namespace Microsoft.OpenApi.Readers.V3 /// internal static partial class OpenApiV3Deserializer { - private static readonly FixedFieldMap _tagFixedFields = new FixedFieldMap + private static readonly FixedFieldMap _tagFixedFields = new() { { OpenApiConstants.Name, (o, n) => @@ -35,7 +35,7 @@ internal static partial class OpenApiV3Deserializer } }; - private static readonly PatternFieldMap _tagPatternFields = new PatternFieldMap + private static readonly PatternFieldMap _tagPatternFields = new() { {s => s.StartsWith("x-"), (o, p, n) => o.AddExtension(p, LoadExtension(p,n))} }; diff --git a/src/Microsoft.OpenApi.Readers/V3/OpenApiV3Deserializer.cs b/src/Microsoft.OpenApi.Readers/V3/OpenApiV3Deserializer.cs index 81ced4a53..79b5f0671 100644 --- a/src/Microsoft.OpenApi.Readers/V3/OpenApiV3Deserializer.cs +++ b/src/Microsoft.OpenApi.Readers/V3/OpenApiV3Deserializer.cs @@ -55,7 +55,7 @@ private static void ProcessAnyFields( catch (OpenApiException exception) { exception.Pointer = mapNode.Context.GetLocation(); - mapNode.Context.Diagnostic.Errors.Add(new OpenApiError(exception)); + mapNode.Context.Diagnostic.Errors.Add(new(exception)); } finally { @@ -90,7 +90,7 @@ private static void ProcessAnyListFields( catch (OpenApiException exception) { exception.Pointer = mapNode.Context.GetLocation(); - mapNode.Context.Diagnostic.Errors.Add(new OpenApiError(exception)); + mapNode.Context.Diagnostic.Errors.Add(new(exception)); } finally { @@ -131,7 +131,7 @@ private static void ProcessAnyMapFields( catch (OpenApiException exception) { exception.Pointer = mapNode.Context.GetLocation(); - mapNode.Context.Diagnostic.Errors.Add(new OpenApiError(exception)); + mapNode.Context.Diagnostic.Errors.Add(new(exception)); } finally { @@ -152,13 +152,13 @@ private static RuntimeExpressionAnyWrapper LoadRuntimeExpressionAnyWrapper(Parse if (value != null && value.StartsWith("$")) { - return new RuntimeExpressionAnyWrapper + return new() { Expression = RuntimeExpression.Build(value) }; } - return new RuntimeExpressionAnyWrapper + return new() { Any = OpenApiAnyConverter.GetSpecificOpenApiAny(node.CreateAny()) }; diff --git a/src/Microsoft.OpenApi.Readers/V3/OpenApiV3VersionService.cs b/src/Microsoft.OpenApi.Readers/V3/OpenApiV3VersionService.cs index a6cb41970..011680d3d 100644 --- a/src/Microsoft.OpenApi.Readers/V3/OpenApiV3VersionService.cs +++ b/src/Microsoft.OpenApi.Readers/V3/OpenApiV3VersionService.cs @@ -80,7 +80,7 @@ public OpenApiReference ConvertToOpenApiReference( { if (type is ReferenceType.Tag or ReferenceType.SecurityScheme) { - return new OpenApiReference + return new() { Type = type, Id = reference @@ -89,7 +89,7 @@ public OpenApiReference ConvertToOpenApiReference( // Either this is an external reference as an entire file // or a simple string-style reference for tag and security scheme. - return new OpenApiReference + return new() { Type = type, ExternalResource = segments[0] @@ -106,7 +106,7 @@ public OpenApiReference ConvertToOpenApiReference( } catch (OpenApiException ex) { - Diagnostic.Errors.Add(new OpenApiError(ex)); + Diagnostic.Errors.Add(new(ex)); } } // Where fragments point into a non-OpenAPI document, the id will be the complete fragment identifier @@ -185,7 +185,7 @@ private OpenApiReference ParseLocalReference(string localReference) if (segments[1] == "components") { var referenceType = segments[2].GetEnumFromDisplayName(); - return new OpenApiReference { Type = referenceType, Id = segments[3] }; + return new() { Type = referenceType, Id = segments[3] }; } } diff --git a/src/Microsoft.OpenApi.Readers/V3/OpenApiXmlDeserializer.cs b/src/Microsoft.OpenApi.Readers/V3/OpenApiXmlDeserializer.cs index 95cc2a585..866f38d01 100644 --- a/src/Microsoft.OpenApi.Readers/V3/OpenApiXmlDeserializer.cs +++ b/src/Microsoft.OpenApi.Readers/V3/OpenApiXmlDeserializer.cs @@ -14,7 +14,7 @@ namespace Microsoft.OpenApi.Readers.V3 /// internal static partial class OpenApiV3Deserializer { - private static readonly FixedFieldMap _xmlFixedFields = new FixedFieldMap + private static readonly FixedFieldMap _xmlFixedFields = new() { { "name", (o, n) => @@ -25,7 +25,7 @@ internal static partial class OpenApiV3Deserializer { "namespace", (o, n) => { - o.Namespace = new Uri(n.GetScalarValue(), UriKind.Absolute); + o.Namespace = new(n.GetScalarValue(), UriKind.Absolute); } }, { @@ -49,7 +49,7 @@ internal static partial class OpenApiV3Deserializer }; private static readonly PatternFieldMap _xmlPatternFields = - new PatternFieldMap + new() { {s => s.StartsWith("x-"), (o, p, n) => o.AddExtension(p, LoadExtension(p,n))} }; diff --git a/src/Microsoft.OpenApi.Workbench/MainModel.cs b/src/Microsoft.OpenApi.Workbench/MainModel.cs index ca47bbd48..52a34df81 100644 --- a/src/Microsoft.OpenApi.Workbench/MainModel.cs +++ b/src/Microsoft.OpenApi.Workbench/MainModel.cs @@ -13,7 +13,6 @@ using Microsoft.OpenApi.Readers; using Microsoft.OpenApi.Services; using Microsoft.OpenApi.Validations; -using Microsoft.OpenApi.Writers; namespace Microsoft.OpenApi.Workbench { @@ -49,7 +48,7 @@ public class MainModel : INotifyPropertyChanged /// private OpenApiSpecVersion _version = OpenApiSpecVersion.OpenApi3_0; - private HttpClient _httpClient = new HttpClient(); + private HttpClient _httpClient = new(); public string Input { @@ -194,7 +193,7 @@ protected void OnPropertyChanged(string propertyName) var handler = PropertyChanged; if (handler != null) { - handler(this, new PropertyChangedEventArgs(propertyName)); + handler(this, new(propertyName)); } } @@ -239,11 +238,11 @@ internal async Task ParseDocument() { if (_inputFile.StartsWith("http")) { - settings.BaseUrl = new Uri(_inputFile); + settings.BaseUrl = new(_inputFile); } else { - settings.BaseUrl = new Uri("file://" + Path.GetDirectoryName(_inputFile) + "/"); + settings.BaseUrl = new("file://" + Path.GetDirectoryName(_inputFile) + "/"); } } var readResult = await new OpenApiStreamReader(settings @@ -309,7 +308,7 @@ private string WriteContents(OpenApiDocument document) outputStream, Version, Format, - new OpenApiWriterSettings + new() { InlineLocalReferences = InlineLocal, InlineExternalReferences = InlineExternal diff --git a/src/Microsoft.OpenApi.Workbench/MainWindow.xaml.cs b/src/Microsoft.OpenApi.Workbench/MainWindow.xaml.cs index 0d2f74582..5f3c3ec38 100644 --- a/src/Microsoft.OpenApi.Workbench/MainWindow.xaml.cs +++ b/src/Microsoft.OpenApi.Workbench/MainWindow.xaml.cs @@ -11,7 +11,7 @@ namespace Microsoft.OpenApi.Workbench /// public partial class MainWindow : Window { - private readonly MainModel _mainModel = new MainModel(); + private readonly MainModel _mainModel = new(); public MainWindow() { diff --git a/src/Microsoft.OpenApi/Error.cs b/src/Microsoft.OpenApi/Error.cs index 9ad76ce54..29e1c7af2 100644 --- a/src/Microsoft.OpenApi/Error.cs +++ b/src/Microsoft.OpenApi/Error.cs @@ -31,7 +31,7 @@ internal static string Format(string format, params object[] args) /// The logged . internal static ArgumentException Argument(string messageFormat, params object[] messageArgs) { - return new ArgumentException(Format(messageFormat, messageArgs)); + return new(Format(messageFormat, messageArgs)); } /// @@ -46,7 +46,7 @@ internal static ArgumentException Argument( string messageFormat, params object[] messageArgs) { - return new ArgumentException(Format(messageFormat, messageArgs), parameterName); + return new(Format(messageFormat, messageArgs), parameterName); } /// @@ -56,7 +56,7 @@ internal static ArgumentException Argument( /// The logged . internal static ArgumentNullException ArgumentNull(string parameterName) { - return new ArgumentNullException(parameterName); + return new(parameterName); } /// @@ -71,7 +71,7 @@ internal static ArgumentNullException ArgumentNull( string messageFormat, params object[] messageArgs) { - return new ArgumentNullException(parameterName, Format(messageFormat, messageArgs)); + return new(parameterName, Format(messageFormat, messageArgs)); } /// @@ -92,7 +92,7 @@ internal static ArgumentException ArgumentNullOrWhiteSpace(string parameterName) /// The logged . internal static NotSupportedException NotSupported(string messageFormat, params object[] messageArgs) { - return new NotSupportedException(Format(messageFormat, messageArgs)); + return new(Format(messageFormat, messageArgs)); } } } diff --git a/src/Microsoft.OpenApi/Expressions/CompositeExpression.cs b/src/Microsoft.OpenApi/Expressions/CompositeExpression.cs index 98c5e069c..bbe0d3076 100644 --- a/src/Microsoft.OpenApi/Expressions/CompositeExpression.cs +++ b/src/Microsoft.OpenApi/Expressions/CompositeExpression.cs @@ -13,12 +13,12 @@ namespace Microsoft.OpenApi.Expressions public class CompositeExpression : RuntimeExpression { private readonly string template; - private Regex expressionPattern = new Regex(@"{(?\$[^}]*)"); + private Regex expressionPattern = new(@"{(?\$[^}]*)"); /// /// Expressions embedded into string literal /// - public List ContainedExpressions = new List(); + public List ContainedExpressions = new(); /// /// Create a composite expression from a string literal with an embedded expression diff --git a/src/Microsoft.OpenApi/Expressions/SourceExpression.cs b/src/Microsoft.OpenApi/Expressions/SourceExpression.cs index 2e55ece90..8504a1e89 100644 --- a/src/Microsoft.OpenApi/Expressions/SourceExpression.cs +++ b/src/Microsoft.OpenApi/Expressions/SourceExpression.cs @@ -65,7 +65,7 @@ protected SourceExpression(string value) return new BodyExpression(); } - return new BodyExpression(new JsonPointer(subString)); + return new BodyExpression(new(subString)); } } diff --git a/src/Microsoft.OpenApi/Extensions/OpenAPIWriterExtensions.cs b/src/Microsoft.OpenApi/Extensions/OpenAPIWriterExtensions.cs index e7d668703..983474243 100644 --- a/src/Microsoft.OpenApi/Extensions/OpenAPIWriterExtensions.cs +++ b/src/Microsoft.OpenApi/Extensions/OpenAPIWriterExtensions.cs @@ -15,7 +15,7 @@ internal static OpenApiWriterSettings GetSettings(this IOpenApiWriter openApiWri { return @base.Settings; } - return new OpenApiWriterSettings(); + return new(); } } } diff --git a/src/Microsoft.OpenApi/Extensions/OpenApiTypeMapper.cs b/src/Microsoft.OpenApi/Extensions/OpenApiTypeMapper.cs index 176762dc6..712e7f5c7 100644 --- a/src/Microsoft.OpenApi/Extensions/OpenApiTypeMapper.cs +++ b/src/Microsoft.OpenApi/Extensions/OpenApiTypeMapper.cs @@ -14,38 +14,38 @@ public static class OpenApiTypeMapper { private static readonly Dictionary> _simpleTypeToOpenApiSchema = new() { - [typeof(bool)] = () => new OpenApiSchema { Type = "boolean" }, - [typeof(byte)] = () => new OpenApiSchema { Type = "string", Format = "byte" }, - [typeof(int)] = () => new OpenApiSchema { Type = "integer", Format = "int32" }, - [typeof(uint)] = () => new OpenApiSchema { Type = "integer", Format = "int32" }, - [typeof(long)] = () => new OpenApiSchema { Type = "integer", Format = "int64" }, - [typeof(ulong)] = () => new OpenApiSchema { Type = "integer", Format = "int64" }, - [typeof(float)] = () => new OpenApiSchema { Type = "number", Format = "float" }, - [typeof(double)] = () => new OpenApiSchema { Type = "number", Format = "double" }, - [typeof(decimal)] = () => new OpenApiSchema { Type = "number", Format = "double" }, - [typeof(DateTime)] = () => new OpenApiSchema { Type = "string", Format = "date-time" }, - [typeof(DateTimeOffset)] = () => new OpenApiSchema { Type = "string", Format = "date-time" }, - [typeof(Guid)] = () => new OpenApiSchema { Type = "string", Format = "uuid" }, - [typeof(char)] = () => new OpenApiSchema { Type = "string" }, + [typeof(bool)] = () => new() { Type = "boolean" }, + [typeof(byte)] = () => new() { Type = "string", Format = "byte" }, + [typeof(int)] = () => new() { Type = "integer", Format = "int32" }, + [typeof(uint)] = () => new() { Type = "integer", Format = "int32" }, + [typeof(long)] = () => new() { Type = "integer", Format = "int64" }, + [typeof(ulong)] = () => new() { Type = "integer", Format = "int64" }, + [typeof(float)] = () => new() { Type = "number", Format = "float" }, + [typeof(double)] = () => new() { Type = "number", Format = "double" }, + [typeof(decimal)] = () => new() { Type = "number", Format = "double" }, + [typeof(DateTime)] = () => new() { Type = "string", Format = "date-time" }, + [typeof(DateTimeOffset)] = () => new() { Type = "string", Format = "date-time" }, + [typeof(Guid)] = () => new() { Type = "string", Format = "uuid" }, + [typeof(char)] = () => new() { Type = "string" }, // Nullable types - [typeof(bool?)] = () => new OpenApiSchema { Type = "boolean", Nullable = true }, - [typeof(byte?)] = () => new OpenApiSchema { Type = "string", Format = "byte", Nullable = true }, - [typeof(int?)] = () => new OpenApiSchema { Type = "integer", Format = "int32", Nullable = true }, - [typeof(uint?)] = () => new OpenApiSchema { Type = "integer", Format = "int32", Nullable = true }, - [typeof(long?)] = () => new OpenApiSchema { Type = "integer", Format = "int64", Nullable = true }, - [typeof(ulong?)] = () => new OpenApiSchema { Type = "integer", Format = "int64", Nullable = true }, - [typeof(float?)] = () => new OpenApiSchema { Type = "number", Format = "float", Nullable = true }, - [typeof(double?)] = () => new OpenApiSchema { Type = "number", Format = "double", Nullable = true }, - [typeof(decimal?)] = () => new OpenApiSchema { Type = "number", Format = "double", Nullable = true }, - [typeof(DateTime?)] = () => new OpenApiSchema { Type = "string", Format = "date-time", Nullable = true }, - [typeof(DateTimeOffset?)] = () => new OpenApiSchema { Type = "string", Format = "date-time", Nullable = true }, - [typeof(Guid?)] = () => new OpenApiSchema { Type = "string", Format = "uuid", Nullable = true }, - [typeof(char?)] = () => new OpenApiSchema { Type = "string", Nullable = true }, + [typeof(bool?)] = () => new() { Type = "boolean", Nullable = true }, + [typeof(byte?)] = () => new() { Type = "string", Format = "byte", Nullable = true }, + [typeof(int?)] = () => new() { Type = "integer", Format = "int32", Nullable = true }, + [typeof(uint?)] = () => new() { Type = "integer", Format = "int32", Nullable = true }, + [typeof(long?)] = () => new() { Type = "integer", Format = "int64", Nullable = true }, + [typeof(ulong?)] = () => new() { Type = "integer", Format = "int64", Nullable = true }, + [typeof(float?)] = () => new() { Type = "number", Format = "float", Nullable = true }, + [typeof(double?)] = () => new() { Type = "number", Format = "double", Nullable = true }, + [typeof(decimal?)] = () => new() { Type = "number", Format = "double", Nullable = true }, + [typeof(DateTime?)] = () => new() { Type = "string", Format = "date-time", Nullable = true }, + [typeof(DateTimeOffset?)] = () => new() { Type = "string", Format = "date-time", Nullable = true }, + [typeof(Guid?)] = () => new() { Type = "string", Format = "uuid", Nullable = true }, + [typeof(char?)] = () => new() { Type = "string", Nullable = true }, - [typeof(Uri)] = () => new OpenApiSchema { Type = "string", Format = "uri"}, // Uri is treated as simple string - [typeof(string)] = () => new OpenApiSchema { Type = "string" }, - [typeof(object)] = () => new OpenApiSchema { Type = "object" } + [typeof(Uri)] = () => new() { Type = "string", Format = "uri"}, // Uri is treated as simple string + [typeof(string)] = () => new() { Type = "string" }, + [typeof(object)] = () => new() { Type = "object" } }; /// @@ -79,7 +79,7 @@ public static OpenApiSchema MapTypeToOpenApiPrimitiveType(this Type type) return _simpleTypeToOpenApiSchema.TryGetValue(type, out var result) ? result() - : new OpenApiSchema { Type = "string" }; + : new() { Type = "string" }; } /// diff --git a/src/Microsoft.OpenApi/JsonPointer.cs b/src/Microsoft.OpenApi/JsonPointer.cs index 1ff843031..110cca81e 100644 --- a/src/Microsoft.OpenApi/JsonPointer.cs +++ b/src/Microsoft.OpenApi/JsonPointer.cs @@ -48,7 +48,7 @@ public JsonPointer ParentPointer return null; } - return new JsonPointer(Tokens.Take(Tokens.Length - 1).ToArray()); + return new(Tokens.Take(Tokens.Length - 1).ToArray()); } } diff --git a/src/Microsoft.OpenApi/MicrosoftExtensions/OpenApiPrimaryErrorMessageExtension.cs b/src/Microsoft.OpenApi/MicrosoftExtensions/OpenApiPrimaryErrorMessageExtension.cs index ed328c433..fde7a54ea 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) public static OpenApiPrimaryErrorMessageExtension Parse(IOpenApiAny source) { if (source is not OpenApiBoolean rawObject) throw new ArgumentOutOfRangeException(nameof(source)); - return new OpenApiPrimaryErrorMessageExtension + return new() { IsPrimaryErrorMessage = rawObject.Value }; diff --git a/src/Microsoft.OpenApi/MicrosoftExtensions/OpenApiReservedParameterExtension.cs b/src/Microsoft.OpenApi/MicrosoftExtensions/OpenApiReservedParameterExtension.cs index 5cfa54082..77428e186 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(IOpenApiAny source) { if (source is not OpenApiBoolean rawBoolean) throw new ArgumentOutOfRangeException(nameof(source)); - return new OpenApiReservedParameterExtension + return new() { IsReserved = rawBoolean.Value }; diff --git a/src/Microsoft.OpenApi/Models/OpenApiCallback.cs b/src/Microsoft.OpenApi/Models/OpenApiCallback.cs index 4a5123e08..e945adc31 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiCallback.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiCallback.cs @@ -17,7 +17,7 @@ public class OpenApiCallback : IOpenApiReferenceable, IOpenApiExtensible, IEffec /// A Path Item Object used to define a callback request and expected responses. /// public Dictionary PathItems { get; set; } - = new Dictionary(); + = new(); /// /// Indicates if object is populated with data or is just a reference to the data @@ -69,7 +69,7 @@ public void AddPathItem(RuntimeExpression expression, OpenApiPathItem pathItem) if (PathItems == null) { - PathItems = new Dictionary(); + PathItems = new(); } PathItems.Add(expression, pathItem); diff --git a/src/Microsoft.OpenApi/Models/OpenApiConstants.cs b/src/Microsoft.OpenApi/Models/OpenApiConstants.cs index eccf3a616..40867d7e0 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiConstants.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiConstants.cs @@ -568,12 +568,12 @@ public static class OpenApiConstants /// /// Field: version3_0_0 /// - public static readonly Version version3_0_0 = new Version(3, 0, 0); + public static readonly Version version3_0_0 = new(3, 0, 0); /// /// Field: defaultUrl /// - public static readonly Uri defaultUrl = new Uri("http://localhost/"); + public static readonly Uri defaultUrl = new("http://localhost/"); #region V2.0 @@ -590,7 +590,7 @@ public static class OpenApiConstants /// /// Field: version2_0 /// - public static readonly Version version2_0 = new Version(2, 0); + public static readonly Version version2_0 = new(2, 0); /// /// Field: BasePath diff --git a/src/Microsoft.OpenApi/Models/OpenApiDocument.cs b/src/Microsoft.OpenApi/Models/OpenApiDocument.cs index c19de5e84..f55d9c205 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiDocument.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiDocument.cs @@ -209,7 +209,7 @@ public void SerializeAsV2(IOpenApiWriter writer) } // parameters var parameters = Components?.Parameters != null - ? new Dictionary(Components.Parameters) + ? new(Components.Parameters) : new Dictionary(); if (Components?.RequestBodies != null) @@ -417,7 +417,7 @@ public static string GenerateHashValue(OpenApiDocument doc) using var cryptoStream = new CryptoStream(Stream.Null, sha, CryptoStreamMode.Write); using var streamWriter = new StreamWriter(cryptoStream); - var openApiJsonWriter = new OpenApiJsonWriter(streamWriter, new OpenApiJsonWriterSettings { Terse = true }); + var openApiJsonWriter = new OpenApiJsonWriter(streamWriter, new() { Terse = true }); doc.SerializeAsV3(openApiJsonWriter); openApiJsonWriter.Flush(); diff --git a/src/Microsoft.OpenApi/Models/OpenApiLink.cs b/src/Microsoft.OpenApi/Models/OpenApiLink.cs index 4f32dd6eb..773c06566 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiLink.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiLink.cs @@ -28,7 +28,7 @@ public class OpenApiLink : IOpenApiReferenceable, IOpenApiExtensible, IEffective /// A map representing parameters to pass to an operation as specified with operationId or identified via operationRef. /// public Dictionary Parameters { get; set; } = - new Dictionary(); + new(); /// /// A literal value or {expression} to use as a request body when calling the target operation. diff --git a/src/Microsoft.OpenApi/Models/OpenApiOperation.cs b/src/Microsoft.OpenApi/Models/OpenApiOperation.cs index 808e50aa0..a569c7d64 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiOperation.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiOperation.cs @@ -67,7 +67,7 @@ public class OpenApiOperation : IOpenApiSerializable, IOpenApiExtensible /// /// REQUIRED. The list of possible responses as they are returned from executing this operation. /// - public OpenApiResponses Responses { get; set; } = new OpenApiResponses(); + public OpenApiResponses Responses { get; set; } = new(); /// /// A map of possible out-of band callbacks related to the parent operation. @@ -226,11 +226,11 @@ public void SerializeAsV2(IOpenApiWriter writer) List parameters; if (Parameters == null) { - parameters = new List(); + parameters = new(); } else { - parameters = new List(Parameters); + parameters = new(Parameters); } if (RequestBody != null) @@ -253,7 +253,7 @@ public void SerializeAsV2(IOpenApiWriter writer) else if (RequestBody.Reference != null) { parameters.Add( - new OpenApiParameter + new() { UnresolvedReference = true, Reference = RequestBody.Reference diff --git a/src/Microsoft.OpenApi/Models/OpenApiRequestBody.cs b/src/Microsoft.OpenApi/Models/OpenApiRequestBody.cs index 83da1e664..7ce175b2d 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiRequestBody.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiRequestBody.cs @@ -182,7 +182,7 @@ internal IEnumerable ConvertToFormDataParameters() paramSchema.Type = "file"; paramSchema.Format = null; } - yield return new OpenApiFormDataParameter + yield return new() { Description = property.Value.Description, Name = property.Key, diff --git a/src/Microsoft.OpenApi/Models/OpenApiServerVariable.cs b/src/Microsoft.OpenApi/Models/OpenApiServerVariable.cs index 95f913a2e..1eefee39b 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiServerVariable.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiServerVariable.cs @@ -26,7 +26,7 @@ public class OpenApiServerVariable : IOpenApiSerializable, IOpenApiExtensible /// /// An enumeration of string values to be used if the substitution options are from a limited set. /// - public List Enum { get; set; } = new List(); + public List Enum { get; set; } = new(); /// /// This object MAY be extended with Specification Extensions. @@ -45,7 +45,7 @@ public OpenApiServerVariable(OpenApiServerVariable serverVariable) { Description = serverVariable?.Description; Default = serverVariable?.Default; - Enum = serverVariable?.Enum != null ? new List(serverVariable?.Enum) : serverVariable?.Enum; + Enum = serverVariable?.Enum != null ? new(serverVariable?.Enum) : serverVariable?.Enum; Extensions = serverVariable?.Extensions != null ? new Dictionary(serverVariable?.Extensions) : serverVariable?.Extensions; } diff --git a/src/Microsoft.OpenApi/Services/CopyReferences.cs b/src/Microsoft.OpenApi/Services/CopyReferences.cs index 6307ed072..757471466 100644 --- a/src/Microsoft.OpenApi/Services/CopyReferences.cs +++ b/src/Microsoft.OpenApi/Services/CopyReferences.cs @@ -91,7 +91,7 @@ private void EnsureComponentsExists() { if (_target.Components == null) { - _target.Components = new OpenApiComponents(); + _target.Components = new(); } } diff --git a/src/Microsoft.OpenApi/Services/LoopDetector.cs b/src/Microsoft.OpenApi/Services/LoopDetector.cs index 2c9618213..904361f97 100644 --- a/src/Microsoft.OpenApi/Services/LoopDetector.cs +++ b/src/Microsoft.OpenApi/Services/LoopDetector.cs @@ -5,7 +5,7 @@ namespace Microsoft.OpenApi.Services { internal class LoopDetector { - private readonly Dictionary> _loopStacks = new Dictionary>(); + private readonly Dictionary> _loopStacks = new(); /// /// Maintain history of traversals to avoid stack overflows from cycles @@ -16,7 +16,7 @@ public bool PushLoop(T key) { if (!_loopStacks.TryGetValue(typeof(T), out var stack)) { - stack = new Stack(); + stack = new(); _loopStacks.Add(typeof(T), stack); } @@ -46,7 +46,7 @@ public void SaveLoop(T loop) { if (!Loops.ContainsKey(typeof(T))) { - Loops[typeof(T)] = new List(); + Loops[typeof(T)] = new(); } Loops[typeof(T)].Add(loop); } @@ -54,7 +54,7 @@ public void SaveLoop(T loop) /// /// List of Loops detected /// - public Dictionary> Loops { get; } = new Dictionary>(); + public Dictionary> Loops { get; } = new(); /// /// Reset loop tracking stack diff --git a/src/Microsoft.OpenApi/Services/OpenApiFilterService.cs b/src/Microsoft.OpenApi/Services/OpenApiFilterService.cs index 5de121380..94bd995c4 100644 --- a/src/Microsoft.OpenApi/Services/OpenApiFilterService.cs +++ b/src/Microsoft.OpenApi/Services/OpenApiFilterService.cs @@ -63,7 +63,7 @@ public static OpenApiDocument CreateFilteredDocument(OpenApiDocument source, Fun // Fetch and copy title, graphVersion and server info from OpenApiDoc var subset = new OpenApiDocument { - Info = new OpenApiInfo + Info = new() { Title = source.Info.Title + " - Subset", Description = source.Info.Description, @@ -74,7 +74,7 @@ public static OpenApiDocument CreateFilteredDocument(OpenApiDocument source, Fun Extensions = source.Info.Extensions }, - Components = new OpenApiComponents { SecuritySchemes = source.Components.SecuritySchemes }, + Components = new() { SecuritySchemes = source.Components.SecuritySchemes }, SecurityRequirements = source.SecurityRequirements, Servers = source.Servers }; @@ -87,15 +87,15 @@ public static OpenApiDocument CreateFilteredDocument(OpenApiDocument source, Fun if (subset.Paths == null) { - subset.Paths = new OpenApiPaths(); - pathItem = new OpenApiPathItem(); + subset.Paths = new(); + pathItem = new(); subset.Paths.Add(pathKey, pathItem); } else { if (!subset.Paths.TryGetValue(pathKey, out pathItem)) { - pathItem = new OpenApiPathItem(); + pathItem = new(); subset.Paths.Add(pathKey, pathItem); } } @@ -284,7 +284,7 @@ private static string ExtractPath(string url, IList serverList) .FirstOrDefault(c => url.Contains(c)); return baseUrl == null ? - new Uri(new Uri(SRResource.DefaultBaseUri), url).GetComponents(UriComponents.Path | UriComponents.KeepDelimiter, UriFormat.Unescaped) + new Uri(new(SRResource.DefaultBaseUri), url).GetComponents(UriComponents.Path | UriComponents.KeepDelimiter, UriFormat.Unescaped) : url.Split(new[] { baseUrl }, StringSplitOptions.None)[1]; } diff --git a/src/Microsoft.OpenApi/Services/OpenApiReferenceResolver.cs b/src/Microsoft.OpenApi/Services/OpenApiReferenceResolver.cs index cca475914..19e463e36 100644 --- a/src/Microsoft.OpenApi/Services/OpenApiReferenceResolver.cs +++ b/src/Microsoft.OpenApi/Services/OpenApiReferenceResolver.cs @@ -17,7 +17,7 @@ public class OpenApiReferenceResolver : OpenApiVisitorBase { private OpenApiDocument _currentDocument; private readonly bool _resolveRemoteReferences; - private List _errors = new List(); + private List _errors = new(); /// /// Initializes the class. @@ -205,7 +205,7 @@ private void ResolveTags(IList tags) if (resolvedTag == null) { - resolvedTag = new OpenApiTag + resolvedTag = new() { Name = tag.Reference.Id }; @@ -290,7 +290,7 @@ private void ResolveTags(IList tags) else { // Leave as unresolved reference - return new T + return new() { UnresolvedReference = true, Reference = reference diff --git a/src/Microsoft.OpenApi/Services/OpenApiUrlTreeNode.cs b/src/Microsoft.OpenApi/Services/OpenApiUrlTreeNode.cs index dbef8414b..2d55e7038 100644 --- a/src/Microsoft.OpenApi/Services/OpenApiUrlTreeNode.cs +++ b/src/Microsoft.OpenApi/Services/OpenApiUrlTreeNode.cs @@ -76,7 +76,7 @@ private OpenApiUrlTreeNode(string segment) /// The root node of the created directory structure. public static OpenApiUrlTreeNode Create() { - return new OpenApiUrlTreeNode(RootPathSegment); + return new(RootPathSegment); } /// diff --git a/src/Microsoft.OpenApi/Services/OpenApiVisitorBase.cs b/src/Microsoft.OpenApi/Services/OpenApiVisitorBase.cs index 15cf7713c..87dd07b81 100644 --- a/src/Microsoft.OpenApi/Services/OpenApiVisitorBase.cs +++ b/src/Microsoft.OpenApi/Services/OpenApiVisitorBase.cs @@ -14,12 +14,12 @@ namespace Microsoft.OpenApi.Services /// public abstract class OpenApiVisitorBase { - private readonly Stack _path = new Stack(); + private readonly Stack _path = new(); /// /// Properties available to identify context of where an object is within OpenAPI Document /// - public CurrentKeys CurrentKeys { get; } = new CurrentKeys(); + public CurrentKeys CurrentKeys { get; } = new(); /// /// Allow Rule to indicate validation error occured at a deeper context level. diff --git a/src/Microsoft.OpenApi/Services/OpenApiWalker.cs b/src/Microsoft.OpenApi/Services/OpenApiWalker.cs index c123dbaa8..ddda44218 100644 --- a/src/Microsoft.OpenApi/Services/OpenApiWalker.cs +++ b/src/Microsoft.OpenApi/Services/OpenApiWalker.cs @@ -16,8 +16,8 @@ namespace Microsoft.OpenApi.Services public class OpenApiWalker { private readonly OpenApiVisitorBase _visitor; - private readonly Stack _schemaLoop = new Stack(); - private readonly Stack _pathItemLoop = new Stack(); + private readonly Stack _schemaLoop = new(); + private readonly Stack _pathItemLoop = new(); /// /// Initializes the class. diff --git a/src/Microsoft.OpenApi/Services/OpenApiWorkspace.cs b/src/Microsoft.OpenApi/Services/OpenApiWorkspace.cs index 1d0636dec..dc7ae75d3 100644 --- a/src/Microsoft.OpenApi/Services/OpenApiWorkspace.cs +++ b/src/Microsoft.OpenApi/Services/OpenApiWorkspace.cs @@ -15,9 +15,9 @@ namespace Microsoft.OpenApi.Services /// public class OpenApiWorkspace { - private Dictionary _documents = new Dictionary(); - private Dictionary _fragments = new Dictionary(); - private Dictionary _artifacts = new Dictionary(); + private Dictionary _documents = new(); + private Dictionary _fragments = new(); + private Dictionary _artifacts = new(); /// /// A list of OpenApiDocuments contained in the workspace @@ -57,7 +57,7 @@ public OpenApiWorkspace(Uri baseUrl) /// public OpenApiWorkspace() { - BaseUrl = new Uri("file://" + Environment.CurrentDirectory + $"{Path.DirectorySeparatorChar}" ); + BaseUrl = new("file://" + Environment.CurrentDirectory + $"{Path.DirectorySeparatorChar}" ); } /// @@ -117,11 +117,11 @@ public void AddArtifact(string location, Stream artifact) /// public IOpenApiReferenceable ResolveReference(OpenApiReference reference) { - if (_documents.TryGetValue(new Uri(BaseUrl, reference.ExternalResource), out var doc)) + if (_documents.TryGetValue(new(BaseUrl, reference.ExternalResource), out var doc)) { return doc.ResolveReference(reference, false); } - else if (_fragments.TryGetValue(new Uri(BaseUrl, reference.ExternalResource), out var fragment)) + else if (_fragments.TryGetValue(new(BaseUrl, reference.ExternalResource), out var fragment)) { var jsonPointer = new JsonPointer($"/{reference.Id ?? string.Empty}"); return fragment.ResolveReference(jsonPointer); @@ -141,7 +141,7 @@ public Stream GetArtifact(string location) private Uri ToLocationUrl(string location) { - return new Uri(BaseUrl, location); + return new(BaseUrl, location); } } } diff --git a/src/Microsoft.OpenApi/Services/OperationSearch.cs b/src/Microsoft.OpenApi/Services/OperationSearch.cs index 8d251ec71..49cdac49c 100644 --- a/src/Microsoft.OpenApi/Services/OperationSearch.cs +++ b/src/Microsoft.OpenApi/Services/OperationSearch.cs @@ -43,7 +43,7 @@ public override void Visit(OpenApiPathItem pathItem) if (_predicate(CurrentKeys.Path, operationType, operation)) { - _searchResults.Add(new SearchResult + _searchResults.Add(new() { Operation = operation, Parameters = pathItem.Parameters, @@ -74,7 +74,7 @@ public override void Visit(IList parameters) private static CurrentKeys CopyCurrentKeys(CurrentKeys currentKeys, OperationType operationType) { - return new CurrentKeys + return new() { Path = currentKeys.Path, Operation = operationType, diff --git a/src/Microsoft.OpenApi/Validations/Rules/OpenApiComponentsRules.cs b/src/Microsoft.OpenApi/Validations/Rules/OpenApiComponentsRules.cs index 468e97447..f2f3a649c 100644 --- a/src/Microsoft.OpenApi/Validations/Rules/OpenApiComponentsRules.cs +++ b/src/Microsoft.OpenApi/Validations/Rules/OpenApiComponentsRules.cs @@ -17,14 +17,14 @@ public static class OpenApiComponentsRules /// /// The key regex. /// - public static Regex KeyRegex = new Regex(@"^[a-zA-Z0-9\.\-_]+$"); + public static Regex KeyRegex = new(@"^[a-zA-Z0-9\.\-_]+$"); /// /// All the fixed fields declared above are objects /// that MUST use keys that match the regular expression: ^[a-zA-Z0-9\.\-_]+$. /// public static ValidationRule KeyMustBeRegularExpression => - new ValidationRule( + new( (context, components) => { ValidateKeys(context, components.Schemas?.Keys, "schemas"); diff --git a/src/Microsoft.OpenApi/Validations/Rules/OpenApiContactRules.cs b/src/Microsoft.OpenApi/Validations/Rules/OpenApiContactRules.cs index 0c949f8a7..b64704375 100644 --- a/src/Microsoft.OpenApi/Validations/Rules/OpenApiContactRules.cs +++ b/src/Microsoft.OpenApi/Validations/Rules/OpenApiContactRules.cs @@ -17,7 +17,7 @@ public static class OpenApiContactRules /// Email field MUST be email address. /// public static ValidationRule EmailMustBeEmailFormat => - new ValidationRule( + new( (context, item) => { context.Enter("email"); diff --git a/src/Microsoft.OpenApi/Validations/Rules/OpenApiDocumentRules.cs b/src/Microsoft.OpenApi/Validations/Rules/OpenApiDocumentRules.cs index 7d01f1319..be0dc1538 100644 --- a/src/Microsoft.OpenApi/Validations/Rules/OpenApiDocumentRules.cs +++ b/src/Microsoft.OpenApi/Validations/Rules/OpenApiDocumentRules.cs @@ -17,7 +17,7 @@ public static class OpenApiDocumentRules /// The Info field is required. /// public static ValidationRule OpenApiDocumentFieldIsMissing => - new ValidationRule( + new( (context, item) => { // info diff --git a/src/Microsoft.OpenApi/Validations/Rules/OpenApiExtensionRules.cs b/src/Microsoft.OpenApi/Validations/Rules/OpenApiExtensionRules.cs index ea7086257..5d124e8de 100644 --- a/src/Microsoft.OpenApi/Validations/Rules/OpenApiExtensionRules.cs +++ b/src/Microsoft.OpenApi/Validations/Rules/OpenApiExtensionRules.cs @@ -17,7 +17,7 @@ public static class OpenApiExtensibleRules /// Extension name MUST start with "x-". /// public static ValidationRule ExtensionNameMustStartWithXDash => - new ValidationRule( + new( (context, item) => { context.Enter("extensions"); diff --git a/src/Microsoft.OpenApi/Validations/Rules/OpenApiExternalDocsRules.cs b/src/Microsoft.OpenApi/Validations/Rules/OpenApiExternalDocsRules.cs index 8556eaa32..ff4fde4a2 100644 --- a/src/Microsoft.OpenApi/Validations/Rules/OpenApiExternalDocsRules.cs +++ b/src/Microsoft.OpenApi/Validations/Rules/OpenApiExternalDocsRules.cs @@ -17,7 +17,7 @@ public static class OpenApiExternalDocsRules /// Validate the field is required. /// public static ValidationRule UrlIsRequired => - new ValidationRule( + new( (context, item) => { // url diff --git a/src/Microsoft.OpenApi/Validations/Rules/OpenApiHeaderRules.cs b/src/Microsoft.OpenApi/Validations/Rules/OpenApiHeaderRules.cs index 6f76d9d91..c446a7b56 100644 --- a/src/Microsoft.OpenApi/Validations/Rules/OpenApiHeaderRules.cs +++ b/src/Microsoft.OpenApi/Validations/Rules/OpenApiHeaderRules.cs @@ -16,7 +16,7 @@ public static class OpenApiHeaderRules /// Validate the data matches with the given data type. /// public static ValidationRule HeaderMismatchedDataType => - new ValidationRule( + new( (context, header) => { // example diff --git a/src/Microsoft.OpenApi/Validations/Rules/OpenApiInfoRules.cs b/src/Microsoft.OpenApi/Validations/Rules/OpenApiInfoRules.cs index b3b533e32..88b534c02 100644 --- a/src/Microsoft.OpenApi/Validations/Rules/OpenApiInfoRules.cs +++ b/src/Microsoft.OpenApi/Validations/Rules/OpenApiInfoRules.cs @@ -17,7 +17,7 @@ public static class OpenApiInfoRules /// Validate the field is required. /// public static ValidationRule InfoRequiredFields => - new ValidationRule( + new( (context, item) => { // title diff --git a/src/Microsoft.OpenApi/Validations/Rules/OpenApiLicenseRules.cs b/src/Microsoft.OpenApi/Validations/Rules/OpenApiLicenseRules.cs index 89b88ca9d..edbf19bf5 100644 --- a/src/Microsoft.OpenApi/Validations/Rules/OpenApiLicenseRules.cs +++ b/src/Microsoft.OpenApi/Validations/Rules/OpenApiLicenseRules.cs @@ -17,7 +17,7 @@ public static class OpenApiLicenseRules /// REQUIRED. /// public static ValidationRule LicenseRequiredFields => - new ValidationRule( + new( (context, license) => { context.Enter("name"); diff --git a/src/Microsoft.OpenApi/Validations/Rules/OpenApiMediaTypeRules.cs b/src/Microsoft.OpenApi/Validations/Rules/OpenApiMediaTypeRules.cs index 347b80e6d..0e78b38de 100644 --- a/src/Microsoft.OpenApi/Validations/Rules/OpenApiMediaTypeRules.cs +++ b/src/Microsoft.OpenApi/Validations/Rules/OpenApiMediaTypeRules.cs @@ -24,7 +24,7 @@ public static class OpenApiMediaTypeRules /// Validate the data matches with the given data type. /// public static ValidationRule MediaTypeMismatchedDataType => - new ValidationRule( + new( (context, mediaType) => { // example diff --git a/src/Microsoft.OpenApi/Validations/Rules/OpenApiOAuthFlowRules.cs b/src/Microsoft.OpenApi/Validations/Rules/OpenApiOAuthFlowRules.cs index 95444fb9a..de31d933d 100644 --- a/src/Microsoft.OpenApi/Validations/Rules/OpenApiOAuthFlowRules.cs +++ b/src/Microsoft.OpenApi/Validations/Rules/OpenApiOAuthFlowRules.cs @@ -17,7 +17,7 @@ public static class OpenApiOAuthFlowRules /// Validate the field is required. /// public static ValidationRule OAuthFlowRequiredFields => - new ValidationRule( + new( (context, flow) => { // authorizationUrl diff --git a/src/Microsoft.OpenApi/Validations/Rules/OpenApiParameterRules.cs b/src/Microsoft.OpenApi/Validations/Rules/OpenApiParameterRules.cs index 878e2db10..5c19ce1d9 100644 --- a/src/Microsoft.OpenApi/Validations/Rules/OpenApiParameterRules.cs +++ b/src/Microsoft.OpenApi/Validations/Rules/OpenApiParameterRules.cs @@ -17,7 +17,7 @@ public static class OpenApiParameterRules /// Validate the field is required. /// public static ValidationRule ParameterRequiredFields => - new ValidationRule( + new( (context, item) => { // name @@ -43,7 +43,7 @@ public static class OpenApiParameterRules /// Validate the "required" field is true when "in" is path. /// public static ValidationRule RequiredMustBeTrueWhenInIsPath => - new ValidationRule( + new( (context, item) => { // required @@ -62,7 +62,7 @@ public static class OpenApiParameterRules /// Validate the data matches with the given data type. /// public static ValidationRule ParameterMismatchedDataType => - new ValidationRule( + new( (context, parameter) => { // example @@ -100,7 +100,7 @@ public static class OpenApiParameterRules /// Validate that a path parameter should always appear in the path /// public static ValidationRule PathParameterShouldBeInThePath => - new ValidationRule( + new( (context, parameter) => { if (parameter.In == ParameterLocation.Path && diff --git a/src/Microsoft.OpenApi/Validations/Rules/OpenApiPathsRules.cs b/src/Microsoft.OpenApi/Validations/Rules/OpenApiPathsRules.cs index f6232f15d..d4e4f5727 100644 --- a/src/Microsoft.OpenApi/Validations/Rules/OpenApiPathsRules.cs +++ b/src/Microsoft.OpenApi/Validations/Rules/OpenApiPathsRules.cs @@ -16,7 +16,7 @@ public static class OpenApiPathsRules /// A relative path to an individual endpoint. The field name MUST begin with a slash. /// public static ValidationRule PathNameMustBeginWithSlash => - new ValidationRule( + new( (context, item) => { foreach (var pathName in item.Keys) diff --git a/src/Microsoft.OpenApi/Validations/Rules/OpenApiResponseRules.cs b/src/Microsoft.OpenApi/Validations/Rules/OpenApiResponseRules.cs index 11b228e74..0f725c90e 100644 --- a/src/Microsoft.OpenApi/Validations/Rules/OpenApiResponseRules.cs +++ b/src/Microsoft.OpenApi/Validations/Rules/OpenApiResponseRules.cs @@ -17,7 +17,7 @@ public static class OpenApiResponseRules /// Validate the field is required. /// public static ValidationRule ResponseRequiredFields => - new ValidationRule( + new( (context, response) => { // description diff --git a/src/Microsoft.OpenApi/Validations/Rules/OpenApiResponsesRules.cs b/src/Microsoft.OpenApi/Validations/Rules/OpenApiResponsesRules.cs index 5df74c2e9..1afe9a388 100644 --- a/src/Microsoft.OpenApi/Validations/Rules/OpenApiResponsesRules.cs +++ b/src/Microsoft.OpenApi/Validations/Rules/OpenApiResponsesRules.cs @@ -17,7 +17,7 @@ public static class OpenApiResponsesRules /// An OpenAPI operation must contain at least one response /// public static ValidationRule ResponsesMustContainAtLeastOneResponse => - new ValidationRule( + new( (context, responses) => { if (!responses.Keys.Any()) @@ -31,7 +31,7 @@ public static class OpenApiResponsesRules /// The response key must either be "default" or an HTTP status code (1xx, 2xx, 3xx, 4xx, 5xx). /// public static ValidationRule ResponsesMustBeIdentifiedByDefaultOrStatusCode => - new ValidationRule( + new( (context, responses) => { foreach (var key in responses.Keys) diff --git a/src/Microsoft.OpenApi/Validations/Rules/OpenApiSchemaRules.cs b/src/Microsoft.OpenApi/Validations/Rules/OpenApiSchemaRules.cs index 6753a3e65..493341acf 100644 --- a/src/Microsoft.OpenApi/Validations/Rules/OpenApiSchemaRules.cs +++ b/src/Microsoft.OpenApi/Validations/Rules/OpenApiSchemaRules.cs @@ -17,7 +17,7 @@ public static class OpenApiSchemaRules /// Validate the data matches with the given data type. /// public static ValidationRule SchemaMismatchedDataType => - new ValidationRule( + new( (context, schema) => { // default @@ -60,7 +60,7 @@ public static class OpenApiSchemaRules /// Validates Schema Discriminator /// public static ValidationRule ValidateSchemaDiscriminator => - new ValidationRule( + new( (context, schema) => { // discriminator diff --git a/src/Microsoft.OpenApi/Validations/Rules/OpenApiServerRules.cs b/src/Microsoft.OpenApi/Validations/Rules/OpenApiServerRules.cs index 67fc5eef2..292fd1fd0 100644 --- a/src/Microsoft.OpenApi/Validations/Rules/OpenApiServerRules.cs +++ b/src/Microsoft.OpenApi/Validations/Rules/OpenApiServerRules.cs @@ -17,7 +17,7 @@ public static class OpenApiServerRules /// Validate the field is required. /// public static ValidationRule ServerRequiredFields => - new ValidationRule( + new( (context, server) => { context.Enter("url"); diff --git a/src/Microsoft.OpenApi/Validations/Rules/OpenApiTagRules.cs b/src/Microsoft.OpenApi/Validations/Rules/OpenApiTagRules.cs index 9dac45966..f28732e1e 100644 --- a/src/Microsoft.OpenApi/Validations/Rules/OpenApiTagRules.cs +++ b/src/Microsoft.OpenApi/Validations/Rules/OpenApiTagRules.cs @@ -17,7 +17,7 @@ public static class OpenApiTagRules /// Validate the field is required. /// public static ValidationRule TagRequiredFields => - new ValidationRule( + new( (context, tag) => { context.Enter("name"); diff --git a/src/Microsoft.OpenApi/Validations/ValidationRuleSet.cs b/src/Microsoft.OpenApi/Validations/ValidationRuleSet.cs index 5199f82bc..6cc4d3a05 100644 --- a/src/Microsoft.OpenApi/Validations/ValidationRuleSet.cs +++ b/src/Microsoft.OpenApi/Validations/ValidationRuleSet.cs @@ -52,7 +52,7 @@ public static ValidationRuleSet GetDefaultRuleSet() // We create a new instance of ValidationRuleSet per call as a safeguard // against unintentional modification of the private _defaultRuleSet. - return new ValidationRuleSet(_defaultRuleSet); + return new(_defaultRuleSet); } /// @@ -62,7 +62,7 @@ public static ValidationRuleSet GetEmptyRuleSet() { // We create a new instance of ValidationRuleSet per call as a safeguard // against unintentional modification of the private _defaultRuleSet. - return new ValidationRuleSet(); + return new(); } /// diff --git a/src/Microsoft.OpenApi/Writers/OpenApiWriterBase.cs b/src/Microsoft.OpenApi/Writers/OpenApiWriterBase.cs index 99cc75841..c39244745 100644 --- a/src/Microsoft.OpenApi/Writers/OpenApiWriterBase.cs +++ b/src/Microsoft.OpenApi/Writers/OpenApiWriterBase.cs @@ -52,10 +52,10 @@ public OpenApiWriterBase(TextWriter textWriter, OpenApiWriterSettings settings) Writer = textWriter; Writer.NewLine = "\n"; - Scopes = new Stack(); + Scopes = new(); if (settings == null) { - settings = new OpenApiWriterSettings(); + settings = new(); } Settings = settings; } diff --git a/src/Microsoft.OpenApi/Writers/OpenApiWriterSettings.cs b/src/Microsoft.OpenApi/Writers/OpenApiWriterSettings.cs index 7c143d456..dda995b0f 100644 --- a/src/Microsoft.OpenApi/Writers/OpenApiWriterSettings.cs +++ b/src/Microsoft.OpenApi/Writers/OpenApiWriterSettings.cs @@ -33,7 +33,7 @@ public class OpenApiWriterSettings [Obsolete("Use InlineLocalReference and InlineExternalReference settings instead")] private ReferenceInlineSetting referenceInline = ReferenceInlineSetting.DoNotInlineReferences; - internal LoopDetector LoopDetector { get; } = new LoopDetector(); + internal LoopDetector LoopDetector { get; } = new(); /// /// Indicates how references in the source document should be handled. /// diff --git a/test/Microsoft.OpenApi.Hidi.Tests/Formatters/PowerShellFormatterTests.cs b/test/Microsoft.OpenApi.Hidi.Tests/Formatters/PowerShellFormatterTests.cs index c261a8e46..a5bf74219 100644 --- a/test/Microsoft.OpenApi.Hidi.Tests/Formatters/PowerShellFormatterTests.cs +++ b/test/Microsoft.OpenApi.Hidi.Tests/Formatters/PowerShellFormatterTests.cs @@ -93,7 +93,7 @@ public void ResolveFunctionParameters() private static OpenApiDocument GetSampleOpenApiDocument() { - return new OpenApiDocument + return new() { Info = new() { Title = "Test", Version = "1.0" }, Servers = new List { new() { Url = "https://localhost/" } }, @@ -108,7 +108,7 @@ private static OpenApiDocument GetSampleOpenApiDocument() OperationId = "Foo.GetFoo", Parameters = new List { - new OpenApiParameter + new() { Name = "ids", In = ParameterLocation.Query, @@ -118,10 +118,10 @@ private static OpenApiDocument GetSampleOpenApiDocument() "application/json", new OpenApiMediaType { - Schema = new OpenApiSchema + Schema = new() { Type = "array", - Items = new OpenApiSchema + Items = new() { Type = "string" } @@ -157,8 +157,8 @@ private static OpenApiDocument GetSampleOpenApiDocument() { AnyOf = new List { - new OpenApiSchema { Type = "number" }, - new OpenApiSchema { Type = "string" } + new() { Type = "number" }, + new() { Type = "string" } }, Format = "float", Nullable = true @@ -169,8 +169,8 @@ private static OpenApiDocument GetSampleOpenApiDocument() { OneOf = new List { - new OpenApiSchema { Type = "number", Format = "double" }, - new OpenApiSchema { Type = "string" } + new() { Type = "number", Format = "double" }, + new() { Type = "string" } } } } diff --git a/test/Microsoft.OpenApi.Hidi.Tests/Services/OpenApiFilterServiceTests.cs b/test/Microsoft.OpenApi.Hidi.Tests/Services/OpenApiFilterServiceTests.cs index 03c611583..0f353b326 100644 --- a/test/Microsoft.OpenApi.Hidi.Tests/Services/OpenApiFilterServiceTests.cs +++ b/test/Microsoft.OpenApi.Hidi.Tests/Services/OpenApiFilterServiceTests.cs @@ -19,7 +19,7 @@ public class OpenApiFilterServiceTests public OpenApiFilterServiceTests() { _openApiDocumentMock = OpenApiDocumentMock.CreateOpenApiDocument(); - _mockLogger = new Mock>(); + _mockLogger = new(); _logger = _mockLogger.Object; } diff --git a/test/Microsoft.OpenApi.Hidi.Tests/Services/OpenApiServiceTests.cs b/test/Microsoft.OpenApi.Hidi.Tests/Services/OpenApiServiceTests.cs index d4e97ed9b..b2b6b6c9b 100644 --- a/test/Microsoft.OpenApi.Hidi.Tests/Services/OpenApiServiceTests.cs +++ b/test/Microsoft.OpenApi.Hidi.Tests/Services/OpenApiServiceTests.cs @@ -92,7 +92,7 @@ public void ShowCommandGeneratesMermaidDiagramAsMarkdown() { var openApiDoc = new OpenApiDocument { - Info = new OpenApiInfo + Info = new() { Title = "Test", Version = "1.0.0" @@ -113,7 +113,7 @@ public void ShowCommandGeneratesMermaidDiagramAsHtml() { var openApiDoc = new OpenApiDocument { - Info = new OpenApiInfo + Info = new() { Title = "Test", Version = "1.0.0" @@ -136,7 +136,7 @@ public async Task ShowCommandGeneratesMermaidMarkdownFileWithMermaidDiagram() var options = new HidiOptions { OpenApi = Path.Combine("UtilityFiles", "SampleOpenApi.yml"), - Output = new FileInfo("sample.md") + Output = new("sample.md") }; await OpenApiService.ShowOpenApiDocument(options, _logger); @@ -163,7 +163,7 @@ public async Task ShowCommandGeneratesMermaidMarkdownFileFromCsdlWithMermaidDiag { Csdl = Path.Combine("UtilityFiles", "Todo.xml"), CsdlFilter = "todos", - Output = new FileInfo("sample.md") + Output = new("sample.md") }; // create a dummy ILogger instance for testing @@ -211,7 +211,7 @@ public async Task TransformCommandConvertsOpenApi() HidiOptions options = new HidiOptions { OpenApi = Path.Combine("UtilityFiles", "SampleOpenApi.yml"), - Output = new FileInfo("sample.json"), + Output = new("sample.json"), CleanOutput = true, TerseOutput = false, InlineLocal = false, diff --git a/test/Microsoft.OpenApi.Hidi.Tests/UtilityFiles/OpenApiDocumentMock.cs b/test/Microsoft.OpenApi.Hidi.Tests/UtilityFiles/OpenApiDocumentMock.cs index 106509a3d..67b06f72a 100644 --- a/test/Microsoft.OpenApi.Hidi.Tests/UtilityFiles/OpenApiDocumentMock.cs +++ b/test/Microsoft.OpenApi.Hidi.Tests/UtilityFiles/OpenApiDocumentMock.cs @@ -22,21 +22,21 @@ public static OpenApiDocument CreateOpenApiDocument() var document = new OpenApiDocument { - Info = new OpenApiInfo + Info = new() { Title = "People", Version = "v1.0" }, Servers = new List { - new OpenApiServer + new() { Url = "https://graph.microsoft.com/v1.0" } }, - Paths = new OpenApiPaths + Paths = new() { - ["/"] = new OpenApiPathItem() // root path + ["/"] = new() // root path { Operations = new Dictionary { @@ -44,10 +44,10 @@ public static OpenApiDocument CreateOpenApiDocument() OperationType.Get, new OpenApiOperation { OperationId = "graphService.GetGraphService", - Responses = new OpenApiResponses + Responses = new() { { - "200",new OpenApiResponse + "200",new() { Description = "OK" } @@ -57,7 +57,7 @@ public static OpenApiDocument CreateOpenApiDocument() } } }, - ["/reports/microsoft.graph.getTeamsUserActivityCounts(period={period})"] = new OpenApiPathItem + ["/reports/microsoft.graph.getTeamsUserActivityCounts(period={period})"] = new() { Operations = new Dictionary { @@ -67,7 +67,7 @@ public static OpenApiDocument CreateOpenApiDocument() Tags = new List { { - new OpenApiTag + new() { Name = "reports.Functions" } @@ -78,22 +78,22 @@ public static OpenApiDocument CreateOpenApiDocument() Parameters = new List { { - new OpenApiParameter + new() { Name = "period", In = ParameterLocation.Path, Required = true, - Schema = new OpenApiSchema + Schema = new() { Type = "string" } } } }, - Responses = new OpenApiResponses + Responses = new() { { - "200", new OpenApiResponse + "200", new() { Description = "Success", Content = new Dictionary @@ -102,7 +102,7 @@ public static OpenApiDocument CreateOpenApiDocument() applicationJsonMediaType, new OpenApiMediaType { - Schema = new OpenApiSchema + Schema = new() { Type = "array" } @@ -118,12 +118,12 @@ public static OpenApiDocument CreateOpenApiDocument() Parameters = new List { { - new OpenApiParameter + new() { Name = "period", In = ParameterLocation.Path, Required = true, - Schema = new OpenApiSchema + Schema = new() { Type = "string" } @@ -131,7 +131,7 @@ public static OpenApiDocument CreateOpenApiDocument() } } }, - ["/reports/microsoft.graph.getTeamsUserActivityUserDetail(date={date})"] = new OpenApiPathItem + ["/reports/microsoft.graph.getTeamsUserActivityUserDetail(date={date})"] = new() { Operations = new Dictionary { @@ -141,7 +141,7 @@ public static OpenApiDocument CreateOpenApiDocument() Tags = new List { { - new OpenApiTag + new() { Name = "reports.Functions" } @@ -152,22 +152,22 @@ public static OpenApiDocument CreateOpenApiDocument() Parameters = new List { { - new OpenApiParameter + new() { Name = "period", In = ParameterLocation.Path, Required = true, - Schema = new OpenApiSchema + Schema = new() { Type = "string" } } } }, - Responses = new OpenApiResponses + Responses = new() { { - "200", new OpenApiResponse + "200", new() { Description = "Success", Content = new Dictionary @@ -176,7 +176,7 @@ public static OpenApiDocument CreateOpenApiDocument() applicationJsonMediaType, new OpenApiMediaType { - Schema = new OpenApiSchema + Schema = new() { Type = "array" } @@ -191,19 +191,19 @@ public static OpenApiDocument CreateOpenApiDocument() }, Parameters = new List { - new OpenApiParameter + new() { Name = "period", In = ParameterLocation.Path, Required = true, - Schema = new OpenApiSchema + Schema = new() { Type = "string" } } } }, - ["/users"] = new OpenApiPathItem + ["/users"] = new() { Operations = new Dictionary { @@ -213,7 +213,7 @@ public static OpenApiDocument CreateOpenApiDocument() Tags = new List { { - new OpenApiTag + new() { Name = "users.user" } @@ -221,10 +221,10 @@ public static OpenApiDocument CreateOpenApiDocument() }, OperationId = "users.user.ListUser", Summary = "Get entities from users", - Responses = new OpenApiResponses + Responses = new() { { - "200", new OpenApiResponse + "200", new() { Description = "Retrieved entities", Content = new Dictionary @@ -233,7 +233,7 @@ public static OpenApiDocument CreateOpenApiDocument() applicationJsonMediaType, new OpenApiMediaType { - Schema = new OpenApiSchema + Schema = new() { Title = "Collection of user", Type = "object", @@ -244,9 +244,9 @@ public static OpenApiDocument CreateOpenApiDocument() new OpenApiSchema { Type = "array", - Items = new OpenApiSchema + Items = new() { - Reference = new OpenApiReference + Reference = new() { Type = ReferenceType.Schema, Id = "microsoft.graph.user" @@ -266,7 +266,7 @@ public static OpenApiDocument CreateOpenApiDocument() } } }, - ["/users/{user-id}"] = new OpenApiPathItem + ["/users/{user-id}"] = new() { Operations = new Dictionary { @@ -276,7 +276,7 @@ public static OpenApiDocument CreateOpenApiDocument() Tags = new List { { - new OpenApiTag + new() { Name = "users.user" } @@ -284,10 +284,10 @@ public static OpenApiDocument CreateOpenApiDocument() }, OperationId = "users.user.GetUser", Summary = "Get entity from users by key", - Responses = new OpenApiResponses + Responses = new() { { - "200", new OpenApiResponse + "200", new() { Description = "Retrieved entity", Content = new Dictionary @@ -296,9 +296,9 @@ public static OpenApiDocument CreateOpenApiDocument() applicationJsonMediaType, new OpenApiMediaType { - Schema = new OpenApiSchema + Schema = new() { - Reference = new OpenApiReference + Reference = new() { Type = ReferenceType.Schema, Id = "microsoft.graph.user" @@ -318,7 +318,7 @@ public static OpenApiDocument CreateOpenApiDocument() Tags = new List { { - new OpenApiTag + new() { Name = "users.user" } @@ -326,10 +326,10 @@ public static OpenApiDocument CreateOpenApiDocument() }, OperationId = "users.user.UpdateUser", Summary = "Update entity in users", - Responses = new OpenApiResponses + Responses = new() { { - "204", new OpenApiResponse + "204", new() { Description = "Success" } @@ -339,7 +339,7 @@ public static OpenApiDocument CreateOpenApiDocument() } } }, - ["/users/{user-id}/messages/{message-id}"] = new OpenApiPathItem + ["/users/{user-id}/messages/{message-id}"] = new() { Operations = new Dictionary { @@ -349,7 +349,7 @@ public static OpenApiDocument CreateOpenApiDocument() Tags = new List { { - new OpenApiTag + new() { Name = "users.message" } @@ -360,23 +360,23 @@ public static OpenApiDocument CreateOpenApiDocument() Description = "The messages in a mailbox or folder. Read-only. Nullable.", Parameters = new List { - new OpenApiParameter + new() { Name = "$select", In = ParameterLocation.Query, Required = true, Description = "Select properties to be returned", - Schema = new OpenApiSchema + Schema = new() { Type = "array" } // missing explode parameter } }, - Responses = new OpenApiResponses + Responses = new() { { - "200", new OpenApiResponse + "200", new() { Description = "Retrieved navigation property", Content = new Dictionary @@ -385,9 +385,9 @@ public static OpenApiDocument CreateOpenApiDocument() applicationJsonMediaType, new OpenApiMediaType { - Schema = new OpenApiSchema + Schema = new() { - Reference = new OpenApiReference + Reference = new() { Type = ReferenceType.Schema, Id = "microsoft.graph.message" @@ -403,7 +403,7 @@ public static OpenApiDocument CreateOpenApiDocument() } } }, - ["/administrativeUnits/{administrativeUnit-id}/microsoft.graph.restore"] = new OpenApiPathItem + ["/administrativeUnits/{administrativeUnit-id}/microsoft.graph.restore"] = new() { Operations = new Dictionary { @@ -413,7 +413,7 @@ public static OpenApiDocument CreateOpenApiDocument() Tags = new List { { - new OpenApiTag + new() { Name = "administrativeUnits.Actions" } @@ -424,23 +424,23 @@ public static OpenApiDocument CreateOpenApiDocument() Parameters = new List { { - new OpenApiParameter + new() { Name = "administrativeUnit-id", In = ParameterLocation.Path, Required = true, Description = "key: id of administrativeUnit", - Schema = new OpenApiSchema + Schema = new() { Type = "string" } } } }, - Responses = new OpenApiResponses + Responses = new() { { - "200", new OpenApiResponse + "200", new() { Description = "Success", Content = new Dictionary @@ -449,11 +449,11 @@ public static OpenApiDocument CreateOpenApiDocument() applicationJsonMediaType, new OpenApiMediaType { - Schema = new OpenApiSchema + Schema = new() { AnyOf = new List { - new OpenApiSchema + new() { Type = "string" } @@ -470,7 +470,7 @@ public static OpenApiDocument CreateOpenApiDocument() } } }, - ["/applications/{application-id}/logo"] = new OpenApiPathItem + ["/applications/{application-id}/logo"] = new() { Operations = new Dictionary { @@ -480,7 +480,7 @@ public static OpenApiDocument CreateOpenApiDocument() Tags = new List { { - new OpenApiTag + new() { Name = "applications.application" } @@ -488,10 +488,10 @@ public static OpenApiDocument CreateOpenApiDocument() }, OperationId = "applications.application.UpdateLogo", Summary = "Update media content for application in applications", - Responses = new OpenApiResponses + Responses = new() { { - "204", new OpenApiResponse + "204", new() { Description = "Success" } @@ -501,7 +501,7 @@ public static OpenApiDocument CreateOpenApiDocument() } } }, - ["/security/hostSecurityProfiles"] = new OpenApiPathItem + ["/security/hostSecurityProfiles"] = new() { Operations = new Dictionary { @@ -511,7 +511,7 @@ public static OpenApiDocument CreateOpenApiDocument() Tags = new List { { - new OpenApiTag + new() { Name = "security.hostSecurityProfile" } @@ -519,10 +519,10 @@ public static OpenApiDocument CreateOpenApiDocument() }, OperationId = "security.ListHostSecurityProfiles", Summary = "Get hostSecurityProfiles from security", - Responses = new OpenApiResponses + Responses = new() { { - "200", new OpenApiResponse + "200", new() { Description = "Retrieved navigation property", Content = new Dictionary @@ -531,7 +531,7 @@ public static OpenApiDocument CreateOpenApiDocument() applicationJsonMediaType, new OpenApiMediaType { - Schema = new OpenApiSchema + Schema = new() { Title = "Collection of hostSecurityProfile", Type = "object", @@ -542,9 +542,9 @@ public static OpenApiDocument CreateOpenApiDocument() new OpenApiSchema { Type = "array", - Items = new OpenApiSchema + Items = new() { - Reference = new OpenApiReference + Reference = new() { Type = ReferenceType.Schema, Id = "microsoft.graph.networkInterface" @@ -564,7 +564,7 @@ public static OpenApiDocument CreateOpenApiDocument() } } }, - ["/communications/calls/{call-id}/microsoft.graph.keepAlive"] = new OpenApiPathItem + ["/communications/calls/{call-id}/microsoft.graph.keepAlive"] = new() { Operations = new Dictionary { @@ -574,7 +574,7 @@ public static OpenApiDocument CreateOpenApiDocument() Tags = new List { { - new OpenApiTag + new() { Name = "communications.Actions" } @@ -584,13 +584,13 @@ public static OpenApiDocument CreateOpenApiDocument() Summary = "Invoke action keepAlive", Parameters = new List { - new OpenApiParameter + new() { Name = "call-id", In = ParameterLocation.Path, Description = "key: id of call", Required = true, - Schema = new OpenApiSchema + Schema = new() { Type = "string" }, @@ -602,10 +602,10 @@ public static OpenApiDocument CreateOpenApiDocument() } } }, - Responses = new OpenApiResponses + Responses = new() { { - "204", new OpenApiResponse + "204", new() { Description = "Success" } @@ -621,7 +621,7 @@ public static OpenApiDocument CreateOpenApiDocument() } } }, - ["/groups/{group-id}/events/{event-id}/calendar/events/microsoft.graph.delta"] = new OpenApiPathItem + ["/groups/{group-id}/events/{event-id}/calendar/events/microsoft.graph.delta"] = new() { Operations = new Dictionary { @@ -630,7 +630,7 @@ public static OpenApiDocument CreateOpenApiDocument() { Tags = new List { - new OpenApiTag + new() { Name = "groups.Functions" } @@ -639,13 +639,13 @@ public static OpenApiDocument CreateOpenApiDocument() Summary = "Invoke function delta", Parameters = new List { - new OpenApiParameter + new() { Name = "group-id", In = ParameterLocation.Path, Description = "key: id of group", Required = true, - Schema = new OpenApiSchema + Schema = new() { Type = "string" }, @@ -656,13 +656,13 @@ public static OpenApiDocument CreateOpenApiDocument() } } }, - new OpenApiParameter + new() { Name = "event-id", In = ParameterLocation.Path, Description = "key: id of event", Required = true, - Schema = new OpenApiSchema + Schema = new() { Type = "string" }, @@ -674,10 +674,10 @@ public static OpenApiDocument CreateOpenApiDocument() } } }, - Responses = new OpenApiResponses + Responses = new() { { - "200", new OpenApiResponse + "200", new() { Description = "Success", Content = new Dictionary @@ -686,10 +686,10 @@ public static OpenApiDocument CreateOpenApiDocument() applicationJsonMediaType, new OpenApiMediaType { - Schema = new OpenApiSchema + Schema = new() { Type = "array", - Reference = new OpenApiReference + Reference = new() { Type = ReferenceType.Schema, Id = "microsoft.graph.event" @@ -711,7 +711,7 @@ public static OpenApiDocument CreateOpenApiDocument() } } }, - ["/applications/{application-id}/createdOnBehalfOf/$ref"] = new OpenApiPathItem + ["/applications/{application-id}/createdOnBehalfOf/$ref"] = new() { Operations = new Dictionary { @@ -720,7 +720,7 @@ public static OpenApiDocument CreateOpenApiDocument() { Tags = new List { - new OpenApiTag + new() { Name = "applications.directoryObject" } @@ -732,7 +732,7 @@ public static OpenApiDocument CreateOpenApiDocument() } } }, - Components = new OpenApiComponents + Components = new() { Schemas = new Dictionary { diff --git a/test/Microsoft.OpenApi.Readers.Tests/OpenApiReaderTests/OpenApiDiagnosticTests.cs b/test/Microsoft.OpenApi.Readers.Tests/OpenApiReaderTests/OpenApiDiagnosticTests.cs index 4231ae4b7..4d1b6675d 100644 --- a/test/Microsoft.OpenApi.Readers.Tests/OpenApiReaderTests/OpenApiDiagnosticTests.cs +++ b/test/Microsoft.OpenApi.Readers.Tests/OpenApiReaderTests/OpenApiDiagnosticTests.cs @@ -40,11 +40,11 @@ public void DetectedSpecificationVersionShouldBeV3_0() public async Task DiagnosticReportMergedForExternalReference() { // Create a reader that will resolve all references - var reader = new OpenApiStreamReader(new OpenApiReaderSettings + var reader = new OpenApiStreamReader(new() { LoadExternalRefs = true, CustomExternalLoader = new ResourceLoader(), - BaseUrl = new Uri("fie://c:\\") + BaseUrl = new("fie://c:\\") }); ReadResult result; @@ -57,7 +57,7 @@ public async Task DiagnosticReportMergedForExternalReference() Assert.NotNull(result.OpenApiDocument.Workspace); Assert.True(result.OpenApiDocument.Workspace.Contains("TodoReference.yaml")); result.OpenApiDiagnostic.Errors.Should().BeEquivalentTo(new List { - new OpenApiError( new OpenApiException("[File: ./TodoReference.yaml] Invalid Reference identifier 'object-not-existing'.")) }); + new( new OpenApiException("[File: ./TodoReference.yaml] Invalid Reference identifier 'object-not-existing'.")) }); } } @@ -70,7 +70,7 @@ public Stream Load(Uri uri) public Task LoadAsync(Uri uri) { - var path = new Uri(new Uri("http://example.org/OpenApiReaderTests/Samples/OpenApiDiagnosticReportMerged/"), uri).AbsolutePath; + var path = new Uri(new("http://example.org/OpenApiReaderTests/Samples/OpenApiDiagnosticReportMerged/"), uri).AbsolutePath; path = path.Substring(1); // remove leading slash return Task.FromResult(Resources.GetStream(path)); } diff --git a/test/Microsoft.OpenApi.Readers.Tests/OpenApiReaderTests/OpenApiStreamReaderTests.cs b/test/Microsoft.OpenApi.Readers.Tests/OpenApiReaderTests/OpenApiStreamReaderTests.cs index 0f6bbce15..91e271549 100644 --- a/test/Microsoft.OpenApi.Readers.Tests/OpenApiReaderTests/OpenApiStreamReaderTests.cs +++ b/test/Microsoft.OpenApi.Readers.Tests/OpenApiReaderTests/OpenApiStreamReaderTests.cs @@ -14,7 +14,7 @@ public class OpenApiStreamReaderTests public void StreamShouldCloseIfLeaveStreamOpenSettingEqualsFalse() { using var stream = Resources.GetStream(Path.Combine(SampleFolderPath, "petStore.yaml")); - var reader = new OpenApiStreamReader(new OpenApiReaderSettings { LeaveStreamOpen = false }); + var reader = new OpenApiStreamReader(new() { LeaveStreamOpen = false }); reader.Read(stream, out _); Assert.False(stream.CanRead); } @@ -23,7 +23,7 @@ public void StreamShouldCloseIfLeaveStreamOpenSettingEqualsFalse() public void StreamShouldNotCloseIfLeaveStreamOpenSettingEqualsTrue() { using var stream = Resources.GetStream(Path.Combine(SampleFolderPath, "petStore.yaml")); - var reader = new OpenApiStreamReader(new OpenApiReaderSettings { LeaveStreamOpen = true}); + var reader = new OpenApiStreamReader(new() { LeaveStreamOpen = true}); reader.Read(stream, out _); Assert.True(stream.CanRead); } diff --git a/test/Microsoft.OpenApi.Readers.Tests/OpenApiWorkspaceTests/OpenApiWorkspaceStreamTests.cs b/test/Microsoft.OpenApi.Readers.Tests/OpenApiWorkspaceTests/OpenApiWorkspaceStreamTests.cs index 21e2ec759..8f9430a87 100644 --- a/test/Microsoft.OpenApi.Readers.Tests/OpenApiWorkspaceTests/OpenApiWorkspaceStreamTests.cs +++ b/test/Microsoft.OpenApi.Readers.Tests/OpenApiWorkspaceTests/OpenApiWorkspaceStreamTests.cs @@ -18,11 +18,11 @@ public class OpenApiWorkspaceStreamTests public async Task LoadingDocumentWithResolveAllReferencesShouldLoadDocumentIntoWorkspace() { // Create a reader that will resolve all references - var reader = new OpenApiStreamReader(new OpenApiReaderSettings + var reader = new OpenApiStreamReader(new() { LoadExternalRefs = true, CustomExternalLoader = new MockLoader(), - BaseUrl = new Uri("file://c:\\") + BaseUrl = new("file://c:\\") }); // Todo: this should be ReadAsync @@ -48,11 +48,11 @@ public async Task LoadingDocumentWithResolveAllReferencesShouldLoadDocumentIntoW public async Task LoadDocumentWithExternalReferenceShouldLoadBothDocumentsIntoWorkspace() { // Create a reader that will resolve all references - var reader = new OpenApiStreamReader(new OpenApiReaderSettings + var reader = new OpenApiStreamReader(new() { LoadExternalRefs = true, CustomExternalLoader = new ResourceLoader(), - BaseUrl = new Uri("fie://c:\\") + BaseUrl = new("fie://c:\\") }); ReadResult result; @@ -107,7 +107,7 @@ public Stream Load(Uri uri) public Task LoadAsync(Uri uri) { - var path = new Uri(new Uri("http://example.org/V3Tests/Samples/OpenApiWorkspace/"), uri).AbsolutePath; + var path = new Uri(new("http://example.org/V3Tests/Samples/OpenApiWorkspace/"), uri).AbsolutePath; path = path.Substring(1); // remove leading slash return Task.FromResult(Resources.GetStream(path)); } diff --git a/test/Microsoft.OpenApi.Readers.Tests/ParseNodeTests.cs b/test/Microsoft.OpenApi.Readers.Tests/ParseNodeTests.cs index 829cecaff..f1af6f933 100644 --- a/test/Microsoft.OpenApi.Readers.Tests/ParseNodeTests.cs +++ b/test/Microsoft.OpenApi.Readers.Tests/ParseNodeTests.cs @@ -30,7 +30,7 @@ public void BrokenSimpleList() diagnostic.Errors.Should().BeEquivalentTo(new List { - new OpenApiError(new OpenApiReaderException("Expected a value.") { + new(new OpenApiReaderException("Expected a value.") { Pointer = "#line=4" }) }); @@ -60,7 +60,7 @@ public void BadSchema() diagnostic.Errors.Should().BeEquivalentTo(new List { - new OpenApiError(new OpenApiReaderException("schema must be a map/object") { + new(new OpenApiReaderException("schema must be a map/object") { Pointer = "#/paths/~1foo/get/responses/200/content/application~1json/schema" }) }); diff --git a/test/Microsoft.OpenApi.Readers.Tests/ParseNodes/OpenApiAnyConverterTests.cs b/test/Microsoft.OpenApi.Readers.Tests/ParseNodes/OpenApiAnyConverterTests.cs index 884bd28fc..0f36d7d89 100644 --- a/test/Microsoft.OpenApi.Readers.Tests/ParseNodes/OpenApiAnyConverterTests.cs +++ b/test/Microsoft.OpenApi.Readers.Tests/ParseNodes/OpenApiAnyConverterTests.cs @@ -44,26 +44,26 @@ public void ParseObjectAsAnyShouldSucceed() Type = "object", Properties = { - ["aString"] = new OpenApiSchema + ["aString"] = new() { Type = "string" }, - ["aInteger"] = new OpenApiSchema + ["aInteger"] = new() { Type = "integer", Format = "int32" }, - ["aDouble"] = new OpenApiSchema + ["aDouble"] = new() { Type = "number", Format = "double" }, - ["aDateTime"] = new OpenApiSchema + ["aDateTime"] = new() { Type = "string", Format = "date-time" }, - ["aDate"] = new OpenApiSchema + ["aDate"] = new() { Type = "string", Format = "date" @@ -130,54 +130,54 @@ public void ParseNestedObjectAsAnyShouldSucceed() Type = "object", Properties = { - ["aString"] = new OpenApiSchema + ["aString"] = new() { Type = "string" }, - ["aInteger"] = new OpenApiSchema + ["aInteger"] = new() { Type = "integer", Format = "int32" }, - ["aArray"] = new OpenApiSchema + ["aArray"] = new() { Type = "array", - Items = new OpenApiSchema + Items = new() { Type = "integer", Format = "int64" } }, - ["aNestedArray"] = new OpenApiSchema + ["aNestedArray"] = new() { Type = "array", - Items = new OpenApiSchema + Items = new() { Type = "object", Properties = { - ["aFloat"] = new OpenApiSchema + ["aFloat"] = new() { Type = "number", Format = "float" }, - ["aPassword"] = new OpenApiSchema + ["aPassword"] = new() { Type = "string", Format = "password" }, - ["aArray"] = new OpenApiSchema + ["aArray"] = new() { Type = "array", - Items = new OpenApiSchema + Items = new() { Type = "string", } }, - ["aDictionary"] = new OpenApiSchema + ["aDictionary"] = new() { Type = "object", - AdditionalProperties = new OpenApiSchema + AdditionalProperties = new() { Type = "integer", Format = "int64" @@ -186,24 +186,24 @@ public void ParseNestedObjectAsAnyShouldSucceed() } } }, - ["aObject"] = new OpenApiSchema + ["aObject"] = new() { Type = "array", Properties = { - ["aDate"] = new OpenApiSchema + ["aDate"] = new() { Type = "string", Format = "date" } } }, - ["aDouble"] = new OpenApiSchema + ["aDouble"] = new() { Type = "number", Format = "double" }, - ["aDateTime"] = new OpenApiSchema + ["aDateTime"] = new() { Type = "string", Format = "date-time" @@ -310,36 +310,36 @@ public void ParseNestedObjectAsAnyWithPartialSchemaShouldSucceed() Type = "object", Properties = { - ["aString"] = new OpenApiSchema + ["aString"] = new() { Type = "string" }, - ["aArray"] = new OpenApiSchema + ["aArray"] = new() { Type = "array", - Items = new OpenApiSchema + Items = new() { Type = "integer" } }, - ["aNestedArray"] = new OpenApiSchema + ["aNestedArray"] = new() { Type = "array", - Items = new OpenApiSchema + Items = new() { Type = "object", Properties = { - ["aFloat"] = new OpenApiSchema + ["aFloat"] = new() { }, - ["aPassword"] = new OpenApiSchema + ["aPassword"] = new() { }, - ["aArray"] = new OpenApiSchema + ["aArray"] = new() { Type = "array", - Items = new OpenApiSchema + Items = new() { Type = "string", } @@ -347,21 +347,21 @@ public void ParseNestedObjectAsAnyWithPartialSchemaShouldSucceed() } } }, - ["aObject"] = new OpenApiSchema + ["aObject"] = new() { Type = "array", Properties = { - ["aDate"] = new OpenApiSchema + ["aDate"] = new() { Type = "string" } } }, - ["aDouble"] = new OpenApiSchema + ["aDouble"] = new() { }, - ["aDateTime"] = new OpenApiSchema + ["aDateTime"] = new() { } } diff --git a/test/Microsoft.OpenApi.Readers.Tests/ReferenceService/ConvertToOpenApiReferenceV2Tests.cs b/test/Microsoft.OpenApi.Readers.Tests/ReferenceService/ConvertToOpenApiReferenceV2Tests.cs index 9bd42a0e3..737f4310c 100644 --- a/test/Microsoft.OpenApi.Readers.Tests/ReferenceService/ConvertToOpenApiReferenceV2Tests.cs +++ b/test/Microsoft.OpenApi.Readers.Tests/ReferenceService/ConvertToOpenApiReferenceV2Tests.cs @@ -14,7 +14,7 @@ public class ConvertToOpenApiReferenceV2Tests public ConvertToOpenApiReferenceV2Tests() { - Diagnostic = new OpenApiDiagnostic(); + Diagnostic = new(); } [Fact] diff --git a/test/Microsoft.OpenApi.Readers.Tests/ReferenceService/ConvertToOpenApiReferenceV3Tests.cs b/test/Microsoft.OpenApi.Readers.Tests/ReferenceService/ConvertToOpenApiReferenceV3Tests.cs index b8555a890..2f00de3c2 100644 --- a/test/Microsoft.OpenApi.Readers.Tests/ReferenceService/ConvertToOpenApiReferenceV3Tests.cs +++ b/test/Microsoft.OpenApi.Readers.Tests/ReferenceService/ConvertToOpenApiReferenceV3Tests.cs @@ -14,7 +14,7 @@ public class ConvertToOpenApiReferenceV3Tests public ConvertToOpenApiReferenceV3Tests() { - Diagnostic = new OpenApiDiagnostic(); + Diagnostic = new(); } [Fact] diff --git a/test/Microsoft.OpenApi.Readers.Tests/ReferenceService/TryLoadReferenceV2Tests.cs b/test/Microsoft.OpenApi.Readers.Tests/ReferenceService/TryLoadReferenceV2Tests.cs index 546b2c1a8..b51f696e0 100644 --- a/test/Microsoft.OpenApi.Readers.Tests/ReferenceService/TryLoadReferenceV2Tests.cs +++ b/test/Microsoft.OpenApi.Readers.Tests/ReferenceService/TryLoadReferenceV2Tests.cs @@ -46,21 +46,21 @@ public void LoadSchemaReference() }, Properties = { - ["id"] = new OpenApiSchema + ["id"] = new() { Type = "integer", Format = "int64" }, - ["name"] = new OpenApiSchema + ["name"] = new() { Type = "string" }, - ["tag"] = new OpenApiSchema + ["tag"] = new() { Type = "string" } }, - Reference = new OpenApiReference + Reference = new() { Type = ReferenceType.Schema, Id = "SampleObject" @@ -98,12 +98,12 @@ public void LoadParameterReference() In = ParameterLocation.Query, Description = "number of items to skip", Required = true, - Schema = new OpenApiSchema + Schema = new() { Type = "integer", Format = "int32" }, - Reference = new OpenApiReference + Reference = new() { Type = ReferenceType.Parameter, Id = "skipParam" @@ -140,7 +140,7 @@ public void LoadSecuritySchemeReference() Type = SecuritySchemeType.ApiKey, Name = "api_key", In = ParameterLocation.Header, - Reference = new OpenApiReference + Reference = new() { Type = ReferenceType.SecurityScheme, Id = "api_key_sample" @@ -175,14 +175,14 @@ public void LoadResponseReference() new OpenApiResponse { Description = "Entity not found.", - Reference = new OpenApiReference + Reference = new() { Type = ReferenceType.Response, Id = "NotFound" }, Content = new Dictionary { - ["application/json"] = new OpenApiMediaType() + ["application/json"] = new() } } ); @@ -216,24 +216,24 @@ public void LoadResponseAndSchemaReference() Description = "General Error", Content = { - ["application/json"] = new OpenApiMediaType + ["application/json"] = new() { - Schema = new OpenApiSchema + Schema = new() { Description = "Sample description", Required = new HashSet {"name" }, Properties = { - ["name"] = new OpenApiSchema + ["name"] = new() { Type = "string" }, - ["tag"] = new OpenApiSchema + ["tag"] = new() { Type = "string" } }, - Reference = new OpenApiReference + Reference = new() { Type = ReferenceType.Schema, Id = "SampleObject2", @@ -242,7 +242,7 @@ public void LoadResponseAndSchemaReference() } } }, - Reference = new OpenApiReference + Reference = new() { Type = ReferenceType.Response, Id = "GeneralError" diff --git a/test/Microsoft.OpenApi.Readers.Tests/TestHelper.cs b/test/Microsoft.OpenApi.Readers.Tests/TestHelper.cs index 654be0858..fa8b939e2 100644 --- a/test/Microsoft.OpenApi.Readers.Tests/TestHelper.cs +++ b/test/Microsoft.OpenApi.Readers.Tests/TestHelper.cs @@ -16,9 +16,9 @@ public static MapNode CreateYamlMapNode(Stream stream) yamlStream.Load(new StreamReader(stream)); var yamlNode = yamlStream.Documents.First().RootNode; - var context = new ParsingContext(new OpenApiDiagnostic()); + var context = new ParsingContext(new()); - return new MapNode(context, (YamlMappingNode)yamlNode); + return new(context, (YamlMappingNode)yamlNode); } } } diff --git a/test/Microsoft.OpenApi.Readers.Tests/V2Tests/OpenApiContactTests.cs b/test/Microsoft.OpenApi.Readers.Tests/V2Tests/OpenApiContactTests.cs index d3197476f..a7d586bf2 100644 --- a/test/Microsoft.OpenApi.Readers.Tests/V2Tests/OpenApiContactTests.cs +++ b/test/Microsoft.OpenApi.Readers.Tests/V2Tests/OpenApiContactTests.cs @@ -3,7 +3,6 @@ using FluentAssertions; using Microsoft.OpenApi.Models; -using System; using Xunit; namespace Microsoft.OpenApi.Readers.Tests.V2Tests @@ -34,7 +33,7 @@ public void ParseStringContactFragmentShouldSucceed() { Email = "support@swagger.io", Name = "API Support", - Url = new Uri("http://www.swagger.io/support") + Url = new("http://www.swagger.io/support") }); } } diff --git a/test/Microsoft.OpenApi.Readers.Tests/V2Tests/OpenApiDocumentTests.cs b/test/Microsoft.OpenApi.Readers.Tests/V2Tests/OpenApiDocumentTests.cs index 6f0b7da9a..9e76f6491 100644 --- a/test/Microsoft.OpenApi.Readers.Tests/V2Tests/OpenApiDocumentTests.cs +++ b/test/Microsoft.OpenApi.Readers.Tests/V2Tests/OpenApiDocumentTests.cs @@ -2,7 +2,6 @@ // Licensed under the MIT license. using System.Collections.Generic; -using System.Globalization; using System.IO; using System.Threading; using FluentAssertions; @@ -40,7 +39,7 @@ public void ShouldThrowWhenReferenceTypeIsInvalid() var doc = reader.Read(input, out var diagnostic); diagnostic.Errors.Should().BeEquivalentTo(new List { - new OpenApiError( new OpenApiException("Unknown reference type 'defi888nition'")) }); + new( new OpenApiException("Unknown reference type 'defi888nition'")) }); doc.Should().NotBeNull(); } @@ -69,7 +68,7 @@ public void ShouldThrowWhenReferenceDoesNotExist() var doc = reader.Read(input, out var diagnostic); diagnostic.Errors.Should().BeEquivalentTo(new List { - new OpenApiError( new OpenApiException("Invalid Reference identifier 'doesnotexist'.")) }); + new( new OpenApiException("Invalid Reference identifier 'doesnotexist'.")) }); doc.Should().NotBeNull(); } @@ -81,8 +80,8 @@ public void ShouldThrowWhenReferenceDoesNotExist() [InlineData("da-DK")] public void ParseDocumentWithDifferentCultureShouldSucceed(string culture) { - Thread.CurrentThread.CurrentCulture = new CultureInfo(culture); - Thread.CurrentThread.CurrentUICulture = new CultureInfo(culture); + Thread.CurrentThread.CurrentCulture = new(culture); + Thread.CurrentThread.CurrentUICulture = new(culture); var openApiDoc = new OpenApiStringReader().Read( """ @@ -108,7 +107,7 @@ public void ParseDocumentWithDifferentCultureShouldSucceed(string culture) openApiDoc.Should().BeEquivalentTo( new OpenApiDocument { - Info = new OpenApiInfo + Info = new() { Title = "Simple Document", Version = "0.9.1", @@ -117,16 +116,16 @@ public void ParseDocumentWithDifferentCultureShouldSucceed(string culture) ["x-extension"] = new OpenApiDouble(2.335) } }, - Components = new OpenApiComponents + Components = new() { Schemas = { - ["sampleSchema"] = new OpenApiSchema + ["sampleSchema"] = new() { Type = "object", Properties = { - ["sampleProperty"] = new OpenApiSchema + ["sampleProperty"] = new() { Type = "double", Minimum = (decimal)100.54, @@ -135,7 +134,7 @@ public void ParseDocumentWithDifferentCultureShouldSucceed(string culture) ExclusiveMinimum = false } }, - Reference = new OpenApiReference + Reference = new() { Id = "sampleSchema", Type = ReferenceType.Schema @@ -143,7 +142,7 @@ public void ParseDocumentWithDifferentCultureShouldSucceed(string culture) } } }, - Paths = new OpenApiPaths() + Paths = new() }); context.Should().BeEquivalentTo( @@ -159,7 +158,7 @@ public void ShouldParseProducesInAnyOrder() var okSchema = new OpenApiSchema { - Reference = new OpenApiReference + Reference = new() { Type = ReferenceType.Schema, Id = "Item", @@ -178,7 +177,7 @@ public void ShouldParseProducesInAnyOrder() var errorSchema = new OpenApiSchema { - Reference = new OpenApiReference + Reference = new() { Type = ReferenceType.Schema, Id = "Error", @@ -207,7 +206,7 @@ public void ShouldParseProducesInAnyOrder() var okMediaType = new OpenApiMediaType { - Schema = new OpenApiSchema + Schema = new() { Type = "array", Items = okSchema @@ -221,7 +220,7 @@ public void ShouldParseProducesInAnyOrder() doc.Should().BeEquivalentTo(new OpenApiDocument { - Info = new OpenApiInfo + Info = new() { Title = "Two responses", Version = "1.0.0" @@ -233,17 +232,17 @@ public void ShouldParseProducesInAnyOrder() Url = "https://" } }, - Paths = new OpenApiPaths + Paths = new() { - ["/items"] = new OpenApiPathItem + ["/items"] = new() { Operations = { - [OperationType.Get] = new OpenApiOperation + [OperationType.Get] = new() { Responses = { - ["200"] = new OpenApiResponse + ["200"] = new() { Description = "An OK response", Content = @@ -252,7 +251,7 @@ public void ShouldParseProducesInAnyOrder() ["application/xml"] = okMediaType, } }, - ["default"] = new OpenApiResponse + ["default"] = new() { Description = "An error response", Content = @@ -263,11 +262,11 @@ public void ShouldParseProducesInAnyOrder() } } }, - [OperationType.Post] = new OpenApiOperation + [OperationType.Post] = new() { Responses = { - ["200"] = new OpenApiResponse + ["200"] = new() { Description = "An OK response", Content = @@ -275,7 +274,7 @@ public void ShouldParseProducesInAnyOrder() ["html/text"] = okMediaType } }, - ["default"] = new OpenApiResponse + ["default"] = new() { Description = "An error response", Content = @@ -285,11 +284,11 @@ public void ShouldParseProducesInAnyOrder() } } }, - [OperationType.Patch] = new OpenApiOperation + [OperationType.Patch] = new() { Responses = { - ["200"] = new OpenApiResponse + ["200"] = new() { Description = "An OK response", Content = @@ -298,7 +297,7 @@ public void ShouldParseProducesInAnyOrder() ["application/xml"] = okMediaType, } }, - ["default"] = new OpenApiResponse + ["default"] = new() { Description = "An error response", Content = @@ -312,7 +311,7 @@ public void ShouldParseProducesInAnyOrder() } } }, - Components = new OpenApiComponents + Components = new() { Schemas = { @@ -338,7 +337,7 @@ public void ShouldAssignSchemaToAllResponses() var successSchema = new OpenApiSchema { Type = "array", - Items = new OpenApiSchema + Items = new() { Properties = { { "id", new OpenApiSchema @@ -348,7 +347,7 @@ public void ShouldAssignSchemaToAllResponses() } } }, - Reference = new OpenApiReference + Reference = new() { Id = "Item", Type = ReferenceType.Schema, @@ -376,7 +375,7 @@ public void ShouldAssignSchemaToAllResponses() } } }, - Reference = new OpenApiReference + Reference = new() { Id = "Error", Type = ReferenceType.Schema, @@ -418,7 +417,7 @@ public void ShouldAllowComponentsThatJustContainAReference() public void ParseDocumentWithDefaultContentTypeSettingShouldSucceed() { using var stream = Resources.GetStream(Path.Combine(SampleFolderPath, "docWithEmptyProduces.yaml")); - var doc = new OpenApiStreamReader(new OpenApiReaderSettings { DefaultContentType = new List { "application/json" } }) + var doc = new OpenApiStreamReader(new() { DefaultContentType = new() { "application/json" } }) .Read(stream, out OpenApiDiagnostic diags); var mediaType = doc.Paths["/example"].Operations[OperationType.Get].Responses["200"].Content; Assert.Contains("application/json", mediaType); diff --git a/test/Microsoft.OpenApi.Readers.Tests/V2Tests/OpenApiHeaderTests.cs b/test/Microsoft.OpenApi.Readers.Tests/V2Tests/OpenApiHeaderTests.cs index 830f0aa9c..39dff183f 100644 --- a/test/Microsoft.OpenApi.Readers.Tests/V2Tests/OpenApiHeaderTests.cs +++ b/test/Microsoft.OpenApi.Readers.Tests/V2Tests/OpenApiHeaderTests.cs @@ -33,7 +33,7 @@ public void ParseHeaderWithDefaultShouldSucceed() header.Should().BeEquivalentTo( new OpenApiHeader { - Schema = new OpenApiSchema + Schema = new() { Type = "number", Format = "float", @@ -59,7 +59,7 @@ public void ParseHeaderWithEnumShouldSucceed() header.Should().BeEquivalentTo( new OpenApiHeader { - Schema = new OpenApiSchema + Schema = new() { Type = "number", Format = "float", diff --git a/test/Microsoft.OpenApi.Readers.Tests/V2Tests/OpenApiOperationTests.cs b/test/Microsoft.OpenApi.Readers.Tests/V2Tests/OpenApiOperationTests.cs index 726bbd03c..d33aa5be2 100644 --- a/test/Microsoft.OpenApi.Readers.Tests/V2Tests/OpenApiOperationTests.cs +++ b/test/Microsoft.OpenApi.Readers.Tests/V2Tests/OpenApiOperationTests.cs @@ -19,75 +19,75 @@ public class OpenApiOperationTests { private const string SampleFolderPath = "V2Tests/Samples/OpenApiOperation/"; - private static readonly OpenApiOperation _basicOperation = new OpenApiOperation + private static readonly OpenApiOperation _basicOperation = new() { Summary = "Updates a pet in the store", Description = "", OperationId = "updatePet", Parameters = new List { - new OpenApiParameter + new() { Name = "petId", In = ParameterLocation.Path, Description = "ID of pet that needs to be updated", Required = true, - Schema = new OpenApiSchema + Schema = new() { Type = "string" } } }, - Responses = new OpenApiResponses + Responses = new() { - ["200"] = new OpenApiResponse + ["200"] = new() { Description = "Pet updated.", Content = new Dictionary { - ["application/json"] = new OpenApiMediaType(), - ["application/xml"] = new OpenApiMediaType() + ["application/json"] = new(), + ["application/xml"] = new() } } } }; private static readonly OpenApiOperation _operationWithFormData = - new OpenApiOperation + new() { Summary = "Updates a pet in the store with form data", Description = "", OperationId = "updatePetWithForm", Parameters = new List { - new OpenApiParameter + new() { Name = "petId", In = ParameterLocation.Path, Description = "ID of pet that needs to be updated", Required = true, - Schema = new OpenApiSchema + Schema = new() { Type = "string" } } }, - RequestBody = new OpenApiRequestBody + RequestBody = new() { Content = { - ["application/x-www-form-urlencoded"] = new OpenApiMediaType + ["application/x-www-form-urlencoded"] = new() { - Schema = new OpenApiSchema + Schema = new() { Properties = { - ["name"] = new OpenApiSchema + ["name"] = new() { Description = "Updated name of the pet", Type = "string" }, - ["status"] = new OpenApiSchema + ["status"] = new() { Description = "Updated status of the pet", Type = "string" @@ -99,18 +99,18 @@ public class OpenApiOperationTests } } }, - ["multipart/form-data"] = new OpenApiMediaType + ["multipart/form-data"] = new() { - Schema = new OpenApiSchema + Schema = new() { Properties = { - ["name"] = new OpenApiSchema + ["name"] = new() { Description = "Updated name of the pet", Type = "string" }, - ["status"] = new OpenApiSchema + ["status"] = new() { Description = "Updated status of the pet", Type = "string" @@ -124,58 +124,58 @@ public class OpenApiOperationTests } } }, - Responses = new OpenApiResponses + Responses = new() { - ["200"] = new OpenApiResponse + ["200"] = new() { Description = "Pet updated.", Content = new Dictionary { - ["application/json"] = new OpenApiMediaType(), - ["application/xml"] = new OpenApiMediaType() + ["application/json"] = new(), + ["application/xml"] = new() } }, - ["405"] = new OpenApiResponse + ["405"] = new() { Description = "Invalid input", Content = new Dictionary { - ["application/json"] = new OpenApiMediaType(), - ["application/xml"] = new OpenApiMediaType() + ["application/json"] = new(), + ["application/xml"] = new() } } } }; - private static readonly OpenApiOperation _operationWithBody = new OpenApiOperation + private static readonly OpenApiOperation _operationWithBody = new() { Summary = "Updates a pet in the store with request body", Description = "", OperationId = "updatePetWithBody", Parameters = new List { - new OpenApiParameter + new() { Name = "petId", In = ParameterLocation.Path, Description = "ID of pet that needs to be updated", Required = true, - Schema = new OpenApiSchema + Schema = new() { Type = "string" } }, }, - RequestBody = new OpenApiRequestBody + RequestBody = new() { Description = "Pet to update with", Required = true, Content = { - ["application/json"] = new OpenApiMediaType + ["application/json"] = new() { - Schema = new OpenApiSchema + Schema = new() { Type = "object" } @@ -185,24 +185,24 @@ public class OpenApiOperationTests [OpenApiConstants.BodyName] = new OpenApiString("petObject") } }, - Responses = new OpenApiResponses + Responses = new() { - ["200"] = new OpenApiResponse + ["200"] = new() { Description = "Pet updated.", Content = new Dictionary { - ["application/json"] = new OpenApiMediaType(), - ["application/xml"] = new OpenApiMediaType() + ["application/json"] = new(), + ["application/xml"] = new() } }, - ["405"] = new OpenApiResponse + ["405"] = new() { Description = "Invalid input", Content = new Dictionary { - ["application/json"] = new OpenApiMediaType(), - ["application/xml"] = new OpenApiMediaType() + ["application/json"] = new(), + ["application/xml"] = new() } } @@ -331,19 +331,19 @@ public void ParseOperationWithResponseExamplesShouldSucceed() operation.Should().BeEquivalentTo( new OpenApiOperation { - Responses = new OpenApiResponses + Responses = new() { - { "200", new OpenApiResponse + { "200", new() { Description = "An array of float response", Content = { - ["application/json"] = new OpenApiMediaType + ["application/json"] = new() { - Schema = new OpenApiSchema + Schema = new() { Type = "array", - Items = new OpenApiSchema + Items = new() { Type = "number", Format = "float" @@ -356,12 +356,12 @@ public void ParseOperationWithResponseExamplesShouldSucceed() new OpenApiFloat(7), } }, - ["application/xml"] = new OpenApiMediaType + ["application/xml"] = new() { - Schema = new OpenApiSchema + Schema = new() { Type = "array", - Items = new OpenApiSchema + Items = new() { Type = "number", Format = "float" @@ -390,16 +390,16 @@ public void ParseOperationWithEmptyProducesArraySetsResponseSchemaIfExists() operation.Should().BeEquivalentTo( new OpenApiOperation { - Responses = new OpenApiResponses + Responses = new() { - { "200", new OpenApiResponse + { "200", new() { Description = "OK", Content = { - ["application/octet-stream"] = new OpenApiMediaType + ["application/octet-stream"] = new() { - Schema = new OpenApiSchema + Schema = new() { Format = "binary", Description = "The content of the file.", diff --git a/test/Microsoft.OpenApi.Readers.Tests/V2Tests/OpenApiParameterTests.cs b/test/Microsoft.OpenApi.Readers.Tests/V2Tests/OpenApiParameterTests.cs index 7239139c1..9eb20df4f 100644 --- a/test/Microsoft.OpenApi.Readers.Tests/V2Tests/OpenApiParameterTests.cs +++ b/test/Microsoft.OpenApi.Readers.Tests/V2Tests/OpenApiParameterTests.cs @@ -57,7 +57,7 @@ public void ParsePathParameterShouldSucceed() Name = "username", Description = "username to fetch", Required = true, - Schema = new OpenApiSchema + Schema = new() { Type = "string" } @@ -85,10 +85,10 @@ public void ParseQueryParameterShouldSucceed() Name = "id", Description = "ID of the object to fetch", Required = false, - Schema = new OpenApiSchema + Schema = new() { Type = "array", - Items = new OpenApiSchema + Items = new() { Type = "string" } @@ -140,10 +140,10 @@ public void ParseHeaderParameterShouldSucceed() Required = true, Style = ParameterStyle.Simple, - Schema = new OpenApiSchema + Schema = new() { Type = "array", - Items = new OpenApiSchema + Items = new() { Type = "integer", Format = "int64", @@ -193,10 +193,10 @@ public void ParseHeaderParameterWithIncorrectDataTypeShouldSucceed() Required = true, Style = ParameterStyle.Simple, - Schema = new OpenApiSchema + Schema = new() { Type = "array", - Items = new OpenApiSchema + Items = new() { Type = "string", Format = "date-time", @@ -244,7 +244,7 @@ public void ParseParameterWithNullLocationShouldSucceed() Name = "username", Description = "username to fetch", Required = true, - Schema = new OpenApiSchema + Schema = new() { Type = "string" } @@ -272,7 +272,7 @@ public void ParseParameterWithNoLocationShouldSucceed() Name = "username", Description = "username to fetch", Required = true, - Schema = new OpenApiSchema + Schema = new() { Type = "string" } @@ -324,7 +324,7 @@ public void ParseParameterWithUnknownLocationShouldSucceed() Name = "username", Description = "username to fetch", Required = true, - Schema = new OpenApiSchema + Schema = new() { Type = "string" } @@ -352,7 +352,7 @@ public void ParseParameterWithDefaultShouldSucceed() Name = "username", Description = "username to fetch", Required = true, - Schema = new OpenApiSchema + Schema = new() { Type = "number", Format = "float", @@ -382,7 +382,7 @@ public void ParseParameterWithEnumShouldSucceed() Name = "username", Description = "username to fetch", Required = true, - Schema = new OpenApiSchema + Schema = new() { Type = "number", Format = "float", diff --git a/test/Microsoft.OpenApi.Readers.Tests/V2Tests/OpenApiPathItemTests.cs b/test/Microsoft.OpenApi.Readers.Tests/V2Tests/OpenApiPathItemTests.cs index 57cf71302..177109131 100644 --- a/test/Microsoft.OpenApi.Readers.Tests/V2Tests/OpenApiPathItemTests.cs +++ b/test/Microsoft.OpenApi.Readers.Tests/V2Tests/OpenApiPathItemTests.cs @@ -17,20 +17,20 @@ public class OpenApiPathItemTests { private const string SampleFolderPath = "V2Tests/Samples/OpenApiPathItem/"; - private static readonly OpenApiPathItem _basicPathItemWithFormData = new OpenApiPathItem + private static readonly OpenApiPathItem _basicPathItemWithFormData = new() { Parameters = new List { - new OpenApiParameter + new() { Name = "id", In = ParameterLocation.Path, Description = "ID of pet to use", Required = true, - Schema = new OpenApiSchema + Schema = new() { Type = "array", - Items = new OpenApiSchema + Items = new() { Type = "string" } @@ -40,41 +40,41 @@ public class OpenApiPathItemTests }, Operations = { - [OperationType.Put] = new OpenApiOperation + [OperationType.Put] = new() { Summary = "Puts a pet in the store with form data", Description = "", OperationId = "putPetWithForm", Parameters = new List { - new OpenApiParameter + new() { Name = "petId", In = ParameterLocation.Path, Description = "ID of pet that needs to be updated", Required = true, - Schema = new OpenApiSchema + Schema = new() { Type = "string" } } }, - RequestBody = new OpenApiRequestBody + RequestBody = new() { Content = { - ["application/x-www-form-urlencoded"] = new OpenApiMediaType + ["application/x-www-form-urlencoded"] = new() { - Schema = new OpenApiSchema + Schema = new() { Properties = { - ["name"] = new OpenApiSchema + ["name"] = new() { Description = "Updated name of the pet", Type = "string" }, - ["status"] = new OpenApiSchema + ["status"] = new() { Description = "Updated status of the pet", Type = "string" @@ -86,18 +86,18 @@ public class OpenApiPathItemTests } } }, - ["multipart/form-data"] = new OpenApiMediaType + ["multipart/form-data"] = new() { - Schema = new OpenApiSchema + Schema = new() { Properties = { - ["name"] = new OpenApiSchema + ["name"] = new() { Description = "Updated name of the pet", Type = "string" }, - ["status"] = new OpenApiSchema + ["status"] = new() { Description = "Updated status of the pet", Type = "string" @@ -111,79 +111,79 @@ public class OpenApiPathItemTests } } }, - Responses = new OpenApiResponses + Responses = new() { - ["200"] = new OpenApiResponse + ["200"] = new() { Description = "Pet updated.", Content = new Dictionary { - ["application/json"] = new OpenApiMediaType(), - ["application/xml"] = new OpenApiMediaType() + ["application/json"] = new(), + ["application/xml"] = new() } }, - ["405"] = new OpenApiResponse + ["405"] = new() { Description = "Invalid input", Content = new Dictionary { - ["application/json"] = new OpenApiMediaType(), - ["application/xml"] = new OpenApiMediaType() + ["application/json"] = new(), + ["application/xml"] = new() } } } }, - [OperationType.Post] = new OpenApiOperation + [OperationType.Post] = new() { Summary = "Posts a pet in the store with form data", Description = "", OperationId = "postPetWithForm", Parameters = new List { - new OpenApiParameter + new() { Name = "petId", In = ParameterLocation.Path, Description = "ID of pet that needs to be updated", Required = true, - Schema = new OpenApiSchema + Schema = new() { Type = "string" } }, - new OpenApiParameter + new() { Name = "petName", In = ParameterLocation.Path, Description = "Name of pet that needs to be updated", Required = true, - Schema = new OpenApiSchema + Schema = new() { Type = "string" } } }, - RequestBody = new OpenApiRequestBody + RequestBody = new() { Content = { - ["application/x-www-form-urlencoded"] = new OpenApiMediaType + ["application/x-www-form-urlencoded"] = new() { - Schema = new OpenApiSchema + Schema = new() { Properties = { - ["name"] = new OpenApiSchema + ["name"] = new() { Description = "Updated name of the pet", Type = "string" }, - ["status"] = new OpenApiSchema + ["status"] = new() { Description = "Updated status of the pet", Type = "string" }, - ["skill"] = new OpenApiSchema + ["skill"] = new() { Description = "Updated skill of the pet", Type = "string" @@ -195,23 +195,23 @@ public class OpenApiPathItemTests } } }, - ["multipart/form-data"] = new OpenApiMediaType + ["multipart/form-data"] = new() { - Schema = new OpenApiSchema + Schema = new() { Properties = { - ["name"] = new OpenApiSchema + ["name"] = new() { Description = "Updated name of the pet", Type = "string" }, - ["status"] = new OpenApiSchema + ["status"] = new() { Description = "Updated status of the pet", Type = "string" }, - ["skill"] = new OpenApiSchema + ["skill"] = new() { Description = "Updated skill of the pet", Type = "string" @@ -225,15 +225,15 @@ public class OpenApiPathItemTests } } }, - Responses = new OpenApiResponses + Responses = new() { - ["200"] = new OpenApiResponse + ["200"] = new() { Description = "Pet updated.", Content = new Dictionary { - ["application/json"] = new OpenApiMediaType(), - ["application/xml"] = new OpenApiMediaType() + ["application/json"] = new(), + ["application/xml"] = new() } } } diff --git a/test/Microsoft.OpenApi.Readers.Tests/V2Tests/OpenApiSecuritySchemeTests.cs b/test/Microsoft.OpenApi.Readers.Tests/V2Tests/OpenApiSecuritySchemeTests.cs index 6fa65252d..80539af75 100644 --- a/test/Microsoft.OpenApi.Readers.Tests/V2Tests/OpenApiSecuritySchemeTests.cs +++ b/test/Microsoft.OpenApi.Readers.Tests/V2Tests/OpenApiSecuritySchemeTests.cs @@ -1,7 +1,6 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. -using System; using System.IO; using System.Linq; using FluentAssertions; @@ -82,11 +81,11 @@ public void ParseOAuth2ImplicitSecuritySchemeShouldSucceed() new OpenApiSecurityScheme { Type = SecuritySchemeType.OAuth2, - Flows = new OpenApiOAuthFlows + Flows = new() { - Implicit = new OpenApiOAuthFlow + Implicit = new() { - AuthorizationUrl = new Uri("http://swagger.io/api/oauth/dialog"), + AuthorizationUrl = new("http://swagger.io/api/oauth/dialog"), Scopes = { ["write:pets"] = "modify pets in your account", @@ -115,11 +114,11 @@ public void ParseOAuth2PasswordSecuritySchemeShouldSucceed() new OpenApiSecurityScheme { Type = SecuritySchemeType.OAuth2, - Flows = new OpenApiOAuthFlows + Flows = new() { - Password = new OpenApiOAuthFlow + Password = new() { - AuthorizationUrl = new Uri("http://swagger.io/api/oauth/dialog"), + AuthorizationUrl = new("http://swagger.io/api/oauth/dialog"), Scopes = { ["write:pets"] = "modify pets in your account", @@ -148,11 +147,11 @@ public void ParseOAuth2ApplicationSecuritySchemeShouldSucceed() new OpenApiSecurityScheme { Type = SecuritySchemeType.OAuth2, - Flows = new OpenApiOAuthFlows + Flows = new() { - ClientCredentials = new OpenApiOAuthFlow + ClientCredentials = new() { - AuthorizationUrl = new Uri("http://swagger.io/api/oauth/dialog"), + AuthorizationUrl = new("http://swagger.io/api/oauth/dialog"), Scopes = { ["write:pets"] = "modify pets in your account", @@ -182,11 +181,11 @@ public void ParseOAuth2AccessCodeSecuritySchemeShouldSucceed() new OpenApiSecurityScheme { Type = SecuritySchemeType.OAuth2, - Flows = new OpenApiOAuthFlows + Flows = new() { - AuthorizationCode = new OpenApiOAuthFlow + AuthorizationCode = new() { - AuthorizationUrl = new Uri("http://swagger.io/api/oauth/dialog"), + AuthorizationUrl = new("http://swagger.io/api/oauth/dialog"), Scopes = { ["write:pets"] = "modify pets in your account", diff --git a/test/Microsoft.OpenApi.Readers.Tests/V2Tests/OpenApiServerTests.cs b/test/Microsoft.OpenApi.Readers.Tests/V2Tests/OpenApiServerTests.cs index 64c7c00fb..f254800b9 100644 --- a/test/Microsoft.OpenApi.Readers.Tests/V2Tests/OpenApiServerTests.cs +++ b/test/Microsoft.OpenApi.Readers.Tests/V2Tests/OpenApiServerTests.cs @@ -1,6 +1,5 @@ using FluentAssertions; using Microsoft.OpenApi.Models; -using System; using System.Linq; using Xunit; @@ -19,7 +18,7 @@ public void NoServer() version: 1.0.0 paths: {} """; - var reader = new OpenApiStringReader(new OpenApiReaderSettings + var reader = new OpenApiStringReader(new() { }); @@ -41,7 +40,7 @@ public void JustSchemeNoDefault() - http paths: {} """; - var reader = new OpenApiStringReader(new OpenApiReaderSettings + var reader = new OpenApiStringReader(new() { }); @@ -62,7 +61,7 @@ public void JustHostNoDefault() host: www.foo.com paths: {} """; - var reader = new OpenApiStringReader(new OpenApiReaderSettings + var reader = new OpenApiStringReader(new() { }); @@ -87,9 +86,9 @@ public void NoBasePath() - http paths: {} """; - var reader = new OpenApiStringReader(new OpenApiReaderSettings + var reader = new OpenApiStringReader(new() { - BaseUrl = new Uri("https://www.foo.com/spec.yaml") + BaseUrl = new("https://www.foo.com/spec.yaml") }); var doc = reader.Read(input, out var diagnostic); @@ -111,7 +110,7 @@ public void JustBasePathNoDefault() basePath: /baz paths: {} """; - var reader = new OpenApiStringReader(new OpenApiReaderSettings + var reader = new OpenApiStringReader(new() { }); @@ -135,9 +134,9 @@ public void JustSchemeWithCustomHost() - http paths: {} """; - var reader = new OpenApiStringReader(new OpenApiReaderSettings + var reader = new OpenApiStringReader(new() { - BaseUrl = new Uri("https://bing.com/foo") + BaseUrl = new("https://bing.com/foo") }); var doc = reader.Read(input, out var diagnostic); @@ -160,9 +159,9 @@ public void JustSchemeWithCustomHostWithEmptyPath() - http paths: {} """; - var reader = new OpenApiStringReader(new OpenApiReaderSettings + var reader = new OpenApiStringReader(new() { - BaseUrl = new Uri("https://bing.com") + BaseUrl = new("https://bing.com") }); var doc = reader.Read(input, out var diagnostic); @@ -184,9 +183,9 @@ public void JustBasePathWithCustomHost() basePath: /api paths: {} """; - var reader = new OpenApiStringReader(new OpenApiReaderSettings + var reader = new OpenApiStringReader(new() { - BaseUrl = new Uri("https://bing.com") + BaseUrl = new("https://bing.com") }); var doc = reader.Read(input, out var diagnostic); @@ -208,9 +207,9 @@ public void JustHostWithCustomHost() host: www.example.com paths: {} """; - var reader = new OpenApiStringReader(new OpenApiReaderSettings + var reader = new OpenApiStringReader(new() { - BaseUrl = new Uri("https://bing.com") + BaseUrl = new("https://bing.com") }); var doc = reader.Read(input, out var diagnostic); @@ -232,9 +231,9 @@ public void JustHostWithCustomHostWithApi() host: prod.bing.com paths: {} """; - var reader = new OpenApiStringReader(new OpenApiReaderSettings + var reader = new OpenApiStringReader(new() { - BaseUrl = new Uri("https://dev.bing.com/api/description.yaml") + BaseUrl = new("https://dev.bing.com/api/description.yaml") }); var doc = reader.Read(input, out var _); @@ -258,9 +257,9 @@ public void MultipleServers() - https paths: {} """; - var reader = new OpenApiStringReader(new OpenApiReaderSettings + var reader = new OpenApiStringReader(new() { - BaseUrl = new Uri("https://dev.bing.com/api") + BaseUrl = new("https://dev.bing.com/api") }); var doc = reader.Read(input, out var diagnostic); @@ -283,9 +282,9 @@ public void LocalHostWithCustomHost() host: localhost:23232 paths: {} """; - var reader = new OpenApiStringReader(new OpenApiReaderSettings + var reader = new OpenApiStringReader(new() { - BaseUrl = new Uri("https://bing.com") + BaseUrl = new("https://bing.com") }); var doc = reader.Read(input, out var diagnostic); @@ -307,9 +306,9 @@ public void InvalidHostShouldYieldError() host: http://test.microsoft.com paths: {} """; - var reader = new OpenApiStringReader(new OpenApiReaderSettings + var reader = new OpenApiStringReader(new() { - BaseUrl = new Uri("https://bing.com") + BaseUrl = new("https://bing.com") }); var doc = reader.Read(input, out var diagnostic); diff --git a/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiCallbackTests.cs b/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiCallbackTests.cs index 38d9cf1d1..3bddf695c 100644 --- a/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiCallbackTests.cs +++ b/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiCallbackTests.cs @@ -44,23 +44,23 @@ public void ParseBasicCallbackShouldSucceed() PathItems = { [RuntimeExpression.Build("$request.body#/url")] - = new OpenApiPathItem + = new() { Operations = { [OperationType.Post] = - new OpenApiOperation + new() { - RequestBody = new OpenApiRequestBody + RequestBody = new() { Content = { ["application/json"] = null } }, - Responses = new OpenApiResponses + Responses = new() { - ["200"] = new OpenApiResponse + ["200"] = new() { Description = "Success" } @@ -93,17 +93,18 @@ public void ParseCallbackWithReferenceShouldSucceed() { PathItems = { - [RuntimeExpression.Build("$request.body#/url")]= new OpenApiPathItem { + [RuntimeExpression.Build("$request.body#/url")]= new() + { Operations = { - [OperationType.Post] = new OpenApiOperation + [OperationType.Post] = new() { - RequestBody = new OpenApiRequestBody + RequestBody = new() { Content = { - ["application/json"] = new OpenApiMediaType + ["application/json"] = new() { - Schema = new OpenApiSchema + Schema = new() { Type = "object" } @@ -111,7 +112,7 @@ public void ParseCallbackWithReferenceShouldSucceed() } }, Responses = { - ["200"]= new OpenApiResponse + ["200"]= new() { Description = "Success" } @@ -120,7 +121,7 @@ public void ParseCallbackWithReferenceShouldSucceed() } } }, - Reference = new OpenApiReference + Reference = new() { Type = ReferenceType.Callback, Id = "simpleHook", @@ -150,17 +151,18 @@ public void ParseMultipleCallbacksWithReferenceShouldSucceed() { PathItems = { - [RuntimeExpression.Build("$request.body#/url")]= new OpenApiPathItem { + [RuntimeExpression.Build("$request.body#/url")]= new() + { Operations = { - [OperationType.Post] = new OpenApiOperation + [OperationType.Post] = new() { - RequestBody = new OpenApiRequestBody + RequestBody = new() { Content = { - ["application/json"] = new OpenApiMediaType + ["application/json"] = new() { - Schema = new OpenApiSchema + Schema = new() { Type = "object" } @@ -168,7 +170,7 @@ public void ParseMultipleCallbacksWithReferenceShouldSucceed() } }, Responses = { - ["200"]= new OpenApiResponse + ["200"]= new() { Description = "Success" } @@ -177,7 +179,7 @@ public void ParseMultipleCallbacksWithReferenceShouldSucceed() } } }, - Reference = new OpenApiReference + Reference = new() { Type = ReferenceType.Callback, Id = "simpleHook", @@ -191,18 +193,19 @@ public void ParseMultipleCallbacksWithReferenceShouldSucceed() { PathItems = { - [RuntimeExpression.Build("/simplePath")]= new OpenApiPathItem { + [RuntimeExpression.Build("/simplePath")]= new() + { Operations = { - [OperationType.Post] = new OpenApiOperation + [OperationType.Post] = new() { - RequestBody = new OpenApiRequestBody + RequestBody = new() { Description = "Callback 2", Content = { - ["application/json"] = new OpenApiMediaType + ["application/json"] = new() { - Schema = new OpenApiSchema + Schema = new() { Type = "string" } @@ -210,7 +213,7 @@ public void ParseMultipleCallbacksWithReferenceShouldSucceed() } }, Responses = { - ["400"]= new OpenApiResponse + ["400"]= new() { Description = "Callback Response" } @@ -227,17 +230,18 @@ public void ParseMultipleCallbacksWithReferenceShouldSucceed() { PathItems = { - [RuntimeExpression.Build(@"http://example.com?transactionId={$request.body#/id}&email={$request.body#/email}")] = new OpenApiPathItem { + [RuntimeExpression.Build(@"http://example.com?transactionId={$request.body#/id}&email={$request.body#/email}")] = new() + { Operations = { - [OperationType.Post] = new OpenApiOperation + [OperationType.Post] = new() { - RequestBody = new OpenApiRequestBody + RequestBody = new() { Content = { - ["application/xml"] = new OpenApiMediaType + ["application/xml"] = new() { - Schema = new OpenApiSchema + Schema = new() { Type = "object" } @@ -245,15 +249,15 @@ public void ParseMultipleCallbacksWithReferenceShouldSucceed() } }, Responses = { - ["200"]= new OpenApiResponse + ["200"]= new() { Description = "Success" }, - ["401"]= new OpenApiResponse + ["401"]= new() { Description = "Unauthorized" }, - ["404"]= new OpenApiResponse + ["404"]= new() { Description = "Not Found" } diff --git a/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiContactTests.cs b/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiContactTests.cs index c4f08f389..3f6b4a320 100644 --- a/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiContactTests.cs +++ b/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiContactTests.cs @@ -3,7 +3,6 @@ using FluentAssertions; using Microsoft.OpenApi.Models; -using System; using Xunit; namespace Microsoft.OpenApi.Readers.Tests.V3Tests @@ -34,7 +33,7 @@ public void ParseStringContactFragmentShouldSucceed() { Email = "support@swagger.io", Name = "API Support", - Url = new Uri("http://www.swagger.io/support") + Url = new("http://www.swagger.io/support") }); } } diff --git a/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiDocumentTests.cs b/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiDocumentTests.cs index f50f7e01f..4505ce33a 100644 --- a/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiDocumentTests.cs +++ b/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiDocumentTests.cs @@ -15,7 +15,6 @@ using Microsoft.OpenApi.Validations.Rules; using Microsoft.OpenApi.Writers; using Xunit; -using Xunit.Abstractions; namespace Microsoft.OpenApi.Readers.Tests.V3Tests { @@ -29,7 +28,7 @@ public T Clone(T element) where T : IOpenApiSerializable using var stream = new MemoryStream(); IOpenApiWriter writer; var streamWriter = new FormattingStreamWriter(stream, CultureInfo.InvariantCulture); - writer = new OpenApiJsonWriter(streamWriter, new OpenApiJsonWriterSettings + writer = new OpenApiJsonWriter(streamWriter, new() { InlineLocalReferences = true }); @@ -47,7 +46,7 @@ public OpenApiSecurityScheme CloneSecurityScheme(OpenApiSecurityScheme element) using var stream = new MemoryStream(); IOpenApiWriter writer; var streamWriter = new FormattingStreamWriter(stream, CultureInfo.InvariantCulture); - writer = new OpenApiJsonWriter(streamWriter, new OpenApiJsonWriterSettings + writer = new OpenApiJsonWriter(streamWriter, new() { InlineLocalReferences = true }); @@ -77,12 +76,12 @@ public void ParseDocumentFromInlineStringShouldSucceed() openApiDoc.Should().BeEquivalentTo( new OpenApiDocument { - Info = new OpenApiInfo + Info = new() { Title = "Simple Document", Version = "0.9.1" }, - Paths = new OpenApiPaths() + Paths = new() }); context.Should().BeEquivalentTo( @@ -97,8 +96,8 @@ public void ParseDocumentFromInlineStringShouldSucceed() [InlineData("da-DK")] public void ParseDocumentWithDifferentCultureShouldSucceed(string culture) { - Thread.CurrentThread.CurrentCulture = new CultureInfo(culture); - Thread.CurrentThread.CurrentUICulture = new CultureInfo(culture); + Thread.CurrentThread.CurrentCulture = new(culture); + Thread.CurrentThread.CurrentUICulture = new(culture); var openApiDoc = new OpenApiStringReader().Read( """ @@ -124,21 +123,21 @@ public void ParseDocumentWithDifferentCultureShouldSucceed(string culture) openApiDoc.Should().BeEquivalentTo( new OpenApiDocument { - Info = new OpenApiInfo + Info = new() { Title = "Simple Document", Version = "0.9.1" }, - Components = new OpenApiComponents + Components = new() { Schemas = { - ["sampleSchema"] = new OpenApiSchema + ["sampleSchema"] = new() { Type = "object", Properties = { - ["sampleProperty"] = new OpenApiSchema + ["sampleProperty"] = new() { Type = "double", Minimum = (decimal)100.54, @@ -147,7 +146,7 @@ public void ParseDocumentWithDifferentCultureShouldSucceed(string culture) ExclusiveMinimum = false } }, - Reference = new OpenApiReference + Reference = new() { Id = "sampleSchema", Type = ReferenceType.Schema @@ -155,7 +154,7 @@ public void ParseDocumentWithDifferentCultureShouldSucceed(string culture) } } }, - Paths = new OpenApiPaths() + Paths = new() }); context.Should().BeEquivalentTo( @@ -174,7 +173,7 @@ public void ParseBasicDocumentWithMultipleServersShouldSucceed() openApiDoc.Should().BeEquivalentTo( new OpenApiDocument { - Info = new OpenApiInfo + Info = new() { Title = "The API", Version = "0.9.1", @@ -192,7 +191,7 @@ public void ParseBasicDocumentWithMultipleServersShouldSucceed() Description = "The https endpoint" } }, - Paths = new OpenApiPaths() + Paths = new() }); } @@ -205,11 +204,11 @@ public void ParseBrokenMinimalDocumentShouldYieldExpectedDiagnostic() openApiDoc.Should().BeEquivalentTo( new OpenApiDocument { - Info = new OpenApiInfo + Info = new() { Version = "0.9" }, - Paths = new OpenApiPaths() + Paths = new() }); diagnostic.Should().BeEquivalentTo( @@ -232,12 +231,12 @@ public void ParseMinimalDocumentShouldSucceed() openApiDoc.Should().BeEquivalentTo( new OpenApiDocument { - Info = new OpenApiInfo + Info = new() { Title = "Simple Document", Version = "0.9.1" }, - Paths = new OpenApiPaths() + Paths = new() }); diagnostic.Should().BeEquivalentTo( @@ -256,7 +255,7 @@ public void ParseStandardPetStoreDocumentShouldSucceed() { Schemas = new Dictionary { - ["pet"] = new OpenApiSchema + ["pet"] = new() { Type = "object", Required = new HashSet @@ -266,28 +265,28 @@ public void ParseStandardPetStoreDocumentShouldSucceed() }, Properties = new Dictionary { - ["id"] = new OpenApiSchema + ["id"] = new() { Type = "integer", Format = "int64" }, - ["name"] = new OpenApiSchema + ["name"] = new() { Type = "string" }, - ["tag"] = new OpenApiSchema + ["tag"] = new() { Type = "string" }, }, - Reference = new OpenApiReference + Reference = new() { Type = ReferenceType.Schema, Id = "pet", HostDocument = actual } }, - ["newPet"] = new OpenApiSchema + ["newPet"] = new() { Type = "object", Required = new HashSet @@ -296,28 +295,28 @@ public void ParseStandardPetStoreDocumentShouldSucceed() }, Properties = new Dictionary { - ["id"] = new OpenApiSchema + ["id"] = new() { Type = "integer", Format = "int64" }, - ["name"] = new OpenApiSchema + ["name"] = new() { Type = "string" }, - ["tag"] = new OpenApiSchema + ["tag"] = new() { Type = "string" }, }, - Reference = new OpenApiReference + Reference = new() { Type = ReferenceType.Schema, Id = "newPet", HostDocument = actual } }, - ["errorModel"] = new OpenApiSchema + ["errorModel"] = new() { Type = "object", Required = new HashSet @@ -327,17 +326,17 @@ public void ParseStandardPetStoreDocumentShouldSucceed() }, Properties = new Dictionary { - ["code"] = new OpenApiSchema + ["code"] = new() { Type = "integer", Format = "int32" }, - ["message"] = new OpenApiSchema + ["message"] = new() { Type = "string" } }, - Reference = new OpenApiReference + Reference = new() { Type = ReferenceType.Schema, Id = "errorModel", @@ -350,7 +349,7 @@ public void ParseStandardPetStoreDocumentShouldSucceed() // Create a clone of the schema to avoid modifying things in components. var petSchema = Clone(components.Schemas["pet"]); - petSchema.Reference = new OpenApiReference + petSchema.Reference = new() { Id = "pet", Type = ReferenceType.Schema, @@ -359,7 +358,7 @@ public void ParseStandardPetStoreDocumentShouldSucceed() var newPetSchema = Clone(components.Schemas["newPet"]); - newPetSchema.Reference = new OpenApiReference + newPetSchema.Reference = new() { Id = "newPet", Type = ReferenceType.Schema, @@ -368,7 +367,7 @@ public void ParseStandardPetStoreDocumentShouldSucceed() var errorModelSchema = Clone(components.Schemas["errorModel"]); - errorModelSchema.Reference = new OpenApiReference + errorModelSchema.Reference = new() { Id = "errorModel", Type = ReferenceType.Schema, @@ -377,90 +376,90 @@ public void ParseStandardPetStoreDocumentShouldSucceed() var expected = new OpenApiDocument { - Info = new OpenApiInfo + Info = new() { Version = "1.0.0", Title = "Swagger Petstore (Simple)", Description = "A sample API that uses a petstore as an example to demonstrate features in the swagger-2.0 specification", - TermsOfService = new Uri("http://helloreverb.com/terms/"), - Contact = new OpenApiContact + TermsOfService = new("http://helloreverb.com/terms/"), + Contact = new() { Name = "Swagger API team", Email = "foo@example.com", - Url = new Uri("http://swagger.io") + Url = new("http://swagger.io") }, - License = new OpenApiLicense + License = new() { Name = "MIT", - Url = new Uri("http://opensource.org/licenses/MIT") + Url = new("http://opensource.org/licenses/MIT") } }, Servers = new List { - new OpenApiServer + new() { Url = "http://petstore.swagger.io/api" } }, - Paths = new OpenApiPaths + Paths = new() { - ["/pets"] = new OpenApiPathItem + ["/pets"] = new() { Operations = new Dictionary { - [OperationType.Get] = new OpenApiOperation + [OperationType.Get] = new() { Description = "Returns all pets from the system that the user has access to", OperationId = "findPets", Parameters = new List { - new OpenApiParameter + new() { Name = "tags", In = ParameterLocation.Query, Description = "tags to filter by", Required = false, - Schema = new OpenApiSchema + Schema = new() { Type = "array", - Items = new OpenApiSchema + Items = new() { Type = "string" } } }, - new OpenApiParameter + new() { Name = "limit", In = ParameterLocation.Query, Description = "maximum number of results to return", Required = false, - Schema = new OpenApiSchema + Schema = new() { Type = "integer", Format = "int32" } } }, - Responses = new OpenApiResponses + Responses = new() { - ["200"] = new OpenApiResponse + ["200"] = new() { Description = "pet response", Content = new Dictionary { - ["application/json"] = new OpenApiMediaType + ["application/json"] = new() { - Schema = new OpenApiSchema + Schema = new() { Type = "array", Items = petSchema } }, - ["application/xml"] = new OpenApiMediaType + ["application/xml"] = new() { - Schema = new OpenApiSchema + Schema = new() { Type = "array", Items = petSchema @@ -468,23 +467,23 @@ public void ParseStandardPetStoreDocumentShouldSucceed() } } }, - ["4XX"] = new OpenApiResponse + ["4XX"] = new() { Description = "unexpected client error", Content = new Dictionary { - ["text/html"] = new OpenApiMediaType + ["text/html"] = new() { Schema = errorModelSchema } } }, - ["5XX"] = new OpenApiResponse + ["5XX"] = new() { Description = "unexpected server error", Content = new Dictionary { - ["text/html"] = new OpenApiMediaType + ["text/html"] = new() { Schema = errorModelSchema } @@ -492,52 +491,52 @@ public void ParseStandardPetStoreDocumentShouldSucceed() } } }, - [OperationType.Post] = new OpenApiOperation + [OperationType.Post] = new() { Description = "Creates a new pet in the store. Duplicates are allowed", OperationId = "addPet", - RequestBody = new OpenApiRequestBody + RequestBody = new() { Description = "Pet to add to the store", Required = true, Content = new Dictionary { - ["application/json"] = new OpenApiMediaType + ["application/json"] = new() { Schema = newPetSchema } } }, - Responses = new OpenApiResponses + Responses = new() { - ["200"] = new OpenApiResponse + ["200"] = new() { Description = "pet response", Content = new Dictionary { - ["application/json"] = new OpenApiMediaType + ["application/json"] = new() { Schema = petSchema }, } }, - ["4XX"] = new OpenApiResponse + ["4XX"] = new() { Description = "unexpected client error", Content = new Dictionary { - ["text/html"] = new OpenApiMediaType + ["text/html"] = new() { Schema = errorModelSchema } } }, - ["5XX"] = new OpenApiResponse + ["5XX"] = new() { Description = "unexpected server error", Content = new Dictionary { - ["text/html"] = new OpenApiMediaType + ["text/html"] = new() { Schema = errorModelSchema } @@ -547,64 +546,64 @@ public void ParseStandardPetStoreDocumentShouldSucceed() } } }, - ["/pets/{id}"] = new OpenApiPathItem + ["/pets/{id}"] = new() { Operations = new Dictionary { - [OperationType.Get] = new OpenApiOperation + [OperationType.Get] = new() { Description = "Returns a user based on a single ID, if the user does not have access to the pet", OperationId = "findPetById", Parameters = new List { - new OpenApiParameter + new() { Name = "id", In = ParameterLocation.Path, Description = "ID of pet to fetch", Required = true, - Schema = new OpenApiSchema + Schema = new() { Type = "integer", Format = "int64" } } }, - Responses = new OpenApiResponses + Responses = new() { - ["200"] = new OpenApiResponse + ["200"] = new() { Description = "pet response", Content = new Dictionary { - ["application/json"] = new OpenApiMediaType + ["application/json"] = new() { Schema = petSchema }, - ["application/xml"] = new OpenApiMediaType + ["application/xml"] = new() { Schema = petSchema } } }, - ["4XX"] = new OpenApiResponse + ["4XX"] = new() { Description = "unexpected client error", Content = new Dictionary { - ["text/html"] = new OpenApiMediaType + ["text/html"] = new() { Schema = errorModelSchema } } }, - ["5XX"] = new OpenApiResponse + ["5XX"] = new() { Description = "unexpected server error", Content = new Dictionary { - ["text/html"] = new OpenApiMediaType + ["text/html"] = new() { Schema = errorModelSchema } @@ -612,48 +611,48 @@ public void ParseStandardPetStoreDocumentShouldSucceed() } } }, - [OperationType.Delete] = new OpenApiOperation + [OperationType.Delete] = new() { Description = "deletes a single pet based on the ID supplied", OperationId = "deletePet", Parameters = new List { - new OpenApiParameter + new() { Name = "id", In = ParameterLocation.Path, Description = "ID of pet to delete", Required = true, - Schema = new OpenApiSchema + Schema = new() { Type = "integer", Format = "int64" } } }, - Responses = new OpenApiResponses + Responses = new() { - ["204"] = new OpenApiResponse + ["204"] = new() { Description = "pet deleted" }, - ["4XX"] = new OpenApiResponse + ["4XX"] = new() { Description = "unexpected client error", Content = new Dictionary { - ["text/html"] = new OpenApiMediaType + ["text/html"] = new() { Schema = errorModelSchema } } }, - ["5XX"] = new OpenApiResponse + ["5XX"] = new() { Description = "unexpected server error", Content = new Dictionary { - ["text/html"] = new OpenApiMediaType + ["text/html"] = new() { Schema = errorModelSchema } @@ -686,7 +685,7 @@ public void ParseModifiedPetStoreDocumentWithTagAndSecurityShouldSucceed() { Schemas = new Dictionary { - ["pet"] = new OpenApiSchema + ["pet"] = new() { Type = "object", Required = new HashSet @@ -696,28 +695,28 @@ public void ParseModifiedPetStoreDocumentWithTagAndSecurityShouldSucceed() }, Properties = new Dictionary { - ["id"] = new OpenApiSchema + ["id"] = new() { Type = "integer", Format = "int64" }, - ["name"] = new OpenApiSchema + ["name"] = new() { Type = "string" }, - ["tag"] = new OpenApiSchema + ["tag"] = new() { Type = "string" }, }, - Reference = new OpenApiReference + Reference = new() { Type = ReferenceType.Schema, Id = "pet", HostDocument = actual } }, - ["newPet"] = new OpenApiSchema + ["newPet"] = new() { Type = "object", Required = new HashSet @@ -726,28 +725,28 @@ public void ParseModifiedPetStoreDocumentWithTagAndSecurityShouldSucceed() }, Properties = new Dictionary { - ["id"] = new OpenApiSchema + ["id"] = new() { Type = "integer", Format = "int64" }, - ["name"] = new OpenApiSchema + ["name"] = new() { Type = "string" }, - ["tag"] = new OpenApiSchema + ["tag"] = new() { Type = "string" }, }, - Reference = new OpenApiReference + Reference = new() { Type = ReferenceType.Schema, Id = "newPet", HostDocument = actual } }, - ["errorModel"] = new OpenApiSchema + ["errorModel"] = new() { Type = "object", Required = new HashSet @@ -757,17 +756,17 @@ public void ParseModifiedPetStoreDocumentWithTagAndSecurityShouldSucceed() }, Properties = new Dictionary { - ["code"] = new OpenApiSchema + ["code"] = new() { Type = "integer", Format = "int32" }, - ["message"] = new OpenApiSchema + ["message"] = new() { Type = "string" } }, - Reference = new OpenApiReference + Reference = new() { Type = ReferenceType.Schema, Id = "errorModel" @@ -776,12 +775,12 @@ public void ParseModifiedPetStoreDocumentWithTagAndSecurityShouldSucceed() }, SecuritySchemes = new Dictionary { - ["securitySchemeName1"] = new OpenApiSecurityScheme + ["securitySchemeName1"] = new() { Type = SecuritySchemeType.ApiKey, Name = "apiKeyName1", In = ParameterLocation.Header, - Reference = new OpenApiReference + Reference = new() { Id = "securitySchemeName1", Type = ReferenceType.SecurityScheme, @@ -789,11 +788,11 @@ public void ParseModifiedPetStoreDocumentWithTagAndSecurityShouldSucceed() } }, - ["securitySchemeName2"] = new OpenApiSecurityScheme + ["securitySchemeName2"] = new() { Type = SecuritySchemeType.OpenIdConnect, - OpenIdConnectUrl = new Uri("http://example.com"), - Reference = new OpenApiReference + OpenIdConnectUrl = new("http://example.com"), + Reference = new() { Id = "securitySchemeName2", Type = ReferenceType.SecurityScheme, @@ -805,7 +804,7 @@ public void ParseModifiedPetStoreDocumentWithTagAndSecurityShouldSucceed() // Create a clone of the schema to avoid modifying things in components. var petSchema = Clone(components.Schemas["pet"]); - petSchema.Reference = new OpenApiReference + petSchema.Reference = new() { Id = "pet", Type = ReferenceType.Schema @@ -813,7 +812,7 @@ public void ParseModifiedPetStoreDocumentWithTagAndSecurityShouldSucceed() var newPetSchema = Clone(components.Schemas["newPet"]); - newPetSchema.Reference = new OpenApiReference + newPetSchema.Reference = new() { Id = "newPet", Type = ReferenceType.Schema @@ -821,7 +820,7 @@ public void ParseModifiedPetStoreDocumentWithTagAndSecurityShouldSucceed() var errorModelSchema = Clone(components.Schemas["errorModel"]); - errorModelSchema.Reference = new OpenApiReference + errorModelSchema.Reference = new() { Id = "errorModel", Type = ReferenceType.Schema @@ -831,7 +830,7 @@ public void ParseModifiedPetStoreDocumentWithTagAndSecurityShouldSucceed() { Name = "tagName1", Description = "tagDescription1", - Reference = new OpenApiReference + Reference = new() { Id = "tagName1", Type = ReferenceType.Tag @@ -845,7 +844,7 @@ public void ParseModifiedPetStoreDocumentWithTagAndSecurityShouldSucceed() var securityScheme1 = CloneSecurityScheme(components.SecuritySchemes["securitySchemeName1"]); - securityScheme1.Reference = new OpenApiReference + securityScheme1.Reference = new() { Id = "securitySchemeName1", Type = ReferenceType.SecurityScheme @@ -853,7 +852,7 @@ public void ParseModifiedPetStoreDocumentWithTagAndSecurityShouldSucceed() var securityScheme2 = CloneSecurityScheme(components.SecuritySchemes["securitySchemeName2"]); - securityScheme2.Reference = new OpenApiReference + securityScheme2.Reference = new() { Id = "securitySchemeName2", Type = ReferenceType.SecurityScheme @@ -861,39 +860,39 @@ public void ParseModifiedPetStoreDocumentWithTagAndSecurityShouldSucceed() var expected = new OpenApiDocument { - Info = new OpenApiInfo + Info = new() { Version = "1.0.0", Title = "Swagger Petstore (Simple)", Description = "A sample API that uses a petstore as an example to demonstrate features in the swagger-2.0 specification", - TermsOfService = new Uri("http://helloreverb.com/terms/"), - Contact = new OpenApiContact + TermsOfService = new("http://helloreverb.com/terms/"), + Contact = new() { Name = "Swagger API team", Email = "foo@example.com", - Url = new Uri("http://swagger.io") + Url = new("http://swagger.io") }, - License = new OpenApiLicense + License = new() { Name = "MIT", - Url = new Uri("http://opensource.org/licenses/MIT") + Url = new("http://opensource.org/licenses/MIT") } }, Servers = new List { - new OpenApiServer + new() { Url = "http://petstore.swagger.io/api" } }, - Paths = new OpenApiPaths + Paths = new() { - ["/pets"] = new OpenApiPathItem + ["/pets"] = new() { Operations = new Dictionary { - [OperationType.Get] = new OpenApiOperation + [OperationType.Get] = new() { Tags = new List { @@ -904,52 +903,52 @@ public void ParseModifiedPetStoreDocumentWithTagAndSecurityShouldSucceed() OperationId = "findPets", Parameters = new List { - new OpenApiParameter + new() { Name = "tags", In = ParameterLocation.Query, Description = "tags to filter by", Required = false, - Schema = new OpenApiSchema + Schema = new() { Type = "array", - Items = new OpenApiSchema + Items = new() { Type = "string" } } }, - new OpenApiParameter + new() { Name = "limit", In = ParameterLocation.Query, Description = "maximum number of results to return", Required = false, - Schema = new OpenApiSchema + Schema = new() { Type = "integer", Format = "int32" } } }, - Responses = new OpenApiResponses + Responses = new() { - ["200"] = new OpenApiResponse + ["200"] = new() { Description = "pet response", Content = new Dictionary { - ["application/json"] = new OpenApiMediaType + ["application/json"] = new() { - Schema = new OpenApiSchema + Schema = new() { Type = "array", Items = petSchema } }, - ["application/xml"] = new OpenApiMediaType + ["application/xml"] = new() { - Schema = new OpenApiSchema + Schema = new() { Type = "array", Items = petSchema @@ -957,23 +956,23 @@ public void ParseModifiedPetStoreDocumentWithTagAndSecurityShouldSucceed() } } }, - ["4XX"] = new OpenApiResponse + ["4XX"] = new() { Description = "unexpected client error", Content = new Dictionary { - ["text/html"] = new OpenApiMediaType + ["text/html"] = new() { Schema = errorModelSchema } } }, - ["5XX"] = new OpenApiResponse + ["5XX"] = new() { Description = "unexpected server error", Content = new Dictionary { - ["text/html"] = new OpenApiMediaType + ["text/html"] = new() { Schema = errorModelSchema } @@ -981,7 +980,7 @@ public void ParseModifiedPetStoreDocumentWithTagAndSecurityShouldSucceed() } } }, - [OperationType.Post] = new OpenApiOperation + [OperationType.Post] = new() { Tags = new List { @@ -990,48 +989,48 @@ public void ParseModifiedPetStoreDocumentWithTagAndSecurityShouldSucceed() }, Description = "Creates a new pet in the store. Duplicates are allowed", OperationId = "addPet", - RequestBody = new OpenApiRequestBody + RequestBody = new() { Description = "Pet to add to the store", Required = true, Content = new Dictionary { - ["application/json"] = new OpenApiMediaType + ["application/json"] = new() { Schema = newPetSchema } } }, - Responses = new OpenApiResponses + Responses = new() { - ["200"] = new OpenApiResponse + ["200"] = new() { Description = "pet response", Content = new Dictionary { - ["application/json"] = new OpenApiMediaType + ["application/json"] = new() { Schema = petSchema }, } }, - ["4XX"] = new OpenApiResponse + ["4XX"] = new() { Description = "unexpected client error", Content = new Dictionary { - ["text/html"] = new OpenApiMediaType + ["text/html"] = new() { Schema = errorModelSchema } } }, - ["5XX"] = new OpenApiResponse + ["5XX"] = new() { Description = "unexpected server error", Content = new Dictionary { - ["text/html"] = new OpenApiMediaType + ["text/html"] = new() { Schema = errorModelSchema } @@ -1040,7 +1039,7 @@ public void ParseModifiedPetStoreDocumentWithTagAndSecurityShouldSucceed() }, Security = new List { - new OpenApiSecurityRequirement + new() { [securityScheme1] = new List(), [securityScheme2] = new List @@ -1053,64 +1052,64 @@ public void ParseModifiedPetStoreDocumentWithTagAndSecurityShouldSucceed() } } }, - ["/pets/{id}"] = new OpenApiPathItem + ["/pets/{id}"] = new() { Operations = new Dictionary { - [OperationType.Get] = new OpenApiOperation + [OperationType.Get] = new() { Description = "Returns a user based on a single ID, if the user does not have access to the pet", OperationId = "findPetById", Parameters = new List { - new OpenApiParameter + new() { Name = "id", In = ParameterLocation.Path, Description = "ID of pet to fetch", Required = true, - Schema = new OpenApiSchema + Schema = new() { Type = "integer", Format = "int64" } } }, - Responses = new OpenApiResponses + Responses = new() { - ["200"] = new OpenApiResponse + ["200"] = new() { Description = "pet response", Content = new Dictionary { - ["application/json"] = new OpenApiMediaType + ["application/json"] = new() { Schema = petSchema }, - ["application/xml"] = new OpenApiMediaType + ["application/xml"] = new() { Schema = petSchema } } }, - ["4XX"] = new OpenApiResponse + ["4XX"] = new() { Description = "unexpected client error", Content = new Dictionary { - ["text/html"] = new OpenApiMediaType + ["text/html"] = new() { Schema = errorModelSchema } } }, - ["5XX"] = new OpenApiResponse + ["5XX"] = new() { Description = "unexpected server error", Content = new Dictionary { - ["text/html"] = new OpenApiMediaType + ["text/html"] = new() { Schema = errorModelSchema } @@ -1118,48 +1117,48 @@ public void ParseModifiedPetStoreDocumentWithTagAndSecurityShouldSucceed() } } }, - [OperationType.Delete] = new OpenApiOperation + [OperationType.Delete] = new() { Description = "deletes a single pet based on the ID supplied", OperationId = "deletePet", Parameters = new List { - new OpenApiParameter + new() { Name = "id", In = ParameterLocation.Path, Description = "ID of pet to delete", Required = true, - Schema = new OpenApiSchema + Schema = new() { Type = "integer", Format = "int64" } } }, - Responses = new OpenApiResponses + Responses = new() { - ["204"] = new OpenApiResponse + ["204"] = new() { Description = "pet deleted" }, - ["4XX"] = new OpenApiResponse + ["4XX"] = new() { Description = "unexpected client error", Content = new Dictionary { - ["text/html"] = new OpenApiMediaType + ["text/html"] = new() { Schema = errorModelSchema } } }, - ["5XX"] = new OpenApiResponse + ["5XX"] = new() { Description = "unexpected server error", Content = new Dictionary { - ["text/html"] = new OpenApiMediaType + ["text/html"] = new() { Schema = errorModelSchema } @@ -1173,11 +1172,11 @@ public void ParseModifiedPetStoreDocumentWithTagAndSecurityShouldSucceed() Components = components, Tags = new List { - new OpenApiTag + new() { Name = "tagName1", Description = "tagDescription1", - Reference = new OpenApiReference + Reference = new() { Id = "tagName1", Type = ReferenceType.Tag @@ -1186,7 +1185,7 @@ public void ParseModifiedPetStoreDocumentWithTagAndSecurityShouldSucceed() }, SecurityRequirements = new List { - new OpenApiSecurityRequirement + new() { [securityScheme1] = new List(), [securityScheme2] = new List @@ -1252,12 +1251,12 @@ public void HeaderParameterShouldAllowExample() Style = ParameterStyle.Simple, Explode = true, Example = new OpenApiString("99391c7e-ad88-49ec-a2ad-99ddcb1f7721"), - Schema = new OpenApiSchema + Schema = new() { Type = "string", Format = "uuid" }, - Reference = new OpenApiReference + Reference = new() { Type = ReferenceType.Header, Id = "example-header" @@ -1289,12 +1288,12 @@ public void HeaderParameterShouldAllowExample() } } }, - Schema = new OpenApiSchema + Schema = new() { Type = "string", Format = "uuid" }, - Reference = new OpenApiReference + Reference = new() { Type = ReferenceType.Header, Id = "examples-header" @@ -1310,7 +1309,7 @@ public void DoesNotChangeExternalReferences() // Act var doc = new OpenApiStreamReader( - new OpenApiReaderSettings { ReferenceResolution = ReferenceResolutionSetting.DoNotResolveReferences }) + new() { ReferenceResolution = ReferenceResolutionSetting.DoNotResolveReferences }) .Read(stream, out var diagnostic); var externalRef = doc.Components.Schemas["Nested"].Properties["AnyOf"].AnyOf.First().Reference.ReferenceV3; @@ -1328,7 +1327,7 @@ public void ParseDocumentWithReferencedSecuritySchemeWorks() using var stream = Resources.GetStream(Path.Combine(SampleFolderPath, "docWithSecuritySchemeReference.yaml")); // Act - var doc = new OpenApiStreamReader(new OpenApiReaderSettings + var doc = new OpenApiStreamReader(new() { ReferenceResolution = ReferenceResolutionSetting.ResolveLocalReferences }).Read(stream, out var diagnostic); diff --git a/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiEncodingTests.cs b/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiEncodingTests.cs index d3cea2d6b..2b9c23fe1 100644 --- a/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiEncodingTests.cs +++ b/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiEncodingTests.cs @@ -65,10 +65,10 @@ public void ParseAdvancedEncodingShouldSucceed() Headers = { ["X-Rate-Limit-Limit"] = - new OpenApiHeader + new() { Description = "The number of allowed requests in the current period", - Schema = new OpenApiSchema + Schema = new() { Type = "integer" } diff --git a/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiInfoTests.cs b/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiInfoTests.cs index 34d821a72..c21789ccf 100644 --- a/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiInfoTests.cs +++ b/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiInfoTests.cs @@ -1,7 +1,6 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. -using System; using System.IO; using System.Linq; using FluentAssertions; @@ -42,8 +41,8 @@ public void ParseAdvancedInfoShouldSucceed() Title = "Advanced Info", Description = "Sample Description", Version = "1.0.0", - TermsOfService = new Uri("http://example.org/termsOfService"), - Contact = new OpenApiContact + TermsOfService = new("http://example.org/termsOfService"), + Contact = new() { Email = "example@example.com", Extensions = @@ -51,13 +50,13 @@ public void ParseAdvancedInfoShouldSucceed() ["x-twitter"] = new OpenApiString("@exampleTwitterHandler") }, Name = "John Doe", - Url = new Uri("http://www.example.com/url1") + Url = new("http://www.example.com/url1") }, - License = new OpenApiLicense + License = new() { Extensions = { ["x-disclaimer"] = new OpenApiString("Sample Extension String Disclaimer") }, Name = "licenseName", - Url = new Uri("http://www.example.com/url2") + Url = new("http://www.example.com/url2") }, Extensions = { @@ -100,17 +99,17 @@ public void ParseBasicInfoShouldSucceed() Title = "Basic Info", Description = "Sample Description", Version = "1.0.1", - TermsOfService = new Uri("http://swagger.io/terms/"), - Contact = new OpenApiContact + TermsOfService = new("http://swagger.io/terms/"), + Contact = new() { Email = "support@swagger.io", Name = "API Support", - Url = new Uri("http://www.swagger.io/support") + Url = new("http://www.swagger.io/support") }, - License = new OpenApiLicense + License = new() { Name = "Apache 2.0", - Url = new Uri("http://www.apache.org/licenses/LICENSE-2.0.html") + Url = new("http://www.apache.org/licenses/LICENSE-2.0.html") } }); } diff --git a/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiMediaTypeTests.cs b/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiMediaTypeTests.cs index f9835bfbb..8e3a6c864 100644 --- a/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiMediaTypeTests.cs +++ b/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiMediaTypeTests.cs @@ -34,7 +34,7 @@ public void ParseMediaTypeWithExampleShouldSucceed() new OpenApiMediaType { Example = new OpenApiFloat(5), - Schema = new OpenApiSchema + Schema = new() { Type = "number", Format = "float" @@ -61,16 +61,16 @@ public void ParseMediaTypeWithExamplesShouldSucceed() { Examples = { - ["example1"] = new OpenApiExample + ["example1"] = new() { Value = new OpenApiFloat(5), }, - ["example2"] = new OpenApiExample + ["example2"] = new() { Value = new OpenApiFloat((float)7.5), } }, - Schema = new OpenApiSchema + Schema = new() { Type = "number", Format = "float" diff --git a/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiOperationTests.cs b/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiOperationTests.cs index db2f3907c..ced80c348 100644 --- a/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiOperationTests.cs +++ b/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiOperationTests.cs @@ -47,7 +47,7 @@ public void ParseOperationWithParameterWithNoLocationShouldSucceed() new OpenApiTag { UnresolvedReference = true, - Reference = new OpenApiReference + Reference = new() { Id = "user", Type = ReferenceType.Tag @@ -64,7 +64,7 @@ public void ParseOperationWithParameterWithNoLocationShouldSucceed() Name = "username", Description = "The user name for login", Required = true, - Schema = new OpenApiSchema + Schema = new() { Type = "string" } @@ -75,7 +75,7 @@ public void ParseOperationWithParameterWithNoLocationShouldSucceed() Description = "The password for login in clear text", In = ParameterLocation.Query, Required = true, - Schema = new OpenApiSchema + Schema = new() { Type = "string" } diff --git a/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiParameterTests.cs b/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiParameterTests.cs index 13188dba1..1439cea2e 100644 --- a/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiParameterTests.cs +++ b/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiParameterTests.cs @@ -37,7 +37,7 @@ public void ParsePathParameterShouldSucceed() Name = "username", Description = "username to fetch", Required = true, - Schema = new OpenApiSchema + Schema = new() { Type = "string" } @@ -65,10 +65,10 @@ public void ParseQueryParameterShouldSucceed() Name = "id", Description = "ID of the object to fetch", Required = false, - Schema = new OpenApiSchema + Schema = new() { Type = "array", - Items = new OpenApiSchema + Items = new() { Type = "string" } @@ -97,10 +97,10 @@ public void ParseQueryParameterWithObjectTypeShouldSucceed() { In = ParameterLocation.Query, Name = "freeForm", - Schema = new OpenApiSchema + Schema = new() { Type = "object", - AdditionalProperties = new OpenApiSchema + AdditionalProperties = new() { Type = "integer" } @@ -130,9 +130,9 @@ public void ParseQueryParameterWithObjectTypeAndContentShouldSucceed() Name = "coordinates", Content = { - ["application/json"] = new OpenApiMediaType + ["application/json"] = new() { - Schema = new OpenApiSchema + Schema = new() { Type = "object", Required = @@ -142,11 +142,11 @@ public void ParseQueryParameterWithObjectTypeAndContentShouldSucceed() }, Properties = { - ["lat"] = new OpenApiSchema + ["lat"] = new() { Type = "number" }, - ["long"] = new OpenApiSchema + ["long"] = new() { Type = "number" } @@ -180,10 +180,10 @@ public void ParseHeaderParameterShouldSucceed() Required = true, Style = ParameterStyle.Simple, - Schema = new OpenApiSchema + Schema = new() { Type = "array", - Items = new OpenApiSchema + Items = new() { Type = "integer", Format = "int64", @@ -213,7 +213,7 @@ public void ParseParameterWithNullLocationShouldSucceed() Name = "username", Description = "username to fetch", Required = true, - Schema = new OpenApiSchema + Schema = new() { Type = "string" } @@ -241,7 +241,7 @@ public void ParseParameterWithNoLocationShouldSucceed() Name = "username", Description = "username to fetch", Required = true, - Schema = new OpenApiSchema + Schema = new() { Type = "string" } @@ -269,7 +269,7 @@ public void ParseParameterWithUnknownLocationShouldSucceed() Name = "username", Description = "username to fetch", Required = true, - Schema = new OpenApiSchema + Schema = new() { Type = "string" } @@ -298,7 +298,7 @@ public void ParseParameterWithExampleShouldSucceed() Description = "username to fetch", Required = true, Example = new OpenApiFloat(5), - Schema = new OpenApiSchema + Schema = new() { Type = "number", Format = "float" @@ -329,16 +329,16 @@ public void ParseParameterWithExamplesShouldSucceed() Required = true, Examples = { - ["example1"] = new OpenApiExample + ["example1"] = new() { Value = new OpenApiFloat(5), }, - ["example2"] = new OpenApiExample + ["example2"] = new() { Value = new OpenApiFloat((float)7.5), } }, - Schema = new OpenApiSchema + Schema = new() { Type = "number", Format = "float" diff --git a/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiSchemaTests.cs b/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiSchemaTests.cs index e84b8cbc5..109997bb6 100644 --- a/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiSchemaTests.cs +++ b/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiSchemaTests.cs @@ -179,15 +179,15 @@ public void ParseSimpleSchemaShouldSucceed() }, Properties = { - ["name"] = new OpenApiSchema + ["name"] = new() { Type = "string" }, - ["address"] = new OpenApiSchema + ["address"] = new() { Type = "string" }, - ["age"] = new OpenApiSchema + ["age"] = new() { Type = "integer", Format = "int32", @@ -223,11 +223,11 @@ public void ParsePathFragmentShouldSucceed() Summary = "externally referenced path item", Operations = new Dictionary { - [OperationType.Get] = new OpenApiOperation + [OperationType.Get] = new() { - Responses = new OpenApiResponses + Responses = new() { - ["200"] = new OpenApiResponse + ["200"] = new() { Description = "Ok" } @@ -260,7 +260,7 @@ public void ParseDictionarySchemaShouldSucceed() new OpenApiSchema { Type = "object", - AdditionalProperties = new OpenApiSchema + AdditionalProperties = new() { Type = "string" } @@ -292,12 +292,12 @@ public void ParseBasicSchemaWithExampleShouldSucceed() Type = "object", Properties = { - ["id"] = new OpenApiSchema + ["id"] = new() { Type = "integer", Format = "int64" }, - ["name"] = new OpenApiSchema + ["name"] = new() { Type = "string" } @@ -332,23 +332,23 @@ public void ParseBasicSchemaWithReferenceShouldSucceed() { Schemas = { - ["ErrorModel"] = new OpenApiSchema + ["ErrorModel"] = new() { Type = "object", Properties = { - ["code"] = new OpenApiSchema + ["code"] = new() { Type = "integer", Minimum = 100, Maximum = 600 }, - ["message"] = new OpenApiSchema + ["message"] = new() { Type = "string" } }, - Reference = new OpenApiReference + Reference = new() { Type = ReferenceType.Schema, Id = "ErrorModel", @@ -360,9 +360,9 @@ public void ParseBasicSchemaWithReferenceShouldSucceed() "code" } }, - ["ExtendedErrorModel"] = new OpenApiSchema + ["ExtendedErrorModel"] = new() { - Reference = new OpenApiReference + Reference = new() { Type = ReferenceType.Schema, Id = "ExtendedErrorModel", @@ -372,7 +372,7 @@ public void ParseBasicSchemaWithReferenceShouldSucceed() { new OpenApiSchema { - Reference = new OpenApiReference + Reference = new() { Type = ReferenceType.Schema, Id = "ErrorModel", @@ -383,13 +383,13 @@ public void ParseBasicSchemaWithReferenceShouldSucceed() Type = "object", Properties = { - ["code"] = new OpenApiSchema + ["code"] = new() { Type = "integer", Minimum = 100, Maximum = 600 }, - ["message"] = new OpenApiSchema + ["message"] = new() { Type = "string" } @@ -406,7 +406,7 @@ public void ParseBasicSchemaWithReferenceShouldSucceed() Required = {"rootCause"}, Properties = { - ["rootCause"] = new OpenApiSchema + ["rootCause"] = new() { Type = "string" } @@ -436,20 +436,20 @@ public void ParseAdvancedSchemaWithReferenceShouldSucceed() { Schemas = { - ["Pet"] = new OpenApiSchema + ["Pet"] = new() { Type = "object", - Discriminator = new OpenApiDiscriminator + Discriminator = new() { PropertyName = "petType" }, Properties = { - ["name"] = new OpenApiSchema + ["name"] = new() { Type = "string" }, - ["petType"] = new OpenApiSchema + ["petType"] = new() { Type = "string" } @@ -459,21 +459,21 @@ public void ParseAdvancedSchemaWithReferenceShouldSucceed() "name", "petType" }, - Reference = new OpenApiReference + Reference = new() { Id= "Pet", Type = ReferenceType.Schema, HostDocument = openApiDoc } }, - ["Cat"] = new OpenApiSchema + ["Cat"] = new() { Description = "A representation of a cat", AllOf = { new OpenApiSchema { - Reference = new OpenApiReference + Reference = new() { Type = ReferenceType.Schema, Id = "Pet", @@ -482,17 +482,17 @@ public void ParseAdvancedSchemaWithReferenceShouldSucceed() // Schema should be dereferenced in our model, so all the properties // from the Pet above should be propagated here. Type = "object", - Discriminator = new OpenApiDiscriminator + Discriminator = new() { PropertyName = "petType" }, Properties = { - ["name"] = new OpenApiSchema + ["name"] = new() { Type = "string" }, - ["petType"] = new OpenApiSchema + ["petType"] = new() { Type = "string" } @@ -509,7 +509,7 @@ public void ParseAdvancedSchemaWithReferenceShouldSucceed() Required = {"huntingSkill"}, Properties = { - ["huntingSkill"] = new OpenApiSchema + ["huntingSkill"] = new() { Type = "string", Description = "The measured skill for hunting", @@ -524,21 +524,21 @@ public void ParseAdvancedSchemaWithReferenceShouldSucceed() } } }, - Reference = new OpenApiReference + Reference = new() { Id= "Cat", Type = ReferenceType.Schema, HostDocument = openApiDoc } }, - ["Dog"] = new OpenApiSchema + ["Dog"] = new() { Description = "A representation of a dog", AllOf = { new OpenApiSchema { - Reference = new OpenApiReference + Reference = new() { Type = ReferenceType.Schema, Id = "Pet", @@ -547,17 +547,17 @@ public void ParseAdvancedSchemaWithReferenceShouldSucceed() // Schema should be dereferenced in our model, so all the properties // from the Pet above should be propagated here. Type = "object", - Discriminator = new OpenApiDiscriminator + Discriminator = new() { PropertyName = "petType" }, Properties = { - ["name"] = new OpenApiSchema + ["name"] = new() { Type = "string" }, - ["petType"] = new OpenApiSchema + ["petType"] = new() { Type = "string" } @@ -574,7 +574,7 @@ public void ParseAdvancedSchemaWithReferenceShouldSucceed() Required = {"packSize"}, Properties = { - ["packSize"] = new OpenApiSchema + ["packSize"] = new() { Type = "integer", Format = "int32", @@ -585,7 +585,7 @@ public void ParseAdvancedSchemaWithReferenceShouldSucceed() } } }, - Reference = new OpenApiReference + Reference = new() { Id= "Dog", Type = ReferenceType.Schema, @@ -616,22 +616,22 @@ public void ParseSelfReferencingSchemaShouldNotStackOverflow() Title = "schemaExtension", Type = "object", Properties = { - ["description"] = new OpenApiSchema { Type = "string", Nullable = true}, - ["targetTypes"] = new OpenApiSchema + ["description"] = new() { Type = "string", Nullable = true}, + ["targetTypes"] = new() { Type = "array", - Items = new OpenApiSchema + Items = new() { Type = "string" } }, - ["status"] = new OpenApiSchema { Type = "string"}, - ["owner"] = new OpenApiSchema { Type = "string"}, + ["status"] = new() { Type = "string"}, + ["owner"] = new() { Type = "string"}, ["child"] = null } } }, - Reference = new OpenApiReference + Reference = new() { Type = ReferenceType.Schema, Id = "microsoft.graph.schemaExtension" diff --git a/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiSecuritySchemeTests.cs b/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiSecuritySchemeTests.cs index fdeb9734d..0e462c2eb 100644 --- a/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiSecuritySchemeTests.cs +++ b/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiSecuritySchemeTests.cs @@ -1,7 +1,6 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. -using System; using System.IO; using System.Linq; using FluentAssertions; @@ -116,11 +115,11 @@ public void ParseOAuth2SecuritySchemeShouldSucceed() new OpenApiSecurityScheme { Type = SecuritySchemeType.OAuth2, - Flows = new OpenApiOAuthFlows + Flows = new() { - Implicit = new OpenApiOAuthFlow + Implicit = new() { - AuthorizationUrl = new Uri("https://example.com/api/oauth/dialog"), + AuthorizationUrl = new("https://example.com/api/oauth/dialog"), Scopes = { ["write:pets"] = "modify pets in your account", @@ -153,7 +152,7 @@ public void ParseOpenIdConnectSecuritySchemeShouldSucceed() { Type = SecuritySchemeType.OpenIdConnect, Description = "Sample Description", - OpenIdConnectUrl = new Uri("http://www.example.com") + OpenIdConnectUrl = new("http://www.example.com") }); } } diff --git a/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiXmlTests.cs b/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiXmlTests.cs index ebba38c35..4f7de222b 100644 --- a/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiXmlTests.cs +++ b/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiXmlTests.cs @@ -1,7 +1,6 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. -using System; using System.IO; using System.Linq; using FluentAssertions; @@ -39,7 +38,7 @@ public void ParseBasicXmlShouldSucceed() new OpenApiXml { Name = "name1", - Namespace = new Uri("http://example.com/schema/namespaceSample"), + Namespace = new("http://example.com/schema/namespaceSample"), Prefix = "samplePrefix", Wrapped = true }); diff --git a/test/Microsoft.OpenApi.SmokeTests/ApiGurus.cs b/test/Microsoft.OpenApi.SmokeTests/ApiGurus.cs index 079ab6569..efc79b133 100644 --- a/test/Microsoft.OpenApi.SmokeTests/ApiGurus.cs +++ b/test/Microsoft.OpenApi.SmokeTests/ApiGurus.cs @@ -28,12 +28,12 @@ public ApisGuruTests(ITestOutputHelper output) static ApisGuruTests() { System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; - _httpClient = new HttpClient(new HttpClientHandler + _httpClient = new(new HttpClientHandler { AutomaticDecompression = DecompressionMethods.GZip }); - _httpClient.DefaultRequestHeaders.AcceptEncoding.Add(new System.Net.Http.Headers.StringWithQualityHeaderValue("gzip")); - _httpClient.DefaultRequestHeaders.UserAgent.Add(new System.Net.Http.Headers.ProductInfoHeaderValue("OpenApi.Net.Tests", "1.0")); + _httpClient.DefaultRequestHeaders.AcceptEncoding.Add(new("gzip")); + _httpClient.DefaultRequestHeaders.UserAgent.Add(new("OpenApi.Net.Tests", "1.0")); } public static IEnumerable GetSchemas() diff --git a/test/Microsoft.OpenApi.SmokeTests/GraphTests.cs b/test/Microsoft.OpenApi.SmokeTests/GraphTests.cs index 9bfebed25..77b4d2525 100644 --- a/test/Microsoft.OpenApi.SmokeTests/GraphTests.cs +++ b/test/Microsoft.OpenApi.SmokeTests/GraphTests.cs @@ -20,11 +20,11 @@ public GraphTests(ITestOutputHelper output) { _output = output; System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; - _httpClient = new HttpClient(new HttpClientHandler + _httpClient = new(new HttpClientHandler { AutomaticDecompression = DecompressionMethods.GZip }); - _httpClient.DefaultRequestHeaders.AcceptEncoding.Add(new System.Net.Http.Headers.StringWithQualityHeaderValue("gzip")); - _httpClient.DefaultRequestHeaders.UserAgent.Add(new System.Net.Http.Headers.ProductInfoHeaderValue("OpenApi.Net.Tests", "1.0")); + _httpClient.DefaultRequestHeaders.AcceptEncoding.Add(new("gzip")); + _httpClient.DefaultRequestHeaders.UserAgent.Add(new("OpenApi.Net.Tests", "1.0")); var response = _httpClient.GetAsync(graphOpenApiUrl) .GetAwaiter().GetResult(); diff --git a/test/Microsoft.OpenApi.Tests/MicrosoftExtensions/OpenApiDeprecationExtensionTests.cs b/test/Microsoft.OpenApi.Tests/MicrosoftExtensions/OpenApiDeprecationExtensionTests.cs index b48a574f3..5f4cd74fa 100644 --- a/test/Microsoft.OpenApi.Tests/MicrosoftExtensions/OpenApiDeprecationExtensionTests.cs +++ b/test/Microsoft.OpenApi.Tests/MicrosoftExtensions/OpenApiDeprecationExtensionTests.cs @@ -74,8 +74,8 @@ public void Parses() { var oaiValue = new OpenApiObject { - { "date", new OpenApiDateTime(new DateTimeOffset(2023,05,04, 16, 0, 0, 0, 0, new TimeSpan(4, 0, 0)))}, - { "removalDate", new OpenApiDateTime(new DateTimeOffset(2023,05,04, 16, 0, 0, 0, 0, new TimeSpan(4, 0, 0)))}, + { "date", new OpenApiDateTime(new(2023,05,04, 16, 0, 0, 0, 0, new(4, 0, 0)))}, + { "removalDate", new OpenApiDateTime(new(2023,05,04, 16, 0, 0, 0, 0, new(4, 0, 0)))}, { "version", new OpenApiString("v1.0")}, { "description", new OpenApiString("removing")} }; @@ -83,16 +83,16 @@ public void Parses() Assert.NotNull(value); Assert.Equal("v1.0", value.Version); Assert.Equal("removing", value.Description); - Assert.Equal(new DateTimeOffset(2023, 05, 04, 16, 0, 0, 0, 0, new TimeSpan(4, 0, 0)), value.Date); - Assert.Equal(new DateTimeOffset(2023, 05, 04, 16, 0, 0, 0, 0, new TimeSpan(4, 0, 0)), value.RemovalDate); + Assert.Equal(new DateTimeOffset(2023, 05, 04, 16, 0, 0, 0, 0, new(4, 0, 0)), value.Date); + Assert.Equal(new DateTimeOffset(2023, 05, 04, 16, 0, 0, 0, 0, new(4, 0, 0)), value.RemovalDate); } [Fact] public void Serializes() { var value = new OpenApiDeprecationExtension { - Date = new DateTimeOffset(2023, 05, 04, 16, 0, 0, 0, 0, new TimeSpan(4, 0, 0)), - RemovalDate = new DateTimeOffset(2023, 05, 04, 16, 0, 0, 0, 0, new TimeSpan(4, 0, 0)), + Date = new DateTimeOffset(2023, 05, 04, 16, 0, 0, 0, 0, new(4, 0, 0)), + RemovalDate = new DateTimeOffset(2023, 05, 04, 16, 0, 0, 0, 0, new(4, 0, 0)), Version = "v1.0", Description = "removing" }; diff --git a/test/Microsoft.OpenApi.Tests/Models/OpenApiCallbackTests.cs b/test/Microsoft.OpenApi.Tests/Models/OpenApiCallbackTests.cs index 05f6f3f00..6b6a8d734 100644 --- a/test/Microsoft.OpenApi.Tests/Models/OpenApiCallbackTests.cs +++ b/test/Microsoft.OpenApi.Tests/Models/OpenApiCallbackTests.cs @@ -16,34 +16,34 @@ namespace Microsoft.OpenApi.Tests.Models [UsesVerify] public class OpenApiCallbackTests { - public static OpenApiCallback AdvancedCallback = new OpenApiCallback + public static OpenApiCallback AdvancedCallback = new() { PathItems = { [RuntimeExpression.Build("$request.body#/url")] - = new OpenApiPathItem + = new() { Operations = { [OperationType.Post] = - new OpenApiOperation + new() { - RequestBody = new OpenApiRequestBody + RequestBody = new() { Content = { - ["application/json"] = new OpenApiMediaType + ["application/json"] = new() { - Schema = new OpenApiSchema + Schema = new() { Type = "object" } } } }, - Responses = new OpenApiResponses + Responses = new() { - ["200"] = new OpenApiResponse + ["200"] = new() { Description = "Success" } @@ -54,9 +54,9 @@ public class OpenApiCallbackTests } }; - public static OpenApiCallback ReferencedCallback = new OpenApiCallback + public static OpenApiCallback ReferencedCallback = new() { - Reference = new OpenApiReference + Reference = new() { Type = ReferenceType.Callback, Id = "simpleHook", @@ -64,29 +64,29 @@ public class OpenApiCallbackTests PathItems = { [RuntimeExpression.Build("$request.body#/url")] - = new OpenApiPathItem + = new() { Operations = { [OperationType.Post] = - new OpenApiOperation + new() { - RequestBody = new OpenApiRequestBody + RequestBody = new() { Content = { - ["application/json"] = new OpenApiMediaType + ["application/json"] = new() { - Schema = new OpenApiSchema + Schema = new() { Type = "object" } } } }, - Responses = new OpenApiResponses + Responses = new() { - ["200"] = new OpenApiResponse + ["200"] = new() { Description = "Success" } @@ -104,7 +104,7 @@ public async Task SerializeAdvancedCallbackAsV3JsonWorks(bool produceTerseOutput { // Arrange var outputStringWriter = new StringWriter(CultureInfo.InvariantCulture); - var writer = new OpenApiJsonWriter(outputStringWriter, new OpenApiJsonWriterSettings { Terse = produceTerseOutput }); + var writer = new OpenApiJsonWriter(outputStringWriter, new() { Terse = produceTerseOutput }); // Act AdvancedCallback.SerializeAsV3(writer); @@ -121,7 +121,7 @@ public async Task SerializeReferencedCallbackAsV3JsonWorks(bool produceTerseOutp { // Arrange var outputStringWriter = new StringWriter(CultureInfo.InvariantCulture); - var writer = new OpenApiJsonWriter(outputStringWriter, new OpenApiJsonWriterSettings { Terse = produceTerseOutput }); + var writer = new OpenApiJsonWriter(outputStringWriter, new() { Terse = produceTerseOutput }); // Act ReferencedCallback.SerializeAsV3(writer); @@ -138,7 +138,7 @@ public async Task SerializeReferencedCallbackAsV3JsonWithoutReferenceWorks(bool { // Arrange var outputStringWriter = new StringWriter(CultureInfo.InvariantCulture); - var writer = new OpenApiJsonWriter(outputStringWriter, new OpenApiJsonWriterSettings { Terse = produceTerseOutput }); + var writer = new OpenApiJsonWriter(outputStringWriter, new() { Terse = produceTerseOutput }); // Act ReferencedCallback.SerializeAsV3WithoutReference(writer); diff --git a/test/Microsoft.OpenApi.Tests/Models/OpenApiComponentsTests.cs b/test/Microsoft.OpenApi.Tests/Models/OpenApiComponentsTests.cs index 371f95e25..b361d6c6c 100644 --- a/test/Microsoft.OpenApi.Tests/Models/OpenApiComponentsTests.cs +++ b/test/Microsoft.OpenApi.Tests/Models/OpenApiComponentsTests.cs @@ -1,7 +1,6 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. -using System; using System.Collections.Generic; using FluentAssertions; using Microsoft.OpenApi.Extensions; @@ -13,19 +12,19 @@ namespace Microsoft.OpenApi.Tests.Models [Collection("DefaultSettings")] public class OpenApiComponentsTests { - public static OpenApiComponents AdvancedComponents = new OpenApiComponents + public static OpenApiComponents AdvancedComponents = new() { Schemas = new Dictionary { - ["schema1"] = new OpenApiSchema + ["schema1"] = new() { Properties = new Dictionary { - ["property2"] = new OpenApiSchema + ["property2"] = new() { Type = "integer" }, - ["property3"] = new OpenApiSchema + ["property3"] = new() { Type = "string", MaxLength = 15 @@ -35,65 +34,65 @@ public class OpenApiComponentsTests }, SecuritySchemes = new Dictionary { - ["securityScheme1"] = new OpenApiSecurityScheme + ["securityScheme1"] = new() { Description = "description1", Type = SecuritySchemeType.OAuth2, - Flows = new OpenApiOAuthFlows + Flows = new() { - Implicit = new OpenApiOAuthFlow + Implicit = new() { Scopes = new Dictionary { ["operation1:object1"] = "operation 1 on object 1", ["operation2:object2"] = "operation 2 on object 2" }, - AuthorizationUrl = new Uri("https://example.com/api/oauth") + AuthorizationUrl = new("https://example.com/api/oauth") } } }, - ["securityScheme2"] = new OpenApiSecurityScheme + ["securityScheme2"] = new() { Description = "description1", Type = SecuritySchemeType.OpenIdConnect, Scheme = OpenApiConstants.Bearer, - OpenIdConnectUrl = new Uri("https://example.com/openIdConnect") + OpenIdConnectUrl = new("https://example.com/openIdConnect") } } }; - public static OpenApiComponents AdvancedComponentsWithReference = new OpenApiComponents + public static OpenApiComponents AdvancedComponentsWithReference = new() { Schemas = new Dictionary { - ["schema1"] = new OpenApiSchema + ["schema1"] = new() { Properties = new Dictionary { - ["property2"] = new OpenApiSchema + ["property2"] = new() { Type = "integer" }, - ["property3"] = new OpenApiSchema + ["property3"] = new() { - Reference = new OpenApiReference + Reference = new() { Type = ReferenceType.Schema, Id = "schema2" } } }, - Reference = new OpenApiReference + Reference = new() { Type = ReferenceType.Schema, Id = "schema1" } }, - ["schema2"] = new OpenApiSchema + ["schema2"] = new() { Properties = new Dictionary { - ["property2"] = new OpenApiSchema + ["property2"] = new() { Type = "integer" } @@ -102,35 +101,35 @@ public class OpenApiComponentsTests }, SecuritySchemes = new Dictionary { - ["securityScheme1"] = new OpenApiSecurityScheme + ["securityScheme1"] = new() { Description = "description1", Type = SecuritySchemeType.OAuth2, - Flows = new OpenApiOAuthFlows + Flows = new() { - Implicit = new OpenApiOAuthFlow + Implicit = new() { Scopes = new Dictionary { ["operation1:object1"] = "operation 1 on object 1", ["operation2:object2"] = "operation 2 on object 2" }, - AuthorizationUrl = new Uri("https://example.com/api/oauth") + AuthorizationUrl = new("https://example.com/api/oauth") } }, - Reference = new OpenApiReference + Reference = new() { Type = ReferenceType.SecurityScheme, Id = "securityScheme1" } }, - ["securityScheme2"] = new OpenApiSecurityScheme + ["securityScheme2"] = new() { Description = "description1", Type = SecuritySchemeType.OpenIdConnect, Scheme = OpenApiConstants.Bearer, - OpenIdConnectUrl = new Uri("https://example.com/openIdConnect"), - Reference = new OpenApiReference + OpenIdConnectUrl = new("https://example.com/openIdConnect"), + Reference = new() { Type = ReferenceType.SecurityScheme, Id = "securityScheme2" @@ -139,26 +138,26 @@ public class OpenApiComponentsTests } }; - public static OpenApiComponents BasicComponents = new OpenApiComponents(); + public static OpenApiComponents BasicComponents = new(); - public static OpenApiComponents BrokenComponents = new OpenApiComponents + public static OpenApiComponents BrokenComponents = new() { Schemas = new Dictionary { - ["schema1"] = new OpenApiSchema + ["schema1"] = new() { Type = "string" }, ["schema2"] = null, ["schema3"] = null, - ["schema4"] = new OpenApiSchema + ["schema4"] = new() { Type = "string", AllOf = new List { null, null, - new OpenApiSchema + new() { Type = "string" }, @@ -169,24 +168,24 @@ public class OpenApiComponentsTests } }; - public static OpenApiComponents TopLevelReferencingComponents = new OpenApiComponents + public static OpenApiComponents TopLevelReferencingComponents = new() { Schemas = { - ["schema1"] = new OpenApiSchema + ["schema1"] = new() { - Reference = new OpenApiReference + Reference = new() { Type = ReferenceType.Schema, Id = "schema2" } }, - ["schema2"] = new OpenApiSchema + ["schema2"] = new() { Type = "object", Properties = { - ["property1"] = new OpenApiSchema + ["property1"] = new() { Type = "string" } @@ -195,32 +194,32 @@ public class OpenApiComponentsTests } }; - public static OpenApiComponents TopLevelSelfReferencingComponentsWithOtherProperties = new OpenApiComponents + public static OpenApiComponents TopLevelSelfReferencingComponentsWithOtherProperties = new() { Schemas = { - ["schema1"] = new OpenApiSchema + ["schema1"] = new() { Type = "object", Properties = { - ["property1"] = new OpenApiSchema + ["property1"] = new() { Type = "string" } }, - Reference = new OpenApiReference + Reference = new() { Type = ReferenceType.Schema, Id = "schema1" } }, - ["schema2"] = new OpenApiSchema + ["schema2"] = new() { Type = "object", Properties = { - ["property1"] = new OpenApiSchema + ["property1"] = new() { Type = "string" } @@ -229,13 +228,13 @@ public class OpenApiComponentsTests } }; - public static OpenApiComponents TopLevelSelfReferencingComponents = new OpenApiComponents + public static OpenApiComponents TopLevelSelfReferencingComponents = new() { Schemas = { - ["schema1"] = new OpenApiSchema + ["schema1"] = new() { - Reference = new OpenApiReference + Reference = new() { Type = ReferenceType.Schema, Id = "schema1" diff --git a/test/Microsoft.OpenApi.Tests/Models/OpenApiContactTests.cs b/test/Microsoft.OpenApi.Tests/Models/OpenApiContactTests.cs index 477b0fa67..b33029261 100644 --- a/test/Microsoft.OpenApi.Tests/Models/OpenApiContactTests.cs +++ b/test/Microsoft.OpenApi.Tests/Models/OpenApiContactTests.cs @@ -1,7 +1,6 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. -using System; using System.Collections.Generic; using FluentAssertions; using Microsoft.OpenApi.Any; @@ -15,12 +14,12 @@ namespace Microsoft.OpenApi.Tests.Models [Collection("DefaultSettings")] public class OpenApiContactTests { - public static OpenApiContact BasicContact = new OpenApiContact(); + public static OpenApiContact BasicContact = new(); - public static OpenApiContact AdvanceContact = new OpenApiContact + public static OpenApiContact AdvanceContact = new() { Name = "API Support", - Url = new Uri("http://www.example.com/support"), + Url = new("http://www.example.com/support"), Email = "support@example.com", Extensions = new Dictionary { diff --git a/test/Microsoft.OpenApi.Tests/Models/OpenApiDocumentTests.cs b/test/Microsoft.OpenApi.Tests/Models/OpenApiDocumentTests.cs index 75903049c..1538aa2fb 100644 --- a/test/Microsoft.OpenApi.Tests/Models/OpenApiDocumentTests.cs +++ b/test/Microsoft.OpenApi.Tests/Models/OpenApiDocumentTests.cs @@ -1,7 +1,6 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. -using System; using System.Collections.Generic; using System.Globalization; using System.IO; @@ -14,7 +13,6 @@ using Microsoft.OpenApi.Writers; using VerifyXunit; using Xunit; -using Xunit.Abstractions; namespace Microsoft.OpenApi.Tests.Models { @@ -22,24 +20,24 @@ namespace Microsoft.OpenApi.Tests.Models [UsesVerify] public class OpenApiDocumentTests { - public static OpenApiComponents TopLevelReferencingComponents = new OpenApiComponents + public static OpenApiComponents TopLevelReferencingComponents = new() { Schemas = { - ["schema1"] = new OpenApiSchema + ["schema1"] = new() { - Reference = new OpenApiReference + Reference = new() { Type = ReferenceType.Schema, Id = "schema2" } }, - ["schema2"] = new OpenApiSchema + ["schema2"] = new() { Type = "object", Properties = { - ["property1"] = new OpenApiSchema + ["property1"] = new() { Type = "string" } @@ -48,32 +46,32 @@ public class OpenApiDocumentTests } }; - public static OpenApiComponents TopLevelSelfReferencingComponentsWithOtherProperties = new OpenApiComponents + public static OpenApiComponents TopLevelSelfReferencingComponentsWithOtherProperties = new() { Schemas = { - ["schema1"] = new OpenApiSchema + ["schema1"] = new() { Type = "object", Properties = { - ["property1"] = new OpenApiSchema + ["property1"] = new() { Type = "string" } }, - Reference = new OpenApiReference + Reference = new() { Type = ReferenceType.Schema, Id = "schema1" } }, - ["schema2"] = new OpenApiSchema + ["schema2"] = new() { Type = "object", Properties = { - ["property1"] = new OpenApiSchema + ["property1"] = new() { Type = "string" } @@ -82,13 +80,13 @@ public class OpenApiDocumentTests } }; - public static OpenApiComponents TopLevelSelfReferencingComponents = new OpenApiComponents + public static OpenApiComponents TopLevelSelfReferencingComponents = new() { Schemas = { - ["schema1"] = new OpenApiSchema + ["schema1"] = new() { - Reference = new OpenApiReference + Reference = new() { Type = ReferenceType.Schema, Id = "schema1" @@ -97,38 +95,38 @@ public class OpenApiDocumentTests } }; - public static OpenApiDocument SimpleDocumentWithTopLevelReferencingComponents = new OpenApiDocument + public static OpenApiDocument SimpleDocumentWithTopLevelReferencingComponents = new() { - Info = new OpenApiInfo + Info = new() { Version = "1.0.0" }, Components = TopLevelReferencingComponents }; - public static OpenApiDocument SimpleDocumentWithTopLevelSelfReferencingComponentsWithOtherProperties = new OpenApiDocument + public static OpenApiDocument SimpleDocumentWithTopLevelSelfReferencingComponentsWithOtherProperties = new() { - Info = new OpenApiInfo + Info = new() { Version = "1.0.0" }, Components = TopLevelSelfReferencingComponentsWithOtherProperties }; - public static OpenApiDocument SimpleDocumentWithTopLevelSelfReferencingComponents = new OpenApiDocument + public static OpenApiDocument SimpleDocumentWithTopLevelSelfReferencingComponents = new() { - Info = new OpenApiInfo + Info = new() { Version = "1.0.0" }, Components = TopLevelSelfReferencingComponents }; - public static OpenApiComponents AdvancedComponentsWithReference = new OpenApiComponents + public static OpenApiComponents AdvancedComponentsWithReference = new() { Schemas = new Dictionary { - ["pet"] = new OpenApiSchema + ["pet"] = new() { Type = "object", Required = new HashSet @@ -138,27 +136,27 @@ public class OpenApiDocumentTests }, Properties = new Dictionary { - ["id"] = new OpenApiSchema + ["id"] = new() { Type = "integer", Format = "int64" }, - ["name"] = new OpenApiSchema + ["name"] = new() { Type = "string" }, - ["tag"] = new OpenApiSchema + ["tag"] = new() { Type = "string" }, }, - Reference = new OpenApiReference + Reference = new() { Id = "pet", Type = ReferenceType.Schema } }, - ["newPet"] = new OpenApiSchema + ["newPet"] = new() { Type = "object", Required = new HashSet @@ -167,27 +165,27 @@ public class OpenApiDocumentTests }, Properties = new Dictionary { - ["id"] = new OpenApiSchema + ["id"] = new() { Type = "integer", Format = "int64" }, - ["name"] = new OpenApiSchema + ["name"] = new() { Type = "string" }, - ["tag"] = new OpenApiSchema + ["tag"] = new() { Type = "string" }, }, - Reference = new OpenApiReference + Reference = new() { Id = "newPet", Type = ReferenceType.Schema } }, - ["errorModel"] = new OpenApiSchema + ["errorModel"] = new() { Type = "object", Required = new HashSet @@ -197,17 +195,17 @@ public class OpenApiDocumentTests }, Properties = new Dictionary { - ["code"] = new OpenApiSchema + ["code"] = new() { Type = "integer", Format = "int32" }, - ["message"] = new OpenApiSchema + ["message"] = new() { Type = "string" } }, - Reference = new OpenApiReference + Reference = new() { Id = "errorModel", Type = ReferenceType.Schema @@ -223,92 +221,92 @@ public class OpenApiDocumentTests public static OpenApiSchema ErrorModelSchemaWithReference = AdvancedComponentsWithReference.Schemas["errorModel"]; - public static OpenApiDocument AdvancedDocumentWithReference = new OpenApiDocument + public static OpenApiDocument AdvancedDocumentWithReference = new() { - Info = new OpenApiInfo + Info = new() { Version = "1.0.0", Title = "Swagger Petstore (Simple)", Description = "A sample API that uses a petstore as an example to demonstrate features in the swagger-2.0 specification", - TermsOfService = new Uri("http://helloreverb.com/terms/"), - Contact = new OpenApiContact + TermsOfService = new("http://helloreverb.com/terms/"), + Contact = new() { Name = "Swagger API team", Email = "foo@example.com", - Url = new Uri("http://swagger.io") + Url = new("http://swagger.io") }, - License = new OpenApiLicense + License = new() { Name = "MIT", - Url = new Uri("http://opensource.org/licenses/MIT") + Url = new("http://opensource.org/licenses/MIT") } }, Servers = new List { - new OpenApiServer + new() { Url = "http://petstore.swagger.io/api" } }, - Paths = new OpenApiPaths + Paths = new() { - ["/pets"] = new OpenApiPathItem + ["/pets"] = new() { Operations = new Dictionary { - [OperationType.Get] = new OpenApiOperation + [OperationType.Get] = new() { Description = "Returns all pets from the system that the user has access to", OperationId = "findPets", Parameters = new List { - new OpenApiParameter + new() { Name = "tags", In = ParameterLocation.Query, Description = "tags to filter by", Required = false, - Schema = new OpenApiSchema + Schema = new() { Type = "array", - Items = new OpenApiSchema + Items = new() { Type = "string" } } }, - new OpenApiParameter + new() { Name = "limit", In = ParameterLocation.Query, Description = "maximum number of results to return", Required = false, - Schema = new OpenApiSchema + Schema = new() { Type = "integer", Format = "int32" } } }, - Responses = new OpenApiResponses + Responses = new() { - ["200"] = new OpenApiResponse + ["200"] = new() { Description = "pet response", Content = new Dictionary { - ["application/json"] = new OpenApiMediaType + ["application/json"] = new() { - Schema = new OpenApiSchema + Schema = new() { Type = "array", Items = PetSchemaWithReference } }, - ["application/xml"] = new OpenApiMediaType + ["application/xml"] = new() { - Schema = new OpenApiSchema + Schema = new() { Type = "array", Items = PetSchemaWithReference @@ -316,23 +314,23 @@ public class OpenApiDocumentTests } } }, - ["4XX"] = new OpenApiResponse + ["4XX"] = new() { Description = "unexpected client error", Content = new Dictionary { - ["text/html"] = new OpenApiMediaType + ["text/html"] = new() { Schema = ErrorModelSchemaWithReference } } }, - ["5XX"] = new OpenApiResponse + ["5XX"] = new() { Description = "unexpected server error", Content = new Dictionary { - ["text/html"] = new OpenApiMediaType + ["text/html"] = new() { Schema = ErrorModelSchemaWithReference } @@ -340,52 +338,52 @@ public class OpenApiDocumentTests } } }, - [OperationType.Post] = new OpenApiOperation + [OperationType.Post] = new() { Description = "Creates a new pet in the store. Duplicates are allowed", OperationId = "addPet", - RequestBody = new OpenApiRequestBody + RequestBody = new() { Description = "Pet to add to the store", Required = true, Content = new Dictionary { - ["application/json"] = new OpenApiMediaType + ["application/json"] = new() { Schema = NewPetSchemaWithReference } } }, - Responses = new OpenApiResponses + Responses = new() { - ["200"] = new OpenApiResponse + ["200"] = new() { Description = "pet response", Content = new Dictionary { - ["application/json"] = new OpenApiMediaType + ["application/json"] = new() { Schema = PetSchemaWithReference }, } }, - ["4XX"] = new OpenApiResponse + ["4XX"] = new() { Description = "unexpected client error", Content = new Dictionary { - ["text/html"] = new OpenApiMediaType + ["text/html"] = new() { Schema = ErrorModelSchemaWithReference } } }, - ["5XX"] = new OpenApiResponse + ["5XX"] = new() { Description = "unexpected server error", Content = new Dictionary { - ["text/html"] = new OpenApiMediaType + ["text/html"] = new() { Schema = ErrorModelSchemaWithReference } @@ -395,64 +393,64 @@ public class OpenApiDocumentTests } } }, - ["/pets/{id}"] = new OpenApiPathItem + ["/pets/{id}"] = new() { Operations = new Dictionary { - [OperationType.Get] = new OpenApiOperation + [OperationType.Get] = new() { Description = "Returns a user based on a single ID, if the user does not have access to the pet", OperationId = "findPetById", Parameters = new List { - new OpenApiParameter + new() { Name = "id", In = ParameterLocation.Path, Description = "ID of pet to fetch", Required = true, - Schema = new OpenApiSchema + Schema = new() { Type = "integer", Format = "int64" } } }, - Responses = new OpenApiResponses + Responses = new() { - ["200"] = new OpenApiResponse + ["200"] = new() { Description = "pet response", Content = new Dictionary { - ["application/json"] = new OpenApiMediaType + ["application/json"] = new() { Schema = PetSchemaWithReference }, - ["application/xml"] = new OpenApiMediaType + ["application/xml"] = new() { Schema = PetSchemaWithReference } } }, - ["4XX"] = new OpenApiResponse + ["4XX"] = new() { Description = "unexpected client error", Content = new Dictionary { - ["text/html"] = new OpenApiMediaType + ["text/html"] = new() { Schema = ErrorModelSchemaWithReference } } }, - ["5XX"] = new OpenApiResponse + ["5XX"] = new() { Description = "unexpected server error", Content = new Dictionary { - ["text/html"] = new OpenApiMediaType + ["text/html"] = new() { Schema = ErrorModelSchemaWithReference } @@ -460,48 +458,48 @@ public class OpenApiDocumentTests } } }, - [OperationType.Delete] = new OpenApiOperation + [OperationType.Delete] = new() { Description = "deletes a single pet based on the ID supplied", OperationId = "deletePet", Parameters = new List { - new OpenApiParameter + new() { Name = "id", In = ParameterLocation.Path, Description = "ID of pet to delete", Required = true, - Schema = new OpenApiSchema + Schema = new() { Type = "integer", Format = "int64" } } }, - Responses = new OpenApiResponses + Responses = new() { - ["204"] = new OpenApiResponse + ["204"] = new() { Description = "pet deleted" }, - ["4XX"] = new OpenApiResponse + ["4XX"] = new() { Description = "unexpected client error", Content = new Dictionary { - ["text/html"] = new OpenApiMediaType + ["text/html"] = new() { Schema = ErrorModelSchemaWithReference } } }, - ["5XX"] = new OpenApiResponse + ["5XX"] = new() { Description = "unexpected server error", Content = new Dictionary { - ["text/html"] = new OpenApiMediaType + ["text/html"] = new() { Schema = ErrorModelSchemaWithReference } @@ -515,11 +513,11 @@ public class OpenApiDocumentTests Components = AdvancedComponentsWithReference }; - public static OpenApiComponents AdvancedComponents = new OpenApiComponents + public static OpenApiComponents AdvancedComponents = new() { Schemas = new Dictionary { - ["pet"] = new OpenApiSchema + ["pet"] = new() { Type = "object", Required = new HashSet @@ -529,22 +527,22 @@ public class OpenApiDocumentTests }, Properties = new Dictionary { - ["id"] = new OpenApiSchema + ["id"] = new() { Type = "integer", Format = "int64" }, - ["name"] = new OpenApiSchema + ["name"] = new() { Type = "string" }, - ["tag"] = new OpenApiSchema + ["tag"] = new() { Type = "string" }, } }, - ["newPet"] = new OpenApiSchema + ["newPet"] = new() { Type = "object", Required = new HashSet @@ -553,22 +551,22 @@ public class OpenApiDocumentTests }, Properties = new Dictionary { - ["id"] = new OpenApiSchema + ["id"] = new() { Type = "integer", Format = "int64" }, - ["name"] = new OpenApiSchema + ["name"] = new() { Type = "string" }, - ["tag"] = new OpenApiSchema + ["tag"] = new() { Type = "string" }, } }, - ["errorModel"] = new OpenApiSchema + ["errorModel"] = new() { Type = "object", Required = new HashSet @@ -578,12 +576,12 @@ public class OpenApiDocumentTests }, Properties = new Dictionary { - ["code"] = new OpenApiSchema + ["code"] = new() { Type = "integer", Format = "int32" }, - ["message"] = new OpenApiSchema + ["message"] = new() { Type = "string" } @@ -598,92 +596,92 @@ public class OpenApiDocumentTests public static OpenApiSchema ErrorModelSchema = AdvancedComponents.Schemas["errorModel"]; - public OpenApiDocument AdvancedDocument = new OpenApiDocument + public OpenApiDocument AdvancedDocument = new() { - Info = new OpenApiInfo + Info = new() { Version = "1.0.0", Title = "Swagger Petstore (Simple)", Description = "A sample API that uses a petstore as an example to demonstrate features in the swagger-2.0 specification", - TermsOfService = new Uri("http://helloreverb.com/terms/"), - Contact = new OpenApiContact + TermsOfService = new("http://helloreverb.com/terms/"), + Contact = new() { Name = "Swagger API team", Email = "foo@example.com", - Url = new Uri("http://swagger.io") + Url = new("http://swagger.io") }, - License = new OpenApiLicense + License = new() { Name = "MIT", - Url = new Uri("http://opensource.org/licenses/MIT") + Url = new("http://opensource.org/licenses/MIT") } }, Servers = new List { - new OpenApiServer + new() { Url = "http://petstore.swagger.io/api" } }, - Paths = new OpenApiPaths + Paths = new() { - ["/pets"] = new OpenApiPathItem + ["/pets"] = new() { Operations = new Dictionary { - [OperationType.Get] = new OpenApiOperation + [OperationType.Get] = new() { Description = "Returns all pets from the system that the user has access to", OperationId = "findPets", Parameters = new List { - new OpenApiParameter + new() { Name = "tags", In = ParameterLocation.Query, Description = "tags to filter by", Required = false, - Schema = new OpenApiSchema + Schema = new() { Type = "array", - Items = new OpenApiSchema + Items = new() { Type = "string" } } }, - new OpenApiParameter + new() { Name = "limit", In = ParameterLocation.Query, Description = "maximum number of results to return", Required = false, - Schema = new OpenApiSchema + Schema = new() { Type = "integer", Format = "int32" } } }, - Responses = new OpenApiResponses + Responses = new() { - ["200"] = new OpenApiResponse + ["200"] = new() { Description = "pet response", Content = new Dictionary { - ["application/json"] = new OpenApiMediaType + ["application/json"] = new() { - Schema = new OpenApiSchema + Schema = new() { Type = "array", Items = PetSchema } }, - ["application/xml"] = new OpenApiMediaType + ["application/xml"] = new() { - Schema = new OpenApiSchema + Schema = new() { Type = "array", Items = PetSchema @@ -691,23 +689,23 @@ public class OpenApiDocumentTests } } }, - ["4XX"] = new OpenApiResponse + ["4XX"] = new() { Description = "unexpected client error", Content = new Dictionary { - ["text/html"] = new OpenApiMediaType + ["text/html"] = new() { Schema = ErrorModelSchema } } }, - ["5XX"] = new OpenApiResponse + ["5XX"] = new() { Description = "unexpected server error", Content = new Dictionary { - ["text/html"] = new OpenApiMediaType + ["text/html"] = new() { Schema = ErrorModelSchema } @@ -715,52 +713,52 @@ public class OpenApiDocumentTests } } }, - [OperationType.Post] = new OpenApiOperation + [OperationType.Post] = new() { Description = "Creates a new pet in the store. Duplicates are allowed", OperationId = "addPet", - RequestBody = new OpenApiRequestBody + RequestBody = new() { Description = "Pet to add to the store", Required = true, Content = new Dictionary { - ["application/json"] = new OpenApiMediaType + ["application/json"] = new() { Schema = NewPetSchema } } }, - Responses = new OpenApiResponses + Responses = new() { - ["200"] = new OpenApiResponse + ["200"] = new() { Description = "pet response", Content = new Dictionary { - ["application/json"] = new OpenApiMediaType + ["application/json"] = new() { Schema = PetSchema }, } }, - ["4XX"] = new OpenApiResponse + ["4XX"] = new() { Description = "unexpected client error", Content = new Dictionary { - ["text/html"] = new OpenApiMediaType + ["text/html"] = new() { Schema = ErrorModelSchema } } }, - ["5XX"] = new OpenApiResponse + ["5XX"] = new() { Description = "unexpected server error", Content = new Dictionary { - ["text/html"] = new OpenApiMediaType + ["text/html"] = new() { Schema = ErrorModelSchema } @@ -770,64 +768,64 @@ public class OpenApiDocumentTests } } }, - ["/pets/{id}"] = new OpenApiPathItem + ["/pets/{id}"] = new() { Operations = new Dictionary { - [OperationType.Get] = new OpenApiOperation + [OperationType.Get] = new() { Description = "Returns a user based on a single ID, if the user does not have access to the pet", OperationId = "findPetById", Parameters = new List { - new OpenApiParameter + new() { Name = "id", In = ParameterLocation.Path, Description = "ID of pet to fetch", Required = true, - Schema = new OpenApiSchema + Schema = new() { Type = "integer", Format = "int64" } } }, - Responses = new OpenApiResponses + Responses = new() { - ["200"] = new OpenApiResponse + ["200"] = new() { Description = "pet response", Content = new Dictionary { - ["application/json"] = new OpenApiMediaType + ["application/json"] = new() { Schema = PetSchema }, - ["application/xml"] = new OpenApiMediaType + ["application/xml"] = new() { Schema = PetSchema } } }, - ["4XX"] = new OpenApiResponse + ["4XX"] = new() { Description = "unexpected client error", Content = new Dictionary { - ["text/html"] = new OpenApiMediaType + ["text/html"] = new() { Schema = ErrorModelSchema } } }, - ["5XX"] = new OpenApiResponse + ["5XX"] = new() { Description = "unexpected server error", Content = new Dictionary { - ["text/html"] = new OpenApiMediaType + ["text/html"] = new() { Schema = ErrorModelSchema } @@ -835,48 +833,48 @@ public class OpenApiDocumentTests } } }, - [OperationType.Delete] = new OpenApiOperation + [OperationType.Delete] = new() { Description = "deletes a single pet based on the ID supplied", OperationId = "deletePet", Parameters = new List { - new OpenApiParameter + new() { Name = "id", In = ParameterLocation.Path, Description = "ID of pet to delete", Required = true, - Schema = new OpenApiSchema + Schema = new() { Type = "integer", Format = "int64" } } }, - Responses = new OpenApiResponses + Responses = new() { - ["204"] = new OpenApiResponse + ["204"] = new() { Description = "pet deleted" }, - ["4XX"] = new OpenApiResponse + ["4XX"] = new() { Description = "unexpected client error", Content = new Dictionary { - ["text/html"] = new OpenApiMediaType + ["text/html"] = new() { Schema = ErrorModelSchema } } }, - ["5XX"] = new OpenApiResponse + ["5XX"] = new() { Description = "unexpected server error", Content = new Dictionary { - ["text/html"] = new OpenApiMediaType + ["text/html"] = new() { Schema = ErrorModelSchema } @@ -890,9 +888,9 @@ public class OpenApiDocumentTests Components = AdvancedComponents }; - public static OpenApiDocument DuplicateExtensions = new OpenApiDocument + public static OpenApiDocument DuplicateExtensions = new() { - Info = new OpenApiInfo + Info = new() { Version = "1.0.0", Title = "Swagger Petstore (Simple)", @@ -900,29 +898,29 @@ public class OpenApiDocumentTests }, Servers = new List { - new OpenApiServer + new() { Url = "http://petstore.swagger.io/api" } }, - Paths = new OpenApiPaths + Paths = new() { - ["/add/{operand1}/{operand2}"] = new OpenApiPathItem + ["/add/{operand1}/{operand2}"] = new() { Operations = new Dictionary { - [OperationType.Get] = new OpenApiOperation + [OperationType.Get] = new() { OperationId = "addByOperand1AndByOperand2", Parameters = new List { - new OpenApiParameter + new() { Name = "operand1", In = ParameterLocation.Path, Description = "The first operand", Required = true, - Schema = new OpenApiSchema + Schema = new() { Type = "integer", Extensions = new Dictionary @@ -935,13 +933,13 @@ public class OpenApiDocumentTests ["my-extension"] = new Any.OpenApiInteger(4), } }, - new OpenApiParameter + new() { Name = "operand2", In = ParameterLocation.Path, Description = "The second operand", Required = true, - Schema = new OpenApiSchema + Schema = new() { Type = "integer", Extensions = new Dictionary @@ -955,16 +953,16 @@ public class OpenApiDocumentTests } }, }, - Responses = new OpenApiResponses + Responses = new() { - ["200"] = new OpenApiResponse + ["200"] = new() { Description = "pet response", Content = new Dictionary { - ["application/json"] = new OpenApiMediaType + ["application/json"] = new() { - Schema = new OpenApiSchema + Schema = new() { Type = "array", Items = PetSchema @@ -979,99 +977,99 @@ public class OpenApiDocumentTests } }; - public OpenApiDocument AdvancedDocumentWithServerVariable = new OpenApiDocument + public OpenApiDocument AdvancedDocumentWithServerVariable = new() { - Info = new OpenApiInfo + Info = new() { Version = "1.0.0", Title = "Swagger Petstore (Simple)", Description = "A sample API that uses a petstore as an example to demonstrate features in the swagger-2.0 specification", - TermsOfService = new Uri("http://helloreverb.com/terms/"), - Contact = new OpenApiContact + TermsOfService = new("http://helloreverb.com/terms/"), + Contact = new() { Name = "Swagger API team", Email = "foo@example.com", - Url = new Uri("http://swagger.io") + Url = new("http://swagger.io") }, - License = new OpenApiLicense + License = new() { Name = "MIT", - Url = new Uri("http://opensource.org/licenses/MIT") + Url = new("http://opensource.org/licenses/MIT") } }, Servers = new List { - new OpenApiServer + new() { Url = "https://{endpoint}/openai", Variables = new Dictionary { - ["endpoint"] = new OpenApiServerVariable + ["endpoint"] = new() { Default = "your-resource-name.openai.azure.com" } } } }, - Paths = new OpenApiPaths + Paths = new() { - ["/pets"] = new OpenApiPathItem + ["/pets"] = new() { Operations = new Dictionary { - [OperationType.Get] = new OpenApiOperation + [OperationType.Get] = new() { Description = "Returns all pets from the system that the user has access to", OperationId = "findPets", Parameters = new List { - new OpenApiParameter + new() { Name = "tags", In = ParameterLocation.Query, Description = "tags to filter by", Required = false, - Schema = new OpenApiSchema + Schema = new() { Type = "array", - Items = new OpenApiSchema + Items = new() { Type = "string" } } }, - new OpenApiParameter + new() { Name = "limit", In = ParameterLocation.Query, Description = "maximum number of results to return", Required = false, - Schema = new OpenApiSchema + Schema = new() { Type = "integer", Format = "int32" } } }, - Responses = new OpenApiResponses + Responses = new() { - ["200"] = new OpenApiResponse + ["200"] = new() { Description = "pet response", Content = new Dictionary { - ["application/json"] = new OpenApiMediaType + ["application/json"] = new() { - Schema = new OpenApiSchema + Schema = new() { Type = "array", Items = PetSchema } }, - ["application/xml"] = new OpenApiMediaType + ["application/xml"] = new() { - Schema = new OpenApiSchema + Schema = new() { Type = "array", Items = PetSchema @@ -1079,23 +1077,23 @@ public class OpenApiDocumentTests } } }, - ["4XX"] = new OpenApiResponse + ["4XX"] = new() { Description = "unexpected client error", Content = new Dictionary { - ["text/html"] = new OpenApiMediaType + ["text/html"] = new() { Schema = ErrorModelSchema } } }, - ["5XX"] = new OpenApiResponse + ["5XX"] = new() { Description = "unexpected server error", Content = new Dictionary { - ["text/html"] = new OpenApiMediaType + ["text/html"] = new() { Schema = ErrorModelSchema } @@ -1103,52 +1101,52 @@ public class OpenApiDocumentTests } } }, - [OperationType.Post] = new OpenApiOperation + [OperationType.Post] = new() { Description = "Creates a new pet in the store. Duplicates are allowed", OperationId = "addPet", - RequestBody = new OpenApiRequestBody + RequestBody = new() { Description = "Pet to add to the store", Required = true, Content = new Dictionary { - ["application/json"] = new OpenApiMediaType + ["application/json"] = new() { Schema = NewPetSchema } } }, - Responses = new OpenApiResponses + Responses = new() { - ["200"] = new OpenApiResponse + ["200"] = new() { Description = "pet response", Content = new Dictionary { - ["application/json"] = new OpenApiMediaType + ["application/json"] = new() { Schema = PetSchema }, } }, - ["4XX"] = new OpenApiResponse + ["4XX"] = new() { Description = "unexpected client error", Content = new Dictionary { - ["text/html"] = new OpenApiMediaType + ["text/html"] = new() { Schema = ErrorModelSchema } } }, - ["5XX"] = new OpenApiResponse + ["5XX"] = new() { Description = "unexpected server error", Content = new Dictionary { - ["text/html"] = new OpenApiMediaType + ["text/html"] = new() { Schema = ErrorModelSchema } @@ -1158,64 +1156,64 @@ public class OpenApiDocumentTests } } }, - ["/pets/{id}"] = new OpenApiPathItem + ["/pets/{id}"] = new() { Operations = new Dictionary { - [OperationType.Get] = new OpenApiOperation + [OperationType.Get] = new() { Description = "Returns a user based on a single ID, if the user does not have access to the pet", OperationId = "findPetById", Parameters = new List { - new OpenApiParameter + new() { Name = "id", In = ParameterLocation.Path, Description = "ID of pet to fetch", Required = true, - Schema = new OpenApiSchema + Schema = new() { Type = "integer", Format = "int64" } } }, - Responses = new OpenApiResponses + Responses = new() { - ["200"] = new OpenApiResponse + ["200"] = new() { Description = "pet response", Content = new Dictionary { - ["application/json"] = new OpenApiMediaType + ["application/json"] = new() { Schema = PetSchema }, - ["application/xml"] = new OpenApiMediaType + ["application/xml"] = new() { Schema = PetSchema } } }, - ["4XX"] = new OpenApiResponse + ["4XX"] = new() { Description = "unexpected client error", Content = new Dictionary { - ["text/html"] = new OpenApiMediaType + ["text/html"] = new() { Schema = ErrorModelSchema } } }, - ["5XX"] = new OpenApiResponse + ["5XX"] = new() { Description = "unexpected server error", Content = new Dictionary { - ["text/html"] = new OpenApiMediaType + ["text/html"] = new() { Schema = ErrorModelSchema } @@ -1223,48 +1221,48 @@ public class OpenApiDocumentTests } } }, - [OperationType.Delete] = new OpenApiOperation + [OperationType.Delete] = new() { Description = "deletes a single pet based on the ID supplied", OperationId = "deletePet", Parameters = new List { - new OpenApiParameter + new() { Name = "id", In = ParameterLocation.Path, Description = "ID of pet to delete", Required = true, - Schema = new OpenApiSchema + Schema = new() { Type = "integer", Format = "int64" } } }, - Responses = new OpenApiResponses + Responses = new() { - ["204"] = new OpenApiResponse + ["204"] = new() { Description = "pet deleted" }, - ["4XX"] = new OpenApiResponse + ["4XX"] = new() { Description = "unexpected client error", Content = new Dictionary { - ["text/html"] = new OpenApiMediaType + ["text/html"] = new() { Schema = ErrorModelSchema } } }, - ["5XX"] = new OpenApiResponse + ["5XX"] = new() { Description = "unexpected server error", Content = new Dictionary { - ["text/html"] = new OpenApiMediaType + ["text/html"] = new() { Schema = ErrorModelSchema } @@ -1285,7 +1283,7 @@ public async Task SerializeAdvancedDocumentAsV3JsonWorks(bool produceTerseOutput { // Arrange var outputStringWriter = new StringWriter(CultureInfo.InvariantCulture); - var writer = new OpenApiJsonWriter(outputStringWriter, new OpenApiJsonWriterSettings { Terse = produceTerseOutput }); + var writer = new OpenApiJsonWriter(outputStringWriter, new() { Terse = produceTerseOutput }); // Act AdvancedDocument.SerializeAsV3(writer); @@ -1302,7 +1300,7 @@ public async Task SerializeAdvancedDocumentWithReferenceAsV3JsonWorks(bool produ { // Arrange var outputStringWriter = new StringWriter(CultureInfo.InvariantCulture); - var writer = new OpenApiJsonWriter(outputStringWriter, new OpenApiJsonWriterSettings { Terse = produceTerseOutput }); + var writer = new OpenApiJsonWriter(outputStringWriter, new() { Terse = produceTerseOutput }); // Act AdvancedDocumentWithReference.SerializeAsV3(writer); @@ -1319,7 +1317,7 @@ public async Task SerializeAdvancedDocumentWithServerVariableAsV2JsonWorks(bool { // Arrange var outputStringWriter = new StringWriter(CultureInfo.InvariantCulture); - var writer = new OpenApiJsonWriter(outputStringWriter, new OpenApiJsonWriterSettings { Terse = produceTerseOutput }); + var writer = new OpenApiJsonWriter(outputStringWriter, new() { Terse = produceTerseOutput }); // Act AdvancedDocumentWithServerVariable.SerializeAsV2(writer); @@ -1336,7 +1334,7 @@ public async Task SerializeAdvancedDocumentAsV2JsonWorks(bool produceTerseOutput { // Arrange var outputStringWriter = new StringWriter(CultureInfo.InvariantCulture); - var writer = new OpenApiJsonWriter(outputStringWriter, new OpenApiJsonWriterSettings { Terse = produceTerseOutput }); + var writer = new OpenApiJsonWriter(outputStringWriter, new() { Terse = produceTerseOutput }); // Act AdvancedDocument.SerializeAsV2(writer); @@ -1353,7 +1351,7 @@ public async Task SerializeDuplicateExtensionsAsV3JsonWorks(bool produceTerseOut { // Arrange var outputStringWriter = new StringWriter(CultureInfo.InvariantCulture); - var writer = new OpenApiJsonWriter(outputStringWriter, new OpenApiJsonWriterSettings { Terse = produceTerseOutput }); + var writer = new OpenApiJsonWriter(outputStringWriter, new() { Terse = produceTerseOutput }); // Act DuplicateExtensions.SerializeAsV3(writer); @@ -1370,7 +1368,7 @@ public async Task SerializeDuplicateExtensionsAsV2JsonWorks(bool produceTerseOut { // Arrange var outputStringWriter = new StringWriter(CultureInfo.InvariantCulture); - var writer = new OpenApiJsonWriter(outputStringWriter, new OpenApiJsonWriterSettings { Terse = produceTerseOutput }); + var writer = new OpenApiJsonWriter(outputStringWriter, new() { Terse = produceTerseOutput }); // Act DuplicateExtensions.SerializeAsV2(writer); @@ -1387,7 +1385,7 @@ public async Task SerializeAdvancedDocumentWithReferenceAsV2JsonWorks(bool produ { // Arrange var outputStringWriter = new StringWriter(CultureInfo.InvariantCulture); - var writer = new OpenApiJsonWriter(outputStringWriter, new OpenApiJsonWriterSettings { Terse = produceTerseOutput }); + var writer = new OpenApiJsonWriter(outputStringWriter, new() { Terse = produceTerseOutput }); // Act AdvancedDocumentWithReference.SerializeAsV2(writer); @@ -1487,30 +1485,30 @@ public void SerializeDocumentWithReferenceButNoComponents() // Arrange var document = new OpenApiDocument { - Info = new OpenApiInfo + Info = new() { Title = "Test", Version = "1.0.0" }, - Paths = new OpenApiPaths + Paths = new() { - ["/"] = new OpenApiPathItem + ["/"] = new() { Operations = new Dictionary { - [OperationType.Get] = new OpenApiOperation + [OperationType.Get] = new() { - Responses = new OpenApiResponses + Responses = new() { - ["200"] = new OpenApiResponse + ["200"] = new() { Content = new Dictionary { - ["application/json"] = new OpenApiMediaType + ["application/json"] = new() { - Schema = new OpenApiSchema + Schema = new() { - Reference = new OpenApiReference + Reference = new() { Id = "test", Type = ReferenceType.Schema @@ -1549,10 +1547,10 @@ public void SerializeRelativePathAsV2JsonWorks() """; var doc = new OpenApiDocument { - Info = new OpenApiInfo { Version = "1.0.0" }, + Info = new() { Version = "1.0.0" }, Servers = new List { - new OpenApiServer + new() { Url = "/server1" } @@ -1583,10 +1581,10 @@ public void SerializeRelativePathWithHostAsV2JsonWorks() """; var doc = new OpenApiDocument { - Info = new OpenApiInfo { Version = "1.0.0" }, + Info = new() { Version = "1.0.0" }, Servers = new List { - new OpenApiServer + new() { Url = "//example.org/server1" } @@ -1616,10 +1614,10 @@ public void SerializeRelativeRootPathWithHostAsV2JsonWorks() """; var doc = new OpenApiDocument { - Info = new OpenApiInfo { Version = "1.0.0" }, + Info = new() { Version = "1.0.0" }, Servers = new List { - new OpenApiServer + new() { Url = "//example.org/" } @@ -1703,27 +1701,27 @@ public void SerializeV2DocumentWithNonArraySchemaTypeDoesNotWriteOutCollectionFo var doc = new OpenApiDocument { - Info = new OpenApiInfo(), - Paths = new OpenApiPaths + Info = new(), + Paths = new() { - ["/foo"] = new OpenApiPathItem + ["/foo"] = new() { Operations = new Dictionary { - [OperationType.Get] = new OpenApiOperation + [OperationType.Get] = new() { Parameters = new List { - new OpenApiParameter + new() { In = ParameterLocation.Query, - Schema = new OpenApiSchema + Schema = new() { Type = "string" } } }, - Responses = new OpenApiResponses() + Responses = new() } } } @@ -1770,45 +1768,45 @@ public void SerializeV2DocumentWithStyleAsNullDoesNotWriteOutStyleValue() var doc = new OpenApiDocument { - Info = new OpenApiInfo + Info = new() { Title = "magic style", Version = "1.0.0" }, - Paths = new OpenApiPaths + Paths = new() { - ["/foo"] = new OpenApiPathItem + ["/foo"] = new() { Operations = new Dictionary { - [OperationType.Get] = new OpenApiOperation + [OperationType.Get] = new() { Parameters = new List { - new OpenApiParameter + new() { Name = "id", In = ParameterLocation.Query, - Schema = new OpenApiSchema + Schema = new() { Type = "object", - AdditionalProperties = new OpenApiSchema + AdditionalProperties = new() { Type = "integer" } } } }, - Responses = new OpenApiResponses + Responses = new() { - ["200"] = new OpenApiResponse + ["200"] = new() { Description = "foo", Content = new Dictionary { - ["text/plain"] = new OpenApiMediaType + ["text/plain"] = new() { - Schema = new OpenApiSchema + Schema = new() { Type = "string" } diff --git a/test/Microsoft.OpenApi.Tests/Models/OpenApiEncodingTests.cs b/test/Microsoft.OpenApi.Tests/Models/OpenApiEncodingTests.cs index bf0561367..fe699f7aa 100644 --- a/test/Microsoft.OpenApi.Tests/Models/OpenApiEncodingTests.cs +++ b/test/Microsoft.OpenApi.Tests/Models/OpenApiEncodingTests.cs @@ -11,9 +11,9 @@ namespace Microsoft.OpenApi.Tests.Models [Collection("DefaultSettings")] public class OpenApiEncodingTests { - public static OpenApiEncoding BasicEncoding = new OpenApiEncoding(); + public static OpenApiEncoding BasicEncoding = new(); - public static OpenApiEncoding AdvanceEncoding = new OpenApiEncoding + public static OpenApiEncoding AdvanceEncoding = new() { ContentType = "image/png, image/jpeg", Style = ParameterStyle.Simple, diff --git a/test/Microsoft.OpenApi.Tests/Models/OpenApiExampleTests.cs b/test/Microsoft.OpenApi.Tests/Models/OpenApiExampleTests.cs index b725f99a6..14561debd 100644 --- a/test/Microsoft.OpenApi.Tests/Models/OpenApiExampleTests.cs +++ b/test/Microsoft.OpenApi.Tests/Models/OpenApiExampleTests.cs @@ -18,7 +18,7 @@ namespace Microsoft.OpenApi.Tests.Models [UsesVerify] public class OpenApiExampleTests { - public static OpenApiExample AdvancedExample = new OpenApiExample + public static OpenApiExample AdvancedExample = new() { Value = new OpenApiObject { @@ -57,9 +57,9 @@ public class OpenApiExampleTests } }; - public static OpenApiExample ReferencedExample = new OpenApiExample + public static OpenApiExample ReferencedExample = new() { - Reference = new OpenApiReference + Reference = new() { Type = ReferenceType.Example, Id = "example1", @@ -107,7 +107,7 @@ public async Task SerializeAdvancedExampleAsV3JsonWorks(bool produceTerseOutput) { // Arrange var outputStringWriter = new StringWriter(CultureInfo.InvariantCulture); - var writer = new OpenApiJsonWriter(outputStringWriter, new OpenApiJsonWriterSettings { Terse = produceTerseOutput }); + var writer = new OpenApiJsonWriter(outputStringWriter, new() { Terse = produceTerseOutput }); // Act AdvancedExample.SerializeAsV3(writer); @@ -124,7 +124,7 @@ public async Task SerializeReferencedExampleAsV3JsonWorks(bool produceTerseOutpu { // Arrange var outputStringWriter = new StringWriter(CultureInfo.InvariantCulture); - var writer = new OpenApiJsonWriter(outputStringWriter, new OpenApiJsonWriterSettings { Terse = produceTerseOutput }); + var writer = new OpenApiJsonWriter(outputStringWriter, new() { Terse = produceTerseOutput }); // Act ReferencedExample.SerializeAsV3(writer); @@ -141,7 +141,7 @@ public async Task SerializeReferencedExampleAsV3JsonWithoutReferenceWorks(bool p { // Arrange var outputStringWriter = new StringWriter(CultureInfo.InvariantCulture); - var writer = new OpenApiJsonWriter(outputStringWriter, new OpenApiJsonWriterSettings { Terse = produceTerseOutput }); + var writer = new OpenApiJsonWriter(outputStringWriter, new() { Terse = produceTerseOutput }); // Act ReferencedExample.SerializeAsV3WithoutReference(writer); diff --git a/test/Microsoft.OpenApi.Tests/Models/OpenApiExternalDocsTests.cs b/test/Microsoft.OpenApi.Tests/Models/OpenApiExternalDocsTests.cs index 52a916d58..25bf6315d 100644 --- a/test/Microsoft.OpenApi.Tests/Models/OpenApiExternalDocsTests.cs +++ b/test/Microsoft.OpenApi.Tests/Models/OpenApiExternalDocsTests.cs @@ -1,7 +1,6 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. -using System; using FluentAssertions; using Microsoft.OpenApi.Extensions; using Microsoft.OpenApi.Models; @@ -12,11 +11,11 @@ namespace Microsoft.OpenApi.Tests.Models [Collection("DefaultSettings")] public class OpenApiExternalDocsTests { - public static OpenApiExternalDocs BasicExDocs = new OpenApiExternalDocs(); + public static OpenApiExternalDocs BasicExDocs = new(); - public static OpenApiExternalDocs AdvanceExDocs = new OpenApiExternalDocs + public static OpenApiExternalDocs AdvanceExDocs = new() { - Url = new Uri("https://example.com"), + Url = new("https://example.com"), Description = "Find more info here" }; diff --git a/test/Microsoft.OpenApi.Tests/Models/OpenApiHeaderTests.cs b/test/Microsoft.OpenApi.Tests/Models/OpenApiHeaderTests.cs index adc0848b5..b54c2457e 100644 --- a/test/Microsoft.OpenApi.Tests/Models/OpenApiHeaderTests.cs +++ b/test/Microsoft.OpenApi.Tests/Models/OpenApiHeaderTests.cs @@ -8,7 +8,6 @@ using Microsoft.OpenApi.Writers; using VerifyXunit; using Xunit; -using Xunit.Abstractions; namespace Microsoft.OpenApi.Tests.Models { @@ -16,25 +15,25 @@ namespace Microsoft.OpenApi.Tests.Models [UsesVerify] public class OpenApiHeaderTests { - public static OpenApiHeader AdvancedHeader = new OpenApiHeader + public static OpenApiHeader AdvancedHeader = new() { Description = "sampleHeader", - Schema = new OpenApiSchema + Schema = new() { Type = "integer", Format = "int32" } }; - public static OpenApiHeader ReferencedHeader = new OpenApiHeader + public static OpenApiHeader ReferencedHeader = new() { - Reference = new OpenApiReference + Reference = new() { Type = ReferenceType.Header, Id = "example1", }, Description = "sampleHeader", - Schema = new OpenApiSchema + Schema = new() { Type = "integer", Format = "int32" @@ -48,7 +47,7 @@ public async Task SerializeAdvancedHeaderAsV3JsonWorks(bool produceTerseOutput) { // Arrange var outputStringWriter = new StringWriter(CultureInfo.InvariantCulture); - var writer = new OpenApiJsonWriter(outputStringWriter, new OpenApiJsonWriterSettings { Terse = produceTerseOutput }); + var writer = new OpenApiJsonWriter(outputStringWriter, new() { Terse = produceTerseOutput }); // Act AdvancedHeader.SerializeAsV3(writer); @@ -65,7 +64,7 @@ public async Task SerializeReferencedHeaderAsV3JsonWorks(bool produceTerseOutput { // Arrange var outputStringWriter = new StringWriter(CultureInfo.InvariantCulture); - var writer = new OpenApiJsonWriter(outputStringWriter, new OpenApiJsonWriterSettings { Terse = produceTerseOutput }); + var writer = new OpenApiJsonWriter(outputStringWriter, new() { Terse = produceTerseOutput }); // Act ReferencedHeader.SerializeAsV3(writer); @@ -82,7 +81,7 @@ public async Task SerializeReferencedHeaderAsV3JsonWithoutReferenceWorks(bool pr { // Arrange var outputStringWriter = new StringWriter(CultureInfo.InvariantCulture); - var writer = new OpenApiJsonWriter(outputStringWriter, new OpenApiJsonWriterSettings { Terse = produceTerseOutput }); + var writer = new OpenApiJsonWriter(outputStringWriter, new() { Terse = produceTerseOutput }); // Act ReferencedHeader.SerializeAsV3WithoutReference(writer); @@ -100,7 +99,7 @@ public async Task SerializeAdvancedHeaderAsV2JsonWorks(bool produceTerseOutput) { // Arrange var outputStringWriter = new StringWriter(CultureInfo.InvariantCulture); - var writer = new OpenApiJsonWriter(outputStringWriter, new OpenApiJsonWriterSettings { Terse = produceTerseOutput }); + var writer = new OpenApiJsonWriter(outputStringWriter, new() { Terse = produceTerseOutput }); // Act AdvancedHeader.SerializeAsV2(writer); @@ -117,7 +116,7 @@ public async Task SerializeReferencedHeaderAsV2JsonWorks(bool produceTerseOutput { // Arrange var outputStringWriter = new StringWriter(CultureInfo.InvariantCulture); - var writer = new OpenApiJsonWriter(outputStringWriter, new OpenApiJsonWriterSettings { Terse = produceTerseOutput }); + var writer = new OpenApiJsonWriter(outputStringWriter, new() { Terse = produceTerseOutput }); // Act ReferencedHeader.SerializeAsV2(writer); @@ -134,7 +133,7 @@ public async Task SerializeReferencedHeaderAsV2JsonWithoutReferenceWorks(bool pr { // Arrange var outputStringWriter = new StringWriter(CultureInfo.InvariantCulture); - var writer = new OpenApiJsonWriter(outputStringWriter, new OpenApiJsonWriterSettings { Terse = produceTerseOutput }); + var writer = new OpenApiJsonWriter(outputStringWriter, new() { Terse = produceTerseOutput }); // Act ReferencedHeader.SerializeAsV2WithoutReference(writer); diff --git a/test/Microsoft.OpenApi.Tests/Models/OpenApiInfoTests.cs b/test/Microsoft.OpenApi.Tests/Models/OpenApiInfoTests.cs index dd744b079..aed69a7a8 100644 --- a/test/Microsoft.OpenApi.Tests/Models/OpenApiInfoTests.cs +++ b/test/Microsoft.OpenApi.Tests/Models/OpenApiInfoTests.cs @@ -1,7 +1,6 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. -using System; using System.Collections.Generic; using FluentAssertions; using Microsoft.OpenApi.Any; @@ -15,11 +14,11 @@ namespace Microsoft.OpenApi.Tests.Models [Collection("DefaultSettings")] public class OpenApiInfoTests { - public static OpenApiInfo AdvanceInfo = new OpenApiInfo + public static OpenApiInfo AdvanceInfo = new() { Title = "Sample Pet Store App", Description = "This is a sample server for a pet store.", - TermsOfService = new Uri("http://example.com/terms/"), + TermsOfService = new("http://example.com/terms/"), Contact = OpenApiContactTests.AdvanceContact, License = OpenApiLicenseTests.AdvanceLicense, Version = "1.1.1", @@ -29,7 +28,7 @@ public class OpenApiInfoTests } }; - public static OpenApiInfo BasicInfo = new OpenApiInfo + public static OpenApiInfo BasicInfo = new() { Title = "Sample Pet Store App", Version = "1.0" diff --git a/test/Microsoft.OpenApi.Tests/Models/OpenApiLicenseTests.cs b/test/Microsoft.OpenApi.Tests/Models/OpenApiLicenseTests.cs index 113ea8440..e5620427b 100644 --- a/test/Microsoft.OpenApi.Tests/Models/OpenApiLicenseTests.cs +++ b/test/Microsoft.OpenApi.Tests/Models/OpenApiLicenseTests.cs @@ -1,7 +1,6 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. -using System; using System.Collections.Generic; using FluentAssertions; using Microsoft.OpenApi.Any; @@ -15,15 +14,15 @@ namespace Microsoft.OpenApi.Tests.Models [Collection("DefaultSettings")] public class OpenApiLicenseTests { - public static OpenApiLicense BasicLicense = new OpenApiLicense + public static OpenApiLicense BasicLicense = new() { Name = "Apache 2.0" }; - public static OpenApiLicense AdvanceLicense = new OpenApiLicense + public static OpenApiLicense AdvanceLicense = new() { Name = "Apache 2.0", - Url = new Uri("http://www.apache.org/licenses/LICENSE-2.0.html"), + Url = new("http://www.apache.org/licenses/LICENSE-2.0.html"), Extensions = new Dictionary { {"x-copyright", new OpenApiString("Abc")} @@ -123,7 +122,7 @@ public void ShouldCopyFromOriginalObjectWithoutMutating() // Act licenseCopy.Name = ""; - licenseCopy.Url = new Uri("https://exampleCopy.com"); + licenseCopy.Url = new("https://exampleCopy.com"); // Assert Assert.NotEqual(AdvanceLicense.Name, licenseCopy.Name); diff --git a/test/Microsoft.OpenApi.Tests/Models/OpenApiLinkTests.cs b/test/Microsoft.OpenApi.Tests/Models/OpenApiLinkTests.cs index 3281c62b5..3f95fb9e3 100644 --- a/test/Microsoft.OpenApi.Tests/Models/OpenApiLinkTests.cs +++ b/test/Microsoft.OpenApi.Tests/Models/OpenApiLinkTests.cs @@ -17,17 +17,17 @@ namespace Microsoft.OpenApi.Tests.Models [UsesVerify] public class OpenApiLinkTests { - public static OpenApiLink AdvancedLink = new OpenApiLink + public static OpenApiLink AdvancedLink = new() { OperationId = "operationId1", Parameters = { - ["parameter1"] = new RuntimeExpressionAnyWrapper + ["parameter1"] = new() { Expression = RuntimeExpression.Build("$request.path.id") } }, - RequestBody = new RuntimeExpressionAnyWrapper + RequestBody = new() { Any = new OpenApiObject { @@ -35,15 +35,15 @@ public class OpenApiLinkTests } }, Description = "description1", - Server = new OpenApiServer + Server = new() { Description = "serverDescription1" } }; - public static OpenApiLink ReferencedLink = new OpenApiLink + public static OpenApiLink ReferencedLink = new() { - Reference = new OpenApiReference + Reference = new() { Type = ReferenceType.Link, Id = "example1", @@ -51,12 +51,12 @@ public class OpenApiLinkTests OperationId = "operationId1", Parameters = { - ["parameter1"] = new RuntimeExpressionAnyWrapper + ["parameter1"] = new() { Expression = RuntimeExpression.Build("$request.path.id") } }, - RequestBody = new RuntimeExpressionAnyWrapper + RequestBody = new() { Any = new OpenApiObject { @@ -64,7 +64,7 @@ public class OpenApiLinkTests } }, Description = "description1", - Server = new OpenApiServer + Server = new() { Description = "serverDescription1" } @@ -77,7 +77,7 @@ public async Task SerializeAdvancedLinkAsV3JsonWorksAsync(bool produceTerseOutpu { // Arrange var outputStringWriter = new StringWriter(CultureInfo.InvariantCulture); - var writer = new OpenApiJsonWriter(outputStringWriter, new OpenApiJsonWriterSettings { Terse = produceTerseOutput }); + var writer = new OpenApiJsonWriter(outputStringWriter, new() { Terse = produceTerseOutput }); // Act AdvancedLink.SerializeAsV3(writer); @@ -94,7 +94,7 @@ public async Task SerializeReferencedLinkAsV3JsonWorksAsync(bool produceTerseOut { // Arrange var outputStringWriter = new StringWriter(CultureInfo.InvariantCulture); - var writer = new OpenApiJsonWriter(outputStringWriter, new OpenApiJsonWriterSettings { Terse = produceTerseOutput }); + var writer = new OpenApiJsonWriter(outputStringWriter, new() { Terse = produceTerseOutput }); // Act ReferencedLink.SerializeAsV3(writer); @@ -111,7 +111,7 @@ public async Task SerializeReferencedLinkAsV3JsonWithoutReferenceWorksAsync(bool { // Arrange var outputStringWriter = new StringWriter(CultureInfo.InvariantCulture); - var writer = new OpenApiJsonWriter(outputStringWriter, new OpenApiJsonWriterSettings { Terse = produceTerseOutput }); + var writer = new OpenApiJsonWriter(outputStringWriter, new() { Terse = produceTerseOutput }); // Act ReferencedLink.SerializeAsV3WithoutReference(writer); diff --git a/test/Microsoft.OpenApi.Tests/Models/OpenApiMediaTypeTests.cs b/test/Microsoft.OpenApi.Tests/Models/OpenApiMediaTypeTests.cs index 9a4e62818..97addbb1e 100644 --- a/test/Microsoft.OpenApi.Tests/Models/OpenApiMediaTypeTests.cs +++ b/test/Microsoft.OpenApi.Tests/Models/OpenApiMediaTypeTests.cs @@ -14,9 +14,9 @@ namespace Microsoft.OpenApi.Tests.Models [Collection("DefaultSettings")] public class OpenApiMediaTypeTests { - public static OpenApiMediaType BasicMediaType = new OpenApiMediaType(); + public static OpenApiMediaType BasicMediaType = new(); - public static OpenApiMediaType AdvanceMediaType = new OpenApiMediaType + public static OpenApiMediaType AdvanceMediaType = new() { Example = new OpenApiInteger(42), Encoding = new Dictionary @@ -25,7 +25,7 @@ public class OpenApiMediaTypeTests } }; - public static OpenApiMediaType MediaTypeWithObjectExample = new OpenApiMediaType + public static OpenApiMediaType MediaTypeWithObjectExample = new() { Example = new OpenApiObject { @@ -66,7 +66,7 @@ public class OpenApiMediaTypeTests } }; - public static OpenApiMediaType MediaTypeWithXmlExample = new OpenApiMediaType + public static OpenApiMediaType MediaTypeWithXmlExample = new() { Example = new OpenApiString("123"), Encoding = new Dictionary @@ -75,10 +75,10 @@ public class OpenApiMediaTypeTests } }; - public static OpenApiMediaType MediaTypeWithObjectExamples = new OpenApiMediaType + public static OpenApiMediaType MediaTypeWithObjectExamples = new() { Examples = { - ["object1"] = new OpenApiExample + ["object1"] = new() { Value = new OpenApiObject { diff --git a/test/Microsoft.OpenApi.Tests/Models/OpenApiOAuthFlowTests.cs b/test/Microsoft.OpenApi.Tests/Models/OpenApiOAuthFlowTests.cs index 0237068a3..3327887c9 100644 --- a/test/Microsoft.OpenApi.Tests/Models/OpenApiOAuthFlowTests.cs +++ b/test/Microsoft.OpenApi.Tests/Models/OpenApiOAuthFlowTests.cs @@ -1,7 +1,6 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. -using System; using System.Collections.Generic; using FluentAssertions; using Microsoft.OpenApi.Extensions; @@ -13,11 +12,11 @@ namespace Microsoft.OpenApi.Tests.Models [Collection("DefaultSettings")] public class OpenApiOAuthFlowTests { - public static OpenApiOAuthFlow BasicOAuthFlow = new OpenApiOAuthFlow(); + public static OpenApiOAuthFlow BasicOAuthFlow = new(); - public static OpenApiOAuthFlow PartialOAuthFlow = new OpenApiOAuthFlow + public static OpenApiOAuthFlow PartialOAuthFlow = new() { - AuthorizationUrl = new Uri("http://example.com/authorization"), + AuthorizationUrl = new("http://example.com/authorization"), Scopes = new Dictionary { ["scopeName3"] = "description3", @@ -25,11 +24,11 @@ public class OpenApiOAuthFlowTests } }; - public static OpenApiOAuthFlow CompleteOAuthFlow = new OpenApiOAuthFlow + public static OpenApiOAuthFlow CompleteOAuthFlow = new() { - AuthorizationUrl = new Uri("http://example.com/authorization"), - TokenUrl = new Uri("http://example.com/token"), - RefreshUrl = new Uri("http://example.com/refresh"), + AuthorizationUrl = new("http://example.com/authorization"), + TokenUrl = new("http://example.com/token"), + RefreshUrl = new("http://example.com/refresh"), Scopes = new Dictionary { ["scopeName3"] = "description3", diff --git a/test/Microsoft.OpenApi.Tests/Models/OpenApiOAuthFlowsTests.cs b/test/Microsoft.OpenApi.Tests/Models/OpenApiOAuthFlowsTests.cs index d4b2364a7..1bb473a89 100644 --- a/test/Microsoft.OpenApi.Tests/Models/OpenApiOAuthFlowsTests.cs +++ b/test/Microsoft.OpenApi.Tests/Models/OpenApiOAuthFlowsTests.cs @@ -1,7 +1,6 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. -using System; using System.Collections.Generic; using FluentAssertions; using Microsoft.OpenApi.Extensions; @@ -13,13 +12,13 @@ namespace Microsoft.OpenApi.Tests.Models [Collection("DefaultSettings")] public class OpenApiOAuthFlowsTests { - public static OpenApiOAuthFlows BasicOAuthFlows = new OpenApiOAuthFlows(); + public static OpenApiOAuthFlows BasicOAuthFlows = new(); - public static OpenApiOAuthFlows OAuthFlowsWithSingleFlow = new OpenApiOAuthFlows + public static OpenApiOAuthFlows OAuthFlowsWithSingleFlow = new() { - Implicit = new OpenApiOAuthFlow + Implicit = new() { - AuthorizationUrl = new Uri("http://example.com/authorization"), + AuthorizationUrl = new("http://example.com/authorization"), Scopes = new Dictionary { ["scopeName1"] = "description1", @@ -28,21 +27,21 @@ public class OpenApiOAuthFlowsTests } }; - public static OpenApiOAuthFlows OAuthFlowsWithMultipleFlows = new OpenApiOAuthFlows + public static OpenApiOAuthFlows OAuthFlowsWithMultipleFlows = new() { - Implicit = new OpenApiOAuthFlow + Implicit = new() { - AuthorizationUrl = new Uri("http://example.com/authorization"), + AuthorizationUrl = new("http://example.com/authorization"), Scopes = new Dictionary { ["scopeName1"] = "description1", ["scopeName2"] = "description2" } }, - Password = new OpenApiOAuthFlow + Password = new() { - TokenUrl = new Uri("http://example.com/token"), - RefreshUrl = new Uri("http://example.com/refresh"), + TokenUrl = new("http://example.com/token"), + RefreshUrl = new("http://example.com/refresh"), Scopes = new Dictionary { ["scopeName3"] = "description3", diff --git a/test/Microsoft.OpenApi.Tests/Models/OpenApiOperationTests.cs b/test/Microsoft.OpenApi.Tests/Models/OpenApiOperationTests.cs index e871735f3..ec6ca8326 100644 --- a/test/Microsoft.OpenApi.Tests/Models/OpenApiOperationTests.cs +++ b/test/Microsoft.OpenApi.Tests/Models/OpenApiOperationTests.cs @@ -1,7 +1,6 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. -using System; using System.Collections.Generic; using FluentAssertions; using Microsoft.OpenApi.Extensions; @@ -13,40 +12,40 @@ namespace Microsoft.OpenApi.Tests.Models [Collection("DefaultSettings")] public class OpenApiOperationTests { - private static readonly OpenApiOperation _basicOperation = new OpenApiOperation(); + private static readonly OpenApiOperation _basicOperation = new(); - private static readonly OpenApiOperation _operationWithBody = new OpenApiOperation + private static readonly OpenApiOperation _operationWithBody = new() { Summary = "summary1", Description = "operationDescription", - ExternalDocs = new OpenApiExternalDocs + ExternalDocs = new() { Description = "externalDocsDescription", - Url = new Uri("http://external.com") + Url = new("http://external.com") }, OperationId = "operationId1", Parameters = new List { - new OpenApiParameter + new() { In = ParameterLocation.Path, Name = "parameter1", }, - new OpenApiParameter + new() { In = ParameterLocation.Header, Name = "parameter2" } }, - RequestBody = new OpenApiRequestBody + RequestBody = new() { Description = "description2", Required = true, Content = new Dictionary { - ["application/json"] = new OpenApiMediaType + ["application/json"] = new() { - Schema = new OpenApiSchema + Schema = new() { Type = "number", Minimum = 5, @@ -55,23 +54,23 @@ public class OpenApiOperationTests } } }, - Responses = new OpenApiResponses + Responses = new() { - ["200"] = new OpenApiResponse + ["200"] = new() { - Reference = new OpenApiReference + Reference = new() { Id = "response1", Type = ReferenceType.Response } }, - ["400"] = new OpenApiResponse + ["400"] = new() { Content = new Dictionary { - ["application/json"] = new OpenApiMediaType + ["application/json"] = new() { - Schema = new OpenApiSchema + Schema = new() { Type = "number", Minimum = 5, @@ -83,7 +82,7 @@ public class OpenApiOperationTests }, Servers = new List { - new OpenApiServer + new() { Url = "http://server.com", Description = "serverDescription" @@ -91,18 +90,18 @@ public class OpenApiOperationTests } }; - private static readonly OpenApiOperation _advancedOperationWithTagsAndSecurity = new OpenApiOperation + private static readonly OpenApiOperation _advancedOperationWithTagsAndSecurity = new() { Tags = new List { - new OpenApiTag + new() { Name = "tagName1", Description = "tagDescription1", }, - new OpenApiTag + new() { - Reference = new OpenApiReference + Reference = new() { Id = "tagId1", Type = ReferenceType.Tag @@ -111,34 +110,34 @@ public class OpenApiOperationTests }, Summary = "summary1", Description = "operationDescription", - ExternalDocs = new OpenApiExternalDocs + ExternalDocs = new() { Description = "externalDocsDescription", - Url = new Uri("http://external.com") + Url = new("http://external.com") }, OperationId = "operationId1", Parameters = new List { - new OpenApiParameter + new() { In = ParameterLocation.Path, Name = "parameter1" }, - new OpenApiParameter + new() { In = ParameterLocation.Header, Name = "parameter2" } }, - RequestBody = new OpenApiRequestBody + RequestBody = new() { Description = "description2", Required = true, Content = new Dictionary { - ["application/json"] = new OpenApiMediaType + ["application/json"] = new() { - Schema = new OpenApiSchema + Schema = new() { Type = "number", Minimum = 5, @@ -147,23 +146,23 @@ public class OpenApiOperationTests } } }, - Responses = new OpenApiResponses + Responses = new() { - ["200"] = new OpenApiResponse + ["200"] = new() { - Reference = new OpenApiReference + Reference = new() { Id = "response1", Type = ReferenceType.Response } }, - ["400"] = new OpenApiResponse + ["400"] = new() { Content = new Dictionary { - ["application/json"] = new OpenApiMediaType + ["application/json"] = new() { - Schema = new OpenApiSchema + Schema = new() { Type = "number", Minimum = 5, @@ -175,19 +174,19 @@ public class OpenApiOperationTests }, Security = new List { - new OpenApiSecurityRequirement + new() { - [new OpenApiSecurityScheme + [new() { - Reference = new OpenApiReference + Reference = new() { Id = "securitySchemeId1", Type = ReferenceType.SecurityScheme } }] = new List(), - [new OpenApiSecurityScheme + [new() { - Reference = new OpenApiReference + Reference = new() { Id = "securitySchemeId2", Type = ReferenceType.SecurityScheme @@ -201,7 +200,7 @@ [new OpenApiSecurityScheme }, Servers = new List { - new OpenApiServer + new() { Url = "http://server.com", Description = "serverDescription" @@ -210,41 +209,41 @@ [new OpenApiSecurityScheme }; private static readonly OpenApiOperation _operationWithFormData = - new OpenApiOperation + new() { Summary = "Updates a pet in the store with form data", Description = "", OperationId = "updatePetWithForm", Parameters = new List { - new OpenApiParameter + new() { Name = "petId", In = ParameterLocation.Path, Description = "ID of pet that needs to be updated", Required = true, - Schema = new OpenApiSchema + Schema = new() { Type = "string" } } }, - RequestBody = new OpenApiRequestBody + RequestBody = new() { Content = { - ["application/x-www-form-urlencoded"] = new OpenApiMediaType + ["application/x-www-form-urlencoded"] = new() { - Schema = new OpenApiSchema + Schema = new() { Properties = { - ["name"] = new OpenApiSchema + ["name"] = new() { Description = "Updated name of the pet", Type = "string" }, - ["status"] = new OpenApiSchema + ["status"] = new() { Description = "Updated status of the pet", Type = "string" @@ -256,18 +255,18 @@ [new OpenApiSecurityScheme } } }, - ["multipart/form-data"] = new OpenApiMediaType + ["multipart/form-data"] = new() { - Schema = new OpenApiSchema + Schema = new() { Properties = { - ["name"] = new OpenApiSchema + ["name"] = new() { Description = "Updated name of the pet", Type = "string" }, - ["status"] = new OpenApiSchema + ["status"] = new() { Description = "Updated status of the pet", Type = "string" @@ -281,13 +280,13 @@ [new OpenApiSecurityScheme } } }, - Responses = new OpenApiResponses + Responses = new() { - ["200"] = new OpenApiResponse + ["200"] = new() { Description = "Pet updated." }, - ["405"] = new OpenApiResponse + ["405"] = new() { Description = "Invalid input" } diff --git a/test/Microsoft.OpenApi.Tests/Models/OpenApiParameterTests.cs b/test/Microsoft.OpenApi.Tests/Models/OpenApiParameterTests.cs index a39a276d1..a49f415e3 100644 --- a/test/Microsoft.OpenApi.Tests/Models/OpenApiParameterTests.cs +++ b/test/Microsoft.OpenApi.Tests/Models/OpenApiParameterTests.cs @@ -19,24 +19,24 @@ namespace Microsoft.OpenApi.Tests.Models [UsesVerify] public class OpenApiParameterTests { - public static OpenApiParameter BasicParameter = new OpenApiParameter + public static OpenApiParameter BasicParameter = new() { Name = "name1", In = ParameterLocation.Path }; - public static OpenApiParameter ReferencedParameter = new OpenApiParameter + public static OpenApiParameter ReferencedParameter = new() { Name = "name1", In = ParameterLocation.Path, - Reference = new OpenApiReference + Reference = new() { Type = ReferenceType.Parameter, Id = "example1" } }; - public static OpenApiParameter AdvancedPathParameterWithSchema = new OpenApiParameter + public static OpenApiParameter AdvancedPathParameterWithSchema = new() { Name = "name1", In = ParameterLocation.Path, @@ -46,19 +46,19 @@ public class OpenApiParameterTests Style = ParameterStyle.Simple, Explode = true, - Schema = new OpenApiSchema + Schema = new() { Title = "title2", Description = "description2", OneOf = new List { - new OpenApiSchema { Type = "number", Format = "double" }, - new OpenApiSchema { Type = "string" } + new() { Type = "number", Format = "double" }, + new() { Type = "string" } } }, Examples = new Dictionary { - ["test"] = new OpenApiExample + ["test"] = new() { Summary = "summary3", Description = "description3" @@ -66,17 +66,17 @@ public class OpenApiParameterTests } }; - public static OpenApiParameter ParameterWithFormStyleAndExplodeFalse = new OpenApiParameter + public static OpenApiParameter ParameterWithFormStyleAndExplodeFalse = new() { Name = "name1", In = ParameterLocation.Query, Description = "description1", Style = ParameterStyle.Form, Explode = false, - Schema = new OpenApiSchema + Schema = new() { Type = "array", - Items = new OpenApiSchema + Items = new() { Enum = new List { @@ -87,17 +87,17 @@ public class OpenApiParameterTests } }; - public static OpenApiParameter ParameterWithFormStyleAndExplodeTrue = new OpenApiParameter + public static OpenApiParameter ParameterWithFormStyleAndExplodeTrue = new() { Name = "name1", In = ParameterLocation.Query, Description = "description1", Style = ParameterStyle.Form, Explode = true, - Schema = new OpenApiSchema + Schema = new() { Type = "array", - Items = new OpenApiSchema + Items = new() { Enum = new List { @@ -108,7 +108,7 @@ public class OpenApiParameterTests } }; - public static OpenApiParameter AdvancedHeaderParameterWithSchemaReference = new OpenApiParameter + public static OpenApiParameter AdvancedHeaderParameterWithSchemaReference = new() { Name = "name1", In = ParameterLocation.Header, @@ -118,9 +118,9 @@ public class OpenApiParameterTests Style = ParameterStyle.Simple, Explode = true, - Schema = new OpenApiSchema + Schema = new() { - Reference = new OpenApiReference + Reference = new() { Type = ReferenceType.Schema, Id = "schemaObject1" @@ -129,7 +129,7 @@ public class OpenApiParameterTests }, Examples = new Dictionary { - ["test"] = new OpenApiExample + ["test"] = new() { Summary = "summary3", Description = "description3" @@ -137,7 +137,7 @@ public class OpenApiParameterTests } }; - public static OpenApiParameter AdvancedHeaderParameterWithSchemaTypeObject = new OpenApiParameter + public static OpenApiParameter AdvancedHeaderParameterWithSchemaTypeObject = new() { Name = "name1", In = ParameterLocation.Header, @@ -147,13 +147,13 @@ public class OpenApiParameterTests Style = ParameterStyle.Simple, Explode = true, - Schema = new OpenApiSchema + Schema = new() { Type = "object" }, Examples = new Dictionary { - ["test"] = new OpenApiExample + ["test"] = new() { Summary = "summary3", Description = "description3" @@ -293,7 +293,7 @@ public async Task SerializeReferencedParameterAsV3JsonWorksAsync(bool produceTer { // Arrange var outputStringWriter = new StringWriter(CultureInfo.InvariantCulture); - var writer = new OpenApiJsonWriter(outputStringWriter, new OpenApiJsonWriterSettings { Terse = produceTerseOutput }); + var writer = new OpenApiJsonWriter(outputStringWriter, new() { Terse = produceTerseOutput }); // Act ReferencedParameter.SerializeAsV3(writer); @@ -310,7 +310,7 @@ public async Task SerializeReferencedParameterAsV3JsonWithoutReferenceWorksAsync { // Arrange var outputStringWriter = new StringWriter(CultureInfo.InvariantCulture); - var writer = new OpenApiJsonWriter(outputStringWriter, new OpenApiJsonWriterSettings { Terse = produceTerseOutput }); + var writer = new OpenApiJsonWriter(outputStringWriter, new() { Terse = produceTerseOutput }); // Act ReferencedParameter.SerializeAsV3WithoutReference(writer); @@ -327,7 +327,7 @@ public async Task SerializeReferencedParameterAsV2JsonWorksAsync(bool produceTer { // Arrange var outputStringWriter = new StringWriter(CultureInfo.InvariantCulture); - var writer = new OpenApiJsonWriter(outputStringWriter, new OpenApiJsonWriterSettings { Terse = produceTerseOutput }); + var writer = new OpenApiJsonWriter(outputStringWriter, new() { Terse = produceTerseOutput }); // Act ReferencedParameter.SerializeAsV2(writer); @@ -344,7 +344,7 @@ public async Task SerializeReferencedParameterAsV2JsonWithoutReferenceWorksAsync { // Arrange var outputStringWriter = new StringWriter(CultureInfo.InvariantCulture); - var writer = new OpenApiJsonWriter(outputStringWriter, new OpenApiJsonWriterSettings { Terse = produceTerseOutput }); + var writer = new OpenApiJsonWriter(outputStringWriter, new() { Terse = produceTerseOutput }); // Act ReferencedParameter.SerializeAsV2WithoutReference(writer); @@ -361,7 +361,7 @@ public async Task SerializeParameterWithSchemaReferenceAsV2JsonWorksAsync(bool p { // Arrange var outputStringWriter = new StringWriter(CultureInfo.InvariantCulture); - var writer = new OpenApiJsonWriter(outputStringWriter, new OpenApiJsonWriterSettings { Terse = produceTerseOutput }); + var writer = new OpenApiJsonWriter(outputStringWriter, new() { Terse = produceTerseOutput }); // Act AdvancedHeaderParameterWithSchemaReference.SerializeAsV2(writer); @@ -378,7 +378,7 @@ public async Task SerializeParameterWithSchemaTypeObjectAsV2JsonWorksAsync(bool { // Arrange var outputStringWriter = new StringWriter(CultureInfo.InvariantCulture); - var writer = new OpenApiJsonWriter(outputStringWriter, new OpenApiJsonWriterSettings { Terse = produceTerseOutput }); + var writer = new OpenApiJsonWriter(outputStringWriter, new() { Terse = produceTerseOutput }); // Act AdvancedHeaderParameterWithSchemaTypeObject.SerializeAsV2(writer); @@ -395,7 +395,7 @@ public async Task SerializeParameterWithFormStyleAndExplodeFalseWorksAsync(bool { // Arrange var outputStringWriter = new StringWriter(CultureInfo.InvariantCulture); - var writer = new OpenApiJsonWriter(outputStringWriter, new OpenApiJsonWriterSettings { Terse = produceTerseOutput }); + var writer = new OpenApiJsonWriter(outputStringWriter, new() { Terse = produceTerseOutput }); // Act ParameterWithFormStyleAndExplodeFalse.SerializeAsV3WithoutReference(writer); @@ -412,7 +412,7 @@ public async Task SerializeParameterWithFormStyleAndExplodeTrueWorksAsync(bool p { // Arrange var outputStringWriter = new StringWriter(CultureInfo.InvariantCulture); - var writer = new OpenApiJsonWriter(outputStringWriter, new OpenApiJsonWriterSettings { Terse = produceTerseOutput }); + var writer = new OpenApiJsonWriter(outputStringWriter, new() { Terse = produceTerseOutput }); // Act ParameterWithFormStyleAndExplodeTrue.SerializeAsV3WithoutReference(writer); diff --git a/test/Microsoft.OpenApi.Tests/Models/OpenApiRequestBodyTests.cs b/test/Microsoft.OpenApi.Tests/Models/OpenApiRequestBodyTests.cs index f08338ea2..08ef42fe7 100644 --- a/test/Microsoft.OpenApi.Tests/Models/OpenApiRequestBodyTests.cs +++ b/test/Microsoft.OpenApi.Tests/Models/OpenApiRequestBodyTests.cs @@ -15,15 +15,15 @@ namespace Microsoft.OpenApi.Tests.Models [UsesVerify] public class OpenApiRequestBodyTests { - public static OpenApiRequestBody AdvancedRequestBody = new OpenApiRequestBody + public static OpenApiRequestBody AdvancedRequestBody = new() { Description = "description", Required = true, Content = { - ["application/json"] = new OpenApiMediaType + ["application/json"] = new() { - Schema = new OpenApiSchema + Schema = new() { Type = "string" } @@ -31,9 +31,9 @@ public class OpenApiRequestBodyTests } }; - public static OpenApiRequestBody ReferencedRequestBody = new OpenApiRequestBody + public static OpenApiRequestBody ReferencedRequestBody = new() { - Reference = new OpenApiReference + Reference = new() { Type = ReferenceType.RequestBody, Id = "example1", @@ -42,9 +42,9 @@ public class OpenApiRequestBodyTests Required = true, Content = { - ["application/json"] = new OpenApiMediaType + ["application/json"] = new() { - Schema = new OpenApiSchema + Schema = new() { Type = "string" } @@ -59,7 +59,7 @@ public async Task SerializeAdvancedRequestBodyAsV3JsonWorksAsync(bool produceTer { // Arrange var outputStringWriter = new StringWriter(CultureInfo.InvariantCulture); - var writer = new OpenApiJsonWriter(outputStringWriter, new OpenApiJsonWriterSettings { Terse = produceTerseOutput }); + var writer = new OpenApiJsonWriter(outputStringWriter, new() { Terse = produceTerseOutput }); // Act AdvancedRequestBody.SerializeAsV3(writer); @@ -76,7 +76,7 @@ public async Task SerializeReferencedRequestBodyAsV3JsonWorksAsync(bool produceT { // Arrange var outputStringWriter = new StringWriter(CultureInfo.InvariantCulture); - var writer = new OpenApiJsonWriter(outputStringWriter, new OpenApiJsonWriterSettings { Terse = produceTerseOutput }); + var writer = new OpenApiJsonWriter(outputStringWriter, new() { Terse = produceTerseOutput }); // Act ReferencedRequestBody.SerializeAsV3(writer); @@ -93,7 +93,7 @@ public async Task SerializeReferencedRequestBodyAsV3JsonWithoutReferenceWorksAsy { // Arrange var outputStringWriter = new StringWriter(CultureInfo.InvariantCulture); - var writer = new OpenApiJsonWriter(outputStringWriter, new OpenApiJsonWriterSettings { Terse = produceTerseOutput }); + var writer = new OpenApiJsonWriter(outputStringWriter, new() { Terse = produceTerseOutput }); // Act ReferencedRequestBody.SerializeAsV3WithoutReference(writer); diff --git a/test/Microsoft.OpenApi.Tests/Models/OpenApiResponseTests.cs b/test/Microsoft.OpenApi.Tests/Models/OpenApiResponseTests.cs index f12861a3f..ea3a6ee29 100644 --- a/test/Microsoft.OpenApi.Tests/Models/OpenApiResponseTests.cs +++ b/test/Microsoft.OpenApi.Tests/Models/OpenApiResponseTests.cs @@ -20,21 +20,21 @@ namespace Microsoft.OpenApi.Tests.Models [UsesVerify] public class OpenApiResponseTests { - public static OpenApiResponse BasicResponse = new OpenApiResponse(); + public static OpenApiResponse BasicResponse = new(); - public static OpenApiResponse AdvancedResponse = new OpenApiResponse + public static OpenApiResponse AdvancedResponse = new() { Description = "A complex object array response", Content = { - ["text/plain"] = new OpenApiMediaType + ["text/plain"] = new() { - Schema = new OpenApiSchema + Schema = new() { Type = "array", - Items = new OpenApiSchema + Items = new() { - Reference = new OpenApiReference {Type = ReferenceType.Schema, Id = "customType"} + Reference = new() {Type = ReferenceType.Schema, Id = "customType"} } }, Example = new OpenApiString("Blabla"), @@ -46,18 +46,18 @@ public class OpenApiResponseTests }, Headers = { - ["X-Rate-Limit-Limit"] = new OpenApiHeader + ["X-Rate-Limit-Limit"] = new() { Description = "The number of allowed requests in the current period", - Schema = new OpenApiSchema + Schema = new() { Type = "integer" } }, - ["X-Rate-Limit-Reset"] = new OpenApiHeader + ["X-Rate-Limit-Reset"] = new() { Description = "The number of seconds left in the current period", - Schema = new OpenApiSchema + Schema = new() { Type = "integer" } @@ -65,9 +65,9 @@ public class OpenApiResponseTests } }; - public static OpenApiResponse ReferencedResponse = new OpenApiResponse + public static OpenApiResponse ReferencedResponse = new() { - Reference = new OpenApiReference + Reference = new() { Type = ReferenceType.Response, Id = "example1" @@ -75,32 +75,32 @@ public class OpenApiResponseTests Description = "A complex object array response", Content = { - ["text/plain"] = new OpenApiMediaType + ["text/plain"] = new() { - Schema = new OpenApiSchema + Schema = new() { Type = "array", - Items = new OpenApiSchema + Items = new() { - Reference = new OpenApiReference {Type = ReferenceType.Schema, Id = "customType"} + Reference = new() {Type = ReferenceType.Schema, Id = "customType"} } } } }, Headers = { - ["X-Rate-Limit-Limit"] = new OpenApiHeader + ["X-Rate-Limit-Limit"] = new() { Description = "The number of allowed requests in the current period", - Schema = new OpenApiSchema + Schema = new() { Type = "integer" } }, - ["X-Rate-Limit-Reset"] = new OpenApiHeader + ["X-Rate-Limit-Reset"] = new() { Description = "The number of seconds left in the current period", - Schema = new OpenApiSchema + Schema = new() { Type = "integer" } @@ -294,7 +294,7 @@ public async Task SerializeReferencedResponseAsV3JsonWorksAsync(bool produceTers { // Arrange var outputStringWriter = new StringWriter(CultureInfo.InvariantCulture); - var writer = new OpenApiJsonWriter(outputStringWriter, new OpenApiJsonWriterSettings { Terse = produceTerseOutput }); + var writer = new OpenApiJsonWriter(outputStringWriter, new() { Terse = produceTerseOutput }); // Act ReferencedResponse.SerializeAsV3(writer); @@ -311,7 +311,7 @@ public async Task SerializeReferencedResponseAsV3JsonWithoutReferenceWorksAsync( { // Arrange var outputStringWriter = new StringWriter(CultureInfo.InvariantCulture); - var writer = new OpenApiJsonWriter(outputStringWriter, new OpenApiJsonWriterSettings { Terse = produceTerseOutput }); + var writer = new OpenApiJsonWriter(outputStringWriter, new() { Terse = produceTerseOutput }); // Act ReferencedResponse.SerializeAsV3WithoutReference(writer); @@ -328,7 +328,7 @@ public async Task SerializeReferencedResponseAsV2JsonWorksAsync(bool produceTers { // Arrange var outputStringWriter = new StringWriter(CultureInfo.InvariantCulture); - var writer = new OpenApiJsonWriter(outputStringWriter, new OpenApiJsonWriterSettings { Terse = produceTerseOutput }); + var writer = new OpenApiJsonWriter(outputStringWriter, new() { Terse = produceTerseOutput }); // Act ReferencedResponse.SerializeAsV2(writer); @@ -345,7 +345,7 @@ public async Task SerializeReferencedResponseAsV2JsonWithoutReferenceWorksAsync( { // Arrange var outputStringWriter = new StringWriter(CultureInfo.InvariantCulture); - var writer = new OpenApiJsonWriter(outputStringWriter, new OpenApiJsonWriterSettings { Terse = produceTerseOutput }); + var writer = new OpenApiJsonWriter(outputStringWriter, new() { Terse = produceTerseOutput }); // Act ReferencedResponse.SerializeAsV2WithoutReference(writer); diff --git a/test/Microsoft.OpenApi.Tests/Models/OpenApiSchemaTests.cs b/test/Microsoft.OpenApi.Tests/Models/OpenApiSchemaTests.cs index f1b985a62..b4c331830 100644 --- a/test/Microsoft.OpenApi.Tests/Models/OpenApiSchemaTests.cs +++ b/test/Microsoft.OpenApi.Tests/Models/OpenApiSchemaTests.cs @@ -1,7 +1,6 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. -using System; using System.Collections.Generic; using System.Globalization; using System.IO; @@ -21,9 +20,9 @@ namespace Microsoft.OpenApi.Tests.Models [UsesVerify] public class OpenApiSchemaTests { - public static OpenApiSchema BasicSchema = new OpenApiSchema(); + public static OpenApiSchema BasicSchema = new(); - public static OpenApiSchema AdvancedSchemaNumber = new OpenApiSchema + public static OpenApiSchema AdvancedSchemaNumber = new() { Title = "title1", MultipleOf = 3, @@ -34,47 +33,47 @@ public class OpenApiSchemaTests Type = "integer", Nullable = true, - ExternalDocs = new OpenApiExternalDocs + ExternalDocs = new() { - Url = new Uri("http://example.com/externalDocs") + Url = new("http://example.com/externalDocs") } }; - public static OpenApiSchema AdvancedSchemaObject = new OpenApiSchema + public static OpenApiSchema AdvancedSchemaObject = new() { Title = "title1", Properties = new Dictionary { - ["property1"] = new OpenApiSchema + ["property1"] = new() { Properties = new Dictionary { - ["property2"] = new OpenApiSchema + ["property2"] = new() { Type = "integer" }, - ["property3"] = new OpenApiSchema + ["property3"] = new() { Type = "string", MaxLength = 15 } }, }, - ["property4"] = new OpenApiSchema + ["property4"] = new() { Properties = new Dictionary { - ["property5"] = new OpenApiSchema + ["property5"] = new() { Properties = new Dictionary { - ["property6"] = new OpenApiSchema + ["property6"] = new() { Type = "boolean" } } }, - ["property7"] = new OpenApiSchema + ["property7"] = new() { Type = "string", MinLength = 2 @@ -83,49 +82,49 @@ public class OpenApiSchemaTests }, }, Nullable = true, - ExternalDocs = new OpenApiExternalDocs + ExternalDocs = new() { - Url = new Uri("http://example.com/externalDocs") + Url = new("http://example.com/externalDocs") } }; - public static OpenApiSchema AdvancedSchemaWithAllOf = new OpenApiSchema + public static OpenApiSchema AdvancedSchemaWithAllOf = new() { Title = "title1", AllOf = new List { - new OpenApiSchema + new() { Title = "title2", Properties = new Dictionary { - ["property1"] = new OpenApiSchema + ["property1"] = new() { Type = "integer" }, - ["property2"] = new OpenApiSchema + ["property2"] = new() { Type = "string", MaxLength = 15 } }, }, - new OpenApiSchema + new() { Title = "title3", Properties = new Dictionary { - ["property3"] = new OpenApiSchema + ["property3"] = new() { Properties = new Dictionary { - ["property4"] = new OpenApiSchema + ["property4"] = new() { Type = "boolean" } } }, - ["property5"] = new OpenApiSchema + ["property5"] = new() { Type = "string", MinLength = 2 @@ -135,13 +134,13 @@ public class OpenApiSchemaTests }, }, Nullable = true, - ExternalDocs = new OpenApiExternalDocs + ExternalDocs = new() { - Url = new Uri("http://example.com/externalDocs") + Url = new("http://example.com/externalDocs") } }; - public static OpenApiSchema ReferencedSchema = new OpenApiSchema + public static OpenApiSchema ReferencedSchema = new() { Title = "title1", MultipleOf = 3, @@ -152,34 +151,34 @@ public class OpenApiSchemaTests Type = "integer", Nullable = true, - ExternalDocs = new OpenApiExternalDocs + ExternalDocs = new() { - Url = new Uri("http://example.com/externalDocs") + Url = new("http://example.com/externalDocs") }, - Reference = new OpenApiReference + Reference = new() { Type = ReferenceType.Schema, Id = "schemaObject1" } }; - public static OpenApiSchema AdvancedSchemaWithRequiredPropertiesObject = new OpenApiSchema + public static OpenApiSchema AdvancedSchemaWithRequiredPropertiesObject = new() { Title = "title1", Required = new HashSet { "property1" }, Properties = new Dictionary { - ["property1"] = new OpenApiSchema + ["property1"] = new() { Required = new HashSet { "property3" }, Properties = new Dictionary { - ["property2"] = new OpenApiSchema + ["property2"] = new() { Type = "integer" }, - ["property3"] = new OpenApiSchema + ["property3"] = new() { Type = "string", MaxLength = 15, @@ -188,21 +187,21 @@ public class OpenApiSchemaTests }, ReadOnly = true, }, - ["property4"] = new OpenApiSchema + ["property4"] = new() { Properties = new Dictionary { - ["property5"] = new OpenApiSchema + ["property5"] = new() { Properties = new Dictionary { - ["property6"] = new OpenApiSchema + ["property6"] = new() { Type = "boolean" } } }, - ["property7"] = new OpenApiSchema + ["property7"] = new() { Type = "string", MinLength = 2 @@ -212,9 +211,9 @@ public class OpenApiSchemaTests }, }, Nullable = true, - ExternalDocs = new OpenApiExternalDocs + ExternalDocs = new() { - Url = new Uri("http://example.com/externalDocs") + Url = new("http://example.com/externalDocs") } }; @@ -377,7 +376,7 @@ public async Task SerializeReferencedSchemaAsV3WithoutReferenceJsonWorksAsync(bo { // Arrange var outputStringWriter = new StringWriter(CultureInfo.InvariantCulture); - var writer = new OpenApiJsonWriter(outputStringWriter, new OpenApiJsonWriterSettings { Terse = produceTerseOutput }); + var writer = new OpenApiJsonWriter(outputStringWriter, new() { Terse = produceTerseOutput }); // Act ReferencedSchema.SerializeAsV3WithoutReference(writer); @@ -394,7 +393,7 @@ public async Task SerializeReferencedSchemaAsV3JsonWorksAsync(bool produceTerseO { // Arrange var outputStringWriter = new StringWriter(CultureInfo.InvariantCulture); - var writer = new OpenApiJsonWriter(outputStringWriter, new OpenApiJsonWriterSettings { Terse = produceTerseOutput }); + var writer = new OpenApiJsonWriter(outputStringWriter, new() { Terse = produceTerseOutput }); // Act ReferencedSchema.SerializeAsV3(writer); @@ -411,7 +410,7 @@ public async Task SerializeSchemaWRequiredPropertiesAsV2JsonWorksAsync(bool prod { // Arrange var outputStringWriter = new StringWriter(CultureInfo.InvariantCulture); - var writer = new OpenApiJsonWriter(outputStringWriter, new OpenApiJsonWriterSettings { Terse = produceTerseOutput }); + var writer = new OpenApiJsonWriter(outputStringWriter, new() { Terse = produceTerseOutput }); // Act AdvancedSchemaWithRequiredPropertiesObject.SerializeAsV2(writer); @@ -429,17 +428,17 @@ public void SerializeAsV2ShouldSetFormatPropertyInParentSchemaIfPresentInChildre { OneOf = new List { - new OpenApiSchema + new() { Type = "number", Format = "decimal" }, - new OpenApiSchema { Type = "string" }, + new() { Type = "string" }, } }; var outputStringWriter = new StringWriter(CultureInfo.InvariantCulture); - var openApiJsonWriter = new OpenApiJsonWriter(outputStringWriter, new OpenApiJsonWriterSettings { Terse = false }); + var openApiJsonWriter = new OpenApiJsonWriter(outputStringWriter, new() { Terse = false }); // Act // Serialize as V2 diff --git a/test/Microsoft.OpenApi.Tests/Models/OpenApiSecurityRequirementTests.cs b/test/Microsoft.OpenApi.Tests/Models/OpenApiSecurityRequirementTests.cs index bc7e4b8a1..36ead6e72 100644 --- a/test/Microsoft.OpenApi.Tests/Models/OpenApiSecurityRequirementTests.cs +++ b/test/Microsoft.OpenApi.Tests/Models/OpenApiSecurityRequirementTests.cs @@ -13,15 +13,15 @@ namespace Microsoft.OpenApi.Tests.Models [Collection("DefaultSettings")] public class OpenApiSecurityRequirementTests { - public static OpenApiSecurityRequirement BasicSecurityRequirement = new OpenApiSecurityRequirement(); + public static OpenApiSecurityRequirement BasicSecurityRequirement = new(); public static OpenApiSecurityRequirement SecurityRequirementWithReferencedSecurityScheme = - new OpenApiSecurityRequirement + new() { [ - new OpenApiSecurityScheme + new() { - Reference = new OpenApiReference { Type = ReferenceType.SecurityScheme, Id = "scheme1" } + Reference = new() { Type = ReferenceType.SecurityScheme, Id = "scheme1" } } ] = new List { @@ -30,9 +30,9 @@ public class OpenApiSecurityRequirementTests "scope3", }, [ - new OpenApiSecurityScheme + new() { - Reference = new OpenApiReference { Type = ReferenceType.SecurityScheme, Id = "scheme2" } + Reference = new() { Type = ReferenceType.SecurityScheme, Id = "scheme2" } } ] = new List { @@ -40,20 +40,20 @@ public class OpenApiSecurityRequirementTests "scope5", }, [ - new OpenApiSecurityScheme + new() { - Reference = new OpenApiReference { Type = ReferenceType.SecurityScheme, Id = "scheme3" } + Reference = new() { Type = ReferenceType.SecurityScheme, Id = "scheme3" } } ] = new List() }; public static OpenApiSecurityRequirement SecurityRequirementWithUnreferencedSecurityScheme = - new OpenApiSecurityRequirement + new() { [ - new OpenApiSecurityScheme + new() { - Reference = new OpenApiReference { Type = ReferenceType.SecurityScheme, Id = "scheme1" } + Reference = new() { Type = ReferenceType.SecurityScheme, Id = "scheme1" } } ] = new List { @@ -62,7 +62,7 @@ public class OpenApiSecurityRequirementTests "scope3", }, [ - new OpenApiSecurityScheme + new() { // This security scheme is unreferenced, so this key value pair cannot be serialized. Name = "brokenUnreferencedScheme" @@ -73,9 +73,9 @@ public class OpenApiSecurityRequirementTests "scope5", }, [ - new OpenApiSecurityScheme + new() { - Reference = new OpenApiReference { Type = ReferenceType.SecurityScheme, Id = "scheme3" } + Reference = new() { Type = ReferenceType.SecurityScheme, Id = "scheme3" } } ] = new List() }; @@ -219,7 +219,7 @@ public void SchemesShouldConsiderOnlyReferenceIdForEquality() Type = SecuritySchemeType.ApiKey, Name = "apiKeyName1", In = ParameterLocation.Header, - Reference = new OpenApiReference + Reference = new() { Id = "securityScheme1", Type = ReferenceType.SecurityScheme @@ -229,8 +229,8 @@ public void SchemesShouldConsiderOnlyReferenceIdForEquality() var securityScheme2 = new OpenApiSecurityScheme { Type = SecuritySchemeType.OpenIdConnect, - OpenIdConnectUrl = new Uri("http://example.com"), - Reference = new OpenApiReference + OpenIdConnectUrl = new("http://example.com"), + Reference = new() { Id = "securityScheme2", Type = ReferenceType.SecurityScheme @@ -242,7 +242,7 @@ public void SchemesShouldConsiderOnlyReferenceIdForEquality() Type = SecuritySchemeType.ApiKey, Name = "apiKeyName1", In = ParameterLocation.Header, - Reference = new OpenApiReference + Reference = new() { Id = "securityScheme1", Type = ReferenceType.SecurityScheme @@ -254,7 +254,7 @@ public void SchemesShouldConsiderOnlyReferenceIdForEquality() Type = SecuritySchemeType.ApiKey, Name = "apiKeyName2", In = ParameterLocation.Query, - Reference = new OpenApiReference + Reference = new() { Id = "securityScheme1", Type = ReferenceType.SecurityScheme diff --git a/test/Microsoft.OpenApi.Tests/Models/OpenApiSecuritySchemeTests.cs b/test/Microsoft.OpenApi.Tests/Models/OpenApiSecuritySchemeTests.cs index 6b93fab24..5cc4a19cb 100644 --- a/test/Microsoft.OpenApi.Tests/Models/OpenApiSecuritySchemeTests.cs +++ b/test/Microsoft.OpenApi.Tests/Models/OpenApiSecuritySchemeTests.cs @@ -1,7 +1,6 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. -using System; using System.Collections.Generic; using System.Globalization; using System.IO; @@ -19,7 +18,7 @@ namespace Microsoft.OpenApi.Tests.Models [UsesVerify] public class OpenApiSecuritySchemeTests { - public static OpenApiSecurityScheme ApiKeySecurityScheme = new OpenApiSecurityScheme + public static OpenApiSecurityScheme ApiKeySecurityScheme = new() { Description = "description1", Name = "parameterName", @@ -27,14 +26,14 @@ public class OpenApiSecuritySchemeTests In = ParameterLocation.Query, }; - public static OpenApiSecurityScheme HttpBasicSecurityScheme = new OpenApiSecurityScheme + public static OpenApiSecurityScheme HttpBasicSecurityScheme = new() { Description = "description1", Type = SecuritySchemeType.Http, Scheme = OpenApiConstants.Basic }; - public static OpenApiSecurityScheme HttpBearerSecurityScheme = new OpenApiSecurityScheme + public static OpenApiSecurityScheme HttpBearerSecurityScheme = new() { Description = "description1", Type = SecuritySchemeType.Http, @@ -42,77 +41,77 @@ public class OpenApiSecuritySchemeTests BearerFormat = OpenApiConstants.Jwt }; - public static OpenApiSecurityScheme OAuth2SingleFlowSecurityScheme = new OpenApiSecurityScheme + public static OpenApiSecurityScheme OAuth2SingleFlowSecurityScheme = new() { Description = "description1", Type = SecuritySchemeType.OAuth2, - Flows = new OpenApiOAuthFlows + Flows = new() { - Implicit = new OpenApiOAuthFlow + Implicit = new() { Scopes = new Dictionary { ["operation1:object1"] = "operation 1 on object 1", ["operation2:object2"] = "operation 2 on object 2" }, - AuthorizationUrl = new Uri("https://example.com/api/oauth") + AuthorizationUrl = new("https://example.com/api/oauth") } } }; - public static OpenApiSecurityScheme OAuth2MultipleFlowSecurityScheme = new OpenApiSecurityScheme + public static OpenApiSecurityScheme OAuth2MultipleFlowSecurityScheme = new() { Description = "description1", Type = SecuritySchemeType.OAuth2, - Flows = new OpenApiOAuthFlows + Flows = new() { - Implicit = new OpenApiOAuthFlow + Implicit = new() { Scopes = new Dictionary { ["operation1:object1"] = "operation 1 on object 1", ["operation2:object2"] = "operation 2 on object 2" }, - AuthorizationUrl = new Uri("https://example.com/api/oauth") + AuthorizationUrl = new("https://example.com/api/oauth") }, - ClientCredentials = new OpenApiOAuthFlow + ClientCredentials = new() { Scopes = new Dictionary { ["operation1:object1"] = "operation 1 on object 1", ["operation2:object2"] = "operation 2 on object 2" }, - TokenUrl = new Uri("https://example.com/api/token"), - RefreshUrl = new Uri("https://example.com/api/refresh"), + TokenUrl = new("https://example.com/api/token"), + RefreshUrl = new("https://example.com/api/refresh"), }, - AuthorizationCode = new OpenApiOAuthFlow + AuthorizationCode = new() { Scopes = new Dictionary { ["operation1:object1"] = "operation 1 on object 1", ["operation2:object2"] = "operation 2 on object 2" }, - TokenUrl = new Uri("https://example.com/api/token"), - AuthorizationUrl = new Uri("https://example.com/api/oauth"), + TokenUrl = new("https://example.com/api/token"), + AuthorizationUrl = new("https://example.com/api/oauth"), } } }; - public static OpenApiSecurityScheme OpenIdConnectSecurityScheme = new OpenApiSecurityScheme + public static OpenApiSecurityScheme OpenIdConnectSecurityScheme = new() { Description = "description1", Type = SecuritySchemeType.OpenIdConnect, Scheme = OpenApiConstants.Bearer, - OpenIdConnectUrl = new Uri("https://example.com/openIdConnect") + OpenIdConnectUrl = new("https://example.com/openIdConnect") }; - public static OpenApiSecurityScheme ReferencedSecurityScheme = new OpenApiSecurityScheme + public static OpenApiSecurityScheme ReferencedSecurityScheme = new() { Description = "description1", Type = SecuritySchemeType.OpenIdConnect, Scheme = OpenApiConstants.Bearer, - OpenIdConnectUrl = new Uri("https://example.com/openIdConnect"), - Reference = new OpenApiReference + OpenIdConnectUrl = new("https://example.com/openIdConnect"), + Reference = new() { Type = ReferenceType.SecurityScheme, Id = "sampleSecurityScheme" @@ -313,7 +312,7 @@ public async Task SerializeReferencedSecuritySchemeAsV3JsonWorksAsync(bool produ { // Arrange var outputStringWriter = new StringWriter(CultureInfo.InvariantCulture); - var writer = new OpenApiJsonWriter(outputStringWriter, new OpenApiJsonWriterSettings { Terse = produceTerseOutput }); + var writer = new OpenApiJsonWriter(outputStringWriter, new() { Terse = produceTerseOutput }); // Act // Add dummy start object, value, and end object to allow SerializeAsV3 to output security scheme @@ -335,7 +334,7 @@ public async Task SerializeReferencedSecuritySchemeAsV3JsonWithoutReferenceWorks { // Arrange var outputStringWriter = new StringWriter(CultureInfo.InvariantCulture); - var writer = new OpenApiJsonWriter(outputStringWriter, new OpenApiJsonWriterSettings { Terse = produceTerseOutput }); + var writer = new OpenApiJsonWriter(outputStringWriter, new() { Terse = produceTerseOutput }); // Act ReferencedSecurityScheme.SerializeAsV3WithoutReference(writer); diff --git a/test/Microsoft.OpenApi.Tests/Models/OpenApiServerTests.cs b/test/Microsoft.OpenApi.Tests/Models/OpenApiServerTests.cs index 8e425f897..19fc00aeb 100644 --- a/test/Microsoft.OpenApi.Tests/Models/OpenApiServerTests.cs +++ b/test/Microsoft.OpenApi.Tests/Models/OpenApiServerTests.cs @@ -12,34 +12,34 @@ namespace Microsoft.OpenApi.Tests.Models [Collection("DefaultSettings")] public class OpenApiServerTests { - public static OpenApiServer BasicServer = new OpenApiServer + public static OpenApiServer BasicServer = new() { Description = "description1", Url = "https://example.com/server1" }; - public static OpenApiServer AdvancedServer = new OpenApiServer + public static OpenApiServer AdvancedServer = new() { Description = "description1", Url = "https://{username}.example.com:{port}/{basePath}", Variables = new Dictionary { - ["username"] = new OpenApiServerVariable + ["username"] = new() { Default = "unknown", Description = "variableDescription1", }, - ["port"] = new OpenApiServerVariable + ["port"] = new() { Default = "8443", Description = "variableDescription2", - Enum = new List + Enum = new() { "443", "8443" } }, - ["basePath"] = new OpenApiServerVariable + ["basePath"] = new() { Default = "v1" }, diff --git a/test/Microsoft.OpenApi.Tests/Models/OpenApiServerVariableTests.cs b/test/Microsoft.OpenApi.Tests/Models/OpenApiServerVariableTests.cs index 1398e2249..ca23e3b97 100644 --- a/test/Microsoft.OpenApi.Tests/Models/OpenApiServerVariableTests.cs +++ b/test/Microsoft.OpenApi.Tests/Models/OpenApiServerVariableTests.cs @@ -1,7 +1,6 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. -using System.Collections.Generic; using FluentAssertions; using Microsoft.OpenApi.Extensions; using Microsoft.OpenApi.Models; @@ -12,12 +11,12 @@ namespace Microsoft.OpenApi.Tests.Models [Collection("DefaultSettings")] public class OpenApiServerVariableTests { - public static OpenApiServerVariable BasicServerVariable = new OpenApiServerVariable(); + public static OpenApiServerVariable BasicServerVariable = new(); - public static OpenApiServerVariable AdvancedServerVariable = new OpenApiServerVariable + public static OpenApiServerVariable AdvancedServerVariable = new() { Default = "8443", - Enum = new List + Enum = new() { "8443", "443" diff --git a/test/Microsoft.OpenApi.Tests/Models/OpenApiTagTests.cs b/test/Microsoft.OpenApi.Tests/Models/OpenApiTagTests.cs index 9d0efd995..fa6690c94 100644 --- a/test/Microsoft.OpenApi.Tests/Models/OpenApiTagTests.cs +++ b/test/Microsoft.OpenApi.Tests/Models/OpenApiTagTests.cs @@ -19,9 +19,9 @@ namespace Microsoft.OpenApi.Tests.Models [UsesVerify] public class OpenApiTagTests { - public static OpenApiTag BasicTag = new OpenApiTag(); + public static OpenApiTag BasicTag = new(); - public static OpenApiTag AdvancedTag = new OpenApiTag + public static OpenApiTag AdvancedTag = new() { Name = "pet", Description = "Pets operations", @@ -32,7 +32,7 @@ public class OpenApiTagTests } }; - public static OpenApiTag ReferencedTag = new OpenApiTag + public static OpenApiTag ReferencedTag = new() { Name = "pet", Description = "Pets operations", @@ -41,7 +41,7 @@ public class OpenApiTagTests { {"x-tag-extension", new OpenApiNull()} }, - Reference = new OpenApiReference + Reference = new() { Type = ReferenceType.Tag, Id = "pet" @@ -55,7 +55,7 @@ public async Task SerializeBasicTagAsV3JsonWithoutReferenceWorksAsync(bool produ { // Arrange var outputStringWriter = new StringWriter(CultureInfo.InvariantCulture); - var writer = new OpenApiJsonWriter(outputStringWriter, new OpenApiJsonWriterSettings { Terse = produceTerseOutput }); + var writer = new OpenApiJsonWriter(outputStringWriter, new() { Terse = produceTerseOutput }); // Act BasicTag.SerializeAsV3WithoutReference(writer); @@ -72,7 +72,7 @@ public async Task SerializeBasicTagAsV2JsonWithoutReferenceWorksAsync(bool produ { // Arrange var outputStringWriter = new StringWriter(CultureInfo.InvariantCulture); - var writer = new OpenApiJsonWriter(outputStringWriter, new OpenApiJsonWriterSettings { Terse = produceTerseOutput }); + var writer = new OpenApiJsonWriter(outputStringWriter, new() { Terse = produceTerseOutput }); // Act BasicTag.SerializeAsV2WithoutReference(writer); @@ -126,7 +126,7 @@ public async Task SerializeAdvancedTagAsV3JsonWithoutReferenceWorksAsync(bool pr { // Arrange var outputStringWriter = new StringWriter(CultureInfo.InvariantCulture); - var writer = new OpenApiJsonWriter(outputStringWriter, new OpenApiJsonWriterSettings { Terse = produceTerseOutput }); + var writer = new OpenApiJsonWriter(outputStringWriter, new() { Terse = produceTerseOutput }); // Act AdvancedTag.SerializeAsV3WithoutReference(writer); @@ -143,7 +143,7 @@ public async Task SerializeAdvancedTagAsV2JsonWithoutReferenceWorksAsync(bool pr { // Arrange var outputStringWriter = new StringWriter(CultureInfo.InvariantCulture); - var writer = new OpenApiJsonWriter(outputStringWriter, new OpenApiJsonWriterSettings { Terse = produceTerseOutput }); + var writer = new OpenApiJsonWriter(outputStringWriter, new() { Terse = produceTerseOutput }); // Act AdvancedTag.SerializeAsV2WithoutReference(writer); @@ -214,7 +214,7 @@ public async Task SerializeAdvancedTagAsV3JsonWorksAsync(bool produceTerseOutput { // Arrange var outputStringWriter = new StringWriter(CultureInfo.InvariantCulture); - var writer = new OpenApiJsonWriter(outputStringWriter, new OpenApiJsonWriterSettings { Terse = produceTerseOutput }); + var writer = new OpenApiJsonWriter(outputStringWriter, new() { Terse = produceTerseOutput }); // Act AdvancedTag.SerializeAsV3(writer); @@ -231,7 +231,7 @@ public async Task SerializeAdvancedTagAsV2JsonWorksAsync(bool produceTerseOutput { // Arrange var outputStringWriter = new StringWriter(CultureInfo.InvariantCulture); - var writer = new OpenApiJsonWriter(outputStringWriter, new OpenApiJsonWriterSettings { Terse = produceTerseOutput }); + var writer = new OpenApiJsonWriter(outputStringWriter, new() { Terse = produceTerseOutput }); // Act AdvancedTag.SerializeAsV2(writer); @@ -288,7 +288,7 @@ public async Task SerializeReferencedTagAsV3JsonWorksAsync(bool produceTerseOutp { // Arrange var outputStringWriter = new StringWriter(CultureInfo.InvariantCulture); - var writer = new OpenApiJsonWriter(outputStringWriter, new OpenApiJsonWriterSettings { Terse = produceTerseOutput }); + var writer = new OpenApiJsonWriter(outputStringWriter, new() { Terse = produceTerseOutput }); // Act ReferencedTag.SerializeAsV3(writer); @@ -305,7 +305,7 @@ public async Task SerializeReferencedTagAsV2JsonWorksAsync(bool produceTerseOutp { // Arrange var outputStringWriter = new StringWriter(CultureInfo.InvariantCulture); - var writer = new OpenApiJsonWriter(outputStringWriter, new OpenApiJsonWriterSettings { Terse = produceTerseOutput }); + var writer = new OpenApiJsonWriter(outputStringWriter, new() { Terse = produceTerseOutput }); // Act ReferencedTag.SerializeAsV2(writer); diff --git a/test/Microsoft.OpenApi.Tests/Models/OpenApiXmlTests.cs b/test/Microsoft.OpenApi.Tests/Models/OpenApiXmlTests.cs index 975a0390b..92562ac18 100644 --- a/test/Microsoft.OpenApi.Tests/Models/OpenApiXmlTests.cs +++ b/test/Microsoft.OpenApi.Tests/Models/OpenApiXmlTests.cs @@ -1,7 +1,6 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. -using System; using System.Collections.Generic; using FluentAssertions; using Microsoft.OpenApi.Any; @@ -15,10 +14,10 @@ namespace Microsoft.OpenApi.Tests.Models [Collection("DefaultSettings")] public class OpenApiXmlTests { - public static OpenApiXml AdvancedXml = new OpenApiXml + public static OpenApiXml AdvancedXml = new() { Name = "animal", - Namespace = new Uri("http://swagger.io/schema/sample"), + Namespace = new("http://swagger.io/schema/sample"), Prefix = "sample", Wrapped = true, Attribute = true, @@ -28,7 +27,7 @@ public class OpenApiXmlTests } }; - public static OpenApiXml BasicXml = new OpenApiXml(); + public static OpenApiXml BasicXml = new(); [Theory] [InlineData(OpenApiSpecVersion.OpenApi3_0, OpenApiFormat.Json)] diff --git a/test/Microsoft.OpenApi.Tests/PublicApi/PublicApiTests.cs b/test/Microsoft.OpenApi.Tests/PublicApi/PublicApiTests.cs index 8bb4901a0..deb8e30be 100755 --- a/test/Microsoft.OpenApi.Tests/PublicApi/PublicApiTests.cs +++ b/test/Microsoft.OpenApi.Tests/PublicApi/PublicApiTests.cs @@ -26,7 +26,7 @@ public void ReviewPublicApiChanges() // It takes a human to read the change, determine if it is breaking and update the PublicApi.approved.txt with the new approved API surface // Arrange - var publicApi = typeof(OpenApiSpecVersion).Assembly.GeneratePublicApi(new ApiGeneratorOptions { AllowNamespacePrefixes = new[] { "Microsoft.OpenApi" } } ); + var publicApi = typeof(OpenApiSpecVersion).Assembly.GeneratePublicApi(new() { AllowNamespacePrefixes = new[] { "Microsoft.OpenApi" } } ); // Act var approvedFilePath = Path.Combine("PublicApi", "PublicApi.approved.txt"); diff --git a/test/Microsoft.OpenApi.Tests/Services/OpenApiUrlTreeNodeTests.cs b/test/Microsoft.OpenApi.Tests/Services/OpenApiUrlTreeNodeTests.cs index 0110cadf0..94a5556f3 100644 --- a/test/Microsoft.OpenApi.Tests/Services/OpenApiUrlTreeNodeTests.cs +++ b/test/Microsoft.OpenApi.Tests/Services/OpenApiUrlTreeNodeTests.cs @@ -15,42 +15,42 @@ namespace Microsoft.OpenApi.Tests.Services [UsesVerify] public class OpenApiUrlTreeNodeTests { - private OpenApiDocument OpenApiDocumentSample_1 => new OpenApiDocument + private OpenApiDocument OpenApiDocumentSample_1 => new() { - Paths = new OpenApiPaths + Paths = new() { - ["/"] = new OpenApiPathItem + ["/"] = new() { Operations = new Dictionary { - [OperationType.Get] = new OpenApiOperation(), + [OperationType.Get] = new(), } }, - ["/houses"] = new OpenApiPathItem + ["/houses"] = new() { Operations = new Dictionary { - [OperationType.Get] = new OpenApiOperation(), - [OperationType.Post] = new OpenApiOperation() + [OperationType.Get] = new(), + [OperationType.Post] = new() } }, - ["/cars"] = new OpenApiPathItem + ["/cars"] = new() { Operations = new Dictionary { - [OperationType.Post] = new OpenApiOperation() + [OperationType.Post] = new() } } } }; - private OpenApiDocument OpenApiDocumentSample_2 => new OpenApiDocument + private OpenApiDocument OpenApiDocumentSample_2 => new() { - Paths = new OpenApiPaths + Paths = new() { - ["/"] = new OpenApiPathItem(), - ["/hotels"] = new OpenApiPathItem(), - ["/offices"] = new OpenApiPathItem() + ["/"] = new(), + ["/hotels"] = new(), + ["/offices"] = new() } }; @@ -67,9 +67,9 @@ public void CreateSingleRootWorks() { var doc = new OpenApiDocument { - Paths = new OpenApiPaths + Paths = new() { - ["/"] = new OpenApiPathItem() + ["/"] = new() } }; @@ -87,9 +87,9 @@ public void CreatePathWithoutRootWorks() { var doc = new OpenApiDocument { - Paths = new OpenApiPaths + Paths = new() { - ["/houses"] = new OpenApiPathItem() + ["/houses"] = new() } }; @@ -155,10 +155,10 @@ public void AttachPathWorks() OperationType.Get, new OpenApiOperation { OperationId = "motorcycles.ListMotorcycle", - Responses = new OpenApiResponses + Responses = new() { { - "200", new OpenApiResponse + "200", new() { Description = "Retrieved entities" } @@ -180,10 +180,10 @@ public void AttachPathWorks() OperationType.Get, new OpenApiOperation { OperationId = "computers.ListComputer", - Responses = new OpenApiResponses + Responses = new() { { - "200", new OpenApiResponse + "200", new() { Description = "Retrieved entities" } @@ -210,11 +210,11 @@ public void CreatePathsWithMultipleSegmentsWorks() { var doc = new OpenApiDocument { - Paths = new OpenApiPaths + Paths = new() { - ["/"] = new OpenApiPathItem(), - ["/houses/apartments/{apartment-id}"] = new OpenApiPathItem(), - ["/cars/coupes"] = new OpenApiPathItem() + ["/"] = new(), + ["/houses/apartments/{apartment-id}"] = new(), + ["/cars/coupes"] = new() } }; @@ -235,11 +235,11 @@ public void HasOperationsWorks() { var doc1 = new OpenApiDocument { - Paths = new OpenApiPaths + Paths = new() { - ["/"] = new OpenApiPathItem(), - ["/houses"] = new OpenApiPathItem(), - ["/cars/{car-id}"] = new OpenApiPathItem + ["/"] = new(), + ["/houses"] = new(), + ["/cars/{car-id}"] = new() { Operations = new Dictionary { @@ -247,10 +247,10 @@ public void HasOperationsWorks() OperationType.Get, new OpenApiOperation { OperationId = "cars.GetCar", - Responses = new OpenApiResponses + Responses = new() { { - "200", new OpenApiResponse + "200", new() { Description = "Retrieved entity" } @@ -265,9 +265,9 @@ public void HasOperationsWorks() var doc2 = new OpenApiDocument { - Paths = new OpenApiPaths + Paths = new() { - ["/cars/{car-id}"] = new OpenApiPathItem + ["/cars/{car-id}"] = new() { Operations = new Dictionary { @@ -275,10 +275,10 @@ public void HasOperationsWorks() OperationType.Get, new OpenApiOperation { OperationId = "cars.GetCar", - Responses = new OpenApiResponses + Responses = new() { { - "200", new OpenApiResponse + "200", new() { Description = "Retrieved entity" } @@ -290,10 +290,10 @@ public void HasOperationsWorks() OperationType.Put, new OpenApiOperation { OperationId = "cars.UpdateCar", - Responses = new OpenApiResponses + Responses = new() { { - "204", new OpenApiResponse + "204", new() { Description = "Success." } @@ -329,10 +329,10 @@ public void SegmentIsParameterWorks() { var doc = new OpenApiDocument { - Paths = new OpenApiPaths + Paths = new() { - ["/"] = new OpenApiPathItem(), - ["/houses/apartments/{apartment-id}"] = new OpenApiPathItem() + ["/"] = new(), + ["/houses/apartments/{apartment-id}"] = new() } }; diff --git a/test/Microsoft.OpenApi.Tests/Services/OpenApiValidatorTests.cs b/test/Microsoft.OpenApi.Tests/Services/OpenApiValidatorTests.cs index 5aa96ba16..02eba9347 100644 --- a/test/Microsoft.OpenApi.Tests/Services/OpenApiValidatorTests.cs +++ b/test/Microsoft.OpenApi.Tests/Services/OpenApiValidatorTests.cs @@ -22,23 +22,23 @@ public class OpenApiValidatorTests public void ResponseMustHaveADescription() { var openApiDocument = new OpenApiDocument(); - openApiDocument.Info = new OpenApiInfo + openApiDocument.Info = new() { Title = "foo", Version = "1.2.2" }; - openApiDocument.Paths = new OpenApiPaths(); + openApiDocument.Paths = new(); openApiDocument.Paths.Add( "/test", - new OpenApiPathItem + new() { Operations = { - [OperationType.Get] = new OpenApiOperation + [OperationType.Get] = new() { Responses = { - ["200"] = new OpenApiResponse() + ["200"] = new() } } } @@ -61,21 +61,21 @@ public void ServersShouldBeReferencedByIndex() { var openApiDocument = new OpenApiDocument { - Info = new OpenApiInfo + Info = new() { Title = "foo", Version = "1.2.2" }, Servers = new List { - new OpenApiServer + new() { Url = "http://example.org" }, - new OpenApiServer + new() { }, }, - Paths = new OpenApiPaths() + Paths = new() }; var validator = new OpenApiValidator(ValidationRuleSet.GetDefaultRuleSet()); @@ -101,18 +101,18 @@ public void ValidateCustomExtension() { if (item.Bar == "hey") { - context.AddError(new OpenApiValidatorError("FooExtensionRule", context.PathString, "Don't say hey")); + context.AddError(new("FooExtensionRule", context.PathString, "Don't say hey")); } })); var openApiDocument = new OpenApiDocument { - Info = new OpenApiInfo + Info = new() { Title = "foo", Version = "1.2.2" }, - Paths = new OpenApiPaths() + Paths = new() }; var fooExtension = new FooExtension diff --git a/test/Microsoft.OpenApi.Tests/Validations/OpenApiHeaderValidationTests.cs b/test/Microsoft.OpenApi.Tests/Validations/OpenApiHeaderValidationTests.cs index cca17e011..b051c1a22 100644 --- a/test/Microsoft.OpenApi.Tests/Validations/OpenApiHeaderValidationTests.cs +++ b/test/Microsoft.OpenApi.Tests/Validations/OpenApiHeaderValidationTests.cs @@ -23,7 +23,7 @@ public void ValidateExampleShouldNotHaveDataTypeMismatchForSimpleSchema() { Required = true, Example = new OpenApiInteger(55), - Schema = new OpenApiSchema + Schema = new() { Type = "string", } @@ -59,21 +59,21 @@ public void ValidateExamplesShouldNotHaveDataTypeMismatchForSimpleSchema() var header = new OpenApiHeader { Required = true, - Schema = new OpenApiSchema + Schema = new() { Type = "object", - AdditionalProperties = new OpenApiSchema + AdditionalProperties = new() { Type = "integer", } }, Examples = { - ["example0"] = new OpenApiExample + ["example0"] = new() { Value = new OpenApiString("1"), }, - ["example1"] = new OpenApiExample + ["example1"] = new() { Value = new OpenApiObject { @@ -82,7 +82,7 @@ public void ValidateExamplesShouldNotHaveDataTypeMismatchForSimpleSchema() ["z"] = new OpenApiString("200") } }, - ["example2"] = new OpenApiExample + ["example2"] = new() { Value = new OpenApiArray @@ -90,7 +90,7 @@ public void ValidateExamplesShouldNotHaveDataTypeMismatchForSimpleSchema() new OpenApiInteger(3) } }, - ["example3"] = new OpenApiExample + ["example3"] = new() { Value = new OpenApiObject { diff --git a/test/Microsoft.OpenApi.Tests/Validations/OpenApiMediaTypeValidationTests.cs b/test/Microsoft.OpenApi.Tests/Validations/OpenApiMediaTypeValidationTests.cs index 48ddcce4d..d33cb02da 100644 --- a/test/Microsoft.OpenApi.Tests/Validations/OpenApiMediaTypeValidationTests.cs +++ b/test/Microsoft.OpenApi.Tests/Validations/OpenApiMediaTypeValidationTests.cs @@ -22,7 +22,7 @@ public void ValidateExampleShouldNotHaveDataTypeMismatchForSimpleSchema() var mediaType = new OpenApiMediaType { Example = new OpenApiInteger(55), - Schema = new OpenApiSchema + Schema = new() { Type = "string", } @@ -57,21 +57,21 @@ public void ValidateExamplesShouldNotHaveDataTypeMismatchForSimpleSchema() var mediaType = new OpenApiMediaType { - Schema = new OpenApiSchema + Schema = new() { Type = "object", - AdditionalProperties = new OpenApiSchema + AdditionalProperties = new() { Type = "integer", } }, Examples = { - ["example0"] = new OpenApiExample + ["example0"] = new() { Value = new OpenApiString("1"), }, - ["example1"] = new OpenApiExample + ["example1"] = new() { Value = new OpenApiObject { @@ -80,7 +80,7 @@ public void ValidateExamplesShouldNotHaveDataTypeMismatchForSimpleSchema() ["z"] = new OpenApiString("200") } }, - ["example2"] = new OpenApiExample + ["example2"] = new() { Value = new OpenApiArray @@ -88,7 +88,7 @@ public void ValidateExamplesShouldNotHaveDataTypeMismatchForSimpleSchema() new OpenApiInteger(3) } }, - ["example3"] = new OpenApiExample + ["example3"] = new() { Value = new OpenApiObject { diff --git a/test/Microsoft.OpenApi.Tests/Validations/OpenApiParameterValidationTests.cs b/test/Microsoft.OpenApi.Tests/Validations/OpenApiParameterValidationTests.cs index 1a3b5442b..27ea80c48 100644 --- a/test/Microsoft.OpenApi.Tests/Validations/OpenApiParameterValidationTests.cs +++ b/test/Microsoft.OpenApi.Tests/Validations/OpenApiParameterValidationTests.cs @@ -72,7 +72,7 @@ public void ValidateExampleShouldNotHaveDataTypeMismatchForSimpleSchema() In = ParameterLocation.Path, Required = true, Example = new OpenApiInteger(55), - Schema = new OpenApiSchema + Schema = new() { Type = "string", } @@ -110,21 +110,21 @@ public void ValidateExamplesShouldNotHaveDataTypeMismatchForSimpleSchema() Name = "parameter1", In = ParameterLocation.Path, Required = true, - Schema = new OpenApiSchema + Schema = new() { Type = "object", - AdditionalProperties = new OpenApiSchema + AdditionalProperties = new() { Type = "integer", } }, Examples = { - ["example0"] = new OpenApiExample + ["example0"] = new() { Value = new OpenApiString("1"), }, - ["example1"] = new OpenApiExample + ["example1"] = new() { Value = new OpenApiObject { @@ -133,7 +133,7 @@ public void ValidateExamplesShouldNotHaveDataTypeMismatchForSimpleSchema() ["z"] = new OpenApiString("200") } }, - ["example2"] = new OpenApiExample + ["example2"] = new() { Value = new OpenApiArray @@ -141,7 +141,7 @@ public void ValidateExamplesShouldNotHaveDataTypeMismatchForSimpleSchema() new OpenApiInteger(3) } }, - ["example3"] = new OpenApiExample + ["example3"] = new() { Value = new OpenApiObject { @@ -190,7 +190,7 @@ public void PathParameterNotInThePathShouldReturnAnError() Name = "parameter1", In = ParameterLocation.Path, Required = true, - Schema = new OpenApiSchema + Schema = new() { Type = "string", } @@ -228,7 +228,7 @@ public void PathParameterInThePathShouldBeOk() Name = "parameter1", In = ParameterLocation.Path, Required = true, - Schema = new OpenApiSchema + Schema = new() { Type = "string", } diff --git a/test/Microsoft.OpenApi.Tests/Validations/OpenApiReferenceValidationTests.cs b/test/Microsoft.OpenApi.Tests/Validations/OpenApiReferenceValidationTests.cs index 61b128e5f..b145f9ab9 100644 --- a/test/Microsoft.OpenApi.Tests/Validations/OpenApiReferenceValidationTests.cs +++ b/test/Microsoft.OpenApi.Tests/Validations/OpenApiReferenceValidationTests.cs @@ -21,7 +21,7 @@ public void ReferencedSchemaShouldOnlyBeValidatedOnce() var sharedSchema = new OpenApiSchema { Type = "string", - Reference = new OpenApiReference + Reference = new() { Id = "test" }, @@ -29,7 +29,7 @@ public void ReferencedSchemaShouldOnlyBeValidatedOnce() }; OpenApiDocument document = new OpenApiDocument(); - document.Components = new OpenApiComponents + document.Components = new() { Schemas = new Dictionary { @@ -37,21 +37,21 @@ public void ReferencedSchemaShouldOnlyBeValidatedOnce() } }; - document.Paths = new OpenApiPaths + document.Paths = new() { - ["/"] = new OpenApiPathItem + ["/"] = new() { Operations = new Dictionary { - [OperationType.Get] = new OpenApiOperation + [OperationType.Get] = new() { - Responses = new OpenApiResponses + Responses = new() { - ["200"] = new OpenApiResponse + ["200"] = new() { Content = new Dictionary { - ["application/json"] = new OpenApiMediaType + ["application/json"] = new() { Schema = sharedSchema } @@ -64,7 +64,7 @@ public void ReferencedSchemaShouldOnlyBeValidatedOnce() }; // Act - var errors = document.Validate(new ValidationRuleSet { new AlwaysFailRule() }); + var errors = document.Validate(new() { new AlwaysFailRule() }); // Assert Assert.True(errors.Count() == 1); @@ -77,7 +77,7 @@ public void UnresolvedReferenceSchemaShouldNotBeValidated() var sharedSchema = new OpenApiSchema { Type = "string", - Reference = new OpenApiReference + Reference = new() { Id = "test" }, @@ -85,7 +85,7 @@ public void UnresolvedReferenceSchemaShouldNotBeValidated() }; OpenApiDocument document = new OpenApiDocument(); - document.Components = new OpenApiComponents + document.Components = new() { Schemas = new Dictionary { @@ -94,7 +94,7 @@ public void UnresolvedReferenceSchemaShouldNotBeValidated() }; // Act - var errors = document.Validate(new ValidationRuleSet { new AlwaysFailRule() }); + var errors = document.Validate(new() { new AlwaysFailRule() }); // Assert Assert.True(errors.Count() == 0); @@ -107,7 +107,7 @@ public void UnresolvedSchemaReferencedShouldNotBeValidated() var sharedSchema = new OpenApiSchema { - Reference = new OpenApiReference + Reference = new() { Id = "test" }, @@ -116,21 +116,21 @@ public void UnresolvedSchemaReferencedShouldNotBeValidated() OpenApiDocument document = new OpenApiDocument(); - document.Paths = new OpenApiPaths + document.Paths = new() { - ["/"] = new OpenApiPathItem + ["/"] = new() { Operations = new Dictionary { - [OperationType.Get] = new OpenApiOperation + [OperationType.Get] = new() { - Responses = new OpenApiResponses + Responses = new() { - ["200"] = new OpenApiResponse + ["200"] = new() { Content = new Dictionary { - ["application/json"] = new OpenApiMediaType + ["application/json"] = new() { Schema = sharedSchema } @@ -143,7 +143,7 @@ public void UnresolvedSchemaReferencedShouldNotBeValidated() }; // Act - var errors = document.Validate(new ValidationRuleSet { new AlwaysFailRule() }); + var errors = document.Validate(new() { new AlwaysFailRule() }); // Assert Assert.True(errors.Count() == 0); diff --git a/test/Microsoft.OpenApi.Tests/Validations/OpenApiSchemaValidationTests.cs b/test/Microsoft.OpenApi.Tests/Validations/OpenApiSchemaValidationTests.cs index 1760b000f..bfe3706f1 100644 --- a/test/Microsoft.OpenApi.Tests/Validations/OpenApiSchemaValidationTests.cs +++ b/test/Microsoft.OpenApi.Tests/Validations/OpenApiSchemaValidationTests.cs @@ -109,7 +109,7 @@ public void ValidateEnumShouldNotHaveDataTypeMismatchForSimpleSchema() }, }, Type = "object", - AdditionalProperties = new OpenApiSchema + AdditionalProperties = new() { Type = "integer", } @@ -151,33 +151,33 @@ public void ValidateDefaultShouldNotHaveDataTypeMismatchForComplexSchema() Type = "object", Properties = { - ["property1"] = new OpenApiSchema + ["property1"] = new() { Type = "array", - Items = new OpenApiSchema + Items = new() { Type = "integer", Format = "int64" } }, - ["property2"] = new OpenApiSchema + ["property2"] = new() { Type = "array", - Items = new OpenApiSchema + Items = new() { Type = "object", - AdditionalProperties = new OpenApiSchema + AdditionalProperties = new() { Type = "boolean" } } }, - ["property3"] = new OpenApiSchema + ["property3"] = new() { Type = "string", Format = "password" }, - ["property4"] = new OpenApiSchema + ["property4"] = new() { Type = "string" } @@ -245,8 +245,8 @@ public void ValidateSchemaRequiredFieldListMustContainThePropertySpecifiedInTheD new OpenApiSchema { Type = "object", - Discriminator = new OpenApiDiscriminator { PropertyName = "property1" }, - Reference = new OpenApiReference { Id = "schema1" } + Discriminator = new() { PropertyName = "property1" }, + Reference = new() { Id = "schema1" } } } } @@ -263,7 +263,7 @@ public void ValidateSchemaRequiredFieldListMustContainThePropertySpecifiedInTheD result.Should().BeFalse(); errors.Should().BeEquivalentTo(new List { - new OpenApiValidatorError(nameof(OpenApiSchemaRules.ValidateSchemaDiscriminator),"#/schemas/schema1/discriminator", + new(nameof(OpenApiSchemaRules.ValidateSchemaDiscriminator),"#/schemas/schema1/discriminator", string.Format(SRResource.Validation_SchemaRequiredFieldListMustContainThePropertySpecifiedInTheDiscriminator, "schema1", "property1")) }); @@ -282,13 +282,13 @@ public void ValidateOneOfSchemaPropertyNameContainsPropertySpecifiedInTheDiscrim new OpenApiSchema { Type = "array", - Discriminator = new OpenApiDiscriminator + Discriminator = new() { PropertyName = "type" }, OneOf = new List { - new OpenApiSchema + new() { Properties = { @@ -300,14 +300,14 @@ public void ValidateOneOfSchemaPropertyNameContainsPropertySpecifiedInTheDiscrim } } }, - Reference = new OpenApiReference + Reference = new() { Type = ReferenceType.Schema, Id = "Person" } } }, - Reference = new OpenApiReference { Id = "Person" } + Reference = new() { Id = "Person" } } } } diff --git a/test/Microsoft.OpenApi.Tests/Visitors/InheritanceTests.cs b/test/Microsoft.OpenApi.Tests/Visitors/InheritanceTests.cs index 6a8286c1d..a4c73e4b1 100644 --- a/test/Microsoft.OpenApi.Tests/Visitors/InheritanceTests.cs +++ b/test/Microsoft.OpenApi.Tests/Visitors/InheritanceTests.cs @@ -66,7 +66,7 @@ public void ExpectedVirtualsInvolved() internal protected class TestVisitor : OpenApiVisitorBase { - public Stack CallStack { get; } = new Stack(); + public Stack CallStack { get; } = new(); private string EncodeCall([CallerMemberName] string name = "", [CallerLineNumber] int lineNumber = 0) { diff --git a/test/Microsoft.OpenApi.Tests/Walkers/WalkerLocationTests.cs b/test/Microsoft.OpenApi.Tests/Walkers/WalkerLocationTests.cs index 71b84bf16..09c808a1e 100644 --- a/test/Microsoft.OpenApi.Tests/Walkers/WalkerLocationTests.cs +++ b/test/Microsoft.OpenApi.Tests/Walkers/WalkerLocationTests.cs @@ -35,13 +35,13 @@ public void LocateTopLevelArrayItems() { Servers = new List { - new OpenApiServer(), - new OpenApiServer() + new(), + new() }, - Paths = new OpenApiPaths(), + Paths = new(), Tags = new List { - new OpenApiTag() + new() } }; @@ -64,23 +64,23 @@ public void LocatePathOperationContentSchema() { var doc = new OpenApiDocument { - Paths = new OpenApiPaths() + Paths = new() }; - doc.Paths.Add("/test", new OpenApiPathItem + doc.Paths.Add("/test", new() { Operations = new Dictionary { - [OperationType.Get] = new OpenApiOperation + [OperationType.Get] = new() { - Responses = new OpenApiResponses + Responses = new() { - ["200"] = new OpenApiResponse + ["200"] = new() { Content = new Dictionary { - ["application/json"] = new OpenApiMediaType + ["application/json"] = new() { - Schema = new OpenApiSchema + Schema = new() { Type = "string" } @@ -122,7 +122,7 @@ public void WalkDOMWithCycles() Type = "object", Properties = new Dictionary { - ["name"] = new OpenApiSchema { Type = "string" } + ["name"] = new() { Type = "string" } } }; @@ -130,8 +130,8 @@ public void WalkDOMWithCycles() var doc = new OpenApiDocument { - Paths = new OpenApiPaths(), - Components = new OpenApiComponents + Paths = new(), + Components = new() { Schemas = new Dictionary { @@ -162,7 +162,7 @@ public void LocateReferences() { var baseSchema = new OpenApiSchema { - Reference = new OpenApiReference + Reference = new() { Id = "base", Type = ReferenceType.Schema @@ -173,7 +173,7 @@ public void LocateReferences() var derivedSchema = new OpenApiSchema { AnyOf = new List { baseSchema }, - Reference = new OpenApiReference + Reference = new() { Id = "derived", Type = ReferenceType.Schema @@ -184,7 +184,7 @@ public void LocateReferences() var testHeader = new OpenApiHeader { Schema = derivedSchema, - Reference = new OpenApiReference + Reference = new() { Id = "test-header", Type = ReferenceType.Header @@ -194,21 +194,21 @@ public void LocateReferences() var doc = new OpenApiDocument { - Paths = new OpenApiPaths + Paths = new() { - ["/"] = new OpenApiPathItem + ["/"] = new() { Operations = new Dictionary { - [OperationType.Get] = new OpenApiOperation + [OperationType.Get] = new() { - Responses = new OpenApiResponses + Responses = new() { - ["200"] = new OpenApiResponse + ["200"] = new() { Content = new Dictionary { - ["application/json"] = new OpenApiMediaType + ["application/json"] = new() { Schema = derivedSchema } @@ -223,7 +223,7 @@ public void LocateReferences() } } }, - Components = new OpenApiComponents + Components = new() { Schemas = new Dictionary { @@ -252,8 +252,8 @@ public void LocateReferences() internal class LocatorVisitor : OpenApiVisitorBase { - public List Locations = new List(); - public List Keys = new List(); + public List Locations = new(); + public List Keys = new(); public override void Visit(OpenApiInfo info) { diff --git a/test/Microsoft.OpenApi.Tests/Workspaces/OpenApiReferencableTests.cs b/test/Microsoft.OpenApi.Tests/Workspaces/OpenApiReferencableTests.cs index c3b49e5f7..6e615bd26 100644 --- a/test/Microsoft.OpenApi.Tests/Workspaces/OpenApiReferencableTests.cs +++ b/test/Microsoft.OpenApi.Tests/Workspaces/OpenApiReferencableTests.cs @@ -14,27 +14,27 @@ namespace Microsoft.OpenApi.Tests.Workspaces { public class OpenApiReferencableTests { - private static readonly OpenApiCallback _callbackFragment = new OpenApiCallback(); - private static readonly OpenApiExample _exampleFragment = new OpenApiExample(); - private static readonly OpenApiLink _linkFragment = new OpenApiLink(); - private static readonly OpenApiHeader _headerFragment = new OpenApiHeader + private static readonly OpenApiCallback _callbackFragment = new(); + private static readonly OpenApiExample _exampleFragment = new(); + private static readonly OpenApiLink _linkFragment = new(); + private static readonly OpenApiHeader _headerFragment = new() { - Schema = new OpenApiSchema(), + Schema = new(), Examples = new Dictionary { { "example1", new OpenApiExample() } } }; - private static readonly OpenApiParameter _parameterFragment = new OpenApiParameter + private static readonly OpenApiParameter _parameterFragment = new() { - Schema = new OpenApiSchema(), + Schema = new(), Examples = new Dictionary { { "example1", new OpenApiExample() } } }; - private static readonly OpenApiRequestBody _requestBodyFragment = new OpenApiRequestBody(); - private static readonly OpenApiResponse _responseFragment = new OpenApiResponse + private static readonly OpenApiRequestBody _requestBodyFragment = new(); + private static readonly OpenApiResponse _responseFragment = new() { Headers = new Dictionary { @@ -45,9 +45,9 @@ public class OpenApiReferencableTests { "link1", new OpenApiLink() } } }; - private static readonly OpenApiSchema _schemaFragment = new OpenApiSchema(); - private static readonly OpenApiSecurityScheme _securitySchemeFragment = new OpenApiSecurityScheme(); - private static readonly OpenApiTag _tagFragment = new OpenApiTag(); + private static readonly OpenApiSchema _schemaFragment = new(); + private static readonly OpenApiSecurityScheme _securitySchemeFragment = new(); + private static readonly OpenApiTag _tagFragment = new(); public static IEnumerable ResolveReferenceCanResolveValidJsonPointersTestData => new List @@ -78,7 +78,7 @@ public void ResolveReferenceCanResolveValidJsonPointers( IOpenApiElement expectedResolvedElement) { // Act - var actualResolvedElement = element.ResolveReference(new JsonPointer(jsonPointer)); + var actualResolvedElement = element.ResolveReference(new(jsonPointer)); // Assert Assert.Same(expectedResolvedElement, actualResolvedElement); @@ -110,7 +110,7 @@ public void ResolveReferenceCanResolveValidJsonPointers( public void ResolveReferenceShouldThrowOnInvalidReferenceId(IOpenApiReferenceable element, string jsonPointer) { // Act - Action resolveReference = () => element.ResolveReference(new JsonPointer(jsonPointer)); + Action resolveReference = () => element.ResolveReference(new(jsonPointer)); // Assert var exception = Assert.Throws(resolveReference); diff --git a/test/Microsoft.OpenApi.Tests/Workspaces/OpenApiWorkspaceTests.cs b/test/Microsoft.OpenApi.Tests/Workspaces/OpenApiWorkspaceTests.cs index deb372016..f86295f35 100644 --- a/test/Microsoft.OpenApi.Tests/Workspaces/OpenApiWorkspaceTests.cs +++ b/test/Microsoft.OpenApi.Tests/Workspaces/OpenApiWorkspaceTests.cs @@ -17,8 +17,8 @@ public void OpenApiWorkspaceCanHoldMultipleDocuments() { var workspace = new OpenApiWorkspace(); - workspace.AddDocument("root", new OpenApiDocument()); - workspace.AddDocument("common", new OpenApiDocument()); + workspace.AddDocument("root", new()); + workspace.AddDocument("common", new()); Assert.Equal(2, workspace.Documents.Count()); } @@ -28,27 +28,27 @@ public void OpenApiWorkspacesAllowDocumentsToReferenceEachOther() { var workspace = new OpenApiWorkspace(); - workspace.AddDocument("root", new OpenApiDocument + workspace.AddDocument("root", new() { - Paths = new OpenApiPaths + Paths = new() { - ["/"] = new OpenApiPathItem + ["/"] = new() { Operations = new Dictionary { - [OperationType.Get] = new OpenApiOperation + [OperationType.Get] = new() { - Responses = new OpenApiResponses + Responses = new() { - ["200"] = new OpenApiResponse + ["200"] = new() { Content = new Dictionary { - ["application/json"] = new OpenApiMediaType + ["application/json"] = new() { - Schema = new OpenApiSchema + Schema = new() { - Reference = new OpenApiReference + Reference = new() { Id = "test", Type = ReferenceType.Schema @@ -63,12 +63,12 @@ public void OpenApiWorkspacesAllowDocumentsToReferenceEachOther() } } }); - workspace.AddDocument("common", new OpenApiDocument + workspace.AddDocument("common", new() { - Components = new OpenApiComponents + Components = new() { Schemas = { - ["test"] = new OpenApiSchema + ["test"] = new() { Type = "string", Description = "The referenced one" @@ -84,7 +84,7 @@ public void OpenApiWorkspacesCanResolveExternalReferences() { var workspace = new OpenApiWorkspace(); workspace.AddDocument("common", CreateCommonDocument()); - var schema = workspace.ResolveReference(new OpenApiReference {Id = "test", Type = ReferenceType.Schema, ExternalResource = "common"}) as OpenApiSchema; + var schema = workspace.ResolveReference(new() {Id = "test", Type = ReferenceType.Schema, ExternalResource = "common"}) as OpenApiSchema; Assert.NotNull(schema); Assert.Equal("The referenced one", schema.Description); @@ -104,9 +104,9 @@ public void OpenApiWorkspacesAllowDocumentsToReferenceEachOther_short() { re.Description = "Success"; re.CreateContent("application/json", co => - co.Schema = new OpenApiSchema + co.Schema = new() { - Reference = new OpenApiReference() // Reference + Reference = new() // Reference { Id = "test", Type = ReferenceType.Schema, ExternalResource = "common" }, @@ -131,8 +131,8 @@ public void OpenApiWorkspacesAllowDocumentsToReferenceEachOther_short() public void OpenApiWorkspacesShouldNormalizeDocumentLocations() { var workspace = new OpenApiWorkspace(); - workspace.AddDocument("hello", new OpenApiDocument()); - workspace.AddDocument("hi", new OpenApiDocument()); + workspace.AddDocument("hello", new()); + workspace.AddDocument("hi", new()); Assert.True(workspace.Contains("./hello")); Assert.True(workspace.Contains("./foo/../hello")); @@ -158,7 +158,7 @@ public void OpenApiWorkspacesCanResolveReferencesToDocumentFragments() workspace.AddFragment("fragment", schemaFragment); // Act - var schema = workspace.ResolveReference(new OpenApiReference {ExternalResource = "fragment"}) as OpenApiSchema; + var schema = workspace.ResolveReference(new() {ExternalResource = "fragment"}) as OpenApiSchema; // Assert Assert.NotNull(schema); @@ -180,7 +180,7 @@ public void OpenApiWorkspacesCanResolveReferencesToDocumentFragmentsWithJsonPoin workspace.AddFragment("fragment", responseFragment); // Act - var resolvedElement = workspace.ResolveReference(new OpenApiReference + var resolvedElement = workspace.ResolveReference(new() { Id = "headers/header1", ExternalResource = "fragment" @@ -193,12 +193,12 @@ public void OpenApiWorkspacesCanResolveReferencesToDocumentFragmentsWithJsonPoin // Test artifacts private static OpenApiDocument CreateCommonDocument() { - return new OpenApiDocument + return new() { - Components = new OpenApiComponents + Components = new() { Schemas = { - ["test"] = new OpenApiSchema + ["test"] = new() { Type = "string", Description = "The referenced one" @@ -215,7 +215,7 @@ public static OpenApiDocument CreatePathItem(this OpenApiDocument document, stri { var pathItem = new OpenApiPathItem(); config(pathItem); - document.Paths = new OpenApiPaths(); + document.Paths = new(); document.Paths.Add(path, pathItem); return document; } diff --git a/test/Microsoft.OpenApi.Tests/Writers/OpenApiJsonWriterTests.cs b/test/Microsoft.OpenApi.Tests/Writers/OpenApiJsonWriterTests.cs index 72c84505c..f53beb8e3 100644 --- a/test/Microsoft.OpenApi.Tests/Writers/OpenApiJsonWriterTests.cs +++ b/test/Microsoft.OpenApi.Tests/Writers/OpenApiJsonWriterTests.cs @@ -46,7 +46,7 @@ public void WriteStringListAsJsonShouldMatchExpected(string[] stringValues, bool { // Arrange var outputString = new StringWriter(CultureInfo.InvariantCulture); - var writer = new OpenApiJsonWriter(outputString, new OpenApiJsonWriterSettings { Terse = produceTerseOutput }); + var writer = new OpenApiJsonWriter(outputString, new() { Terse = produceTerseOutput }); // Act writer.WriteStartArray(); @@ -128,7 +128,7 @@ public static IEnumerable WriteMapAsJsonShouldMatchExpectedTestCasesCo new Dictionary { ["property1"] = new DateTime(1970, 01, 01), - ["property2"] = new DateTimeOffset(new DateTime(1970, 01, 01)), + ["property2"] = new DateTimeOffset(new(1970, 01, 01)), ["property3"] = new DateTime(2018, 04, 03), }, @@ -219,7 +219,7 @@ public void WriteMapAsJsonShouldMatchExpected(IDictionary inputM { // Arrange var outputString = new StringWriter(CultureInfo.InvariantCulture); - var writer = new OpenApiJsonWriter(outputString, new OpenApiJsonWriterSettings { Terse = produceTerseOutput }); + var writer = new OpenApiJsonWriter(outputString, new() { Terse = produceTerseOutput }); // Act WriteValueRecursive(writer, inputMap); @@ -235,8 +235,8 @@ public static IEnumerable WriteDateTimeAsJsonTestCases() { return from input in new DateTimeOffset[] { - new DateTimeOffset(2018, 1, 1, 10, 20, 30, TimeSpan.Zero), - new DateTimeOffset(2018, 1, 1, 10, 20, 30, 100, TimeSpan.FromHours(14)), + new(2018, 1, 1, 10, 20, 30, TimeSpan.Zero), + new(2018, 1, 1, 10, 20, 30, 100, TimeSpan.FromHours(14)), DateTimeOffset.UtcNow + TimeSpan.FromDays(4), DateTime.UtcNow + TimeSpan.FromDays(4), } @@ -250,7 +250,7 @@ public void WriteDateTimeAsJsonShouldMatchExpected(DateTimeOffset dateTimeOffset { // Arrange var outputString = new StringWriter(CultureInfo.InvariantCulture); - var writer = new OpenApiJsonWriter(outputString, new OpenApiJsonWriterSettings { Terse = produceTerseOutput }); + var writer = new OpenApiJsonWriter(outputString, new() { Terse = produceTerseOutput }); // Act writer.WriteValue(dateTimeOffset); diff --git a/test/Microsoft.OpenApi.Tests/Writers/OpenApiWriterAnyExtensionsTests.cs b/test/Microsoft.OpenApi.Tests/Writers/OpenApiWriterAnyExtensionsTests.cs index 6e6ab8ba3..7c378c16f 100644 --- a/test/Microsoft.OpenApi.Tests/Writers/OpenApiWriterAnyExtensionsTests.cs +++ b/test/Microsoft.OpenApi.Tests/Writers/OpenApiWriterAnyExtensionsTests.cs @@ -265,7 +265,7 @@ private static string WriteAsJson(IOpenApiAny any, bool produceTerseOutput = fal var stream = new MemoryStream(); IOpenApiWriter writer = new OpenApiJsonWriter( new StreamWriter(stream), - new OpenApiJsonWriterSettings { Terse = produceTerseOutput }); + new() { Terse = produceTerseOutput }); writer.WriteAny(any); writer.Flush(); diff --git a/test/Microsoft.OpenApi.Tests/Writers/OpenApiWriterSpecialCharacterTests.cs b/test/Microsoft.OpenApi.Tests/Writers/OpenApiWriterSpecialCharacterTests.cs index 64ccdac64..5e738ecc6 100644 --- a/test/Microsoft.OpenApi.Tests/Writers/OpenApiWriterSpecialCharacterTests.cs +++ b/test/Microsoft.OpenApi.Tests/Writers/OpenApiWriterSpecialCharacterTests.cs @@ -43,7 +43,7 @@ public void WriteStringWithSpecialCharactersAsJsonWorks(string input, string exp { // Arrange var outputStringWriter = new StringWriter(CultureInfo.InvariantCulture); - var writer = new OpenApiJsonWriter(outputStringWriter, new OpenApiJsonWriterSettings { Terse = produceTerseOutput }); + var writer = new OpenApiJsonWriter(outputStringWriter, new() { Terse = produceTerseOutput }); // Act writer.WriteValue(input); diff --git a/test/Microsoft.OpenApi.Tests/Writers/OpenApiYamlWriterTests.cs b/test/Microsoft.OpenApi.Tests/Writers/OpenApiYamlWriterTests.cs index 2bd5bab5e..74e6a7d27 100644 --- a/test/Microsoft.OpenApi.Tests/Writers/OpenApiYamlWriterTests.cs +++ b/test/Microsoft.OpenApi.Tests/Writers/OpenApiYamlWriterTests.cs @@ -385,7 +385,7 @@ public void WriteInlineSchema() """; var outputString = new StringWriter(CultureInfo.InvariantCulture); - var writer = new OpenApiYamlWriter(outputString, new OpenApiWriterSettings { InlineLocalReferences = true } ); + var writer = new OpenApiYamlWriter(outputString, new() { InlineLocalReferences = true } ); // Act doc.SerializeAsV3(writer); @@ -421,7 +421,7 @@ public void WriteInlineSchemaV2() """; var outputString = new StringWriter(CultureInfo.InvariantCulture); - var writer = new OpenApiYamlWriter(outputString, new OpenApiWriterSettings { InlineLocalReferences = true }); + var writer = new OpenApiYamlWriter(outputString, new() { InlineLocalReferences = true }); // Act doc.SerializeAsV2(writer); @@ -440,7 +440,7 @@ private static OpenApiDocument CreateDocWithSimpleSchemaToInline() { Type = "object", UnresolvedReference = false, - Reference = new OpenApiReference + Reference = new() { Id = "thing", Type = ReferenceType.Schema @@ -449,23 +449,24 @@ private static OpenApiDocument CreateDocWithSimpleSchemaToInline() var doc = new OpenApiDocument { - Info = new OpenApiInfo + Info = new() { Title = "Demo", Version = "1.0.0" }, - Paths = new OpenApiPaths + Paths = new() { - ["/"] = new OpenApiPathItem + ["/"] = new() { Operations = { - [OperationType.Get] = new OpenApiOperation + [OperationType.Get] = new() { Responses = { - ["200"] = new OpenApiResponse { + ["200"] = new() + { Description = "OK", Content = { - ["application/json"] = new OpenApiMediaType + ["application/json"] = new() { Schema = thingSchema } @@ -476,7 +477,7 @@ private static OpenApiDocument CreateDocWithSimpleSchemaToInline() } } }, - Components = new OpenApiComponents + Components = new() { Schemas = { ["thing"] = thingSchema} @@ -533,7 +534,7 @@ public void WriteInlineRecursiveSchema() // Component schemas that are there due to cycles are still inlined because the items they reference may not exist in the components because they don't have cycles. var outputString = new StringWriter(CultureInfo.InvariantCulture); - var writer = new OpenApiYamlWriter(outputString, new OpenApiWriterSettings { InlineLocalReferences = true }); + var writer = new OpenApiYamlWriter(outputString, new() { InlineLocalReferences = true }); // Act doc.SerializeAsV3(writer); @@ -551,7 +552,7 @@ private static OpenApiDocument CreateDocWithRecursiveSchemaReference() { Type = "object", UnresolvedReference = false, - Reference = new OpenApiReference + Reference = new() { Id = "thing", Type = ReferenceType.Schema @@ -568,23 +569,24 @@ private static OpenApiDocument CreateDocWithRecursiveSchemaReference() var doc = new OpenApiDocument { - Info = new OpenApiInfo + Info = new() { Title = "Demo", Version = "1.0.0" }, - Paths = new OpenApiPaths + Paths = new() { - ["/"] = new OpenApiPathItem + ["/"] = new() { Operations = { - [OperationType.Get] = new OpenApiOperation + [OperationType.Get] = new() { Responses = { - ["200"] = new OpenApiResponse { + ["200"] = new() + { Description = "OK", Content = { - ["application/json"] = new OpenApiMediaType + ["application/json"] = new() { Schema = thingSchema } @@ -595,7 +597,7 @@ private static OpenApiDocument CreateDocWithRecursiveSchemaReference() } } }, - Components = new OpenApiComponents + Components = new() { Schemas = { ["thing"] = thingSchema} @@ -649,7 +651,7 @@ public void WriteInlineRecursiveSchemav2() // Component schemas that are there due to cycles are still inlined because the items they reference may not exist in the components because they don't have cycles. var outputString = new StringWriter(CultureInfo.InvariantCulture); - var writer = new OpenApiYamlWriter(outputString, new OpenApiWriterSettings { InlineLocalReferences = true }); + var writer = new OpenApiYamlWriter(outputString, new() { InlineLocalReferences = true }); // Act doc.SerializeAsV2(writer);