-
-
Notifications
You must be signed in to change notification settings - Fork 159
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1647 from json-api-dotnet/merge-master-into-openapi
Merge master into openapi
- Loading branch information
Showing
20 changed files
with
404 additions
and
225 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 0 additions & 16 deletions
16
src/JsonApiDotNetCore.OpenApi.Swashbuckle/JsonApiEndpoint.cs
This file was deleted.
Oops, something went wrong.
60 changes: 13 additions & 47 deletions
60
src/JsonApiDotNetCore.OpenApi.Swashbuckle/JsonApiMetadata/EndpointResolver.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,72 +1,38 @@ | ||
using System.Reflection; | ||
using JsonApiDotNetCore.Controllers; | ||
using Microsoft.AspNetCore.Mvc; | ||
using JsonApiDotNetCore.Middleware; | ||
using Microsoft.AspNetCore.Mvc.Routing; | ||
|
||
namespace JsonApiDotNetCore.OpenApi.Swashbuckle.JsonApiMetadata; | ||
|
||
internal sealed class EndpointResolver | ||
{ | ||
public JsonApiEndpoint? Get(MethodInfo controllerAction) | ||
public static EndpointResolver Instance { get; } = new(); | ||
|
||
private EndpointResolver() | ||
{ | ||
} | ||
|
||
public JsonApiEndpoints GetEndpoint(MethodInfo controllerAction) | ||
{ | ||
ArgumentGuard.NotNull(controllerAction); | ||
|
||
if (!IsJsonApiController(controllerAction)) | ||
{ | ||
return null; | ||
} | ||
|
||
if (IsAtomicOperationsController(controllerAction)) | ||
{ | ||
return JsonApiEndpoint.PostOperations; | ||
return JsonApiEndpoints.None; | ||
} | ||
|
||
HttpMethodAttribute? method = Attribute.GetCustomAttributes(controllerAction, true).OfType<HttpMethodAttribute>().FirstOrDefault(); | ||
|
||
return ResolveJsonApiEndpoint(method); | ||
IEnumerable<HttpMethodAttribute> httpMethodAttributes = controllerAction.GetCustomAttributes<HttpMethodAttribute>(true); | ||
return httpMethodAttributes.GetJsonApiEndpoint(); | ||
} | ||
|
||
private static bool IsJsonApiController(MethodInfo controllerAction) | ||
private bool IsJsonApiController(MethodInfo controllerAction) | ||
{ | ||
return typeof(CoreJsonApiController).IsAssignableFrom(controllerAction.ReflectedType); | ||
} | ||
|
||
private static bool IsAtomicOperationsController(MethodInfo controllerAction) | ||
public bool IsAtomicOperationsController(MethodInfo controllerAction) | ||
{ | ||
return typeof(BaseJsonApiOperationsController).IsAssignableFrom(controllerAction.ReflectedType); | ||
} | ||
|
||
private static JsonApiEndpoint? ResolveJsonApiEndpoint(HttpMethodAttribute? httpMethod) | ||
{ | ||
return httpMethod switch | ||
{ | ||
HttpGetAttribute attr => attr.Template switch | ||
{ | ||
null => JsonApiEndpoint.GetCollection, | ||
JsonApiRoutingTemplate.PrimaryEndpoint => JsonApiEndpoint.GetSingle, | ||
JsonApiRoutingTemplate.SecondaryEndpoint => JsonApiEndpoint.GetSecondary, | ||
JsonApiRoutingTemplate.RelationshipEndpoint => JsonApiEndpoint.GetRelationship, | ||
_ => null | ||
}, | ||
HttpPostAttribute attr => attr.Template switch | ||
{ | ||
null => JsonApiEndpoint.PostResource, | ||
JsonApiRoutingTemplate.RelationshipEndpoint => JsonApiEndpoint.PostRelationship, | ||
_ => null | ||
}, | ||
HttpPatchAttribute attr => attr.Template switch | ||
{ | ||
JsonApiRoutingTemplate.PrimaryEndpoint => JsonApiEndpoint.PatchResource, | ||
JsonApiRoutingTemplate.RelationshipEndpoint => JsonApiEndpoint.PatchRelationship, | ||
_ => null | ||
}, | ||
HttpDeleteAttribute attr => attr.Template switch | ||
{ | ||
JsonApiRoutingTemplate.PrimaryEndpoint => JsonApiEndpoint.DeleteResource, | ||
JsonApiRoutingTemplate.RelationshipEndpoint => JsonApiEndpoint.DeleteRelationship, | ||
_ => null | ||
}, | ||
_ => null | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 0 additions & 8 deletions
8
src/JsonApiDotNetCore.OpenApi.Swashbuckle/JsonApiPathParameter.cs
This file was deleted.
Oops, something went wrong.
12 changes: 0 additions & 12 deletions
12
src/JsonApiDotNetCore.OpenApi.Swashbuckle/JsonApiRoutingTemplate.cs
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.