Skip to content

chore(codegen): stop on spec features it can't map - #74

Merged
Reddimus merged 1 commit into
mainfrom
chore/codegen-unsupported
Sep 27, 2026
Merged

Reddimus merged 1 commit into
mainfrom
chore/codegen-unsupported

Conversation

@Reddimus

@Reddimus Reddimus commented Sep 27, 2026 •

Copy link
Copy Markdown
Owner

The script in tools/codegen/ quietly dropped or mistranslated spec features it had no mapping for. Kalshi's current specs use none of them. But a future refresh could lose an endpoint or its data, and the route and message tests, which come from the same model, would keep passing. This PR makes each case stop with a message naming the operation or schema.

What now stops

  • Operations:
    • PATCH, HEAD, OPTIONS, and TRACE operations, which were skipped.
    • Path-item $refs.
    • A missing operationId (it was a KeyError).
    • Two operations mapping to one method name.
    • A parameter declared twice.
  • Parameters:
    • in: header and in: cookie, which were dropped.
    • content parameters.
    • Arrays that aren't style: form, explode: true.
    • Object-typed query parameters.
    • Parameter $refs outside components/parameters.
  • Bodies and responses:
    • Non-JSON, inline, or $ref request bodies, which sent {}.
    • Inline, non-JSON, or $ref success responses, which became Result<void>.
    • 2xx codes other than 200, 201, or 204.
    • Success codes with different bodies.
    • Operations with no 2xx response.
  • Schemas:
    • oneOf, anyOf, not, and discriminator.
    • allOf with more than one member, or with shape-changing keys beside it.
    • Components that are only an allOf or a $ref.
    • 3.1 type lists on the REST side.
    • properties combined with additionalProperties, and top-level maps.
    • Nullable array items or map values.
    • Integer enums.
    • Refs outside components/schemas.
    • Inline objects whose name clashes with another schema.
    • JSON keys that aren't C++ identifiers, checked against the full C++23 keyword list.
    • Required readOnly fields in request bodies.
  • WebSocket:
    • The same schema checks.
    • Untyped schemas, which became std::string.
    • Arrays without items.
    • Extra envelope fields that Update<T> would drop.
    • msg bodies that aren't objects.
    • A new update_subscription variant not listed in UPDATE_PAYLOADS.
    • Shared command parameters whose schemas differ.

Three mappings were wrong rather than unsupported, so they're fixed instead:

  • A $ref message body now resolves; it used to become an empty struct.
  • A nullable component makes its members optional.
  • A command parameter is required only when every variant requires it.

Testing

  • Byte-identical output: generate.py --check passes on the committed files.
  • tools/codegen/test_codegen.py: 72 tests, run by make lint, which CI's build-linux runs. Each check has a test. Against the old generator, 63 of them fail. The other 9 cover specs both versions handle.
  • Real specs:
    • Kalshi Perps still generates all 50 operations.
    • Swagger Petstore now stops on its inline array response.
    • Binance Spot now stops on its first missing operationId.
    • Before this change, both Petstore and Binance "succeeded" while discarding response bodies.
  • Review: a two-lens review with adversarial verification confirmed 22 findings on the first draft, all fixed here.
  • Other gates: make test (287 passed), ./tools/test_consumers.sh, make docs, and markdownlint.

There's no CHANGELOG entry, because nothing changes for users of the library.

The script silently dropped or mistranslated spec features it had no
mapping for: PATCH operations, header parameters, non-JSON or inline
bodies and responses, unions, multi-member allOf, 3.1 type lists, and
more. A future spec refresh could lose an endpoint or its data while the
tests, which come from the same model, kept passing.

Each case now stops with a message naming the operation or schema.
Kalshi's current specs use none of them, so the committed output is
byte-identical. test_codegen.py covers every check, and make lint runs it.
Copilot AI lite review requested due to automatic review settings September 27, 2026 01:43

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@Reddimus
Reddimus merged commit 6d9d995 into main Sep 27, 2026
14 checks passed
@Reddimus
Reddimus deleted the chore/codegen-unsupported branch September 27, 2026 02:02
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