-
-
Notifications
You must be signed in to change notification settings - Fork 158
Make InputFormatters and OutputFormatters implement IApiRequestFormatMetadataProvider #967
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
Changes from 3 commits
1a17ab0
cc34540
ede65dc
0b46597
29fb4ff
37c9b85
1f50fd6
72e83db
d589079
8387528
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
using System; | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using JsonApiDotNetCore.Resources; | ||
using Microsoft.AspNetCore.Mvc.ApiExplorer; | ||
using Microsoft.AspNetCore.Mvc.Formatters; | ||
using Microsoft.Net.Http.Headers; | ||
|
||
namespace JsonApiDotNetCore.Middleware | ||
{ | ||
/// <summary> | ||
/// Application-wide entry point for writing JSON:API response bodies. | ||
/// </summary> | ||
public abstract class JsonApiFormatter : IApiRequestFormatMetadataProvider | ||
{ | ||
private readonly Type _operationContainerType = typeof(OperationContainer); | ||
maurei marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
/// <inheritdoc /> | ||
public IReadOnlyList<string> GetSupportedContentTypes(string contentType, Type objectType) | ||
{ | ||
ArgumentGuard.NotNull(contentType, nameof(contentType)); | ||
ArgumentGuard.NotNull(objectType, nameof(objectType)); | ||
|
||
string mediaType = IsAtomicOperationsType(objectType) ? HeaderConstants.AtomicOperationsMediaType : HeaderConstants.MediaType; | ||
|
||
return new MediaTypeCollection | ||
{ | ||
new MediaTypeHeaderValue(mediaType) | ||
}; | ||
} | ||
|
||
private bool IsAtomicOperationsType(Type objectType) | ||
{ | ||
return objectType.GetInterface(nameof(IEnumerable)) != null && objectType.GetGenericArguments().First() == _operationContainerType; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wanted to try why such complex logic is needed, instead of the obvious |
||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,8 +5,8 @@ | |
|
||
namespace JsonApiDotNetCore.Middleware | ||
{ | ||
/// <inheritdoc /> | ||
public sealed class JsonApiInputFormatter : IJsonApiInputFormatter | ||
/// <inheritdoc cref="JsonApiDotNetCore.Middleware.IJsonApiInputFormatter" /> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I assume the cref is to disambiguate between the docs on JsonApiFormatter and IJsonApiInputFormatter. We haven't used this before, but perhaps we should start doing that. Does this work correctly in:
|
||
public sealed class JsonApiInputFormatter : JsonApiFormatter, IJsonApiInputFormatter | ||
{ | ||
/// <inheritdoc /> | ||
public bool CanRead(InputFormatterContext context) | ||
|
Uh oh!
There was an error while loading. Please reload this page.