@@ -89,7 +89,8 @@ private void AddSchemaToComponents(IOpenApiSchema? schema, string? referenceId =
89
89
{
90
90
EnsureComponentsExist ( ) ;
91
91
EnsureSchemasExist ( ) ;
92
- if ( Components . Schemas is not null && referenceId is not null && schema is not null && ! Components . Schemas . ContainsKey ( referenceId ) )
92
+ Components . Schemas ??= new Dictionary < string , IOpenApiSchema > ( ) ;
93
+ if ( referenceId is not null && schema is not null && ! Components . Schemas . ContainsKey ( referenceId ) )
93
94
{
94
95
Components . Schemas . Add ( referenceId , schema ) ;
95
96
}
@@ -99,7 +100,8 @@ private void AddParameterToComponents(IOpenApiParameter? parameter, string? refe
99
100
{
100
101
EnsureComponentsExist ( ) ;
101
102
EnsureParametersExist ( ) ;
102
- if ( Components . Parameters is not null && parameter is not null && referenceId is not null && ! Components . Parameters . ContainsKey ( referenceId ) )
103
+ Components . Parameters ??= new Dictionary < string , IOpenApiParameter > ( ) ;
104
+ if ( parameter is not null && referenceId is not null && ! Components . Parameters . ContainsKey ( referenceId ) )
103
105
{
104
106
Components . Parameters . Add ( referenceId , parameter ) ;
105
107
}
@@ -109,7 +111,8 @@ private void AddResponseToComponents(IOpenApiResponse? response, string? referen
109
111
{
110
112
EnsureComponentsExist ( ) ;
111
113
EnsureResponsesExist ( ) ;
112
- if ( Components . Responses is not null && referenceId is not null && response is not null && ! Components . Responses . ContainsKey ( referenceId ) )
114
+ Components . Responses ??= new Dictionary < string , IOpenApiResponse > ( ) ;
115
+ if ( referenceId is not null && response is not null && ! Components . Responses . ContainsKey ( referenceId ) )
113
116
{
114
117
Components . Responses . Add ( referenceId , response ) ;
115
118
}
@@ -118,7 +121,8 @@ private void AddRequestBodyToComponents(IOpenApiRequestBody? requestBody, string
118
121
{
119
122
EnsureComponentsExist ( ) ;
120
123
EnsureRequestBodiesExist ( ) ;
121
- if ( Components . RequestBodies is not null && requestBody is not null && referenceId is not null && ! Components . RequestBodies . ContainsKey ( referenceId ) )
124
+ Components . RequestBodies ??= new Dictionary < string , IOpenApiRequestBody > ( ) ;
125
+ if ( requestBody is not null && referenceId is not null && ! Components . RequestBodies . ContainsKey ( referenceId ) )
122
126
{
123
127
Components . RequestBodies . Add ( referenceId , requestBody ) ;
124
128
}
@@ -127,7 +131,8 @@ private void AddLinkToComponents(IOpenApiLink? link, string? referenceId = null)
127
131
{
128
132
EnsureComponentsExist ( ) ;
129
133
EnsureLinksExist ( ) ;
130
- if ( Components . Links is not null && link is not null && referenceId is not null && ! Components . Links . ContainsKey ( referenceId ) )
134
+ Components . Links ??= new Dictionary < string , IOpenApiLink > ( ) ;
135
+ if ( link is not null && referenceId is not null && ! Components . Links . ContainsKey ( referenceId ) )
131
136
{
132
137
Components . Links . Add ( referenceId , link ) ;
133
138
}
@@ -136,7 +141,8 @@ private void AddCallbackToComponents(IOpenApiCallback? callback, string? referen
136
141
{
137
142
EnsureComponentsExist ( ) ;
138
143
EnsureCallbacksExist ( ) ;
139
- if ( Components . Callbacks is not null && callback is not null && referenceId is not null && ! Components . Callbacks . ContainsKey ( referenceId ) )
144
+ Components . Callbacks ??= new Dictionary < string , IOpenApiCallback > ( ) ;
145
+ if ( callback is not null && referenceId is not null && ! Components . Callbacks . ContainsKey ( referenceId ) )
140
146
{
141
147
Components . Callbacks . Add ( referenceId , callback ) ;
142
148
}
@@ -145,7 +151,8 @@ private void AddHeaderToComponents(IOpenApiHeader? header, string? referenceId =
145
151
{
146
152
EnsureComponentsExist ( ) ;
147
153
EnsureHeadersExist ( ) ;
148
- if ( Components . Headers is not null && header is not null && referenceId is not null && ! Components . Headers . ContainsKey ( referenceId ) )
154
+ Components . Headers ??= new Dictionary < string , IOpenApiHeader > ( ) ;
155
+ if ( header is not null && referenceId is not null && ! Components . Headers . ContainsKey ( referenceId ) )
149
156
{
150
157
Components . Headers . Add ( referenceId , header ) ;
151
158
}
@@ -154,7 +161,8 @@ private void AddExampleToComponents(IOpenApiExample? example, string? referenceI
154
161
{
155
162
EnsureComponentsExist ( ) ;
156
163
EnsureExamplesExist ( ) ;
157
- if ( Components . Examples is not null && example is not null && referenceId is not null && ! Components . Examples . ContainsKey ( referenceId ) )
164
+ Components . Examples ??= new Dictionary < string , IOpenApiExample > ( ) ;
165
+ if ( example is not null && referenceId is not null && ! Components . Examples . ContainsKey ( referenceId ) )
158
166
{
159
167
Components . Examples . Add ( referenceId , example ) ;
160
168
}
@@ -163,7 +171,8 @@ private void AddPathItemToComponents(IOpenApiPathItem? pathItem, string? referen
163
171
{
164
172
EnsureComponentsExist ( ) ;
165
173
EnsurePathItemsExist ( ) ;
166
- if ( Components . PathItems is not null && pathItem is not null && referenceId is not null && ! Components . PathItems . ContainsKey ( referenceId ) )
174
+ Components . PathItems ??= new Dictionary < string , IOpenApiPathItem > ( ) ;
175
+ if ( pathItem is not null && referenceId is not null && ! Components . PathItems . ContainsKey ( referenceId ) )
167
176
{
168
177
Components . PathItems . Add ( referenceId , pathItem ) ;
169
178
}
@@ -172,7 +181,8 @@ private void AddSecuritySchemeToComponents(IOpenApiSecurityScheme? securitySchem
172
181
{
173
182
EnsureComponentsExist ( ) ;
174
183
EnsureSecuritySchemesExist ( ) ;
175
- if ( Components . SecuritySchemes is not null && securityScheme is not null && referenceId is not null && ! Components . SecuritySchemes . ContainsKey ( referenceId ) )
184
+ Components . SecuritySchemes ??= new Dictionary < string , IOpenApiSecurityScheme > ( ) ;
185
+ if ( securityScheme is not null && referenceId is not null && ! Components . SecuritySchemes . ContainsKey ( referenceId ) )
176
186
{
177
187
Components . SecuritySchemes . Add ( referenceId , securityScheme ) ;
178
188
}
0 commit comments