Skip to content

Commit a3ea095

Browse files
committed
Use var everywhere
1 parent 6920bc2 commit a3ea095

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+352
-352
lines changed

src/JsonApiDotNetCore.OpenApi.Swashbuckle/ConfigureSwaggerGenOptions.cs

+8-8
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public void Configure(SwaggerGenOptions options)
7878

7979
private List<Type> SelectDerivedTypes(Type baseType)
8080
{
81-
if (BaseToDerivedSchemaTypes.TryGetValue(baseType, out Type? schemaOpenType))
81+
if (BaseToDerivedSchemaTypes.TryGetValue(baseType, out var schemaOpenType))
8282
{
8383
return GetConstructedTypesFromResourceGraph(schemaOpenType);
8484
}
@@ -90,7 +90,7 @@ private List<Type> SelectDerivedTypes(Type baseType)
9090

9191
if (baseType.IsAssignableTo(typeof(IIdentifiable)))
9292
{
93-
ResourceType? resourceType = _resourceGraph.FindResourceType(baseType);
93+
var resourceType = _resourceGraph.FindResourceType(baseType);
9494

9595
if (resourceType != null && resourceType.IsPartOfTypeHierarchy())
9696
{
@@ -105,9 +105,9 @@ private List<Type> GetConstructedTypesFromResourceGraph(Type schemaOpenType)
105105
{
106106
List<Type> constructedTypes = [];
107107

108-
foreach (ResourceType resourceType in _resourceGraph.GetResourceTypes())
108+
foreach (var resourceType in _resourceGraph.GetResourceTypes())
109109
{
110-
Type constructedType = schemaOpenType.MakeGenericType(resourceType.ClrType);
110+
var constructedType = schemaOpenType.MakeGenericType(resourceType.ClrType);
111111
constructedTypes.Add(constructedType);
112112
}
113113

@@ -118,7 +118,7 @@ private List<Type> GetConstructedTypesForAtomicOperation()
118118
{
119119
List<Type> derivedTypes = [];
120120

121-
foreach (ResourceType resourceType in _resourceGraph.GetResourceTypes())
121+
foreach (var resourceType in _resourceGraph.GetResourceTypes())
122122
{
123123
derivedTypes.AddRange(AtomicOperationDerivedSchemaTypes.Select(openType => openType.MakeGenericType(resourceType.ClrType)));
124124
}
@@ -135,7 +135,7 @@ private static List<Type> GetResourceDerivedTypes(ResourceType baseType)
135135

136136
private static void IncludeDerivedTypes(ResourceType baseType, List<Type> clrTypes)
137137
{
138-
foreach (ResourceType derivedType in baseType.DirectlyDerivedTypes)
138+
foreach (var derivedType in baseType.DirectlyDerivedTypes)
139139
{
140140
clrTypes.Add(derivedType.ClrType);
141141
IncludeDerivedTypes(derivedType, clrTypes);
@@ -144,8 +144,8 @@ private static void IncludeDerivedTypes(ResourceType baseType, List<Type> clrTyp
144144

145145
private static List<string> GetOpenApiOperationTags(ApiDescription description, IControllerResourceMapping controllerResourceMapping)
146146
{
147-
MethodInfo actionMethod = description.ActionDescriptor.GetActionMethod();
148-
ResourceType? resourceType = controllerResourceMapping.GetResourceTypeForController(actionMethod.ReflectedType);
147+
var actionMethod = description.ActionDescriptor.GetActionMethod();
148+
var resourceType = controllerResourceMapping.GetResourceTypeForController(actionMethod.ReflectedType);
149149

150150
return resourceType == null ? ["operations"] : [resourceType.PublicName];
151151
}

src/JsonApiDotNetCore.OpenApi.Swashbuckle/IncludeDependencyScanner.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,15 @@ private static void IncludeResourceType(ResourceType resourceType, ISet<Resource
3737

3838
private static void IncludeDerivedTypes(ResourceType resourceType, ISet<ResourceType> resourceTypesFound)
3939
{
40-
foreach (ResourceType derivedType in resourceType.DirectlyDerivedTypes)
40+
foreach (var derivedType in resourceType.DirectlyDerivedTypes)
4141
{
4242
IncludeResourceType(derivedType, resourceTypesFound);
4343
}
4444
}
4545

4646
private static void IncludeRelatedTypes(ResourceType resourceType, ISet<ResourceType> resourceTypesFound)
4747
{
48-
foreach (RelationshipAttribute relationship in resourceType.Relationships)
48+
foreach (var relationship in resourceType.Relationships)
4949
{
5050
IncludeResourceType(relationship.RightType, resourceTypesFound);
5151
}

src/JsonApiDotNetCore.OpenApi.Swashbuckle/JsonApiActionDescriptorCollectionProvider.cs

+15-15
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,13 @@ public JsonApiActionDescriptorCollectionProvider(IActionDescriptorCollectionProv
4141

4242
private ActionDescriptorCollection GetActionDescriptors()
4343
{
44-
List<ActionDescriptor> newDescriptors = _defaultProvider.ActionDescriptors.Items.ToList();
45-
ActionDescriptor[] endpoints = newDescriptors.Where(IsVisibleJsonApiEndpoint).ToArray();
44+
var newDescriptors = _defaultProvider.ActionDescriptors.Items.ToList();
45+
var endpoints = newDescriptors.Where(IsVisibleJsonApiEndpoint).ToArray();
4646

47-
foreach (ActionDescriptor endpoint in endpoints)
47+
foreach (var endpoint in endpoints)
4848
{
49-
MethodInfo actionMethod = endpoint.GetActionMethod();
50-
JsonApiEndpointMetadataContainer endpointMetadataContainer = _jsonApiEndpointMetadataProvider.Get(actionMethod);
49+
var actionMethod = endpoint.GetActionMethod();
50+
var endpointMetadataContainer = _jsonApiEndpointMetadataProvider.Get(actionMethod);
5151

5252
List<ActionDescriptor> replacementDescriptorsForEndpoint =
5353
[
@@ -62,7 +62,7 @@ .. AddJsonApiMetadataToAction(endpoint, endpointMetadataContainer.ResponseMetada
6262
}
6363
}
6464

65-
int descriptorVersion = _defaultProvider.ActionDescriptors.Version;
65+
var descriptorVersion = _defaultProvider.ActionDescriptors.Version;
6666
return new ActionDescriptorCollection(newDescriptors.AsReadOnly(), descriptorVersion);
6767
}
6868

@@ -136,9 +136,9 @@ private static bool ProducesJsonApiResponseDocument(ActionDescriptor endpoint)
136136

137137
if (produces != null)
138138
{
139-
foreach (string contentType in produces.ContentTypes)
139+
foreach (var contentType in produces.ContentTypes)
140140
{
141-
if (MediaTypeHeaderValue.TryParse(contentType, out MediaTypeHeaderValue? headerValue))
141+
if (MediaTypeHeaderValue.TryParse(contentType, out var headerValue))
142142
{
143143
if (headerValue.MediaType.Equals(DefaultMediaType, StringComparison.OrdinalIgnoreCase))
144144
{
@@ -156,14 +156,14 @@ private static List<ActionDescriptor> Expand(ActionDescriptor genericEndpoint, N
156156
{
157157
List<ActionDescriptor> expansion = [];
158158

159-
foreach ((string relationshipName, Type documentType) in metadata.DocumentTypesByRelationshipName)
159+
foreach ((var relationshipName, var documentType) in metadata.DocumentTypesByRelationshipName)
160160
{
161161
if (genericEndpoint.AttributeRouteInfo == null)
162162
{
163163
throw new NotSupportedException("Only attribute routing is supported for JsonApiDotNetCore endpoints.");
164164
}
165165

166-
ActionDescriptor expandedEndpoint = Clone(genericEndpoint);
166+
var expandedEndpoint = Clone(genericEndpoint);
167167

168168
RemovePathParameter(expandedEndpoint.Parameters, "relationshipName");
169169

@@ -179,11 +179,11 @@ private static List<ActionDescriptor> Expand(ActionDescriptor genericEndpoint, N
179179

180180
private static void UpdateBodyParameterDescriptor(ActionDescriptor endpoint, Type documentType, string? parameterName)
181181
{
182-
ControllerParameterDescriptor? requestBodyDescriptor = endpoint.GetBodyParameterDescriptor();
182+
var requestBodyDescriptor = endpoint.GetBodyParameterDescriptor();
183183

184184
if (requestBodyDescriptor == null)
185185
{
186-
MethodInfo actionMethod = endpoint.GetActionMethod();
186+
var actionMethod = endpoint.GetActionMethod();
187187

188188
throw new InvalidConfigurationException(
189189
$"The action method '{actionMethod}' on type '{actionMethod.ReflectedType?.FullName}' contains no parameter with a [FromBody] attribute.");
@@ -195,7 +195,7 @@ private static void UpdateBodyParameterDescriptor(ActionDescriptor endpoint, Typ
195195

196196
private static ActionDescriptor Clone(ActionDescriptor descriptor)
197197
{
198-
ActionDescriptor clone = descriptor.MemberwiseClone();
198+
var clone = descriptor.MemberwiseClone();
199199
clone.AttributeRouteInfo = descriptor.AttributeRouteInfo!.MemberwiseClone();
200200
clone.FilterDescriptors = descriptor.FilterDescriptors.Select(Clone).ToList();
201201
clone.Parameters = descriptor.Parameters.Select(parameter => parameter.MemberwiseClone()).ToList();
@@ -204,7 +204,7 @@ private static ActionDescriptor Clone(ActionDescriptor descriptor)
204204

205205
private static FilterDescriptor Clone(FilterDescriptor descriptor)
206206
{
207-
IFilterMetadata clone = descriptor.Filter.MemberwiseClone();
207+
var clone = descriptor.Filter.MemberwiseClone();
208208

209209
return new FilterDescriptor(clone, descriptor.Scope)
210210
{
@@ -214,7 +214,7 @@ private static FilterDescriptor Clone(FilterDescriptor descriptor)
214214

215215
private static void RemovePathParameter(ICollection<ParameterDescriptor> parameters, string parameterName)
216216
{
217-
ParameterDescriptor descriptor = parameters.Single(parameterDescriptor => parameterDescriptor.Name == parameterName);
217+
var descriptor = parameters.Single(parameterDescriptor => parameterDescriptor.Name == parameterName);
218218
parameters.Remove(descriptor);
219219
}
220220

src/JsonApiDotNetCore.OpenApi.Swashbuckle/JsonApiMetadata/EndpointResolver.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public JsonApiEndpoints GetEndpoint(MethodInfo controllerAction)
2222
return JsonApiEndpoints.None;
2323
}
2424

25-
IEnumerable<HttpMethodAttribute> httpMethodAttributes = controllerAction.GetCustomAttributes<HttpMethodAttribute>(true);
25+
var httpMethodAttributes = controllerAction.GetCustomAttributes<HttpMethodAttribute>(true);
2626
return httpMethodAttributes.GetJsonApiEndpoint();
2727
}
2828

src/JsonApiDotNetCore.OpenApi.Swashbuckle/JsonApiMetadata/JsonApiEndpointMetadataProvider.cs

+9-9
Original file line numberDiff line numberDiff line change
@@ -34,18 +34,18 @@ public JsonApiEndpointMetadataContainer Get(MethodInfo controllerAction)
3434
return new JsonApiEndpointMetadataContainer(AtomicOperationsRequestMetadata.Instance, AtomicOperationsResponseMetadata.Instance);
3535
}
3636

37-
JsonApiEndpoints endpoint = EndpointResolver.Instance.GetEndpoint(controllerAction);
37+
var endpoint = EndpointResolver.Instance.GetEndpoint(controllerAction);
3838

3939
if (endpoint == JsonApiEndpoints.None)
4040
{
4141
throw new NotSupportedException($"Unable to provide metadata for non-JSON:API endpoint '{controllerAction.ReflectedType!.FullName}'.");
4242
}
4343

44-
ResourceType? primaryResourceType = _controllerResourceMapping.GetResourceTypeForController(controllerAction.ReflectedType);
44+
var primaryResourceType = _controllerResourceMapping.GetResourceTypeForController(controllerAction.ReflectedType);
4545
ConsistencyGuard.ThrowIf(primaryResourceType == null);
4646

47-
IJsonApiRequestMetadata? requestMetadata = GetRequestMetadata(endpoint, primaryResourceType);
48-
IJsonApiResponseMetadata? responseMetadata = GetResponseMetadata(endpoint, primaryResourceType);
47+
var requestMetadata = GetRequestMetadata(endpoint, primaryResourceType);
48+
var responseMetadata = GetResponseMetadata(endpoint, primaryResourceType);
4949
return new JsonApiEndpointMetadataContainer(requestMetadata, responseMetadata);
5050
}
5151

@@ -63,21 +63,21 @@ public JsonApiEndpointMetadataContainer Get(MethodInfo controllerAction)
6363

6464
private static PrimaryRequestMetadata GetPostResourceRequestMetadata(Type resourceClrType)
6565
{
66-
Type documentType = typeof(CreateRequestDocument<>).MakeGenericType(resourceClrType);
66+
var documentType = typeof(CreateRequestDocument<>).MakeGenericType(resourceClrType);
6767

6868
return new PrimaryRequestMetadata(documentType);
6969
}
7070

7171
private static PrimaryRequestMetadata GetPatchResourceRequestMetadata(Type resourceClrType)
7272
{
73-
Type documentType = typeof(UpdateRequestDocument<>).MakeGenericType(resourceClrType);
73+
var documentType = typeof(UpdateRequestDocument<>).MakeGenericType(resourceClrType);
7474

7575
return new PrimaryRequestMetadata(documentType);
7676
}
7777

7878
private RelationshipRequestMetadata GetRelationshipRequestMetadata(IEnumerable<RelationshipAttribute> relationships, bool ignoreHasOneRelationships)
7979
{
80-
IEnumerable<RelationshipAttribute> relationshipsOfEndpoint = ignoreHasOneRelationships ? relationships.OfType<HasManyAttribute>() : relationships;
80+
var relationshipsOfEndpoint = ignoreHasOneRelationships ? relationships.OfType<HasManyAttribute>() : relationships;
8181

8282
IDictionary<string, Type> requestDocumentTypesByRelationshipName = relationshipsOfEndpoint.ToDictionary(relationship => relationship.PublicName,
8383
_nonPrimaryDocumentTypeFactory.GetForRelationshipRequest);
@@ -99,8 +99,8 @@ private RelationshipRequestMetadata GetRelationshipRequestMetadata(IEnumerable<R
9999

100100
private static PrimaryResponseMetadata GetPrimaryResponseMetadata(Type resourceClrType, bool endpointReturnsCollection)
101101
{
102-
Type documentOpenType = endpointReturnsCollection ? typeof(CollectionResponseDocument<>) : typeof(PrimaryResponseDocument<>);
103-
Type documentType = documentOpenType.MakeGenericType(resourceClrType);
102+
var documentOpenType = endpointReturnsCollection ? typeof(CollectionResponseDocument<>) : typeof(PrimaryResponseDocument<>);
103+
var documentType = documentOpenType.MakeGenericType(resourceClrType);
104104

105105
return new PrimaryResponseMetadata(documentType);
106106
}

src/JsonApiDotNetCore.OpenApi.Swashbuckle/JsonApiMetadata/NonPrimaryDocumentTypeFactory.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ private Type Get(RelationshipAttribute relationship, DocumentOpenTypes types)
4949
{
5050
// @formatter:nested_ternary_style expanded
5151

52-
Type documentOpenType = relationship is HasManyAttribute
52+
var documentOpenType = relationship is HasManyAttribute
5353
? types.ManyDataOpenType
5454
: _resourceFieldValidationMetadataProvider.IsNullable(relationship)
5555
? types.NullableSingleDataOpenType

src/JsonApiDotNetCore.OpenApi.Swashbuckle/JsonApiMetadata/RelationshipTypeFactory.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public Type GetForResponse(RelationshipAttribute relationship)
3131

3232
// @formatter:nested_ternary_style expanded
3333

34-
Type relationshipDataOpenType = relationship is HasManyAttribute
34+
var relationshipDataOpenType = relationship is HasManyAttribute
3535
? typeof(ToManyInResponse<>)
3636
: _resourceFieldValidationMetadataProvider.IsNullable(relationship)
3737
? typeof(NullableToOneInResponse<>)

src/JsonApiDotNetCore.OpenApi.Swashbuckle/JsonApiRequestFormatMetadataProvider.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public IReadOnlyList<string> GetSupportedContentTypes(string contentType, Type o
2828
ArgumentException.ThrowIfNullOrEmpty(contentType);
2929
ArgumentNullException.ThrowIfNull(objectType);
3030

31-
if (JsonApiSchemaFacts.IsRequestBodySchemaType(objectType) && MediaTypeHeaderValue.TryParse(contentType, out MediaTypeHeaderValue? headerValue) &&
31+
if (JsonApiSchemaFacts.IsRequestBodySchemaType(objectType) && MediaTypeHeaderValue.TryParse(contentType, out var headerValue) &&
3232
headerValue.MediaType.Equals(DefaultMediaType, StringComparison.OrdinalIgnoreCase))
3333
{
3434
return new MediaTypeCollection

src/JsonApiDotNetCore.OpenApi.Swashbuckle/JsonApiSchemaFacts.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -34,21 +34,21 @@ internal static class JsonApiSchemaFacts
3434

3535
public static bool IsRequestBodySchemaType(Type schemaType)
3636
{
37-
Type lookupType = schemaType.ConstructedToOpenType();
37+
var lookupType = schemaType.ConstructedToOpenType();
3838
return RequestBodySchemaTypes.Contains(lookupType);
3939
}
4040

4141
public static bool HasNullableDataProperty(Type schemaType)
4242
{
4343
// Swashbuckle infers non-nullable because our Data properties are [Required].
4444

45-
Type lookupType = schemaType.ConstructedToOpenType();
45+
var lookupType = schemaType.ConstructedToOpenType();
4646
return SchemaTypesHavingNullableDataProperty.Contains(lookupType);
4747
}
4848

4949
public static bool IsRelationshipInResponseType(Type schemaType)
5050
{
51-
Type lookupType = schemaType.ConstructedToOpenType();
51+
var lookupType = schemaType.ConstructedToOpenType();
5252
return RelationshipInResponseSchemaTypes.Contains(lookupType);
5353
}
5454
}

src/JsonApiDotNetCore.OpenApi.Swashbuckle/JsonApiSchemaIdSelector.cs

+10-10
Original file line numberDiff line numberDiff line change
@@ -87,28 +87,28 @@ public string GetSchemaId(Type type)
8787
{
8888
ArgumentNullException.ThrowIfNull(type);
8989

90-
ResourceType? resourceType = _resourceGraph.FindResourceType(type);
90+
var resourceType = _resourceGraph.FindResourceType(type);
9191

9292
if (resourceType != null)
9393
{
9494
return resourceType.PublicName.Singularize();
9595
}
9696

97-
Type openType = type.ConstructedToOpenType();
97+
var openType = type.ConstructedToOpenType();
9898

9999
if (openType != type)
100100
{
101-
if (SchemaTypeToTemplateMap.TryGetValue(openType, out string? schemaTemplate))
101+
if (SchemaTypeToTemplateMap.TryGetValue(openType, out var schemaTemplate))
102102
{
103-
Type resourceClrType = type.GetGenericArguments().First();
103+
var resourceClrType = type.GetGenericArguments().First();
104104
resourceType = _resourceGraph.GetResourceType(resourceClrType);
105105

106106
return ApplySchemaTemplate(schemaTemplate, resourceType, null, null);
107107
}
108108
}
109109
else
110110
{
111-
if (SchemaTypeToTemplateMap.TryGetValue(type, out string? schemaTemplate))
111+
if (SchemaTypeToTemplateMap.TryGetValue(type, out var schemaTemplate))
112112
{
113113
return ApplySchemaTemplate(schemaTemplate, null, null, null);
114114
}
@@ -120,7 +120,7 @@ public string GetSchemaId(Type type)
120120

121121
private string ApplySchemaTemplate(string schemaTemplate, ResourceType? resourceType, string? relationshipName, AtomicOperationCode? operationCode)
122122
{
123-
string schemaId = schemaTemplate;
123+
var schemaId = schemaTemplate;
124124

125125
schemaId = resourceType != null
126126
? schemaId.Replace("[ResourceName]", resourceType.PublicName.Singularize()).Pascalize()
@@ -136,9 +136,9 @@ private string ApplySchemaTemplate(string schemaTemplate, ResourceType? resource
136136
schemaId = schemaId.Replace("[OperationCode]", operationCode.Value.ToString().Pascalize());
137137
}
138138

139-
string pascalCaseSchemaId = schemaId.Pascalize();
139+
var pascalCaseSchemaId = schemaId.Pascalize();
140140

141-
JsonNamingPolicy? namingPolicy = _options.SerializerOptions.PropertyNamingPolicy;
141+
var namingPolicy = _options.SerializerOptions.PropertyNamingPolicy;
142142
return namingPolicy != null ? namingPolicy.ConvertName(pascalCaseSchemaId) : pascalCaseSchemaId;
143143
}
144144

@@ -168,7 +168,7 @@ public string GetAtomicOperationDiscriminatorValue(AtomicOperationCode operation
168168
{
169169
ArgumentNullException.ThrowIfNull(relationship);
170170

171-
string schemaIdTemplate = operationCode switch
171+
var schemaIdTemplate = operationCode switch
172172
{
173173
AtomicOperationCode.Add => AddToRelationshipAtomicOperationDiscriminatorValueTemplate,
174174
AtomicOperationCode.Remove => RemoveFromRelationshipAtomicOperationDiscriminatorValueTemplate,
@@ -182,7 +182,7 @@ public string GetRelationshipAtomicOperationSchemaId(RelationshipAttribute relat
182182
{
183183
ArgumentNullException.ThrowIfNull(relationship);
184184

185-
string schemaIdTemplate = operationCode switch
185+
var schemaIdTemplate = operationCode switch
186186
{
187187
AtomicOperationCode.Add => AddToRelationshipAtomicOperationSchemaIdTemplate,
188188
AtomicOperationCode.Remove => RemoveFromRelationshipAtomicOperationSchemaIdTemplate,

src/JsonApiDotNetCore.OpenApi.Swashbuckle/OpenApiDescriptionLinkProvider.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@ public OpenApiDescriptionLinkProvider(IOptionsMonitor<SwaggerGeneratorOptions> s
2626
/// <inheritdoc />
2727
public string? GetUrl()
2828
{
29-
SwaggerGeneratorOptions swaggerGeneratorOptions = _swaggerGeneratorOptionsMonitor.CurrentValue;
29+
var swaggerGeneratorOptions = _swaggerGeneratorOptionsMonitor.CurrentValue;
3030

3131
if (swaggerGeneratorOptions.SwaggerDocs.Count > 0)
3232
{
33-
string latestVersionDocumentName = swaggerGeneratorOptions.SwaggerDocs.Last().Key;
33+
var latestVersionDocumentName = swaggerGeneratorOptions.SwaggerDocs.Last().Key;
3434

35-
SwaggerOptions swaggerOptions = _swaggerOptionsMonitor.CurrentValue;
35+
var swaggerOptions = _swaggerOptionsMonitor.CurrentValue;
3636
return swaggerOptions.RouteTemplate.Replace("{documentName}", latestVersionDocumentName).Replace("{extension:regex(^(json|ya?ml)$)}", "json");
3737
}
3838

0 commit comments

Comments
 (0)