feat(api): generate REST models from pinned OpenAPI spec - #690
Conversation
Implements step 1 of #683. This does not add public REST methods. It adds two type namespaces: - `braintrust.api._generated.models`: private generated `TypedDict`s and type aliases - `braintrust.api.types`: the public REST type namespace, empty until resource APIs are added The generated module is derived from committed inputs: openapi/spec.json + openapi/config.json | v validation | v datamodel-code-generator + Ruff | v braintrust/api/_generated/models.py `make generate-api-client` runs that pipeline. `make check-api-client-codegen` runs it in a temporary directory and fails if the committed output differs, so CI catches hand edits and stale models. Builds use the committed models and do not run code generation. Spec updates are manual for now: update the pinned upstream commit and spec SHA-256 in `openapi/config.json`, fetch the snapshot, regenerate, and review the spec and model diffs together. Automated update PRs are deferred to step 7.
7afac7a to
f0fd32e
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: f0fd32e425
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "Codex (@codex) review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "Codex (@codex) address that feedback".
| """ | ||
| A stable, time-ordered key that can be used to paginate over project logs events. This field is auto-generated by Braintrust and only exists in Brainstore. | ||
| """ | ||
| field_xact_id: str |
There was a problem hiding this comment.
Preserve leading-underscore API property names
When these generated TypedDicts are used to type REST payloads, this annotation represents a JSON key named field_xact_id, but the pinned schema defines the required key as _xact_id (openapi/spec.json:1188,1440). The same rewrite affects _pagination_key, _object_org_id, _array_delete, and other properties throughout the generated models, so type checkers will reject valid API objects and accept objects containing keys the API never sends or expects. Configure generation to preserve these valid leading-underscore names, or otherwise emit key-preserving TypedDict definitions.
Useful? React with 👍 / 👎.
AI Summary
Implements step 1 of #683.
This does not add public REST methods. It adds two type namespaces:
braintrust.api._generated.models: private generatedTypedDicts and type aliasesbraintrust.api.types: the public REST type namespace, empty until resource APIs are addedThe generated module is derived from committed inputs:
make generate-api-clientruns that pipeline.make check-api-client-codegenruns it in a temporary directory and fails if the committed output differs, so CI catches hand edits and stale models. Builds use the committed models and do not run code generation.Spec updates are manual for now: update the pinned upstream commit and spec SHA-256 in
openapi/config.json, fetch the snapshot, regenerate, and review the spec and model diffs together. Automated update PRs are deferred to step 7.