Skip to content

fix(openapi): bulk response definition #854

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

Merged
merged 1 commit into from
Apr 8, 2025
Merged

fix(openapi): bulk response definition #854

merged 1 commit into from
Apr 8, 2025

Conversation

gfyrag
Copy link
Contributor

@gfyrag gfyrag commented Apr 8, 2025

Fixes LX-33

@gfyrag gfyrag requested a review from a team as a code owner April 8, 2025 08:23
Copy link

coderabbitai bot commented Apr 8, 2025

Walkthrough

This update removes the "details" field from error response examples in the API documentation and updates the bulk response model. The changes include modifying required field flags in the documentation, converting certain fields in the V2BulkResponse struct to pointer types with the omitempty option, and removing the GetDetails method. Additionally, the error handling in the generator's Apply method now properly dereferences error message pointers. These modifications aim to simplify and correct the error response structure across the API and client models.

Changes

File(s) Change Summary
docs/api/README.md, pkg/client/docs/models/components/v2bulkresponse.md Removed the "details" field from error response examples and documentation; updated required flags for Data, ErrorCode, and ErrorMessage fields.
pkg/client/models/components/v2bulkresponse.go Converted ErrorCode and ErrorMessage fields to pointers with the omitempty option; updated method signatures (returning pointers) and removed the GetDetails() method.
pkg/generate/generator.go Modified the Apply method to explicitly dereference error message fields from V2BulkResponse for accurate HTTP 400 error handling.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant Generator
    participant BulkResponse

    Client->>Generator: Send request causing error (e.g., bad cursor)
    Generator->>BulkResponse: Retrieve ErrorMessage & ErrorCode pointers
    BulkResponse-->>Generator: Return pointer values (nil if absent)
    Generator->>Client: Respond with HTTP 400 and simplified error response (without "details")
Loading

Assessment against linked issues

Objective Addressed Explanation
LX-33: fix(openapi): Invalid definition of bulk response

Possibly related PRs

Poem

I'm a rabbit, hopping along the code trail,
No extra "details" left to derail.
Pointers now dance with a nimble beat,
Error responses feel oh so neat.
With binkies and thumps, I celebrate the fix!
🐇💻 Happy coding, with every hop and click!

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @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.

@gfyrag gfyrag enabled auto-merge April 8, 2025 08:24
Copy link

codecov bot commented Apr 8, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 82.46%. Comparing base (8a8c3ba) to head (345d3bd).
Report is 4 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #854      +/-   ##
==========================================
+ Coverage   82.17%   82.46%   +0.28%     
==========================================
  Files         139      140       +1     
  Lines        7536     7595      +59     
==========================================
+ Hits         6193     6263      +70     
+ Misses       1027     1017      -10     
+ Partials      316      315       -1     

☔ 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.

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: 1

🧹 Nitpick comments (1)
docs/api/README.md (1)

3869-3869: Duplicate Heading Warning:
Static analysis indicates that there are multiple headings with the same content (MD024). Although this can sometimes be intentional in API documentation, it could also potentially reduce clarity. Consider reviewing these duplicated headings to determine if they can be made unique or supplemented with additional context. If the duplications are intentional, it might be helpful to add a comment to explain the rationale.

🧰 Tools
🪛 markdownlint-cli2 (0.17.2)

3869-3869: Multiple headings with the same content
null

(MD024, no-duplicate-heading)

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between a2ef7c9 and 345d3bd.

⛔ Files ignored due to path filters (3)
  • openapi.yaml is excluded by !**/*.yaml
  • openapi/v2.yaml is excluded by !**/*.yaml
  • pkg/client/.speakeasy/gen.lock is excluded by !**/*.lock, !**/*.lock
📒 Files selected for processing (4)
  • docs/api/README.md (2 hunks)
  • pkg/client/docs/models/components/v2bulkresponse.md (1 hunks)
  • pkg/client/models/components/v2bulkresponse.go (1 hunks)
  • pkg/generate/generator.go (1 hunks)
🧰 Additional context used
🧬 Code Definitions (2)
pkg/generate/generator.go (1)
pkg/client/models/components/v2bulkresponse.go (1)
  • V2BulkResponse (5-9)
pkg/client/models/components/v2bulkresponse.go (2)
pkg/client/models/components/v2bulkelementresult.go (1)
  • V2BulkElementResult (157-165)
pkg/client/models/components/v2errorsenum.go (1)
  • V2ErrorsEnum (10-10)
🪛 markdownlint-cli2 (0.17.2)
docs/api/README.md

3869-3869: Multiple headings with the same content
null

(MD024, no-duplicate-heading)

🔇 Additional comments (7)
pkg/client/docs/models/components/v2bulkresponse.md (1)

6-10: Documentation properly reflects API changes

The table updates accurately reflect the changes in the V2BulkResponse struct, where fields are now optional with omitempty tags. This maintains consistency between code and documentation.

pkg/client/models/components/v2bulkresponse.go (5)

6-8: Appropriate conversion of fields to optional with omitempty

The conversion of Data, ErrorCode, and ErrorMessage fields to be optional (with omitempty tag) and the conversion of ErrorCode and ErrorMessage to pointer types is appropriate. This allows these fields to be omitted from JSON responses when they're not present.


11-16: Improved nil handling in GetData method

The GetData method now correctly returns nil instead of an empty slice when the receiver is nil, which is consistent with the behavior of the other getter methods.


18-23: Consistent update to GetErrorCode method

The GetErrorCode method has been properly updated to return a pointer type, maintaining consistency with the field type change in the struct.


25-30: Consistent update to GetErrorMessage method

The GetErrorMessage method has been properly updated to return a pointer type, maintaining consistency with the field type change in the struct.


1-30: Removed GetDetails method

The GetDetails method has been removed, which is consistent with the removal of the Details field from the struct and documentation. This simplifies the error response structure.

docs/api/README.md (1)

3766-3866: Bulk Response Schema Update – "details" Field Removal:
The change in the V2BulkResponse schema correctly removes the "details" field from the error response example. This aligns with the PR objective of simplifying and correcting the bulk response definition. Please verify that the client code or any downstream documentation that previously expected the "details" field is updated accordingly.

Comment on lines +155 to +156
*response.V2BulkResponse.ErrorMessage,
*response.V2BulkResponse.ErrorCode,
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Check for nil pointers before dereferencing ErrorMessage and ErrorCode

The code now properly dereferences the ErrorMessage and ErrorCode pointers from the V2BulkResponse struct. However, there's no nil check before dereferencing, which could lead to a panic if these fields are nil in the response.

Consider adding nil checks before dereferencing these pointers:

if response.HTTPMeta.Response.StatusCode == http.StatusBadRequest {
+    var errorMsg string
+    if response.V2BulkResponse.ErrorMessage != nil {
+        errorMsg = *response.V2BulkResponse.ErrorMessage
+    } else {
+        errorMsg = "unknown error"
+    }
+    
+    var errorCode string
+    if response.V2BulkResponse.ErrorCode != nil {
+        errorCode = string(*response.V2BulkResponse.ErrorCode)
+    } else {
+        errorCode = "UNKNOWN"
+    }
+    
     return nil, fmt.Errorf(
         "unexpected error: %s [%s]",
-        *response.V2BulkResponse.ErrorMessage,
-        *response.V2BulkResponse.ErrorCode,
+        errorMsg,
+        errorCode,
     )
}
📝 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
*response.V2BulkResponse.ErrorMessage,
*response.V2BulkResponse.ErrorCode,
if response.HTTPMeta.Response.StatusCode == http.StatusBadRequest {
var errorMsg string
if response.V2BulkResponse.ErrorMessage != nil {
errorMsg = *response.V2BulkResponse.ErrorMessage
} else {
errorMsg = "unknown error"
}
var errorCode string
if response.V2BulkResponse.ErrorCode != nil {
errorCode = string(*response.V2BulkResponse.ErrorCode)
} else {
errorCode = "UNKNOWN"
}
return nil, fmt.Errorf(
"unexpected error: %s [%s]",
errorMsg,
errorCode,
)
}

@gfyrag gfyrag added this pull request to the merge queue Apr 8, 2025
Merged via the queue into main with commit ba4fdb1 Apr 8, 2025
10 checks passed
@gfyrag gfyrag deleted the fix/openapi-bulk branch April 8, 2025 08:52
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