Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Small refactor #1116

Merged
merged 5 commits into from
Dec 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
namespace JsonApiDotNetCore.OpenApi.JsonApiObjects.Documents
{
[UsedImplicitly(ImplicitUseTargetFlags.Members)]
internal sealed class NullableSecondaryResourceResponseDocument<TResource> : NullableSingleData<ResourceResponseObject<TResource>>
internal sealed class NullableSecondaryResourceResponseDocument<TResource> : NullableSingleData<ResourceObjectInResponse<TResource>>
where TResource : IIdentifiable
{
public IDictionary<string, object> Meta { get; set; } = null!;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace JsonApiDotNetCore.OpenApi.JsonApiObjects.Documents
// Types in the current namespace are never touched by ASP.NET ModelState validation, therefore using a non-nullable reference type for a property does not
// imply this property is required. Instead, we use [Required] explicitly, because this is how Swashbuckle is instructed to mark properties as required.
[UsedImplicitly(ImplicitUseTargetFlags.Members)]
internal sealed class PrimaryResourceResponseDocument<TResource> : SingleData<ResourceResponseObject<TResource>>
internal sealed class PrimaryResourceResponseDocument<TResource> : SingleData<ResourceObjectInResponse<TResource>>
where TResource : IIdentifiable
{
public IDictionary<string, object> Meta { get; set; } = null!;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
namespace JsonApiDotNetCore.OpenApi.JsonApiObjects.Documents
{
[UsedImplicitly(ImplicitUseTargetFlags.Members)]
internal sealed class ResourceCollectionResponseDocument<TResource> : ManyData<ResourceResponseObject<TResource>>
internal sealed class ResourceCollectionResponseDocument<TResource> : ManyData<ResourceObjectInResponse<TResource>>
where TResource : IIdentifiable
{
public IDictionary<string, object> Meta { get; set; } = null!;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace JsonApiDotNetCore.OpenApi.JsonApiObjects.Documents
{
[UsedImplicitly(ImplicitUseTargetFlags.Members)]
internal sealed class ResourcePatchRequestDocument<TResource> : SingleData<ResourcePatchRequestObject<TResource>>
internal sealed class ResourcePatchRequestDocument<TResource> : SingleData<ResourceObjectInPatchRequest<TResource>>
where TResource : IIdentifiable
{
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace JsonApiDotNetCore.OpenApi.JsonApiObjects.Documents
{
[UsedImplicitly(ImplicitUseTargetFlags.Members)]
internal sealed class ResourcePostRequestDocument<TResource> : SingleData<ResourcePostRequestObject<TResource>>
internal sealed class ResourcePostRequestDocument<TResource> : SingleData<ResourceObjectInPostRequest<TResource>>
where TResource : IIdentifiable
{
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
namespace JsonApiDotNetCore.OpenApi.JsonApiObjects.Documents
{
[UsedImplicitly(ImplicitUseTargetFlags.Members)]
internal sealed class SecondaryResourceResponseDocument<TResource> : SingleData<ResourceResponseObject<TResource>>
internal sealed class SecondaryResourceResponseDocument<TResource> : SingleData<ResourceObjectInResponse<TResource>>
where TResource : IIdentifiable
{
public IDictionary<string, object> Meta { get; set; } = null!;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System;
using JsonApiDotNetCore.OpenApi.JsonApiObjects.Documents;
using JsonApiDotNetCore.OpenApi.JsonApiObjects.RelationshipData;
using JsonApiDotNetCore.OpenApi.JsonApiObjects.Relationships;
using JsonApiDotNetCore.Resources.Annotations;

namespace JsonApiDotNetCore.OpenApi.JsonApiObjects
Expand All @@ -10,8 +10,8 @@ internal sealed class NonPrimaryDocumentTypeFactory
private static readonly DocumentOpenTypes SecondaryResponseDocumentOpenTypes = new(typeof(ResourceCollectionResponseDocument<>),
typeof(NullableSecondaryResourceResponseDocument<>), typeof(SecondaryResourceResponseDocument<>));

private static readonly DocumentOpenTypes RelationshipRequestDocumentOpenTypes = new(typeof(ToManyRelationshipRequestData<>),
typeof(NullableToOneRelationshipRequestData<>), typeof(ToOneRelationshipRequestData<>));
private static readonly DocumentOpenTypes RelationshipRequestDocumentOpenTypes = new(typeof(ToManyRelationshipInRequest<>),
typeof(NullableToOneRelationshipInRequest<>), typeof(ToOneRelationshipInRequest<>));

private static readonly DocumentOpenTypes RelationshipResponseDocumentOpenTypes = new(typeof(ResourceIdentifierCollectionResponseDocument<>),
typeof(NullableResourceIdentifierResponseDocument<>), typeof(ResourceIdentifierResponseDocument<>));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
using System;
using JsonApiDotNetCore.OpenApi.JsonApiObjects.RelationshipData;
using JsonApiDotNetCore.OpenApi.JsonApiObjects.Relationships;
using JsonApiDotNetCore.Resources.Annotations;

namespace JsonApiDotNetCore.OpenApi.JsonApiObjects
{
internal sealed class RelationshipDataTypeFactory
internal sealed class RelationshipTypeFactory
{
public static RelationshipDataTypeFactory Instance { get; } = new();
public static RelationshipTypeFactory Instance { get; } = new();

private RelationshipDataTypeFactory()
private RelationshipTypeFactory()
{
}

Expand All @@ -26,10 +26,10 @@ public Type GetForResponse(RelationshipAttribute relationship)
// @formatter:nested_ternary_style expanded

Type relationshipDataOpenType = relationship is HasManyAttribute
? typeof(ToManyRelationshipResponseData<>)
? typeof(ToManyRelationshipInResponse<>)
: relationship.IsNullable()
? typeof(NullableToOneRelationshipResponseData<>)
: typeof(ToOneRelationshipResponseData<>);
? typeof(NullableToOneRelationshipInResponse<>)
: typeof(ToOneRelationshipInResponse<>);

// @formatter:nested_ternary_style restore

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
using JsonApiDotNetCore.OpenApi.JsonApiObjects.ResourceObjects;
using JsonApiDotNetCore.Resources;

namespace JsonApiDotNetCore.OpenApi.JsonApiObjects.RelationshipData
namespace JsonApiDotNetCore.OpenApi.JsonApiObjects.Relationships
{
[UsedImplicitly(ImplicitUseTargetFlags.Members)]
internal sealed class NullableToOneRelationshipRequestData<TResource> : NullableSingleData<ResourceIdentifierObject<TResource>>
internal sealed class NullableToOneRelationshipInRequest<TResource> : NullableSingleData<ResourceIdentifierObject<TResource>>
where TResource : IIdentifiable
{
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
using JsonApiDotNetCore.OpenApi.JsonApiObjects.ResourceObjects;
using JsonApiDotNetCore.Resources;

namespace JsonApiDotNetCore.OpenApi.JsonApiObjects.RelationshipData
namespace JsonApiDotNetCore.OpenApi.JsonApiObjects.Relationships
{
[UsedImplicitly(ImplicitUseTargetFlags.Members)]
internal sealed class NullableToOneRelationshipResponseData<TResource> : NullableSingleData<ResourceIdentifierObject<TResource>>
internal sealed class NullableToOneRelationshipInResponse<TResource> : NullableSingleData<ResourceIdentifierObject<TResource>>
where TResource : IIdentifiable
{
[Required]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
using JsonApiDotNetCore.OpenApi.JsonApiObjects.ResourceObjects;
using JsonApiDotNetCore.Resources;

namespace JsonApiDotNetCore.OpenApi.JsonApiObjects.RelationshipData
namespace JsonApiDotNetCore.OpenApi.JsonApiObjects.Relationships
{
[UsedImplicitly(ImplicitUseTargetFlags.Members)]
internal sealed class ToManyRelationshipRequestData<TResource> : ManyData<ResourceIdentifierObject<TResource>>
internal sealed class ToManyRelationshipInRequest<TResource> : ManyData<ResourceIdentifierObject<TResource>>
where TResource : IIdentifiable
{
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
using JsonApiDotNetCore.OpenApi.JsonApiObjects.ResourceObjects;
using JsonApiDotNetCore.Resources;

namespace JsonApiDotNetCore.OpenApi.JsonApiObjects.RelationshipData
namespace JsonApiDotNetCore.OpenApi.JsonApiObjects.Relationships
{
[UsedImplicitly(ImplicitUseTargetFlags.Members)]
internal sealed class ToManyRelationshipResponseData<TResource> : ManyData<ResourceIdentifierObject<TResource>>
internal sealed class ToManyRelationshipInResponse<TResource> : ManyData<ResourceIdentifierObject<TResource>>
where TResource : IIdentifiable
{
[Required]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
using JsonApiDotNetCore.OpenApi.JsonApiObjects.ResourceObjects;
using JsonApiDotNetCore.Resources;

namespace JsonApiDotNetCore.OpenApi.JsonApiObjects.RelationshipData
namespace JsonApiDotNetCore.OpenApi.JsonApiObjects.Relationships
{
[UsedImplicitly(ImplicitUseTargetFlags.Members)]
internal sealed class ToOneRelationshipRequestData<TResource> : SingleData<ResourceIdentifierObject<TResource>>
internal sealed class ToOneRelationshipInRequest<TResource> : SingleData<ResourceIdentifierObject<TResource>>
where TResource : IIdentifiable
{
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
using JsonApiDotNetCore.OpenApi.JsonApiObjects.ResourceObjects;
using JsonApiDotNetCore.Resources;

namespace JsonApiDotNetCore.OpenApi.JsonApiObjects.RelationshipData
namespace JsonApiDotNetCore.OpenApi.JsonApiObjects.Relationships
{
[UsedImplicitly(ImplicitUseTargetFlags.Members)]
internal sealed class ToOneRelationshipResponseData<TResource> : SingleData<ResourceIdentifierObject<TResource>>
internal sealed class ToOneRelationshipInResponse<TResource> : SingleData<ResourceIdentifierObject<TResource>>
where TResource : IIdentifiable
{
[Required]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using JsonApiDotNetCore.Resources;

namespace JsonApiDotNetCore.OpenApi.JsonApiObjects.ResourceObjects
{
// ReSharper disable once UnusedTypeParameter
internal sealed class AttributesInPatchRequest<TResource>
where TResource : IIdentifiable
{
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

namespace JsonApiDotNetCore.OpenApi.JsonApiObjects.ResourceObjects
{
internal sealed class ResourcePostRequestObject<TResource> : ResourceObject<TResource>
// ReSharper disable once UnusedTypeParameter
internal sealed class AttributesInPostRequest<TResource>
where TResource : IIdentifiable
{
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

namespace JsonApiDotNetCore.OpenApi.JsonApiObjects.ResourceObjects
{
internal sealed class ResourcePatchRequestObject<TResource> : ResourceObject<TResource>
// ReSharper disable once UnusedTypeParameter
internal sealed class AttributesInResponse<TResource>
where TResource : IIdentifiable
{
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using JsonApiDotNetCore.Resources;

namespace JsonApiDotNetCore.OpenApi.JsonApiObjects.ResourceObjects
{
// ReSharper disable once UnusedTypeParameter
internal sealed class RelationshipsInPatchRequest<TResource>
where TResource : IIdentifiable
{
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using JsonApiDotNetCore.Resources;

namespace JsonApiDotNetCore.OpenApi.JsonApiObjects.ResourceObjects
{
// ReSharper disable once UnusedTypeParameter
internal sealed class RelationshipsInPostRequest<TResource>
where TResource : IIdentifiable
{
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using JsonApiDotNetCore.Resources;

namespace JsonApiDotNetCore.OpenApi.JsonApiObjects.ResourceObjects
{
// ReSharper disable once UnusedTypeParameter
internal sealed class RelationshipsInResponse<TResource>
where TResource : IIdentifiable
{
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace JsonApiDotNetCore.OpenApi.JsonApiObjects.ResourceObjects
{
// ReSharper disable once UnusedTypeParameter
internal class ResourceIdentifierObject<TResource> : ResourceIdentifierObject
internal sealed class ResourceIdentifierObject<TResource> : ResourceIdentifierObject
where TResource : IIdentifiable
{
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using JetBrains.Annotations;
using JsonApiDotNetCore.Resources;

namespace JsonApiDotNetCore.OpenApi.JsonApiObjects.ResourceObjects
{
[UsedImplicitly(ImplicitUseTargetFlags.Members)]
internal sealed class ResourceObjectInPatchRequest<TResource> : ResourceIdentifierObject
where TResource : IIdentifiable
{
public AttributesInPatchRequest<TResource> Attributes { get; set; } = null!;

public RelationshipsInPatchRequest<TResource> Relationships { get; set; } = null!;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using JetBrains.Annotations;
using JsonApiDotNetCore.Resources;

namespace JsonApiDotNetCore.OpenApi.JsonApiObjects.ResourceObjects
{
[UsedImplicitly(ImplicitUseTargetFlags.Members)]
internal sealed class ResourceObjectInPostRequest<TResource> : ResourceIdentifierObject
where TResource : IIdentifiable
{
public AttributesInPostRequest<TResource> Attributes { get; set; } = null!;

public RelationshipsInPostRequest<TResource> Relationships { get; set; } = null!;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,13 @@
namespace JsonApiDotNetCore.OpenApi.JsonApiObjects.ResourceObjects
{
[UsedImplicitly(ImplicitUseTargetFlags.Members)]
internal sealed class ResourceResponseObject<TResource> : ResourceObject<TResource>
internal sealed class ResourceObjectInResponse<TResource> : ResourceIdentifierObject
where TResource : IIdentifiable
{
public AttributesInResponse<TResource> Attributes { get; set; } = null!;

public RelationshipsInResponse<TResource> Relationships { get; set; } = null!;

[Required]
public LinksInResourceObject Links { get; set; } = null!;

Expand Down
8 changes: 4 additions & 4 deletions src/JsonApiDotNetCore.OpenApi/JsonApiOperationIdSelector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
using JsonApiDotNetCore.Configuration;
using JsonApiDotNetCore.Middleware;
using JsonApiDotNetCore.OpenApi.JsonApiObjects.Documents;
using JsonApiDotNetCore.OpenApi.JsonApiObjects.RelationshipData;
using JsonApiDotNetCore.OpenApi.JsonApiObjects.Relationships;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.ApiExplorer;
using Microsoft.AspNetCore.Mvc.Controllers;
Expand All @@ -32,9 +32,9 @@ internal sealed class JsonApiOperationIdSelector
[typeof(ResourceIdentifierCollectionResponseDocument<>)] = RelationshipOperationIdTemplate,
[typeof(ResourceIdentifierResponseDocument<>)] = RelationshipOperationIdTemplate,
[typeof(NullableResourceIdentifierResponseDocument<>)] = RelationshipOperationIdTemplate,
[typeof(ToOneRelationshipRequestData<>)] = RelationshipOperationIdTemplate,
[typeof(NullableToOneRelationshipRequestData<>)] = RelationshipOperationIdTemplate,
[typeof(ToManyRelationshipRequestData<>)] = RelationshipOperationIdTemplate
[typeof(ToOneRelationshipInRequest<>)] = RelationshipOperationIdTemplate,
[typeof(NullableToOneRelationshipInRequest<>)] = RelationshipOperationIdTemplate,
[typeof(ToManyRelationshipInRequest<>)] = RelationshipOperationIdTemplate
};

private readonly IControllerResourceMapping _controllerResourceMapping;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using System.Threading.Tasks;
using JsonApiDotNetCore.Middleware;
using JsonApiDotNetCore.OpenApi.JsonApiObjects.Documents;
using JsonApiDotNetCore.OpenApi.JsonApiObjects.RelationshipData;
using JsonApiDotNetCore.OpenApi.JsonApiObjects.Relationships;
using Microsoft.AspNetCore.Mvc.ApiExplorer;
using Microsoft.AspNetCore.Mvc.Formatters;
using Microsoft.Net.Http.Headers;
Expand All @@ -15,9 +15,9 @@ internal sealed class JsonApiRequestFormatMetadataProvider : IInputFormatter, IA
{
private static readonly Type[] JsonApiRequestObjectOpenType =
{
typeof(ToManyRelationshipRequestData<>),
typeof(ToOneRelationshipRequestData<>),
typeof(NullableToOneRelationshipRequestData<>),
typeof(ToManyRelationshipInRequest<>),
typeof(ToOneRelationshipInRequest<>),
typeof(NullableToOneRelationshipInRequest<>),
typeof(ResourcePostRequestDocument<>),
typeof(ResourcePatchRequestDocument<>)
};
Expand Down
Loading