16
16
using Microsoft . OpenApi . Services ;
17
17
using Microsoft . OpenApi . Writers ;
18
18
19
+ #nullable enable
20
+
19
21
namespace Microsoft . OpenApi . Models
20
22
{
21
23
/// <summary>
@@ -26,7 +28,7 @@ public class OpenApiDocument : IOpenApiSerializable, IOpenApiExtensible
26
28
/// <summary>
27
29
/// Related workspace containing components that are referenced in a document
28
30
/// </summary>
29
- public OpenApiWorkspace Workspace { get ; set ; }
31
+ public OpenApiWorkspace ? Workspace { get ; set ; }
30
32
31
33
/// <summary>
32
34
/// REQUIRED. Provides metadata about the API. The metadata MAY be used by tooling as required.
@@ -36,12 +38,12 @@ public class OpenApiDocument : IOpenApiSerializable, IOpenApiExtensible
36
38
/// <summary>
37
39
/// The default value for the $schema keyword within Schema Objects contained within this OAS document. This MUST be in the form of a URI.
38
40
/// </summary>
39
- public string JsonSchemaDialect { get ; set ; }
41
+ public string ? JsonSchemaDialect { get ; set ; }
40
42
41
43
/// <summary>
42
44
/// An array of Server Objects, which provide connectivity information to a target server.
43
45
/// </summary>
44
- public IList < OpenApiServer > Servers { get ; set ; } = new List < OpenApiServer > ( ) ;
46
+ public IList < OpenApiServer > ? Servers { get ; set ; } = new List < OpenApiServer > ( ) ;
45
47
46
48
/// <summary>
47
49
/// REQUIRED. The available paths and operations for the API.
@@ -53,33 +55,33 @@ public class OpenApiDocument : IOpenApiSerializable, IOpenApiExtensible
53
55
/// A map of requests initiated other than by an API call, for example by an out of band registration.
54
56
/// 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
55
57
/// </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 > ( ) ;
57
59
58
60
/// <summary>
59
61
/// An element to hold various schemas for the specification.
60
62
/// </summary>
61
- public OpenApiComponents Components { get ; set ; }
63
+ public OpenApiComponents ? Components { get ; set ; }
62
64
63
65
/// <summary>
64
66
/// A declaration of which security mechanisms can be used across the API.
65
67
/// </summary>
66
- public IList < OpenApiSecurityRequirement > SecurityRequirements { get ; set ; } =
68
+ public IList < OpenApiSecurityRequirement > ? SecurityRequirements { get ; set ; } =
67
69
new List < OpenApiSecurityRequirement > ( ) ;
68
70
69
71
/// <summary>
70
72
/// A list of tags used by the specification with additional metadata.
71
73
/// </summary>
72
- public IList < OpenApiTag > Tags { get ; set ; } = new List < OpenApiTag > ( ) ;
74
+ public IList < OpenApiTag > ? Tags { get ; set ; } = new List < OpenApiTag > ( ) ;
73
75
74
76
/// <summary>
75
77
/// Additional external documentation.
76
78
/// </summary>
77
- public OpenApiExternalDocs ExternalDocs { get ; set ; }
79
+ public OpenApiExternalDocs ? ExternalDocs { get ; set ; }
78
80
79
81
/// <summary>
80
82
/// This object MAY be extended with Specification Extensions.
81
83
/// </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 > ( ) ;
83
85
84
86
/// <summary>
85
87
/// The unique hash code of the generated OpenAPI document
@@ -97,25 +99,28 @@ public class OpenApiDocument : IOpenApiSerializable, IOpenApiExtensible
97
99
public OpenApiDocument ( )
98
100
{
99
101
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 ( ) ;
101
105
}
102
106
103
107
/// <summary>
104
108
/// Initializes a copy of an an <see cref="OpenApiDocument"/> object
105
109
/// </summary>
106
- public OpenApiDocument ( OpenApiDocument document )
110
+ public OpenApiDocument ( OpenApiDocument ? document )
107
111
{
108
112
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 ( ) ;
110
114
JsonSchemaDialect = document ? . JsonSchemaDialect ?? JsonSchemaDialect ;
111
115
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 ( ) ;
113
117
Webhooks = document ? . Webhooks != null ? new Dictionary < string , OpenApiPathItem > ( document . Webhooks ) : null ;
114
118
Components = document ? . Components != null ? new ( document ? . Components ) : null ;
115
119
SecurityRequirements = document ? . SecurityRequirements != null ? new List < OpenApiSecurityRequirement > ( document . SecurityRequirements ) : null ;
116
120
Tags = document ? . Tags != null ? new List < OpenApiTag > ( document . Tags ) : null ;
117
121
ExternalDocs = document ? . ExternalDocs != null ? new ( document ? . ExternalDocs ) : null ;
118
122
Extensions = document ? . Extensions != null ? new Dictionary < string , IOpenApiExtension > ( document . Extensions ) : null ;
123
+ BaseUri = document ? . BaseUri != null ? document . BaseUri : new ( OpenApiConstants . BaseRegistryUri + Guid . NewGuid ( ) ) ;
119
124
}
120
125
121
126
/// <summary>
@@ -360,7 +365,7 @@ private static string ParseServerUrl(OpenApiServer server)
360
365
return parsedUrl ;
361
366
}
362
367
363
- private static void WriteHostInfoV2 ( IOpenApiWriter writer , IList < OpenApiServer > servers )
368
+ private static void WriteHostInfoV2 ( IOpenApiWriter writer , IList < OpenApiServer > ? servers )
364
369
{
365
370
if ( servers == null || ! servers . Any ( ) )
366
371
{
@@ -440,7 +445,7 @@ public void SetReferenceHostDocument()
440
445
/// <summary>
441
446
/// Load the referenced <see cref="IOpenApiReferenceable"/> object from a <see cref="OpenApiReference"/> object
442
447
/// </summary>
443
- internal T ResolveReferenceTo < T > ( OpenApiReference reference ) where T : class , IOpenApiReferenceable
448
+ internal T ? ResolveReferenceTo < T > ( OpenApiReference reference ) where T : class , IOpenApiReferenceable
444
449
{
445
450
if ( reference . IsExternal )
446
451
{
@@ -489,7 +494,7 @@ private static string ConvertByteArrayToString(byte[] hash)
489
494
/// <summary>
490
495
/// Load the referenced <see cref="IOpenApiReferenceable"/> object from a <see cref="OpenApiReference"/> object
491
496
/// </summary>
492
- internal IOpenApiReferenceable ResolveReference ( OpenApiReference reference , bool useExternal )
497
+ internal IOpenApiReferenceable ? ResolveReference ( OpenApiReference ? reference , bool useExternal )
493
498
{
494
499
if ( reference == null )
495
500
{
@@ -504,7 +509,7 @@ internal IOpenApiReferenceable ResolveReference(OpenApiReference reference, bool
504
509
// Special case for Tag
505
510
if ( reference . Type == ReferenceType . Tag )
506
511
{
507
- foreach ( var tag in this . Tags )
512
+ foreach ( var tag in this . Tags ?? Enumerable . Empty < OpenApiTag > ( ) )
508
513
{
509
514
if ( tag . Name == reference . Id )
510
515
{
@@ -526,11 +531,11 @@ internal IOpenApiReferenceable ResolveReference(OpenApiReference reference, bool
526
531
string relativePath = OpenApiConstants . ComponentsSegment + reference . Type . GetDisplayName ( ) + "/" + reference . Id ;
527
532
528
533
uriLocation = useExternal
529
- ? Workspace . GetDocumentId ( reference . ExternalResource ) ? . OriginalString + relativePath
534
+ ? Workspace ? . GetDocumentId ( reference . ExternalResource ) ? . OriginalString + relativePath
530
535
: BaseUri + relativePath ;
531
536
}
532
537
533
- return Workspace . ResolveReference < IOpenApiReferenceable > ( uriLocation ) ;
538
+ return Workspace ? . ResolveReference < IOpenApiReferenceable > ( uriLocation ) ;
534
539
}
535
540
536
541
/// <summary>
@@ -539,7 +544,7 @@ internal IOpenApiReferenceable ResolveReference(OpenApiReference reference, bool
539
544
/// <param name="url"> The path to the OpenAPI file.</param>
540
545
/// <param name="settings"></param>
541
546
/// <returns></returns>
542
- public static ReadResult Load ( string url , OpenApiReaderSettings settings = null )
547
+ public static ReadResult Load ( string url , OpenApiReaderSettings ? settings = null )
543
548
{
544
549
return OpenApiModelFactory . Load ( url , settings ) ;
545
550
}
@@ -553,7 +558,7 @@ public static ReadResult Load(string url, OpenApiReaderSettings settings = null)
553
558
/// <returns></returns>
554
559
public static ReadResult Load ( Stream stream ,
555
560
string format ,
556
- OpenApiReaderSettings settings = null )
561
+ OpenApiReaderSettings ? settings = null )
557
562
{
558
563
return OpenApiModelFactory . Load ( stream , format , settings ) ;
559
564
}
@@ -567,7 +572,7 @@ public static ReadResult Load(Stream stream,
567
572
/// <returns></returns>
568
573
public static ReadResult Load ( TextReader input ,
569
574
string format ,
570
- OpenApiReaderSettings settings = null )
575
+ OpenApiReaderSettings ? settings = null )
571
576
{
572
577
return OpenApiModelFactory . Load ( input , format , settings ) ;
573
578
}
@@ -578,7 +583,7 @@ public static ReadResult Load(TextReader input,
578
583
/// <param name="url"> The path to the OpenAPI file.</param>
579
584
/// <param name="settings">The OpenApi reader settings.</param>
580
585
/// <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 )
582
587
{
583
588
return await OpenApiModelFactory . LoadAsync ( url , settings ) ;
584
589
}
@@ -591,7 +596,7 @@ public static async Task<ReadResult> LoadAsync(string url, OpenApiReaderSettings
591
596
/// <param name="settings">The OpenApi reader settings.</param>
592
597
/// <param name="cancellationToken">Propagates information about operation cancelling.</param>
593
598
/// <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 )
595
600
{
596
601
return await OpenApiModelFactory . LoadAsync ( stream , format , settings , cancellationToken ) ;
597
602
}
@@ -603,7 +608,7 @@ public static async Task<ReadResult> LoadAsync(Stream stream, string format, Ope
603
608
/// <param name="format"> The OpenAPI format to use during parsing.</param>
604
609
/// <param name="settings">The OpenApi reader settings.</param>
605
610
/// <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 )
607
612
{
608
613
return await OpenApiModelFactory . LoadAsync ( input , format , settings ) ;
609
614
}
@@ -616,18 +621,18 @@ public static async Task<ReadResult> LoadAsync(TextReader input, string format,
616
621
/// <param name="settings"></param>
617
622
/// <returns></returns>
618
623
public static ReadResult Parse ( string input ,
619
- string format = null ,
620
- OpenApiReaderSettings settings = null )
624
+ string ? format = null ,
625
+ OpenApiReaderSettings ? settings = null )
621
626
{
622
627
return OpenApiModelFactory . Parse ( input , format , settings ) ;
623
628
}
624
629
}
625
630
626
631
internal class FindSchemaReferences : OpenApiVisitorBase
627
632
{
628
- private Dictionary < string , OpenApiSchema > Schemas ;
633
+ private Dictionary < string , OpenApiSchema > Schemas = new ( ) ;
629
634
630
- public static void ResolveSchemas ( OpenApiComponents components , Dictionary < string , OpenApiSchema > schemas )
635
+ public static void ResolveSchemas ( OpenApiComponents ? components , Dictionary < string , OpenApiSchema > schemas )
631
636
{
632
637
var visitor = new FindSchemaReferences ( ) ;
633
638
visitor . Schemas = schemas ;
0 commit comments