Skip to content
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

feat(webAPI): Make all lists nullable in OpenAPI schema #1359

Merged
16 changes: 0 additions & 16 deletions src/Digdir.Domain.Dialogporten.WebApi/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -167,11 +167,6 @@ static void BuildAndRun(string[] args, TelemetryConfiguration telemetryConfigura
TypeNameConverter.ToShortName(endpointDefinition.EndpointType)))));
};
x.Serializer.Options.DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull;
// Do not serialize empty collections
x.Serializer.Options.TypeInfoResolver = new DefaultJsonTypeInfoResolver
{
Modifiers = { IgnoreEmptyCollections }
};
x.Serializer.Options.Converters.Add(new JsonStringEnumConverter());
x.Serializer.Options.Converters.Add(new UtcDateTimeOffsetConverter());
x.Serializer.Options.Converters.Add(new DateTimeNotSupportedConverter());
Expand Down Expand Up @@ -207,16 +202,5 @@ static void BuildAndRun(string[] args, TelemetryConfiguration telemetryConfigura
app.Run();
}

static void IgnoreEmptyCollections(JsonTypeInfo typeInfo)
{
foreach (var property in typeInfo.Properties)
{
if (property.PropertyType.IsAssignableTo(typeof(ICollection)))
{
property.ShouldSerialize = (_, val) => val is ICollection collection && collection.Count > 0;
}
}
}

// ReSharper disable once ClassNeverInstantiated.Global
public sealed partial class Program;
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ public async Task InitializeAsync()

AssertionOptions.AssertEquivalencyUsing(options =>
{
//options.ExcludingMissingMembers();
options.Using<DateTimeOffset>(ctx => ctx.Subject.Should().BeCloseTo(ctx.Expectation, TimeSpan.FromMicroseconds(1)))
.WhenTypeIs<DateTimeOffset>();
return options;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ public async Task Get_ReturnsSimpleDialog_WhenDialogExists()
response.TryPickT0(out var result, out _).Should().BeTrue();
result.Should().NotBeNull();
result.Should().BeEquivalentTo(createDialogCommand, options => options
.ExcludingMissingMembers()
.Excluding(x => x.UpdatedAt)
.Excluding(x => x.CreatedAt)
.Excluding(x => x.SystemLabel));
Expand All @@ -48,7 +47,6 @@ public async Task Get_ReturnsDialog_WhenDialogExists()
response.TryPickT0(out var result, out _).Should().BeTrue();
result.Should().NotBeNull();
result.Should().BeEquivalentTo(createCommand, options => options
.ExcludingMissingMembers()
.Excluding(x => x.UpdatedAt)
.Excluding(x => x.CreatedAt)
.Excluding(x => x.SystemLabel));
Expand Down
6 changes: 4 additions & 2 deletions tests/k6/tests/serviceowner/dialogSearch.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export default function () {
let titleForLastItem = uuidv4();
let updatedAfter = (new Date()).toISOString(); // We use this on all tests to avoid clashing with unrelated dialogs
let defaultFilter = "?UpdatedAfter=" + updatedAfter;

describe('Arrange: Create some dialogs to test against', () => {

for (let i = 0; i < 20; i++) {
Expand Down Expand Up @@ -207,7 +207,9 @@ export default function () {
let r = getSO('dialogs/' + defaultFilter + '&EndUserId=' + invalidEndUserId + '&ServiceResource=' + auxResource);
expectStatusFor(r).to.equal(200);
expect(r, 'response').to.have.validJsonBody();
expect(r.json(), 'response json').not.to.have.property("items");
let response = r.json();
expect(response, 'response json').to.have.property("items");
expect(response.items, 'items').to.have.lengthOf(0);
})

describe("Cleanup", () => {
Expand Down
Loading