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

[Question]: Specify max and min range for double and decimal datatype #3130

Open
c6-dark opened this issue Nov 7, 2024 · 3 comments
Open
Labels

Comments

@c6-dark
Copy link

c6-dark commented Nov 7, 2024

What are you wanting to achieve?

Because of some requirements, I want to specify max and min values of decimal and double datatype for both of them but in the above case, the swagger is not showing maximum and minimum for both.

What code or approach do you have so far?

[Range[decimal.minvalue, decimal.maxvalue)]
public decimal amt { get; set; }

[Range[double.minvalue, double.maxvalue)]
public double pamt { get; set; }

How do I achieve the above so the max and min value of decimal and double is shown in swagger

Additional context

No response

@amabilee
Copy link

amabilee commented Nov 7, 2024

Hey there!
Have you tried the Swashbuckle.AspNetCore.Annotations package?

@c6-dark
Copy link
Author

c6-dark commented Dec 10, 2024

Hey, I am using that package. It doesnt support decimal.maxvalue or decimal.minvalue, or double.maxvalue, double.minvalue

@martincostello
Copy link
Collaborator

This is the code that handles [Range]:

private static void ApplyRangeAttribute(OpenApiSchema schema, RangeAttribute rangeAttribute)
{
#if NET8_0_OR_GREATER
if (rangeAttribute.MinimumIsExclusive)
{
schema.ExclusiveMinimum = true;
}
if (rangeAttribute.MaximumIsExclusive)
{
schema.ExclusiveMaximum = true;
}
#endif
schema.Maximum = decimal.TryParse(rangeAttribute.Maximum.ToString(), out decimal maximum)
? maximum
: schema.Maximum;
schema.Minimum = decimal.TryParse(rangeAttribute.Minimum.ToString(), out decimal minimum)
? minimum
: schema.Minimum;
}

On inspection, it looks like it would support decimal and double.

If it's not working maybe it's a bug? Please provide a minimal reproducible example as a GitHub repository that demonstrates the issue you're experiencing so we can look into this further.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants