-
-
Notifications
You must be signed in to change notification settings - Fork 503
feat: allow index files customization #2058
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,6 +3,7 @@ import { | |
| ConfigExternal, | ||
| createLogger, | ||
| FormDataArrayHandling, | ||
| GeneratorSchema, | ||
| GlobalMockOptions, | ||
| GlobalOptions, | ||
| HonoOptions, | ||
|
|
@@ -24,14 +25,15 @@ import { | |
| NormalizedMutator, | ||
| NormalizedOperationOptions, | ||
| NormalizedOptions, | ||
| NormalizedOutputIndexFiles, | ||
| NormalizedOverrideOutput, | ||
| NormalizedQueryOptions, | ||
| OperationOptions, | ||
| OptionsExport, | ||
| OutputClient, | ||
| OutputHttpClient, | ||
| OutputIndexFiles, | ||
| OutputMode, | ||
| OutputOptions, | ||
| OverrideOutput, | ||
| PropertySortOrder, | ||
| QueryOptions, | ||
|
|
@@ -196,7 +198,7 @@ export const normalizeOptions = async ( | |
| tsconfig, | ||
| packageJson, | ||
| headers: outputOptions.headers ?? false, | ||
| indexFiles: outputOptions.indexFiles ?? true, | ||
| indexFiles: normalizeIndexFiles(outputOptions.indexFiles), | ||
| baseUrl: outputOptions.baseUrl, | ||
| unionAddMissingProperties: | ||
| outputOptions.unionAddMissingProperties ?? false, | ||
|
|
@@ -430,6 +432,24 @@ export const normalizePath = <T>(path: T, workspace: string) => { | |
| return upath.resolve(workspace, path); | ||
| }; | ||
|
|
||
| const normalizeIndexFiles = ( | ||
| indexFiles: OutputIndexFiles | boolean | undefined = true, | ||
| ): NormalizedOutputIndexFiles => { | ||
| if (isBoolean(indexFiles)) { | ||
| return indexFiles | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add a const |
||
| ? { | ||
| workspace: (implementations: string[]) => implementations, | ||
| schemas: (schemas: GeneratorSchema[]) => schemas, | ||
| } | ||
| : false; | ||
| } | ||
| return { | ||
| workspace: (implementations: string[]) => implementations, | ||
| schemas: (schemas: GeneratorSchema[]) => schemas, | ||
| ...indexFiles, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If a user puts {
schemas: undefined
}in the config, we will get undefined here. I'd suggest doing something like const defaultIndex = {
workspace: (implementations: string[]) => implementations,
schemas: (schemas: GeneratorSchema[]) => schemas,
};
return {
workspace: indexFiles.workspace ?? defaultIndex.workspace,
schemas: indexFiles.schemas ?? defaultIndex.schemas,
}; |
||
| }; | ||
| }; | ||
|
|
||
| const normalizeOperationsAndTags = ( | ||
| operationsOrTags: { | ||
| [key: string]: OperationOptions; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| import { defineConfig } from 'orval'; | ||
|
|
||
| export default defineConfig({ | ||
| reactQuery: { | ||
| input: '../specifications/petstore.yaml', | ||
| output: { | ||
| client: 'react-query', | ||
| mode: 'tags-split', | ||
| schemas: '../models', | ||
| target: './will-not-exists.ts', | ||
| workspace: '../generated/multi-client/react-query', | ||
| indexFiles: { | ||
| workspace(implementations) { | ||
| return implementations.filter((impl) => !impl.includes('models')); | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| zod: { | ||
| input: '../specifications/petstore.yaml', | ||
| output: { | ||
| client({ zod }) { | ||
| return { | ||
| title: zod.title, | ||
| footer: zod.footer, | ||
| client: zod.client, | ||
| header: zod.header, | ||
| dependencies: zod.dependencies, | ||
| async extraFiles(verbOptions, output, context) { | ||
| return [ | ||
| ...(zod.extraFiles | ||
| ? await zod.extraFiles(verbOptions, output, context) | ||
| : []), | ||
| { | ||
| path: context.output.workspace + '/extrafiles/index.ts', | ||
| content: 'export * from "./file1";\nexport * from "./file2";\n', | ||
| exposeIndexFile: true, | ||
| }, | ||
| { | ||
| path: context.output.workspace + '/extrafiles/file1.ts', | ||
| content: 'export const extraFile1 = "extraFile1"', | ||
| }, | ||
| { | ||
| path: context.output.workspace + '/extrafiles/file2.ts', | ||
| content: 'export const extraFile2 = "extraFile2"', | ||
| }, | ||
| ]; | ||
| }, | ||
| }; | ||
| }, | ||
| mode: 'tags-split', | ||
| schemas: '../models', | ||
| target: './will-not-exists.ts', | ||
| workspace: '../generated/multi-client/zod', | ||
| indexFiles: { | ||
| workspace(implementations) { | ||
| return implementations.filter((impl) => !impl.includes('models')); | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't need to have the default value of the param here