hey-api / openapi-ts

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

sdk.gen.ts imports nonexistent OptionsLegacyParser #1346

Open chrisranderson opened 4 days ago

chrisranderson commented 4 days ago

Description

sdk.gen.ts includes this line:

import { createClient, createConfig, type OptionsLegacyParser } from '@hey-api/client-fetch';

tsc fails for me:

❯ tsc        
src/generatedClient/sdk.gen.ts:3:43 - error TS2305: Module '"@hey-api/client-fetch"' has no exported member 'OptionsLegacyParser'.

3 import { createClient, createConfig, type OptionsLegacyParser } from '@hey-api/client-fetch';
                                            ~~~~~~~~~~~~~~~~~~~
Found 1 error in src/generatedClient/sdk.gen.ts:3

Sharing some basics in case it's an obvious fix, I can provide more info if needed.

Reproducible example or configuration

No response

OpenAPI specification (optional)

3.1.0

System information (optional)

Relevant snippets from package-lock.json:


    "node_modules/@hey-api/client-fetch": {
      "version": "0.4.1",
      "resolved": "https://registry.npmjs.org/@hey-api/client-fetch/-/client-fetch-0.4.1.tgz",
      "integrity": "sha512-dQ53vyuszaMptG4SguWxTdDwZsbhQzg7OVyTPTHnOYMtIbITfg739dz5iR7xh5tkCCWidQnkU8VOXygUx94mWA==",
      "license": "MIT",
      "funding": {
        "url": "https://github.com/sponsors/mrlubos"
      }
    },
    "node_modules/@hey-api/openapi-ts": {
      "version": "0.53.10",
      "resolved": "https://registry.npmjs.org/@hey-api/openapi-ts/-/openapi-ts-0.53.10.tgz",
      "integrity": "sha512-FHtUBiP0uMKxgdzEsaCR2IHHRR7v+SC7adgQ/gk5H4vh+30HN2NxIObXL+sy0VFvk+WwgzcL0pcZWbEiRXFMpg==",
      "dev": true,
      "license": "FSL-1.1-MIT",
      "dependencies": {
        "@apidevtools/json-schema-ref-parser": "11.7.0",
        "c12": "2.0.1",
        "commander": "12.1.0",
        "handlebars": "4.7.8"
      },
      "bin": {
        "openapi-ts": "bin/index.cjs"
      },
      "engines": {
        "node": "^18.0.0 || >=20.0.0"
      },
      "funding": {
        "url": "https://github.com/sponsors/mrlubos"
      },
      "peerDependencies": {
        "typescript": "^5.x"
      }
    },
❯ npm --version
10.8.3

❯ node --version
v22.9.0
chrisranderson commented 4 days ago

I'll add stuff here as I learn more:

❯ tsc
src/generatedClient/services.gen.ts:11:84 - error TS2344: Type 'UpdateEntryData' does not satisfy the constraint '{ url: string; }'.
  Property 'url' is missing in type 'UpdateEntryData' but required in type '{ url: string; }'.

11 export const updateEntry = <ThrowOnError extends boolean = false>(options: Options<UpdateEntryData, ThrowOnError>) => {
                                                                                      ~~~~~~~~~~~~~~~

  node_modules/@hey-api/client-fetch/dist/index.d.ts:163:5
    163     url: string;
            ~~~
    'url' is declared here.
chrisranderson commented 4 days ago

@mrlubos This might be related to this commit?

https://github.com/hey-api/openapi-ts/commit/734a62dd8d594b8266964fe16766a481d37eb7df#diff-941d4b5df0df7de2b988213222747c24d5b9e5a4d79384b26ab2d022cb5e1f50R112

mrlubos commented 4 days ago

Hey @chrisranderson, yes. Broadly, you should be able to resolve these by following the migration notes for v0.57.0 and upgrading both packages to the latest version. In your comment with 8 errors, I see the services.gen.ts file reference. This file should be deleted and any imports updated, see https://heyapi.dev/openapi-ts/migrating.html#changed-sdk-output-value. One thing I did not note in the migration notes but this might not be affecting you, if you import UpdateEntryData in your code, you'd need to omit url from it to avoid seeing new errors, e.g. Omit<UpdateEntryData, 'url'> to get the same type as before. Let me know if this helps!

rpatidar commented 4 days ago

this should be backward compatible ? or may be the command we run that pull the latest version causing this errors ?

 npx @hey-api/openapi-ts -i http://localhost:8081/openapi.json  -o src/common/api/services/backend-v2  -c @hey-api/client-axios

i only have

    "@hey-api/client-axios": "^0.2.8",
chrisranderson commented 4 days ago

@mrlubos thanks for the recommendations. What got things working for me:

Sorry, I tried multiple things at once so I'm not sure which of those finally did the trick.

mrlubos commented 4 days ago

@chrisranderson sounds like the issue is resolved now?

mrlubos commented 4 days ago

@rpatidar you'd need to update to the latest version, it doesn't detect which client version you're on and base the output on that... maybe will add it later

mrlubos commented 4 days ago

@chrisranderson I think we should be wiping the whole folder on every run, that would have helped here a bit

mrlubos commented 4 days ago

Created https://github.com/hey-api/openapi-ts/issues/1347, it will be the default so nothing to do from your side. Thank you for the sponsorship @chrisranderson!