question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

The minimum and maximum of Integer types include a decimal point or use scientific E notation.

See original GitHub issue

Hi. While building my Swagger instance from scratch, I import JSON Schemas using the syntax:

Model model = io.swagger.util.Json.mapper().readValue(jsonSchemaFile, Model.class);

I then create BodyParameters and Response objects and set these model instances on them.

I then serialize my Swagger instance to JSON using the following syntax.

Json.pretty().writeValue(swaggerFile, swagger);

The first problem I’m running into is that my Integer type minimum and maximum facets gain a decimal point (from somewhere).

Before (in JSON Schema file):

              "AccountCount":{
                 "type":"integer",
                 "maximum":9,
                 "minimum":0
              },

After (in Swagger file):

            "AccountCount" : {
              "type" : "integer",
              "minimum" : 0.0,
              "maximum" : 9.0
            },

The second issue I’m hitting is with decimal types where the bounds no longer come out right, and Swagger Editor complains about the use of scientific E notation for minimum and maximum.

Before (in JSON Schema file):

                            "Balance":{
                                "type":"number",
                                "format":"decimal",
                                "multipleOf":0.01,
                                "maximum":9999999999999999.99,
                                "minimum":-9999999999999999.99
                             } 

After (in Swagger file):

                      "Balance" : {
                        "type" : "number",
                        "format" : "decimal",
                        "minimum" : -1.0E16,
                        "maximum" : 1.0E16
                      }

Here’s another peculiar one where an Integer is expressed using scientific E notation.

Before (in JSON Schema file):

                             "AccID":{
                                "type":"integer",
                                "maximum":2147483647,
                                "minimum":-2147483648
                             },

After (in Swagger file):

                      "AccID" : {
                        "type" : "integer",
                        "minimum" : -2.147483648E9,
                        "maximum" : 2.147483647E9
                      },

I’ve attached the JSON Schemas and the serialized swagger doc. Thanks for any help!

numerics.zip

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
ChaitaliRKcommented, Feb 6, 2019

I uplifted swagger-core to 1.5.11, but I still see the minimum and maximum values as decimals. Am I missing something here?

1reaction
cipressocommented, Sep 14, 2016

Hi. I changed Double to BigDecimal for the minimum and maximum facets of numerics in the relevant classes (AbstractNumericProperty, DecimalProperty.setExample, PropertyDeserializer) and configured the Json.mapper() with mapper.enable(DeserializationFeature.USE_BIG_DECIMAL_FOR_FLOATS). With these changes the original decimal quantity that describes my minimum and maximum survive from deserialization of the JSON schema all the way to serialization of the Swagger model. I would like to commit the changes for review if that’s OK.

Read more comments on GitHub >

github_iconTop Results From Across the Web

C# Numbers - TutorialsTeacher
Integer type numbers are positive or negative whole numbers without decimal points. C# includes four data types for integer numbers: byte, short, int,...
Read more >
1.2 Basic Types
The number after E in scientific notation must be an integer. Commas and spaces are not allowed in any numbers (eg. both 10,853...
Read more >
Beej's Guide to C Programming
But there are a couple more integer types we should look at, and the minimum minimum and maximum values they can hold. Yes,...
Read more >
Primitive Data Types (The Java™ Tutorials > Learning the ...
It has a minimum value of -128 and a maximum value of 127 (inclusive). ... Use the Integer class to use int data...
Read more >
The Swift Numeric Data Types - AndyBargh.com
These include integer types such as UInt8 (an unsigned integer type using 8 ... To write decimal floating point literals in scientific notation...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found