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

Using Operation object with the methodNameGenarator #695

Closed anchan828 closed 5 days ago

anchan828 commented 1 week ago

Description

The argument of the methodNameGenarator added in #663 is operationId, but it is actually the operationName by converted operationId to camelCase. If possible, I would like to use the raw operationId.

However, when reading the code, Operation does not have an operationId.

Is it possible to retain the operationId and use it in the methodNameGenerator?

Although, I have read this comment and understand that using operationName for consistency. https://github.com/hey-api/openapi-ts/pull/663#discussion_r1632639760 So I think it would be good to change the argument name to "operationName" and clearly state that it has been converted to camelCase. However, there is a concern that the name may be changed in the future for rational reasons.

Related issue: #535


OAS

openapi: 3.0.0
info:
  title: Test

tags:
  - name: Tag

components:
  schemas:
    Tag:
      type: object
      properties:
        id:
          type: string
      required:
        - id
paths:
  /api/tag:
    get:
      operationId: Tag_get
      parameters:
        - name: test
          in: path
          description: description
          required: true
          schema:
            type: string
          example: example
      responses:
        "200":
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Tag"
      tags:
        - Tag

Config

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

export default defineConfig({
  input: './openapi.yml',
  output: './client',
  services: {
    methodNameBuilder: (service: string, operationId: string): string => {
      // actual: { service: 'Tag', operationId: 'tagGet' }
      // expect: { service: 'Tag', operationId: 'Tag_get' }
      console.log({ service, operationId });
      return operationId;
    },
    asClass: true,
    operationId: true,
  },
  name: 'ApiClient',
});

Stackblitz

https://stackblitz.com/edit/hey-api-example-sik3vs?file=openapi-ts.config.ts

stackblitz[bot] commented 1 week ago

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