Skip to content

Commit 51f8923

Browse files
committed
use some target typed new
1 parent cdf9f84 commit 51f8923

File tree

187 files changed

+1857
-1879
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

187 files changed

+1857
-1879
lines changed

src/Microsoft.OpenApi.Hidi/Formatters/PowerShellFormatter.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -163,10 +163,10 @@ private static IList<OpenApiParameter> ResolveFunctionParameters(IList<OpenApiPa
163163
// Replace content with a schema object of type array
164164
// for structured or collection-valued function parameters
165165
parameter.Content = null;
166-
parameter.Schema = new OpenApiSchema
166+
parameter.Schema = new()
167167
{
168168
Type = "array",
169-
Items = new OpenApiSchema
169+
Items = new()
170170
{
171171
Type = "string"
172172
}
@@ -179,7 +179,7 @@ private void AddAdditionalPropertiesToSchema(OpenApiSchema schema)
179179
{
180180
if (schema != null && !_schemaLoop.Contains(schema) && "object".Equals(schema.Type, StringComparison.OrdinalIgnoreCase))
181181
{
182-
schema.AdditionalProperties = new OpenApiSchema { Type = "object" };
182+
schema.AdditionalProperties = new() { Type = "object" };
183183

184184
/* Because 'additionalProperties' are now being walked,
185185
* we need a way to keep track of visited schemas to avoid

src/Microsoft.OpenApi.Hidi/OpenApiService.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public static async Task TransformOpenApiDocument(HidiOptions options, ILogger l
5353
if (options.Output == null)
5454
{
5555
var inputExtension = GetInputPathExtension(options.OpenApi, options.Csdl);
56-
options.Output = new FileInfo($"./output{inputExtension}");
56+
options.Output = new($"./output{inputExtension}");
5757
};
5858

5959
if (options.CleanOutput && options.Output.Exists)
@@ -194,7 +194,7 @@ private static void WriteOpenApi(HidiOptions options, OpenApiFormat openApiForma
194194

195195
IOpenApiWriter writer = openApiFormat switch
196196
{
197-
OpenApiFormat.Json => options.TerseOutput ? new OpenApiJsonWriter(textWriter, settings, options.TerseOutput) : new OpenApiJsonWriter(textWriter, settings, false),
197+
OpenApiFormat.Json => options.TerseOutput ? new(textWriter, settings, options.TerseOutput) : new OpenApiJsonWriter(textWriter, settings, false),
198198
OpenApiFormat.Yaml => new OpenApiYamlWriter(textWriter, settings),
199199
_ => throw new ArgumentException("Unknown format"),
200200
};
@@ -368,11 +368,11 @@ private static async Task<ReadResult> ParseOpenApi(string openApiFile, bool inli
368368
{
369369
stopwatch.Start();
370370

371-
result = await new OpenApiStreamReader(new OpenApiReaderSettings
372-
{
371+
result = await new OpenApiStreamReader(new()
372+
{
373373
LoadExternalRefs = inlineExternal,
374374
BaseUrl = openApiFile.StartsWith("http", StringComparison.OrdinalIgnoreCase) ?
375-
new Uri(openApiFile) :
375+
new(openApiFile) :
376376
new Uri("file://" + new FileInfo(openApiFile).DirectoryName + Path.DirectorySeparatorChar)
377377
}
378378
).ReadAsync(stream, cancellationToken).ConfigureAwait(false);
@@ -459,7 +459,7 @@ private static Dictionary<string, List<string>> EnumerateJsonDocument(JsonElemen
459459
}
460460
else
461461
{
462-
paths.Add(path, new List<string> {method});
462+
paths.Add(path, new() {method});
463463
}
464464
}
465465
else
@@ -741,7 +741,7 @@ internal static async Task PluginManifest(HidiOptions options, ILogger logger, C
741741
outputFolder.Create();
742742
}
743743
// Write OpenAPI to Output folder
744-
options.Output = new FileInfo(Path.Combine(options.OutputFolder, "openapi.json"));
744+
options.Output = new(Path.Combine(options.OutputFolder, "openapi.json"));
745745
options.TerseOutput = true;
746746
WriteOpenApi(options, OpenApiFormat.Json, OpenApiSpecVersion.OpenApi3_0, document, logger);
747747

@@ -762,7 +762,7 @@ internal static async Task PluginManifest(HidiOptions options, ILogger logger, C
762762
// Write OpenAIPluginManifest to Output folder
763763
var manifestFile = new FileInfo(Path.Combine(options.OutputFolder, "ai-plugin.json"));
764764
using var file = new FileStream(manifestFile.FullName, FileMode.Create);
765-
using var jsonWriter = new Utf8JsonWriter(file, new JsonWriterOptions { Indented = true });
765+
using var jsonWriter = new Utf8JsonWriter(file, new() { Indented = true });
766766
manifest.Write(jsonWriter);
767767
await jsonWriter.FlushAsync(cancellationToken).ConfigureAwait(false);
768768
}

src/Microsoft.OpenApi.Hidi/Options/HidiOptions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ private void ParseHidiOptions(ParseResult parseResult, CommandOptions options)
5353
LogLevel = parseResult.GetValueForOption(options.LogLevelOption);
5454
InlineLocal = parseResult.GetValueForOption(options.InlineLocalOption);
5555
InlineExternal = parseResult.GetValueForOption(options.InlineExternalOption);
56-
FilterOptions = new FilterOptions
56+
FilterOptions = new()
5757
{
5858
FilterByOperationIds = parseResult.GetValueForOption(options.FilterByOperationIdsOption),
5959
FilterByTags = parseResult.GetValueForOption(options.FilterByTagsOption),

src/Microsoft.OpenApi.Readers/OpenApiDiagnostic.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,12 @@ public void AppendDiagnostic(OpenApiDiagnostic diagnosticToAdd, string fileNameT
3939
foreach (var err in diagnosticToAdd.Errors)
4040
{
4141
var errMsgWithFileName = fileNameIsSupplied ? $"[File: {fileNameToAdd}] {err.Message}" : err.Message;
42-
Errors.Add(new OpenApiError(err.Pointer, errMsgWithFileName));
42+
Errors.Add(new(err.Pointer, errMsgWithFileName));
4343
}
4444
foreach (var warn in diagnosticToAdd.Warnings)
4545
{
4646
var warnMsgWithFileName = fileNameIsSupplied ? $"[File: {fileNameToAdd}] {warn.Message}" : warn.Message;
47-
Warnings.Add(new OpenApiError(warn.Pointer, warnMsgWithFileName));
47+
Warnings.Add(new(warn.Pointer, warnMsgWithFileName));
4848
}
4949
}
5050
}

src/Microsoft.OpenApi.Readers/OpenApiReaderSettings.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public class OpenApiReaderSettings
5050
/// <summary>
5151
/// Dictionary of parsers for converting extensions into strongly typed classes
5252
/// </summary>
53-
public Dictionary<string, Func<IOpenApiAny, OpenApiSpecVersion, IOpenApiExtension>> ExtensionParsers { get; set; } = new Dictionary<string, Func<IOpenApiAny, OpenApiSpecVersion, IOpenApiExtension>>();
53+
public Dictionary<string, Func<IOpenApiAny, OpenApiSpecVersion, IOpenApiExtension>> ExtensionParsers { get; set; } = new();
5454

5555
/// <summary>
5656
/// Rules to use for validating OpenAPI specification. If none are provided a default set of rules are applied.

src/Microsoft.OpenApi.Readers/OpenApiStreamReader.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public async Task<ReadResult> ReadAsync(Stream input, CancellationToken cancella
6868
{
6969
// Buffer stream so that OpenApiTextReaderReader can process it synchronously
7070
// YamlDocument doesn't support async reading.
71-
bufferedStream = new MemoryStream();
71+
bufferedStream = new();
7272
await input.CopyToAsync(bufferedStream, 81920, cancellationToken);
7373
bufferedStream.Position = 0;
7474
}

src/Microsoft.OpenApi.Readers/OpenApiTextReaderReader.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@ public OpenApiDocument Read(TextReader input, out OpenApiDiagnostic diagnostic)
4646
}
4747
catch (YamlException ex)
4848
{
49-
diagnostic = new OpenApiDiagnostic();
50-
diagnostic.Errors.Add(new OpenApiError($"#line={ex.Start.Line}", ex.Message));
51-
return new OpenApiDocument();
49+
diagnostic = new();
50+
diagnostic.Errors.Add(new($"#line={ex.Start.Line}", ex.Message));
51+
return new();
5252
}
5353

5454
return new OpenApiYamlDocumentReader(this._settings).Read(yamlDocument, out diagnostic);
@@ -72,8 +72,8 @@ public async Task<ReadResult> ReadAsync(TextReader input, CancellationToken canc
7272
catch (YamlException ex)
7373
{
7474
var diagnostic = new OpenApiDiagnostic();
75-
diagnostic.Errors.Add(new OpenApiError($"#line={ex.Start.Line}", ex.Message));
76-
return new ReadResult
75+
diagnostic.Errors.Add(new($"#line={ex.Start.Line}", ex.Message));
76+
return new()
7777
{
7878
OpenApiDocument = null,
7979
OpenApiDiagnostic = diagnostic
@@ -101,8 +101,8 @@ public T ReadFragment<T>(TextReader input, OpenApiSpecVersion version, out OpenA
101101
}
102102
catch (YamlException ex)
103103
{
104-
diagnostic = new OpenApiDiagnostic();
105-
diagnostic.Errors.Add(new OpenApiError($"#line={ex.Start.Line}", ex.Message));
104+
diagnostic = new();
105+
diagnostic.Errors.Add(new($"#line={ex.Start.Line}", ex.Message));
106106
return default;
107107
}
108108

src/Microsoft.OpenApi.Readers/OpenApiYamlDocumentReader.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public OpenApiYamlDocumentReader(OpenApiReaderSettings settings = null)
4242
/// <returns>Instance of newly created OpenApiDocument</returns>
4343
public OpenApiDocument Read(YamlDocument input, out OpenApiDiagnostic diagnostic)
4444
{
45-
diagnostic = new OpenApiDiagnostic();
45+
diagnostic = new();
4646
var context = new ParsingContext(diagnostic)
4747
{
4848
ExtensionParsers = _settings.ExtensionParsers,
@@ -65,7 +65,7 @@ public OpenApiDocument Read(YamlDocument input, out OpenApiDiagnostic diagnostic
6565
}
6666
catch (OpenApiException ex)
6767
{
68-
diagnostic.Errors.Add(new OpenApiError(ex));
68+
diagnostic.Errors.Add(new(ex));
6969
}
7070

7171
// Validate the document
@@ -115,7 +115,7 @@ public async Task<ReadResult> ReadAsync(YamlDocument input, CancellationToken ca
115115
}
116116
catch (OpenApiException ex)
117117
{
118-
diagnostic.Errors.Add(new OpenApiError(ex));
118+
diagnostic.Errors.Add(new(ex));
119119
}
120120

121121
// Validate the document
@@ -132,7 +132,7 @@ public async Task<ReadResult> ReadAsync(YamlDocument input, CancellationToken ca
132132
}
133133
}
134134

135-
return new ReadResult
135+
return new()
136136
{
137137
OpenApiDocument = document,
138138
OpenApiDiagnostic = diagnostic
@@ -147,7 +147,7 @@ private Task<OpenApiDiagnostic> LoadExternalRefs(OpenApiDocument document, Cance
147147
// Load this root document into the workspace
148148
var streamLoader = new DefaultStreamLoader(_settings.BaseUrl);
149149
var workspaceLoader = new OpenApiWorkspaceLoader(openApiWorkSpace, _settings.CustomExternalLoader ?? streamLoader, _settings);
150-
return workspaceLoader.LoadAsync(new OpenApiReference { ExternalResource = "/" }, document, null, cancellationToken);
150+
return workspaceLoader.LoadAsync(new() { ExternalResource = "/" }, document, null, cancellationToken);
151151
}
152152

153153
private void ResolveReferences(OpenApiDiagnostic diagnostic, OpenApiDocument document)
@@ -181,7 +181,7 @@ private void ResolveReferences(OpenApiDiagnostic diagnostic, OpenApiDocument doc
181181
/// <returns>Instance of newly created OpenApiDocument</returns>
182182
public T ReadFragment<T>(YamlDocument input, OpenApiSpecVersion version, out OpenApiDiagnostic diagnostic) where T : IOpenApiElement
183183
{
184-
diagnostic = new OpenApiDiagnostic();
184+
diagnostic = new();
185185
var context = new ParsingContext(diagnostic)
186186
{
187187
ExtensionParsers = _settings.ExtensionParsers
@@ -195,7 +195,7 @@ public T ReadFragment<T>(YamlDocument input, OpenApiSpecVersion version, out Ope
195195
}
196196
catch (OpenApiException ex)
197197
{
198-
diagnostic.Errors.Add(new OpenApiError(ex));
198+
diagnostic.Errors.Add(new(ex));
199199
}
200200

201201
// Validate the element

src/Microsoft.OpenApi.Readers/ParseNodes/ListNode.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public override List<T> CreateList<T>(Func<MapNode, T> map)
2929
$"Expected list at line {_nodeList.Start.Line} while parsing {typeof(T).Name}", _nodeList);
3030
}
3131

32-
return _nodeList.Select(n => map(new MapNode(Context, n as YamlMappingNode)))
32+
return _nodeList.Select(n => map(new(Context, n as YamlMappingNode)))
3333
.Where(i => i != null)
3434
.ToList();
3535
}
@@ -49,7 +49,7 @@ public override List<T> CreateSimpleList<T>(Func<ValueNode, T> map)
4949
$"Expected list at line {_nodeList.Start.Line} while parsing {typeof(T).Name}", _nodeList);
5050
}
5151

52-
return _nodeList.Select(n => map(new ValueNode(Context, n))).ToList();
52+
return _nodeList.Select(n => map(new(Context, n))).ToList();
5353
}
5454

5555
public IEnumerator<ParseNode> GetEnumerator()

src/Microsoft.OpenApi.Readers/ParseNodes/MapNode.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public PropertyNode this[string key]
4949
{
5050
if (this._node.Children.TryGetValue(new YamlScalarNode(key), out var node))
5151
{
52-
return new PropertyNode(Context, key, node);
52+
return new(Context, key, node);
5353
}
5454

5555
return null;
@@ -74,7 +74,7 @@ public override Dictionary<string, T> CreateMap<T>(Func<MapNode, T> map)
7474
Context.StartObject(key);
7575
value = n.Value as YamlMappingNode == null
7676
? default
77-
: map(new MapNode(Context, n.Value as YamlMappingNode));
77+
: map(new(Context, n.Value as YamlMappingNode));
7878
}
7979
finally
8080
{
@@ -110,7 +110,7 @@ public override Dictionary<string, T> CreateMapWithReference<T>(
110110
Context.StartObject(key);
111111
entry = (
112112
key: key,
113-
value: map(new MapNode(Context, (YamlMappingNode)n.Value))
113+
value: map(new(Context, (YamlMappingNode)n.Value))
114114
);
115115
if (entry.value == null)
116116
{
@@ -119,7 +119,7 @@ public override Dictionary<string, T> CreateMapWithReference<T>(
119119
// If the component isn't a reference to another component, then point it to itself.
120120
if (entry.value.Reference == null)
121121
{
122-
entry.value.Reference = new OpenApiReference
122+
entry.value.Reference = new()
123123
{
124124
Type = referenceType,
125125
Id = entry.key
@@ -155,7 +155,7 @@ public override Dictionary<string, T> CreateSimpleMap<T>(Func<ValueNode, T> map)
155155
{
156156
throw new OpenApiReaderException($"Expected scalar while parsing {typeof(T).Name}", Context);
157157
}
158-
return (key, value: map(new ValueNode(Context, (YamlScalarNode)n.Value)));
158+
return (key, value: map(new(Context, (YamlScalarNode)n.Value)));
159159
} finally {
160160
Context.EndObject();
161161
}
@@ -175,14 +175,14 @@ IEnumerator IEnumerable.GetEnumerator()
175175

176176
public override string GetRaw()
177177
{
178-
var x = new Serializer(new SerializerSettings(new JsonSchema()) { EmitJsonComptible = true });
178+
var x = new Serializer(new(new JsonSchema()) { EmitJsonComptible = true });
179179
return x.Serialize(_node);
180180
}
181181

182182
public T GetReferencedObject<T>(ReferenceType referenceType, string referenceId)
183183
where T : IOpenApiReferenceable, new()
184184
{
185-
return new T
185+
return new()
186186
{
187187
UnresolvedReference = true,
188188
Reference = Context.VersionService.ConvertToOpenApiReference(referenceId, referenceType)

0 commit comments

Comments
 (0)