Skip to content

Commit d302b5d

Browse files
committed
Fix merge conflict
2 parents 2102659 + 45b0e5e commit d302b5d

File tree

11 files changed

+157
-143
lines changed

11 files changed

+157
-143
lines changed

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ public override void Visit(OpenApiSchema schema)
5252

5353
public override void Visit(OpenApiPathItem pathItem)
5454
{
55-
if (pathItem.Operations.TryGetValue(OperationType.Put, out var value))
55+
if (pathItem.Operations.TryGetValue(OperationType.Put, out var value) &&
56+
value.OperationId != null)
5657
{
5758
var operationId = value.OperationId;
5859
pathItem.Operations[OperationType.Put].OperationId = ResolvePutOperationId(operationId);
@@ -67,14 +68,14 @@ public override void Visit(OpenApiOperation operation)
6768
throw new ArgumentException($"OperationId is required {PathString}", nameof(operation));
6869

6970
var operationId = operation.OperationId;
70-
var operationTypeExtension = operation.Extensions.GetExtension("x-ms-docs-operation-type");
71+
var operationTypeExtension = operation.Extensions?.GetExtension("x-ms-docs-operation-type");
7172
if (operationTypeExtension.IsEquals("function"))
72-
operation.Parameters = ResolveFunctionParameters(operation.Parameters);
73+
operation.Parameters = ResolveFunctionParameters(operation.Parameters ?? new List<OpenApiParameter>());
7374

7475
// Order matters. Resolve operationId.
7576
operationId = RemoveHashSuffix(operationId);
7677
if (operationTypeExtension.IsEquals("action") || operationTypeExtension.IsEquals("function"))
77-
operationId = RemoveKeyTypeSegment(operationId, operation.Parameters);
78+
operationId = RemoveKeyTypeSegment(operationId, operation.Parameters ?? new List<OpenApiParameter>());
7879
operationId = SingularizeAndDeduplicateOperationId(operationId.SplitByChar('.'));
7980
operationId = ResolveODataCastOperationId(operationId);
8081
operationId = ResolveByRefOperationId(operationId);

src/Microsoft.OpenApi/Models/OpenApiComponents.cs

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using Microsoft.OpenApi.Models.References;
99
using Microsoft.OpenApi.Writers;
1010

11+
#nullable enable
1112

1213
namespace Microsoft.OpenApi.Models
1314
{
@@ -19,60 +20,60 @@ public class OpenApiComponents : IOpenApiSerializable, IOpenApiExtensible
1920
/// <summary>
2021
/// An object to hold reusable <see cref="OpenApiSchema"/> Objects.
2122
/// </summary>
22-
public IDictionary<string, OpenApiSchema> Schemas { get; set; } = new Dictionary<string, OpenApiSchema>();
23+
public IDictionary<string, OpenApiSchema>? Schemas { get; set; } = new Dictionary<string, OpenApiSchema>();
2324

2425
/// <summary>
2526
/// An object to hold reusable <see cref="OpenApiResponse"/> Objects.
2627
/// </summary>
27-
public virtual IDictionary<string, OpenApiResponse> Responses { get; set; } = new Dictionary<string, OpenApiResponse>();
28+
public virtual IDictionary<string, OpenApiResponse>? Responses { get; set; } = new Dictionary<string, OpenApiResponse>();
2829

2930
/// <summary>
3031
/// An object to hold reusable <see cref="OpenApiParameter"/> Objects.
3132
/// </summary>
32-
public virtual IDictionary<string, OpenApiParameter> Parameters { get; set; } =
33+
public virtual IDictionary<string, OpenApiParameter>? Parameters { get; set; } =
3334
new Dictionary<string, OpenApiParameter>();
3435

3536
/// <summary>
3637
/// An object to hold reusable <see cref="OpenApiExample"/> Objects.
3738
/// </summary>
38-
public virtual IDictionary<string, OpenApiExample> Examples { get; set; } = new Dictionary<string, OpenApiExample>();
39+
public virtual IDictionary<string, OpenApiExample>? Examples { get; set; } = new Dictionary<string, OpenApiExample>();
3940

4041
/// <summary>
4142
/// An object to hold reusable <see cref="OpenApiRequestBody"/> Objects.
4243
/// </summary>
43-
public virtual IDictionary<string, OpenApiRequestBody> RequestBodies { get; set; } =
44+
public virtual IDictionary<string, OpenApiRequestBody>? RequestBodies { get; set; } =
4445
new Dictionary<string, OpenApiRequestBody>();
4546

4647
/// <summary>
4748
/// An object to hold reusable <see cref="OpenApiHeader"/> Objects.
4849
/// </summary>
49-
public virtual IDictionary<string, OpenApiHeader> Headers { get; set; } = new Dictionary<string, OpenApiHeader>();
50+
public virtual IDictionary<string, OpenApiHeader>? Headers { get; set; } = new Dictionary<string, OpenApiHeader>();
5051

5152
/// <summary>
5253
/// An object to hold reusable <see cref="OpenApiSecurityScheme"/> Objects.
5354
/// </summary>
54-
public virtual IDictionary<string, OpenApiSecurityScheme> SecuritySchemes { get; set; } =
55+
public virtual IDictionary<string, OpenApiSecurityScheme>? SecuritySchemes { get; set; } =
5556
new Dictionary<string, OpenApiSecurityScheme>();
5657

5758
/// <summary>
5859
/// An object to hold reusable <see cref="OpenApiLink"/> Objects.
5960
/// </summary>
60-
public virtual IDictionary<string, OpenApiLink> Links { get; set; } = new Dictionary<string, OpenApiLink>();
61+
public virtual IDictionary<string, OpenApiLink>? Links { get; set; } = new Dictionary<string, OpenApiLink>();
6162

6263
/// <summary>
6364
/// An object to hold reusable <see cref="OpenApiCallback"/> Objects.
6465
/// </summary>
65-
public virtual IDictionary<string, OpenApiCallback> Callbacks { get; set; } = new Dictionary<string, OpenApiCallback>();
66+
public virtual IDictionary<string, OpenApiCallback>? Callbacks { get; set; } = new Dictionary<string, OpenApiCallback>();
6667

6768
/// <summary>
6869
/// An object to hold reusable <see cref="OpenApiPathItem"/> Object.
6970
/// </summary>
70-
public virtual IDictionary<string, OpenApiPathItem> PathItems { get; set; } = new Dictionary<string, OpenApiPathItem>();
71+
public virtual IDictionary<string, OpenApiPathItem>? PathItems { get; set; } = new Dictionary<string, OpenApiPathItem>();
7172

7273
/// <summary>
7374
/// This object MAY be extended with Specification Extensions.
7475
/// </summary>
75-
public virtual IDictionary<string, IOpenApiExtension> Extensions { get; set; } = new Dictionary<string, IOpenApiExtension>();
76+
public virtual IDictionary<string, IOpenApiExtension>? Extensions { get; set; } = new Dictionary<string, IOpenApiExtension>();
7677

7778
/// <summary>
7879
/// Parameter-less constructor
@@ -82,7 +83,7 @@ public OpenApiComponents() { }
8283
/// <summary>
8384
/// Initializes a copy of an <see cref="OpenApiComponents"/> object
8485
/// </summary>
85-
public OpenApiComponents(OpenApiComponents components)
86+
public OpenApiComponents(OpenApiComponents? components)
8687
{
8788
Schemas = components?.Schemas != null ? new Dictionary<string, OpenApiSchema>(components.Schemas) : null;
8889
Responses = components?.Responses != null ? new Dictionary<string, OpenApiResponse>(components.Responses) : null;

src/Microsoft.OpenApi/Models/OpenApiDocument.cs

Lines changed: 34 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
using Microsoft.OpenApi.Services;
1717
using Microsoft.OpenApi.Writers;
1818

19+
#nullable enable
20+
1921
namespace Microsoft.OpenApi.Models
2022
{
2123
/// <summary>
@@ -26,7 +28,7 @@ public class OpenApiDocument : IOpenApiSerializable, IOpenApiExtensible
2628
/// <summary>
2729
/// Related workspace containing components that are referenced in a document
2830
/// </summary>
29-
public OpenApiWorkspace Workspace { get; set; }
31+
public OpenApiWorkspace? Workspace { get; set; }
3032

3133
/// <summary>
3234
/// REQUIRED. Provides metadata about the API. The metadata MAY be used by tooling as required.
@@ -36,12 +38,12 @@ public class OpenApiDocument : IOpenApiSerializable, IOpenApiExtensible
3638
/// <summary>
3739
/// The default value for the $schema keyword within Schema Objects contained within this OAS document. This MUST be in the form of a URI.
3840
/// </summary>
39-
public string JsonSchemaDialect { get; set; }
41+
public string? JsonSchemaDialect { get; set; }
4042

4143
/// <summary>
4244
/// An array of Server Objects, which provide connectivity information to a target server.
4345
/// </summary>
44-
public IList<OpenApiServer> Servers { get; set; } = new List<OpenApiServer>();
46+
public IList<OpenApiServer>? Servers { get; set; } = new List<OpenApiServer>();
4547

4648
/// <summary>
4749
/// REQUIRED. The available paths and operations for the API.
@@ -53,33 +55,33 @@ public class OpenApiDocument : IOpenApiSerializable, IOpenApiExtensible
5355
/// A map of requests initiated other than by an API call, for example by an out of band registration.
5456
/// The key name is a unique string to refer to each webhook, while the (optionally referenced) Path Item Object describes a request that may be initiated by the API provider and the expected responses
5557
/// </summary>
56-
public IDictionary<string, OpenApiPathItem> Webhooks { get; set; } = new Dictionary<string, OpenApiPathItem>();
58+
public IDictionary<string, OpenApiPathItem>? Webhooks { get; set; } = new Dictionary<string, OpenApiPathItem>();
5759

5860
/// <summary>
5961
/// An element to hold various schemas for the specification.
6062
/// </summary>
61-
public OpenApiComponents Components { get; set; }
63+
public OpenApiComponents? Components { get; set; }
6264

6365
/// <summary>
6466
/// A declaration of which security mechanisms can be used across the API.
6567
/// </summary>
66-
public IList<OpenApiSecurityRequirement> SecurityRequirements { get; set; } =
68+
public IList<OpenApiSecurityRequirement>? SecurityRequirements { get; set; } =
6769
new List<OpenApiSecurityRequirement>();
6870

6971
/// <summary>
7072
/// A list of tags used by the specification with additional metadata.
7173
/// </summary>
72-
public IList<OpenApiTag> Tags { get; set; } = new List<OpenApiTag>();
74+
public IList<OpenApiTag>? Tags { get; set; } = new List<OpenApiTag>();
7375

7476
/// <summary>
7577
/// Additional external documentation.
7678
/// </summary>
77-
public OpenApiExternalDocs ExternalDocs { get; set; }
79+
public OpenApiExternalDocs? ExternalDocs { get; set; }
7880

7981
/// <summary>
8082
/// This object MAY be extended with Specification Extensions.
8183
/// </summary>
82-
public IDictionary<string, IOpenApiExtension> Extensions { get; set; } = new Dictionary<string, IOpenApiExtension>();
84+
public IDictionary<string, IOpenApiExtension>? Extensions { get; set; } = new Dictionary<string, IOpenApiExtension>();
8385

8486
/// <summary>
8587
/// The unique hash code of the generated OpenAPI document
@@ -97,25 +99,28 @@ public class OpenApiDocument : IOpenApiSerializable, IOpenApiExtensible
9799
public OpenApiDocument()
98100
{
99101
Workspace = new OpenApiWorkspace();
100-
BaseUri = new(OpenApiConstants.BaseRegistryUri + Guid.NewGuid().ToString());
102+
BaseUri = new(OpenApiConstants.BaseRegistryUri + Guid.NewGuid());
103+
Info = new OpenApiInfo();
104+
Paths = new OpenApiPaths();
101105
}
102106

103107
/// <summary>
104108
/// Initializes a copy of an an <see cref="OpenApiDocument"/> object
105109
/// </summary>
106-
public OpenApiDocument(OpenApiDocument document)
110+
public OpenApiDocument(OpenApiDocument? document)
107111
{
108112
Workspace = document?.Workspace != null ? new(document?.Workspace) : null;
109-
Info = document?.Info != null ? new(document?.Info) : null;
113+
Info = document?.Info != null ? new(document?.Info) : new OpenApiInfo();
110114
JsonSchemaDialect = document?.JsonSchemaDialect ?? JsonSchemaDialect;
111115
Servers = document?.Servers != null ? new List<OpenApiServer>(document.Servers) : null;
112-
Paths = document?.Paths != null ? new(document?.Paths) : null;
116+
Paths = document?.Paths != null ? new(document?.Paths) : new OpenApiPaths();
113117
Webhooks = document?.Webhooks != null ? new Dictionary<string, OpenApiPathItem>(document.Webhooks) : null;
114118
Components = document?.Components != null ? new(document?.Components) : null;
115119
SecurityRequirements = document?.SecurityRequirements != null ? new List<OpenApiSecurityRequirement>(document.SecurityRequirements) : null;
116120
Tags = document?.Tags != null ? new List<OpenApiTag>(document.Tags) : null;
117121
ExternalDocs = document?.ExternalDocs != null ? new(document?.ExternalDocs) : null;
118122
Extensions = document?.Extensions != null ? new Dictionary<string, IOpenApiExtension>(document.Extensions) : null;
123+
BaseUri = document?.BaseUri != null ? document.BaseUri : new(OpenApiConstants.BaseRegistryUri + Guid.NewGuid());
119124
}
120125

121126
/// <summary>
@@ -360,7 +365,7 @@ private static string ParseServerUrl(OpenApiServer server)
360365
return parsedUrl;
361366
}
362367

363-
private static void WriteHostInfoV2(IOpenApiWriter writer, IList<OpenApiServer> servers)
368+
private static void WriteHostInfoV2(IOpenApiWriter writer, IList<OpenApiServer>? servers)
364369
{
365370
if (servers == null || !servers.Any())
366371
{
@@ -440,7 +445,7 @@ public void SetReferenceHostDocument()
440445
/// <summary>
441446
/// Load the referenced <see cref="IOpenApiReferenceable"/> object from a <see cref="OpenApiReference"/> object
442447
/// </summary>
443-
internal T ResolveReferenceTo<T>(OpenApiReference reference) where T : class, IOpenApiReferenceable
448+
internal T? ResolveReferenceTo<T>(OpenApiReference reference) where T : class, IOpenApiReferenceable
444449
{
445450
if (reference.IsExternal)
446451
{
@@ -489,7 +494,7 @@ private static string ConvertByteArrayToString(byte[] hash)
489494
/// <summary>
490495
/// Load the referenced <see cref="IOpenApiReferenceable"/> object from a <see cref="OpenApiReference"/> object
491496
/// </summary>
492-
internal IOpenApiReferenceable ResolveReference(OpenApiReference reference, bool useExternal)
497+
internal IOpenApiReferenceable? ResolveReference(OpenApiReference? reference, bool useExternal)
493498
{
494499
if (reference == null)
495500
{
@@ -504,7 +509,7 @@ internal IOpenApiReferenceable ResolveReference(OpenApiReference reference, bool
504509
// Special case for Tag
505510
if (reference.Type == ReferenceType.Tag)
506511
{
507-
foreach (var tag in this.Tags)
512+
foreach (var tag in this.Tags ?? Enumerable.Empty<OpenApiTag>())
508513
{
509514
if (tag.Name == reference.Id)
510515
{
@@ -526,11 +531,11 @@ internal IOpenApiReferenceable ResolveReference(OpenApiReference reference, bool
526531
string relativePath = OpenApiConstants.ComponentsSegment + reference.Type.GetDisplayName() + "/" + reference.Id;
527532

528533
uriLocation = useExternal
529-
? Workspace.GetDocumentId(reference.ExternalResource)?.OriginalString + relativePath
534+
? Workspace?.GetDocumentId(reference.ExternalResource)?.OriginalString + relativePath
530535
: BaseUri + relativePath;
531536
}
532537

533-
return Workspace.ResolveReference<IOpenApiReferenceable>(uriLocation);
538+
return Workspace?.ResolveReference<IOpenApiReferenceable>(uriLocation);
534539
}
535540

536541
/// <summary>
@@ -539,7 +544,7 @@ internal IOpenApiReferenceable ResolveReference(OpenApiReference reference, bool
539544
/// <param name="url"> The path to the OpenAPI file.</param>
540545
/// <param name="settings"></param>
541546
/// <returns></returns>
542-
public static ReadResult Load(string url, OpenApiReaderSettings settings = null)
547+
public static ReadResult Load(string url, OpenApiReaderSettings? settings = null)
543548
{
544549
return OpenApiModelFactory.Load(url, settings);
545550
}
@@ -553,7 +558,7 @@ public static ReadResult Load(string url, OpenApiReaderSettings settings = null)
553558
/// <returns></returns>
554559
public static ReadResult Load(Stream stream,
555560
string format,
556-
OpenApiReaderSettings settings = null)
561+
OpenApiReaderSettings? settings = null)
557562
{
558563
return OpenApiModelFactory.Load(stream, format, settings);
559564
}
@@ -567,7 +572,7 @@ public static ReadResult Load(Stream stream,
567572
/// <returns></returns>
568573
public static ReadResult Load(TextReader input,
569574
string format,
570-
OpenApiReaderSettings settings = null)
575+
OpenApiReaderSettings? settings = null)
571576
{
572577
return OpenApiModelFactory.Load(input, format, settings);
573578
}
@@ -578,7 +583,7 @@ public static ReadResult Load(TextReader input,
578583
/// <param name="url"> The path to the OpenAPI file.</param>
579584
/// <param name="settings">The OpenApi reader settings.</param>
580585
/// <returns></returns>
581-
public static async Task<ReadResult> LoadAsync(string url, OpenApiReaderSettings settings = null)
586+
public static async Task<ReadResult> LoadAsync(string url, OpenApiReaderSettings? settings = null)
582587
{
583588
return await OpenApiModelFactory.LoadAsync(url, settings);
584589
}
@@ -591,7 +596,7 @@ public static async Task<ReadResult> LoadAsync(string url, OpenApiReaderSettings
591596
/// <param name="settings">The OpenApi reader settings.</param>
592597
/// <param name="cancellationToken">Propagates information about operation cancelling.</param>
593598
/// <returns></returns>
594-
public static async Task<ReadResult> LoadAsync(Stream stream, string format, OpenApiReaderSettings settings = null, CancellationToken cancellationToken = default)
599+
public static async Task<ReadResult> LoadAsync(Stream stream, string format, OpenApiReaderSettings? settings = null, CancellationToken cancellationToken = default)
595600
{
596601
return await OpenApiModelFactory.LoadAsync(stream, format, settings, cancellationToken);
597602
}
@@ -603,7 +608,7 @@ public static async Task<ReadResult> LoadAsync(Stream stream, string format, Ope
603608
/// <param name="format"> The OpenAPI format to use during parsing.</param>
604609
/// <param name="settings">The OpenApi reader settings.</param>
605610
/// <returns></returns>
606-
public static async Task<ReadResult> LoadAsync(TextReader input, string format, OpenApiReaderSettings settings = null)
611+
public static async Task<ReadResult> LoadAsync(TextReader input, string format, OpenApiReaderSettings? settings = null)
607612
{
608613
return await OpenApiModelFactory.LoadAsync(input, format, settings);
609614
}
@@ -616,18 +621,18 @@ public static async Task<ReadResult> LoadAsync(TextReader input, string format,
616621
/// <param name="settings"></param>
617622
/// <returns></returns>
618623
public static ReadResult Parse(string input,
619-
string format = null,
620-
OpenApiReaderSettings settings = null)
624+
string? format = null,
625+
OpenApiReaderSettings? settings = null)
621626
{
622627
return OpenApiModelFactory.Parse(input, format, settings);
623628
}
624629
}
625630

626631
internal class FindSchemaReferences : OpenApiVisitorBase
627632
{
628-
private Dictionary<string, OpenApiSchema> Schemas;
633+
private Dictionary<string, OpenApiSchema> Schemas = new();
629634

630-
public static void ResolveSchemas(OpenApiComponents components, Dictionary<string, OpenApiSchema> schemas)
635+
public static void ResolveSchemas(OpenApiComponents? components, Dictionary<string, OpenApiSchema> schemas)
631636
{
632637
var visitor = new FindSchemaReferences();
633638
visitor.Schemas = schemas;

0 commit comments

Comments
 (0)