Skip to content

feat(api): generate REST models from pinned OpenAPI spec - #690

Merged
Abhijeet Prasad (AbhiPrasad) merged 1 commit into
mainfrom
abhi-openapi
Aug 17, 2026
Merged

feat(api): generate REST models from pinned OpenAPI spec#690
Abhijeet Prasad (AbhiPrasad) merged 1 commit into
mainfrom
abhi-openapi

Conversation

@AbhiPrasad

Copy link
Copy Markdown
Member

AI Summary

Implements step 1 of #683.

This does not add public REST methods. It adds two type namespaces:

  • braintrust.api._generated.models: private generated TypedDicts 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.

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.

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 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

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge 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 👍 / 👎.

@AbhiPrasad
Abhijeet Prasad (AbhiPrasad) merged commit c67d80d into main Aug 17, 2026
83 checks passed
@AbhiPrasad
Abhijeet Prasad (AbhiPrasad) deleted the abhi-openapi branch August 17, 2026 16:29
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