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

methodNameBuilder no longer exposes name #1278

Open Stono opened 1 week ago

Stono commented 1 week ago

Description

Trying to upgrade to the latest version and I noticed that the signature for methodNameBuilder has changed to now just passing a single operation object.

That's fine, however the operation object doesn't appear to have name on it:

interface IROperationObject {
  body?: IRBodyObject;
  deprecated?: boolean;
  description?: string;
  id: string;
  parameters?: IRParametersObject;
  responses?: IRResponsesObject;
  // TODO: parser - add more properties
  // security?: ReadonlyArray<SecurityRequirementObject>;
  // servers?: ReadonlyArray<ServerObject>;
  summary?: string;
  tags?: ReadonlyArray<string>;
}

If i console.log the operation object out, name is there, so this just looks like an accidental omission on the type?

Reproducible example or configuration

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

OpenAPI specification (optional)

No response

System information (optional)

No response

stackblitz[bot] commented 1 week ago

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

mrlubos commented 1 week ago

I think you should be able to do if ('name' in operation) {} to narrow it down as the object is a union with the experimental parser type which you shared above

KiwiKilian commented 3 days ago

The previous name now seems to be id. So I've updated our code to this:

      {
        name: '@hey-api/services',
        methodNameBuilder: (operation) => {
          const id = operation.id;

          if (!id) {
            throw new Error('Missing operation.id');
          }

          return  //....
        },
mrlubos commented 3 days ago

@KiwiKilian the answer is, kind of? With experimental parser, each operation has a unique id. Without it, the interface is unchanged and contains name too, but you need to narrow it down since with the new types it won't be autocompleted by default