Skip to content

feat: add detailed schemas for V2Log data payloads#1234

Merged
flemzord merged 6 commits intomainfrom
feat/add-schema-for-logs
Jan 19, 2026
Merged

feat: add detailed schemas for V2Log data payloads#1234
flemzord merged 6 commits intomainfrom
feat/add-schema-for-logs

Conversation

@flemzord
Copy link
Member

Summary

This PR adds strongly-typed schemas for all V2Log data payloads in the OpenAPI specification, addressing feedback from issue #1232.

Changes

  • New schemas added to openapi/v2.yaml:

    • V2LogTransaction - Transaction structure specific to log payloads
    • V2LogDataNewTransaction - Payload for NEW_TRANSACTION logs
    • V2LogDataSetMetadata - Payload for SET_METADATA logs
    • V2LogDataRevertedTransaction - Payload for REVERTED_TRANSACTION logs
    • V2LogDataDeleteMetadata - Payload for DELETE_METADATA logs
    • V2LogDataInsertedSchema - Payload for INSERTED_SCHEMA logs
  • Modified V2Log schema to use oneOf with discriminated types instead of additionalProperties: true

  • Regenerated SDK with new strongly-typed models

  • Updated e2e tests to use the new typed structures

Benefits

  • Log payloads are now fully documented in the OpenAPI spec
  • SDK consumers get strongly-typed access to log data
  • CDC tools (like Debezium) can rely on a stable, documented schema
  • Improved developer experience with IDE autocompletion

Related

Closes #1232

Test plan

  • go build ./... passes
  • just lint passes (0 issues)
  • go build -tags it ./test/e2e/... passes
  • CI pipeline

…a structures

- Added descriptions for V2Log properties to clarify their purpose.
- Introduced new schemas for log data types: V2LogDataNewTransaction, V2LogDataSetMetadata, V2LogDataRevertedTransaction, V2LogDataDeleteMetadata, and V2LogDataInsertedSchema.
- Improved overall documentation for better understanding of log entry structures and their payloads.
…nal log data structures

- Removed unnecessary x-speakeasy-errors from the insertSchema endpoint.
- Enhanced descriptions for V2Log properties to improve clarity.
- Added new schemas for log data types: V2LogTransaction, V2LogDataNewTransaction, V2LogDataSetMetadata, V2LogDataRevertedTransaction, V2LogDataDeleteMetadata, and V2LogDataInsertedSchema.
- Improved documentation for log entry structures and their payloads.
…escriptions

- Expanded the V2Log schema to include comprehensive descriptions for properties.
- Added new log data structures: V2LogTransaction, V2LogDataNewTransaction, V2LogDataSetMetadata, V2LogDataRevertedTransaction, V2LogDataDeleteMetadata, and V2LogDataInsertedSchema.
- Improved documentation for log entry payloads and their respective structures to facilitate better understanding.
…entation

- Introduced new log data structures: V2LogDataDeleteMetadata, V2LogDataDeleteMetadataTargetID, V2LogDataDeleteMetadataTargetType, V2LogDataInsertedSchema, V2LogDataNewTransaction, V2LogDataRevertedTransaction, and V2LogDataSetMetadata.
- Updated V2LogData to support various log entry types, enhancing the payload structure for better clarity.
- Improved documentation for log entry payloads and their respective structures to facilitate better understanding and usage.
- Refactored tests to utilize the updated V2LogDataNewTransaction structure for better clarity and consistency.
- Changed assertions to match the new data types and structures, ensuring accurate validation of log entries.
- Improved readability by replacing map assertions with structured field access for transaction data.
@flemzord flemzord requested a review from a team as a code owner January 19, 2026 11:21
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 19, 2026

Walkthrough

This PR replaces V2Log's generic Data payload with a structured union type V2LogData (variants: NEW_TRANSACTION, SET_METADATA, REVERTED_TRANSACTION, DELETE_METADATA, INSERTED_SCHEMA), adds corresponding Go models, JSON (un)marshal logic, generated docs, examples, and updates tests to use the typed payloads.

Changes

Cohort / File(s) Summary
Core V2Log union
pkg/client/models/components/v2log.go
Replaced Data map[string]any with Data V2LogData; added V2LogDataType constants, constructors, and JSON Marshal/Unmarshal for selecting the active variant; updated GetData() signature.
V2LogData variants
pkg/client/models/components/v2logdatanewtransaction.go, pkg/client/models/components/v2logdatasetmetadata.go, pkg/client/models/components/v2logdatarevertedtransaction.go, pkg/client/models/components/v2logdatadeletemetadata.go, pkg/client/models/components/v2logdatainsertedschema.go
Added concrete payload structs for each variant with nil-safe getters, constructors, and (where needed) union/discriminator handling for nested fields (TargetID, TargetType). Includes JSON (un)marshal logic for union-like nested types.
V2LogTransaction & supporting models
pkg/client/models/components/v2logtransaction.go, ... (related V2Volume/V2Posting referenced)
New V2LogTransaction model with fields for ID, postings, metadata, timestamps, template, reverted flag, and pre/post-commit volume maps; includes JSON (un)marshal and nil-safe getters.
Union nested types (TargetID/TargetType)
pkg/client/models/components/v2logdatasetmetadata.go, pkg/client/models/components/v2logdatadeletemetadata.go
Implemented string/bigint union for TargetID (discriminator, constructors, marshal/unmarshal) and TargetType enums with validation helpers used by SET_METADATA and DELETE_METADATA payloads.
Generated docs & API examples
docs/api/README.md, pkg/client/docs/models/components/v2log*.md (14 files)
Expanded V2Log schema docs: replaced placeholder data examples with full V2LogTransaction payloads, added oneOf/xor-style descriptions for data variants, and added per-variant examples and new model docs.
Client docs for TargetID/Type
pkg/client/docs/models/components/targetid.md, pkg/client/docs/models/components/targettype.md
New documentation describing TargetID and TargetType usage and examples.
Tests updated
test/e2e/api_logs_list_test.go
Test assertions moved from untyped map access to typed V2LogData fields; postings and transactions updated to use typed components.V2Posting and V2LogTransaction fields.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

🐰 I stitched the logs with tidy care,

Transactions snug in typed-out lair.
No stray maps hopping in the night,
Each variant tucked—everything's right.
🥕✨

🚥 Pre-merge checks | ✅ 3 | ❌ 2
❌ Failed checks (2 warnings)
Check name Status Explanation Resolution
Linked Issues check ⚠️ Warning The PR claims to close issue #1232, but the changes do not implement the requested transactional outbox pattern. The PR only adds OpenAPI schemas for V2Log payloads without implementing the outbox table or event delivery guarantees. The PR addresses only documentation/schema aspects but omits the core implementation (outbox table, transactional writes, configuration) required by issue #1232. Clarify whether this PR is preparatory work or if implementation is incomplete.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: adding detailed schemas for V2Log data payloads, which is accurately reflected throughout the changeset.
Description check ✅ Passed The description is well-related to the changeset, providing context about new schemas, OpenAPI modifications, SDK regeneration, and test updates that align with the code changes.
Out of Scope Changes check ✅ Passed The changes are focused on adding OpenAPI schemas, regenerating SDK models, and updating e2e tests. These are all in-scope for improving log payload documentation but do not address the outbox pattern implementation from #1232.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/add-schema-for-logs

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 4

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
test/e2e/api_logs_list_test.go (1)

222-228: Test assertion will fail: comparing V2LogData struct to map[string]any.

The Data field is now typed as V2LogData (a struct), but this assertion still compares it to a map[string]any. This type mismatch will cause the test to fail at runtime.

Update to use the typed V2LogDataSetMetadata accessor, consistent with the NEW_TRANSACTION assertions below.

🐛 Proposed fix
-		Expect(response.V2LogsCursorResponse.Cursor.Data[0].Data).To(Equal(map[string]any{
-			"targetType": "ACCOUNT",
-			"metadata": map[string]any{
-				"clientType": "gold",
-			},
-			"targetId": "foo:baz",
-		}))
+		Expect(response.V2LogsCursorResponse.Cursor.Data[0].Data.V2LogDataSetMetadata).NotTo(BeNil())
+		setMetadata := response.V2LogsCursorResponse.Cursor.Data[0].Data.V2LogDataSetMetadata
+		Expect(setMetadata.TargetType).To(Equal(components.TargetTypeAccount))
+		Expect(setMetadata.TargetID.Str).To(Equal(pointer.For("foo:baz")))
+		Expect(setMetadata.Metadata).To(Equal(map[string]string{
+			"clientType": "gold",
+		}))
🤖 Fix all issues with AI agents
In `@pkg/client/docs/models/components/targetid.md`:
- Around line 6-16: The TargetID docs contain empty "###" headings and invalid
Go snippets; update the headings to meaningful text (e.g., "CreateTargetID from
string" and "CreateTargetID from bigint") and replace the broken examples for
CreateTargetIDStr and CreateTargetIDBigint with valid Go code: show a simple
string literal for CreateTargetIDStr and a proper big.Int construction (import
"math/big", use big.NewInt or new(big.Int).SetString) for CreateTargetIDBigint
so the examples compile and demonstrate correct usage of CreateTargetIDStr and
CreateTargetIDBigint.

In `@pkg/client/docs/models/components/v2logdatadeletemetadata.md`:
- Around line 8-12: Update the documentation row for TargetID
(components.V2LogDataDeleteMetadataTargetID) to replace "N/A" with a concise
description stating that TargetID identifies the target entity being
modified/removed, and may be represented as a string or bigint (e.g., UUID,
numeric ID) so consumers know how to construct the identifier; keep the
description short and concrete so readers understand its purpose and accepted
formats.

In `@pkg/client/docs/models/components/v2logtransaction.md`:
- Line 14: The table entries for the fields Reference and Template are
incorrectly formatted as "`**string*`"; update those type cells to the correct
pointer notation "`*string`" (i.e., replace `**string*` with `*string`) in the
v2logtransaction component markdown so both the Reference and Template rows
display the optional string pointer type correctly.
- Line 12: The docs table for the V2LogTransaction component shows a
typographical error in the Metadata type; replace the incorrect
`map[string]*string*` with the correct `map[string]string` to match the
V2LogTransaction struct's Metadata field and remove the stray asterisks so the
generated docs accurately reflect the type.
🧹 Nitpick comments (3)
pkg/client/docs/models/components/v2logdatasetmetadata.md (1)

8-12: Consider describing TargetID/Metadata semantics instead of “N/A.”

A short description will make the table more actionable for readers.

✏️ Suggested doc tweak
-| `TargetID`                                                     | [components.TargetID](../../models/components/targetid.md)     | :heavy_check_mark:                                             | N/A                                                            |                                                                |
-| `Metadata`                                                     | map[string]*string*                                            | :heavy_check_mark:                                             | N/A                                                            | {<br/>"admin": "true"<br/>}                                    |
+| `TargetID`                                                     | [components.TargetID](../../models/components/targetid.md)     | :heavy_check_mark:                                             | Account address (ACCOUNT) or transaction ID (TRANSACTION)      | `users:001`                                                    |
+| `Metadata`                                                     | map[string]*string*                                            | :heavy_check_mark:                                             | Metadata key/value set on the target                           | {<br/>"admin": "true"<br/>}                                    |
pkg/client/docs/models/components/v2logdatadeletemetadatatargetid.md (1)

6-16: Add headings for the supported variants.

The two subsections have empty titles, which hurts scanability in generated docs. Consider naming them (e.g., “String” and “BigInt”).

📝 Suggested doc tweak
-### 
+### String
...
-### 
+### BigInt
test/e2e/api_logs_list_test.go (1)

275-283: compareLogs assumes V2LogDataNewTransaction without type verification.

The helper directly accesses log.Data.V2LogDataNewTransaction without checking if the log type is NEW_TRANSACTION. If this helper is ever used with a different log type, it will panic on nil pointer dereference.

Consider adding a guard or documenting the precondition.

♻️ Suggested improvement
 	var (
 		compareLogs = func(log components.V2Log, expected expectedLog) {
 			Expect(log.ID).To(Equal(expected.id))
 			Expect(log.Type).To(Equal(expected.typ))
+			Expect(log.Type).To(Equal(components.V2LogTypeNewTransaction), "compareLogs only supports NEW_TRANSACTION logs")
 			Expect(log.Data.V2LogDataNewTransaction).NotTo(BeNil())

gfyrag
gfyrag previously approved these changes Jan 19, 2026
Use typed V2LogDataSetMetadata structure instead of map[string]any
@codecov
Copy link

codecov bot commented Jan 19, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 74.63%. Comparing base (fa61317) to head (01c111d).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1234   +/-   ##
=======================================
  Coverage   74.63%   74.63%           
=======================================
  Files         198      198           
  Lines       10410    10410           
=======================================
  Hits         7769     7769           
- Misses       1512     1514    +2     
+ Partials     1129     1127    -2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@flemzord flemzord enabled auto-merge January 19, 2026 13:51
@flemzord flemzord added this pull request to the merge queue Jan 19, 2026
Merged via the queue into main with commit 1cfd498 Jan 19, 2026
9 checks passed
@flemzord flemzord deleted the feat/add-schema-for-logs branch January 19, 2026 17:42
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.

Support transactional outbox pattern for guaranteed event delivery

2 participants