orval-labs/orval

Allow filtering and customizing exports in generated index.ts

开放

#2,044 创建于 2025年4月18日

 (0 条评论) (5 个反应) (1 位负责人)TypeScript (648 个派生)auto 404
enhancementhelp wanted

仓库指标

星标
 (6,272 个星标)
PR 合并指标
 (平均合并 2天 15小时) (30 天内合并 73 个 PR)

描述

Description

Currently, when Orval generates code, it automatically exports everything from the generated index.ts file. There's no way to:

  1. Filter out specific exports (e.g., schemas)
  2. Append custom exports from other files
  3. Control what gets exported from the generated index.ts

Use Case

In our project, we need to:

  • Exclude schema exports from the generated index.ts file to avoid polluting the public API
  • Append exports from our custom files to the generated index.ts
  • Have more granular control over what gets exported from the generated code

Current Behavior

The generated index.ts automatically exports everything:

export * from './schemas';
export * from './endpoints';
// ... other exports

Desired Behavior

Ability to configure exports in orval.config.js:

module.exports = {
  myApi: {
    output: {
      // ... other config
      indexFiles(statements) {
        // note that this is merely an idea, I guess it should be more "precise"
        const exports = statementes.filter((name) => name !== "./schemas")
        exports.push("./custom-files")
        return exports;
      }
    }
  }
}

Benefits

  1. Better control over the public API surface
  2. Ability to keep schemas internal when needed
  3. Easier integration with custom code
  4. More flexible code organization

Additional Context

This would be particularly useful for larger projects especially when we generate multiple clients at once, we use package json exports to separate msw, axios, react, and zod client and I want to expose the schemas from one entry only (instead of all of them) Further more I have custom zod schemas generated on top of orval's output (using the extraFiles feature) and would like to export them from the generated client (automatically)

Possible Implementation Approaches

  1. Add an exports configuration option in the output config
  2. Support glob patterns for include/exclude
  3. Allow specifying additional files to export from

Would love to hear thoughts on the best approach to implement this!

贡献者指南