Skip to content

Commit

Permalink
Merge pull request #782 from hey-api/fix/types-tree
Browse files Browse the repository at this point in the history
fix: allow not generating types tree with types.tree = false
  • Loading branch information
mrlubos authored Jul 15, 2024
2 parents 8bd45bf + edfd2bd commit 23e3808
Show file tree
Hide file tree
Showing 7 changed files with 1,343 additions and 14 deletions.
5 changes: 5 additions & 0 deletions .changeset/hungry-pants-care.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@hey-api/openapi-ts': patch
---

fix: allow not generating types tree with types.tree = false
28 changes: 15 additions & 13 deletions packages/openapi-ts/src/generate/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export interface TypesProps {
onRemoveNode?: VoidFunction;
}

const serviceExportedNamespace = () => '$OpenApiTs';
const treeName = '$OpenApiTs';

export const emptyModel: Model = {
$refs: [],
Expand Down Expand Up @@ -489,18 +489,20 @@ const processServiceTypes = ({
return pathKey;
});

generateType({
client,
meta: {
$ref: '@hey-api/openapi-ts',
name: serviceExportedNamespace(),
},
onNode,
type: toType({
...emptyModel,
properties,
}),
});
if (config.types.tree) {
generateType({
client,
meta: {
$ref: '@hey-api/openapi-ts',
name: treeName,
},
onNode,
type: toType({
...emptyModel,
properties,
}),
});
}
};

export const generateTypes = async ({
Expand Down
1 change: 1 addition & 0 deletions packages/openapi-ts/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ const getTypes = (userConfig: ClientConfig): Config['types'] => {
enums: false,
export: true,
name: 'preserve',
tree: true,
};
if (typeof userConfig.types === 'boolean') {
types.export = userConfig.types;
Expand Down
6 changes: 6 additions & 0 deletions packages/openapi-ts/src/types/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,12 @@ export interface ClientConfig {
* @default 'preserve'
*/
name?: 'PascalCase' | 'preserve';
/**
* Generate a tree of types containing all operations? It will be named
* $OpenApiTs and is generated by default.
* @default true
*/
tree?: boolean;
};
/**
* Use options or arguments functions
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// This file is auto-generated by @hey-api/openapi-ts
export * from './types.gen';
Loading

0 comments on commit 23e3808

Please sign in to comment.