Skip to content

Basic OpenAPI tests for all JSON:API endpoints #1512

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 15 commits into from
Mar 22, 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 @@ -232,8 +232,18 @@
}
}
},
"404": {
"description": "A related resource does not exist.",
"content": {
"application/vnd.api+json": {
"schema": {
"$ref": "#/components/schemas/errorResponseDocument"
}
}
}
},
"409": {
"description": "A resource type in the request body is incompatible.",
"description": "The request body contains conflicting information or another resource with the same ID already exists.",
"content": {
"application/vnd.api+json": {
"schema": {
Expand Down Expand Up @@ -957,7 +967,7 @@
}
},
"404": {
"description": "The person does not exist.",
"description": "The person or a related resource does not exist.",
"content": {
"application/vnd.api+json": {
"schema": {
Expand All @@ -967,7 +977,7 @@
}
},
"409": {
"description": "A resource type in the request body is incompatible.",
"description": "The request body contains conflicting information or another resource with the same ID already exists.",
"content": {
"application/vnd.api+json": {
"schema": {
Expand Down Expand Up @@ -1025,7 +1035,7 @@
}
},
"404": {
"description": "The person does not exist.",
"description": "The person or a related resource does not exist.",
"content": {
"application/vnd.api+json": {
"schema": {
Expand All @@ -1035,7 +1045,7 @@
}
},
"409": {
"description": "A resource type in the request body is incompatible.",
"description": "The request body contains conflicting information or another resource with the same ID already exists.",
"content": {
"application/vnd.api+json": {
"schema": {
Expand Down Expand Up @@ -1093,7 +1103,7 @@
}
},
"404": {
"description": "The person does not exist.",
"description": "The person or a related resource does not exist.",
"content": {
"application/vnd.api+json": {
"schema": {
Expand All @@ -1103,7 +1113,7 @@
}
},
"409": {
"description": "A resource type in the request body is incompatible.",
"description": "The request body contains conflicting information or another resource with the same ID already exists.",
"content": {
"application/vnd.api+json": {
"schema": {
Expand Down Expand Up @@ -1509,7 +1519,7 @@
}
},
"404": {
"description": "The person does not exist.",
"description": "The person or a related resource does not exist.",
"content": {
"application/vnd.api+json": {
"schema": {
Expand All @@ -1519,7 +1529,7 @@
}
},
"409": {
"description": "A resource type in the request body is incompatible.",
"description": "The request body contains conflicting information or another resource with the same ID already exists.",
"content": {
"application/vnd.api+json": {
"schema": {
Expand Down Expand Up @@ -1577,7 +1587,7 @@
}
},
"404": {
"description": "The person does not exist.",
"description": "The person or a related resource does not exist.",
"content": {
"application/vnd.api+json": {
"schema": {
Expand All @@ -1587,7 +1597,7 @@
}
},
"409": {
"description": "A resource type in the request body is incompatible.",
"description": "The request body contains conflicting information or another resource with the same ID already exists.",
"content": {
"application/vnd.api+json": {
"schema": {
Expand Down Expand Up @@ -1645,7 +1655,7 @@
}
},
"404": {
"description": "The person does not exist.",
"description": "The person or a related resource does not exist.",
"content": {
"application/vnd.api+json": {
"schema": {
Expand All @@ -1655,7 +1665,7 @@
}
},
"409": {
"description": "A resource type in the request body is incompatible.",
"description": "The request body contains conflicting information or another resource with the same ID already exists.",
"content": {
"application/vnd.api+json": {
"schema": {
Expand Down Expand Up @@ -1889,8 +1899,18 @@
}
}
},
"404": {
"description": "A related resource does not exist.",
"content": {
"application/vnd.api+json": {
"schema": {
"$ref": "#/components/schemas/errorResponseDocument"
}
}
}
},
"409": {
"description": "A resource type in the request body is incompatible.",
"description": "The request body contains conflicting information or another resource with the same ID already exists.",
"content": {
"application/vnd.api+json": {
"schema": {
Expand Down Expand Up @@ -2614,7 +2634,7 @@
}
},
"404": {
"description": "The tag does not exist.",
"description": "The tag or a related resource does not exist.",
"content": {
"application/vnd.api+json": {
"schema": {
Expand All @@ -2624,7 +2644,7 @@
}
},
"409": {
"description": "A resource type in the request body is incompatible.",
"description": "The request body contains conflicting information or another resource with the same ID already exists.",
"content": {
"application/vnd.api+json": {
"schema": {
Expand Down Expand Up @@ -2682,7 +2702,7 @@
}
},
"404": {
"description": "The tag does not exist.",
"description": "The tag or a related resource does not exist.",
"content": {
"application/vnd.api+json": {
"schema": {
Expand All @@ -2692,7 +2712,7 @@
}
},
"409": {
"description": "A resource type in the request body is incompatible.",
"description": "The request body contains conflicting information or another resource with the same ID already exists.",
"content": {
"application/vnd.api+json": {
"schema": {
Expand Down Expand Up @@ -2750,7 +2770,7 @@
}
},
"404": {
"description": "The tag does not exist.",
"description": "The tag or a related resource does not exist.",
"content": {
"application/vnd.api+json": {
"schema": {
Expand All @@ -2760,7 +2780,7 @@
}
},
"409": {
"description": "A resource type in the request body is incompatible.",
"description": "The request body contains conflicting information or another resource with the same ID already exists.",
"content": {
"application/vnd.api+json": {
"schema": {
Expand Down Expand Up @@ -2994,8 +3014,18 @@
}
}
},
"404": {
"description": "A related resource does not exist.",
"content": {
"application/vnd.api+json": {
"schema": {
"$ref": "#/components/schemas/errorResponseDocument"
}
}
}
},
"409": {
"description": "A resource type in the request body is incompatible.",
"description": "The request body contains conflicting information or another resource with the same ID already exists.",
"content": {
"application/vnd.api+json": {
"schema": {
Expand Down Expand Up @@ -3719,7 +3749,7 @@
}
},
"404": {
"description": "The todoItem does not exist.",
"description": "The todoItem or a related resource does not exist.",
"content": {
"application/vnd.api+json": {
"schema": {
Expand All @@ -3729,7 +3759,7 @@
}
},
"409": {
"description": "A resource type in the request body is incompatible.",
"description": "The request body contains conflicting information or another resource with the same ID already exists.",
"content": {
"application/vnd.api+json": {
"schema": {
Expand Down Expand Up @@ -4135,7 +4165,7 @@
}
},
"404": {
"description": "The todoItem does not exist.",
"description": "The todoItem or a related resource does not exist.",
"content": {
"application/vnd.api+json": {
"schema": {
Expand All @@ -4145,7 +4175,7 @@
}
},
"409": {
"description": "A resource type in the request body is incompatible.",
"description": "The request body contains conflicting information or another resource with the same ID already exists.",
"content": {
"application/vnd.api+json": {
"schema": {
Expand Down Expand Up @@ -4551,7 +4581,7 @@
}
},
"404": {
"description": "The todoItem does not exist.",
"description": "The todoItem or a related resource does not exist.",
"content": {
"application/vnd.api+json": {
"schema": {
Expand All @@ -4561,7 +4591,7 @@
}
},
"409": {
"description": "A resource type in the request body is incompatible.",
"description": "The request body contains conflicting information or another resource with the same ID already exists.",
"content": {
"application/vnd.api+json": {
"schema": {
Expand Down Expand Up @@ -4619,7 +4649,7 @@
}
},
"404": {
"description": "The todoItem does not exist.",
"description": "The todoItem or a related resource does not exist.",
"content": {
"application/vnd.api+json": {
"schema": {
Expand All @@ -4629,7 +4659,7 @@
}
},
"409": {
"description": "A resource type in the request body is incompatible.",
"description": "The request body contains conflicting information or another resource with the same ID already exists.",
"content": {
"application/vnd.api+json": {
"schema": {
Expand Down Expand Up @@ -4687,7 +4717,7 @@
}
},
"404": {
"description": "The todoItem does not exist.",
"description": "The todoItem or a related resource does not exist.",
"content": {
"application/vnd.api+json": {
"schema": {
Expand All @@ -4697,7 +4727,7 @@
}
},
"409": {
"description": "A resource type in the request body is incompatible.",
"description": "The request body contains conflicting information or another resource with the same ID already exists.",
"content": {
"application/vnd.api+json": {
"schema": {
Expand Down Expand Up @@ -5255,9 +5285,6 @@
"$ref": "#/components/schemas/dataInResponse"
},
{
"required": [
"links"
],
"type": "object",
"properties": {
"attributes": {
Expand Down Expand Up @@ -5647,9 +5674,6 @@
"$ref": "#/components/schemas/dataInResponse"
},
{
"required": [
"links"
],
"type": "object",
"properties": {
"attributes": {
Expand Down Expand Up @@ -6157,9 +6181,6 @@
"$ref": "#/components/schemas/dataInResponse"
},
{
"required": [
"links"
],
"type": "object",
"properties": {
"attributes": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ public async Task<PersonPrimaryResponseDocument> PostAsync(PersonPostRequestDocu
var errorMapping = new Dictionary<string, ParsableFactory<IParsable>> {
{"400", ErrorResponseDocument.CreateFromDiscriminatorValue},
{"403", ErrorResponseDocument.CreateFromDiscriminatorValue},
{"404", ErrorResponseDocument.CreateFromDiscriminatorValue},
{"409", ErrorResponseDocument.CreateFromDiscriminatorValue},
{"422", ErrorResponseDocument.CreateFromDiscriminatorValue},
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ public async Task<TagPrimaryResponseDocument> PostAsync(TagPostRequestDocument b
var errorMapping = new Dictionary<string, ParsableFactory<IParsable>> {
{"400", ErrorResponseDocument.CreateFromDiscriminatorValue},
{"403", ErrorResponseDocument.CreateFromDiscriminatorValue},
{"404", ErrorResponseDocument.CreateFromDiscriminatorValue},
{"409", ErrorResponseDocument.CreateFromDiscriminatorValue},
{"422", ErrorResponseDocument.CreateFromDiscriminatorValue},
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ public async Task<TodoItemPrimaryResponseDocument> PostAsync(TodoItemPostRequest
var errorMapping = new Dictionary<string, ParsableFactory<IParsable>> {
{"400", ErrorResponseDocument.CreateFromDiscriminatorValue},
{"403", ErrorResponseDocument.CreateFromDiscriminatorValue},
{"404", ErrorResponseDocument.CreateFromDiscriminatorValue},
{"409", ErrorResponseDocument.CreateFromDiscriminatorValue},
{"422", ErrorResponseDocument.CreateFromDiscriminatorValue},
};
Expand Down
4 changes: 2 additions & 2 deletions src/Examples/OpenApiNSwagClientExample/Worker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ protected override async Task ExecuteAsync(CancellationToken stoppingToken)
private static Task<ApiResponse<PersonCollectionResponseDocument?>> GetPeopleAsync(ExampleApiClient apiClient, IDictionary<string, string?> queryString,
string? ifNoneMatch, CancellationToken cancellationToken)
{
return ApiResponse.TranslateAsync(() => apiClient.GetPersonCollectionAsync(queryString, ifNoneMatch, cancellationToken));
return ApiResponse.TranslateAsync(async () => await apiClient.GetPersonCollectionAsync(queryString, ifNoneMatch, cancellationToken));
}

private async Task UpdatePersonAsync(CancellationToken cancellationToken)
Expand All @@ -66,7 +66,7 @@ private async Task UpdatePersonAsync(CancellationToken cancellationToken)
using (_apiClient.WithPartialAttributeSerialization<PersonPatchRequestDocument, PersonAttributesInPatchRequest>(patchRequest,
person => person.FirstName))
{
_ = await ApiResponse.TranslateAsync(() => _apiClient.PatchPersonAsync(patchRequest.Data.Id, null, patchRequest, cancellationToken));
_ = await ApiResponse.TranslateAsync(async () => await _apiClient.PatchPersonAsync(patchRequest.Data.Id, null, patchRequest, cancellationToken));
}
}
}
5 changes: 1 addition & 4 deletions src/JsonApiDotNetCore.OpenApi/ActionDescriptorExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,7 @@ public static MethodInfo GetActionMethod(this ActionDescriptor descriptor)
{
ArgumentGuard.NotNull(descriptor);

IFilterMetadata? filterMetadata = descriptor.FilterDescriptors.Select(filterDescriptor => filterDescriptor.Filter)
.OfType<TFilterMetaData>().FirstOrDefault();

return (TFilterMetaData?)filterMetadata;
return descriptor.FilterDescriptors.Select(filterDescriptor => filterDescriptor.Filter).OfType<TFilterMetaData>().FirstOrDefault();
}

public static ControllerParameterDescriptor? GetBodyParameterDescriptor(this ActionDescriptor descriptor)
Expand Down
Loading