From 4f5ee425b2863e69e476b91f39101ca4717f7c4b Mon Sep 17 00:00:00 2001 From: Bart Koelman Date: Mon, 20 Sep 2021 10:55:59 +0200 Subject: [PATCH] Small cleanups --- .../SwaggerComponents/JsonApiDataContractResolver.cs | 9 +++------ .../SwaggerComponents/JsonApiSchemaGenerator.cs | 8 +++----- .../ResourceObjectSchemaGenerator.cs | 12 ++++++------ 3 files changed, 12 insertions(+), 17 deletions(-) diff --git a/src/JsonApiDotNetCore.OpenApi/SwaggerComponents/JsonApiDataContractResolver.cs b/src/JsonApiDotNetCore.OpenApi/SwaggerComponents/JsonApiDataContractResolver.cs index a84acc86aa..c5723fa0ec 100644 --- a/src/JsonApiDotNetCore.OpenApi/SwaggerComponents/JsonApiDataContractResolver.cs +++ b/src/JsonApiDotNetCore.OpenApi/SwaggerComponents/JsonApiDataContractResolver.cs @@ -2,7 +2,6 @@ using System.Collections.Generic; using System.Linq; using System.Reflection; -using System.Text.Json; using JsonApiDotNetCore.Configuration; using JsonApiDotNetCore.Resources; using JsonApiDotNetCore.Resources.Annotations; @@ -18,15 +17,13 @@ internal sealed class JsonApiDataContractResolver : ISerializerDataContractResol private readonly JsonSerializerDataContractResolver _dataContractResolver; private readonly IResourceGraph _resourceGraph; - public JsonApiDataContractResolver(IResourceGraph resourceGraph, IJsonApiOptions jsonApiOptions) + public JsonApiDataContractResolver(IResourceGraph resourceGraph, IJsonApiOptions options) { ArgumentGuard.NotNull(resourceGraph, nameof(resourceGraph)); - ArgumentGuard.NotNull(jsonApiOptions, nameof(jsonApiOptions)); + ArgumentGuard.NotNull(options, nameof(options)); _resourceGraph = resourceGraph; - - JsonSerializerOptions serializerOptions = jsonApiOptions.SerializerOptions; - _dataContractResolver = new JsonSerializerDataContractResolver(serializerOptions); + _dataContractResolver = new JsonSerializerDataContractResolver(options.SerializerOptions); } public DataContract GetDataContractForType(Type type) diff --git a/src/JsonApiDotNetCore.OpenApi/SwaggerComponents/JsonApiSchemaGenerator.cs b/src/JsonApiDotNetCore.OpenApi/SwaggerComponents/JsonApiSchemaGenerator.cs index 4a75378f1a..05e17fabce 100644 --- a/src/JsonApiDotNetCore.OpenApi/SwaggerComponents/JsonApiSchemaGenerator.cs +++ b/src/JsonApiDotNetCore.OpenApi/SwaggerComponents/JsonApiSchemaGenerator.cs @@ -40,18 +40,16 @@ internal sealed class JsonApiSchemaGenerator : ISchemaGenerator private readonly JsonApiObjectNullabilityProcessor _jsonApiObjectNullabilityProcessor; private readonly SchemaRepositoryAccessor _schemaRepositoryAccessor = new(); - public JsonApiSchemaGenerator(SchemaGenerator defaultSchemaGenerator, IResourceGraph resourceGraph, IJsonApiOptions jsonApiOptions) + public JsonApiSchemaGenerator(SchemaGenerator defaultSchemaGenerator, IResourceGraph resourceGraph, IJsonApiOptions options) { ArgumentGuard.NotNull(defaultSchemaGenerator, nameof(defaultSchemaGenerator)); ArgumentGuard.NotNull(resourceGraph, nameof(resourceGraph)); - ArgumentGuard.NotNull(jsonApiOptions, nameof(jsonApiOptions)); + ArgumentGuard.NotNull(options, nameof(options)); _defaultSchemaGenerator = defaultSchemaGenerator; _nullableReferenceSchemaGenerator = new NullableReferenceSchemaGenerator(_schemaRepositoryAccessor); _jsonApiObjectNullabilityProcessor = new JsonApiObjectNullabilityProcessor(_schemaRepositoryAccessor); - - _resourceObjectSchemaGenerator = - new ResourceObjectSchemaGenerator(defaultSchemaGenerator, resourceGraph, jsonApiOptions, _schemaRepositoryAccessor); + _resourceObjectSchemaGenerator = new ResourceObjectSchemaGenerator(defaultSchemaGenerator, resourceGraph, options, _schemaRepositoryAccessor); } public OpenApiSchema GenerateSchema(Type type, SchemaRepository schemaRepository, MemberInfo memberInfo = null, ParameterInfo parameterInfo = null) diff --git a/src/JsonApiDotNetCore.OpenApi/SwaggerComponents/ResourceObjectSchemaGenerator.cs b/src/JsonApiDotNetCore.OpenApi/SwaggerComponents/ResourceObjectSchemaGenerator.cs index 5aabb571a7..baf380972d 100644 --- a/src/JsonApiDotNetCore.OpenApi/SwaggerComponents/ResourceObjectSchemaGenerator.cs +++ b/src/JsonApiDotNetCore.OpenApi/SwaggerComponents/ResourceObjectSchemaGenerator.cs @@ -17,12 +17,12 @@ internal sealed class ResourceObjectSchemaGenerator private readonly bool _allowClientGeneratedIds; private readonly Func _createFieldObjectBuilderFactory; - public ResourceObjectSchemaGenerator(SchemaGenerator defaultSchemaGenerator, IResourceGraph resourceGraph, IJsonApiOptions jsonApiOptions, + public ResourceObjectSchemaGenerator(SchemaGenerator defaultSchemaGenerator, IResourceGraph resourceGraph, IJsonApiOptions options, ISchemaRepositoryAccessor schemaRepositoryAccessor) { ArgumentGuard.NotNull(defaultSchemaGenerator, nameof(defaultSchemaGenerator)); ArgumentGuard.NotNull(resourceGraph, nameof(resourceGraph)); - ArgumentGuard.NotNull(jsonApiOptions, nameof(jsonApiOptions)); + ArgumentGuard.NotNull(options, nameof(options)); ArgumentGuard.NotNull(schemaRepositoryAccessor, nameof(schemaRepositoryAccessor)); _defaultSchemaGenerator = defaultSchemaGenerator; @@ -30,17 +30,17 @@ public ResourceObjectSchemaGenerator(SchemaGenerator defaultSchemaGenerator, IRe _schemaRepositoryAccessor = schemaRepositoryAccessor; _resourceTypeSchemaGenerator = new ResourceTypeSchemaGenerator(schemaRepositoryAccessor, resourceGraph); - _allowClientGeneratedIds = jsonApiOptions.AllowClientGeneratedIds; + _allowClientGeneratedIds = options.AllowClientGeneratedIds; - _createFieldObjectBuilderFactory = CreateFieldObjectBuilderFactory(defaultSchemaGenerator, resourceGraph, jsonApiOptions, schemaRepositoryAccessor, + _createFieldObjectBuilderFactory = CreateFieldObjectBuilderFactory(defaultSchemaGenerator, resourceGraph, options, schemaRepositoryAccessor, _resourceTypeSchemaGenerator); } private static Func CreateFieldObjectBuilderFactory(SchemaGenerator defaultSchemaGenerator, - IResourceGraph resourceGraph, IJsonApiOptions jsonApiOptions, ISchemaRepositoryAccessor schemaRepositoryAccessor, + IResourceGraph resourceGraph, IJsonApiOptions options, ISchemaRepositoryAccessor schemaRepositoryAccessor, ResourceTypeSchemaGenerator resourceTypeSchemaGenerator) { - JsonNamingPolicy namingPolicy = jsonApiOptions.SerializerOptions.PropertyNamingPolicy; + JsonNamingPolicy namingPolicy = options.SerializerOptions.PropertyNamingPolicy; ResourceNameFormatter resourceNameFormatter = new(namingPolicy); var jsonApiSchemaIdSelector = new JsonApiSchemaIdSelector(resourceNameFormatter, resourceGraph);