Skip to content

[Protocol] generate:typescript: snake_case fields, slim publishable lib#3464

Merged
Herklos merged 2 commits into
devfrom
feature/add-ts-protocol
May 17, 2026
Merged

[Protocol] generate:typescript: snake_case fields, slim publishable lib#3464
Herklos merged 2 commits into
devfrom
feature/add-ts-protocol

Conversation

@Herklos
Copy link
Copy Markdown
Contributor

@Herklos Herklos commented May 16, 2026

No description provided.

Switches `generate:typescript` to `-g typescript` (plain) with `modelPropertyNaming=original` so schema field names stay snake_case (e.g. `created_at`, `pair_settings`). Adds a post-processor (`scripts/postprocess-protocol-typescript.mjs`) that strips the now-broken `HttpFile` import emitted under `--global-property models` (no `http/` supporting dir generated) and writes a `models/index.ts` barrel re-exporting every model.

The `octobot_protocol_ts/` shell package is slimmed to a types-only npm package: `types: "./models/index.ts"`, `files: ["models"]`, no runtime `index.js`. Clean script keep-set narrowed to `package.json` only — `index.js`, `index.d.ts`, `schema.d.ts` no longer needed. Resulting package: ~12 kB packed, 86 files.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@Herklos Herklos self-assigned this May 16, 2026
@Herklos Herklos requested a review from GuillaumeDSM as a code owner May 16, 2026 22:11
@Herklos Herklos force-pushed the feature/add-ts-protocol branch 7 times, most recently from 5d1bcb7 to 87123b4 Compare May 17, 2026 08:51
openapi-generator types each variant's discriminator field as the shared
enum union (e.g. ActionConfigurationType), losing per-variant narrowing
on the TypeScript side.

Fix in post-process, no schema changes:
- scripts/postprocess-protocol-typescript.mjs already strips the broken
  HttpFile import, rewrites Date typings to string, and converts string
  enums to literal unions. Add a narrowing pass that walks openapi.json
  for any property with both \$ref and description, and rewrites the
  variant TS file so that field's type becomes the description literal
  (which is the wire value for each variant in this spec).
- Logic factored into scripts/postprocess-protocol-typescript.lib.mjs
  so it is unit-testable.
- Tests live in the test/ folder next to the auto-generated Python
  tests (different extension so unittest ignores them):
  * test/postprocess-typescript.test.mjs           — 14 unit tests
  * test/postprocess-typescript.codegen.test.mjs   —  8 integration
- Update clean-protocol-codegen-output.mjs to preserve \`.mjs\` test
  files in test/ while still wiping the auto-generated Python tests
  on each codegen run.
- \`npm test\` runs postprocess unit + codegen integration + python
  model tests.

Bumps @drakkar.software/octobot-protocol to 0.3.0.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@Herklos Herklos force-pushed the feature/add-ts-protocol branch from 87123b4 to 6eea6b9 Compare May 17, 2026 08:54
@Herklos Herklos enabled auto-merge (rebase) May 17, 2026 09:00
@Herklos Herklos merged commit eb49262 into dev May 17, 2026
65 of 68 checks passed
@Herklos Herklos deleted the feature/add-ts-protocol branch May 17, 2026 09:12
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.

2 participants