-
-
Notifications
You must be signed in to change notification settings - Fork 6.7k
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
[REQ] Add ability to differentiate between integer and int32 schemas #9447
Comments
@spacether after seeing your problem statement, i was wondering can we use java |
Which specific use case are you describing? Are you asking if you can swap in BigInteger in place of the current isInteger? |
@spacether yes, i was asking if we can use BigInteger inplace of isUnboundedInteger, even BigInteger supports numerical values greater than 64 bit. |
@SivaTharun yes that is a good solution for that use case. Another solution you could consider is using java BigDecimal to store all numeric types (isNumber). In a new generator that I am working on I store all numeric types in python Decimal: |
@spacether The above alternative that you are proposing makes sense , we can use BigDecimal in place of BigInt that works as well, but i had a query related to type conversion of BigDecimal type to int/float type. This any way would work fine, in python. So basically my question revolves around the case that, what if a number greater than Long.MAX_VALUE, is sent for Json encoding like in this method. do we need to use the same logic of Type conversion to int/ float type in java too. i fell we will have to directly use BigDecimal here for Json encoding. |
It would if you were strictly casting into classes that allow for overflow but how will you instantiate these classes/schemas?
If you use BigDecimal as the base class as all of those schemas and impose the max and min constraints in the constructor for the Int32 schema it will work. If you assume that you have to choose a class that will have overflows, how will Combo work? I think that casting into the most permissive container class (python Decimal/java BigDecimal) and then imposing constraints on top of that type at instantiation or validation time is the easiest way to do it.
You can choose how you want to send number over the wire. I did it this way to preserve an ingested int being sent as an int and an ingested float being sent as a float. From my reading it sounds like some languages choose to send 9.0 as 9 which is a reason to describe a payload of that type as number and NOT int or float. Maybe where I cast to int to send it in json you would cast it to BigInt to prevent overflow issues? |
Per a discussion with @wing328 it is okay to add just isShortInteger and have isInteger cover unbounded integers from now on. It will be a breaking change with fallback, where the fallback is for users to update their template isInteger usages to isShortInteger if they need int32 behavior, or they can update their specs to specify format: int32. |
Is your feature request related to a problem? Please describe.
Our current java code cannot differentiate between these two use cases:
in classes that implement IJsonSchemaValidationProperties.
Both schemas define this property as codegenProperty.isInteger
so we have no way of differentiating between the two above use cases.
Describe the solution you'd like
I would like two booleans to describe each of these use cases:
We can keep the existing isInteger property for existing generators.
This way the addition will be a non-breaking change.
Describe alternatives you've considered
One could use isInteger as isUnboundedInteger but that would be a bad way to do it because our current code is using it for both isUnboundedInteger + isShortInteger
Better to make two new boolean fields which fully represent these formats.
These two new fields should be added to https://github.com/OpenAPITools/openapi-generator/blob/master/modules/openapi-generator/src/main/java/org/openapitools/codegen/IJsonSchemaValidationProperties.java
Additional context
This came up when working on imposing format constraints in
#8325
The text was updated successfully, but these errors were encountered: