Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Issue] running openapi-codegen in github actions #296

Closed
kev2480 opened this issue Feb 12, 2025 · 2 comments
Closed

[Issue] running openapi-codegen in github actions #296

kev2480 opened this issue Feb 12, 2025 · 2 comments

Comments

@kev2480
Copy link
Contributor

kev2480 commented Feb 12, 2025

Issue I'm seeing after running npx openapi-codegen gen apiClient in github actions

node:fs:453
    return binding.readFileUtf8(path, stringToFlags(options.flag));
                   ^

Error: ENOENT: no such file or directory, open '/home/runner/.npm/_npx/d0626b3472b240bf/node_modules/openapi-codegen/configs/gen.json'
    at Object.readFileSync (node:fs:453:20)
    at Object.<anonymous> (/home/runner/.npm/_npx/d0626b3472b240bf/node_modules/openapi-codegen/cg.js:80:62)
    at Module._compile (node:internal/modules/cjs/loader:1376:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1435:10)
    at Module.load (node:internal/modules/cjs/loader:1207:32)
    at Module._load (node:internal/modules/cjs/loader:10[23](https://github.com/3sidedcube-orca/psma-web/actions/runs/13269446482/job/37045377640#step:4:24):12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:135:12)
    at node:internal/main/run_main_module:28:49 {
  errno: -2,
  code: 'ENOENT',
  syscall: 'open',
  path: '/home/runner/.npm/_npx/d0626b3472b[24](https://github.com/3sidedcube-orca/psma-web/actions/runs/13269446482/job/37045377640#step:4:25)0bf/node_modules/openapi-codegen/configs/gen.json'
}
Image

This is my config:

import { generateSchemaTypes, generateReactQueryComponents } from "@openapi-codegen/typescript";
import { defineConfig } from "@openapi-codegen/cli";
import * as dotenv from "dotenv";

dotenv.config();

console.log("API Endpoint", process.env.API_ENDPOINT);

export default defineConfig({
  apiClient: {
    from: {
      source: "url",
      url: `${process.env.API_ENDPOINT}/dev/api-yaml`
    },
    outputDir: "src/generated/api",
    to: async context => {
      const filenamePrefix = "apiClient";
      const { schemasFiles } = await generateSchemaTypes(context, {
        filenamePrefix
      });
      await generateReactQueryComponents(context, {
        filenamePrefix,
        schemasFiles
      });
    }
  }
});

Github Action Job

  build:
    name: Build Project
    runs-on: ubuntu-latest
    needs: install
    steps:
      - name: Checkout Code
        uses: actions/checkout@v4
      - name: Setup Node.js
        uses: actions/setup-node@v3
        with:
          node-version: 20.11.0
          cache: "npm"
      - name: Build and Test
        run: |
          npm run api:generate
          npm run test
          npm run build
      - name: Upload Artifacts
        uses: actions/upload-artifact@v4
        with:
          name: build-artifacts
          path: |
            dist/
            coverage/

npm run api:generate script is just npx openapi-codegen gen apiClient

@fabien0102
Copy link
Owner

Looking at the logs, it seams that you are not using the correct package, if you are using npx you need the full package name so:

npx @openapi-codegen/cli gen apiClient

(openapi-codegen is the name of the binary, only available when you install the package)

@kev2480
Copy link
Contributor Author

kev2480 commented Feb 18, 2025

Thanks @fabien0102 - this looks like another issue you found, i did resolve this by ensuring i had installed npm packages in the same job . I will update to use @openapi-codegen/cli though!

@kev2480 kev2480 closed this as completed Feb 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants