Search code examples
swaggerswagger-editor

Should string object property representing a number be a string or number


As stated in the title, my team always sends a response of which properties which represent float/int/bigInteger as strings, should the swagger type of those properties be number or a string?


Solution

  • The data type in your OpenAPI definition must indicate the actual data type used in the payload.

    If the response is

    {
      "id": "12345"
    }
    

    then id is a type: string property.

    You can use format and pattern (regex pattern) to clarify the value format. For example, if id strings contains non-negative integer numbers, you can define id as:

    type: string
    pattern: "^\\d+$"