Skip to content

@tanstack/react-query with pagination keywords causes type error #2232

Open
@FredrikErikJohansson

Description

@FredrikErikJohansson

Description

While combining custom pagination keywords and tanstack query plugin:

pagination: {
  keywords: ['pageSize', 'pageToken'],
  plugins: ['@tanstack/react-query']
},

The generated react-query code has type errors due to wrong casing:

query: {
    pagesize: pageParam, // Should be pageSize
},

Reproducible example or configuration

https://stackblitz.com/edit/hey-api-client-fetch-example-pbmmlfen?file=src%2Fclient%2F%40tanstack%2Freact-query.gen.ts

OpenAPI specification (optional)

openapi: 3.1.0
info:
  title: Test API - Minimal Pagination Example
  description: A minimal API example demonstrating pagination with pageSize and pageToken
  version: 1.0.0
servers:
  - url: https://api.example.com
    description: Example server

tags:
  - name: Items
    description: Test items operations

paths:
  /test/v1/items:
    get:
      summary: List items
      description: |
        Retrieve a paginated list of test items.

        This endpoint demonstrates pagination using:
        - `pageSize`: Controls how many items are returned per page (1-100, default 20)
        - `pageToken`: Used to fetch subsequent pages of results

        The response includes a `nextPageToken` when more results are available.
      operationId: listItems
      tags:
        - Items
      parameters:
        - name: pageSize
          in: query
          description: Maximum number of items to return per page
          required: false
          schema:
            type: integer
            minimum: 1
            maximum: 100
            default: 20
          example: 10
        - name: pageToken
          in: query
          description: |
            Token for the specific page to return. 
            Use the `nextPageToken` from a previous response to get the next page.
            Omit this parameter to get the first page.
          required: false
          schema:
            type: string
          example: 'eyJhZnRlciI6Iml0ZW0tMTIzIiwibGltaXQiOjEwfQ'
      responses:
        '200':
          description: Paginated list of items
          content:
            application/json:
              schema:
                type: object
                properties:
                  items:
                    type: array
                    items:
                      $ref: '#/components/schemas/Item'
                    description: Array of item objects for the current page
                  nextPageToken:
                    type: string
                    description: |
                      Token to retrieve the next page of results.
                      This field is omitted when there are no more pages.
                    nullable: true
                  totalCount:
                    type: integer
                    description: Total number of items available (optional)
                    example: 150
                required:
                  - items
              examples:
                first_page:
                  summary: First page with next page available
                  value:
                    items:
                      - id: 'item-001'
                        name: 'Test Item Alpha'
                        description: 'First test item for demonstration'
                        version: '1.0.0'
                        createdAt: '2024-03-20T10:00:00Z'
                        updatedAt: '2024-03-20T10:00:00Z'
                      - id: 'item-002'
                        name: 'Test Item Beta'
                        description: 'Second test item for demonstration'
                        version: '1.0.0'
                        createdAt: '2024-03-21T10:00:00Z'
                        updatedAt: '2024-03-21T10:00:00Z'
                    nextPageToken: 'eyJhZnRlciI6Iml0ZW0tMDAyIiwibGltaXQiOjEwfQ'
                    totalCount: 150
                last_page:
                  summary: Last page with no more results
                  value:
                    items:
                      - id: 'item-149'
                        name: 'Test Item Omega'
                        description: 'Last test item in the collection'
                        version: '1.0.0'
                        createdAt: '2024-06-20T10:00:00Z'
                        updatedAt: '2024-06-20T10:00:00Z'
                    totalCount: 150
        '400':
          $ref: '#/components/responses/BadRequest'
        '500':
          $ref: '#/components/responses/InternalServerError'
components:
  responses:
    BadRequest:
      description: Invalid request parameters
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          examples:
            invalid_page_size:
              summary: Invalid pageSize parameter
              value:
                error: 'pageSize must be between 1 and 100'
            invalid_page_token:
              summary: Invalid pageToken parameter
              value:
                error: 'Invalid pageToken format'

    InternalServerError:
      description: Internal server error
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            error: 'Internal server error. Please try again later.'

  schemas:
    Error:
      type: object
      description: Standard error response
      properties:
        error:
          type: string
          description: Error message describing what went wrong
      required:
        - error

    Item:
      type: object
      description: A test item
      properties:
        id:
          type: string
          description: Unique identifier for the item
          example: 'item-001'
        name:
          type: string
          description: Name of the test item
          example: 'Test Item Alpha'
        description:
          type: string
          description: Detailed description of the item
          example: 'First test item for demonstration'
        version:
          type: string
          description: Version of the item
          example: '1.0.0'
        createdAt:
          type: string
          format: date-time
          description: Timestamp when the item was created
          example: '2024-03-20T10:00:00Z'
        updatedAt:
          type: string
          format: date-time
          description: Timestamp when the item was last updated
          example: '2024-03-20T10:00:00Z'
      required:
        - id
        - name
        - description
        - version
        - createdAt
        - updatedAt

System information (optional)

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug 🔥Something isn't workingprioritized 🚚This issue has been prioritized and will be worked on soon

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions