Skip to content

Is a fractional part of ".0" allowed for integers? #2976

Closed

Description

@mkauf

Please clarify: Are values like 1.0 valid for the integer data type?

JSON schema allows values like 1.0 for integers. But the OpenAPI specification contains this sentence:

Note that integer as a type is also supported and is defined as a JSON number without a fraction or exponent part.

"without a fraction or exponent part" - does that mean that the number is not allowed to have a fraction part at all, e.g. 1 is valid but 1.0 is invalid? Or does it mean that a fraction of 0 is allowed, so 1 is valid and 1.0 is also valid?

Are the rules the same for JSON parameters and for query parameters?

For example, consider this OpenAPI specification:

{
    "openapi": "3.0.0",
    "info": {
        "title": "Integers",
        "version": "1.0"
    },
    "paths": {
        "/path1": {
            "post": {
                "requestBody": {
                    "content": {
                        "application/json": {
                            "schema": {
                                "type": "object",
                                "properties": {
                                    "value": {
                                        "type": "integer"
                                    }
                                }
                            }
                        }
                    }
                },
                "responses": {
                    "default": {
                        "description": "test"
                    }
                }
            }
        },
        "/path2": {
            "get": {
                "parameters": [
                    {
                        "in": "query",
                        "name": "a",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "default": {
                        "description": "test"
                    }
                }
            }
        }
    }
}

Are these requests valid?

  • Request 1:
curl -H "Content-Type: application/json" --data '{ "value": 1.0 }' 'http://localhost/path1'
  • Request 2:
curl 'http://localhost/path2?a=1.0'

Activity

  1. locked and limited conversation to collaborators on Jul 21, 2022
  2. converted this issue into a discussion #2977 on Jul 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions