Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
michaelfbradley opened this issue Nov 5, 2024 · 2 comments
Open

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

michaelfbradley opened this issue Nov 5, 2024 · 2 comments
Labels
bug 🔥 Something isn't working info needed ❓ Further information is required

Comments

@michaelfbradley
Copy link

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)

  • MacOS
  • Chrome 130
  • NPM 9.5.1
  • Node 18.16.1
  • openapi-ts 0.54.2
@michaelfbradley michaelfbradley added the bug 🔥 Something isn't working label Nov 5, 2024
Copy link

stackblitz bot commented Nov 5, 2024

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

@mrlubos
Copy link
Member

mrlubos commented Nov 5, 2024

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

@mrlubos mrlubos added the info needed ❓ Further information is required label Nov 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🔥 Something isn't working info needed ❓ Further information is required
Projects
None yet
Development

No branches or pull requests

2 participants