Repository navigation
Labels
area:apiIssues related to the `api` CLI, which builds the SDKsenhancementNew feature or requestgood first issueGood for newcomershelp wantedExtra attention is needed
Description
It seems like this script does not respect projects that use yarn and instead will always create a package-lock file. Here is the outcome from running it on my project:
➜ npx api install @basiq/v3.0#73eilabzsv3b
✔ What language would you like to generate an SDK for? › TypeScript
✔ Fetching your API
✔ Generating your SDK
✔ Saving your SDK into your codebase
⚠ This generator requires some packages to be installed alongside it:
› api: Required for the `api/dist/core` library that the codegen''d SDK uses for making requests. https://npm.im/api
› json-schema-to-ts: Required for TypeScript type handling. https://npm.im/json-schema-to-ts
› oas: Used within `api/dist/core` and is also loaded for TypeScript types. https://npm.im/oas
✔ OK to proceed with package installation? … yes
✔ Installing required packages
🚀 All done!
➜ git status
On branch basiq-connect
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
modified: yarn.lock
Untracked files:
(use "git add <file>..." to include in what will be committed)
.api/
package-lock.json
no changes added to commit (use "git add" and/or "git commit -a")I am not sure why the package-lock.json file is there at all - I don't think it will do anything since I am using yarn.
Furthermore I also am not sure how I would go about importing the downloaded SDK. I can see the files under ./.api but there is nothing in the documentation instructing me on how to consume them. Do I need to add a local file entry to package.json?
➜ tree -L 3 .api
.api
├── api.json
└── apis
└── basiq
├── index.ts
├── node_modules
├── openapi.json
├── package-lock.json
├── package.json
├── schemas.ts
└── types.tsReacted by xinbenlv
Reacted by xinbenlv
Metadata
Metadata
Assignees
Labels
area:apiIssues related to the `api` CLI, which builds the SDKsenhancementNew feature or requestgood first issueGood for newcomershelp wantedExtra attention is needed
Activity
erunion commentedon Nov 25, 2022
apicurrently doesn't support Yarn but it's on our immediate roadmap.There was actually a bug that was preventing the installed API in
.api/.apis/from being hooked up into yourpackage.json. If you re-install that API@api/basiqwill be added to yourpackage.jsonso you can import it.gugahoi commentedon Nov 28, 2022
Thanks for fixing the consumption part, however I am still having some problems and I am not sure if they are due to the API spec that I am trying to consume or something missing from this package. Following is the terminal output:
As you can see, yarn complains about the installed api sdk due to a missing version. I can manually rectify this locally but I don't think this is the correct way to approach this. Is the problem on my end? On the API spec I am consuming? Or is this still a bug?
erunion commentedon Nov 28, 2022
Seems this is happening because we aren't setting a
versionproperty in thepackage.jsonwe create for the installed API in the.apis/directory. I'll get a fix going for this.erunion commentedon Nov 28, 2022
@gugahoi That issue should now be resolved in v5.0.3.
I'll see if I can carve out some time this week to prioritize Yarn support.
haltcase commentedon Dec 2, 2022
@erunion similarly, it would be nice to have support for pnpm, but it could be more complicated. What ended up working for me as a workaround was to:
pnpm dlx api install @render-api/v1.0#f084kp1glacw8qb7and say yes to package installation.api/apis/render-api/package.jsonfile is updated with dependencies ( this wasn't perfect — I had to manually addopenapi-typesas it was missing, might have been timing but I'm not sure yet )pnpm-workspace.yaml(pnpm doesn't handle dependency installation well for locally linked packages)package.jsonpnpm installand the package should be importable nowHowever, I wonder if it would be worth looking into how Prisma generates its client since that works rather well across package managers in my experience. You'd have to regenerate the API package in fresh directories though (since it's dropped into
node_modules).erunion commentedon Oct 18, 2023
Dug into this a bit after discovering preferred-pm and that's got a pretty big blocker for us where if we you run
npx api installfrom inside of an NPM workspace directory likepackages/clientit thinks you use Yarn. I've filed the bug to zkochan/packages#180 but am unfortunately going to have to put Yarn and pnpm on hold until that's sorted out.EugenGedroyc commentedon Jan 25, 2024
I use ynpx and get the same problems
answer received
phorcys420 commentedon Jan 21, 2025
While this issue seems to have been fixed, I think you might be better off by relying on Corepack's
packageManagerfield in thepackage.json.If you don't use Corepack, it's harmless, and it's a pretty simple config too.
For context, I'm running into this issue with Bun by using
bunx(npxequivalent).