Skip to content

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

@mkauf

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'

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