Skip to content

Conversation

@bkoelman
Copy link
Member

@bkoelman bkoelman commented Nov 8, 2025

This PR adds OpenAPI tests for using various data types in attributes that behave like values, such as Int128/BigInteger/Half/Uri/IPAddress/Version and various others.

Depending on the built-in support (which varies per technology), the following custom converters may need to be added:

  • Entity Framework Core database mapping:
    ModelConfigurationBuilder.Properties<YourType>().HaveConversion<YourTypeConverter>()
  • Request/response body serialization:
    JsonApiOptions.SerializerOptions.Converters.Add(new YourTypeJsonConverter())
  • Specify/override the format used in OpenAPI:
    SwaggerGenOptions.MapType<YourType>(() => new OpenApiSchema { Type = "...", Format = "..." })
  • Parsing values in filter query strings: inherit from FilterParser and override GetConstantValueConverterForType
    protected override ConstantValueConverter GetConstantValueConverterForType(Type destinationType)
    {
        if (destinationType == typeof(YourType) || destinationType == typeof(YourType?))
        {
            // ...
        }
    
        return base.GetConstantValueConverterForType(destinationType);
    }

Changes in this PR:

  • Publicly exposes RuntimeTypeConverter.GetFriendlyTypeName(), which expands generic type arguments
  • Improved conversion from string to date/time values in RuntimeTypeConverter
  • Add conversion from string to System.Uri in RuntimeTypeConverter
  • Improved LiteralConstantExpression.GetStringValue for date/time values
  • Include original request body parse exception in meta stack trace
  • Use generic math in SumFilterParser example

Despite mentioned in the original issue, tuples are not covered because exposing them in an HTTP API is just odd.
Complex types and collections are not covered either, because how they work is likely going to change when #1439 is implemented.

Closes #1051.

QUALITY CHECKLIST

@codecov
Copy link

codecov bot commented Nov 8, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.80%. Comparing base (91c9392) to head (6508259).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1832      +/-   ##
==========================================
+ Coverage   92.76%   92.80%   +0.03%     
==========================================
  Files         437      437              
  Lines       14821    14831      +10     
  Branches     2391     2392       +1     
==========================================
+ Hits        13749    13764      +15     
  Misses        654      654              
+ Partials      418      413       -5     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

…ave like values, such as Int128/BigInteger/Half/Uri/IPAddress/Version and various others

- Publicly exposes RuntimeTypeConverter.GetFriendlyTypeName(), which expands generic type arguments
- Improved conversion from string to date/time values in RuntimeTypeConverter
- Add conversion from string to System.Uri in RuntimeTypeConverter
- Improved LiteralConstantExpression.GetStringValue for date/time values
- Include original request body parse exception in meta stack trace
- Use generic math in SumFilterParser example
@bkoelman bkoelman marked this pull request as ready for review November 8, 2025 19:09
@bkoelman bkoelman merged commit ba3accf into master Nov 8, 2025
16 checks passed
@bkoelman bkoelman deleted the various-data-types branch November 8, 2025 19:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Support for various data types of resource attributes and id

2 participants