Ensure that the format keyword is valid for the type defined in the schema

Ensure that the format keyword is valid for the type defined in the schema. The format keyword is an optional modifier that allows for basic semantic validation on certain kinds of data. For example, the integer type can have the format of int32 or int64, and the number type can have the format of float or double. If the format is not valid for the type, it may cause errors or inconsistencies in the API behavior.

Risk Level: medium
Platform: OpenAPI
Spectral Rule ID: OPENAPI006

REMEDIATION

Use the correct format for the type defined in the schema. Refer to the table below for the supported formats for each type:

TypeFormatDescription
integerint32Signed 32-bit integers
integerint64Signed 64-bit integers
numberfloatFloating-point numbers
numberdoubleFloating-point numbers with double precision
stringbyteBase64-encoded characters
stringbinaryAny sequence of octets
stringdateDate in ISO 8601 format
stringdate-timeDate and time in ISO 8601 format
stringpasswordA hint to UIs to obscure input
stringuuidA Universally Unique Identifier
stringemailAn email address
stringhostnameA network host name
stringipv4An IPv4 address
stringipv6An IPv6 address
# Example of parameters with valid formats

paths:
"/":
  get:
    operationId: listVersionsv2
    summary: List API versions
    responses:
      "200":
        description: 202 response
      "201":
        description: 201 response

.
.
.

    parameters:
      - name: id
        in: body
        description: ID of pet to use
        required: true
        schema:
          type: array
          items:
            type: object
            properties:
              id:
                type: string
                format: uuid
              quantity:
                type: integer
                format: int32
              percentage:
                type: number
                format: float
              result:
                type: number
                format: double
# OR

# Example of components with valid formats

components:
  schemas:
    MyObject:
      type: object
      properties:
        id:
          type: integer
          format: int64
        quantity:
          type: integer
          format: int32
        percentage:
          type: number
          format: float
        result:
          type: number
          format: double

Read more: