Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions packages/openapi-ts/src/plugins/@hey-api/typescript/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,12 @@ export const defaultConfig: HeyApiTypeScriptPlugin['Config'] = {
plugin.config.errors = context.valueToObject({
defaultValue: {
case: plugin.config.case ?? 'PascalCase',
enabled: true,
error: '{{name}}Error',
name: '{{name}}Errors',
},
mappers: {
boolean: (enabled) => ({ enabled }),
function: (name) => ({ name }),
string: (name) => ({ name }),
},
Expand All @@ -57,9 +59,11 @@ export const defaultConfig: HeyApiTypeScriptPlugin['Config'] = {
plugin.config.requests = context.valueToObject({
defaultValue: {
case: plugin.config.case ?? 'PascalCase',
enabled: true,
name: '{{name}}Data',
},
mappers: {
boolean: (enabled) => ({ enabled }),
function: (name) => ({ name }),
string: (name) => ({ name }),
},
Expand All @@ -69,10 +73,12 @@ export const defaultConfig: HeyApiTypeScriptPlugin['Config'] = {
plugin.config.responses = context.valueToObject({
defaultValue: {
case: plugin.config.case ?? 'PascalCase',
enabled: true,
name: '{{name}}Responses',
response: '{{name}}Response',
},
mappers: {
boolean: (enabled) => ({ enabled }),
function: (name) => ({ name }),
string: (name) => ({ name }),
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,32 +115,34 @@ export const operationToType = ({
schema: data,
});

const dataSymbol = plugin.registerSymbol(
buildSymbolIn({
meta: {
category: 'type',
path,
resource: 'operation',
resourceId: operation.id,
role: 'data',
tags,
tool: 'typescript',
},
name: operation.id,
naming: plugin.config.requests,
operation,
plugin,
}),
);
const dataNode = $.type
.alias(dataSymbol)
.export()
.type(dataResult?.type ?? $.type('never'));
plugin.node(dataNode);
if (plugin.config.requests.enabled) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor: dataResult from processor.process({...}) above (the call that fills path: [...path, operation.id, 'data']) is still computed when requests.enabled === false, then discarded. The data-shape processing is the most expensive step here, so it would be cleaner to move it inside this guard alongside the symbol registration.

const dataSymbol = plugin.registerSymbol(
buildSymbolIn({
meta: {
category: 'type',
path,
resource: 'operation',
resourceId: operation.id,
role: 'data',
tags,
tool: 'typescript',
},
name: operation.id,
naming: plugin.config.requests,
operation,
plugin,
}),
);
const dataNode = $.type
.alias(dataSymbol)
.export()
.type(dataResult?.type ?? $.type('never'));
plugin.node(dataNode);
}

const { error, errors, response, responses } = operationResponsesMap(operation);

if (errors) {
if (plugin.config.errors.enabled && errors) {
const errorsResult = processor.process({
export: false,
meta: {
Expand Down Expand Up @@ -205,7 +207,7 @@ export const operationToType = ({
}
}

if (responses) {
if (plugin.config.responses.enabled && responses) {
const responsesResult = processor.process({
export: false,
meta: {
Expand Down
46 changes: 33 additions & 13 deletions packages/openapi-ts/src/plugins/@hey-api/typescript/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,12 @@ export type UserConfig = Plugin.Name<'@hey-api/typescript'> &
* @default 'PascalCase'
*/
case?: Casing;
/**
* Whether this feature is enabled.
*
* @default true
*/
enabled?: boolean;
/**
* Naming pattern for generated names.
*
Expand Down Expand Up @@ -146,6 +152,12 @@ export type UserConfig = Plugin.Name<'@hey-api/typescript'> &
* @default 'PascalCase'
*/
case?: Casing;
/**
* Whether this feature is enabled.
*
* @default true
*/
enabled?: boolean;
/**
* Naming pattern for generated names.
*
Expand Down Expand Up @@ -173,6 +185,12 @@ export type UserConfig = Plugin.Name<'@hey-api/typescript'> &
* @default 'PascalCase'
*/
case?: Casing;
/**
* Whether this feature is enabled.
*
* @default true
*/
enabled?: boolean;
/**
* Naming pattern for generated names.
*
Expand Down Expand Up @@ -290,30 +308,32 @@ export type Config = Plugin.Name<'@hey-api/typescript'> &
* - `string` or `function`: Shorthand for `{ name: string | function }`
* - `object`: Full configuration object
*/
errors: NamingOptions & {
/**
* Naming pattern for generated names.
*/
error: NameTransformer;
};
errors: FeatureToggle &
NamingOptions & {
/**
* Naming pattern for generated names.
*/
error: NameTransformer;
};
/**
* Configuration for request-specific types.
*
* Controls generation of types for request bodies, query parameters, path
* parameters, and headers.
*/
requests: NamingOptions;
requests: FeatureToggle & NamingOptions;
/**
* Configuration for response-specific types.
*
* Controls generation of types for response bodies and status codes.
*/
responses: NamingOptions & {
/**
* Naming pattern for generated names.
*/
response: NameTransformer;
};
responses: FeatureToggle &
NamingOptions & {
/**
* Naming pattern for generated names.
*/
response: NameTransformer;
};
/**
* The top type to use for untyped or unspecified schema values.
*
Expand Down
Loading