Skip to content

Commit c035940

Browse files
committed
chore: move assignment within the condition
1 parent eabd01d commit c035940

File tree

1 file changed

+20
-20
lines changed

1 file changed

+20
-20
lines changed

Diff for: src/Microsoft.OpenApi/Services/CopyReferences.cs

+20-20
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,9 @@ private void AddSchemaToComponents(IOpenApiSchema? schema, string? referenceId =
8989
{
9090
EnsureComponentsExist();
9191
EnsureSchemasExist();
92-
Components.Schemas ??= new Dictionary<string, IOpenApiSchema>();
93-
if (referenceId is not null && schema is not null && !Components.Schemas.ContainsKey(referenceId))
92+
if (referenceId is not null && schema is not null && !(Components.Schemas?.ContainsKey(referenceId) ?? false))
9493
{
94+
Components.Schemas ??= new Dictionary<string, IOpenApiSchema>();
9595
Components.Schemas.Add(referenceId, schema);
9696
}
9797
}
@@ -100,9 +100,9 @@ private void AddParameterToComponents(IOpenApiParameter? parameter, string? refe
100100
{
101101
EnsureComponentsExist();
102102
EnsureParametersExist();
103-
Components.Parameters ??= new Dictionary<string, IOpenApiParameter>();
104-
if (parameter is not null && referenceId is not null && !Components.Parameters.ContainsKey(referenceId))
103+
if (parameter is not null && referenceId is not null && !(Components.Parameters?.ContainsKey(referenceId) ?? false))
105104
{
105+
Components.Parameters ??= new Dictionary<string, IOpenApiParameter>();
106106
Components.Parameters.Add(referenceId, parameter);
107107
}
108108
}
@@ -111,79 +111,79 @@ private void AddResponseToComponents(IOpenApiResponse? response, string? referen
111111
{
112112
EnsureComponentsExist();
113113
EnsureResponsesExist();
114-
Components.Responses ??= new Dictionary<string, IOpenApiResponse>();
115-
if (referenceId is not null && response is not null && !Components.Responses.ContainsKey(referenceId))
114+
if (referenceId is not null && response is not null && !(Components.Responses?.ContainsKey(referenceId) ?? false))
116115
{
116+
Components.Responses ??= new Dictionary<string, IOpenApiResponse>();
117117
Components.Responses.Add(referenceId, response);
118118
}
119119
}
120120
private void AddRequestBodyToComponents(IOpenApiRequestBody? requestBody, string? referenceId = null)
121121
{
122122
EnsureComponentsExist();
123123
EnsureRequestBodiesExist();
124-
Components.RequestBodies ??= new Dictionary<string, IOpenApiRequestBody>();
125-
if (requestBody is not null && referenceId is not null && !Components.RequestBodies.ContainsKey(referenceId))
124+
if (requestBody is not null && referenceId is not null && !(Components.RequestBodies?.ContainsKey(referenceId) ?? false))
126125
{
126+
Components.RequestBodies ??= new Dictionary<string, IOpenApiRequestBody>();
127127
Components.RequestBodies.Add(referenceId, requestBody);
128128
}
129129
}
130130
private void AddLinkToComponents(IOpenApiLink? link, string? referenceId = null)
131131
{
132132
EnsureComponentsExist();
133133
EnsureLinksExist();
134-
Components.Links ??= new Dictionary<string, IOpenApiLink>();
135-
if (link is not null && referenceId is not null && !Components.Links.ContainsKey(referenceId))
134+
if (link is not null && referenceId is not null && !(Components.Links?.ContainsKey(referenceId) ?? false))
136135
{
136+
Components.Links ??= new Dictionary<string, IOpenApiLink>();
137137
Components.Links.Add(referenceId, link);
138138
}
139139
}
140140
private void AddCallbackToComponents(IOpenApiCallback? callback, string? referenceId = null)
141141
{
142142
EnsureComponentsExist();
143143
EnsureCallbacksExist();
144-
Components.Callbacks ??= new Dictionary<string, IOpenApiCallback>();
145-
if (callback is not null && referenceId is not null && !Components.Callbacks.ContainsKey(referenceId))
144+
if (callback is not null && referenceId is not null && !(Components.Callbacks?.ContainsKey(referenceId) ?? false))
146145
{
146+
Components.Callbacks ??= new Dictionary<string, IOpenApiCallback>();
147147
Components.Callbacks.Add(referenceId, callback);
148148
}
149149
}
150150
private void AddHeaderToComponents(IOpenApiHeader? header, string? referenceId = null)
151151
{
152152
EnsureComponentsExist();
153153
EnsureHeadersExist();
154-
Components.Headers ??= new Dictionary<string, IOpenApiHeader>();
155-
if (header is not null && referenceId is not null && !Components.Headers.ContainsKey(referenceId))
154+
if (header is not null && referenceId is not null && !(Components.Headers?.ContainsKey(referenceId) ?? false))
156155
{
156+
Components.Headers ??= new Dictionary<string, IOpenApiHeader>();
157157
Components.Headers.Add(referenceId, header);
158158
}
159159
}
160160
private void AddExampleToComponents(IOpenApiExample? example, string? referenceId = null)
161161
{
162162
EnsureComponentsExist();
163163
EnsureExamplesExist();
164-
Components.Examples ??= new Dictionary<string, IOpenApiExample>();
165-
if (example is not null && referenceId is not null && !Components.Examples.ContainsKey(referenceId))
164+
if (example is not null && referenceId is not null && !(Components.Examples?.ContainsKey(referenceId) ?? false))
166165
{
166+
Components.Examples ??= new Dictionary<string, IOpenApiExample>();
167167
Components.Examples.Add(referenceId, example);
168168
}
169169
}
170170
private void AddPathItemToComponents(IOpenApiPathItem? pathItem, string? referenceId = null)
171171
{
172172
EnsureComponentsExist();
173173
EnsurePathItemsExist();
174-
Components.PathItems ??= new Dictionary<string, IOpenApiPathItem>();
175-
if (pathItem is not null && referenceId is not null && !Components.PathItems.ContainsKey(referenceId))
174+
if (pathItem is not null && referenceId is not null && !(Components.PathItems?.ContainsKey(referenceId) ?? false))
176175
{
176+
Components.PathItems ??= new Dictionary<string, IOpenApiPathItem>();
177177
Components.PathItems.Add(referenceId, pathItem);
178178
}
179179
}
180180
private void AddSecuritySchemeToComponents(IOpenApiSecurityScheme? securityScheme, string? referenceId = null)
181181
{
182182
EnsureComponentsExist();
183183
EnsureSecuritySchemesExist();
184-
Components.SecuritySchemes ??= new Dictionary<string, IOpenApiSecurityScheme>();
185-
if (securityScheme is not null && referenceId is not null && !Components.SecuritySchemes.ContainsKey(referenceId))
184+
if (securityScheme is not null && referenceId is not null && !(Components.SecuritySchemes?.ContainsKey(referenceId) ?? false))
186185
{
186+
Components.SecuritySchemes ??= new Dictionary<string, IOpenApiSecurityScheme>();
187187
Components.SecuritySchemes.Add(referenceId, securityScheme);
188188
}
189189
}

0 commit comments

Comments
 (0)