From 6160ad05c59e4d1091af5ae10ece6a68b68d303c Mon Sep 17 00:00:00 2001 From: maurei Date: Tue, 23 Nov 2021 11:28:56 +0100 Subject: [PATCH 1/5] Renamed variables and types to be consistent with JSON:API spec, where the vocabulary is 'RelationshipsObject' with its members being a 'Relationship'. --- .../NonPrimaryDocumentTypeFactory.cs | 6 +- ...eFactory.cs => RelationshipTypeFactory.cs} | 14 +-- .../NullableToOneRelationshipInRequest.cs} | 4 +- .../NullableToOneRelationshipInResponse.cs} | 4 +- .../ToManyRelationshipInRequest.cs} | 4 +- .../ToManyRelationshipInResponse.cs} | 4 +- .../ToOneRelationshipInRequest.cs} | 4 +- .../ToOneRelationshipInResponse.cs} | 4 +- .../JsonApiOperationIdSelector.cs | 8 +- .../JsonApiRequestFormatMetadataProvider.cs | 8 +- .../JsonApiSchemaIdSelector.cs | 14 +-- .../JsonApiSchemaGenerator.cs | 8 +- .../ResourceFieldObjectSchemaBuilder.cs | 51 +++++----- .../LegacyClient/RequestTests.cs | 12 +-- .../LegacyClient/ResponseTests.cs | 10 +- .../LegacyOpenApiIntegration/swagger.json | 96 +++++++++---------- 16 files changed, 125 insertions(+), 126 deletions(-) rename src/JsonApiDotNetCore.OpenApi/JsonApiObjects/{RelationshipDataTypeFactory.cs => RelationshipTypeFactory.cs} (67%) rename src/JsonApiDotNetCore.OpenApi/JsonApiObjects/{RelationshipData/NullableToOneRelationshipRequestData.cs => Relationships/NullableToOneRelationshipInRequest.cs} (54%) rename src/JsonApiDotNetCore.OpenApi/JsonApiObjects/{RelationshipData/NullableToOneRelationshipResponseData.cs => Relationships/NullableToOneRelationshipInResponse.cs} (72%) rename src/JsonApiDotNetCore.OpenApi/JsonApiObjects/{RelationshipData/ToManyRelationshipRequestData.cs => Relationships/ToManyRelationshipInRequest.cs} (56%) rename src/JsonApiDotNetCore.OpenApi/JsonApiObjects/{RelationshipData/ToManyRelationshipResponseData.cs => Relationships/ToManyRelationshipInResponse.cs} (74%) rename src/JsonApiDotNetCore.OpenApi/JsonApiObjects/{RelationshipData/ToOneRelationshipRequestData.cs => Relationships/ToOneRelationshipInRequest.cs} (56%) rename src/JsonApiDotNetCore.OpenApi/JsonApiObjects/{RelationshipData/ToOneRelationshipResponseData.cs => Relationships/ToOneRelationshipInResponse.cs} (74%) diff --git a/src/JsonApiDotNetCore.OpenApi/JsonApiObjects/NonPrimaryDocumentTypeFactory.cs b/src/JsonApiDotNetCore.OpenApi/JsonApiObjects/NonPrimaryDocumentTypeFactory.cs index 54a3d82bf3..9b213ca336 100644 --- a/src/JsonApiDotNetCore.OpenApi/JsonApiObjects/NonPrimaryDocumentTypeFactory.cs +++ b/src/JsonApiDotNetCore.OpenApi/JsonApiObjects/NonPrimaryDocumentTypeFactory.cs @@ -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 @@ -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<>)); diff --git a/src/JsonApiDotNetCore.OpenApi/JsonApiObjects/RelationshipDataTypeFactory.cs b/src/JsonApiDotNetCore.OpenApi/JsonApiObjects/RelationshipTypeFactory.cs similarity index 67% rename from src/JsonApiDotNetCore.OpenApi/JsonApiObjects/RelationshipDataTypeFactory.cs rename to src/JsonApiDotNetCore.OpenApi/JsonApiObjects/RelationshipTypeFactory.cs index dde79ca61a..4a2dc2775d 100644 --- a/src/JsonApiDotNetCore.OpenApi/JsonApiObjects/RelationshipDataTypeFactory.cs +++ b/src/JsonApiDotNetCore.OpenApi/JsonApiObjects/RelationshipTypeFactory.cs @@ -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() { } @@ -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 diff --git a/src/JsonApiDotNetCore.OpenApi/JsonApiObjects/RelationshipData/NullableToOneRelationshipRequestData.cs b/src/JsonApiDotNetCore.OpenApi/JsonApiObjects/Relationships/NullableToOneRelationshipInRequest.cs similarity index 54% rename from src/JsonApiDotNetCore.OpenApi/JsonApiObjects/RelationshipData/NullableToOneRelationshipRequestData.cs rename to src/JsonApiDotNetCore.OpenApi/JsonApiObjects/Relationships/NullableToOneRelationshipInRequest.cs index a6163ab358..7c21bee5d8 100644 --- a/src/JsonApiDotNetCore.OpenApi/JsonApiObjects/RelationshipData/NullableToOneRelationshipRequestData.cs +++ b/src/JsonApiDotNetCore.OpenApi/JsonApiObjects/Relationships/NullableToOneRelationshipInRequest.cs @@ -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 : NullableSingleData> + internal sealed class NullableToOneRelationshipInRequest : NullableSingleData> where TResource : IIdentifiable { } diff --git a/src/JsonApiDotNetCore.OpenApi/JsonApiObjects/RelationshipData/NullableToOneRelationshipResponseData.cs b/src/JsonApiDotNetCore.OpenApi/JsonApiObjects/Relationships/NullableToOneRelationshipInResponse.cs similarity index 72% rename from src/JsonApiDotNetCore.OpenApi/JsonApiObjects/RelationshipData/NullableToOneRelationshipResponseData.cs rename to src/JsonApiDotNetCore.OpenApi/JsonApiObjects/Relationships/NullableToOneRelationshipInResponse.cs index 7e2c8714ba..795d5a503b 100644 --- a/src/JsonApiDotNetCore.OpenApi/JsonApiObjects/RelationshipData/NullableToOneRelationshipResponseData.cs +++ b/src/JsonApiDotNetCore.OpenApi/JsonApiObjects/Relationships/NullableToOneRelationshipInResponse.cs @@ -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 : NullableSingleData> + internal sealed class NullableToOneRelationshipInResponse : NullableSingleData> where TResource : IIdentifiable { [Required] diff --git a/src/JsonApiDotNetCore.OpenApi/JsonApiObjects/RelationshipData/ToManyRelationshipRequestData.cs b/src/JsonApiDotNetCore.OpenApi/JsonApiObjects/Relationships/ToManyRelationshipInRequest.cs similarity index 56% rename from src/JsonApiDotNetCore.OpenApi/JsonApiObjects/RelationshipData/ToManyRelationshipRequestData.cs rename to src/JsonApiDotNetCore.OpenApi/JsonApiObjects/Relationships/ToManyRelationshipInRequest.cs index 0d29dd496a..51570a56f4 100644 --- a/src/JsonApiDotNetCore.OpenApi/JsonApiObjects/RelationshipData/ToManyRelationshipRequestData.cs +++ b/src/JsonApiDotNetCore.OpenApi/JsonApiObjects/Relationships/ToManyRelationshipInRequest.cs @@ -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 : ManyData> + internal sealed class ToManyRelationshipInRequest : ManyData> where TResource : IIdentifiable { } diff --git a/src/JsonApiDotNetCore.OpenApi/JsonApiObjects/RelationshipData/ToManyRelationshipResponseData.cs b/src/JsonApiDotNetCore.OpenApi/JsonApiObjects/Relationships/ToManyRelationshipInResponse.cs similarity index 74% rename from src/JsonApiDotNetCore.OpenApi/JsonApiObjects/RelationshipData/ToManyRelationshipResponseData.cs rename to src/JsonApiDotNetCore.OpenApi/JsonApiObjects/Relationships/ToManyRelationshipInResponse.cs index eb5eb2d1ac..90e88d334e 100644 --- a/src/JsonApiDotNetCore.OpenApi/JsonApiObjects/RelationshipData/ToManyRelationshipResponseData.cs +++ b/src/JsonApiDotNetCore.OpenApi/JsonApiObjects/Relationships/ToManyRelationshipInResponse.cs @@ -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 : ManyData> + internal sealed class ToManyRelationshipInResponse : ManyData> where TResource : IIdentifiable { [Required] diff --git a/src/JsonApiDotNetCore.OpenApi/JsonApiObjects/RelationshipData/ToOneRelationshipRequestData.cs b/src/JsonApiDotNetCore.OpenApi/JsonApiObjects/Relationships/ToOneRelationshipInRequest.cs similarity index 56% rename from src/JsonApiDotNetCore.OpenApi/JsonApiObjects/RelationshipData/ToOneRelationshipRequestData.cs rename to src/JsonApiDotNetCore.OpenApi/JsonApiObjects/Relationships/ToOneRelationshipInRequest.cs index 1526768c31..0d95b0efb2 100644 --- a/src/JsonApiDotNetCore.OpenApi/JsonApiObjects/RelationshipData/ToOneRelationshipRequestData.cs +++ b/src/JsonApiDotNetCore.OpenApi/JsonApiObjects/Relationships/ToOneRelationshipInRequest.cs @@ -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 : SingleData> + internal sealed class ToOneRelationshipInRequest : SingleData> where TResource : IIdentifiable { } diff --git a/src/JsonApiDotNetCore.OpenApi/JsonApiObjects/RelationshipData/ToOneRelationshipResponseData.cs b/src/JsonApiDotNetCore.OpenApi/JsonApiObjects/Relationships/ToOneRelationshipInResponse.cs similarity index 74% rename from src/JsonApiDotNetCore.OpenApi/JsonApiObjects/RelationshipData/ToOneRelationshipResponseData.cs rename to src/JsonApiDotNetCore.OpenApi/JsonApiObjects/Relationships/ToOneRelationshipInResponse.cs index 02798adee8..491c42740e 100644 --- a/src/JsonApiDotNetCore.OpenApi/JsonApiObjects/RelationshipData/ToOneRelationshipResponseData.cs +++ b/src/JsonApiDotNetCore.OpenApi/JsonApiObjects/Relationships/ToOneRelationshipInResponse.cs @@ -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 : SingleData> + internal sealed class ToOneRelationshipInResponse : SingleData> where TResource : IIdentifiable { [Required] diff --git a/src/JsonApiDotNetCore.OpenApi/JsonApiOperationIdSelector.cs b/src/JsonApiDotNetCore.OpenApi/JsonApiOperationIdSelector.cs index 410a63a4ba..e73c23e822 100644 --- a/src/JsonApiDotNetCore.OpenApi/JsonApiOperationIdSelector.cs +++ b/src/JsonApiDotNetCore.OpenApi/JsonApiOperationIdSelector.cs @@ -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; @@ -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; diff --git a/src/JsonApiDotNetCore.OpenApi/JsonApiRequestFormatMetadataProvider.cs b/src/JsonApiDotNetCore.OpenApi/JsonApiRequestFormatMetadataProvider.cs index e3d2a0a17a..738c90e043 100644 --- a/src/JsonApiDotNetCore.OpenApi/JsonApiRequestFormatMetadataProvider.cs +++ b/src/JsonApiDotNetCore.OpenApi/JsonApiRequestFormatMetadataProvider.cs @@ -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; @@ -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<>) }; diff --git a/src/JsonApiDotNetCore.OpenApi/JsonApiSchemaIdSelector.cs b/src/JsonApiDotNetCore.OpenApi/JsonApiSchemaIdSelector.cs index d8ad776cf8..64579c81e7 100644 --- a/src/JsonApiDotNetCore.OpenApi/JsonApiSchemaIdSelector.cs +++ b/src/JsonApiDotNetCore.OpenApi/JsonApiSchemaIdSelector.cs @@ -4,7 +4,7 @@ using Humanizer; using JsonApiDotNetCore.Configuration; using JsonApiDotNetCore.OpenApi.JsonApiObjects.Documents; -using JsonApiDotNetCore.OpenApi.JsonApiObjects.RelationshipData; +using JsonApiDotNetCore.OpenApi.JsonApiObjects.Relationships; using JsonApiDotNetCore.OpenApi.JsonApiObjects.ResourceObjects; namespace JsonApiDotNetCore.OpenApi @@ -17,9 +17,9 @@ internal sealed class JsonApiSchemaIdSelector [typeof(ResourcePatchRequestDocument<>)] = "###-patch-request-document", [typeof(ResourcePostRequestObject<>)] = "###-data-in-post-request", [typeof(ResourcePatchRequestObject<>)] = "###-data-in-patch-request", - [typeof(ToOneRelationshipRequestData<>)] = "to-one-###-request-data", - [typeof(NullableToOneRelationshipRequestData<>)] = "nullable-to-one-###-request-data", - [typeof(ToManyRelationshipRequestData<>)] = "to-many-###-request-data", + [typeof(ToOneRelationshipInRequest<>)] = "to-one-###-data-in-request", + [typeof(NullableToOneRelationshipInRequest<>)] = "nullable-to-one-###-data-in-request", + [typeof(ToManyRelationshipInRequest<>)] = "to-many-###-data-in-request", [typeof(PrimaryResourceResponseDocument<>)] = "###-primary-response-document", [typeof(SecondaryResourceResponseDocument<>)] = "###-secondary-response-document", [typeof(NullableSecondaryResourceResponseDocument<>)] = "nullable-###-secondary-response-document", @@ -27,9 +27,9 @@ internal sealed class JsonApiSchemaIdSelector [typeof(ResourceIdentifierResponseDocument<>)] = "###-identifier-response-document", [typeof(NullableResourceIdentifierResponseDocument<>)] = "nullable-###-identifier-response-document", [typeof(ResourceIdentifierCollectionResponseDocument<>)] = "###-identifier-collection-response-document", - [typeof(ToOneRelationshipResponseData<>)] = "to-one-###-response-data", - [typeof(NullableToOneRelationshipResponseData<>)] = "nullable-to-one-###-response-data", - [typeof(ToManyRelationshipResponseData<>)] = "to-many-###-response-data", + [typeof(ToOneRelationshipInResponse<>)] = "to-one-###-data-in-response", + [typeof(NullableToOneRelationshipInResponse<>)] = "nullable-to-one-###-data-in-response", + [typeof(ToManyRelationshipInResponse<>)] = "to-many-###-data-in-response", [typeof(ResourceResponseObject<>)] = "###-data-in-response", [typeof(ResourceIdentifierObject<>)] = "###-identifier" }; diff --git a/src/JsonApiDotNetCore.OpenApi/SwaggerComponents/JsonApiSchemaGenerator.cs b/src/JsonApiDotNetCore.OpenApi/SwaggerComponents/JsonApiSchemaGenerator.cs index 3e7c98b9f9..7d47d180d5 100644 --- a/src/JsonApiDotNetCore.OpenApi/SwaggerComponents/JsonApiSchemaGenerator.cs +++ b/src/JsonApiDotNetCore.OpenApi/SwaggerComponents/JsonApiSchemaGenerator.cs @@ -4,7 +4,7 @@ using JsonApiDotNetCore.Configuration; using JsonApiDotNetCore.OpenApi.JsonApiObjects; using JsonApiDotNetCore.OpenApi.JsonApiObjects.Documents; -using JsonApiDotNetCore.OpenApi.JsonApiObjects.RelationshipData; +using JsonApiDotNetCore.OpenApi.JsonApiObjects.Relationships; using Microsoft.OpenApi.Models; using Swashbuckle.AspNetCore.SwaggerGen; @@ -23,9 +23,9 @@ internal sealed class JsonApiSchemaGenerator : ISchemaGenerator typeof(ResourceIdentifierCollectionResponseDocument<>), typeof(ResourceIdentifierResponseDocument<>), typeof(NullableResourceIdentifierResponseDocument<>), - typeof(ToManyRelationshipRequestData<>), - typeof(ToOneRelationshipRequestData<>), - typeof(NullableToOneRelationshipRequestData<>) + typeof(ToManyRelationshipInRequest<>), + typeof(ToOneRelationshipInRequest<>), + typeof(NullableToOneRelationshipInRequest<>) }; private readonly ISchemaGenerator _defaultSchemaGenerator; diff --git a/src/JsonApiDotNetCore.OpenApi/SwaggerComponents/ResourceFieldObjectSchemaBuilder.cs b/src/JsonApiDotNetCore.OpenApi/SwaggerComponents/ResourceFieldObjectSchemaBuilder.cs index bb45460968..5fae9f3e22 100644 --- a/src/JsonApiDotNetCore.OpenApi/SwaggerComponents/ResourceFieldObjectSchemaBuilder.cs +++ b/src/JsonApiDotNetCore.OpenApi/SwaggerComponents/ResourceFieldObjectSchemaBuilder.cs @@ -4,7 +4,7 @@ using System.Linq; using System.Reflection; using JsonApiDotNetCore.OpenApi.JsonApiObjects; -using JsonApiDotNetCore.OpenApi.JsonApiObjects.RelationshipData; +using JsonApiDotNetCore.OpenApi.JsonApiObjects.Relationships; using JsonApiDotNetCore.OpenApi.JsonApiObjects.ResourceObjects; using JsonApiDotNetCore.Resources.Annotations; using Microsoft.OpenApi.Models; @@ -16,11 +16,11 @@ internal sealed class ResourceFieldObjectSchemaBuilder { private static readonly SchemaRepository ResourceSchemaRepository = new(); - private static readonly Type[] RelationshipResponseDataOpenTypes = + private static readonly Type[] RelationshipInResponseOpenTypes = { - typeof(ToOneRelationshipResponseData<>), - typeof(ToManyRelationshipResponseData<>), - typeof(NullableToOneRelationshipResponseData<>) + typeof(ToOneRelationshipInResponse<>), + typeof(ToManyRelationshipInResponse<>), + typeof(NullableToOneRelationshipInResponse<>) }; private readonly ResourceTypeInfo _resourceTypeInfo; @@ -180,7 +180,7 @@ private void SetMembersOfRelationshipsObject(OpenApiSchema fullSchemaForRelation if (matchingRelationship != null) { EnsureResourceIdentifierObjectSchemaExists(matchingRelationship); - AddRelationshipDataSchemaToResourceObject(matchingRelationship, fullSchemaForRelationshipsObject); + AddRelationshipSchemaToResourceObject(matchingRelationship, fullSchemaForRelationshipsObject); } } } @@ -212,49 +212,46 @@ private void GenerateResourceIdentifierObjectSchema(Type resourceIdentifierObjec fullSchemaForResourceIdentifierObject.Properties[JsonApiObjectPropertyName.Type] = _resourceTypeSchemaGenerator.Get(resourceType); } - private void AddRelationshipDataSchemaToResourceObject(RelationshipAttribute relationship, OpenApiSchema fullSchemaForRelationshipObject) + private void AddRelationshipSchemaToResourceObject(RelationshipAttribute relationship, OpenApiSchema fullSchemaForRelationshipsObject) { - Type relationshipDataType = GetRelationshipDataType(relationship, _resourceTypeInfo.ResourceObjectOpenType); + Type relationshipSchemaType = GetRelationshipSchemaType(relationship, _resourceTypeInfo.ResourceObjectOpenType); - OpenApiSchema relationshipDataSchema = GetReferenceSchemaForRelationshipData(relationshipDataType) ?? - CreateRelationshipDataObjectSchema(relationshipDataType); + OpenApiSchema relationshipSchema = GetReferenceSchemaForRelationship(relationshipSchemaType) ?? CreateRelationshipSchema(relationshipSchemaType); - fullSchemaForRelationshipObject.Properties.Add(relationship.PublicName, relationshipDataSchema); + fullSchemaForRelationshipsObject.Properties.Add(relationship.PublicName, relationshipSchema); if (IsFieldRequired(relationship)) { - fullSchemaForRelationshipObject.Required.Add(relationship.PublicName); + fullSchemaForRelationshipsObject.Required.Add(relationship.PublicName); } } - private static Type GetRelationshipDataType(RelationshipAttribute relationship, Type resourceObjectType) + private static Type GetRelationshipSchemaType(RelationshipAttribute relationship, Type resourceObjectType) { return resourceObjectType.GetGenericTypeDefinition().IsAssignableTo(typeof(ResourceResponseObject<>)) - ? RelationshipDataTypeFactory.Instance.GetForResponse(relationship) - : RelationshipDataTypeFactory.Instance.GetForRequest(relationship); + ? RelationshipTypeFactory.Instance.GetForResponse(relationship) + : RelationshipTypeFactory.Instance.GetForRequest(relationship); } - private OpenApiSchema? GetReferenceSchemaForRelationshipData(Type relationshipDataType) + private OpenApiSchema? GetReferenceSchemaForRelationship(Type relationshipSchemaType) { - _schemaRepositoryAccessor.Current.TryLookupByType(relationshipDataType, out OpenApiSchema? referenceSchemaForRelationshipData); - return referenceSchemaForRelationshipData; + _schemaRepositoryAccessor.Current.TryLookupByType(relationshipSchemaType, out OpenApiSchema? referenceSchema); + return referenceSchema; } - private OpenApiSchema CreateRelationshipDataObjectSchema(Type relationshipDataType) + private OpenApiSchema CreateRelationshipSchema(Type relationshipSchemaType) { - OpenApiSchema referenceSchema = _defaultSchemaGenerator.GenerateSchema(relationshipDataType, _schemaRepositoryAccessor.Current); + OpenApiSchema referenceSchema = _defaultSchemaGenerator.GenerateSchema(relationshipSchemaType, _schemaRepositoryAccessor.Current); OpenApiSchema fullSchema = _schemaRepositoryAccessor.Current.Schemas[referenceSchema.Reference.Id]; - if (IsDataPropertyNullable(relationshipDataType)) + if (IsDataPropertyNullable(relationshipSchemaType)) { fullSchema.Properties[JsonApiObjectPropertyName.Data] = _nullableReferenceSchemaGenerator.GenerateSchema(fullSchema.Properties[JsonApiObjectPropertyName.Data]); } - Type relationshipDataOpenType = relationshipDataType.GetGenericTypeDefinition(); - - if (IsRelationshipDataPropertyInResponse(relationshipDataOpenType)) + if (IsRelationshipInResponseType(relationshipSchemaType)) { fullSchema.Required.Remove(JsonApiObjectPropertyName.Data); } @@ -262,9 +259,11 @@ private OpenApiSchema CreateRelationshipDataObjectSchema(Type relationshipDataTy return referenceSchema; } - private static bool IsRelationshipDataPropertyInResponse(Type relationshipDataOpenType) + private static bool IsRelationshipInResponseType(Type relationshipSchemaType) { - return RelationshipResponseDataOpenTypes.Contains(relationshipDataOpenType); + Type relationshipSchemaOpenType = relationshipSchemaType.GetGenericTypeDefinition(); + + return RelationshipInResponseOpenTypes.Contains(relationshipSchemaOpenType); } private static bool IsDataPropertyNullable(Type type) diff --git a/test/OpenApiClientTests/LegacyClient/RequestTests.cs b/test/OpenApiClientTests/LegacyClient/RequestTests.cs index 4f4ddce61b..ef33288171 100644 --- a/test/OpenApiClientTests/LegacyClient/RequestTests.cs +++ b/test/OpenApiClientTests/LegacyClient/RequestTests.cs @@ -69,7 +69,7 @@ public async Task Partial_posting_resource_with_selected_relationships_produces_ Type = FlightsResourceType.Flights, Relationships = new FlightRelationshipsInPostRequest { - Purser = new ToOneFlightAttendantRequestData + Purser = new ToOneFlightAttendantDataInRequest { Data = new FlightAttendantIdentifier { @@ -77,7 +77,7 @@ public async Task Partial_posting_resource_with_selected_relationships_produces_ Type = FlightAttendantsResourceType.FlightAttendants } }, - BackupPurser = new NullableToOneFlightAttendantRequestData + BackupPurser = new NullableToOneFlightAttendantDataInRequest { Data = new FlightAttendantIdentifier { @@ -325,7 +325,7 @@ public async Task Patching_ToOne_relationship_produces_expected_request() using var wrapper = FakeHttpClientWrapper.Create(HttpStatusCode.NoContent, null); IOpenApiClient apiClient = new OpenApiClient(wrapper.HttpClient); - var requestDocument = new ToOneFlightAttendantRequestData + var requestDocument = new ToOneFlightAttendantDataInRequest { Data = new FlightAttendantIdentifier { @@ -382,7 +382,7 @@ public async Task Posting_ToMany_relationship_produces_expected_request() using var wrapper = FakeHttpClientWrapper.Create(HttpStatusCode.NoContent, null); IOpenApiClient apiClient = new OpenApiClient(wrapper.HttpClient); - var requestDocument = new ToManyFlightAttendantRequestData + var requestDocument = new ToManyFlightAttendantDataInRequest { Data = new List { @@ -433,7 +433,7 @@ public async Task Patching_ToMany_relationship_produces_expected_request() using var wrapper = FakeHttpClientWrapper.Create(HttpStatusCode.NoContent, null); IOpenApiClient apiClient = new OpenApiClient(wrapper.HttpClient); - var requestDocument = new ToManyFlightAttendantRequestData + var requestDocument = new ToManyFlightAttendantDataInRequest { Data = new List { @@ -484,7 +484,7 @@ public async Task Deleting_ToMany_relationship_produces_expected_request() using var wrapper = FakeHttpClientWrapper.Create(HttpStatusCode.NoContent, null); IOpenApiClient apiClient = new OpenApiClient(wrapper.HttpClient); - var requestDocument = new ToManyFlightAttendantRequestData + var requestDocument = new ToManyFlightAttendantDataInRequest { Data = new List { diff --git a/test/OpenApiClientTests/LegacyClient/ResponseTests.cs b/test/OpenApiClientTests/LegacyClient/ResponseTests.cs index 5a823219aa..9ca148f46a 100644 --- a/test/OpenApiClientTests/LegacyClient/ResponseTests.cs +++ b/test/OpenApiClientTests/LegacyClient/ResponseTests.cs @@ -283,7 +283,7 @@ public async Task Posting_resource_translates_response() Type = FlightsResourceType.Flights, Relationships = new FlightRelationshipsInPostRequest { - Purser = new ToOneFlightAttendantRequestData + Purser = new ToOneFlightAttendantDataInRequest { Data = new FlightAttendantIdentifier { @@ -552,7 +552,7 @@ public async Task Patching_ToOne_relationship_translates_response() IOpenApiClient apiClient = new OpenApiClient(wrapper.HttpClient); // Act - await apiClient.PatchFlightPurserRelationshipAsync("ZvuH1", new ToOneFlightAttendantRequestData + await apiClient.PatchFlightPurserRelationshipAsync("ZvuH1", new ToOneFlightAttendantDataInRequest { Data = new FlightAttendantIdentifier { @@ -608,7 +608,7 @@ public async Task Posting_ToMany_relationship_produces_empty_response() IOpenApiClient apiClient = new OpenApiClient(wrapper.HttpClient); // Act - Func action = async () => await apiClient.PostFlightCabinCrewMembersRelationshipAsync("ZvuH1", new ToManyFlightAttendantRequestData + Func action = async () => await apiClient.PostFlightCabinCrewMembersRelationshipAsync("ZvuH1", new ToManyFlightAttendantDataInRequest { Data = new List { @@ -637,7 +637,7 @@ public async Task Patching_ToMany_relationship_produces_empty_response() IOpenApiClient apiClient = new OpenApiClient(wrapper.HttpClient); // Act - Func action = async () => await apiClient.PatchFlightCabinCrewMembersRelationshipAsync("ZvuH1", new ToManyFlightAttendantRequestData + Func action = async () => await apiClient.PatchFlightCabinCrewMembersRelationshipAsync("ZvuH1", new ToManyFlightAttendantDataInRequest { Data = new List { @@ -666,7 +666,7 @@ public async Task Deleting_ToMany_relationship_produces_empty_response() IOpenApiClient apiClient = new OpenApiClient(wrapper.HttpClient); // Act - Func action = async () => await apiClient.DeleteFlightCabinCrewMembersRelationshipAsync("ZvuH1", new ToManyFlightAttendantRequestData + Func action = async () => await apiClient.DeleteFlightCabinCrewMembersRelationshipAsync("ZvuH1", new ToManyFlightAttendantDataInRequest { Data = new List { diff --git a/test/OpenApiTests/LegacyOpenApiIntegration/swagger.json b/test/OpenApiTests/LegacyOpenApiIntegration/swagger.json index 00d523bfe8..b3f72fe3c5 100644 --- a/test/OpenApiTests/LegacyOpenApiIntegration/swagger.json +++ b/test/OpenApiTests/LegacyOpenApiIntegration/swagger.json @@ -326,7 +326,7 @@ "content": { "application/vnd.api+json": { "schema": { - "$ref": "#/components/schemas/to-many-flight-request-data" + "$ref": "#/components/schemas/to-many-flight-data-in-request" } } } @@ -356,7 +356,7 @@ "content": { "application/vnd.api+json": { "schema": { - "$ref": "#/components/schemas/to-many-flight-request-data" + "$ref": "#/components/schemas/to-many-flight-data-in-request" } } } @@ -386,7 +386,7 @@ "content": { "application/vnd.api+json": { "schema": { - "$ref": "#/components/schemas/to-many-flight-request-data" + "$ref": "#/components/schemas/to-many-flight-data-in-request" } } } @@ -719,7 +719,7 @@ "content": { "application/vnd.api+json": { "schema": { - "$ref": "#/components/schemas/to-many-flight-request-data" + "$ref": "#/components/schemas/to-many-flight-data-in-request" } } } @@ -749,7 +749,7 @@ "content": { "application/vnd.api+json": { "schema": { - "$ref": "#/components/schemas/to-many-flight-request-data" + "$ref": "#/components/schemas/to-many-flight-data-in-request" } } } @@ -779,7 +779,7 @@ "content": { "application/vnd.api+json": { "schema": { - "$ref": "#/components/schemas/to-many-flight-request-data" + "$ref": "#/components/schemas/to-many-flight-data-in-request" } } } @@ -925,7 +925,7 @@ "content": { "application/vnd.api+json": { "schema": { - "$ref": "#/components/schemas/to-many-flight-request-data" + "$ref": "#/components/schemas/to-many-flight-data-in-request" } } } @@ -955,7 +955,7 @@ "content": { "application/vnd.api+json": { "schema": { - "$ref": "#/components/schemas/to-many-flight-request-data" + "$ref": "#/components/schemas/to-many-flight-data-in-request" } } } @@ -985,7 +985,7 @@ "content": { "application/vnd.api+json": { "schema": { - "$ref": "#/components/schemas/to-many-flight-request-data" + "$ref": "#/components/schemas/to-many-flight-data-in-request" } } } @@ -1318,7 +1318,7 @@ "content": { "application/vnd.api+json": { "schema": { - "$ref": "#/components/schemas/nullable-to-one-flight-attendant-request-data" + "$ref": "#/components/schemas/nullable-to-one-flight-attendant-data-in-request" } } } @@ -1464,7 +1464,7 @@ "content": { "application/vnd.api+json": { "schema": { - "$ref": "#/components/schemas/to-many-flight-attendant-request-data" + "$ref": "#/components/schemas/to-many-flight-attendant-data-in-request" } } } @@ -1494,7 +1494,7 @@ "content": { "application/vnd.api+json": { "schema": { - "$ref": "#/components/schemas/to-many-flight-attendant-request-data" + "$ref": "#/components/schemas/to-many-flight-attendant-data-in-request" } } } @@ -1524,7 +1524,7 @@ "content": { "application/vnd.api+json": { "schema": { - "$ref": "#/components/schemas/to-many-flight-attendant-request-data" + "$ref": "#/components/schemas/to-many-flight-attendant-data-in-request" } } } @@ -1670,7 +1670,7 @@ "content": { "application/vnd.api+json": { "schema": { - "$ref": "#/components/schemas/to-many-passenger-request-data" + "$ref": "#/components/schemas/to-many-passenger-data-in-request" } } } @@ -1700,7 +1700,7 @@ "content": { "application/vnd.api+json": { "schema": { - "$ref": "#/components/schemas/to-many-passenger-request-data" + "$ref": "#/components/schemas/to-many-passenger-data-in-request" } } } @@ -1730,7 +1730,7 @@ "content": { "application/vnd.api+json": { "schema": { - "$ref": "#/components/schemas/to-many-passenger-request-data" + "$ref": "#/components/schemas/to-many-passenger-data-in-request" } } } @@ -1876,7 +1876,7 @@ "content": { "application/vnd.api+json": { "schema": { - "$ref": "#/components/schemas/to-one-flight-attendant-request-data" + "$ref": "#/components/schemas/to-one-flight-attendant-data-in-request" } } } @@ -2156,7 +2156,7 @@ "type": "object", "properties": { "flights": { - "$ref": "#/components/schemas/to-many-flight-request-data" + "$ref": "#/components/schemas/to-many-flight-data-in-request" } }, "additionalProperties": false @@ -2165,7 +2165,7 @@ "type": "object", "properties": { "flights": { - "$ref": "#/components/schemas/to-many-flight-request-data" + "$ref": "#/components/schemas/to-many-flight-data-in-request" } }, "additionalProperties": false @@ -2174,7 +2174,7 @@ "type": "object", "properties": { "flights": { - "$ref": "#/components/schemas/to-many-flight-response-data" + "$ref": "#/components/schemas/to-many-flight-data-in-response" } }, "additionalProperties": false @@ -2469,10 +2469,10 @@ "type": "object", "properties": { "scheduled-for-flights": { - "$ref": "#/components/schemas/to-many-flight-request-data" + "$ref": "#/components/schemas/to-many-flight-data-in-request" }, "purser-on-flights": { - "$ref": "#/components/schemas/to-many-flight-request-data" + "$ref": "#/components/schemas/to-many-flight-data-in-request" } }, "additionalProperties": false @@ -2481,10 +2481,10 @@ "type": "object", "properties": { "scheduled-for-flights": { - "$ref": "#/components/schemas/to-many-flight-request-data" + "$ref": "#/components/schemas/to-many-flight-data-in-request" }, "purser-on-flights": { - "$ref": "#/components/schemas/to-many-flight-request-data" + "$ref": "#/components/schemas/to-many-flight-data-in-request" } }, "additionalProperties": false @@ -2493,10 +2493,10 @@ "type": "object", "properties": { "scheduled-for-flights": { - "$ref": "#/components/schemas/to-many-flight-response-data" + "$ref": "#/components/schemas/to-many-flight-data-in-response" }, "purser-on-flights": { - "$ref": "#/components/schemas/to-many-flight-response-data" + "$ref": "#/components/schemas/to-many-flight-data-in-response" } }, "additionalProperties": false @@ -2768,16 +2768,16 @@ "type": "object", "properties": { "cabin-crew-members": { - "$ref": "#/components/schemas/to-many-flight-attendant-request-data" + "$ref": "#/components/schemas/to-many-flight-attendant-data-in-request" }, "purser": { - "$ref": "#/components/schemas/to-one-flight-attendant-request-data" + "$ref": "#/components/schemas/to-one-flight-attendant-data-in-request" }, "backup-purser": { - "$ref": "#/components/schemas/nullable-to-one-flight-attendant-request-data" + "$ref": "#/components/schemas/nullable-to-one-flight-attendant-data-in-request" }, "passengers": { - "$ref": "#/components/schemas/to-many-passenger-request-data" + "$ref": "#/components/schemas/to-many-passenger-data-in-request" } }, "additionalProperties": false @@ -2789,16 +2789,16 @@ "type": "object", "properties": { "cabin-crew-members": { - "$ref": "#/components/schemas/to-many-flight-attendant-request-data" + "$ref": "#/components/schemas/to-many-flight-attendant-data-in-request" }, "purser": { - "$ref": "#/components/schemas/to-one-flight-attendant-request-data" + "$ref": "#/components/schemas/to-one-flight-attendant-data-in-request" }, "backup-purser": { - "$ref": "#/components/schemas/nullable-to-one-flight-attendant-request-data" + "$ref": "#/components/schemas/nullable-to-one-flight-attendant-data-in-request" }, "passengers": { - "$ref": "#/components/schemas/to-many-passenger-request-data" + "$ref": "#/components/schemas/to-many-passenger-data-in-request" } }, "additionalProperties": false @@ -2807,16 +2807,16 @@ "type": "object", "properties": { "cabin-crew-members": { - "$ref": "#/components/schemas/to-many-flight-attendant-response-data" + "$ref": "#/components/schemas/to-many-flight-attendant-data-in-response" }, "purser": { - "$ref": "#/components/schemas/to-one-flight-attendant-response-data" + "$ref": "#/components/schemas/to-one-flight-attendant-data-in-response" }, "backup-purser": { - "$ref": "#/components/schemas/nullable-to-one-flight-attendant-response-data" + "$ref": "#/components/schemas/nullable-to-one-flight-attendant-data-in-response" }, "passengers": { - "$ref": "#/components/schemas/to-many-passenger-response-data" + "$ref": "#/components/schemas/to-many-passenger-data-in-response" } }, "additionalProperties": false @@ -3057,7 +3057,7 @@ }, "additionalProperties": false }, - "nullable-to-one-flight-attendant-request-data": { + "nullable-to-one-flight-attendant-data-in-request": { "required": [ "data" ], @@ -3076,7 +3076,7 @@ }, "additionalProperties": false }, - "nullable-to-one-flight-attendant-response-data": { + "nullable-to-one-flight-attendant-data-in-response": { "required": [ "links" ], @@ -3216,7 +3216,7 @@ ], "type": "string" }, - "to-many-flight-attendant-request-data": { + "to-many-flight-attendant-data-in-request": { "required": [ "data" ], @@ -3231,7 +3231,7 @@ }, "additionalProperties": false }, - "to-many-flight-attendant-response-data": { + "to-many-flight-attendant-data-in-response": { "required": [ "links" ], @@ -3253,7 +3253,7 @@ }, "additionalProperties": false }, - "to-many-flight-request-data": { + "to-many-flight-data-in-request": { "required": [ "data" ], @@ -3268,7 +3268,7 @@ }, "additionalProperties": false }, - "to-many-flight-response-data": { + "to-many-flight-data-in-response": { "required": [ "links" ], @@ -3290,7 +3290,7 @@ }, "additionalProperties": false }, - "to-many-passenger-request-data": { + "to-many-passenger-data-in-request": { "required": [ "data" ], @@ -3305,7 +3305,7 @@ }, "additionalProperties": false }, - "to-many-passenger-response-data": { + "to-many-passenger-data-in-response": { "required": [ "links" ], @@ -3327,7 +3327,7 @@ }, "additionalProperties": false }, - "to-one-flight-attendant-request-data": { + "to-one-flight-attendant-data-in-request": { "required": [ "data" ], @@ -3339,7 +3339,7 @@ }, "additionalProperties": false }, - "to-one-flight-attendant-response-data": { + "to-one-flight-attendant-data-in-response": { "required": [ "links" ], From 796f104684cffba6bfec84cfceb70ccd06676f5a Mon Sep 17 00:00:00 2001 From: maurei Date: Fri, 26 Nov 2021 17:50:42 +0100 Subject: [PATCH 2/5] Process review feedback, fixed culture issue in test --- ...llableSecondaryResourceResponseDocument.cs | 2 +- .../PrimaryResourceResponseDocument.cs | 2 +- .../ResourceCollectionResponseDocument.cs | 2 +- .../Documents/ResourcePatchRequestDocument.cs | 2 +- .../Documents/ResourcePostRequestDocument.cs | 2 +- .../SecondaryResourceResponseDocument.cs | 2 +- ...ect.cs => ResourceObjectInPatchRequest.cs} | 2 +- ...ject.cs => ResourceObjectInPostRequest.cs} | 2 +- ...eObject.cs => ResourceObjectInResponse.cs} | 2 +- .../JsonApiSchemaIdSelector.cs | 45 +- .../ResourceObjectFieldType.cs | 8 + .../CachingSwaggerGenerator.cs | 11 +- .../ResourceFieldObjectSchemaBuilder.cs | 25 +- .../ResourceObjectSchemaGenerator.cs | 2 +- ...lientAttributeRegistrationLifeTimeTests.cs | 26 +- .../LegacyClient/RequestTests.cs | 18 +- .../LegacyClient/ResponseTests.cs | 18 +- .../LegacyOpenApiIntegration/swagger.json | 392 +++++++++--------- 18 files changed, 300 insertions(+), 263 deletions(-) rename src/JsonApiDotNetCore.OpenApi/JsonApiObjects/ResourceObjects/{ResourcePostRequestObject.cs => ResourceObjectInPatchRequest.cs} (62%) rename src/JsonApiDotNetCore.OpenApi/JsonApiObjects/ResourceObjects/{ResourcePatchRequestObject.cs => ResourceObjectInPostRequest.cs} (63%) rename src/JsonApiDotNetCore.OpenApi/JsonApiObjects/ResourceObjects/{ResourceResponseObject.cs => ResourceObjectInResponse.cs} (85%) create mode 100644 src/JsonApiDotNetCore.OpenApi/ResourceObjectFieldType.cs diff --git a/src/JsonApiDotNetCore.OpenApi/JsonApiObjects/Documents/NullableSecondaryResourceResponseDocument.cs b/src/JsonApiDotNetCore.OpenApi/JsonApiObjects/Documents/NullableSecondaryResourceResponseDocument.cs index 4f86562323..b1cfe45062 100644 --- a/src/JsonApiDotNetCore.OpenApi/JsonApiObjects/Documents/NullableSecondaryResourceResponseDocument.cs +++ b/src/JsonApiDotNetCore.OpenApi/JsonApiObjects/Documents/NullableSecondaryResourceResponseDocument.cs @@ -8,7 +8,7 @@ namespace JsonApiDotNetCore.OpenApi.JsonApiObjects.Documents { [UsedImplicitly(ImplicitUseTargetFlags.Members)] - internal sealed class NullableSecondaryResourceResponseDocument : NullableSingleData> + internal sealed class NullableSecondaryResourceResponseDocument : NullableSingleData> where TResource : IIdentifiable { public IDictionary Meta { get; set; } = null!; diff --git a/src/JsonApiDotNetCore.OpenApi/JsonApiObjects/Documents/PrimaryResourceResponseDocument.cs b/src/JsonApiDotNetCore.OpenApi/JsonApiObjects/Documents/PrimaryResourceResponseDocument.cs index d7c2ee83e3..76b47786d2 100644 --- a/src/JsonApiDotNetCore.OpenApi/JsonApiObjects/Documents/PrimaryResourceResponseDocument.cs +++ b/src/JsonApiDotNetCore.OpenApi/JsonApiObjects/Documents/PrimaryResourceResponseDocument.cs @@ -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 : SingleData> + internal sealed class PrimaryResourceResponseDocument : SingleData> where TResource : IIdentifiable { public IDictionary Meta { get; set; } = null!; diff --git a/src/JsonApiDotNetCore.OpenApi/JsonApiObjects/Documents/ResourceCollectionResponseDocument.cs b/src/JsonApiDotNetCore.OpenApi/JsonApiObjects/Documents/ResourceCollectionResponseDocument.cs index 4b90acec0e..97d35c0156 100644 --- a/src/JsonApiDotNetCore.OpenApi/JsonApiObjects/Documents/ResourceCollectionResponseDocument.cs +++ b/src/JsonApiDotNetCore.OpenApi/JsonApiObjects/Documents/ResourceCollectionResponseDocument.cs @@ -8,7 +8,7 @@ namespace JsonApiDotNetCore.OpenApi.JsonApiObjects.Documents { [UsedImplicitly(ImplicitUseTargetFlags.Members)] - internal sealed class ResourceCollectionResponseDocument : ManyData> + internal sealed class ResourceCollectionResponseDocument : ManyData> where TResource : IIdentifiable { public IDictionary Meta { get; set; } = null!; diff --git a/src/JsonApiDotNetCore.OpenApi/JsonApiObjects/Documents/ResourcePatchRequestDocument.cs b/src/JsonApiDotNetCore.OpenApi/JsonApiObjects/Documents/ResourcePatchRequestDocument.cs index 7246695ccd..6a5e7615c5 100644 --- a/src/JsonApiDotNetCore.OpenApi/JsonApiObjects/Documents/ResourcePatchRequestDocument.cs +++ b/src/JsonApiDotNetCore.OpenApi/JsonApiObjects/Documents/ResourcePatchRequestDocument.cs @@ -5,7 +5,7 @@ namespace JsonApiDotNetCore.OpenApi.JsonApiObjects.Documents { [UsedImplicitly(ImplicitUseTargetFlags.Members)] - internal sealed class ResourcePatchRequestDocument : SingleData> + internal sealed class ResourcePatchRequestDocument : SingleData> where TResource : IIdentifiable { } diff --git a/src/JsonApiDotNetCore.OpenApi/JsonApiObjects/Documents/ResourcePostRequestDocument.cs b/src/JsonApiDotNetCore.OpenApi/JsonApiObjects/Documents/ResourcePostRequestDocument.cs index 034863b5cf..2459cef0eb 100644 --- a/src/JsonApiDotNetCore.OpenApi/JsonApiObjects/Documents/ResourcePostRequestDocument.cs +++ b/src/JsonApiDotNetCore.OpenApi/JsonApiObjects/Documents/ResourcePostRequestDocument.cs @@ -5,7 +5,7 @@ namespace JsonApiDotNetCore.OpenApi.JsonApiObjects.Documents { [UsedImplicitly(ImplicitUseTargetFlags.Members)] - internal sealed class ResourcePostRequestDocument : SingleData> + internal sealed class ResourcePostRequestDocument : SingleData> where TResource : IIdentifiable { } diff --git a/src/JsonApiDotNetCore.OpenApi/JsonApiObjects/Documents/SecondaryResourceResponseDocument.cs b/src/JsonApiDotNetCore.OpenApi/JsonApiObjects/Documents/SecondaryResourceResponseDocument.cs index 6a2fbae85b..73698b6351 100644 --- a/src/JsonApiDotNetCore.OpenApi/JsonApiObjects/Documents/SecondaryResourceResponseDocument.cs +++ b/src/JsonApiDotNetCore.OpenApi/JsonApiObjects/Documents/SecondaryResourceResponseDocument.cs @@ -8,7 +8,7 @@ namespace JsonApiDotNetCore.OpenApi.JsonApiObjects.Documents { [UsedImplicitly(ImplicitUseTargetFlags.Members)] - internal sealed class SecondaryResourceResponseDocument : SingleData> + internal sealed class SecondaryResourceResponseDocument : SingleData> where TResource : IIdentifiable { public IDictionary Meta { get; set; } = null!; diff --git a/src/JsonApiDotNetCore.OpenApi/JsonApiObjects/ResourceObjects/ResourcePostRequestObject.cs b/src/JsonApiDotNetCore.OpenApi/JsonApiObjects/ResourceObjects/ResourceObjectInPatchRequest.cs similarity index 62% rename from src/JsonApiDotNetCore.OpenApi/JsonApiObjects/ResourceObjects/ResourcePostRequestObject.cs rename to src/JsonApiDotNetCore.OpenApi/JsonApiObjects/ResourceObjects/ResourceObjectInPatchRequest.cs index 9447c74668..90113a9d86 100644 --- a/src/JsonApiDotNetCore.OpenApi/JsonApiObjects/ResourceObjects/ResourcePostRequestObject.cs +++ b/src/JsonApiDotNetCore.OpenApi/JsonApiObjects/ResourceObjects/ResourceObjectInPatchRequest.cs @@ -2,7 +2,7 @@ namespace JsonApiDotNetCore.OpenApi.JsonApiObjects.ResourceObjects { - internal sealed class ResourcePostRequestObject : ResourceObject + internal sealed class ResourceObjectInPatchRequest : ResourceObject where TResource : IIdentifiable { } diff --git a/src/JsonApiDotNetCore.OpenApi/JsonApiObjects/ResourceObjects/ResourcePatchRequestObject.cs b/src/JsonApiDotNetCore.OpenApi/JsonApiObjects/ResourceObjects/ResourceObjectInPostRequest.cs similarity index 63% rename from src/JsonApiDotNetCore.OpenApi/JsonApiObjects/ResourceObjects/ResourcePatchRequestObject.cs rename to src/JsonApiDotNetCore.OpenApi/JsonApiObjects/ResourceObjects/ResourceObjectInPostRequest.cs index e642d93bbb..56bc3d0726 100644 --- a/src/JsonApiDotNetCore.OpenApi/JsonApiObjects/ResourceObjects/ResourcePatchRequestObject.cs +++ b/src/JsonApiDotNetCore.OpenApi/JsonApiObjects/ResourceObjects/ResourceObjectInPostRequest.cs @@ -2,7 +2,7 @@ namespace JsonApiDotNetCore.OpenApi.JsonApiObjects.ResourceObjects { - internal sealed class ResourcePatchRequestObject : ResourceObject + internal sealed class ResourceObjectInPostRequest : ResourceObject where TResource : IIdentifiable { } diff --git a/src/JsonApiDotNetCore.OpenApi/JsonApiObjects/ResourceObjects/ResourceResponseObject.cs b/src/JsonApiDotNetCore.OpenApi/JsonApiObjects/ResourceObjects/ResourceObjectInResponse.cs similarity index 85% rename from src/JsonApiDotNetCore.OpenApi/JsonApiObjects/ResourceObjects/ResourceResponseObject.cs rename to src/JsonApiDotNetCore.OpenApi/JsonApiObjects/ResourceObjects/ResourceObjectInResponse.cs index 62cb0378e5..3a12ee1007 100644 --- a/src/JsonApiDotNetCore.OpenApi/JsonApiObjects/ResourceObjects/ResourceResponseObject.cs +++ b/src/JsonApiDotNetCore.OpenApi/JsonApiObjects/ResourceObjects/ResourceObjectInResponse.cs @@ -7,7 +7,7 @@ namespace JsonApiDotNetCore.OpenApi.JsonApiObjects.ResourceObjects { [UsedImplicitly(ImplicitUseTargetFlags.Members)] - internal sealed class ResourceResponseObject : ResourceObject + internal sealed class ResourceObjectInResponse : ResourceObject where TResource : IIdentifiable { [Required] diff --git a/src/JsonApiDotNetCore.OpenApi/JsonApiSchemaIdSelector.cs b/src/JsonApiDotNetCore.OpenApi/JsonApiSchemaIdSelector.cs index 64579c81e7..8b471bd8e0 100644 --- a/src/JsonApiDotNetCore.OpenApi/JsonApiSchemaIdSelector.cs +++ b/src/JsonApiDotNetCore.OpenApi/JsonApiSchemaIdSelector.cs @@ -15,11 +15,11 @@ internal sealed class JsonApiSchemaIdSelector { [typeof(ResourcePostRequestDocument<>)] = "###-post-request-document", [typeof(ResourcePatchRequestDocument<>)] = "###-patch-request-document", - [typeof(ResourcePostRequestObject<>)] = "###-data-in-post-request", - [typeof(ResourcePatchRequestObject<>)] = "###-data-in-patch-request", - [typeof(ToOneRelationshipInRequest<>)] = "to-one-###-data-in-request", - [typeof(NullableToOneRelationshipInRequest<>)] = "nullable-to-one-###-data-in-request", - [typeof(ToManyRelationshipInRequest<>)] = "to-many-###-data-in-request", + [typeof(ResourceObjectInPostRequest<>)] = "###-in-post-request", + [typeof(ResourceObjectInPatchRequest<>)] = "###-in-patch-request", + [typeof(ToOneRelationshipInRequest<>)] = "to-one-###-in-request", + [typeof(NullableToOneRelationshipInRequest<>)] = "nullable-to-one-###-in-request", + [typeof(ToManyRelationshipInRequest<>)] = "to-many-###-in-request", [typeof(PrimaryResourceResponseDocument<>)] = "###-primary-response-document", [typeof(SecondaryResourceResponseDocument<>)] = "###-secondary-response-document", [typeof(NullableSecondaryResourceResponseDocument<>)] = "nullable-###-secondary-response-document", @@ -27,13 +27,20 @@ internal sealed class JsonApiSchemaIdSelector [typeof(ResourceIdentifierResponseDocument<>)] = "###-identifier-response-document", [typeof(NullableResourceIdentifierResponseDocument<>)] = "nullable-###-identifier-response-document", [typeof(ResourceIdentifierCollectionResponseDocument<>)] = "###-identifier-collection-response-document", - [typeof(ToOneRelationshipInResponse<>)] = "to-one-###-data-in-response", - [typeof(NullableToOneRelationshipInResponse<>)] = "nullable-to-one-###-data-in-response", - [typeof(ToManyRelationshipInResponse<>)] = "to-many-###-data-in-response", - [typeof(ResourceResponseObject<>)] = "###-data-in-response", + [typeof(ToOneRelationshipInResponse<>)] = "to-one-###-in-response", + [typeof(NullableToOneRelationshipInResponse<>)] = "nullable-to-one-###-in-response", + [typeof(ToManyRelationshipInResponse<>)] = "to-many-###-in-response", + [typeof(ResourceObjectInResponse<>)] = "###-in-response", [typeof(ResourceIdentifierObject<>)] = "###-identifier" }; + private readonly Type[] _resourceObjectOpenTypes = + { + typeof(ResourceObjectInPostRequest<>), + typeof(ResourceObjectInPatchRequest<>), + typeof(ResourceObjectInResponse<>) + }; + private readonly ResourceNameFormatter _formatter; private readonly IResourceGraph _resourceGraph; @@ -69,5 +76,25 @@ public string GetSchemaId(Type type) // Used for a fixed set of types, such as jsonapi-object, links-in-many-resource-document etc. return _formatter.FormatResourceName(type).Singularize(); } + + public string GetSchemaId(Type resourceObjectOpenType, ResourceObjectFieldType fieldType) + { + ArgumentGuard.NotNull(resourceObjectOpenType, nameof(resourceObjectOpenType)); + + if (!resourceObjectOpenType.IsConstructedGenericType || !_resourceObjectOpenTypes.Contains(resourceObjectOpenType.GetGenericTypeDefinition())) + { + throw new InvalidOperationException($"Type '{resourceObjectOpenType.Name}' must be an open type representing a resource object."); + } + + Type resourceClrType = resourceObjectOpenType.GetGenericArguments().First(); + string resourceName = _formatter.FormatResourceName(resourceClrType).Singularize(); + string template = OpenTypeToSchemaTemplateMap[resourceObjectOpenType.GetGenericTypeDefinition()]; + + string fieldObjectName = fieldType == ResourceObjectFieldType.Attributes + ? JsonApiObjectPropertyName.AttributesObject + : JsonApiObjectPropertyName.RelationshipsObject; + + return template.Replace("###", $"{resourceName}-{fieldObjectName}"); + } } } diff --git a/src/JsonApiDotNetCore.OpenApi/ResourceObjectFieldType.cs b/src/JsonApiDotNetCore.OpenApi/ResourceObjectFieldType.cs new file mode 100644 index 0000000000..3ddb18540b --- /dev/null +++ b/src/JsonApiDotNetCore.OpenApi/ResourceObjectFieldType.cs @@ -0,0 +1,8 @@ +namespace JsonApiDotNetCore.OpenApi +{ + internal enum ResourceObjectFieldType + { + Attributes, + Relationships + } +} diff --git a/src/JsonApiDotNetCore.OpenApi/SwaggerComponents/CachingSwaggerGenerator.cs b/src/JsonApiDotNetCore.OpenApi/SwaggerComponents/CachingSwaggerGenerator.cs index 07128b71e6..f36f7f9b58 100644 --- a/src/JsonApiDotNetCore.OpenApi/SwaggerComponents/CachingSwaggerGenerator.cs +++ b/src/JsonApiDotNetCore.OpenApi/SwaggerComponents/CachingSwaggerGenerator.cs @@ -1,4 +1,6 @@ +using System; using System.Collections.Concurrent; +using System.Collections.Generic; using Microsoft.OpenApi.Models; using Swashbuckle.AspNetCore.Swagger; using Swashbuckle.AspNetCore.SwaggerGen; @@ -26,7 +28,14 @@ public OpenApiDocument GetSwagger(string documentName, string? host = null, stri string cacheKey = $"{documentName}#{host}#{basePath}"; - return _openApiDocumentCache.GetOrAdd(cacheKey, _ => _defaultSwaggerGenerator.GetSwagger(documentName, host, basePath)); + return _openApiDocumentCache.GetOrAdd(cacheKey, _ => + { + OpenApiDocument document = _defaultSwaggerGenerator.GetSwagger(documentName, host, basePath); + + // Remove once https://github.com/domaindrivendev/Swashbuckle.AspNetCore/issues/2283 is addressed. + document.Components.Schemas = new SortedDictionary(document.Components.Schemas, StringComparer.Ordinal); + return document; + }); } } } diff --git a/src/JsonApiDotNetCore.OpenApi/SwaggerComponents/ResourceFieldObjectSchemaBuilder.cs b/src/JsonApiDotNetCore.OpenApi/SwaggerComponents/ResourceFieldObjectSchemaBuilder.cs index 5fae9f3e22..b4722cb2eb 100644 --- a/src/JsonApiDotNetCore.OpenApi/SwaggerComponents/ResourceFieldObjectSchemaBuilder.cs +++ b/src/JsonApiDotNetCore.OpenApi/SwaggerComponents/ResourceFieldObjectSchemaBuilder.cs @@ -76,7 +76,8 @@ private IDictionary GetFieldSchemas() fullSchemaForAttributesObject.AdditionalPropertiesAllowed = false; - return GetReferenceSchemaForFieldObject(fullSchemaForAttributesObject, JsonApiObjectPropertyName.AttributesObject); + string fieldObjectSchemaId = _jsonApiSchemaIdSelector.GetSchemaId(_resourceTypeInfo.ResourceObjectType, ResourceObjectFieldType.Attributes); + return _schemaRepositoryAccessor.Current.AddDefinition(fieldObjectSchemaId, fullSchemaForAttributesObject); } private void SetMembersOfAttributesObject(OpenApiSchema fullSchemaForAttributesObject) @@ -103,9 +104,9 @@ private void SetMembersOfAttributesObject(OpenApiSchema fullSchemaForAttributesO private static AttrCapabilities GetRequiredCapabilityForAttributes(Type resourceObjectOpenType) { - return resourceObjectOpenType == typeof(ResourceResponseObject<>) ? AttrCapabilities.AllowView : - resourceObjectOpenType == typeof(ResourcePostRequestObject<>) ? AttrCapabilities.AllowCreate : - resourceObjectOpenType == typeof(ResourcePatchRequestObject<>) ? AttrCapabilities.AllowChange : throw new UnreachableCodeException(); + return resourceObjectOpenType == typeof(ResourceObjectInResponse<>) ? AttrCapabilities.AllowView : + resourceObjectOpenType == typeof(ResourceObjectInPostRequest<>) ? AttrCapabilities.AllowCreate : + resourceObjectOpenType == typeof(ResourceObjectInPatchRequest<>) ? AttrCapabilities.AllowChange : throw new UnreachableCodeException(); } private void AddAttributeSchemaToResourceObject(AttrAttribute attribute, OpenApiSchema attributesObjectSchema, OpenApiSchema resourceAttributeSchema) @@ -127,7 +128,7 @@ private void ExposeSchema(OpenApiReference openApiReference, Type typeRepresente private bool IsFieldRequired(ResourceFieldAttribute field) { - if (field is HasManyAttribute || _resourceTypeInfo.ResourceObjectOpenType != typeof(ResourcePostRequestObject<>)) + if (field is HasManyAttribute || _resourceTypeInfo.ResourceObjectOpenType != typeof(ResourceObjectInPostRequest<>)) { return false; } @@ -144,15 +145,6 @@ private bool IsFieldRequired(ResourceFieldAttribute field) }; } - private OpenApiSchema GetReferenceSchemaForFieldObject(OpenApiSchema fullSchema, string fieldObjectName) - { - // NSwag does not have proper support for using an inline schema for the attributes and relationships object in a resource object, see https://github.com/RicoSuter/NSwag/issues/3474. Once this issue has been resolved, we can remove this. - string resourceObjectSchemaId = _jsonApiSchemaIdSelector.GetSchemaId(_resourceTypeInfo.ResourceObjectType); - string fieldObjectSchemaId = resourceObjectSchemaId.Replace(JsonApiObjectPropertyName.Data, fieldObjectName); - - return _schemaRepositoryAccessor.Current.AddDefinition(fieldObjectSchemaId, fullSchema); - } - public OpenApiSchema? BuildRelationshipsObject(OpenApiSchema fullSchemaForResourceObject) { ArgumentGuard.NotNull(fullSchemaForResourceObject, nameof(fullSchemaForResourceObject)); @@ -168,7 +160,8 @@ private OpenApiSchema GetReferenceSchemaForFieldObject(OpenApiSchema fullSchema, fullSchemaForRelationshipsObject.AdditionalPropertiesAllowed = false; - return GetReferenceSchemaForFieldObject(fullSchemaForRelationshipsObject, JsonApiObjectPropertyName.RelationshipsObject); + string fieldObjectSchemaId = _jsonApiSchemaIdSelector.GetSchemaId(_resourceTypeInfo.ResourceObjectType, ResourceObjectFieldType.Relationships); + return _schemaRepositoryAccessor.Current.AddDefinition(fieldObjectSchemaId, fullSchemaForRelationshipsObject); } private void SetMembersOfRelationshipsObject(OpenApiSchema fullSchemaForRelationshipsObject) @@ -228,7 +221,7 @@ private void AddRelationshipSchemaToResourceObject(RelationshipAttribute relatio private static Type GetRelationshipSchemaType(RelationshipAttribute relationship, Type resourceObjectType) { - return resourceObjectType.GetGenericTypeDefinition().IsAssignableTo(typeof(ResourceResponseObject<>)) + return resourceObjectType.GetGenericTypeDefinition().IsAssignableTo(typeof(ResourceObjectInResponse<>)) ? RelationshipTypeFactory.Instance.GetForResponse(relationship) : RelationshipTypeFactory.Instance.GetForRequest(relationship); } diff --git a/src/JsonApiDotNetCore.OpenApi/SwaggerComponents/ResourceObjectSchemaGenerator.cs b/src/JsonApiDotNetCore.OpenApi/SwaggerComponents/ResourceObjectSchemaGenerator.cs index e374b203b7..4ea23c1450 100644 --- a/src/JsonApiDotNetCore.OpenApi/SwaggerComponents/ResourceObjectSchemaGenerator.cs +++ b/src/JsonApiDotNetCore.OpenApi/SwaggerComponents/ResourceObjectSchemaGenerator.cs @@ -92,7 +92,7 @@ public OpenApiSchema GenerateSchema(Type resourceObjectType) private void RemoveResourceIdIfPostResourceObject(Type resourceObjectOpenType, OpenApiSchema fullSchemaForResourceObject) { - if (resourceObjectOpenType == typeof(ResourcePostRequestObject<>) && !_allowClientGeneratedIds) + if (resourceObjectOpenType == typeof(ResourceObjectInPostRequest<>) && !_allowClientGeneratedIds) { fullSchemaForResourceObject.Required.Remove(JsonApiObjectPropertyName.Id); fullSchemaForResourceObject.Properties.Remove(JsonApiObjectPropertyName.Id); diff --git a/test/OpenApiClientTests/LegacyClient/ClientAttributeRegistrationLifeTimeTests.cs b/test/OpenApiClientTests/LegacyClient/ClientAttributeRegistrationLifeTimeTests.cs index f9e48c5da0..ff32763a81 100644 --- a/test/OpenApiClientTests/LegacyClient/ClientAttributeRegistrationLifeTimeTests.cs +++ b/test/OpenApiClientTests/LegacyClient/ClientAttributeRegistrationLifeTimeTests.cs @@ -20,7 +20,7 @@ public async Task Disposed_attribute_registration_for_document_does_not_affect_r var requestDocument = new AirplanePatchRequestDocument { - Data = new AirplaneDataInPatchRequest + Data = new AirplaneInPatchRequest { Id = airplaneId, Type = AirplanesResourceType.Airplanes, @@ -62,7 +62,7 @@ public async Task Attribute_registration_can_be_used_for_multiple_requests() var requestDocument = new AirplanePatchRequestDocument { - Data = new AirplaneDataInPatchRequest + Data = new AirplaneInPatchRequest { Id = airplaneId, Type = AirplanesResourceType.Airplanes, @@ -109,7 +109,7 @@ public async Task Request_is_unaffected_by_attribute_registration_for_different_ var requestDocument1 = new AirplanePatchRequestDocument { - Data = new AirplaneDataInPatchRequest + Data = new AirplaneInPatchRequest { Id = airplaneId1, Type = AirplanesResourceType.Airplanes, @@ -121,7 +121,7 @@ public async Task Request_is_unaffected_by_attribute_registration_for_different_ var requestDocument2 = new AirplanePatchRequestDocument { - Data = new AirplaneDataInPatchRequest + Data = new AirplaneInPatchRequest { Id = airplaneId2, Type = AirplanesResourceType.Airplanes, @@ -164,7 +164,7 @@ public async Task Attribute_values_can_be_changed_after_attribute_registration() var requestDocument = new AirplanePatchRequestDocument { - Data = new AirplaneDataInPatchRequest + Data = new AirplaneInPatchRequest { Id = airplaneId, Type = AirplanesResourceType.Airplanes, @@ -207,7 +207,7 @@ public async Task Attribute_registration_is_unaffected_by_successive_attribute_r var requestDocument1 = new AirplanePatchRequestDocument { - Data = new AirplaneDataInPatchRequest + Data = new AirplaneInPatchRequest { Id = airplaneId1, Type = AirplanesResourceType.Airplanes, @@ -217,7 +217,7 @@ public async Task Attribute_registration_is_unaffected_by_successive_attribute_r var requestDocument2 = new AirplanePostRequestDocument { - Data = new AirplaneDataInPostRequest + Data = new AirplaneInPostRequest { Type = AirplanesResourceType.Airplanes, Attributes = new AirplaneAttributesInPostRequest() @@ -258,7 +258,7 @@ public async Task Attribute_registration_is_unaffected_by_preceding_disposed_att var requestDocument1 = new AirplanePatchRequestDocument { - Data = new AirplaneDataInPatchRequest + Data = new AirplaneInPatchRequest { Id = airplaneId1, Type = AirplanesResourceType.Airplanes, @@ -276,7 +276,7 @@ public async Task Attribute_registration_is_unaffected_by_preceding_disposed_att var requestDocument2 = new AirplanePatchRequestDocument { - Data = new AirplaneDataInPatchRequest + Data = new AirplaneInPatchRequest { Id = airplaneId2, Type = AirplanesResourceType.Airplanes, @@ -318,7 +318,7 @@ public async Task Attribute_registration_is_unaffected_by_preceding_disposed_att var requestDocument1 = new AirplanePostRequestDocument { - Data = new AirplaneDataInPostRequest + Data = new AirplaneInPostRequest { Type = AirplanesResourceType.Airplanes, Attributes = new AirplaneAttributesInPostRequest() @@ -335,7 +335,7 @@ public async Task Attribute_registration_is_unaffected_by_preceding_disposed_att var requestDocument2 = new AirplanePatchRequestDocument { - Data = new AirplaneDataInPatchRequest + Data = new AirplaneInPatchRequest { Id = airplaneId, Type = AirplanesResourceType.Airplanes, @@ -379,7 +379,7 @@ public async Task Attribute_registration_is_unaffected_by_preceding_attribute_re var requestDocument1 = new AirplanePatchRequestDocument { - Data = new AirplaneDataInPatchRequest + Data = new AirplaneInPatchRequest { Id = airplaneId1, Type = AirplanesResourceType.Airplanes, @@ -391,7 +391,7 @@ public async Task Attribute_registration_is_unaffected_by_preceding_attribute_re var requestDocument2 = new AirplanePatchRequestDocument { - Data = new AirplaneDataInPatchRequest + Data = new AirplaneInPatchRequest { Id = airplaneId2, Type = AirplanesResourceType.Airplanes, diff --git a/test/OpenApiClientTests/LegacyClient/RequestTests.cs b/test/OpenApiClientTests/LegacyClient/RequestTests.cs index ef33288171..cf7848d1a5 100644 --- a/test/OpenApiClientTests/LegacyClient/RequestTests.cs +++ b/test/OpenApiClientTests/LegacyClient/RequestTests.cs @@ -64,12 +64,12 @@ public async Task Partial_posting_resource_with_selected_relationships_produces_ var requestDocument = new FlightPostRequestDocument { - Data = new FlightDataInPostRequest + Data = new FlightInPostRequest { Type = FlightsResourceType.Flights, Relationships = new FlightRelationshipsInPostRequest { - Purser = new ToOneFlightAttendantDataInRequest + Purser = new ToOneFlightAttendantInRequest { Data = new FlightAttendantIdentifier { @@ -77,7 +77,7 @@ public async Task Partial_posting_resource_with_selected_relationships_produces_ Type = FlightAttendantsResourceType.FlightAttendants } }, - BackupPurser = new NullableToOneFlightAttendantDataInRequest + BackupPurser = new NullableToOneFlightAttendantInRequest { Data = new FlightAttendantIdentifier { @@ -144,7 +144,7 @@ public async Task Partial_posting_resource_produces_expected_request() var requestDocument = new AirplanePostRequestDocument { - Data = new AirplaneDataInPostRequest + Data = new AirplaneInPostRequest { Type = AirplanesResourceType.Airplanes, Attributes = new AirplaneAttributesInPostRequest @@ -195,7 +195,7 @@ public async Task Partial_patching_resource_produces_expected_request() var requestDocument = new AirplanePatchRequestDocument { - Data = new AirplaneDataInPatchRequest + Data = new AirplaneInPatchRequest { Id = airplaneId, Type = AirplanesResourceType.Airplanes, @@ -325,7 +325,7 @@ public async Task Patching_ToOne_relationship_produces_expected_request() using var wrapper = FakeHttpClientWrapper.Create(HttpStatusCode.NoContent, null); IOpenApiClient apiClient = new OpenApiClient(wrapper.HttpClient); - var requestDocument = new ToOneFlightAttendantDataInRequest + var requestDocument = new ToOneFlightAttendantInRequest { Data = new FlightAttendantIdentifier { @@ -382,7 +382,7 @@ public async Task Posting_ToMany_relationship_produces_expected_request() using var wrapper = FakeHttpClientWrapper.Create(HttpStatusCode.NoContent, null); IOpenApiClient apiClient = new OpenApiClient(wrapper.HttpClient); - var requestDocument = new ToManyFlightAttendantDataInRequest + var requestDocument = new ToManyFlightAttendantInRequest { Data = new List { @@ -433,7 +433,7 @@ public async Task Patching_ToMany_relationship_produces_expected_request() using var wrapper = FakeHttpClientWrapper.Create(HttpStatusCode.NoContent, null); IOpenApiClient apiClient = new OpenApiClient(wrapper.HttpClient); - var requestDocument = new ToManyFlightAttendantDataInRequest + var requestDocument = new ToManyFlightAttendantInRequest { Data = new List { @@ -484,7 +484,7 @@ public async Task Deleting_ToMany_relationship_produces_expected_request() using var wrapper = FakeHttpClientWrapper.Create(HttpStatusCode.NoContent, null); IOpenApiClient apiClient = new OpenApiClient(wrapper.HttpClient); - var requestDocument = new ToManyFlightAttendantDataInRequest + var requestDocument = new ToManyFlightAttendantInRequest { Data = new List { diff --git a/test/OpenApiClientTests/LegacyClient/ResponseTests.cs b/test/OpenApiClientTests/LegacyClient/ResponseTests.cs index 9ca148f46a..38efbd9fef 100644 --- a/test/OpenApiClientTests/LegacyClient/ResponseTests.cs +++ b/test/OpenApiClientTests/LegacyClient/ResponseTests.cs @@ -110,7 +110,7 @@ public async Task Getting_resource_collection_translates_response() document.Links.Last.Should().Be(topLevelLink); document.Data.Should().HaveCount(1); - FlightDataInResponse flight = document.Data.First(); + FlightInResponse flight = document.Data.First(); flight.Id.Should().Be(flightId); flight.Type.Should().Be(FlightsResourceType.Flights); flight.Links.Self.Should().Be(flightResourceLink); @@ -278,12 +278,12 @@ public async Task Posting_resource_translates_response() // Act FlightPrimaryResponseDocument document = await apiClient.PostFlightAsync(new FlightPostRequestDocument { - Data = new FlightDataInPostRequest + Data = new FlightInPostRequest { Type = FlightsResourceType.Flights, Relationships = new FlightRelationshipsInPostRequest { - Purser = new ToOneFlightAttendantDataInRequest + Purser = new ToOneFlightAttendantInRequest { Data = new FlightAttendantIdentifier { @@ -330,7 +330,7 @@ public async Task Patching_resource_with_side_effects_translates_response() // Act FlightPrimaryResponseDocument document = await apiClient.PatchFlightAsync(flightId, new FlightPatchRequestDocument { - Data = new FlightDataInPatchRequest + Data = new FlightInPatchRequest { Id = flightId, Type = FlightsResourceType.Flights @@ -355,7 +355,7 @@ public async Task Patching_resource_without_side_effects_translates_response() FlightPrimaryResponseDocument? document = await ApiResponse.TranslateAsync(async () => await apiClient.PatchFlightAsync(flightId, new FlightPatchRequestDocument { - Data = new FlightDataInPatchRequest + Data = new FlightInPatchRequest { Id = flightId, Type = FlightsResourceType.Flights @@ -552,7 +552,7 @@ public async Task Patching_ToOne_relationship_translates_response() IOpenApiClient apiClient = new OpenApiClient(wrapper.HttpClient); // Act - await apiClient.PatchFlightPurserRelationshipAsync("ZvuH1", new ToOneFlightAttendantDataInRequest + await apiClient.PatchFlightPurserRelationshipAsync("ZvuH1", new ToOneFlightAttendantInRequest { Data = new FlightAttendantIdentifier { @@ -608,7 +608,7 @@ public async Task Posting_ToMany_relationship_produces_empty_response() IOpenApiClient apiClient = new OpenApiClient(wrapper.HttpClient); // Act - Func action = async () => await apiClient.PostFlightCabinCrewMembersRelationshipAsync("ZvuH1", new ToManyFlightAttendantDataInRequest + Func action = async () => await apiClient.PostFlightCabinCrewMembersRelationshipAsync("ZvuH1", new ToManyFlightAttendantInRequest { Data = new List { @@ -637,7 +637,7 @@ public async Task Patching_ToMany_relationship_produces_empty_response() IOpenApiClient apiClient = new OpenApiClient(wrapper.HttpClient); // Act - Func action = async () => await apiClient.PatchFlightCabinCrewMembersRelationshipAsync("ZvuH1", new ToManyFlightAttendantDataInRequest + Func action = async () => await apiClient.PatchFlightCabinCrewMembersRelationshipAsync("ZvuH1", new ToManyFlightAttendantInRequest { Data = new List { @@ -666,7 +666,7 @@ public async Task Deleting_ToMany_relationship_produces_empty_response() IOpenApiClient apiClient = new OpenApiClient(wrapper.HttpClient); // Act - Func action = async () => await apiClient.DeleteFlightCabinCrewMembersRelationshipAsync("ZvuH1", new ToManyFlightAttendantDataInRequest + Func action = async () => await apiClient.DeleteFlightCabinCrewMembersRelationshipAsync("ZvuH1", new ToManyFlightAttendantInRequest { Data = new List { diff --git a/test/OpenApiTests/LegacyOpenApiIntegration/swagger.json b/test/OpenApiTests/LegacyOpenApiIntegration/swagger.json index b3f72fe3c5..eba42ef0d0 100644 --- a/test/OpenApiTests/LegacyOpenApiIntegration/swagger.json +++ b/test/OpenApiTests/LegacyOpenApiIntegration/swagger.json @@ -326,7 +326,7 @@ "content": { "application/vnd.api+json": { "schema": { - "$ref": "#/components/schemas/to-many-flight-data-in-request" + "$ref": "#/components/schemas/to-many-flight-in-request" } } } @@ -356,7 +356,7 @@ "content": { "application/vnd.api+json": { "schema": { - "$ref": "#/components/schemas/to-many-flight-data-in-request" + "$ref": "#/components/schemas/to-many-flight-in-request" } } } @@ -386,7 +386,7 @@ "content": { "application/vnd.api+json": { "schema": { - "$ref": "#/components/schemas/to-many-flight-data-in-request" + "$ref": "#/components/schemas/to-many-flight-in-request" } } } @@ -719,7 +719,7 @@ "content": { "application/vnd.api+json": { "schema": { - "$ref": "#/components/schemas/to-many-flight-data-in-request" + "$ref": "#/components/schemas/to-many-flight-in-request" } } } @@ -749,7 +749,7 @@ "content": { "application/vnd.api+json": { "schema": { - "$ref": "#/components/schemas/to-many-flight-data-in-request" + "$ref": "#/components/schemas/to-many-flight-in-request" } } } @@ -779,7 +779,7 @@ "content": { "application/vnd.api+json": { "schema": { - "$ref": "#/components/schemas/to-many-flight-data-in-request" + "$ref": "#/components/schemas/to-many-flight-in-request" } } } @@ -925,7 +925,7 @@ "content": { "application/vnd.api+json": { "schema": { - "$ref": "#/components/schemas/to-many-flight-data-in-request" + "$ref": "#/components/schemas/to-many-flight-in-request" } } } @@ -955,7 +955,7 @@ "content": { "application/vnd.api+json": { "schema": { - "$ref": "#/components/schemas/to-many-flight-data-in-request" + "$ref": "#/components/schemas/to-many-flight-in-request" } } } @@ -985,7 +985,7 @@ "content": { "application/vnd.api+json": { "schema": { - "$ref": "#/components/schemas/to-many-flight-data-in-request" + "$ref": "#/components/schemas/to-many-flight-in-request" } } } @@ -1318,7 +1318,7 @@ "content": { "application/vnd.api+json": { "schema": { - "$ref": "#/components/schemas/nullable-to-one-flight-attendant-data-in-request" + "$ref": "#/components/schemas/nullable-to-one-flight-attendant-in-request" } } } @@ -1464,7 +1464,7 @@ "content": { "application/vnd.api+json": { "schema": { - "$ref": "#/components/schemas/to-many-flight-attendant-data-in-request" + "$ref": "#/components/schemas/to-many-flight-attendant-in-request" } } } @@ -1494,7 +1494,7 @@ "content": { "application/vnd.api+json": { "schema": { - "$ref": "#/components/schemas/to-many-flight-attendant-data-in-request" + "$ref": "#/components/schemas/to-many-flight-attendant-in-request" } } } @@ -1524,7 +1524,7 @@ "content": { "application/vnd.api+json": { "schema": { - "$ref": "#/components/schemas/to-many-flight-attendant-data-in-request" + "$ref": "#/components/schemas/to-many-flight-attendant-in-request" } } } @@ -1670,7 +1670,7 @@ "content": { "application/vnd.api+json": { "schema": { - "$ref": "#/components/schemas/to-many-passenger-data-in-request" + "$ref": "#/components/schemas/to-many-passenger-in-request" } } } @@ -1700,7 +1700,7 @@ "content": { "application/vnd.api+json": { "schema": { - "$ref": "#/components/schemas/to-many-passenger-data-in-request" + "$ref": "#/components/schemas/to-many-passenger-in-request" } } } @@ -1730,7 +1730,7 @@ "content": { "application/vnd.api+json": { "schema": { - "$ref": "#/components/schemas/to-many-passenger-data-in-request" + "$ref": "#/components/schemas/to-many-passenger-in-request" } } } @@ -1876,7 +1876,7 @@ "content": { "application/vnd.api+json": { "schema": { - "$ref": "#/components/schemas/to-one-flight-attendant-data-in-request" + "$ref": "#/components/schemas/to-one-flight-attendant-in-request" } } } @@ -2019,7 +2019,7 @@ "data": { "type": "array", "items": { - "$ref": "#/components/schemas/airplane-data-in-response" + "$ref": "#/components/schemas/airplane-in-response" } }, "meta": { @@ -2035,7 +2035,7 @@ }, "additionalProperties": false }, - "airplane-data-in-patch-request": { + "airplane-in-patch-request": { "required": [ "id", "type" @@ -2057,7 +2057,7 @@ }, "additionalProperties": false }, - "airplane-data-in-post-request": { + "airplane-in-post-request": { "required": [ "type" ], @@ -2075,7 +2075,7 @@ }, "additionalProperties": false }, - "airplane-data-in-response": { + "airplane-in-response": { "required": [ "id", "links", @@ -2112,7 +2112,7 @@ "type": "object", "properties": { "data": { - "$ref": "#/components/schemas/airplane-data-in-patch-request" + "$ref": "#/components/schemas/airplane-in-patch-request" } }, "additionalProperties": false @@ -2124,7 +2124,7 @@ "type": "object", "properties": { "data": { - "$ref": "#/components/schemas/airplane-data-in-post-request" + "$ref": "#/components/schemas/airplane-in-post-request" } }, "additionalProperties": false @@ -2137,7 +2137,7 @@ "type": "object", "properties": { "data": { - "$ref": "#/components/schemas/airplane-data-in-response" + "$ref": "#/components/schemas/airplane-in-response" }, "meta": { "type": "object", @@ -2156,7 +2156,7 @@ "type": "object", "properties": { "flights": { - "$ref": "#/components/schemas/to-many-flight-data-in-request" + "$ref": "#/components/schemas/to-many-flight-in-request" } }, "additionalProperties": false @@ -2165,7 +2165,7 @@ "type": "object", "properties": { "flights": { - "$ref": "#/components/schemas/to-many-flight-data-in-request" + "$ref": "#/components/schemas/to-many-flight-in-request" } }, "additionalProperties": false @@ -2174,7 +2174,7 @@ "type": "object", "properties": { "flights": { - "$ref": "#/components/schemas/to-many-flight-data-in-response" + "$ref": "#/components/schemas/to-many-flight-in-response" } }, "additionalProperties": false @@ -2267,7 +2267,7 @@ "data": { "type": "array", "items": { - "$ref": "#/components/schemas/flight-attendant-data-in-response" + "$ref": "#/components/schemas/flight-attendant-in-response" } }, "meta": { @@ -2283,7 +2283,7 @@ }, "additionalProperties": false }, - "flight-attendant-data-in-patch-request": { + "flight-attendant-identifier": { "required": [ "id", "type" @@ -2295,65 +2295,60 @@ }, "id": { "type": "string" - }, - "attributes": { - "$ref": "#/components/schemas/flight-attendant-attributes-in-patch-request" - }, - "relationships": { - "$ref": "#/components/schemas/flight-attendant-relationships-in-patch-request" } }, "additionalProperties": false }, - "flight-attendant-data-in-post-request": { + "flight-attendant-identifier-collection-response-document": { "required": [ - "type" + "data", + "links" ], "type": "object", "properties": { - "type": { - "$ref": "#/components/schemas/flight-attendants-resource-type" + "data": { + "type": "array", + "items": { + "$ref": "#/components/schemas/flight-attendant-identifier" + } }, - "attributes": { - "$ref": "#/components/schemas/flight-attendant-attributes-in-post-request" + "meta": { + "type": "object", + "additionalProperties": {} }, - "relationships": { - "$ref": "#/components/schemas/flight-attendant-relationships-in-post-request" + "jsonapi": { + "$ref": "#/components/schemas/jsonapi-object" + }, + "links": { + "$ref": "#/components/schemas/links-in-resource-identifier-collection-document" } }, "additionalProperties": false }, - "flight-attendant-data-in-response": { + "flight-attendant-identifier-response-document": { "required": [ - "id", - "links", - "type" + "data", + "links" ], "type": "object", "properties": { - "type": { - "$ref": "#/components/schemas/flight-attendants-resource-type" - }, - "id": { - "type": "string" - }, - "attributes": { - "$ref": "#/components/schemas/flight-attendant-attributes-in-response" - }, - "relationships": { - "$ref": "#/components/schemas/flight-attendant-relationships-in-response" - }, - "links": { - "$ref": "#/components/schemas/links-in-resource-object" + "data": { + "$ref": "#/components/schemas/flight-attendant-identifier" }, "meta": { "type": "object", "additionalProperties": {} + }, + "jsonapi": { + "$ref": "#/components/schemas/jsonapi-object" + }, + "links": { + "$ref": "#/components/schemas/links-in-resource-identifier-document" } }, "additionalProperties": false }, - "flight-attendant-identifier": { + "flight-attendant-in-patch-request": { "required": [ "id", "type" @@ -2365,55 +2360,60 @@ }, "id": { "type": "string" + }, + "attributes": { + "$ref": "#/components/schemas/flight-attendant-attributes-in-patch-request" + }, + "relationships": { + "$ref": "#/components/schemas/flight-attendant-relationships-in-patch-request" } }, "additionalProperties": false }, - "flight-attendant-identifier-collection-response-document": { + "flight-attendant-in-post-request": { "required": [ - "data", - "links" + "type" ], "type": "object", "properties": { - "data": { - "type": "array", - "items": { - "$ref": "#/components/schemas/flight-attendant-identifier" - } - }, - "meta": { - "type": "object", - "additionalProperties": {} + "type": { + "$ref": "#/components/schemas/flight-attendants-resource-type" }, - "jsonapi": { - "$ref": "#/components/schemas/jsonapi-object" + "attributes": { + "$ref": "#/components/schemas/flight-attendant-attributes-in-post-request" }, - "links": { - "$ref": "#/components/schemas/links-in-resource-identifier-collection-document" + "relationships": { + "$ref": "#/components/schemas/flight-attendant-relationships-in-post-request" } }, "additionalProperties": false }, - "flight-attendant-identifier-response-document": { + "flight-attendant-in-response": { "required": [ - "data", - "links" + "id", + "links", + "type" ], "type": "object", "properties": { - "data": { - "$ref": "#/components/schemas/flight-attendant-identifier" + "type": { + "$ref": "#/components/schemas/flight-attendants-resource-type" }, - "meta": { - "type": "object", - "additionalProperties": {} + "id": { + "type": "string" }, - "jsonapi": { - "$ref": "#/components/schemas/jsonapi-object" + "attributes": { + "$ref": "#/components/schemas/flight-attendant-attributes-in-response" + }, + "relationships": { + "$ref": "#/components/schemas/flight-attendant-relationships-in-response" }, "links": { - "$ref": "#/components/schemas/links-in-resource-identifier-document" + "$ref": "#/components/schemas/links-in-resource-object" + }, + "meta": { + "type": "object", + "additionalProperties": {} } }, "additionalProperties": false @@ -2425,7 +2425,7 @@ "type": "object", "properties": { "data": { - "$ref": "#/components/schemas/flight-attendant-data-in-patch-request" + "$ref": "#/components/schemas/flight-attendant-in-patch-request" } }, "additionalProperties": false @@ -2437,7 +2437,7 @@ "type": "object", "properties": { "data": { - "$ref": "#/components/schemas/flight-attendant-data-in-post-request" + "$ref": "#/components/schemas/flight-attendant-in-post-request" } }, "additionalProperties": false @@ -2450,7 +2450,7 @@ "type": "object", "properties": { "data": { - "$ref": "#/components/schemas/flight-attendant-data-in-response" + "$ref": "#/components/schemas/flight-attendant-in-response" }, "meta": { "type": "object", @@ -2469,10 +2469,10 @@ "type": "object", "properties": { "scheduled-for-flights": { - "$ref": "#/components/schemas/to-many-flight-data-in-request" + "$ref": "#/components/schemas/to-many-flight-in-request" }, "purser-on-flights": { - "$ref": "#/components/schemas/to-many-flight-data-in-request" + "$ref": "#/components/schemas/to-many-flight-in-request" } }, "additionalProperties": false @@ -2481,10 +2481,10 @@ "type": "object", "properties": { "scheduled-for-flights": { - "$ref": "#/components/schemas/to-many-flight-data-in-request" + "$ref": "#/components/schemas/to-many-flight-in-request" }, "purser-on-flights": { - "$ref": "#/components/schemas/to-many-flight-data-in-request" + "$ref": "#/components/schemas/to-many-flight-in-request" } }, "additionalProperties": false @@ -2493,10 +2493,10 @@ "type": "object", "properties": { "scheduled-for-flights": { - "$ref": "#/components/schemas/to-many-flight-data-in-response" + "$ref": "#/components/schemas/to-many-flight-in-response" }, "purser-on-flights": { - "$ref": "#/components/schemas/to-many-flight-data-in-response" + "$ref": "#/components/schemas/to-many-flight-in-response" } }, "additionalProperties": false @@ -2509,7 +2509,7 @@ "type": "object", "properties": { "data": { - "$ref": "#/components/schemas/flight-attendant-data-in-response" + "$ref": "#/components/schemas/flight-attendant-in-response" }, "meta": { "type": "object", @@ -2592,7 +2592,7 @@ "data": { "type": "array", "items": { - "$ref": "#/components/schemas/flight-data-in-response" + "$ref": "#/components/schemas/flight-in-response" } }, "meta": { @@ -2608,7 +2608,7 @@ }, "additionalProperties": false }, - "flight-data-in-patch-request": { + "flight-identifier": { "required": [ "id", "type" @@ -2620,35 +2620,39 @@ }, "id": { "type": "string" - }, - "attributes": { - "$ref": "#/components/schemas/flight-attributes-in-patch-request" - }, - "relationships": { - "$ref": "#/components/schemas/flight-relationships-in-patch-request" } }, "additionalProperties": false }, - "flight-data-in-post-request": { + "flight-identifier-collection-response-document": { "required": [ - "type" + "data", + "links" ], "type": "object", "properties": { - "type": { - "$ref": "#/components/schemas/flights-resource-type" + "data": { + "type": "array", + "items": { + "$ref": "#/components/schemas/flight-identifier" + } }, - "relationships": { - "$ref": "#/components/schemas/flight-relationships-in-post-request" + "meta": { + "type": "object", + "additionalProperties": {} + }, + "jsonapi": { + "$ref": "#/components/schemas/jsonapi-object" + }, + "links": { + "$ref": "#/components/schemas/links-in-resource-identifier-collection-document" } }, "additionalProperties": false }, - "flight-data-in-response": { + "flight-in-patch-request": { "required": [ "id", - "links", "type" ], "type": "object", @@ -2660,24 +2664,16 @@ "type": "string" }, "attributes": { - "$ref": "#/components/schemas/flight-attributes-in-response" + "$ref": "#/components/schemas/flight-attributes-in-patch-request" }, "relationships": { - "$ref": "#/components/schemas/flight-relationships-in-response" - }, - "links": { - "$ref": "#/components/schemas/links-in-resource-object" - }, - "meta": { - "type": "object", - "additionalProperties": {} + "$ref": "#/components/schemas/flight-relationships-in-patch-request" } }, "additionalProperties": false }, - "flight-identifier": { + "flight-in-post-request": { "required": [ - "id", "type" ], "type": "object", @@ -2685,34 +2681,38 @@ "type": { "$ref": "#/components/schemas/flights-resource-type" }, - "id": { - "type": "string" + "relationships": { + "$ref": "#/components/schemas/flight-relationships-in-post-request" } }, "additionalProperties": false }, - "flight-identifier-collection-response-document": { + "flight-in-response": { "required": [ - "data", - "links" + "id", + "links", + "type" ], "type": "object", "properties": { - "data": { - "type": "array", - "items": { - "$ref": "#/components/schemas/flight-identifier" - } + "type": { + "$ref": "#/components/schemas/flights-resource-type" }, - "meta": { - "type": "object", - "additionalProperties": {} + "id": { + "type": "string" }, - "jsonapi": { - "$ref": "#/components/schemas/jsonapi-object" + "attributes": { + "$ref": "#/components/schemas/flight-attributes-in-response" + }, + "relationships": { + "$ref": "#/components/schemas/flight-relationships-in-response" }, "links": { - "$ref": "#/components/schemas/links-in-resource-identifier-collection-document" + "$ref": "#/components/schemas/links-in-resource-object" + }, + "meta": { + "type": "object", + "additionalProperties": {} } }, "additionalProperties": false @@ -2724,7 +2724,7 @@ "type": "object", "properties": { "data": { - "$ref": "#/components/schemas/flight-data-in-patch-request" + "$ref": "#/components/schemas/flight-in-patch-request" } }, "additionalProperties": false @@ -2736,7 +2736,7 @@ "type": "object", "properties": { "data": { - "$ref": "#/components/schemas/flight-data-in-post-request" + "$ref": "#/components/schemas/flight-in-post-request" } }, "additionalProperties": false @@ -2749,7 +2749,7 @@ "type": "object", "properties": { "data": { - "$ref": "#/components/schemas/flight-data-in-response" + "$ref": "#/components/schemas/flight-in-response" }, "meta": { "type": "object", @@ -2768,16 +2768,16 @@ "type": "object", "properties": { "cabin-crew-members": { - "$ref": "#/components/schemas/to-many-flight-attendant-data-in-request" + "$ref": "#/components/schemas/to-many-flight-attendant-in-request" }, "purser": { - "$ref": "#/components/schemas/to-one-flight-attendant-data-in-request" + "$ref": "#/components/schemas/to-one-flight-attendant-in-request" }, "backup-purser": { - "$ref": "#/components/schemas/nullable-to-one-flight-attendant-data-in-request" + "$ref": "#/components/schemas/nullable-to-one-flight-attendant-in-request" }, "passengers": { - "$ref": "#/components/schemas/to-many-passenger-data-in-request" + "$ref": "#/components/schemas/to-many-passenger-in-request" } }, "additionalProperties": false @@ -2789,16 +2789,16 @@ "type": "object", "properties": { "cabin-crew-members": { - "$ref": "#/components/schemas/to-many-flight-attendant-data-in-request" + "$ref": "#/components/schemas/to-many-flight-attendant-in-request" }, "purser": { - "$ref": "#/components/schemas/to-one-flight-attendant-data-in-request" + "$ref": "#/components/schemas/to-one-flight-attendant-in-request" }, "backup-purser": { - "$ref": "#/components/schemas/nullable-to-one-flight-attendant-data-in-request" + "$ref": "#/components/schemas/nullable-to-one-flight-attendant-in-request" }, "passengers": { - "$ref": "#/components/schemas/to-many-passenger-data-in-request" + "$ref": "#/components/schemas/to-many-passenger-in-request" } }, "additionalProperties": false @@ -2807,16 +2807,16 @@ "type": "object", "properties": { "cabin-crew-members": { - "$ref": "#/components/schemas/to-many-flight-attendant-data-in-response" + "$ref": "#/components/schemas/to-many-flight-attendant-in-response" }, "purser": { - "$ref": "#/components/schemas/to-one-flight-attendant-data-in-response" + "$ref": "#/components/schemas/to-one-flight-attendant-in-response" }, "backup-purser": { - "$ref": "#/components/schemas/nullable-to-one-flight-attendant-data-in-response" + "$ref": "#/components/schemas/nullable-to-one-flight-attendant-in-response" }, "passengers": { - "$ref": "#/components/schemas/to-many-passenger-data-in-response" + "$ref": "#/components/schemas/to-many-passenger-in-response" } }, "additionalProperties": false @@ -3037,7 +3037,7 @@ "data": { "oneOf": [ { - "$ref": "#/components/schemas/flight-attendant-data-in-response" + "$ref": "#/components/schemas/flight-attendant-in-response" }, { "$ref": "#/components/schemas/null-value" @@ -3057,7 +3057,7 @@ }, "additionalProperties": false }, - "nullable-to-one-flight-attendant-data-in-request": { + "nullable-to-one-flight-attendant-in-request": { "required": [ "data" ], @@ -3076,7 +3076,7 @@ }, "additionalProperties": false }, - "nullable-to-one-flight-attendant-data-in-response": { + "nullable-to-one-flight-attendant-in-response": { "required": [ "links" ], @@ -3125,7 +3125,7 @@ "data": { "type": "array", "items": { - "$ref": "#/components/schemas/passenger-data-in-response" + "$ref": "#/components/schemas/passenger-in-response" } }, "meta": { @@ -3141,33 +3141,6 @@ }, "additionalProperties": false }, - "passenger-data-in-response": { - "required": [ - "id", - "links", - "type" - ], - "type": "object", - "properties": { - "type": { - "$ref": "#/components/schemas/passengers-resource-type" - }, - "id": { - "type": "string" - }, - "attributes": { - "$ref": "#/components/schemas/passenger-attributes-in-response" - }, - "links": { - "$ref": "#/components/schemas/links-in-resource-object" - }, - "meta": { - "type": "object", - "additionalProperties": {} - } - }, - "additionalProperties": false - }, "passenger-identifier": { "required": [ "id", @@ -3210,13 +3183,40 @@ }, "additionalProperties": false }, + "passenger-in-response": { + "required": [ + "id", + "links", + "type" + ], + "type": "object", + "properties": { + "type": { + "$ref": "#/components/schemas/passengers-resource-type" + }, + "id": { + "type": "string" + }, + "attributes": { + "$ref": "#/components/schemas/passenger-attributes-in-response" + }, + "links": { + "$ref": "#/components/schemas/links-in-resource-object" + }, + "meta": { + "type": "object", + "additionalProperties": {} + } + }, + "additionalProperties": false + }, "passengers-resource-type": { "enum": [ "passengers" ], "type": "string" }, - "to-many-flight-attendant-data-in-request": { + "to-many-flight-attendant-in-request": { "required": [ "data" ], @@ -3231,7 +3231,7 @@ }, "additionalProperties": false }, - "to-many-flight-attendant-data-in-response": { + "to-many-flight-attendant-in-response": { "required": [ "links" ], @@ -3253,7 +3253,7 @@ }, "additionalProperties": false }, - "to-many-flight-data-in-request": { + "to-many-flight-in-request": { "required": [ "data" ], @@ -3268,7 +3268,7 @@ }, "additionalProperties": false }, - "to-many-flight-data-in-response": { + "to-many-flight-in-response": { "required": [ "links" ], @@ -3290,7 +3290,7 @@ }, "additionalProperties": false }, - "to-many-passenger-data-in-request": { + "to-many-passenger-in-request": { "required": [ "data" ], @@ -3305,7 +3305,7 @@ }, "additionalProperties": false }, - "to-many-passenger-data-in-response": { + "to-many-passenger-in-response": { "required": [ "links" ], @@ -3327,7 +3327,7 @@ }, "additionalProperties": false }, - "to-one-flight-attendant-data-in-request": { + "to-one-flight-attendant-in-request": { "required": [ "data" ], @@ -3339,7 +3339,7 @@ }, "additionalProperties": false }, - "to-one-flight-attendant-data-in-response": { + "to-one-flight-attendant-in-response": { "required": [ "links" ], From 727d06843328eeafa61fa454b87da7dc81c6dd70 Mon Sep 17 00:00:00 2001 From: maurei Date: Fri, 26 Nov 2021 18:04:58 +0100 Subject: [PATCH 3/5] fix variable name --- .../JsonApiSchemaIdSelector.cs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/JsonApiDotNetCore.OpenApi/JsonApiSchemaIdSelector.cs b/src/JsonApiDotNetCore.OpenApi/JsonApiSchemaIdSelector.cs index 8b471bd8e0..dab1f45729 100644 --- a/src/JsonApiDotNetCore.OpenApi/JsonApiSchemaIdSelector.cs +++ b/src/JsonApiDotNetCore.OpenApi/JsonApiSchemaIdSelector.cs @@ -77,18 +77,18 @@ public string GetSchemaId(Type type) return _formatter.FormatResourceName(type).Singularize(); } - public string GetSchemaId(Type resourceObjectOpenType, ResourceObjectFieldType fieldType) + public string GetSchemaId(Type resourceObjectType, ResourceObjectFieldType fieldType) { - ArgumentGuard.NotNull(resourceObjectOpenType, nameof(resourceObjectOpenType)); + ArgumentGuard.NotNull(resourceObjectType, nameof(resourceObjectType)); - if (!resourceObjectOpenType.IsConstructedGenericType || !_resourceObjectOpenTypes.Contains(resourceObjectOpenType.GetGenericTypeDefinition())) + if (!resourceObjectType.IsConstructedGenericType || !_resourceObjectOpenTypes.Contains(resourceObjectType.GetGenericTypeDefinition())) { - throw new InvalidOperationException($"Type '{resourceObjectOpenType.Name}' must be an open type representing a resource object."); + throw new InvalidOperationException($"Type '{resourceObjectType.Name}' must be a resource object."); } - Type resourceClrType = resourceObjectOpenType.GetGenericArguments().First(); + Type resourceClrType = resourceObjectType.GetGenericArguments().First(); string resourceName = _formatter.FormatResourceName(resourceClrType).Singularize(); - string template = OpenTypeToSchemaTemplateMap[resourceObjectOpenType.GetGenericTypeDefinition()]; + string template = OpenTypeToSchemaTemplateMap[resourceObjectType.GetGenericTypeDefinition()]; string fieldObjectName = fieldType == ResourceObjectFieldType.Attributes ? JsonApiObjectPropertyName.AttributesObject From 12eed0b0df703edf4762efd3da46cef460c8a3cc Mon Sep 17 00:00:00 2001 From: maurei Date: Tue, 30 Nov 2021 12:54:55 +0100 Subject: [PATCH 4/5] Introduced types for attributes and relationships in resource objects --- .../AttributesInPatchRequest.cs | 10 ++++ .../AttributesInPostRequest.cs | 10 ++++ .../ResourceObjects/AttributesInResponse.cs | 10 ++++ .../RelationshipsInPatchRequest.cs | 10 ++++ .../RelationshipsInPostRequest.cs | 10 ++++ .../RelationshipsInResponse.cs | 10 ++++ .../ResourceIdentifierObject.cs | 2 +- .../ResourceObjects/ResourceObject.cs | 15 ------ .../ResourceObjectInPatchRequest.cs | 7 ++- .../ResourceObjectInPostRequest.cs | 7 ++- .../ResourceObjectInResponse.cs | 6 ++- .../JsonApiSchemaIdSelector.cs | 33 +++--------- .../ResourceObjectFieldType.cs | 8 --- .../ResourceFieldObjectSchemaBuilder.cs | 47 ++--------------- .../ResourceObjectSchemaGenerator.cs | 50 +++++++++---------- .../SwaggerComponents/ResourceTypeInfo.cs | 6 +-- 16 files changed, 112 insertions(+), 129 deletions(-) create mode 100644 src/JsonApiDotNetCore.OpenApi/JsonApiObjects/ResourceObjects/AttributesInPatchRequest.cs create mode 100644 src/JsonApiDotNetCore.OpenApi/JsonApiObjects/ResourceObjects/AttributesInPostRequest.cs create mode 100644 src/JsonApiDotNetCore.OpenApi/JsonApiObjects/ResourceObjects/AttributesInResponse.cs create mode 100644 src/JsonApiDotNetCore.OpenApi/JsonApiObjects/ResourceObjects/RelationshipsInPatchRequest.cs create mode 100644 src/JsonApiDotNetCore.OpenApi/JsonApiObjects/ResourceObjects/RelationshipsInPostRequest.cs create mode 100644 src/JsonApiDotNetCore.OpenApi/JsonApiObjects/ResourceObjects/RelationshipsInResponse.cs delete mode 100644 src/JsonApiDotNetCore.OpenApi/JsonApiObjects/ResourceObjects/ResourceObject.cs delete mode 100644 src/JsonApiDotNetCore.OpenApi/ResourceObjectFieldType.cs diff --git a/src/JsonApiDotNetCore.OpenApi/JsonApiObjects/ResourceObjects/AttributesInPatchRequest.cs b/src/JsonApiDotNetCore.OpenApi/JsonApiObjects/ResourceObjects/AttributesInPatchRequest.cs new file mode 100644 index 0000000000..84e4c3cc5b --- /dev/null +++ b/src/JsonApiDotNetCore.OpenApi/JsonApiObjects/ResourceObjects/AttributesInPatchRequest.cs @@ -0,0 +1,10 @@ +using JsonApiDotNetCore.Resources; + +namespace JsonApiDotNetCore.OpenApi.JsonApiObjects.ResourceObjects +{ + // ReSharper disable once UnusedTypeParameter + internal sealed class AttributesInPatchRequest + where TResource : IIdentifiable + { + } +} diff --git a/src/JsonApiDotNetCore.OpenApi/JsonApiObjects/ResourceObjects/AttributesInPostRequest.cs b/src/JsonApiDotNetCore.OpenApi/JsonApiObjects/ResourceObjects/AttributesInPostRequest.cs new file mode 100644 index 0000000000..798ccfd30b --- /dev/null +++ b/src/JsonApiDotNetCore.OpenApi/JsonApiObjects/ResourceObjects/AttributesInPostRequest.cs @@ -0,0 +1,10 @@ +using JsonApiDotNetCore.Resources; + +namespace JsonApiDotNetCore.OpenApi.JsonApiObjects.ResourceObjects +{ + // ReSharper disable once UnusedTypeParameter + internal sealed class AttributesInPostRequest + where TResource : IIdentifiable + { + } +} diff --git a/src/JsonApiDotNetCore.OpenApi/JsonApiObjects/ResourceObjects/AttributesInResponse.cs b/src/JsonApiDotNetCore.OpenApi/JsonApiObjects/ResourceObjects/AttributesInResponse.cs new file mode 100644 index 0000000000..65af8f7423 --- /dev/null +++ b/src/JsonApiDotNetCore.OpenApi/JsonApiObjects/ResourceObjects/AttributesInResponse.cs @@ -0,0 +1,10 @@ +using JsonApiDotNetCore.Resources; + +namespace JsonApiDotNetCore.OpenApi.JsonApiObjects.ResourceObjects +{ + // ReSharper disable once UnusedTypeParameter + internal sealed class AttributesInResponse + where TResource : IIdentifiable + { + } +} diff --git a/src/JsonApiDotNetCore.OpenApi/JsonApiObjects/ResourceObjects/RelationshipsInPatchRequest.cs b/src/JsonApiDotNetCore.OpenApi/JsonApiObjects/ResourceObjects/RelationshipsInPatchRequest.cs new file mode 100644 index 0000000000..da648ecb05 --- /dev/null +++ b/src/JsonApiDotNetCore.OpenApi/JsonApiObjects/ResourceObjects/RelationshipsInPatchRequest.cs @@ -0,0 +1,10 @@ +using JsonApiDotNetCore.Resources; + +namespace JsonApiDotNetCore.OpenApi.JsonApiObjects.ResourceObjects +{ + // ReSharper disable once UnusedTypeParameter + internal sealed class RelationshipsInPatchRequest + where TResource : IIdentifiable + { + } +} diff --git a/src/JsonApiDotNetCore.OpenApi/JsonApiObjects/ResourceObjects/RelationshipsInPostRequest.cs b/src/JsonApiDotNetCore.OpenApi/JsonApiObjects/ResourceObjects/RelationshipsInPostRequest.cs new file mode 100644 index 0000000000..2ac99e1970 --- /dev/null +++ b/src/JsonApiDotNetCore.OpenApi/JsonApiObjects/ResourceObjects/RelationshipsInPostRequest.cs @@ -0,0 +1,10 @@ +using JsonApiDotNetCore.Resources; + +namespace JsonApiDotNetCore.OpenApi.JsonApiObjects.ResourceObjects +{ + // ReSharper disable once UnusedTypeParameter + internal sealed class RelationshipsInPostRequest + where TResource : IIdentifiable + { + } +} diff --git a/src/JsonApiDotNetCore.OpenApi/JsonApiObjects/ResourceObjects/RelationshipsInResponse.cs b/src/JsonApiDotNetCore.OpenApi/JsonApiObjects/ResourceObjects/RelationshipsInResponse.cs new file mode 100644 index 0000000000..75bff02ac1 --- /dev/null +++ b/src/JsonApiDotNetCore.OpenApi/JsonApiObjects/ResourceObjects/RelationshipsInResponse.cs @@ -0,0 +1,10 @@ +using JsonApiDotNetCore.Resources; + +namespace JsonApiDotNetCore.OpenApi.JsonApiObjects.ResourceObjects +{ + // ReSharper disable once UnusedTypeParameter + internal sealed class RelationshipsInResponse + where TResource : IIdentifiable + { + } +} diff --git a/src/JsonApiDotNetCore.OpenApi/JsonApiObjects/ResourceObjects/ResourceIdentifierObject.cs b/src/JsonApiDotNetCore.OpenApi/JsonApiObjects/ResourceObjects/ResourceIdentifierObject.cs index ad7fb8bb6c..7471acabd6 100644 --- a/src/JsonApiDotNetCore.OpenApi/JsonApiObjects/ResourceObjects/ResourceIdentifierObject.cs +++ b/src/JsonApiDotNetCore.OpenApi/JsonApiObjects/ResourceObjects/ResourceIdentifierObject.cs @@ -5,7 +5,7 @@ namespace JsonApiDotNetCore.OpenApi.JsonApiObjects.ResourceObjects { // ReSharper disable once UnusedTypeParameter - internal class ResourceIdentifierObject : ResourceIdentifierObject + internal sealed class ResourceIdentifierObject : ResourceIdentifierObject where TResource : IIdentifiable { } diff --git a/src/JsonApiDotNetCore.OpenApi/JsonApiObjects/ResourceObjects/ResourceObject.cs b/src/JsonApiDotNetCore.OpenApi/JsonApiObjects/ResourceObjects/ResourceObject.cs deleted file mode 100644 index 38218eddc6..0000000000 --- a/src/JsonApiDotNetCore.OpenApi/JsonApiObjects/ResourceObjects/ResourceObject.cs +++ /dev/null @@ -1,15 +0,0 @@ -using System.Collections.Generic; -using JetBrains.Annotations; -using JsonApiDotNetCore.Resources; - -namespace JsonApiDotNetCore.OpenApi.JsonApiObjects.ResourceObjects -{ - [UsedImplicitly(ImplicitUseTargetFlags.Members)] - internal abstract class ResourceObject : ResourceIdentifierObject - where TResource : IIdentifiable - { - public IDictionary Attributes { get; set; } = null!; - - public IDictionary Relationships { get; set; } = null!; - } -} diff --git a/src/JsonApiDotNetCore.OpenApi/JsonApiObjects/ResourceObjects/ResourceObjectInPatchRequest.cs b/src/JsonApiDotNetCore.OpenApi/JsonApiObjects/ResourceObjects/ResourceObjectInPatchRequest.cs index 90113a9d86..dc785579a1 100644 --- a/src/JsonApiDotNetCore.OpenApi/JsonApiObjects/ResourceObjects/ResourceObjectInPatchRequest.cs +++ b/src/JsonApiDotNetCore.OpenApi/JsonApiObjects/ResourceObjects/ResourceObjectInPatchRequest.cs @@ -1,9 +1,14 @@ +using JetBrains.Annotations; using JsonApiDotNetCore.Resources; namespace JsonApiDotNetCore.OpenApi.JsonApiObjects.ResourceObjects { - internal sealed class ResourceObjectInPatchRequest : ResourceObject + [UsedImplicitly(ImplicitUseTargetFlags.Members)] + internal sealed class ResourceObjectInPatchRequest : ResourceIdentifierObject where TResource : IIdentifiable { + public AttributesInPatchRequest Attributes { get; set; } = null!; + + public RelationshipsInPatchRequest Relationships { get; set; } = null!; } } diff --git a/src/JsonApiDotNetCore.OpenApi/JsonApiObjects/ResourceObjects/ResourceObjectInPostRequest.cs b/src/JsonApiDotNetCore.OpenApi/JsonApiObjects/ResourceObjects/ResourceObjectInPostRequest.cs index 56bc3d0726..873c12d9c4 100644 --- a/src/JsonApiDotNetCore.OpenApi/JsonApiObjects/ResourceObjects/ResourceObjectInPostRequest.cs +++ b/src/JsonApiDotNetCore.OpenApi/JsonApiObjects/ResourceObjects/ResourceObjectInPostRequest.cs @@ -1,9 +1,14 @@ +using JetBrains.Annotations; using JsonApiDotNetCore.Resources; namespace JsonApiDotNetCore.OpenApi.JsonApiObjects.ResourceObjects { - internal sealed class ResourceObjectInPostRequest : ResourceObject + [UsedImplicitly(ImplicitUseTargetFlags.Members)] + internal sealed class ResourceObjectInPostRequest : ResourceIdentifierObject where TResource : IIdentifiable { + public AttributesInPostRequest Attributes { get; set; } = null!; + + public RelationshipsInPostRequest Relationships { get; set; } = null!; } } diff --git a/src/JsonApiDotNetCore.OpenApi/JsonApiObjects/ResourceObjects/ResourceObjectInResponse.cs b/src/JsonApiDotNetCore.OpenApi/JsonApiObjects/ResourceObjects/ResourceObjectInResponse.cs index 3a12ee1007..07e5f42f88 100644 --- a/src/JsonApiDotNetCore.OpenApi/JsonApiObjects/ResourceObjects/ResourceObjectInResponse.cs +++ b/src/JsonApiDotNetCore.OpenApi/JsonApiObjects/ResourceObjects/ResourceObjectInResponse.cs @@ -7,9 +7,13 @@ namespace JsonApiDotNetCore.OpenApi.JsonApiObjects.ResourceObjects { [UsedImplicitly(ImplicitUseTargetFlags.Members)] - internal sealed class ResourceObjectInResponse : ResourceObject + internal sealed class ResourceObjectInResponse : ResourceIdentifierObject where TResource : IIdentifiable { + public AttributesInResponse Attributes { get; set; } = null!; + + public RelationshipsInResponse Relationships { get; set; } = null!; + [Required] public LinksInResourceObject Links { get; set; } = null!; diff --git a/src/JsonApiDotNetCore.OpenApi/JsonApiSchemaIdSelector.cs b/src/JsonApiDotNetCore.OpenApi/JsonApiSchemaIdSelector.cs index dab1f45729..a607fead36 100644 --- a/src/JsonApiDotNetCore.OpenApi/JsonApiSchemaIdSelector.cs +++ b/src/JsonApiDotNetCore.OpenApi/JsonApiSchemaIdSelector.cs @@ -16,7 +16,11 @@ internal sealed class JsonApiSchemaIdSelector [typeof(ResourcePostRequestDocument<>)] = "###-post-request-document", [typeof(ResourcePatchRequestDocument<>)] = "###-patch-request-document", [typeof(ResourceObjectInPostRequest<>)] = "###-in-post-request", + [typeof(AttributesInPostRequest<>)] = "###-attributes-in-post-request", + [typeof(RelationshipsInPostRequest<>)] = "###-relationships-in-post-request", [typeof(ResourceObjectInPatchRequest<>)] = "###-in-patch-request", + [typeof(AttributesInPatchRequest<>)] = "###-attributes-in-patch-request", + [typeof(RelationshipsInPatchRequest<>)] = "###-relationships-in-patch-request", [typeof(ToOneRelationshipInRequest<>)] = "to-one-###-in-request", [typeof(NullableToOneRelationshipInRequest<>)] = "nullable-to-one-###-in-request", [typeof(ToManyRelationshipInRequest<>)] = "to-many-###-in-request", @@ -31,16 +35,11 @@ internal sealed class JsonApiSchemaIdSelector [typeof(NullableToOneRelationshipInResponse<>)] = "nullable-to-one-###-in-response", [typeof(ToManyRelationshipInResponse<>)] = "to-many-###-in-response", [typeof(ResourceObjectInResponse<>)] = "###-in-response", + [typeof(AttributesInResponse<>)] = "###-attributes-in-response", + [typeof(RelationshipsInResponse<>)] = "###-relationships-in-response", [typeof(ResourceIdentifierObject<>)] = "###-identifier" }; - private readonly Type[] _resourceObjectOpenTypes = - { - typeof(ResourceObjectInPostRequest<>), - typeof(ResourceObjectInPatchRequest<>), - typeof(ResourceObjectInResponse<>) - }; - private readonly ResourceNameFormatter _formatter; private readonly IResourceGraph _resourceGraph; @@ -76,25 +75,5 @@ public string GetSchemaId(Type type) // Used for a fixed set of types, such as jsonapi-object, links-in-many-resource-document etc. return _formatter.FormatResourceName(type).Singularize(); } - - public string GetSchemaId(Type resourceObjectType, ResourceObjectFieldType fieldType) - { - ArgumentGuard.NotNull(resourceObjectType, nameof(resourceObjectType)); - - if (!resourceObjectType.IsConstructedGenericType || !_resourceObjectOpenTypes.Contains(resourceObjectType.GetGenericTypeDefinition())) - { - throw new InvalidOperationException($"Type '{resourceObjectType.Name}' must be a resource object."); - } - - Type resourceClrType = resourceObjectType.GetGenericArguments().First(); - string resourceName = _formatter.FormatResourceName(resourceClrType).Singularize(); - string template = OpenTypeToSchemaTemplateMap[resourceObjectType.GetGenericTypeDefinition()]; - - string fieldObjectName = fieldType == ResourceObjectFieldType.Attributes - ? JsonApiObjectPropertyName.AttributesObject - : JsonApiObjectPropertyName.RelationshipsObject; - - return template.Replace("###", $"{resourceName}-{fieldObjectName}"); - } } } diff --git a/src/JsonApiDotNetCore.OpenApi/ResourceObjectFieldType.cs b/src/JsonApiDotNetCore.OpenApi/ResourceObjectFieldType.cs deleted file mode 100644 index 3ddb18540b..0000000000 --- a/src/JsonApiDotNetCore.OpenApi/ResourceObjectFieldType.cs +++ /dev/null @@ -1,8 +0,0 @@ -namespace JsonApiDotNetCore.OpenApi -{ - internal enum ResourceObjectFieldType - { - Attributes, - Relationships - } -} diff --git a/src/JsonApiDotNetCore.OpenApi/SwaggerComponents/ResourceFieldObjectSchemaBuilder.cs b/src/JsonApiDotNetCore.OpenApi/SwaggerComponents/ResourceFieldObjectSchemaBuilder.cs index b4722cb2eb..620409d5ab 100644 --- a/src/JsonApiDotNetCore.OpenApi/SwaggerComponents/ResourceFieldObjectSchemaBuilder.cs +++ b/src/JsonApiDotNetCore.OpenApi/SwaggerComponents/ResourceFieldObjectSchemaBuilder.cs @@ -26,24 +26,21 @@ internal sealed class ResourceFieldObjectSchemaBuilder private readonly ResourceTypeInfo _resourceTypeInfo; private readonly ISchemaRepositoryAccessor _schemaRepositoryAccessor; private readonly SchemaGenerator _defaultSchemaGenerator; - private readonly JsonApiSchemaIdSelector _jsonApiSchemaIdSelector; private readonly ResourceTypeSchemaGenerator _resourceTypeSchemaGenerator; private readonly NullableReferenceSchemaGenerator _nullableReferenceSchemaGenerator; private readonly IDictionary _schemasForResourceFields; public ResourceFieldObjectSchemaBuilder(ResourceTypeInfo resourceTypeInfo, ISchemaRepositoryAccessor schemaRepositoryAccessor, - SchemaGenerator defaultSchemaGenerator, JsonApiSchemaIdSelector jsonApiSchemaIdSelector, ResourceTypeSchemaGenerator resourceTypeSchemaGenerator) + SchemaGenerator defaultSchemaGenerator, ResourceTypeSchemaGenerator resourceTypeSchemaGenerator) { ArgumentGuard.NotNull(resourceTypeInfo, nameof(resourceTypeInfo)); ArgumentGuard.NotNull(schemaRepositoryAccessor, nameof(schemaRepositoryAccessor)); ArgumentGuard.NotNull(defaultSchemaGenerator, nameof(defaultSchemaGenerator)); - ArgumentGuard.NotNull(jsonApiSchemaIdSelector, nameof(jsonApiSchemaIdSelector)); ArgumentGuard.NotNull(resourceTypeSchemaGenerator, nameof(resourceTypeSchemaGenerator)); _resourceTypeInfo = resourceTypeInfo; _schemaRepositoryAccessor = schemaRepositoryAccessor; _defaultSchemaGenerator = defaultSchemaGenerator; - _jsonApiSchemaIdSelector = jsonApiSchemaIdSelector; _resourceTypeSchemaGenerator = resourceTypeSchemaGenerator; _nullableReferenceSchemaGenerator = new NullableReferenceSchemaGenerator(schemaRepositoryAccessor); @@ -61,26 +58,7 @@ private IDictionary GetFieldSchemas() return fullSchemaForResource.Properties; } - public OpenApiSchema? BuildAttributesObject(OpenApiSchema fullSchemaForResourceObject) - { - ArgumentGuard.NotNull(fullSchemaForResourceObject, nameof(fullSchemaForResourceObject)); - - OpenApiSchema fullSchemaForAttributesObject = fullSchemaForResourceObject.Properties[JsonApiObjectPropertyName.AttributesObject]; - - SetMembersOfAttributesObject(fullSchemaForAttributesObject); - - if (!fullSchemaForAttributesObject.Properties.Any()) - { - return null; - } - - fullSchemaForAttributesObject.AdditionalPropertiesAllowed = false; - - string fieldObjectSchemaId = _jsonApiSchemaIdSelector.GetSchemaId(_resourceTypeInfo.ResourceObjectType, ResourceObjectFieldType.Attributes); - return _schemaRepositoryAccessor.Current.AddDefinition(fieldObjectSchemaId, fullSchemaForAttributesObject); - } - - private void SetMembersOfAttributesObject(OpenApiSchema fullSchemaForAttributesObject) + public void SetMembersOfAttributesObject(OpenApiSchema fullSchemaForAttributesObject) { AttrCapabilities requiredCapability = GetRequiredCapabilityForAttributes(_resourceTypeInfo.ResourceObjectOpenType); @@ -145,26 +123,7 @@ private bool IsFieldRequired(ResourceFieldAttribute field) }; } - public OpenApiSchema? BuildRelationshipsObject(OpenApiSchema fullSchemaForResourceObject) - { - ArgumentGuard.NotNull(fullSchemaForResourceObject, nameof(fullSchemaForResourceObject)); - - OpenApiSchema fullSchemaForRelationshipsObject = fullSchemaForResourceObject.Properties[JsonApiObjectPropertyName.RelationshipsObject]; - - SetMembersOfRelationshipsObject(fullSchemaForRelationshipsObject); - - if (!fullSchemaForRelationshipsObject.Properties.Any()) - { - return null; - } - - fullSchemaForRelationshipsObject.AdditionalPropertiesAllowed = false; - - string fieldObjectSchemaId = _jsonApiSchemaIdSelector.GetSchemaId(_resourceTypeInfo.ResourceObjectType, ResourceObjectFieldType.Relationships); - return _schemaRepositoryAccessor.Current.AddDefinition(fieldObjectSchemaId, fullSchemaForRelationshipsObject); - } - - private void SetMembersOfRelationshipsObject(OpenApiSchema fullSchemaForRelationshipsObject) + public void SetMembersOfRelationshipsObject(OpenApiSchema fullSchemaForRelationshipsObject) { foreach (string fieldName in _schemasForResourceFields.Keys) { diff --git a/src/JsonApiDotNetCore.OpenApi/SwaggerComponents/ResourceObjectSchemaGenerator.cs b/src/JsonApiDotNetCore.OpenApi/SwaggerComponents/ResourceObjectSchemaGenerator.cs index 4ea23c1450..1db417f7e5 100644 --- a/src/JsonApiDotNetCore.OpenApi/SwaggerComponents/ResourceObjectSchemaGenerator.cs +++ b/src/JsonApiDotNetCore.OpenApi/SwaggerComponents/ResourceObjectSchemaGenerator.cs @@ -1,6 +1,6 @@ using System; using System.Collections.Generic; -using System.Text.Json; +using System.Linq; using JsonApiDotNetCore.Configuration; using JsonApiDotNetCore.OpenApi.JsonApiObjects.ResourceObjects; using Microsoft.OpenApi.Models; @@ -15,7 +15,7 @@ internal sealed class ResourceObjectSchemaGenerator private readonly ISchemaRepositoryAccessor _schemaRepositoryAccessor; private readonly ResourceTypeSchemaGenerator _resourceTypeSchemaGenerator; private readonly bool _allowClientGeneratedIds; - private readonly Func _createFieldObjectBuilderFactory; + private readonly Func _resourceFieldObjectSchemaBuilderFactory; public ResourceObjectSchemaGenerator(SchemaGenerator defaultSchemaGenerator, IResourceGraph resourceGraph, IJsonApiOptions options, ISchemaRepositoryAccessor schemaRepositoryAccessor) @@ -32,20 +32,8 @@ public ResourceObjectSchemaGenerator(SchemaGenerator defaultSchemaGenerator, IRe _resourceTypeSchemaGenerator = new ResourceTypeSchemaGenerator(schemaRepositoryAccessor, resourceGraph); _allowClientGeneratedIds = options.AllowClientGeneratedIds; - _createFieldObjectBuilderFactory = CreateFieldObjectBuilderFactory(defaultSchemaGenerator, resourceGraph, options, schemaRepositoryAccessor, - _resourceTypeSchemaGenerator); - } - - private static Func CreateFieldObjectBuilderFactory(SchemaGenerator defaultSchemaGenerator, - IResourceGraph resourceGraph, IJsonApiOptions options, ISchemaRepositoryAccessor schemaRepositoryAccessor, - ResourceTypeSchemaGenerator resourceTypeSchemaGenerator) - { - JsonNamingPolicy? namingPolicy = options.SerializerOptions.PropertyNamingPolicy; - ResourceNameFormatter resourceNameFormatter = new(namingPolicy); - var jsonApiSchemaIdSelector = new JsonApiSchemaIdSelector(resourceNameFormatter, resourceGraph); - - return resourceTypeInfo => new ResourceFieldObjectSchemaBuilder(resourceTypeInfo, schemaRepositoryAccessor, defaultSchemaGenerator, - jsonApiSchemaIdSelector, resourceTypeSchemaGenerator); + _resourceFieldObjectSchemaBuilderFactory = resourceTypeInfo => new ResourceFieldObjectSchemaBuilder(resourceTypeInfo, schemaRepositoryAccessor, + defaultSchemaGenerator, _resourceTypeSchemaGenerator); } public OpenApiSchema GenerateSchema(Type resourceObjectType) @@ -55,7 +43,7 @@ public OpenApiSchema GenerateSchema(Type resourceObjectType) (OpenApiSchema fullSchemaForResourceObject, OpenApiSchema referenceSchemaForResourceObject) = EnsureSchemasExist(resourceObjectType); var resourceTypeInfo = ResourceTypeInfo.Create(resourceObjectType, _resourceGraph); - ResourceFieldObjectSchemaBuilder fieldObjectBuilder = _createFieldObjectBuilderFactory(resourceTypeInfo); + ResourceFieldObjectSchemaBuilder fieldObjectBuilder = _resourceFieldObjectSchemaBuilderFactory(resourceTypeInfo); RemoveResourceIdIfPostResourceObject(resourceTypeInfo.ResourceObjectOpenType, fullSchemaForResourceObject); @@ -104,31 +92,39 @@ private void SetResourceType(OpenApiSchema fullSchemaForResourceObject, Type res fullSchemaForResourceObject.Properties[JsonApiObjectPropertyName.Type] = _resourceTypeSchemaGenerator.Get(resourceType); } - private static void SetResourceAttributes(OpenApiSchema fullSchemaForResourceObject, ResourceFieldObjectSchemaBuilder builder) + private void SetResourceAttributes(OpenApiSchema fullSchemaForResourceObject, ResourceFieldObjectSchemaBuilder builder) { - OpenApiSchema? fullSchemaForAttributesObject = builder.BuildAttributesObject(fullSchemaForResourceObject); + OpenApiSchema referenceSchemaForAttributesObject = fullSchemaForResourceObject.Properties[JsonApiObjectPropertyName.AttributesObject]; + OpenApiSchema fullSchemaForAttributesObject = _schemaRepositoryAccessor.Current.Schemas[referenceSchemaForAttributesObject.Reference.Id]; + + builder.SetMembersOfAttributesObject(fullSchemaForAttributesObject); - if (fullSchemaForAttributesObject != null) + if (!fullSchemaForAttributesObject.Properties.Any()) { - fullSchemaForResourceObject.Properties[JsonApiObjectPropertyName.AttributesObject] = fullSchemaForAttributesObject; + fullSchemaForResourceObject.Properties.Remove(JsonApiObjectPropertyName.AttributesObject); + _schemaRepositoryAccessor.Current.Schemas.Remove(referenceSchemaForAttributesObject.Reference.Id); } else { - fullSchemaForResourceObject.Properties.Remove(JsonApiObjectPropertyName.AttributesObject); + fullSchemaForAttributesObject.AdditionalPropertiesAllowed = false; } } - private static void SetResourceRelationships(OpenApiSchema fullSchemaForResourceObject, ResourceFieldObjectSchemaBuilder builder) + private void SetResourceRelationships(OpenApiSchema fullSchemaForResourceObject, ResourceFieldObjectSchemaBuilder builder) { - OpenApiSchema? fullSchemaForRelationshipsObject = builder.BuildRelationshipsObject(fullSchemaForResourceObject); + OpenApiSchema referenceSchemaForRelationshipsObject = fullSchemaForResourceObject.Properties[JsonApiObjectPropertyName.RelationshipsObject]; + OpenApiSchema fullSchemaForRelationshipsObject = _schemaRepositoryAccessor.Current.Schemas[referenceSchemaForRelationshipsObject.Reference.Id]; + + builder.SetMembersOfRelationshipsObject(fullSchemaForRelationshipsObject); - if (fullSchemaForRelationshipsObject != null) + if (!fullSchemaForRelationshipsObject.Properties.Any()) { - fullSchemaForResourceObject.Properties[JsonApiObjectPropertyName.RelationshipsObject] = fullSchemaForRelationshipsObject; + fullSchemaForResourceObject.Properties.Remove(JsonApiObjectPropertyName.RelationshipsObject); + _schemaRepositoryAccessor.Current.Schemas.Remove(referenceSchemaForRelationshipsObject.Reference.Id); } else { - fullSchemaForResourceObject.Properties.Remove(JsonApiObjectPropertyName.RelationshipsObject); + fullSchemaForRelationshipsObject.AdditionalPropertiesAllowed = false; } } diff --git a/src/JsonApiDotNetCore.OpenApi/SwaggerComponents/ResourceTypeInfo.cs b/src/JsonApiDotNetCore.OpenApi/SwaggerComponents/ResourceTypeInfo.cs index ff7cc34d5e..4bef12a5bb 100644 --- a/src/JsonApiDotNetCore.OpenApi/SwaggerComponents/ResourceTypeInfo.cs +++ b/src/JsonApiDotNetCore.OpenApi/SwaggerComponents/ResourceTypeInfo.cs @@ -5,13 +5,11 @@ namespace JsonApiDotNetCore.OpenApi.SwaggerComponents { internal sealed class ResourceTypeInfo { - public Type ResourceObjectType { get; } public Type ResourceObjectOpenType { get; } public ResourceType ResourceType { get; } - private ResourceTypeInfo(Type resourceObjectType, Type resourceObjectOpenType, ResourceType resourceType) + private ResourceTypeInfo(Type resourceObjectOpenType, ResourceType resourceType) { - ResourceObjectType = resourceObjectType; ResourceObjectOpenType = resourceObjectOpenType; ResourceType = resourceType; } @@ -25,7 +23,7 @@ public static ResourceTypeInfo Create(Type resourceObjectType, IResourceGraph re Type resourceClrType = resourceObjectType.GenericTypeArguments[0]; ResourceType resourceType = resourceGraph.GetResourceType(resourceClrType); - return new ResourceTypeInfo(resourceObjectType, resourceObjectOpenType, resourceType); + return new ResourceTypeInfo(resourceObjectOpenType, resourceType); } } } From d877f7d907cb3336b47d84000eb8176c004b6ec2 Mon Sep 17 00:00:00 2001 From: maurei Date: Tue, 30 Nov 2021 12:59:21 +0100 Subject: [PATCH 5/5] Reintroduced 'data' in schema names of resource objects. --- .../JsonApiSchemaIdSelector.cs | 6 +- ...lientAttributeRegistrationLifeTimeTests.cs | 26 +- .../LegacyClient/RequestTests.cs | 6 +- .../LegacyClient/ResponseTests.cs | 8 +- .../LegacyOpenApiIntegration/swagger.json | 296 +++++++++--------- 5 files changed, 171 insertions(+), 171 deletions(-) diff --git a/src/JsonApiDotNetCore.OpenApi/JsonApiSchemaIdSelector.cs b/src/JsonApiDotNetCore.OpenApi/JsonApiSchemaIdSelector.cs index a607fead36..a4c9f5575d 100644 --- a/src/JsonApiDotNetCore.OpenApi/JsonApiSchemaIdSelector.cs +++ b/src/JsonApiDotNetCore.OpenApi/JsonApiSchemaIdSelector.cs @@ -15,10 +15,10 @@ internal sealed class JsonApiSchemaIdSelector { [typeof(ResourcePostRequestDocument<>)] = "###-post-request-document", [typeof(ResourcePatchRequestDocument<>)] = "###-patch-request-document", - [typeof(ResourceObjectInPostRequest<>)] = "###-in-post-request", + [typeof(ResourceObjectInPostRequest<>)] = "###-data-in-post-request", [typeof(AttributesInPostRequest<>)] = "###-attributes-in-post-request", [typeof(RelationshipsInPostRequest<>)] = "###-relationships-in-post-request", - [typeof(ResourceObjectInPatchRequest<>)] = "###-in-patch-request", + [typeof(ResourceObjectInPatchRequest<>)] = "###-data-in-patch-request", [typeof(AttributesInPatchRequest<>)] = "###-attributes-in-patch-request", [typeof(RelationshipsInPatchRequest<>)] = "###-relationships-in-patch-request", [typeof(ToOneRelationshipInRequest<>)] = "to-one-###-in-request", @@ -34,7 +34,7 @@ internal sealed class JsonApiSchemaIdSelector [typeof(ToOneRelationshipInResponse<>)] = "to-one-###-in-response", [typeof(NullableToOneRelationshipInResponse<>)] = "nullable-to-one-###-in-response", [typeof(ToManyRelationshipInResponse<>)] = "to-many-###-in-response", - [typeof(ResourceObjectInResponse<>)] = "###-in-response", + [typeof(ResourceObjectInResponse<>)] = "###-data-in-response", [typeof(AttributesInResponse<>)] = "###-attributes-in-response", [typeof(RelationshipsInResponse<>)] = "###-relationships-in-response", [typeof(ResourceIdentifierObject<>)] = "###-identifier" diff --git a/test/OpenApiClientTests/LegacyClient/ClientAttributeRegistrationLifeTimeTests.cs b/test/OpenApiClientTests/LegacyClient/ClientAttributeRegistrationLifeTimeTests.cs index ff32763a81..f9e48c5da0 100644 --- a/test/OpenApiClientTests/LegacyClient/ClientAttributeRegistrationLifeTimeTests.cs +++ b/test/OpenApiClientTests/LegacyClient/ClientAttributeRegistrationLifeTimeTests.cs @@ -20,7 +20,7 @@ public async Task Disposed_attribute_registration_for_document_does_not_affect_r var requestDocument = new AirplanePatchRequestDocument { - Data = new AirplaneInPatchRequest + Data = new AirplaneDataInPatchRequest { Id = airplaneId, Type = AirplanesResourceType.Airplanes, @@ -62,7 +62,7 @@ public async Task Attribute_registration_can_be_used_for_multiple_requests() var requestDocument = new AirplanePatchRequestDocument { - Data = new AirplaneInPatchRequest + Data = new AirplaneDataInPatchRequest { Id = airplaneId, Type = AirplanesResourceType.Airplanes, @@ -109,7 +109,7 @@ public async Task Request_is_unaffected_by_attribute_registration_for_different_ var requestDocument1 = new AirplanePatchRequestDocument { - Data = new AirplaneInPatchRequest + Data = new AirplaneDataInPatchRequest { Id = airplaneId1, Type = AirplanesResourceType.Airplanes, @@ -121,7 +121,7 @@ public async Task Request_is_unaffected_by_attribute_registration_for_different_ var requestDocument2 = new AirplanePatchRequestDocument { - Data = new AirplaneInPatchRequest + Data = new AirplaneDataInPatchRequest { Id = airplaneId2, Type = AirplanesResourceType.Airplanes, @@ -164,7 +164,7 @@ public async Task Attribute_values_can_be_changed_after_attribute_registration() var requestDocument = new AirplanePatchRequestDocument { - Data = new AirplaneInPatchRequest + Data = new AirplaneDataInPatchRequest { Id = airplaneId, Type = AirplanesResourceType.Airplanes, @@ -207,7 +207,7 @@ public async Task Attribute_registration_is_unaffected_by_successive_attribute_r var requestDocument1 = new AirplanePatchRequestDocument { - Data = new AirplaneInPatchRequest + Data = new AirplaneDataInPatchRequest { Id = airplaneId1, Type = AirplanesResourceType.Airplanes, @@ -217,7 +217,7 @@ public async Task Attribute_registration_is_unaffected_by_successive_attribute_r var requestDocument2 = new AirplanePostRequestDocument { - Data = new AirplaneInPostRequest + Data = new AirplaneDataInPostRequest { Type = AirplanesResourceType.Airplanes, Attributes = new AirplaneAttributesInPostRequest() @@ -258,7 +258,7 @@ public async Task Attribute_registration_is_unaffected_by_preceding_disposed_att var requestDocument1 = new AirplanePatchRequestDocument { - Data = new AirplaneInPatchRequest + Data = new AirplaneDataInPatchRequest { Id = airplaneId1, Type = AirplanesResourceType.Airplanes, @@ -276,7 +276,7 @@ public async Task Attribute_registration_is_unaffected_by_preceding_disposed_att var requestDocument2 = new AirplanePatchRequestDocument { - Data = new AirplaneInPatchRequest + Data = new AirplaneDataInPatchRequest { Id = airplaneId2, Type = AirplanesResourceType.Airplanes, @@ -318,7 +318,7 @@ public async Task Attribute_registration_is_unaffected_by_preceding_disposed_att var requestDocument1 = new AirplanePostRequestDocument { - Data = new AirplaneInPostRequest + Data = new AirplaneDataInPostRequest { Type = AirplanesResourceType.Airplanes, Attributes = new AirplaneAttributesInPostRequest() @@ -335,7 +335,7 @@ public async Task Attribute_registration_is_unaffected_by_preceding_disposed_att var requestDocument2 = new AirplanePatchRequestDocument { - Data = new AirplaneInPatchRequest + Data = new AirplaneDataInPatchRequest { Id = airplaneId, Type = AirplanesResourceType.Airplanes, @@ -379,7 +379,7 @@ public async Task Attribute_registration_is_unaffected_by_preceding_attribute_re var requestDocument1 = new AirplanePatchRequestDocument { - Data = new AirplaneInPatchRequest + Data = new AirplaneDataInPatchRequest { Id = airplaneId1, Type = AirplanesResourceType.Airplanes, @@ -391,7 +391,7 @@ public async Task Attribute_registration_is_unaffected_by_preceding_attribute_re var requestDocument2 = new AirplanePatchRequestDocument { - Data = new AirplaneInPatchRequest + Data = new AirplaneDataInPatchRequest { Id = airplaneId2, Type = AirplanesResourceType.Airplanes, diff --git a/test/OpenApiClientTests/LegacyClient/RequestTests.cs b/test/OpenApiClientTests/LegacyClient/RequestTests.cs index cf7848d1a5..f5a0244525 100644 --- a/test/OpenApiClientTests/LegacyClient/RequestTests.cs +++ b/test/OpenApiClientTests/LegacyClient/RequestTests.cs @@ -64,7 +64,7 @@ public async Task Partial_posting_resource_with_selected_relationships_produces_ var requestDocument = new FlightPostRequestDocument { - Data = new FlightInPostRequest + Data = new FlightDataInPostRequest { Type = FlightsResourceType.Flights, Relationships = new FlightRelationshipsInPostRequest @@ -144,7 +144,7 @@ public async Task Partial_posting_resource_produces_expected_request() var requestDocument = new AirplanePostRequestDocument { - Data = new AirplaneInPostRequest + Data = new AirplaneDataInPostRequest { Type = AirplanesResourceType.Airplanes, Attributes = new AirplaneAttributesInPostRequest @@ -195,7 +195,7 @@ public async Task Partial_patching_resource_produces_expected_request() var requestDocument = new AirplanePatchRequestDocument { - Data = new AirplaneInPatchRequest + Data = new AirplaneDataInPatchRequest { Id = airplaneId, Type = AirplanesResourceType.Airplanes, diff --git a/test/OpenApiClientTests/LegacyClient/ResponseTests.cs b/test/OpenApiClientTests/LegacyClient/ResponseTests.cs index 38efbd9fef..1b6b00faf6 100644 --- a/test/OpenApiClientTests/LegacyClient/ResponseTests.cs +++ b/test/OpenApiClientTests/LegacyClient/ResponseTests.cs @@ -110,7 +110,7 @@ public async Task Getting_resource_collection_translates_response() document.Links.Last.Should().Be(topLevelLink); document.Data.Should().HaveCount(1); - FlightInResponse flight = document.Data.First(); + FlightDataInResponse flight = document.Data.First(); flight.Id.Should().Be(flightId); flight.Type.Should().Be(FlightsResourceType.Flights); flight.Links.Self.Should().Be(flightResourceLink); @@ -278,7 +278,7 @@ public async Task Posting_resource_translates_response() // Act FlightPrimaryResponseDocument document = await apiClient.PostFlightAsync(new FlightPostRequestDocument { - Data = new FlightInPostRequest + Data = new FlightDataInPostRequest { Type = FlightsResourceType.Flights, Relationships = new FlightRelationshipsInPostRequest @@ -330,7 +330,7 @@ public async Task Patching_resource_with_side_effects_translates_response() // Act FlightPrimaryResponseDocument document = await apiClient.PatchFlightAsync(flightId, new FlightPatchRequestDocument { - Data = new FlightInPatchRequest + Data = new FlightDataInPatchRequest { Id = flightId, Type = FlightsResourceType.Flights @@ -355,7 +355,7 @@ public async Task Patching_resource_without_side_effects_translates_response() FlightPrimaryResponseDocument? document = await ApiResponse.TranslateAsync(async () => await apiClient.PatchFlightAsync(flightId, new FlightPatchRequestDocument { - Data = new FlightInPatchRequest + Data = new FlightDataInPatchRequest { Id = flightId, Type = FlightsResourceType.Flights diff --git a/test/OpenApiTests/LegacyOpenApiIntegration/swagger.json b/test/OpenApiTests/LegacyOpenApiIntegration/swagger.json index eba42ef0d0..ac62204a53 100644 --- a/test/OpenApiTests/LegacyOpenApiIntegration/swagger.json +++ b/test/OpenApiTests/LegacyOpenApiIntegration/swagger.json @@ -2019,7 +2019,7 @@ "data": { "type": "array", "items": { - "$ref": "#/components/schemas/airplane-in-response" + "$ref": "#/components/schemas/airplane-data-in-response" } }, "meta": { @@ -2035,7 +2035,7 @@ }, "additionalProperties": false }, - "airplane-in-patch-request": { + "airplane-data-in-patch-request": { "required": [ "id", "type" @@ -2057,7 +2057,7 @@ }, "additionalProperties": false }, - "airplane-in-post-request": { + "airplane-data-in-post-request": { "required": [ "type" ], @@ -2075,7 +2075,7 @@ }, "additionalProperties": false }, - "airplane-in-response": { + "airplane-data-in-response": { "required": [ "id", "links", @@ -2112,7 +2112,7 @@ "type": "object", "properties": { "data": { - "$ref": "#/components/schemas/airplane-in-patch-request" + "$ref": "#/components/schemas/airplane-data-in-patch-request" } }, "additionalProperties": false @@ -2124,7 +2124,7 @@ "type": "object", "properties": { "data": { - "$ref": "#/components/schemas/airplane-in-post-request" + "$ref": "#/components/schemas/airplane-data-in-post-request" } }, "additionalProperties": false @@ -2137,7 +2137,7 @@ "type": "object", "properties": { "data": { - "$ref": "#/components/schemas/airplane-in-response" + "$ref": "#/components/schemas/airplane-data-in-response" }, "meta": { "type": "object", @@ -2267,7 +2267,7 @@ "data": { "type": "array", "items": { - "$ref": "#/components/schemas/flight-attendant-in-response" + "$ref": "#/components/schemas/flight-attendant-data-in-response" } }, "meta": { @@ -2283,7 +2283,7 @@ }, "additionalProperties": false }, - "flight-attendant-identifier": { + "flight-attendant-data-in-patch-request": { "required": [ "id", "type" @@ -2295,62 +2295,38 @@ }, "id": { "type": "string" - } - }, - "additionalProperties": false - }, - "flight-attendant-identifier-collection-response-document": { - "required": [ - "data", - "links" - ], - "type": "object", - "properties": { - "data": { - "type": "array", - "items": { - "$ref": "#/components/schemas/flight-attendant-identifier" - } - }, - "meta": { - "type": "object", - "additionalProperties": {} }, - "jsonapi": { - "$ref": "#/components/schemas/jsonapi-object" + "attributes": { + "$ref": "#/components/schemas/flight-attendant-attributes-in-patch-request" }, - "links": { - "$ref": "#/components/schemas/links-in-resource-identifier-collection-document" + "relationships": { + "$ref": "#/components/schemas/flight-attendant-relationships-in-patch-request" } }, "additionalProperties": false }, - "flight-attendant-identifier-response-document": { + "flight-attendant-data-in-post-request": { "required": [ - "data", - "links" + "type" ], "type": "object", "properties": { - "data": { - "$ref": "#/components/schemas/flight-attendant-identifier" - }, - "meta": { - "type": "object", - "additionalProperties": {} + "type": { + "$ref": "#/components/schemas/flight-attendants-resource-type" }, - "jsonapi": { - "$ref": "#/components/schemas/jsonapi-object" + "attributes": { + "$ref": "#/components/schemas/flight-attendant-attributes-in-post-request" }, - "links": { - "$ref": "#/components/schemas/links-in-resource-identifier-document" + "relationships": { + "$ref": "#/components/schemas/flight-attendant-relationships-in-post-request" } }, "additionalProperties": false }, - "flight-attendant-in-patch-request": { + "flight-attendant-data-in-response": { "required": [ "id", + "links", "type" ], "type": "object", @@ -2362,16 +2338,24 @@ "type": "string" }, "attributes": { - "$ref": "#/components/schemas/flight-attendant-attributes-in-patch-request" + "$ref": "#/components/schemas/flight-attendant-attributes-in-response" }, "relationships": { - "$ref": "#/components/schemas/flight-attendant-relationships-in-patch-request" + "$ref": "#/components/schemas/flight-attendant-relationships-in-response" + }, + "links": { + "$ref": "#/components/schemas/links-in-resource-object" + }, + "meta": { + "type": "object", + "additionalProperties": {} } }, "additionalProperties": false }, - "flight-attendant-in-post-request": { + "flight-attendant-identifier": { "required": [ + "id", "type" ], "type": "object", @@ -2379,41 +2363,57 @@ "type": { "$ref": "#/components/schemas/flight-attendants-resource-type" }, - "attributes": { - "$ref": "#/components/schemas/flight-attendant-attributes-in-post-request" - }, - "relationships": { - "$ref": "#/components/schemas/flight-attendant-relationships-in-post-request" + "id": { + "type": "string" } }, "additionalProperties": false }, - "flight-attendant-in-response": { + "flight-attendant-identifier-collection-response-document": { "required": [ - "id", - "links", - "type" + "data", + "links" ], "type": "object", "properties": { - "type": { - "$ref": "#/components/schemas/flight-attendants-resource-type" - }, - "id": { - "type": "string" + "data": { + "type": "array", + "items": { + "$ref": "#/components/schemas/flight-attendant-identifier" + } }, - "attributes": { - "$ref": "#/components/schemas/flight-attendant-attributes-in-response" + "meta": { + "type": "object", + "additionalProperties": {} }, - "relationships": { - "$ref": "#/components/schemas/flight-attendant-relationships-in-response" + "jsonapi": { + "$ref": "#/components/schemas/jsonapi-object" }, "links": { - "$ref": "#/components/schemas/links-in-resource-object" + "$ref": "#/components/schemas/links-in-resource-identifier-collection-document" + } + }, + "additionalProperties": false + }, + "flight-attendant-identifier-response-document": { + "required": [ + "data", + "links" + ], + "type": "object", + "properties": { + "data": { + "$ref": "#/components/schemas/flight-attendant-identifier" }, "meta": { "type": "object", "additionalProperties": {} + }, + "jsonapi": { + "$ref": "#/components/schemas/jsonapi-object" + }, + "links": { + "$ref": "#/components/schemas/links-in-resource-identifier-document" } }, "additionalProperties": false @@ -2425,7 +2425,7 @@ "type": "object", "properties": { "data": { - "$ref": "#/components/schemas/flight-attendant-in-patch-request" + "$ref": "#/components/schemas/flight-attendant-data-in-patch-request" } }, "additionalProperties": false @@ -2437,7 +2437,7 @@ "type": "object", "properties": { "data": { - "$ref": "#/components/schemas/flight-attendant-in-post-request" + "$ref": "#/components/schemas/flight-attendant-data-in-post-request" } }, "additionalProperties": false @@ -2450,7 +2450,7 @@ "type": "object", "properties": { "data": { - "$ref": "#/components/schemas/flight-attendant-in-response" + "$ref": "#/components/schemas/flight-attendant-data-in-response" }, "meta": { "type": "object", @@ -2509,7 +2509,7 @@ "type": "object", "properties": { "data": { - "$ref": "#/components/schemas/flight-attendant-in-response" + "$ref": "#/components/schemas/flight-attendant-data-in-response" }, "meta": { "type": "object", @@ -2592,7 +2592,7 @@ "data": { "type": "array", "items": { - "$ref": "#/components/schemas/flight-in-response" + "$ref": "#/components/schemas/flight-data-in-response" } }, "meta": { @@ -2608,7 +2608,7 @@ }, "additionalProperties": false }, - "flight-identifier": { + "flight-data-in-patch-request": { "required": [ "id", "type" @@ -2620,39 +2620,35 @@ }, "id": { "type": "string" + }, + "attributes": { + "$ref": "#/components/schemas/flight-attributes-in-patch-request" + }, + "relationships": { + "$ref": "#/components/schemas/flight-relationships-in-patch-request" } }, "additionalProperties": false }, - "flight-identifier-collection-response-document": { + "flight-data-in-post-request": { "required": [ - "data", - "links" + "type" ], "type": "object", "properties": { - "data": { - "type": "array", - "items": { - "$ref": "#/components/schemas/flight-identifier" - } - }, - "meta": { - "type": "object", - "additionalProperties": {} - }, - "jsonapi": { - "$ref": "#/components/schemas/jsonapi-object" + "type": { + "$ref": "#/components/schemas/flights-resource-type" }, - "links": { - "$ref": "#/components/schemas/links-in-resource-identifier-collection-document" + "relationships": { + "$ref": "#/components/schemas/flight-relationships-in-post-request" } }, "additionalProperties": false }, - "flight-in-patch-request": { + "flight-data-in-response": { "required": [ "id", + "links", "type" ], "type": "object", @@ -2664,16 +2660,24 @@ "type": "string" }, "attributes": { - "$ref": "#/components/schemas/flight-attributes-in-patch-request" + "$ref": "#/components/schemas/flight-attributes-in-response" }, "relationships": { - "$ref": "#/components/schemas/flight-relationships-in-patch-request" + "$ref": "#/components/schemas/flight-relationships-in-response" + }, + "links": { + "$ref": "#/components/schemas/links-in-resource-object" + }, + "meta": { + "type": "object", + "additionalProperties": {} } }, "additionalProperties": false }, - "flight-in-post-request": { + "flight-identifier": { "required": [ + "id", "type" ], "type": "object", @@ -2681,38 +2685,34 @@ "type": { "$ref": "#/components/schemas/flights-resource-type" }, - "relationships": { - "$ref": "#/components/schemas/flight-relationships-in-post-request" + "id": { + "type": "string" } }, "additionalProperties": false }, - "flight-in-response": { + "flight-identifier-collection-response-document": { "required": [ - "id", - "links", - "type" + "data", + "links" ], "type": "object", "properties": { - "type": { - "$ref": "#/components/schemas/flights-resource-type" - }, - "id": { - "type": "string" - }, - "attributes": { - "$ref": "#/components/schemas/flight-attributes-in-response" - }, - "relationships": { - "$ref": "#/components/schemas/flight-relationships-in-response" - }, - "links": { - "$ref": "#/components/schemas/links-in-resource-object" + "data": { + "type": "array", + "items": { + "$ref": "#/components/schemas/flight-identifier" + } }, "meta": { "type": "object", "additionalProperties": {} + }, + "jsonapi": { + "$ref": "#/components/schemas/jsonapi-object" + }, + "links": { + "$ref": "#/components/schemas/links-in-resource-identifier-collection-document" } }, "additionalProperties": false @@ -2724,7 +2724,7 @@ "type": "object", "properties": { "data": { - "$ref": "#/components/schemas/flight-in-patch-request" + "$ref": "#/components/schemas/flight-data-in-patch-request" } }, "additionalProperties": false @@ -2736,7 +2736,7 @@ "type": "object", "properties": { "data": { - "$ref": "#/components/schemas/flight-in-post-request" + "$ref": "#/components/schemas/flight-data-in-post-request" } }, "additionalProperties": false @@ -2749,7 +2749,7 @@ "type": "object", "properties": { "data": { - "$ref": "#/components/schemas/flight-in-response" + "$ref": "#/components/schemas/flight-data-in-response" }, "meta": { "type": "object", @@ -3037,7 +3037,7 @@ "data": { "oneOf": [ { - "$ref": "#/components/schemas/flight-attendant-in-response" + "$ref": "#/components/schemas/flight-attendant-data-in-response" }, { "$ref": "#/components/schemas/null-value" @@ -3125,7 +3125,7 @@ "data": { "type": "array", "items": { - "$ref": "#/components/schemas/passenger-in-response" + "$ref": "#/components/schemas/passenger-data-in-response" } }, "meta": { @@ -3141,6 +3141,33 @@ }, "additionalProperties": false }, + "passenger-data-in-response": { + "required": [ + "id", + "links", + "type" + ], + "type": "object", + "properties": { + "type": { + "$ref": "#/components/schemas/passengers-resource-type" + }, + "id": { + "type": "string" + }, + "attributes": { + "$ref": "#/components/schemas/passenger-attributes-in-response" + }, + "links": { + "$ref": "#/components/schemas/links-in-resource-object" + }, + "meta": { + "type": "object", + "additionalProperties": {} + } + }, + "additionalProperties": false + }, "passenger-identifier": { "required": [ "id", @@ -3183,33 +3210,6 @@ }, "additionalProperties": false }, - "passenger-in-response": { - "required": [ - "id", - "links", - "type" - ], - "type": "object", - "properties": { - "type": { - "$ref": "#/components/schemas/passengers-resource-type" - }, - "id": { - "type": "string" - }, - "attributes": { - "$ref": "#/components/schemas/passenger-attributes-in-response" - }, - "links": { - "$ref": "#/components/schemas/links-in-resource-object" - }, - "meta": { - "type": "object", - "additionalProperties": {} - } - }, - "additionalProperties": false - }, "passengers-resource-type": { "enum": [ "passengers"