-
-
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.
* Added tests for nullable and required properties in schema generation * Added handling of modelstate validation in setting required attributes * Not all swagger documents need to be saved to disk; changes in OpenApiTestContext to allow for this * Added OpenApi client tests for nullable and required properties * Use NullabilityInfoContext for nullability information * Post-merge fixes * Post-merge fixes * Fixed: do not share NullabilityInfoContext, it is not thread-safe * Review feedback OpenApiTests/SchemaProperties test collection: * Allow for usage of OpenApiStartup directly * Remove unneeded adding of JsonConverter * Replace null checks with .ShouldHaveCount() calls * Adjust test names Misc: * Reverted .editorconfig changes and fixed ApiException constructor instead * Remove Debug statement * remove redundant new lines in eof added by cleanupcode * Improved naming in OpenApiTests/SchemaProperties * Review feedback: NullabilityTests * Improved JsonApiClient and testing SchemaProperty Tests: * More rigorous test suite, see PR description IJsonApiClient: * Renamed registration method to a more functionally descriptive name. * Improved documentation to contain most relevant information on top instead of at the end, and removed ambiguigity in wording. JsonApiClient * Fix bug: disallow omitting members that are explicitly required by the OAS description * Renamed AttributeNamesContainer to AttributesObjectContext because it was more than just a container * Misc: better variable naming * Fix test: should not omit required field in test request body * Temp enable CI buid for current branch * Rename test files: it no longer only concerns required attributes, but more generally request behaviour * Changes and tests for support of nullable and required for relationships * - Rename placeholder model names and properties to examples consisent with existing test suite - Use existing DbContext instead of temporary one * Move into consistent folder structure, remove bad cleanupcode eof linebreaks * Organise tests such that they map directly to the tables in #1231 and #1111 Organise tests such that they map directly to the tables in #1231 and #1111 * Add two missing 'Act' comments * More elaborate testing -> in sync with latest version of nullability/required table -> introduces ResourceFieldValidationMetadataProvider -> Fix test in legacy projects -> Reusable faker building block for OpenApiClient related concerns * Remove non-sensical testcases. Add caching in ObjectExtensions. * Remove overlooked code duplication in OpenApiTests, revert reflection caching in object extension * Make AutoFakers deterministic; generate positive IDs * Fix nameof * Use On/Off naming, shorten type names by using Nrt+Msv * Renamed EmptyResource to Empty to further shorten FK names * Fixed invalid EF Core mappings, resulting in logged warnings and inability to clear optional to-one relationship when NRT off; fixed wrong public names * Move misplaced Act comments * Optimize and clarify ResourceFieldValidationMetadataProvider * Rename method, provide error message * Refactor JsonApiClient: simplified recursion by using two converters, clearer naming, separation of concerns, improved error message * Add relationship nullability assertions in OpenAPI client tests * Cleanup JsonElementExtensions * Cleanup ObjectExtensions * Make base type abstract, remove redundant TranslateAsync calls, inline relationship Data property name * Simplify usings * Sync up test names * Fix invalid tests * Fix assertion messages * Sync up tests * Revert change to pass full options instead of just the naming policy * Fix casing in test names * Simplify Cannot_exclude_Id tests * Rename base type to avoid OpenApiClientTests.OpenApiClientTests * Adapt to existing naming convention * Remove redundant assertions, fix formatting * Correct test names * Centralize code for property assignment in tests * Apply Resharper hint: convert switch statement to expression * Simplify expressions * Simplify exception assertions * Use string interpolation * Corrections in openapi documentation * Simplify code * Remove redundant suppression * Combine OpenAPI client tests for create resource with null/default attribute * Fixup OpenAPI example and docs * Revert "Merge branch 'master' into openapi-required-and-nullable-properties" This reverts commit 66a2dc4, reversing changes made to c3c4844. * Workaround for running OpenAPI tests on Windows * Address failing InspectCode * Remove redundant calls * Remove redundant tests * Move types out of the wrong namespace * Remove redundant suppressions in openapi after update to CSharpGuidelinesAnalyzer v3.8.4 --------- Co-authored-by: Bart Koelman <[email protected]>
- Loading branch information
Showing
102 changed files
with
12,343 additions
and
909 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
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
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,26 +1,47 @@ | ||
namespace JsonApiDotNetCoreExampleClient; | ||
using JsonApiDotNetCoreExampleClient; | ||
|
||
internal static class Program | ||
{ | ||
private const string BaseUrl = "http://localhost:14140"; | ||
using var httpClient = new HttpClient(); | ||
var apiClient = new ExampleApiClient("http://localhost:14140", httpClient); | ||
|
||
private static async Task Main() | ||
{ | ||
using var httpClient = new HttpClient(); | ||
PersonCollectionResponseDocument getResponse = await apiClient.GetPersonCollectionAsync(); | ||
|
||
ExampleApiClient exampleApiClient = new(BaseUrl, httpClient); | ||
foreach (PersonDataInResponse person in getResponse.Data) | ||
{ | ||
Console.WriteLine($"Found person {person.Id}: {person.Attributes.DisplayName}"); | ||
} | ||
|
||
try | ||
{ | ||
const int nonExistingId = int.MaxValue; | ||
await exampleApiClient.DeletePersonAsync(nonExistingId); | ||
} | ||
catch (ApiException exception) | ||
var patchRequest = new PersonPatchRequestDocument | ||
{ | ||
Data = new PersonDataInPatchRequest | ||
{ | ||
Id = "1", | ||
Attributes = new PersonAttributesInPatchRequest | ||
{ | ||
Console.WriteLine(exception.Response); | ||
LastName = "Doe" | ||
} | ||
} | ||
}; | ||
|
||
Console.WriteLine("Press any key to close."); | ||
Console.ReadKey(); | ||
// This line results in sending "firstName: null" instead of omitting it. | ||
using (apiClient.WithPartialAttributeSerialization<PersonPatchRequestDocument, PersonAttributesInPatchRequest>(patchRequest, person => person.FirstName)) | ||
{ | ||
await TranslateAsync(async () => await apiClient.PatchPersonAsync(1, patchRequest)); | ||
} | ||
|
||
Console.WriteLine("Press any key to close."); | ||
Console.ReadKey(); | ||
|
||
// ReSharper disable once UnusedLocalFunctionReturnValue | ||
static async Task<TResponse?> TranslateAsync<TResponse>(Func<Task<TResponse>> operation) | ||
where TResponse : class | ||
{ | ||
try | ||
{ | ||
return await operation(); | ||
} | ||
catch (ApiException exception) when (exception.StatusCode == 204) | ||
{ | ||
// Workaround for https://github.com/RicoSuter/NSwag/issues/2499 | ||
return 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
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
Oops, something went wrong.