Skip to content

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

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

Open
maastrich opened this issue Apr 18, 2025 · 0 comments · May be fixed by #2058
Open

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

maastrich opened this issue Apr 18, 2025 · 0 comments · May be fixed by #2058
Assignees
Labels
enhancement New feature or request
Milestone

Comments

@maastrich
Copy link

maastrich commented Apr 18, 2025

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!

@melloware melloware added the enhancement New feature or request label Apr 19, 2025
@maastrich maastrich linked a pull request Apr 22, 2025 that will close this issue
@melloware melloware modified the milestones: 7.9.0, 7.10.0 Apr 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants