Skip to content

Commit 3c873a4

Browse files
Re-enable test
Re-enable test now that the difference is known.
1 parent 97aa607 commit 3c873a4

File tree

4 files changed

+14
-2
lines changed

4 files changed

+14
-2
lines changed

src/TodoApp/ApiEndpoints.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Copyright (c) Martin Costello, 2024. All rights reserved.
22
// Licensed under the Apache 2.0 license. See the LICENSE file in the project root for full license information.
33

4+
using System.Text.Json.Serialization;
45
using Microsoft.AspNetCore.Http.HttpResults;
56
using Microsoft.AspNetCore.Mvc;
67
using Microsoft.EntityFrameworkCore;
@@ -33,6 +34,15 @@ public static IServiceCollection AddTodoApi(this IServiceCollection services)
3334
services.AddScoped<ITodoRepository, TodoRepository>();
3435
services.AddScoped<ITodoService, TodoService>();
3536

37+
// Use the same JSON serializer options for OpenAPI as for the API itself
38+
services.ConfigureHttpJsonOptions(options =>
39+
{
40+
options.SerializerOptions.DefaultIgnoreCondition = TodoJsonSerializerContext.Default.Options.DefaultIgnoreCondition;
41+
options.SerializerOptions.NumberHandling = TodoJsonSerializerContext.Default.Options.NumberHandling;
42+
options.SerializerOptions.PropertyNamingPolicy = TodoJsonSerializerContext.Default.Options.PropertyNamingPolicy;
43+
options.SerializerOptions.WriteIndented = TodoJsonSerializerContext.Default.Options.WriteIndented;
44+
});
45+
3646
// Configure an EFCore data context to store the Todos backed by SQLite
3747
services.AddDbContext<TodoContext>((serviceProvider, options) =>
3848
{

src/TodoApp/TodoJsonSerializerContext.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ namespace TodoApp;
2020
[JsonSerializable(typeof(TodoListViewModel))]
2121
[JsonSourceGenerationOptions(
2222
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull,
23+
NumberHandling = JsonNumberHandling.Strict,
2324
PropertyNamingPolicy = JsonKnownNamingPolicy.CamelCase,
2425
WriteIndented = true)]
2526
public sealed partial class TodoJsonSerializerContext : JsonSerializerContext;

tests/TodoApp.Tests/OpenApiTests.Schema_Is_Correct_schemaUrl=openapi.verified.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,8 @@
293293
nullable: true
294294
},
295295
status: {
296-
type: integer
296+
type: integer,
297+
nullable: true,
297298
format: int32
298299
},
299300
detail: {

tests/TodoApp.Tests/OpenApiTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public OpenApiTests(TodoAppFixture fixture, ITestOutputHelper outputHelper)
2525

2626
[Theory]
2727
[InlineData("/nswag/v1.json")]
28-
[InlineData("/openapi/v1.json", Skip = "https://github.com/dotnet/aspnetcore/issues/61038")]
28+
[InlineData("/openapi/v1.json")]
2929
[InlineData("/swagger/v1/swagger.json")]
3030
public async Task Schema_Is_Correct(string schemaUrl)
3131
{

0 commit comments

Comments
 (0)