Skip to content

Commit bf3ef9d

Browse files
feat: update SDK build process and add OpenAPI patch script
1 parent a23c410 commit bf3ef9d

6 files changed

Lines changed: 44 additions & 92 deletions

File tree

README.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,17 @@ The output files will be in `tsp-output/schema/openapi.yaml`. You can preview us
7272
- [Prism](https://prismjs.com/) - For API documentation preview and testing. Run `pnpm start` and open <http://localhost:4010>.
7373
- [Yaak](https://yaak.app/) - Import the `yaak` folder.
7474

75-
## Publish SDK
75+
## SDK
76+
77+
### Build
78+
79+
```bash
80+
pnpm compile
81+
pnpm generate:sdk
82+
pnpm build:sdk
83+
```
84+
85+
### Publish
7686

7787
```bash
7888
git checkout main

README.zh.md

Lines changed: 0 additions & 82 deletions
This file was deleted.

orval.config.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,6 @@ module.exports = {
99
enumGenerationType: "enum",
1010
clean: true,
1111
prettier: true
12-
},
13-
override: {
14-
formData: {
15-
file: "File"
16-
}
1712
}
1813
}
1914
};

package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,14 @@
77
"type": "module",
88
"packageManager": "pnpm@10.18.1+sha512.77a884a165cbba2d8d1c19e3b4880eee6d2fcabd0d879121e282196b80042351d5eb3ca0935fa599da1dc51265cc68816ad2bddd2a2de5ea9fdf92adbec7cd34",
99
"scripts": {
10-
"build": "pnpm run format && pnpm run compile && pnpm run yaak",
10+
"build": "pnpm run compile && pnpm run yaak",
1111
"format": "tsp format **/*.tsp",
12-
"compile": "tsp compile .",
12+
"compile": "tsp compile . && node scripts/patch-openapi.js",
1313
"clean": "rm -rf tsp-output yaak",
1414
"start": "pnpm exec prism mock tsp-output/schema/openapi.1.0.0.yaml --port 4010 --host 0.0.0.0",
1515
"yaak": "node scripts/generate-yaak.js",
16-
"generate:sdk": "orval --config orval.config.js"
16+
"generate:sdk": "orval --config orval.config.js",
17+
"build:sdk": "pnpm --filter @nycu-sdc/core-system-sdk run build"
1718
},
1819
"devDependencies": {
1920
"@stoplight/prism-cli": "^5.14.2",

packages/sdk/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@nycu-sdc/core-system-sdk",
3-
"version": "0.1.3",
3+
"version": "0.1.4",
44
"author": {
55
"name": "NYCU SDC",
66
"email": "contact@sdc.nycu.club",

scripts/patch-openapi.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { readFileSync, writeFileSync } from "fs";
2+
import yaml from "js-yaml";
3+
4+
const OPENAPI_PATH = "./tsp-output/schema/openapi.1.0.0.yaml";
5+
6+
const spec = yaml.load(readFileSync(OPENAPI_PATH, "utf8"));
7+
8+
// 1. 強制指定 requestBody 是 multipart
9+
const upload = spec.paths?.["/forms/{id}/cover"]?.post;
10+
11+
if (upload?.requestBody) {
12+
upload.requestBody.content = {
13+
"multipart/form-data": upload.requestBody.content?.["application/json"] ?? upload.requestBody.content?.[Object.keys(upload.requestBody.content)[0]]
14+
};
15+
}
16+
17+
// 2. 強制指定 binary 欄位
18+
const schema = spec.components?.schemas?.["Forms.FormCoverUploadRequest"];
19+
20+
if (schema?.properties?.coverImage) {
21+
schema.properties.coverImage = {
22+
type: "string",
23+
format: "binary"
24+
};
25+
}
26+
27+
writeFileSync(OPENAPI_PATH, yaml.dump(spec, { lineWidth: -1 }), "utf8");
28+
console.log("😉 Patched OpenAPI spec successfully.");

0 commit comments

Comments
 (0)