Skip to content

Incorrect OpenAPI schema for the Range attribute when using a culture different from en-US #62922

@marcominerva

Description

@marcominerva

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

I'm working on a PC that uses Italian Culture (it-IT). The following code:

builder.Services.AddValidation();

// ...

app.MapPost("/api/range", (Input input, [Range(42.1, 89.8)] double value) =>
{
    return TypedResults.Ok();
});

app.Run();

public record Input 
{
    [Required]
    [Range(1234.56, 7891.1)]
    public double Value { get; set; }    
}

Produces incorrect OpenAPI schemas because it does not take regional settings into account (e.g., minimum and maximum values):

"parameters": [
    {
      "name": "value",
      "in": "query",
      "required": true,
      "schema": {
        "maximum": 898,
        "minimum": 421,
        "pattern": "^-?(?:0|[1-9]\\d*)(?:\\.\\d+)?(?:[eE][+-]?\\d+)?$",
        "type": [
          "number",
          "string"
        ],
        "format": "double"
      }
    }
"schemas": {
    "Input": {
      "required": [
        "value"
      ],
      "type": "object",
      "properties": {
        "value": {
          "maximum": 78911,
          "minimum": 123456,
          "pattern": "^-?(?:0|[1-9]\\d*)(?:\\.\\d+)?(?:[eE][+-]?\\d+)?$",
          "type": [
            "number",
            "string"
          ],
          "format": "double"
        }
      }
    }
}

In fact, the test GetOpenApiParameters_HandlesRouteParameterWithValidationAttributes fails on my Italian machine, in particular on this assert:

[([Range(1234.56, 7891.1)] decimal id) => {}, (OpenApiSchema schema) => { Assert.Equal("1234.56", schema.Minimum); Assert.Equal("7891.1", schema.Maximum); }],

Expected Behavior

Minimum and maximum values should be correctly set in the OpenAPI schema even when the culture used is different from en-US.

Steps To Reproduce

Minimal repro at https://github.com/marcominerva/RangeAttributeIssue

.NET Version

10.0.100-preview.6.25358.103

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions