OpenAPI-Qraft / openapi-qraft

Generate a type-safe TanStack Query React ✨ client from your OpenAPI document
https://openapi-qraft.github.io/openapi-qraft/
MIT License
31 stars 3 forks source link

Quick start from docs doesn't work #117

Closed mauriciabad closed 1 month ago

mauriciabad commented 2 months ago

Hi, I can't use the library because the quick start described in the docs doesn't work.

npx openapi-qraft --plugin tanstack-query-react --plugin openapi-typescript https://raw.githubusercontent.com/swagger-api/swagger-petstore/master/src/main/resources/openapi.yaml \
  --output-dir src/api

It gives this error:

npm error code E404
npm error 404 Not Found - GET https://registry.npmjs.org/openapi-qraft - Not found
npm error 404
npm error 404  'openapi-qraft@*' is not in this registry.
npm error 404
npm error 404 Note that you can also install from a
npm error 404 tarball, folder, http url, or git url.
npm error A complete log of this run can be found in: /Users/username/.npm/_logs/2024-07-23T22_42_02_653Z-debug-0.log

And if I change the command to @openapi-qraft/cli:

npx @openapi-qraft/cli --plugin tanstack-query-react --plugin openapi-typescript https://raw.githubusercontent.com/swagger-api/swagger-petstore/master/src/main/resources/openapi.yaml --output-dir src/api

I get this other error:

(node:7177) [DEP0040] DeprecationWarning: The `punycode` module is deprecated. Please use a userland alternative instead.
(Use `node --trace-deprecation ...` to show where the warning was created)
node:internal/modules/esm/assert:88
        throw new ERR_IMPORT_ATTRIBUTE_MISSING(url, 'type', validType);
              ^

TypeError [ERR_IMPORT_ATTRIBUTE_MISSING]: Module "file:///Users/username/.npm/_npx/09ac6d5fc70ce7ef/node_modules/@openapi-qraft/plugin/package.json" needs an import attribute of "type: json"
    at validateAttributes (node:internal/modules/esm/assert:88:15)
    at defaultLoad (node:internal/modules/esm/load:143:3)
    at async ModuleLoader.load (node:internal/modules/esm/loader:555:7)
    at async ModuleLoader.moduleProvider (node:internal/modules/esm/loader:436:45)
    at async ModuleJob._link (node:internal/modules/esm/module_job:106:19) {
  code: 'ERR_IMPORT_ATTRIBUTE_MISSING'
}

Node.js v22.2.0

Even doing it from the package.json doesn't work:

{
  "scripts": {
    "generate-client": "openapi-qraft --plugin tanstack-query-react --plugin openapi-typescript https://raw.githubusercontent.com/swagger-api/swagger-petstore/master/src/main/resources/openapi.yaml --output-dir src/api"
  },
  "devDependencies": {
    "@openapi-qraft/cli": "1.12.1"
  }
}

It also gives the ERR_IMPORT_ATTRIBUTE_MISSING error.

radist2s commented 2 months ago

@mauriciabad, thank you for the report. I've updated the documentation.

radist2s commented 2 months ago

@mauriciabad, released v1.13.0-beta.2. If you get a chance, let me know if it helped.

mauriciabad commented 2 months ago

Cool, now it works and doesn't crash.

mauriciabad commented 2 months ago

But the punycode error is still being displayed.

Screenshot 2024-08-06 at 12 15 54 PM
radist2s commented 2 months ago

Unfortunately, this warning occurs when importing openapi-typescript ==> @redocly/openapi-core ==> node-fetch ==> whatwg-url@5.0.0. node-fetch is not updated for a year, but there is a rejected PR.

mauriciabad commented 1 month ago

But fetch is available since Node.js@18 https://nodejs.org/docs/v20.16.0/api/globals.html#fetch There's no need to have the node-fetch dependency.

I'll open a issue/PR in @redocly/openapi-core to see if they can stop using node-fetch.

radist2s commented 1 month ago

@mauriciabad, thanks for the collaboration. Looking forward to updating either node-fetch or redocly/openapi-core.