Skip to content

Merge master into openapi (controller attribute fixes) #1507

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

Merged
merged 5 commits into from
Mar 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,8 @@
]
}
}
}
},
"required": true
},
"responses": {
"201": {
Expand Down Expand Up @@ -469,7 +470,8 @@
]
}
}
}
},
"required": true
},
"responses": {
"200": {
Expand Down Expand Up @@ -937,7 +939,8 @@
]
}
}
}
},
"required": true
},
"responses": {
"204": {
Expand Down Expand Up @@ -1004,7 +1007,8 @@
]
}
}
}
},
"required": true
},
"responses": {
"204": {
Expand Down Expand Up @@ -1071,7 +1075,8 @@
]
}
}
}
},
"required": true
},
"responses": {
"204": {
Expand Down Expand Up @@ -1486,7 +1491,8 @@
]
}
}
}
},
"required": true
},
"responses": {
"204": {
Expand Down Expand Up @@ -1553,7 +1559,8 @@
]
}
}
}
},
"required": true
},
"responses": {
"204": {
Expand Down Expand Up @@ -1620,7 +1627,8 @@
]
}
}
}
},
"required": true
},
"responses": {
"204": {
Expand Down Expand Up @@ -1834,7 +1842,8 @@
]
}
}
}
},
"required": true
},
"responses": {
"201": {
Expand Down Expand Up @@ -2118,7 +2127,8 @@
]
}
}
}
},
"required": true
},
"responses": {
"200": {
Expand Down Expand Up @@ -2586,7 +2596,8 @@
]
}
}
}
},
"required": true
},
"responses": {
"204": {
Expand Down Expand Up @@ -2653,7 +2664,8 @@
]
}
}
}
},
"required": true
},
"responses": {
"204": {
Expand Down Expand Up @@ -2720,7 +2732,8 @@
]
}
}
}
},
"required": true
},
"responses": {
"204": {
Expand Down Expand Up @@ -2934,7 +2947,8 @@
]
}
}
}
},
"required": true
},
"responses": {
"201": {
Expand Down Expand Up @@ -3218,7 +3232,8 @@
]
}
}
}
},
"required": true
},
"responses": {
"200": {
Expand Down Expand Up @@ -3686,7 +3701,8 @@
]
}
}
}
},
"required": true
},
"responses": {
"204": {
Expand Down Expand Up @@ -4101,7 +4117,8 @@
]
}
}
}
},
"required": true
},
"responses": {
"204": {
Expand Down Expand Up @@ -4516,7 +4533,8 @@
]
}
}
}
},
"required": true
},
"responses": {
"204": {
Expand Down Expand Up @@ -4583,7 +4601,8 @@
]
}
}
}
},
"required": true
},
"responses": {
"204": {
Expand Down Expand Up @@ -4650,7 +4669,8 @@
]
}
}
}
},
"required": true
},
"responses": {
"204": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ internal sealed class EndpointResolver
return null;
}

HttpMethodAttribute? method = controllerAction.GetCustomAttributes(true).OfType<HttpMethodAttribute>().FirstOrDefault();
HttpMethodAttribute? method = Attribute.GetCustomAttributes(controllerAction, true).OfType<HttpMethodAttribute>().FirstOrDefault();

return ResolveJsonApiEndpoint(method);
}
Expand Down
24 changes: 11 additions & 13 deletions src/JsonApiDotNetCore/Controllers/BaseJsonApiController.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System.ComponentModel.DataAnnotations;
using JsonApiDotNetCore.Configuration;
using JsonApiDotNetCore.Errors;
using JsonApiDotNetCore.Middleware;
Expand Down Expand Up @@ -107,7 +106,7 @@ public virtual async Task<IActionResult> GetAsync(CancellationToken cancellation
/// GET /articles/1 HTTP/1.1
/// ]]></code>
/// </summary>
public virtual async Task<IActionResult> GetAsync([Required] TId id, CancellationToken cancellationToken)
public virtual async Task<IActionResult> GetAsync(TId id, CancellationToken cancellationToken)
{
_traceWriter.LogMethodStart(new
{
Expand All @@ -132,7 +131,7 @@ public virtual async Task<IActionResult> GetAsync([Required] TId id, Cancellatio
/// GET /articles/1/revisions HTTP/1.1
/// ]]></code>
/// </summary>
public virtual async Task<IActionResult> GetSecondaryAsync([Required] TId id, [Required] string relationshipName, CancellationToken cancellationToken)
public virtual async Task<IActionResult> GetSecondaryAsync(TId id, string relationshipName, CancellationToken cancellationToken)
{
_traceWriter.LogMethodStart(new
{
Expand Down Expand Up @@ -161,7 +160,7 @@ public virtual async Task<IActionResult> GetSecondaryAsync([Required] TId id, [R
/// GET /articles/1/relationships/revisions HTTP/1.1
/// ]]></code>
/// </summary>
public virtual async Task<IActionResult> GetRelationshipAsync([Required] TId id, [Required] string relationshipName, CancellationToken cancellationToken)
public virtual async Task<IActionResult> GetRelationshipAsync(TId id, string relationshipName, CancellationToken cancellationToken)
{
_traceWriter.LogMethodStart(new
{
Expand All @@ -186,7 +185,7 @@ public virtual async Task<IActionResult> GetRelationshipAsync([Required] TId id,
/// POST /articles HTTP/1.1
/// ]]></code>
/// </summary>
public virtual async Task<IActionResult> PostAsync([FromBody] [Required] TResource resource, CancellationToken cancellationToken)
public virtual async Task<IActionResult> PostAsync(TResource resource, CancellationToken cancellationToken)
{
_traceWriter.LogMethodStart(new
{
Expand Down Expand Up @@ -236,8 +235,8 @@ public virtual async Task<IActionResult> PostAsync([FromBody] [Required] TResour
/// <param name="cancellationToken">
/// Propagates notification that request handling should be canceled.
/// </param>
public virtual async Task<IActionResult> PostRelationshipAsync([Required] TId id, [Required] string relationshipName,
[FromBody] [Required] ISet<IIdentifiable> rightResourceIds, CancellationToken cancellationToken)
public virtual async Task<IActionResult> PostRelationshipAsync(TId id, string relationshipName, ISet<IIdentifiable> rightResourceIds,
CancellationToken cancellationToken)
{
_traceWriter.LogMethodStart(new
{
Expand Down Expand Up @@ -265,7 +264,7 @@ public virtual async Task<IActionResult> PostRelationshipAsync([Required] TId id
/// PATCH /articles/1 HTTP/1.1
/// ]]></code>
/// </summary>
public virtual async Task<IActionResult> PatchAsync([Required] TId id, [FromBody] [Required] TResource resource, CancellationToken cancellationToken)
public virtual async Task<IActionResult> PatchAsync(TId id, TResource resource, CancellationToken cancellationToken)
{
_traceWriter.LogMethodStart(new
{
Expand Down Expand Up @@ -311,8 +310,7 @@ public virtual async Task<IActionResult> PatchAsync([Required] TId id, [FromBody
/// <param name="cancellationToken">
/// Propagates notification that request handling should be canceled.
/// </param>
public virtual async Task<IActionResult> PatchRelationshipAsync([Required] TId id, [Required] string relationshipName, [FromBody] object? rightValue,
CancellationToken cancellationToken)
public virtual async Task<IActionResult> PatchRelationshipAsync(TId id, string relationshipName, object? rightValue, CancellationToken cancellationToken)
{
_traceWriter.LogMethodStart(new
{
Expand All @@ -338,7 +336,7 @@ public virtual async Task<IActionResult> PatchRelationshipAsync([Required] TId i
/// DELETE /articles/1 HTTP/1.1
/// ]]></code>
/// </summary>
public virtual async Task<IActionResult> DeleteAsync([Required] TId id, CancellationToken cancellationToken)
public virtual async Task<IActionResult> DeleteAsync(TId id, CancellationToken cancellationToken)
{
_traceWriter.LogMethodStart(new
{
Expand Down Expand Up @@ -372,8 +370,8 @@ public virtual async Task<IActionResult> DeleteAsync([Required] TId id, Cancella
/// <param name="cancellationToken">
/// Propagates notification that request handling should be canceled.
/// </param>
public virtual async Task<IActionResult> DeleteRelationshipAsync([Required] TId id, [Required] string relationshipName,
[FromBody] [Required] ISet<IIdentifiable> rightResourceIds, CancellationToken cancellationToken)
public virtual async Task<IActionResult> DeleteRelationshipAsync(TId id, string relationshipName, ISet<IIdentifiable> rightResourceIds,
CancellationToken cancellationToken)
{
_traceWriter.LogMethodStart(new
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System.ComponentModel.DataAnnotations;
using JetBrains.Annotations;
using JsonApiDotNetCore.AtomicOperations;
using JsonApiDotNetCore.Configuration;
Expand Down Expand Up @@ -103,8 +102,7 @@ protected BaseJsonApiOperationsController(IJsonApiOptions options, IResourceGrap
/// }
/// ]]></code>
/// </example>
public virtual async Task<IActionResult> PostOperationsAsync([FromBody] [Required] IList<OperationContainer> operations,
CancellationToken cancellationToken)
public virtual async Task<IActionResult> PostOperationsAsync(IList<OperationContainer> operations, CancellationToken cancellationToken)
{
_traceWriter.LogMethodStart(new
{
Expand Down
Loading