api
api copied to clipboard
Running with a project that uses `yarn` creates a `package-lock.json` file
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.ts
api currently doesn't support Yarn but it's on our immediate roadmap.
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?
There was actually a bug that was preventing the installed API in .api/.apis/ from being hooked up into your package.json. If you re-install that API @api/basiq will be added to your package.json so you can import it.
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:
➜ npx api install @basiq/v3.0#73eilabzsv3b
Need to install the following packages:
api
Ok to proceed? (y)
✔ 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!
flux/packages/api-service …
✘130 ➜ yarn
yarn install v1.22.18
warning package-lock.json found. Your project contains lock files generated by tools other than Yarn. It is advised not to mix package managers in order to avoid resolution inconsistencies caused by unsynchronized lock files. To clear this warning, remove package-lock.json.
[1/4] 🔍 Resolving packages...
error Can't add "@api/basiq": invalid package version "".
info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.
flux/packages/api-service …
✘1 ➜ rm package-lock.json
flux/packages/api-service …
➜ yarn
yarn install v1.22.18
[1/4] 🔍 Resolving packages...
error Can't add "@api/basiq": invalid package version "".
info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.
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?
Seems this is happening because we aren't setting a version property in the package.json we create for the installed API in the .apis/ directory. I'll get a fix going for this.
@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.
@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:
- Execute
pnpm dlx api install @render-api/v1.0#f084kp1glacw8qb7and say yes to package installation - Cancel once the
.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 ) - Create
pnpm-workspace.yaml(pnpm doesn't handle dependency installation well for locally linked packages)packages: - ".api/apis/*" - Add the api package as a workspace dependency in the root
package.json"dependencies": { "@api/render-api": "workspace:*" } - Run
pnpm installand the package should be importable now
However, 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).
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 install from inside of an NPM workspace directory like packages/client it thinks you use Yarn. I've filed the bug to https://github.com/zkochan/packages/issues/180 but am unfortunately going to have to put Yarn and pnpm on hold until that's sorted out.