OpenAPI Cursor & Offset Pagination Schema Example

How to declare query parameters and response pagination wrapper metadata in OpenAPI specifications.

The problem

Collection endpoints without pagination parameters risk server timeout crashes when returning large datasets.

AvoidThe anti-pattern

YAMLbad-pattern.yaml
paths:
  /v1/orders:
    get:
      responses:
        '200':
          description: List of orders

Collection endpoint returning array without limit/offset or cursor parameters.

PreferThe refactored version

YAMLgood-pattern.yaml
paths:
  /v1/orders:
    get:
      summary: List orders with cursor pagination
      parameters:
        - name: limit
          in: query
          schema:
            type: integer
            default: 20
        - name: starting_after
          in: query
          schema:
            type: string
      responses:
        '200':
          description: Paginated orders payload
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: array
                    items:
                      $ref: '#/components/schemas/Order'
                  has_more:
                    type: boolean

Cursor-based pagination with limit and starting_after parameters.

How APIForge checks this

  • Analyzes collection endpoint parameters
  • Verifies response wrapper schemas