1616using  Microsoft . OpenApi . Services ; 
1717using  Microsoft . OpenApi . Writers ; 
1818
19+ #nullable enable
20+ 
1921namespace  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