hey-api / openapi-ts

✨ Turn your OpenAPI specification into a beautiful TypeScript client
https://heyapi.vercel.app
MIT License
635 stars 44 forks source link

client-fetch: array of string in body unsupported #673

Closed mlankamp closed 2 weeks ago

mlankamp commented 2 weeks ago

Description

When I use the @hey-api/client-fetch client, and the request body is an array of string there is a typescript error:

Argument of type '{ url: string; headers?: Record<string, unknown> | HeadersInit | undefined; method?: "CONNECT" | "DELETE" | "GET" | "HEAD" | "OPTIONS" | "PATCH" | "POST" | "PUT" | "TRACE" | undefined; ... 19 more ...; body?: string[] | undefined; }' is not assignable to parameter of type 'RequestOptionsBase'.
  Types of property 'body' are incompatible.
    Type 'string[] | undefined' is not assignable to type 'Record<string, unknown> | BodyInit | Record<string, unknown>[] | null | undefined'.
      Type 'string[]' is not assignable to type 'Record<string, unknown> | BodyInit | Record<string, unknown>[] | null | undefined'.
        Type 'string[]' is not assignable to type 'Record<string, unknown>[]'.
          Type 'string' is not assignable to type 'Record<string, unknown>'.

OpenAPI specification (optional)

openapi: 3.0.1
info:
  title: Testing
  version: v1
paths:
  '/demo/{id}':
    post:
      tags:
        - Testing
      operationId: DeleteMultiple
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: string
            format: uuid
      requestBody:
        content:
          application/json:
            schema:
              type: array
              items:
                type: string
                format: uuid
      responses:
        '204':
          description: No Content

Configuration

import { defineConfig } from '@hey-api/openapi-ts';

export default defineConfig({
  input: 'source/swagger.yaml',
  output: {
    path: 'output',
    format: false,
    lint: false
  } ,
  client: '@hey-api/client-fetch',
  schemas: false,
  types: {
    enums: 'javascript'
  },
  services: {
    asClass: true,
  }
});

System information (optional)

See: https://github.com/mlankamp/openapi

Probable solution: add Array<unknown> to https://github.com/hey-api/openapi-ts/blob/d9372335368015aeed63b9a88d066f19fc6d3d57/packages/client-fetch/src/types.ts#L22