Skip to content

Issue handling parameters of type "long" #2663

@TsengSR

Description

@TsengSR

Describe the bug

The generated OpenApi 3.1 definition of an action containing long parameter results in ["integer", "string"] type definition. This cuases issues in SwaggerUI where it fails validation for any valid integer number.

Tried with

  • `Microsoft.AspNetCore.OpenApi: 10.0.1
  • Swashbuckle.AspNetCore: 10.1.0
  • .NET 10 runetime

OpenApi File To Reproduce
Add the OpenApi file you're using or a link to it as well as the steps to reproduce the current behavior.

Expected behavior
Validation to pass and request to be sent when displayed in SwaggerUI.

Screenshots/Code Snippets

Image

Additional context

    [HttpPut("{projectId}/active")]
    public async Task<ActionResult<Project>> IsActive([Range(0, long.MaxValue)] long projectId)
    {
    }

Issue appears whether the range is set or not.

Workaround

builder.Services.AddOpenApi(options =>
{
    options.AddSchemaTransformer((schema, context, cancellationToken) =>
    {
        if (schema.Format == "int64" && schema.Type.HasValue)
        {
            schema.Type = JsonSchemaType.Integer;
        }
        return Task.CompletedTask;
    });
}

This was the only workaround I found. It works well with both, integers and long numbers.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions