feat(serve): add REST API server command#232
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
98aadb8 to
2a4b1a8
Compare
2a4b1a8 to
145bbbe
Compare
|
Hi @hfl0506 we have conflicts here, Could you resolve it with the latest branch |
145bbbe to
a44e748
Compare
|
Warning Review limit reached
Next review available in: 24 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughAdds the ChangesServe REST API
Estimated code review effort: 4 (Complex) | ~60 minutes Sequence Diagram(s)sequenceDiagram
participant CLI
participant HTTPServer
participant RESTHandler
participant Core
participant UIGenerator
CLI->>HTTPServer: start serve command
HTTPServer->>RESTHandler: receive POST request
RESTHandler->>Core: convert or merge request data
Core-->>RESTHandler: return datasets
RESTHandler->>UIGenerator: generate HTML for UI output
RESTHandler-->>HTTPServer: write JSON, HTML, or problem response
Possibly related issues
Possibly related PRs
Suggested labels: Suggested reviewers: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 5
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@cmd/serve_contract.go`:
- Around line 570-577: Update the settings loop in the dataset validation flow
to track each decoded ChartType and reject duplicate types before applyUIOptions
can index them by type. Return a validation error identifying the duplicate
setting while preserving normal handling for unique settings. Add or update a
dataset-validation test covering two settings with the same type and asserting
rejection.
- Around line 461-476: Update the chart configuration construction around
targetTypes and the existing/overrides lookups so every explicitly selected
valid chart type produces a configuration even when the dataset has neither a
base setting nor an override; materialize that chart type’s defaults instead of
silently continuing. Preserve skipping unknown chart types, and add a test
covering a valid charts.types selection absent from the input dataset.
In `@cmd/serve.go`:
- Around line 218-222: Update the error handling in the generateUI path and the
corresponding alternate path in the serving handler to stop returning
err.Error() through writeAPIProblem. Log the underlying generation errors
server-side, then return a generic internal-server-error detail to clients while
preserving the existing HTTP status and response flow.
- Around line 105-106: Replace the direct Cobra bindings for Host and Port in
the serve command with bindings through cli.FlagBag, using the existing FlagBag
setup and lifecycle conventions. Preserve the current flag names, shorthand,
defaults, descriptions, and option targets while removing the direct StringVar
and IntVarP calls.
- Around line 231-258: Update handleMerge to negotiate the request’s Accept
header before writing the JSON response, returning HTTP 406 when
application/json is explicitly rejected while preserving the existing successful
JSON response otherwise. Add or update the merge endpoint test to send Accept:
text/html and assert a 406 response.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 10bd4102-35d1-4d7e-b167-8bb7819e71a6
📒 Files selected for processing (6)
api/openapi.yamlcmd/serve.gocmd/serve_contract.gocmd/serve_test.gocmd/testing.godocs/src/content/docs/commands/serve.mdx
Hi @fahimfaisaal resolved and kindly take a look when you have a chance. Thanks |
fahimfaisaal
left a comment
There was a problem hiding this comment.
Oversized requests are currently handled as 400 Bad Request because *http.MaxBytesError flows into writeValidationProblem. Please detect this error and return a 413 Content Too Large Problem Details response. Update the limit test to assert the status, content type, response body, and that no application operation runs. Also add 413 to the OpenAPI responses and error documentation.
fahimfaisaal
left a comment
There was a problem hiding this comment.
Unknown paths and wrong HTTP methods currently use http.ServeMux’s plain-text 404/405 responses. Please return application/problem+json for both cases, preserve Allow: POST on 405 responses, and update the routing tests to verify status, content type, Problem Details body, and the Allow header.
fahimfaisaal
left a comment
There was a problem hiding this comment.
Semantic validation errors currently always return 400 Bad Request, while the local REST specification requires 400 only for malformed JSON and 422 Unprocessable Content for valid JSON that violates schema or semantic constraints. Please separate these error paths and update the implementation, OpenAPI contract, documentation, and tests to use consistent statuses.
fahimfaisaal
left a comment
There was a problem hiding this comment.
When graceful shutdown reaches its deadline or fails, the server returns an error without force-closing active connections. Please call Server.Close() after Server.Shutdown() fails or times out, preserve the relevant shutdown/close error, and add a test with an active request proving connections are force-closed after the deadline.
|
and finally, can we improve the coverage a bit? @hfl0506 |
|
Hi @fahimfaisaal I updated from what you mention, kindly have a look when you have a moment. Thanks |
fahimfaisaal
left a comment
There was a problem hiding this comment.
Thanks for the changes. we can improve it more in the near future. for now it LGTM
Related issues
Resolve #213
Changes
Added vizb serve with --host/--port defaults, limits, timeouts, listener
errors, and bounded SIGINT/SIGTERM shutdown in cmd/serve.go.
Registered testable POST route composition for /, /merge, and /ui.
Added lifecycle/configuration/limit tests in cmd/serve_test.go.
Documented limits and lifecycle defaults in docs/src/content/docs/commands/
Included the local extract a server-safe Vizb core #212 server-safe core prerequisite commits.
Test Steps
go test ./... task test:cli task format:check:cli go vet ./...Summary by CodeRabbit
New Features
vizb servecommand for local HTTP conversion (/), merging (/merge), and HTML UI generation (/ui).application/problem+jsonerror responses and improvedAcceptnegotiation behavior.settingsso each chart type can appear at most once; added support for integer-typed CLI/chart flags.Documentation
serveand API docs with request limits, lifecycle/shutdown behavior, and refined error/status meanings.Tests