-
Notifications
You must be signed in to change notification settings - Fork 6k
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
[Rust] Match integer type to minimum and maximum constraints #6985
[Rust] Match integer type to minimum and maximum constraints #6985
Conversation
The logic as you've described it (assuming I've understood) doesn't seem to cope with cases where the valid range is -(something large) to +(something small). You'll correctly pick a signed quantity, but the size will only be big enough for the positive max, not the negative max. I think you need to use the maximum and minimum to determine the size needed. |
You are right. I changed the calculation to use As a sensible default, I made I also added a test for the min / max constraints to int sizing logic, you can look at it, it makes the choices clearer. |
Thanks for the PR but your commit (as shown in the Commits tab) is not linked to your Github account, which means this PR won't count as your contribution in https://github.com/swagger-api/swagger-codegen/graphs/contributors. Let me know if you need help fixing it. |
Thank you for noticing this. I fixed my local git config for the future, amended the commit and added my secondary email to my github account for good measure. |
Although the commit is now to my primary email, I noticed that my avatar picture for the commit is small, and the generic octocat is still shown behind. Let me know if this is normal or if it's something I should fix. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One minor typo. Otherwise looks good.
assertEquals(RustServerCodegen.matchingIntType(false, null, Long.MAX_VALUE), "i64"); | ||
} | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks
@@ -269,7 +262,7 @@ public String toApiName(String name) { | |||
|
|||
/** | |||
* Escapes a reserved word as defined in the `reservedWords` array. Handle escaping | |||
* those terms here. This logic is only called if a variable matches the reserved words | |||
* those terms here. This logic is only called if a variable matches the reseved words |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
reserved
?
@fralalonde thanks for the PR, which has been merged into master. @bjgill thanks for reviewing the change. |
@frol @farcaller
In rust-server, use rust integer types best matching the
format
,minimum
andmaximum
schema constraints.Matching rules cover all rust standard int size, from 8 to 64bits, signed and unsigned, including
size
types.minimum
is used to determine if the int type should be signed. Default is signed.maximum
is used to determine the int size. Default isisize
orusize
.formats
int32
andint64
can be used to force int size.uint32
anduint64
have been preserved, even though they are superseded by new code.minimum
andmaximum
constraints also respects theirexclusive
flags if specified.