Ensure array schema should have the field `maxItems` set
Ensure that the maximum number of items in an array is defined in OpenAPI. Otherwise, the API may accept excessive or unexpected data and cause errors.
Risk Level: high
Platform: OpenAPI
Spectral Rule ID: OPENAPI003
REMEDIATION
Define the maxItems
field for the array schema.
swagger: '2.0'
# OR
openapi: '3.0.0'
info:
version: 1.0.0
title: Sample API
paths:
/users:
get:
responses:
'200':
description: A list of users.
content:
application/json:
schema:
type: array
+ maxItems: 10
items:
type: object
properties:
name:
type: string
age:
type: integer
email:
type: string
format: email
Read more:
Updated over 1 year ago