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

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

Closed
DamianEdwards opened this issue Aug 5, 2022 · 4 comments
Closed

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

DamianEdwards opened this issue Aug 5, 2022 · 4 comments
Labels
area-minimal Includes minimal APIs, endpoint filters, parameter binding, request delegate generator etc area-web-frameworks feature-minimal-actions Controller-like actions for endpoint routing

Comments

@DamianEdwards
Copy link
Member

DamianEdwards commented Aug 5, 2022

.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

@DamianEdwards DamianEdwards added area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates feature-minimal-actions Controller-like actions for endpoint routing area-web-frameworks labels Aug 5, 2022
@mkArtakMSFT mkArtakMSFT removed the area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates label Aug 8, 2022
@rafikiassumani-msft rafikiassumani-msft added this to the .NET 8 Planning milestone Aug 9, 2022
@danmoseley
Copy link
Member

Just curious do we know of real scenarios for this or is it just completeness (like supporting Half, etc)

@captainsafia
Copy link
Member

Triage: @DamianEdwards will validate if this is still an issue given that it seems like the appropriate TryParse overloads do exist in the BCL.

@DamianEdwards
Copy link
Member Author

So parameters are parsed correctly, but the schema of Int128 is inferred incorrectly (both as parameters and response type). A query parameter of type Int128 is described as a string, and an Int128 member on a schema definition is described as a complex type ("object") with no additional properties. This likely means the change needs to be made in SwashBuckle rather than ASP.NET Core.

@captainsafia
Copy link
Member

Filed domaindrivendev/Swashbuckle.AspNetCore#2611 to follow-up on the schema-related changes in Swashbuckle.

@ghost ghost locked as resolved and limited conversation to collaborators Mar 17, 2023
@amcasey amcasey added the area-minimal Includes minimal APIs, endpoint filters, parameter binding, request delegate generator etc label Jun 2, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-minimal Includes minimal APIs, endpoint filters, parameter binding, request delegate generator etc area-web-frameworks feature-minimal-actions Controller-like actions for endpoint routing
Projects
No open projects
Status: Committed
Development

No branches or pull requests

6 participants