Repository navigation
feat(ui-plugins): add API To SDK (api-to-sdk) - #246
Open
ppppp2005-p wants to merge 11 commits into
Open
ppppp2005-p wants to merge 11 commits into
ppppp2005-p wants to merge 11 commits into
Conversation
Author
|
ZCode desktop demo (ZCode 4.0.0, macOS arm64) api-to-sdk-demo.mp4Flow shown:
演示流程:本地 marketplace 安装 → |
Collaborator
|
✅ Internal validation passed. A ZCode maintainer will review the change next; after acceptance, release checks run separately and this PR is closed automatically. |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Plugin type (required) / 插件类型(必填)
Affected plugin name(s) / 涉及的插件名称:
api-to-sdk(UI Plugin, new)What / 改动内容
New community UI plugin API To SDK / 接口转 SDK: an OpenAPI 3.0/3.1 spec becomes a typed, dependency-free TypeScript SDK package. It is verified by a strict TypeScript compile and by calling every operation against a mock server built from the spec.
Tools:
sdk_inspect(read-only),sdk_generate,sdk_test.sdk_state.How it works:
src/openapi.ts):yaml, or JSON.$refresolution (#/..., ~0/~1 escapes). External refs produce warnings.default.security: []meaning none. Schemes: bearer, basic, apiKey (header/query/cookie), oauth2/OIDC (token).src/codegen.ts):$ref→ named types; enum/const literals; oneOf/anyOf unions; allOf intersections; 3.0nullable/ 3.1["x","null"]; objects with optional/required properties and quoted keys;additionalProperties; arrays; binary →Blob.body) and{ headers, signal }.request(): URL + query (arrays repeated); auth picked from the first satisfiable security alternative; bodies (JSON, FormData, URLSearchParams, raw); timeout viaAbortSignal.timeout/AbortSignal.any.ApiError(status, body, operation, response).<Op>Args,<Op>Response,<Op>ErrorBody.src/, pre-builtdist/(compiled in memory with the bundled TypeScript 6.0.2, strict, NodeNext;.js+.d.ts),package.json(exports/types),tsconfig.json,README.md(operation table).examples/all-operations.ts: typed calls with spec examples. It is type-checked so that spec examples contradicting their schemas are reported.mock/(mock.mjs,server.mjs,openapi.json).src/runtime/mock.mjs, plain JS, also used for verification):examples[0]→ schema-synthesised value, choosing the media type byAccept.Prefer: code=NNN/X-Mock-Statusselects a documented status. Calls are recorded.src/verify.ts):ApiErrorwith that status and the parsed body.Panel:
src/client.tspreview.Network / API / side effects: none. No API keys. Verification uses a mock on 127.0.0.1; the real API is never contacted. Writes the SDK folder and
.api-to-sdk/sdks.json. No hooks. The plugin bundles TypeScript, soserver.mjsis ~11 MB.Testing:
$ref, undeclared path param).tscCLI. The bundled mock runs standalone (example response, 400 with reasons,Prefer: code=404).sdk_testcatches a client that drops a query parameter and one that no longer compiles.imports the generated ESM SDK and calls the bundled mock (CORS, bearer, query arrays, oneOf body, CSV, ApiError 404).A ZCode Desktop demo recording is attached in the comments. / ZCode 桌面版演示录屏见评论。
Self-check / 自查清单
external_plugins/<name>/categoryis set (productivity)version0.1.0 in bothplugin.jsonandmarketplace.jsonREADME.md(EN) andREADME_CN.md(中文) both provided and equivalentdescription_i18nhas bothenandzh-CNpython3 scripts/validate.pyandpython3 scripts/build_dist.pypass locallyapi/harbor-bikes-api.yamland generate a TypeScript SDK; the agent ransdk_inspect→sdk_generate→sdk_test: 12 methods / 14 types, strict TypeScript compile clean, 12/12 mock-server calls passed; demo video in the comments)