Skip to content

feat: multi-language API clients (Node.js, Python, Go, Rust) from one OpenAPI spec - #63

Draft
EastSun5566 wants to merge 16 commits into
developfrom
feature/dev-3165-python-spike
Draft

EastSun5566 wants to merge 16 commits into
developfrom
feature/dev-3165-python-spike

Conversation

@EastSun5566

@EastSun5566 EastSun5566 commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Turn the repository into a multi-language monorepo: every client is generated from one OpenAPI spec with the most mature generator for its language. This is still an experiment; nothing new is published.

Language Package Generator
Node.js @hackmd/api (unchanged) hey-api openapi-ts
Python hackmd-api openapi-python-client (replaces the patched @hey-api/openapi-python spike)
Go github.com/hackmdio/api-client/go oapi-codegen v2.8.2
Rust hackmd-api (new crate name) progenitor, ported from EastSun5566/hackmd-api-client-rs @ b33fa75

hackmd-api is unused on both PyPI and crates.io (hackmd is taken on crates.io), so it matches @hackmd/api everywhere.

Linked issue

  • Resolves DEV-3460

Changes

  • Layout: the spec moved from nodejs/spec/ to spec/. The root is a pnpm workspace for JS only (nodejs, examples/*), with one lockfile seeded from the old nodejs lockfile so Node dependency versions do not change. A root justfile runs spec-pull / codegen / check / check-generated across all clients.
  • CI: one workflow per language (nodejs-ci, python-ci, go-ci, rust-ci), each limited to its directory plus spec/. Each checks that regenerated code matches what is committed.
  • Release tags are prefixed per language. npm releases now use nodejs-v* instead of v*; publish.yml and nodejs/AGENTS.md are updated. Release notes still start from the previous stable tag, old v* or new nodejs-v*. Develop pre-releases run only when nodejs/, spec/ or the lockfile change.
  • Python: the generated client separates omitted fields (UNSET) from None, types If-None-Match, and handles multipart, so the hey-api patches are no longer needed. scripts/codegen.py also generates API / AsyncAPI with one typed method per operation (59). Retries and error wrapping run at the httpx2 transport layer, so every operation gets them. 19 offline tests pass; mypy strict passes; tested on 3.11 and 3.14.
  • Go: hackmd.New(token, opts...) wraps the generated ClientWithResponses with auth, retries and *APIError. Nullable fields use nullable.Nullable[T]. overlay.yaml fixes Go-only naming issues (duplicate User.Teams) without touching the shared spec. Helpers cover the create-note union body, which oapi-codegen does not serialize, and multipart uploads.
  • Rust: copied, renamed, and pointed at ../spec. That spec is older than the one the original crate used, so add_notes_to_folder, add_notes_to_team_folder and get_trash_note were removed for now. The original repository is unchanged. Then aligned with the other clients: POST/PATCH are no longer retried, retries stop when the rate-limit quota is 0, error messages no longer include the response body (now in a body field), and get_note_conditional / get_team_note_conditional handle ETags. The README lists the migration from hackmd-api-client-rs 0.4.
  • docs/conformance.md lists the shared behavior (retries, rate limits, errors, ETag, null vs omitted, multipart) and which clients meet it.

Known gaps / follow-ups

  • The shared spec has 59 operations; the published spec now has 64. Syncing it is a separate change that regenerates all four clients.
  • No publish workflows for Python, Go or Rust yet.

Testing

  • just check passes locally: Node 122 tests plus build/lint/typecheck/docs; Python ruff, mypy, 19 tests; Go vet and tests (also with -race); Rust fmt, clippy, 43 tests, examples and docs.
  • just check-generated: all four clients regenerate with no diff.
  • Live E2E against api.hackmd.io, reads and writes including folders: Node.js 12/12, Python 3/3, Go 3/3, Rust 3/3. Go (go/live_test.go, e2e build tag) and Rust (rust/tests/live.rs, #[ignore]) live tests are new; both skip without a token.
  • Found while running them: folder deletes are eventually consistent (a deleted folder stays listed for 1-2 s), so the Node.js folder test now waits for the delete instead of failing every time. The API's 429 responses carry no x-ratelimit-* headers.

🤖 Generated with Claude Code

@EastSun5566
EastSun5566 added this pull request to stack #64 September 26, 2026 16:54
@EastSun5566
EastSun5566 force-pushed the feature/dev-3165-python-spike branch from 54498c7 to dfe110d Compare September 27, 2026 17:49
@EastSun5566 EastSun5566 changed the title chore: explore Python API client codegen feat: explore Python API client codegen Sep 27, 2026
@EastSun5566
EastSun5566 force-pushed the feature/dev-3165-python-spike branch 2 times, most recently from 063182d to 0a34b93 Compare September 29, 2026 05:36
@EastSun5566
EastSun5566 force-pushed the feature/dev-3165-python-spike branch from 0a34b93 to e43ba59 Compare October 6, 2026 11:03
@EastSun5566
EastSun5566 force-pushed the feature/dev-3165-python-spike branch from e43ba59 to 70ab3bb Compare November 6, 2026 16:06
Base automatically changed from feature/dev-3165 to develop November 20, 2026 07:37
@Yukaii
Yukaii force-pushed the feature/dev-3165-python-spike branch from 70ab3bb to edaf345 Compare November 20, 2026 07:37
@EastSun5566
EastSun5566 force-pushed the feature/dev-3165-python-spike branch from edaf345 to c4c879e Compare December 2, 2026 21:50
@EastSun5566 EastSun5566 changed the title feat: explore Python API client codegen feat: multi-language API clients (Node.js, Python, Go, Rust) from one OpenAPI spec Dec 2, 2026
@EastSun5566
EastSun5566 removed this pull request from stack #64 December 3, 2026 09:56
@EastSun5566
EastSun5566 marked this pull request as ready for review December 3, 2026 10:33
EastSun5566 and others added 15 commits December 3, 2026 20:19
Move the OpenAPI spec to the repository root (spec/) so every language
client generates from the same file. Make the root a pnpm workspace for
the JavaScript packages only (nodejs and examples/*), with one lockfile
seeded from the previous nodejs lockfile so resolved versions do not
change.

Rename the Node.js CI workflow and add path filters, so each language's
workflows run only for its own changes. Prefix release tags per language;
npm releases now use nodejs-v* tags.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Replace the patched @hey-api/openapi-python spike. openapi-python-client
generates an httpx2 + attrs client that separates omitted fields (UNSET)
from explicit nulls, types the If-None-Match header, and serializes
multipart uploads, which the previous generator needed patches for.

scripts/codegen.py also generates API and AsyncAPI with one typed method
per operation, returning only the success body. Retries and error
wrapping run in an httpx2 transport and response hook, so every
operation gets them. The package is named hackmd-api to match
@hackmd/api.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Copy the progenitor-based client from EastSun5566/hackmd-api-client-rs
(b33fa75) into rust/, renamed to hackmd-api to match @hackmd/api. The
original repository and crate are left as they are.

xtask now generates from the shared ../spec/hackmd-openapi.json; the spec
download moved to the root justfile. That spec is older than the one the
original crate used, so add_notes_to_folder, add_notes_to_team_folder and
get_trash_note are removed until the shared spec is updated.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Add github.com/hackmdio/api-client/go (package hackmd), generated from
the shared spec with oapi-codegen v2.8.2, pinned through the go.mod tool
directive. ClientWithResponses has a typed method for every operation.

hackmd.New wraps the generated client's HTTP doer to add the bearer token,
retries with backoff for idempotent methods, and *APIError for 4xx/5xx.
Nullable fields use nullable.Nullable[T], so a request can leave a field
out or clear it with null. overlay.yaml renames the duplicate User.Teams
property and names the create-note option types, without changing the
shared spec. Helpers cover the create-note union body, which the
generated request type does not serialize, and multipart image uploads.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Add a root justfile that pulls the spec, regenerates and checks every
client, and docs/conformance.md, which lists the behavior each client adds
on top of its generated code and the known gaps in the Rust port. The root
README now lists all four clients; add a Python example.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Retry only GET, PUT and DELETE. POST and PATCH (creates, updates,
  pings, uploads) are sent once, so a write is never applied twice.
- Stop retrying 429s once x-ratelimit-userremaining is 0. The rate-limit
  fields are now Option<u32>, so a missing header no longer reads as 0.
- Wait base_delay * 2^n from the first retry, matching Node.js.
- Keep response bodies out of error messages; they are in a new body
  field instead.
- Add get_note_conditional and get_team_note_conditional, which send
  If-None-Match and return Conditional::NotModified on 304.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Go gets live tests behind the e2e build tag and Rust gets ignored tests in
tests/live.rs. Both cover reads, a 404, the note lifecycle (ETag 304,
clearing a nullable field, image upload) and a folder lifecycle, and skip
without HACKMD_ACCESS_TOKEN.

Folder deletes are eventually consistent: a deleted folder stays listed for
a second or two. The Node.js folder test asserted it was gone immediately
and failed every time, so it now waits for the delete to land.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@EastSun5566
EastSun5566 force-pushed the feature/dev-3165-python-spike branch from cbdc03b to e44b0dc Compare December 3, 2026 12:22
package.json declares engines >=22, but CI only ran Node 24. Test the
minimum (22), the version that builds the npm release (24) and the
latest (26), like Python CI tests 3.11 and 3.14.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@EastSun5566
EastSun5566 marked this pull request as draft December 4, 2026 06:23

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant