ferdikoomen / openapi-typescript-codegen

NodeJS library that generates Typescript or Javascript clients based on the OpenAPI specification
MIT License
2.95k stars 524 forks source link

command not found: openapi #1919

Open cartoon2541 opened 11 months ago

cartoon2541 commented 11 months ago

I install via command

npm install openapi-typescript-codegen --save-dev

in my project, and then i call openapi --help

I got sh: command not found: openapi

my project is nextjs and my dependencies look like

"dependencies": {
    "@ant-design/cssinjs": "^1.17.0",
    "@headlessui/react": "^1.7.17",
    "@heroicons/react": "^2.0.18",
    "@ionic/react": "^7.5.4",
    "@ionic/react-router": "^7.5.4",
    "@tailwindcss/forms": "^0.5.6",
    "@types/antd": "^1.0.0",
    "antd": "^5.9.4",
    "axios": "^1.5.1",
    "dayjs": "^1.11.10",
    "i18next": "^23.5.1",
    "ionicons": "^7.2.1",
    "js-cookie": "^3.0.5",
    "next": "^13.5.6",
    "rc-select": "^14.10.0",
    "react": "^18",
    "react-dom": "^18",
    "react-i18next": "^13.2.2"
  },
"devDependencies": {
    "@tailwindcss/typography": "^0.5.10",
    "@types/js-cookie": "^3.0.5",
    "@types/node": "^20",
    "@types/react": "^18.2.25",
    "@types/react-dom": "^18.2.11",
    "autoprefixer": "^10",
    "eslint": "^8",
    "eslint-config-next": "13.5.4",
    "openapi-typescript-codegen": "^0.25.0",
    "postcss": "^8",
    "tailwindcss": "^3",
    "typescript": "^5"
  }

how can i do ?

funny-cat-happy commented 11 months ago

openapi is not a global cammand. It is not a exe file.It must depend on node to run. So you have two choices. First, you can run it by npx openapi-typescript-codegen --help. Second, you can write it to package.json like following:

"scripts": {
    "dev": "vite",
    "build": "run-p type-check \"build-only {@}\" --",
    "preview": "vite preview",
    "build-only": "vite build",
    "type-check": "vue-tsc --noEmit -p tsconfig.app.json --composite false",
    "lint": "eslint . --ext .vue,.js,.jsx,.cjs,.mjs,.ts,.tsx,.cts,.mts --fix --ignore-path .gitignore",
    "format": "prettier --write src/",
    "codegen": "openapi --input ./openapi.json --output ./src/api-services"
  },

And run it by npm run codegen