Skip to content

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

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

Closed
c6-dark opened this issue Nov 7, 2024 · 5 comments
Closed
Labels
question stale Stale issues or pull requests

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.

Copy link
Contributor

github-actions bot commented Feb 9, 2025

This issue is stale because it has been open for 60 days with no activity. It will be automatically closed in 14 days if no further updates are made.

@github-actions github-actions bot added the stale Stale issues or pull requests label Feb 9, 2025
Copy link
Contributor

This issue was closed because it has been inactive for 14 days since being marked as stale.

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Feb 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question stale Stale issues or pull requests
Projects
None yet
Development

No branches or pull requests

3 participants