Skip to content

Allow filtering and customizing exports in generated index.ts #2044

@maastrich

Description

@maastrich

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!

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions