fork of hey-api/openapi-ts because I need some additional things
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

fix: pass default value to output header function

Lubos c076e4d3 83fec670

+52 -14
+5
.changeset/brown-owls-flow.md
··· 1 + --- 2 + "@hey-api/shared": patch 3 + --- 4 + 5 + **utils**: `outputHeaderToPrefix()` function signature change
+5
.changeset/weak-onions-flash.md
··· 1 + --- 2 + "@hey-api/openapi-ts": patch 3 + --- 4 + 5 + **output**: pass default value to `header` function
-1
packages/openapi-python/src/config/output/config.ts
··· 24 24 name: '{{name}}', 25 25 suffix: '_gen', 26 26 }, 27 - header: '# This file is auto-generated by @hey-api/openapi-python', 28 27 path: '', 29 28 postProcess: [], 30 29 preferExportAll: false,
+6 -1
packages/openapi-python/src/createClient.ts
··· 107 107 eventInputPatch.timeEnd(); 108 108 109 109 const eventParser = logger.timeEvent('parser'); 110 + const header = config.output.header; 110 111 // TODO: allow overriding via config 111 112 const project = new Project({ 112 113 defaultFileName: '__init__', ··· 125 126 : undefined, 126 127 renderers: [ 127 128 new PythonRenderer({ 128 - header: config.output.header, 129 + header: (ctx) => { 130 + const defaultValue = ['# This file is auto-generated by @hey-api/openapi-python']; 131 + const result = typeof header === 'function' ? header({ ...ctx, defaultValue }) : header; 132 + return result === undefined ? defaultValue : result; 133 + }, 129 134 preferExportAll: config.output.preferExportAll, 130 135 preferFileExtension: config.output.importFileExtension || undefined, 131 136 resolveModuleName: config.output.resolveModuleName,
+5 -1
packages/openapi-python/src/generate/client.ts
··· 154 154 project: IProject; 155 155 }): Map<string, string> | undefined { 156 156 const renamed = new Map<string, string>(); 157 - const headerPrefix = outputHeaderToPrefix(header, project); 157 + const headerPrefix = outputHeaderToPrefix({ 158 + defaultValue: ['# This file is auto-generated by @hey-api/openapi-python'], 159 + header, 160 + project, 161 + }); 158 162 159 163 // copy Hey API clients to output 160 164 const isHeyApiClientPlugin = plugin.name.startsWith('@hey-api/client-');
+3 -2
packages/openapi-python/src/py-dsl/utils/render.ts
··· 11 11 preferExportAll?: boolean; 12 12 }; 13 13 type Header = MaybeArray<string> | null | undefined; 14 + type HeaderArg = MaybeFunc<(ctx: RenderContext<PyDsl>) => Header>; 14 15 type Imports = Array<ReadonlyArray<ModuleImport>>; 15 16 16 17 function headerToLines(header: Header): ReadonlyArray<string> { ··· 32 33 * 33 34 * @private 34 35 */ 35 - private _header?: MaybeFunc<(ctx: RenderContext<PyDsl>) => Header>; 36 + private _header?: HeaderArg; 36 37 /** 37 38 * Whether `export * from 'module'` should be used when possible instead of named exports. 38 39 * ··· 54 55 55 56 constructor( 56 57 args: { 57 - header?: MaybeFunc<(ctx: RenderContext<PyDsl>) => Header>; 58 + header?: HeaderArg; 58 59 preferExportAll?: boolean; 59 60 preferFileExtension?: string; 60 61 resolveModuleName?: (moduleName: string) => string | undefined;
-1
packages/openapi-ts/src/config/output/config.ts
··· 36 36 suffix: '.gen', 37 37 }, 38 38 format: null, 39 - header: '// This file is auto-generated by @hey-api/openapi-ts', 40 39 lint: null, 41 40 path: '', 42 41 postProcess: [],
+6 -1
packages/openapi-ts/src/createClient.ts
··· 107 107 eventInputPatch.timeEnd(); 108 108 109 109 const eventParser = logger.timeEvent('parser'); 110 + const header = config.output.header; 110 111 // TODO: allow overriding via config 111 112 const project = new Project({ 112 113 defaultFileName: 'index', ··· 125 126 : undefined, 126 127 renderers: [ 127 128 new TypeScriptRenderer({ 128 - header: config.output.header, 129 + header: (ctx) => { 130 + const defaultValue = ['// This file is auto-generated by @hey-api/openapi-ts']; 131 + const result = typeof header === 'function' ? header({ ...ctx, defaultValue }) : header; 132 + return result === undefined ? defaultValue : result; 133 + }, 129 134 preferExportAll: config.output.preferExportAll, 130 135 preferFileExtension: config.output.importFileExtension || undefined, 131 136 resolveModuleName: config.output.resolveModuleName,
+5 -1
packages/openapi-ts/src/generate/client.ts
··· 157 157 project: IProject; 158 158 }): Map<string, string> | undefined { 159 159 const renamed = new Map<string, string>(); 160 - const headerPrefix = outputHeaderToPrefix(header, project); 160 + const headerPrefix = outputHeaderToPrefix({ 161 + defaultValue: ['// This file is auto-generated by @hey-api/openapi-ts'], 162 + header, 163 + project, 164 + }); 161 165 162 166 // copy Hey API clients to output 163 167 const isHeyApiClientPlugin = plugin.name.startsWith('@hey-api/client-');
+3 -2
packages/openapi-ts/src/ts-dsl/utils/render.ts
··· 12 12 preferExportAll?: boolean; 13 13 }; 14 14 type Header = MaybeArray<string> | null | undefined; 15 + type HeaderArg = MaybeFunc<(ctx: RenderContext<TsDsl>) => Header>; 15 16 type Imports = ReadonlyArray<ReadonlyArray<ModuleImport>>; 16 17 17 18 function headerToLines(header: Header): ReadonlyArray<string> { ··· 33 34 * 34 35 * @private 35 36 */ 36 - private _header?: MaybeFunc<(ctx: RenderContext<TsDsl>) => Header>; 37 + private _header?: HeaderArg; 37 38 /** 38 39 * Whether `export * from 'module'` should be used when possible instead of named exports. 39 40 * ··· 55 56 56 57 constructor( 57 58 args: { 58 - header?: MaybeFunc<(ctx: RenderContext<TsDsl>) => Header>; 59 + header?: HeaderArg; 59 60 preferExportAll?: boolean; 60 61 preferFileExtension?: string; 61 62 resolveModuleName?: (moduleName: string) => string | undefined;
+5 -1
packages/shared/src/config/output/types.ts
··· 3 3 4 4 export type OutputHeader = MaybeFunc< 5 5 ( 6 - ctx: Omit<RenderContext, 'file'> & Pick<Partial<RenderContext>, 'file'>, 6 + ctx: Pick<RenderContext, 'meta' | 'project'> & 7 + Pick<Partial<RenderContext>, 'file'> & { 8 + /** The default header value. */ 9 + defaultValue: ReadonlyArray<string>; 10 + }, 7 11 ) => MaybeArray<string> | null | undefined 8 12 >;
+9 -3
packages/shared/src/utils/header.ts
··· 5 5 /** 6 6 * Converts an {@link OutputHeader} value to a string prefix for file content. 7 7 */ 8 - export function outputHeaderToPrefix(header: OutputHeader, project: IProject): string { 9 - let lines = typeof header === 'function' ? header({ project }) : header; 10 - if (lines === null || lines === undefined) return ''; 8 + export function outputHeaderToPrefix(ctx: { 9 + defaultValue: ReadonlyArray<string>; 10 + header: OutputHeader; 11 + project: IProject; 12 + }): string { 13 + const { defaultValue, header, project } = ctx; 14 + let lines = typeof header === 'function' ? header({ defaultValue, project }) : header; 15 + if (lines === undefined) lines = defaultValue; 16 + if (lines === null) return ''; 11 17 lines = 12 18 typeof lines === 'string' ? lines.split(/\r?\n/) : lines.flatMap((line) => line.split(/\r?\n/)); 13 19 const content = lines.join('\n');