Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

Support loading a config from a `openapi-codegen.config.mts` file

オープン
#334 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
52/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
静か
技術スタック
typescript
領域
cli

調査の方向性

Reproduce the failure with npx openapi-codegen -c openapi-codegen.config.mts using the configuration shown in the issue. Start at GenerateCommand.getFromOptions around lib/cli.js:282 and trace how the .mts export is loaded. Done means the module-style config loads without the workaround and generation proceeds successfully.

索引モデルが issue の本文から書いたものです。

説明

When i use the mts file extension to define my config as a module, rather than allowing it to be treated as commonjs, the loading doesnt work properly. With npx openapi-codegen -c openapi-codegen.config.mts, i see

Type Error: Cannot read properties of undefined (reading 'source')
    at GenerateCommand.getFromOptions (file:///Users/emily.klassen/code/tmp/oapi-codegen-example/node_modules/@openapi-codegen/cli/lib/cli.js:282:47)
    at Object.task (file:///Users/emily.klassen/code/tmp/oapi-codegen-example/node_modules/@openapi-codegen/cli/lib/cli.js:364:32)
    at xe (file:///Users/emily.klassen/code/tmp/oapi-codegen-example/node_modules/@clack/prompts/dist/index.mjs:79:394)
    at GenerateCommand.execute (file:///Users/emily.klassen/code/tmp/oapi-codegen-example/node_modules/@openapi-codegen/cli/lib/cli.js:359:11)
    at async GenerateCommand.validateAndExecute (file:///Users/emily.klassen/code/tmp/oapi-codegen-example/node_modules/clipanion/lib/advanced/Command.mjs:49:26)
    at async Cli.run (file:///Users/emily.klassen/code/tmp/oapi-codegen-example/node_modules/clipanion/lib/advanced/Cli.mjs:227:24)
    at async Cli.runExit (file:///Users/emily.klassen/code/tmp/oapi-codegen-example/node_modules/clipanion/lib/advanced/Cli.mjs:236:28)

To work around this, i need to change the config like

// openapi-codegen.config.mts
import { defineConfig } from "@openapi-codegen/cli";
import {
  generateSchemaTypes,
  generateReactQueryComponents,
} from "@openapi-codegen/typescript";

export const example = defineConfig({
  example: {
    // can be overridden from cli
    from: {
      source: "github",
      owner: "fabien0102",
      repository: "openapi-codegen",
      ref: "main",
      specPath: "examples/spec.yaml",
    },

    // can be overridden from cli
    outputDir: "src/queries",

    to: async (context) => {
      // You can transform the `context.openAPIDocument` here, can be useful to remove internal routes or fixing some known issues in the specs ;)

      // Generate all the schemas types (components & responses)
      const { schemasFiles } = await generateSchemaTypes(context, {
        /* config */
      });

      // Generate all react-query components
      await generateReactQueryComponents(context, {
        /* config*/
        schemasFiles,
      });
    },
  },
}).example;

The primary motivation for using an mts file is, if i have a tsconfig which uses module: 'node16', the types will not resolve properly, as "@openapi-codegen/cli" et al are esm. Otherwise, i'd have to create another tsconfig specifically to target the config, which is less than ideal.

主要言語
TypeScript
スター
634
フォーク
83
PR マージ指標
30日以内にマージされた PR はありません

環境構築

このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

fabien0102/openapi-codegen のほかの issue

fabien0102/openapi-codegen の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。