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:
Type | Format | Description |
---|---|---|
integer | int32 | Signed 32-bit integers |
integer | int64 | Signed 64-bit integers |
number | float | Floating-point numbers |
number | double | Floating-point numbers with double precision |
string | byte | Base64-encoded characters |
string | binary | Any sequence of octets |
string | date | Date in ISO 8601 format |
string | date-time | Date and time in ISO 8601 format |
string | password | A hint to UIs to obscure input |
string | uuid | A Universally Unique Identifier |
string | An email address | |
string | hostname | A network host name |
string | ipv4 | An IPv4 address |
string | ipv6 | An 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:
Updated about 1 year ago