orval icon indicating copy to clipboard operation
orval copied to clipboard

feat: allow index files customization

Open maastrich opened this issue 7 months ago • 4 comments

Status

READY

Related

Fix https://github.com/orval-labs/orval/issues/2044

Description

add a way to customize index files:

export default defineConfig({
  output: {
    // ....rest of the config
    indexFiles: {
      schema: (schema) => schemaPaths.filter(schema => schema.name === "Dog"),
      workspace: (implementationPaths) => implementationPaths.filter(path => path.includes('do-not-expose-this-file')),
    },
  },
});

add a way to expose custom files:

export default defineConfig({
  output: {
    // ....rest of the config
    client() {
        return {
            // ... client definition
            extraFiles() {
                return [
                    {
                        path: 'src/file-to-expose.ts',
                        content: 'export default function () {}',
                        exposeIndexFile: true,
                    },
                    {
                        path: 'src/file-to-not-expose.ts',
                        content: 'export default function () {}',
                        exposeIndexFile: false,
                    },
                    {
                        path: 'src/file-to-not-expose-2.ts',
                        content: 'export default function () {}',
                    }
                ]
            }
        }
    }
});

Steps to Test or Reproduce

> git pull --prune
> git checkout feat/customize-index-files
> grunt jasmine
> yarn
> yarn build
> cd tests
> yarn
> yarn generate:multi-client
  1. check generated clients in generated/multi-client/*
  2. check index.ts in each client, it should only include files that were exposed (no models)
  3. check zod client and see exports for ./extrafiles/index

maastrich avatar Apr 22 '25 21:04 maastrich

I've an update for the readme if you want me to add it in the pull request 👀

maastrich avatar Apr 22 '25 21:04 maastrich

Sure

melloware avatar Apr 22 '25 23:04 melloware

Hey @melloware, I've pushed it with my last commit https://github.com/orval-labs/orval/pull/2058/commits/b1b956fe66cc3680227d985b52eb5a84152126e3

maastrich avatar Apr 23 '25 11:04 maastrich

OK i have added some others for review

melloware avatar Apr 23 '25 14:04 melloware