Skip to content

Support Int128 and UInt128 in API binding, ApiExplorer, etc. #43119

@DamianEdwards

Description

@DamianEdwards

.NET 7 introduces the new Int128 and UInt128 structs to represent 128-bit numbers. Attempting to use these new structs in parameters of or responses from minimal APIs or MVC APIs results in broken behavior though, as the type inference logic and serialization doesn't recognize these types.

For example, the following minimal API ends up being described as accepting a string parameter and returning a complex type Int128 with no members (see auto-generated swagger document further below):

app.MapGet("/numbers/{number}", (Int128 number) => new NumbersResult(number, (long)number))
    .WithName("Numbers");

record NumbersResult (Int128 Number, long AsLong);
{
    "openapi": "3.0.1",
    "info": {
        "title": "WebApplication6",
        "version": "1.0"
    },
    "paths": {
        "/numbers/{number}": {
            "get": {
                "tags": [
                    "WebApplication6"
                ],
                "operationId": "Numbers",
                "parameters": [
                    {
                        "name": "number",
                        "in": "path",
                        "required": true,
                        "schema": {
                            "type": "string"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "Success",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/NumbersResult"
                                }
                            }
                        }
                    }
                }
            }
        }
    },
    "components": {
        "schemas": {
            "Int128": {
                "type": "object",
                "additionalProperties": false
            },
            "NumbersResult": {
                "type": "object",
                "properties": {
                    "number": {
                        "$ref": "#/components/schemas/Int128"
                    },
                    "asLong": {
                        "type": "integer",
                        "format": "int64"
                    }
                },
                "additionalProperties": false
            }
        }
    }
}

image

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-minimalIncludes minimal APIs, endpoint filters, parameter binding, request delegate generator etcfeature-minimal-actionsController-like actions for endpoint routingold-area-web-frameworks-do-not-use*DEPRECATED* This label is deprecated in favor of the area-mvc and area-minimal labels

    Type

    No type

    Projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions