Skip to content

Commit

Permalink
Small cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
Bart Koelman committed Sep 20, 2021
1 parent 41c24c4 commit 4f5ee42
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,30 +17,30 @@ internal sealed class ResourceObjectSchemaGenerator
private readonly bool _allowClientGeneratedIds;
private readonly Func<ResourceTypeInfo, ResourceFieldObjectSchemaBuilder> _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;
_resourceGraph = resourceGraph;
_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<ResourceTypeInfo, ResourceFieldObjectSchemaBuilder> 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);

Expand Down

0 comments on commit 4f5ee42

Please sign in to comment.