Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(open-api): make insertedAt optional #616

Merged
merged 3 commits into from
Dec 20, 2024
Merged

Conversation

reslene
Copy link
Contributor

@reslene reslene commented Dec 13, 2024

No description provided.

@reslene reslene requested a review from a team as a code owner December 13, 2024 17:53
Copy link

coderabbitai bot commented Dec 13, 2024

Walkthrough

The pull request introduces extensive updates to the Ledger API v2 documentation, enhancing the README.md with detailed descriptions for various endpoints, including authentication methods, request parameters, and response schemas. New endpoints are documented, and existing ones are clarified with examples. Additionally, the error handling structure is updated in the V2ErrorsEnum documentation, and the V2Transaction model is revised to allow optional fields through pointer types. These changes collectively improve the clarity and usability of the API documentation.

Changes

File Path Change Summary
docs/api/README.md Updated with detailed endpoint descriptions, authentication methods, request parameters, and response schemas. Added new endpoints for ledger operations and transaction management. Enhanced pagination handling.
pkg/client/docs/models/components/v2errorsenum.md Updated V2ErrorsEnum to replace V2ErrorsEnumBucketOutdated with V2ErrorsEnumOutdatedSchema.
pkg/client/docs/models/components/v2transaction.md Updated V2Transaction documentation to reflect changes in field types and requirements, transitioning certain fields from required to optional.
pkg/client/models/components/v2errorsenum.go Removed V2ErrorsEnumBucketOutdated and added V2ErrorsEnumOutdatedSchema in the V2ErrorsEnum type.
pkg/client/models/components/v2transaction.go Modified V2Transaction struct to change several fields to pointer types, allowing for optional values. Updated method signatures accordingly.
pkg/testserver/helpers.go Updated ConvertSDKTxToCoreTX to dereference the pointer for the InsertedAt field.
test/e2e/api_balances_aggregated_test.go Modified handling of the InsertedAt field to dereference the pointer, ensuring it holds a concrete value for tests.

Possibly related PRs

  • chore: update dependencies (#592) #599: The changes in this PR also involve updates to the README.md documentation for the Ledger API v2, specifically adding new endpoints and enhancing existing ones, which aligns with the comprehensive updates made in the main PR.
  • fix(upgrades): upgrades when creating a new ledger on an already migration bucket #602: This PR includes modifications to the error handling related to ledger creation, which may connect to the overall API functionality described in the main PR, particularly regarding how errors are documented and handled in the API.
  • fix: blocking migrations #604: Although primarily focused on SQL migration scripts, this PR's changes to the underlying database structure may indirectly relate to the API endpoints documented in the main PR, especially if those endpoints interact with the affected database tables.

Suggested reviewers

  • flemzord
  • paul-nicolas
  • Dav-14

🐇 In the meadow, where bunnies play,
The API grows clearer every day.
With endpoints new and docs refined,
Developers' joy is surely aligned.
So hop along, with code in hand,
The Ledger API now takes a stand! 🌼

Tip

CodeRabbit's docstrings feature is now available as part of our Early Access Program! Simply use the command @coderabbitai generate docstrings to have CodeRabbit automatically generate docstrings for your pull request. We would love to hear your feedback on Discord.


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@reslene reslene requested a review from gfyrag December 13, 2024 17:54
@reslene reslene enabled auto-merge December 13, 2024 17:54
@gfyrag gfyrag force-pushed the fix/InsertedAtOptionnal branch from 5fb49c2 to da10f66 Compare December 20, 2024 13:29
Copy link

@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: 2

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5fb49c2 and da10f66.

⛔ Files ignored due to path filters (7)
  • go.mod is excluded by !**/*.mod
  • go.sum is excluded by !**/*.sum, !**/*.sum
  • openapi.yaml is excluded by !**/*.yaml
  • openapi/v2.yaml is excluded by !**/*.yaml
  • pkg/client/.speakeasy/gen.lock is excluded by !**/*.lock, !**/*.lock
  • tools/generator/go.mod is excluded by !**/*.mod
  • tools/generator/go.sum is excluded by !**/*.sum, !**/*.sum
📒 Files selected for processing (7)
  • docs/api/README.md (1 hunks)
  • pkg/client/docs/models/components/v2errorsenum.md (1 hunks)
  • pkg/client/docs/models/components/v2transaction.md (1 hunks)
  • pkg/client/models/components/v2errorsenum.go (2 hunks)
  • pkg/client/models/components/v2transaction.go (2 hunks)
  • pkg/testserver/helpers.go (1 hunks)
  • test/e2e/api_balances_aggregated_test.go (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (4)
  • pkg/client/docs/models/components/v2errorsenum.md
  • pkg/client/models/components/v2errorsenum.go
  • pkg/client/models/components/v2transaction.go
  • pkg/client/docs/models/components/v2transaction.md
🔇 Additional comments (2)
docs/api/README.md (2)

2638-2638: Documentation accurately reflects InsertedAt optionality

The schema update correctly shows that InsertedAt is now an optional field in the V2Transaction type.


2638-2638: Verify all InsertedAt usages in the codebase

Let's verify that all other usages of InsertedAt have been updated to handle the optional nature of the field.

✅ Verification successful

Let me gather more context about the InsertedAt field's type definition and usage in API responses.


Based on the gathered information, I can now provide the final response:

InsertedAt field is already properly handled as optional

The codebase already handles InsertedAt as an optional field:

  • In the model definition (pkg/client/models/components/v2transaction.go), InsertedAt is properly defined as a pointer (*time.Time) with omitempty JSON tag
  • The test cases and helper functions handle the field appropriately
  • The OpenAPI/Swagger spec correctly defines it as a date-time string without required constraint
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Find all usages of InsertedAt to verify they handle nil case

# Search for direct InsertedAt field access
rg -A 2 "InsertedAt\." 

# Search for InsertedAt in struct initialization
rg -A 2 "InsertedAt:"

# Search for InsertedAt in type definitions
ast-grep --pattern 'InsertedAt $type'

Length of output: 882


Script:

#!/bin/bash
# Search for InsertedAt in API response types and models
rg -A 3 -B 1 "type.*struct" | rg -A 3 -B 1 "InsertedAt"

# Search for InsertedAt in OpenAPI/Swagger specs
fd -e yaml -e json --exec rg -A 2 "insertedAt:"

# Search for validation or handling of InsertedAt
rg -A 3 "InsertedAt.*\b(nil|optional|required)\b"

Length of output: 756

@@ -26,7 +26,7 @@ func ConvertSDKTxToCoreTX(tx *components.V2Transaction) ledger.Transaction {
TransactionData: ledger.TransactionData{
Postings: collectionutils.Map(tx.Postings, ConvertSDKPostingToCorePosting),
Timestamp: time.New(tx.Timestamp),
InsertedAt: time.New(tx.InsertedAt),
InsertedAt: time.New(*tx.InsertedAt),
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Add nil check before dereferencing InsertedAt pointer

The code assumes tx.InsertedAt is never nil, which could lead to a panic. Since InsertedAt is now optional, we should handle the nil case gracefully.

Consider adding a nil check:

-InsertedAt: time.New(*tx.InsertedAt),
+InsertedAt: func() time.Time {
+    if tx.InsertedAt == nil {
+        return time.Now() // or another appropriate default
+    }
+    return time.New(*tx.InsertedAt)
+}(),
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
InsertedAt: time.New(*tx.InsertedAt),
InsertedAt: func() time.Time {
if tx.InsertedAt == nil {
return time.Now() // or another appropriate default
}
return time.New(*tx.InsertedAt)
}(),

@@ -99,7 +99,7 @@ var _ = Context("Ledger engine tests", func() {
})
Expect(err).To(Succeed())

firstTransactionsInsertedAt = ret[2].V2BulkElementResultCreateTransaction.Data.InsertedAt
firstTransactionsInsertedAt = *ret[2].V2BulkElementResultCreateTransaction.Data.InsertedAt
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Add nil check in test for InsertedAt

Since InsertedAt is now optional, the test should verify both cases: when InsertedAt is present and when it's nil.

Add test coverage for nil case and add nil check:

-firstTransactionsInsertedAt = *ret[2].V2BulkElementResultCreateTransaction.Data.InsertedAt
+if ret[2].V2BulkElementResultCreateTransaction.Data.InsertedAt == nil {
+    t.Fatal("expected InsertedAt to be set in test case")
+}
+firstTransactionsInsertedAt = *ret[2].V2BulkElementResultCreateTransaction.Data.InsertedAt
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
firstTransactionsInsertedAt = *ret[2].V2BulkElementResultCreateTransaction.Data.InsertedAt
if ret[2].V2BulkElementResultCreateTransaction.Data.InsertedAt == nil {
t.Fatal("expected InsertedAt to be set in test case")
}
firstTransactionsInsertedAt = *ret[2].V2BulkElementResultCreateTransaction.Data.InsertedAt

@reslene reslene added this pull request to the merge queue Dec 20, 2024
Merged via the queue into main with commit 8cf1718 Dec 20, 2024
8 checks passed
@reslene reslene deleted the fix/InsertedAtOptionnal branch December 20, 2024 13:39
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