oapi-codegen icon indicating copy to clipboard operation
oapi-codegen copied to clipboard

Type checking on integers is allowing floats where decimal value is .0

Open MichaelMcAleer opened this issue 3 years ago • 0 comments

Where we have an OAPI component type as integer, we have correct type checking on inputs if the value is x.[1-9] but not x.0: Example:

maxAge:
  type: integer
  minimum: 5
  maximum: 60000

If we set maxAge to 10.1 we get the following expected response:

{
    "code": 100,
    "details": [
        {
            "description": "request body has an error: doesn't match the schema: Error at \"/maxAge\": Value must be an integer"
        }
    ],
    "message": "Failed to validate Request"
}

But if we change the value to 10.0, we get past the API input type check and go straight to JSON decode error in our Go code that uses the auto-generated struct MaxAge *int json:"maxAge,omitempty":

{
    "code": 11111,
    "message": "Error occurred while parsing the request body. Check the format of the request and try again."
}

MichaelMcAleer avatar Jun 09 '22 14:06 MichaelMcAleer