Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Update openapi branch #1105

Merged
merged 28 commits into from
Nov 23, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
fb0c5fc
Empty commit to republish docs from master branch
Oct 18, 2021
758a191
Redesign conversion between JSON objects and ASP.NET models (#1091)
Oct 27, 2021
4a2abe9
Remove short-hand interfaces for TId is int (#1093)
Oct 28, 2021
f0d638f
Nullable reference types (#1095)
Nov 3, 2021
edfcd8c
Abort build when install failed
Nov 3, 2021
1c2313a
Downgrade docfx due to published corrupt zip
Nov 3, 2021
4798144
Secondary paging (#1100)
Nov 4, 2021
b8f63e5
Add None enum member to flags
Nov 4, 2021
fb8913f
Merge master
maurei Nov 4, 2021
b88d39e
fix broken build
Nov 4, 2021
78a4e9d
Resource Graph validations (#1101)
Nov 8, 2021
40f6826
- Replaced ResourceContext with ResourceType and calls to ResourceTyp…
maurei Nov 8, 2021
ee9f2eb
removed JsonApiObjectNullabilityProcessor and enabled NRT support in …
maurei Nov 8, 2021
7b78e99
Remove unused members
maurei Nov 8, 2021
fb5102f
Merge branch 'master' into master-into-openapi
maurei Nov 8, 2021
67b39e7
Merge branch 'openapi' into master-into-openapi
maurei Nov 9, 2021
b7930de
Added authors element to NuGet package spec
Nov 9, 2021
1b01e52
Added .NET 6 support to roadmap
Nov 15, 2021
e07903c
Process review feedback
maurei Nov 16, 2021
8a6bfac
Fix code cleanup (#1107)
Nov 18, 2021
a1b0a7b
Process review feedback
maurei Nov 19, 2021
ae17e01
Various fixes and improvements (#1114)
Nov 22, 2021
15f5923
Fixed: swapped method names
Nov 22, 2021
a6e11be
- Renamed ExpansibleEndpointMetadata to NonPrimaryEndpointMetadata
maurei Nov 22, 2021
1bdb70a
Process review feedback
maurei Nov 22, 2021
17fed9b
Rephrase
maurei Nov 22, 2021
8694e6a
Merge branch 'master' into master-into-openapi
Nov 23, 2021
d50719b
Update version prefix after merge
Nov 23, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,12 @@ private static IEnumerable<ActionDescriptor> AddJsonApiMetadataToAction(ActionDe
UpdateBodyParameterDescriptor(endpoint, primaryMetadata.DocumentType);
return Array.Empty<ActionDescriptor>();
}
case ExpansibleEndpointMetadata expansibleMetadata and (RelationshipResponseMetadata or SecondaryResponseMetadata):
case NonPrimaryEndpointMetadata expansibleMetadata and (RelationshipResponseMetadata or SecondaryResponseMetadata):
bart-degreed marked this conversation as resolved.
Show resolved Hide resolved
{
return Expand(endpoint, expansibleMetadata,
(expandedEndpoint, documentType, _) => UpdateProducesResponseTypeAttribute(expandedEndpoint, documentType));
}
case ExpansibleEndpointMetadata expansibleMetadata and RelationshipRequestMetadata:
case NonPrimaryEndpointMetadata expansibleMetadata and RelationshipRequestMetadata:
{
return Expand(endpoint, expansibleMetadata, UpdateBodyParameterDescriptor);
}
Expand Down Expand Up @@ -118,7 +118,7 @@ private static bool ProducesJsonApiResponseDocument(ActionDescriptor endpoint)
return produces != null && produces.ContentTypes.Any(contentType => contentType == HeaderConstants.MediaType);
}

private static IEnumerable<ActionDescriptor> Expand(ActionDescriptor genericEndpoint, ExpansibleEndpointMetadata metadata,
private static IEnumerable<ActionDescriptor> Expand(ActionDescriptor genericEndpoint, NonPrimaryEndpointMetadata metadata,
Action<ActionDescriptor, Type, string> expansionCallback)
{
var expansion = new List<ActionDescriptor>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ internal sealed class JsonApiEndpointMetadataProvider
{
private readonly IControllerResourceMapping _controllerResourceMapping;
private readonly EndpointResolver _endpointResolver = new();
private readonly NonPrimaryDocumentTypeFactory _nonPrimaryDocumentTypeFactory = new();

public JsonApiEndpointMetadataProvider(IControllerResourceMapping controllerResourceMapping)
{
Expand Down Expand Up @@ -89,12 +88,13 @@ private static PrimaryRequestMetadata GetPatchRequestMetadata(Type resourceClrTy
return new PrimaryRequestMetadata(documentType);
}

private RelationshipRequestMetadata GetRelationshipRequestMetadata(IEnumerable<RelationshipAttribute> relationships, bool ignoreHasOneRelationships)
private static RelationshipRequestMetadata GetRelationshipRequestMetadata(IEnumerable<RelationshipAttribute> relationships,
bool ignoreHasOneRelationships)
{
IEnumerable<RelationshipAttribute> relationshipsOfEndpoint = ignoreHasOneRelationships ? relationships.OfType<HasManyAttribute>() : relationships;

IDictionary<string, Type> requestDocumentTypesByRelationshipName = relationshipsOfEndpoint.ToDictionary(relationship => relationship.PublicName,
_nonPrimaryDocumentTypeFactory.GetForRelationshipRequest);
NonPrimaryDocumentTypeFactory.Instance.GetForRelationshipRequest);

return new RelationshipRequestMetadata(requestDocumentTypesByRelationshipName);
}
Expand Down Expand Up @@ -133,18 +133,18 @@ private static PrimaryResponseMetadata GetPrimaryResponseMetadata(Type resourceC
return new PrimaryResponseMetadata(documentType);
}

private SecondaryResponseMetadata GetSecondaryResponseMetadata(IEnumerable<RelationshipAttribute> relationships)
private static SecondaryResponseMetadata GetSecondaryResponseMetadata(IEnumerable<RelationshipAttribute> relationships)
{
IDictionary<string, Type> responseDocumentTypesByRelationshipName = relationships.ToDictionary(relationship => relationship.PublicName,
_nonPrimaryDocumentTypeFactory.GetForSecondaryResponse);
NonPrimaryDocumentTypeFactory.Instance.GetForSecondaryResponse);

return new SecondaryResponseMetadata(responseDocumentTypesByRelationshipName);
}

private RelationshipResponseMetadata GetRelationshipResponseMetadata(IEnumerable<RelationshipAttribute> relationships)
private static RelationshipResponseMetadata GetRelationshipResponseMetadata(IEnumerable<RelationshipAttribute> relationships)
{
IDictionary<string, Type> responseDocumentTypesByRelationshipName = relationships.ToDictionary(relationship => relationship.PublicName,
_nonPrimaryDocumentTypeFactory.GetForRelationshipResponse);
NonPrimaryDocumentTypeFactory.Instance.GetForRelationshipResponse);

return new RelationshipResponseMetadata(responseDocumentTypesByRelationshipName);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@

namespace JsonApiDotNetCore.OpenApi.JsonApiMetadata
{
internal abstract class ExpansibleEndpointMetadata
internal abstract class NonPrimaryEndpointMetadata
{
public IDictionary<string, Type> DocumentTypesByRelationshipName { get; }

protected ExpansibleEndpointMetadata(IDictionary<string, Type> documentTypesByRelationshipName)
protected NonPrimaryEndpointMetadata(IDictionary<string, Type> documentTypesByRelationshipName)
{
ArgumentGuard.NotNull(documentTypesByRelationshipName, nameof(documentTypesByRelationshipName));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace JsonApiDotNetCore.OpenApi.JsonApiMetadata
{
internal sealed class RelationshipRequestMetadata : ExpansibleEndpointMetadata, IJsonApiRequestMetadata
internal sealed class RelationshipRequestMetadata : NonPrimaryEndpointMetadata, IJsonApiRequestMetadata
{
public RelationshipRequestMetadata(IDictionary<string, Type> documentTypesByRelationshipName)
: base(documentTypesByRelationshipName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace JsonApiDotNetCore.OpenApi.JsonApiMetadata
{
internal sealed class RelationshipResponseMetadata : ExpansibleEndpointMetadata, IJsonApiResponseMetadata
internal sealed class RelationshipResponseMetadata : NonPrimaryEndpointMetadata, IJsonApiResponseMetadata
{
public RelationshipResponseMetadata(IDictionary<string, Type> documentTypesByRelationshipName)
: base(documentTypesByRelationshipName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace JsonApiDotNetCore.OpenApi.JsonApiMetadata
{
internal sealed class SecondaryResponseMetadata : ExpansibleEndpointMetadata, IJsonApiResponseMetadata
internal sealed class SecondaryResponseMetadata : NonPrimaryEndpointMetadata, IJsonApiResponseMetadata
{
public SecondaryResponseMetadata(IDictionary<string, Type> documentTypesByRelationshipName)
: base(documentTypesByRelationshipName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,34 +7,40 @@ namespace JsonApiDotNetCore.OpenApi.JsonApiObjects
{
internal sealed class NonPrimaryDocumentTypeFactory
{
private readonly DocumentOpenTypeOptions _secondaryResponseDocumentTypeOptions = new(typeof(ResourceCollectionResponseDocument<>),
private static readonly DocumentOpenTypeOptions SecondaryResponseDocumentTypeOptions = new(typeof(ResourceCollectionResponseDocument<>),
typeof(NullableSecondaryResourceResponseDocument<>), typeof(SecondaryResourceResponseDocument<>));

private readonly DocumentOpenTypeOptions _relationshipRequestDocumentTypeOptions = new(typeof(ToManyRelationshipRequestData<>),
private static readonly DocumentOpenTypeOptions RelationshipRequestDocumentTypeOptions = new(typeof(ToManyRelationshipRequestData<>),
typeof(NullableToOneRelationshipRequestData<>), typeof(ToOneRelationshipRequestData<>));

private readonly DocumentOpenTypeOptions _relationshipResponseDocumentTypeOptions = new(typeof(ResourceIdentifierCollectionResponseDocument<>),
private static readonly DocumentOpenTypeOptions RelationshipResponseDocumentTypeOptions = new(typeof(ResourceIdentifierCollectionResponseDocument<>),
typeof(NullableResourceIdentifierResponseDocument<>), typeof(ResourceIdentifierResponseDocument<>));

public static NonPrimaryDocumentTypeFactory Instance { get; } = new();

private NonPrimaryDocumentTypeFactory()
{
}

public Type GetForSecondaryResponse(RelationshipAttribute relationship)
{
ArgumentGuard.NotNull(relationship, nameof(relationship));

return Get(relationship, _secondaryResponseDocumentTypeOptions);
return Get(relationship, SecondaryResponseDocumentTypeOptions);
}

public Type GetForRelationshipRequest(RelationshipAttribute relationship)
{
ArgumentGuard.NotNull(relationship, nameof(relationship));

return Get(relationship, _relationshipRequestDocumentTypeOptions);
return Get(relationship, RelationshipRequestDocumentTypeOptions);
}

public Type GetForRelationshipResponse(RelationshipAttribute relationship)
{
ArgumentGuard.NotNull(relationship, nameof(relationship));

return Get(relationship, _relationshipResponseDocumentTypeOptions);
return Get(relationship, RelationshipResponseDocumentTypeOptions);
}

private static Type Get(RelationshipAttribute relationship, DocumentOpenTypeOptions typeOptions)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,17 @@ namespace JsonApiDotNetCore.OpenApi.JsonApiObjects
{
internal sealed class RelationshipDataTypeFactory
{
private readonly NonPrimaryDocumentTypeFactory _nonPrimaryDocumentTypeFactory = new();
public static RelationshipDataTypeFactory Instance { get; } = new();

private RelationshipDataTypeFactory()
{
}

public Type GetForRequest(RelationshipAttribute relationship)
{
ArgumentGuard.NotNull(relationship, nameof(relationship));

return _nonPrimaryDocumentTypeFactory.GetForRelationshipRequest(relationship);
return NonPrimaryDocumentTypeFactory.Instance.GetForRelationshipRequest(relationship);
}

public Type GetForResponse(RelationshipAttribute relationship)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ internal sealed class ResourceFieldObjectSchemaBuilder
private readonly ResourceTypeSchemaGenerator _resourceTypeSchemaGenerator;
private readonly NullableReferenceSchemaGenerator _nullableReferenceSchemaGenerator;
private readonly IDictionary<string, OpenApiSchema> _schemasForResourceFields;
private readonly RelationshipDataTypeFactory _relationshipDataTypeFactory = new();

public ResourceFieldObjectSchemaBuilder(ResourceTypeInfo resourceTypeInfo, ISchemaRepositoryAccessor schemaRepositoryAccessor,
SchemaGenerator defaultSchemaGenerator, JsonApiSchemaIdSelector jsonApiSchemaIdSelector, ResourceTypeSchemaGenerator resourceTypeSchemaGenerator)
Expand Down Expand Up @@ -228,11 +227,11 @@ private void AddRelationshipDataSchemaToResourceObject(RelationshipAttribute rel
}
}

private Type GetRelationshipDataType(RelationshipAttribute relationship, Type resourceObjectType)
private static Type GetRelationshipDataType(RelationshipAttribute relationship, Type resourceObjectType)
{
return resourceObjectType.GetGenericTypeDefinition().IsAssignableTo(typeof(ResourceResponseObject<>))
? _relationshipDataTypeFactory.GetForResponse(relationship)
: _relationshipDataTypeFactory.GetForRequest(relationship);
? RelationshipDataTypeFactory.Instance.GetForResponse(relationship)
: RelationshipDataTypeFactory.Instance.GetForRequest(relationship);
}

private OpenApiSchema? GetReferenceSchemaForRelationshipData(Type relationshipDataType)
Expand Down