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

[Bug]: Incorrect maximum value in open api document for RangeAttribute with long.MaxValue #3159

Open
ArieGato opened this issue Nov 20, 2024 · 7 comments
Labels
bug stale Stale issues or pull requests

Comments

@ArieGato
Copy link

Describe the bug

The maximum value of a property of type long is generated incorrectly. The issue occurs when the property is decorated with a custom range attribute derived from RangeAttribute. The generated value is 9223372036854776000, but should be 9223372036854775807.

Expected behavior

The expected behavior is that the generated max value is the correct max value of a long data type: 9223372036854775807

Actual behavior

The generated value is 9223372036854776000

Steps to reproduce

  1. Open repro: https://github.com/ArieGato/Swashbuckle.AspNetCore
  2. Start web site test/Basic
  3. Under DataAnnotation section, notice that the example value contains the incorrect max value : the body creditCard -> Id

Exception(s) (if any)

No response

Swashbuckle.AspNetCore version

7.0.0

.NET Version

any

Anything else?

The issue was previously reported here: 1038

@ArieGato ArieGato added the bug label Nov 20, 2024
@martincostello
Copy link
Collaborator

At a glance without looking at the repro, there's a chance this is related to serializer behaviours and JavaScript/JSON precision of large values in browsers. I've seen similar issues raised against ASP.NET Core itself with the same wrong number that were related to that.

If you want to check yourself to rule that out that would be useful, otherwise I'll look into it at some point in the near future.

@ArieGato
Copy link
Author

Hi @martincostello

I can concur that the schema is generated correctly in code:

image

The open api document however contains this:

"id": {
  "maximum": 9223372036854776000,
  "minimum": 0,
  "type": "integer",
  "format": "int64"
},

@martincostello
Copy link
Collaborator

The value's type is a decimal rather than a long in the screenshot. This suggests to me it's a rounding issue in the serialisation, and that's handled in the Microsoft.OpenApi library, rather than by Swashbuckle itself.

@ArieGato
Copy link
Author

The issue is getting harder to grasp for me. I dug a little deeper and checked the output that was written to the HttpResponse. The open api json that is returned is in fact correct. All the time I was debugging in Edge.

image

In Chrome the json is shown without some extra Microsoft magic.

image

However... The Swagger UI also doesn't render the correct maximum value. So I guess it ends here.

Any suggestions on how to go forwards?

@martincostello
Copy link
Collaborator

I think as I mentioned in my first comment, you're hitting issues with Javascript's precision when it comes to dealing with very large numbers. I'm not aware of a way to deal with it.

@martincostello
Copy link
Collaborator

Copy link
Contributor

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 Jan 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug stale Stale issues or pull requests
Projects
None yet
Development

No branches or pull requests

2 participants