Skip to content

Commit f324a4e

Browse files
authored
Merge pull request #3512 from hey-api/refactor/playground
refactor: add python playground
2 parents 32edd13 + beb50ae commit f324a4e

14 files changed

Lines changed: 72 additions & 50 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ coverage
2424

2525
# test files
2626
.gen/
27+
dev/gen/
2728
test/generated
2829

2930
# debug files

dev/openapi-python.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export default defineConfig(() => [
1414
path: './logs',
1515
},
1616
output: {
17-
path: path.resolve(__dirname, '.gen', 'python'),
17+
path: path.resolve(__dirname, 'gen', 'python'),
1818
},
1919
plugins: getPreset(),
2020
},

dev/openapi-ts.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export default defineConfig(() => [
1414
path: './logs',
1515
},
1616
output: {
17-
path: path.resolve(__dirname, '.gen', 'typescript'),
17+
path: path.resolve(__dirname, 'gen', 'typescript'),
1818
},
1919
plugins: getPreset(),
2020
},

dev/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"private": true,
55
"type": "module",
66
"scripts": {
7-
"dev": "ts-node ./playground.ts"
7+
"dev": "tsx ./playground.ts"
88
},
99
"devDependencies": {
1010
"@angular/common": "21.1.2",
@@ -23,6 +23,7 @@
2323
"arktype": "2.1.29",
2424
"nuxt": "3.21.0",
2525
"swr": "2.4.0",
26+
"tsx": "4.21.0",
2627
"typescript": "5.9.3",
2728
"valibot": "1.2.0",
2829
"vue": "3.5.25",

dev/playground.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
from gen.python import OpenCode
2+
3+
4+
def run():
5+
client = OpenCode()
6+
client.tui.publish()
7+
# body={
8+
# "properties": {
9+
# "message": "Hello from Hey API OpenAPI TS Playground!",
10+
# "variant": "success",
11+
# },
12+
# "type": "tui.toast.show",
13+
# },
14+
# directory="main",
15+
16+
run()

dev/playground.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import type { DefinePlugin, IR } from '@hey-api/openapi-ts';
22

33
// import { createOpencode } from '@opencode-ai/sdk';
4-
import { PetStore } from './.gen/typescript/sdk.gen.ts';
4+
import { client } from './gen/typescript/client.gen';
5+
import { OpenCode } from './gen/typescript/sdk.gen';
56

67
type MyPluginConfig = { readonly name: 'myplugin' };
78
type MyPlugin = DefinePlugin<MyPluginConfig>;
@@ -19,8 +20,11 @@ export const handler: MyPlugin['Handler'] = ({ plugin }) => {
1920
async function run() {
2021
// const { client, server } = await createOpencode();
2122
// console.log(client, server);
22-
const client = new PetStore();
23-
client.tui.publish({
23+
client.setConfig({
24+
baseUrl: 'https://api.example.com',
25+
});
26+
const sdk = new OpenCode({ client });
27+
sdk.tui.publish({
2428
body: {
2529
properties: {
2630
message: 'Hello from Hey API OpenAPI TS Playground!',

dev/python/presets.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,9 @@ export const presets = {
55
sdk: () => [
66
/** SDK */
77
sdk({
8-
'~hooks': {
9-
symbols: {
10-
// getExportFromFilePath(symbol) {
11-
// console.log(symbol.toString());
12-
// return undefined;
13-
// },
14-
},
8+
operations: {
9+
containerName: 'OpenCode',
10+
strategy: 'single',
1511
},
1612
}),
1713
],

dev/tsconfig.json

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
{
2-
"extends": "../packages/openapi-ts-tests/tsconfig.base.json",
2+
"extends": "../tsconfig.base.json",
33
"compilerOptions": {
44
"allowImportingTsExtensions": true,
5-
"declaration": false,
6-
"esModuleInterop": true,
5+
"module": "ESNext",
6+
"moduleResolution": "bundler",
77
"noEmit": true,
8-
"resolveJsonModule": true,
9-
"skipLibCheck": true
8+
"resolveJsonModule": true
109
}
1110
}

dev/typescript/presets.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ export const presets = {
2222
containerName: 'OpenCode',
2323
strategy: 'single',
2424
},
25+
paramsStructure: 'flat',
2526
}),
2627
],
2728
tanstack: () => [

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@
7070
"husky": "9.1.7",
7171
"lint-staged": "16.2.7",
7272
"oxfmt": "0.35.0",
73-
"ts-node": "10.9.2",
7473
"tsdown": "0.18.4",
7574
"tsx": "4.21.0",
7675
"turbo": "2.8.12",

0 commit comments

Comments
 (0)