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

ConfigureForNodaTime not map Type correctly #4841

Open
darix795 opened this issue Mar 29, 2024 · 0 comments
Open

ConfigureForNodaTime not map Type correctly #4841

darix795 opened this issue Mar 29, 2024 · 0 comments

Comments

@darix795
Copy link

darix795 commented Mar 29, 2024

After .NET 8 migration I move NSwag from v13 to v14. I have this Startup json api configuration:

.AddJsonOptions(options =>
{
    options.JsonSerializerOptions.Converters.Add(new DictionaryEnumConverter());
    options.JsonSerializerOptions.Converters.Add(
        new JsonStringEnumConverter(JsonNamingPolicy.CamelCase));
    options.JsonSerializerOptions.Converters.Add(new JsonDocumentCamelCaseConverter());
    options.JsonSerializerOptions.ConfigureForNodaTime(DateTimeZoneProviders.Tzdb);
});

It seems that json converter ConfigureForNodaTime not work as expected on SchemaSettings, but work good on .NET Api json options. For example type Period not converted to string but as complex object similar to C# class. Nswag has a wrong behavior because correct conversion produce a string like described on NodaTime source code (https://github.com/nodatime/nodatime/blob/main/src/NodaTime/Text/PeriodPattern.cs#L70).

I write a workaround for this specific issue that map manually Period type:

if (document.SchemaSettings is SystemTextJsonSchemaGeneratorSettings schemaSettings)
{
    schemaSettings.TypeMappers.Add(new PrimitiveTypeMapper(typeof(Period), s =>
    {
        s.Type = JsonObjectType.String;
        s.Format = "period";
    }));
}

but i expect that ConfigureForNodaTime work fine like other converters for example JsonStringEnumConverter.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant