Skip to content

Support NRT and MSV in required and nullable #1185

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 76 commits into from
Oct 9, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
76 commits
Select commit Hold shift + click to select a range
99dcfa8
Added tests for nullable and required properties in schema generation
maurei Sep 5, 2022
2604f84
Added handling of modelstate validation in setting required attributes
maurei Jul 5, 2022
f7194d9
Not all swagger documents need to be saved to disk; changes in OpenAp…
maurei Sep 5, 2022
449a079
Added OpenApi client tests for nullable and required properties
maurei Sep 6, 2022
c55a2cb
Use NullabilityInfoContext for nullability information
maurei Sep 6, 2022
31638b8
Merge branch 'merge-master-v503-into-openapi' into openapi-required-a…
bkoelman Sep 8, 2022
fc15912
Post-merge fixes
bkoelman Sep 8, 2022
7288b8a
Merge branch 'openapi' into openapi-required-and-nullable-properties
bkoelman Dec 15, 2022
d7c8b4b
Post-merge fixes
bkoelman Dec 15, 2022
d72e43e
Fixed: do not share NullabilityInfoContext, it is not thread-safe
bkoelman Dec 15, 2022
526d03f
Merge pull request #1229 from json-api-dotnet/merge-openapi-into-1185
bkoelman Dec 15, 2022
f8e640b
Review feedback
maurei Dec 19, 2022
7266bc6
remove redundant new lines in eof added by cleanupcode
maurei Dec 19, 2022
945a803
Improved naming in OpenApiTests/SchemaProperties
maurei Dec 19, 2022
f5bb7fc
Review feedback: NullabilityTests
maurei Dec 20, 2022
919a3f8
Improved JsonApiClient and testing
maurei Dec 20, 2022
87aea3e
Fix test: should not omit required field in test request body
maurei Dec 20, 2022
2ff06fc
Temp enable CI buid for current branch
maurei Dec 20, 2022
932367e
Rename test files: it no longer only concerns required attributes, bu…
maurei Dec 20, 2022
061f426
Changes and tests for support of nullable and required for relationships
maurei Dec 22, 2022
90970a8
- Rename placeholder model names and properties to examples consisent…
maurei Dec 24, 2022
affc187
Move into consistent folder structure, remove bad cleanupcode eof lin…
maurei Dec 24, 2022
daf25a2
Merge branch 'openapi' into openapi-required-and-nullable-properties
maurei Dec 24, 2022
d4f1d69
Merge pull request #1231 from json-api-dotnet/attributes-object-schem…
maurei Dec 27, 2022
76e098a
Organise tests such that they map directly to the tables in #1231 and…
maurei Dec 28, 2022
a2e7a96
Add two missing 'Act' comments
maurei Dec 28, 2022
1815dec
More elaborate testing
maurei Jan 3, 2023
63ba43d
Remove non-sensical testcases. Add caching in ObjectExtensions.
maurei Jan 4, 2023
3e9708a
Remove overlooked code duplication in OpenApiTests, revert reflection…
maurei Jan 5, 2023
8304c05
Make AutoFakers deterministic; generate positive IDs
bkoelman Jan 7, 2023
9672b14
Fix nameof
bkoelman Jan 7, 2023
345a689
Use On/Off naming, shorten type names by using Nrt+Msv
bkoelman Jan 7, 2023
22ad300
Renamed EmptyResource to Empty to further shorten FK names
bkoelman Jan 7, 2023
3069533
Fixed invalid EF Core mappings, resulting in logged warnings and inab…
bkoelman Jan 7, 2023
36ac8e7
Move misplaced Act comments
bkoelman Jan 7, 2023
a88bce8
Optimize and clarify ResourceFieldValidationMetadataProvider
bkoelman Jan 8, 2023
2652063
Rename method, provide error message
bkoelman Jan 8, 2023
f2ecb5f
Refactor JsonApiClient: simplified recursion by using two converters,…
bkoelman Jan 8, 2023
d337230
Add relationship nullability assertions in OpenAPI client tests
bkoelman Jan 8, 2023
52cc1f1
Cleanup JsonElementExtensions
bkoelman Jan 8, 2023
b30a680
Cleanup ObjectExtensions
bkoelman Jan 8, 2023
73c3232
Make base type abstract, remove redundant TranslateAsync calls, inlin…
bkoelman Jan 8, 2023
55e702c
Simplify usings
bkoelman Jan 9, 2023
28bb39b
Sync up test names
bkoelman Jan 9, 2023
ff4262e
Fix invalid tests
bkoelman Jan 9, 2023
821d09d
Fix assertion messages
bkoelman Jan 9, 2023
5b71d90
Sync up tests
bkoelman Jan 9, 2023
df9a1b4
Revert change to pass full options instead of just the naming policy
bkoelman Jan 9, 2023
9844e6a
Fix casing in test names
bkoelman Jan 10, 2023
6071f5b
Simplify Cannot_exclude_Id tests
bkoelman Jan 10, 2023
6881208
Rename base type to avoid OpenApiClientTests.OpenApiClientTests
bkoelman Jan 10, 2023
cc3815c
Adapt to existing naming convention
bkoelman Sep 30, 2023
4ef8214
Remove redundant assertions, fix formatting
bkoelman Sep 30, 2023
dcdf5a5
Correct test names
bkoelman Sep 30, 2023
2d7f8b9
Centralize code for property assignment in tests
bkoelman Oct 1, 2023
7364e94
Merge pull request #1244 from json-api-dotnet/openapi-nrt-msv-updates
bkoelman Oct 1, 2023
7c6f9eb
Merge branch 'openapi' into openapi-required-and-nullable-properties
bkoelman Oct 1, 2023
41d6d67
Apply Resharper hint: convert switch statement to expression
bkoelman Oct 1, 2023
bd31216
Simplify expressions
bkoelman Oct 1, 2023
6a87751
Simplify exception assertions
bkoelman Oct 1, 2023
5c85c3a
Use string interpolation
bkoelman Oct 1, 2023
b08ab9b
Corrections in openapi documentation
bkoelman Oct 1, 2023
f7786bb
Simplify code
bkoelman Oct 1, 2023
c3c4844
Remove redundant suppression
bkoelman Oct 1, 2023
66a2dc4
Merge branch 'master' into openapi-required-and-nullable-properties
bkoelman Oct 1, 2023
f46db8a
Combine OpenAPI client tests for create resource with null/default at…
bkoelman Oct 1, 2023
63bf071
Fixup OpenAPI example and docs
bkoelman Oct 1, 2023
ce8045d
Revert "Merge branch 'master' into openapi-required-and-nullable-prop…
bkoelman Oct 1, 2023
fac0471
Workaround for running OpenAPI tests on Windows
bkoelman Oct 2, 2023
dd667be
Merge branch 'openapi' into openapi-required-and-nullable-properties
bkoelman Oct 2, 2023
9194487
Address failing InspectCode
bkoelman Oct 2, 2023
85d608b
Remove redundant calls
bkoelman Oct 2, 2023
007ff30
Remove redundant tests
bkoelman Oct 2, 2023
817aeb3
Move types out of the wrong namespace
bkoelman Oct 2, 2023
fb9b12a
Merge branch 'openapi' into openapi-required-and-nullable-properties
bkoelman Oct 4, 2023
0dd49b0
Remove redundant suppressions in openapi after update to CSharpGuidel…
bkoelman Oct 4, 2023
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
Prev Previous commit
Next Next commit
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
  • Loading branch information
maurei committed Dec 28, 2022
commit 76e098aab019ec38bf82c6186fa33806138022fb
1 change: 0 additions & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ environment:

branches:
only:
- openapi-required-and-nullable-properties # TODO: remove
- master
- openapi
- develop
Expand Down
12 changes: 12 additions & 0 deletions test/OpenApiClientTests/FakeHttpClientWrapper.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Net;
using System.Net.Http.Headers;
using System.Text;
using System.Text.Json;
using JsonApiDotNetCore.OpenApi.Client;

namespace OpenApiClientTests;
Expand All @@ -22,6 +23,17 @@ private FakeHttpClientWrapper(HttpClient httpClient, FakeHttpMessageHandler hand
_handler = handler;
}

public JsonElement ParseRequestBody()
{
if (RequestBody == null)
{
throw new InvalidOperationException();
}

using JsonDocument jsonDocument = JsonDocument.Parse(RequestBody);
return jsonDocument.RootElement.Clone();
}

public static FakeHttpClientWrapper Create(HttpStatusCode statusCode, string? responseBody)
{
HttpResponseMessage response = CreateResponse(statusCode, responseBody);
Expand Down
20 changes: 0 additions & 20 deletions test/OpenApiClientTests/ObjectExtensions.cs

This file was deleted.

8 changes: 4 additions & 4 deletions test/OpenApiClientTests/OpenApiClientTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,15 @@
<CodeGenerator>NSwagCSharp</CodeGenerator>
<Options>/UseBaseUrl:false /ClientClassAccessModifier:internal /GenerateExceptionClasses:false /AdditionalNamespaceUsages:JsonApiDotNetCore.OpenApi.Client.Exceptions</Options>
</OpenApiReference>
<OpenApiReference Include="SchemaProperties\NullableReferenceTypesEnabled\swagger.g.json">
<Namespace>OpenApiClientTests.SchemaProperties.NullableReferenceTypesEnabled.GeneratedCode</Namespace>
<OpenApiReference Include="ResourceFieldsValidation\NullableReferenceTypesEnabled\swagger.g.json">
<Namespace>OpenApiClientTests.ResourceFieldsValidation.NullableReferenceTypesEnabled.GeneratedCode</Namespace>
<ClassName>NullableReferenceTypesEnabledClient</ClassName>
<OutputPath>NullableReferenceTypesEnabledClient.cs</OutputPath>
<CodeGenerator>NSwagCSharp</CodeGenerator>
<Options>/UseBaseUrl:false /ClientClassAccessModifier:internal /GenerateExceptionClasses:false /AdditionalNamespaceUsages:JsonApiDotNetCore.OpenApi.Client.Exceptions /GenerateNullableReferenceTypes:true</Options>
</OpenApiReference>
<OpenApiReference Include="SchemaProperties\NullableReferenceTypesDisabled\swagger.g.json">
<Namespace>OpenApiClientTests.SchemaProperties.NullableReferenceTypesDisabled.GeneratedCode</Namespace>
<OpenApiReference Include="ResourceFieldsValidation\NullableReferenceTypesDisabled\swagger.g.json">
<Namespace>OpenApiClientTests.ResourceFieldsValidation.NullableReferenceTypesDisabled.GeneratedCode</Namespace>
<ClassName>NullableReferenceTypesDisabledClient</ClassName>
<OutputPath>NullableReferenceTypesDisabledClient.cs</OutputPath>
<CodeGenerator>NSwagCSharp</CodeGenerator>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using JsonApiDotNetCore.OpenApi.Client;
using Newtonsoft.Json;

namespace OpenApiClientTests.SchemaProperties.NullableReferenceTypesDisabled.GeneratedCode;
namespace OpenApiClientTests.ResourceFieldsValidation.NullableReferenceTypesDisabled.GeneratedCode;

internal partial class NullableReferenceTypesDisabledClient : JsonApiClient
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
using System.Reflection;
using FluentAssertions;
using OpenApiClientTests.SchemaProperties.NullableReferenceTypesDisabled.GeneratedCode;
using OpenApiClientTests.ResourceFieldsValidation.NullableReferenceTypesDisabled.GeneratedCode;
using Xunit;

namespace OpenApiClientTests.SchemaProperties.NullableReferenceTypesDisabled;
namespace OpenApiClientTests.ResourceFieldsValidation.NullableReferenceTypesDisabled;

public sealed class NullabilityTests
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
using Bogus;
using OpenApiClientTests.ResourceFieldsValidation.NullableReferenceTypesDisabled.GeneratedCode;

namespace OpenApiClientTests.ResourceFieldsValidation.NullableReferenceTypesDisabled;

// @formatter:wrap_chained_method_calls chop_always
// @formatter:keep_existing_linebreaks true

internal sealed class NullableReferenceTypesDisabledFaker
{
private readonly Lazy<Faker<HenHousePostRequestDocument>> _lazyHenHousePostRequestDocumentFaker;
private readonly Lazy<Faker<HenHousePatchRequestDocument>> _lazyHenHousePatchRequestDocumentFaker;

private readonly Lazy<Faker<ChickenPostRequestDocument>> _lazyChickenPostRequestDocumentFaker = new(() =>
{
Faker<ChickenAttributesInPostRequest> attributesInPostRequestFaker = new Faker<ChickenAttributesInPostRequest>()
.RuleFor(attributes => attributes.Name, faker => faker.Name.FirstName())
.RuleFor(attributes => attributes.NameOfCurrentFarm, faker => faker.Company.CompanyName())
.RuleFor(attributes => attributes.Age, faker => faker.Random.Int(1, 20))
.RuleFor(attributes => attributes.Weight, faker => faker.Random.Int(20, 50))
.RuleFor(attributes => attributes.TimeAtCurrentFarmInDays, faker => faker.Random.Int(1, 356))
.RuleFor(attributes => attributes.HasProducedEggs, _ => true);

Faker<ChickenDataInPostRequest> dataInPostRequestFaker = new Faker<ChickenDataInPostRequest>()
.RuleFor(data => data.Attributes, _ => attributesInPostRequestFaker.Generate());

return new Faker<ChickenPostRequestDocument>()
.RuleFor(document => document.Data, _ => dataInPostRequestFaker.Generate());
});

private readonly Lazy<Faker<ChickenPatchRequestDocument>> _lazyChickenPatchRequestDocumentFaker = new(() =>
{
Faker<ChickenAttributesInPatchRequest> attributesInPatchRequestFaker = new Faker<ChickenAttributesInPatchRequest>()
.RuleFor(attributes => attributes.Name, faker => faker.Name.FirstName())
.RuleFor(attributes => attributes.NameOfCurrentFarm, faker => faker.Company.CompanyName())
.RuleFor(attributes => attributes.Age, faker => faker.Random.Int(1, 20))
.RuleFor(attributes => attributes.Weight, faker => faker.Random.Int(20, 50))
.RuleFor(attributes => attributes.TimeAtCurrentFarmInDays, faker => faker.Random.Int(1, 356))
.RuleFor(attributes => attributes.HasProducedEggs, _ => true);

Faker<ChickenDataInPatchRequest> dataInPatchRequestFaker = new Faker<ChickenDataInPatchRequest>()
// @formatter:wrap_chained_method_calls chop_if_long
.RuleFor(data => data.Id, faker => faker.Random.Int(1, 100).ToString())
// @formatter:wrap_chained_method_calls restore
.RuleFor(data => data.Attributes, _ => attributesInPatchRequestFaker.Generate());

return new Faker<ChickenPatchRequestDocument>()
.RuleFor(document => document.Data, _ => dataInPatchRequestFaker.Generate());
});

private readonly Lazy<Faker<ToOneChickenInRequest>> _lazyToOneChickenInRequestFaker = new(() =>
new Faker<ToOneChickenInRequest>()
.RuleFor(relationship => relationship.Data, faker => new ChickenIdentifier
{
// @formatter:wrap_chained_method_calls chop_if_long
Id = faker.Random.Int(1, 100).ToString()
// @formatter:wrap_chained_method_calls restore
}));

private readonly Lazy<Faker<NullableToOneChickenInRequest>> _lazyNullableToOneChickenInRequestFaker = new(() =>
new Faker<NullableToOneChickenInRequest>()
.RuleFor(relationship => relationship.Data, faker => new ChickenIdentifier
{
// @formatter:wrap_chained_method_calls chop_if_long
Id = faker.Random.Int(1, 100).ToString()
// @formatter:wrap_chained_method_calls restore
}));

private readonly Lazy<Faker<ToManyChickenInRequest>> _lazyToManyChickenInRequestFaker = new(() =>
new Faker<ToManyChickenInRequest>()
.RuleFor(relationship => relationship.Data, faker => new List<ChickenIdentifier>
{
new()
{
// @formatter:wrap_chained_method_calls chop_if_long
Id = faker.Random.Int(1, 100).ToString()
// @formatter:wrap_chained_method_calls restore
}
}));

public Faker<ChickenPostRequestDocument> ChickenPostRequestDocument => _lazyChickenPostRequestDocumentFaker.Value;
public Faker<ChickenPatchRequestDocument> ChickenPatchRequestDocument => _lazyChickenPatchRequestDocumentFaker.Value;
public Faker<HenHousePostRequestDocument> HenHousePostRequestDocument => _lazyHenHousePostRequestDocumentFaker.Value;
public Faker<HenHousePatchRequestDocument> HenHousePatchRequestDocument => _lazyHenHousePatchRequestDocumentFaker.Value;

public NullableReferenceTypesDisabledFaker()
{
_lazyHenHousePostRequestDocumentFaker = new Lazy<Faker<HenHousePostRequestDocument>>(HenHousePostRequestDocumentFakerFactory);
_lazyHenHousePatchRequestDocumentFaker = new Lazy<Faker<HenHousePatchRequestDocument>>(HenHousePatchRequestDocumentFakerFactory);
}

private Faker<HenHousePostRequestDocument> HenHousePostRequestDocumentFakerFactory()
{
Faker<HenHouseRelationshipsInPostRequest> relationshipsInPostRequestFaker = new Faker<HenHouseRelationshipsInPostRequest>()
.RuleFor(relationships => relationships.OldestChicken, _ => _lazyNullableToOneChickenInRequestFaker.Value.Generate())
.RuleFor(relationships => relationships.FirstChicken, _ => _lazyToOneChickenInRequestFaker.Value.Generate())
.RuleFor(relationships => relationships.ChickensReadyForLaying, _ => _lazyToManyChickenInRequestFaker.Value.Generate())
.RuleFor(relationships => relationships.AllChickens, _ => _lazyToManyChickenInRequestFaker.Value.Generate());

Faker<HenHouseDataInPostRequest> dataInPostRequestFaker = new Faker<HenHouseDataInPostRequest>()
.RuleFor(data => data.Relationships, _ => relationshipsInPostRequestFaker.Generate());

return new Faker<HenHousePostRequestDocument>()
.RuleFor(document => document.Data, _ => dataInPostRequestFaker.Generate());
}

private Faker<HenHousePatchRequestDocument> HenHousePatchRequestDocumentFakerFactory()
{
Faker<HenHouseRelationshipsInPatchRequest> relationshipsInPatchRequestFaker = new Faker<HenHouseRelationshipsInPatchRequest>()
.RuleFor(relationships => relationships.OldestChicken, _ => _lazyNullableToOneChickenInRequestFaker.Value.Generate())
.RuleFor(relationships => relationships.FirstChicken, _ => _lazyToOneChickenInRequestFaker.Value.Generate())
.RuleFor(relationships => relationships.ChickensReadyForLaying, _ => _lazyToManyChickenInRequestFaker.Value.Generate())
.RuleFor(relationships => relationships.AllChickens, _ => _lazyToManyChickenInRequestFaker.Value.Generate());

Faker<HenHouseDataInPatchRequest> dataInPatchRequestFaker = new Faker<HenHouseDataInPatchRequest>()
// @formatter:wrap_chained_method_calls chop_if_long
.RuleFor(data => data.Id, faker => faker.Random.Int(1, 100).ToString())
// @formatter:wrap_chained_method_calls restore
.RuleFor(data => data.Relationships, _ => relationshipsInPatchRequestFaker.Generate());

return new Faker<HenHousePatchRequestDocument>()
.RuleFor(document => document.Data, _ => dataInPatchRequestFaker.Generate());
}
}
Loading