hey-api / openapi-ts

🚀 The OpenAPI to TypeScript codegen. Generate clients, SDKs, validators, and more. Support: @mrlubos
https://heyapi.dev
Other
1.39k stars 107 forks source link

Add/Create service call results in a GET request #1229

Open michaelfbradley opened 2 weeks ago

michaelfbradley commented 2 weeks ago

Description

I'm experimenting with openapi-ts in a new project, and am currently attempting to create a new organization by using the following service (fetch)

/**
 * Create an organization.
 */
export const createOrganization = <ThrowOnError extends boolean = false>(
  options: Options<CreateOrganizationData, ThrowOnError>
) => {
  return (options?.client ?? client).post<
    CreateOrganizationResponse,
    CreateOrganizationError,
    ThrowOnError
  >({
    ...options,
    url: '/v1/organizations'
  })
}

The above is invoked by the following call.

const someFunction = async () => {
    createOrganization({
      headers: {
        'Management-Set-GUID': managementSetGuid,
      },
      body: { name: restaurantInfo.managementSet?.name }
    })
      .then((response) => {
        console.log('Success', response)
      })
      .catch((error) => {
        console.error('Error', error)
      })
  }

However, the issue here is that the above call does not result in a POST requests to /organisations but rather a GET.

When console logging the request, everything seems to be in order.

Screenshot 2024-11-05 at 16 55 26

I'm at a loss to understand why the correct POST call isn't happening.

Reproducible example or configuration

https://stackblitz.com/edit/hey-api-client-fetch-example

OpenAPI specification (optional)

Relevant OpenAPI spec for organization creation

paths:
  /v1/organizations:
    post:
      summary: Create an organization.
      operationId: createOrganization
      security:
        - BearerAuth: []
      tags:
        - Organizations
      parameters:
        - name: Management-Set-GUID
          in: header
          required: true
          description: The GUID of the management set that the user is part of.
          schema:
            type: string
            format: uuid
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CreateOrganizationRequest'
      responses:
        '201':
          description: Organization created.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/OrganizationResponse'
        '400':
          description: The request is invalid.
        '401':
          description: The client is not authenticated.
        '403':
          description: The client is not authorized to perform this operation.

System information (optional)

stackblitz[bot] commented 2 weeks ago

Fix this issue in StackBlitz Codeflow Start a new pull request in StackBlitz Codeflow.

mrlubos commented 2 weeks ago

Hey @michaelfbradley, can you share a reproducible example in StackBlitz? Or at least provide more information? Everything you've shared indicates that a POST request is happening