Skip to content

Commit 4a3de97

Browse files
authored
Merge pull request #3217 from hey-api/refactor/shared-types
refactor: move shared utility types into a separate package
2 parents 1df38b0 + b64680f commit 4a3de97

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+835
-66
lines changed

packages/codegen-core/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
},
7070
"devDependencies": {
7171
"@config/vite-base": "workspace:*",
72+
"@hey-api/types": "workspace:*",
7273
"eslint": "9.39.1",
7374
"prettier": "3.4.2",
7475
"typescript": "5.9.3"

packages/codegen-core/src/log.ts

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,10 @@
1+
import type { MaybeArray, MaybeFunc } from '@hey-api/types';
12
import colors from 'ansi-colors';
23
// @ts-expect-error
34
import colorSupport from 'color-support';
45

56
colors.enabled = colorSupport().hasBasic;
67

7-
/**
8-
* Accepts a value or a readonly array of values of type T.
9-
*/
10-
export type MaybeArray<T> = T | ReadonlyArray<T>;
11-
12-
/**
13-
* Accepts a value or a function returning a value.
14-
*/
15-
export type MaybeFunc<T extends (...args: Array<any>) => any> =
16-
| T
17-
| ReturnType<T>;
18-
198
const DEBUG_NAMESPACE = 'heyapi';
209

2110
const NO_WARNINGS = /^(1|true|yes|on)$/i.test(

packages/codegen-core/tsdown.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export default defineConfig({
1919
entry: ['src/index.ts'],
2020
format: ['cjs', 'esm'],
2121
minify: false,
22+
noExternal: ['@hey-api/types'],
2223
shims: false,
2324
sourcemap: true,
2425
treeshake: true,

packages/openapi-python/.gitignore

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
.DS_Store
2+
.idea
3+
.tsdown
4+
.tmp
5+
junit.xml
6+
logs
7+
node_modules
8+
npm-debug.log*
9+
temp
10+
11+
*.iml
12+
dist
13+
coverage
14+
.env

packages/openapi-python/LICENSE.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) Hey API
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

packages/openapi-python/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<div align="center">
2+
<h1><b>OpenAPI Python</b></h1>
3+
</div>
4+
5+
Coming soon.
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
{
2+
"name": "@hey-api/openapi-python",
3+
"version": "0.0.1",
4+
"private": true,
5+
"description": "🐍 OpenAPI to Python codegen.",
6+
"homepage": "https://heyapi.dev/",
7+
"repository": {
8+
"type": "git",
9+
"url": "git+https://github.com/hey-api/openapi-ts.git"
10+
},
11+
"bugs": {
12+
"url": "https://github.com/hey-api/openapi-ts/issues"
13+
},
14+
"license": "MIT",
15+
"author": {
16+
"email": "lubos@heyapi.dev",
17+
"name": "Hey API",
18+
"url": "https://heyapi.dev"
19+
},
20+
"funding": "https://github.com/sponsors/hey-api",
21+
"keywords": [
22+
"codegen",
23+
"generator",
24+
"http",
25+
"javascript",
26+
"json",
27+
"node",
28+
"openapi",
29+
"python",
30+
"rest",
31+
"swagger",
32+
"typescript",
33+
"yaml"
34+
],
35+
"type": "module",
36+
"main": "./dist/index.cjs",
37+
"module": "./dist/index.mjs",
38+
"types": "./dist/index.d.mts",
39+
"exports": {
40+
".": {
41+
"import": {
42+
"types": "./dist/index.d.mts",
43+
"default": "./dist/index.mjs"
44+
},
45+
"require": {
46+
"types": "./dist/index.d.cts",
47+
"default": "./dist/index.cjs"
48+
}
49+
},
50+
"./package.json": "./package.json"
51+
},
52+
"bin": {
53+
"openapi-python": "./bin/run.js"
54+
},
55+
"files": [
56+
"bin",
57+
"dist",
58+
"LICENSE.md",
59+
"README.md"
60+
],
61+
"scripts": {
62+
"build": "tsdown && pnpm check-exports",
63+
"check-exports": "attw --pack . --profile node16",
64+
"dev": "tsdown --watch",
65+
"prepublishOnly": "pnpm build",
66+
"test:coverage": "vitest run --coverage",
67+
"test:update": "vitest watch --update",
68+
"test:watch": "vitest watch",
69+
"test": "vitest run",
70+
"typecheck": "tsc --noEmit"
71+
},
72+
"engines": {
73+
"node": ">=20.19.0"
74+
},
75+
"dependencies": {
76+
"@hey-api/codegen-core": "workspace:^0.5.2",
77+
"@hey-api/json-schema-ref-parser": "1.2.2",
78+
"ansi-colors": "4.1.3",
79+
"c12": "3.3.3",
80+
"color-support": "1.1.3",
81+
"commander": "14.0.2",
82+
"open": "11.0.0",
83+
"semver": "7.7.3"
84+
},
85+
"peerDependencies": {
86+
"typescript": ">=5.5.3"
87+
},
88+
"devDependencies": {
89+
"@config/vite-base": "workspace:*",
90+
"@hey-api/types": "workspace:*",
91+
"@types/cross-spawn": "6.0.6",
92+
"@types/semver": "7.7.1",
93+
"cross-spawn": "7.0.6",
94+
"eslint": "9.39.1",
95+
"prettier": "3.4.2",
96+
"typescript": "5.9.3",
97+
"yaml": "2.8.2"
98+
}
99+
}
Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
import { describe, expect, it } from 'vitest';
2+
3+
// import { createClient } from '~/index';
4+
5+
// type Config = Parameters<typeof createClient>[0];
6+
7+
describe('createClient', () => {
8+
it('works', () => {
9+
expect(true).toBe(true);
10+
});
11+
// it('1 config, 1 input, 1 output', async () => {
12+
// const config: Config = {
13+
// dryRun: true,
14+
// input: {
15+
// info: { title: 'foo', version: '1.0.0' },
16+
// openapi: '3.0.0',
17+
// },
18+
// logs: {
19+
// level: 'silent',
20+
// },
21+
// output: 'output',
22+
// plugins: ['@hey-api/typescript'],
23+
// };
24+
25+
// const results = await createClient(config);
26+
// expect(results).toHaveLength(1);
27+
// });
28+
29+
// it('1 config, 2 inputs, 1 output', async () => {
30+
// const config: Config = {
31+
// dryRun: true,
32+
// input: [
33+
// {
34+
// info: { title: 'foo', version: '1.0.0' },
35+
// openapi: '3.0.0',
36+
// },
37+
// {
38+
// info: { title: 'bar', version: '1.0.0' },
39+
// openapi: '3.0.0',
40+
// paths: {},
41+
// },
42+
// ],
43+
// logs: {
44+
// level: 'silent',
45+
// },
46+
// output: 'output',
47+
// plugins: ['@hey-api/typescript'],
48+
// };
49+
50+
// const results = await createClient(config);
51+
// expect(results).toHaveLength(1);
52+
// });
53+
54+
// it('1 config, 2 inputs, 2 outputs', async () => {
55+
// const config: Config = {
56+
// dryRun: true,
57+
// input: [
58+
// {
59+
// info: { title: 'foo', version: '1.0.0' },
60+
// openapi: '3.0.0',
61+
// },
62+
// {
63+
// info: { title: 'bar', version: '1.0.0' },
64+
// openapi: '3.0.0',
65+
// paths: {},
66+
// },
67+
// ],
68+
// logs: {
69+
// level: 'silent',
70+
// },
71+
// output: ['output', 'output2'],
72+
// plugins: ['@hey-api/typescript'],
73+
// };
74+
75+
// const results = await createClient(config);
76+
// expect(results).toHaveLength(2);
77+
// });
78+
79+
// it('2 configs, 1 input, 1 output', async () => {
80+
// const config: Config = [
81+
// {
82+
// dryRun: true,
83+
// input: {
84+
// info: { title: 'foo', version: '1.0.0' },
85+
// openapi: '3.0.0',
86+
// },
87+
// logs: {
88+
// level: 'silent',
89+
// },
90+
// output: 'output',
91+
// plugins: ['@hey-api/typescript'],
92+
// },
93+
// {
94+
// dryRun: true,
95+
// input: {
96+
// info: { title: 'bar', version: '1.0.0' },
97+
// openapi: '3.0.0',
98+
// },
99+
// logs: {
100+
// level: 'silent',
101+
// },
102+
// output: 'output2',
103+
// plugins: ['@hey-api/typescript'],
104+
// },
105+
// ];
106+
107+
// const results = await createClient(config);
108+
// expect(results).toHaveLength(2);
109+
// });
110+
111+
// it('2 configs, 2 inputs, 2 outputs', async () => {
112+
// const config: Config = [
113+
// {
114+
// dryRun: true,
115+
// input: [
116+
// {
117+
// info: { title: 'foo', version: '1.0.0' },
118+
// openapi: '3.0.0',
119+
// },
120+
// {
121+
// info: { title: 'bar', version: '1.0.0' },
122+
// openapi: '3.0.0',
123+
// paths: {},
124+
// },
125+
// ],
126+
// logs: {
127+
// level: 'silent',
128+
// },
129+
// output: ['output', 'output2'],
130+
// plugins: ['@hey-api/typescript'],
131+
// },
132+
// {
133+
// dryRun: true,
134+
// input: [
135+
// {
136+
// info: { title: 'baz', version: '1.0.0' },
137+
// openapi: '3.0.0',
138+
// },
139+
// {
140+
// info: { title: 'qux', version: '1.0.0' },
141+
// openapi: '3.0.0',
142+
// paths: {},
143+
// },
144+
// ],
145+
// logs: {
146+
// level: 'silent',
147+
// },
148+
// output: ['output3', 'output4'],
149+
// plugins: ['@hey-api/typescript'],
150+
// },
151+
// ];
152+
153+
// const results = await createClient(config);
154+
// expect(results).toHaveLength(4);
155+
// });
156+
});

0 commit comments

Comments
 (0)