feat(openapi): Harden @api_endpoint decorator and OpenAPI generator#1617
Merged
feat(openapi): Harden @api_endpoint decorator and OpenAPI generator#1617
Conversation
|
| Branch | feat/openapi-improvements |
| Testbed | ubuntu-22.04 |
Click to view all benchmark results
| Benchmark | Latency | Benchmark Result minutes (m) (Result Δ%) | Lower Boundary minutes (m) (Limit %) | Upper Boundary minutes (m) (Limit %) |
|---|---|---|---|---|
| sync-v2 (up to 20000 blocks) | 📈 view plot 🚷 view threshold | 1.60 m(-6.44%)Baseline: 1.71 m | 1.54 m (96.19%) | 2.05 m (77.97%) |
c35f3ff to
0fc1fc7
Compare
0fc1fc7 to
6053018
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1617 +/- ##
==========================================
+ Coverage 85.38% 85.40% +0.02%
==========================================
Files 462 462
Lines 31135 31166 +31
Branches 4720 4730 +10
==========================================
+ Hits 26584 26617 +33
- Misses 3639 3641 +2
+ Partials 912 908 -4
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
jansegre
previously approved these changes
Mar 13, 2026
6053018 to
145fad9
Compare
glevco
previously approved these changes
Mar 17, 2026
145fad9 to
3efa052
Compare
3efa052 to
199c42b
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
The
@api_endpointdecorator and OpenAPI generator introduced in the pydantic migration PR had several gaps identified during code review: unhandledHathorErrorexceptions would propagate as 500s, PydanticValidationErrormessages leaked model internals to API consumers, there was no request body size limit, duplicate endpoint registrations were silently accepted, and the OpenAPI generator could crash onOptionalresponse models or silently overwrite conflicting$defs. This PR addresses all approved findings from that review.Acceptance Criteria
@api_endpointcatchesHathorErrorraised in handlers and returns a structuredErrorResponsewith HTTP 400 (or the exception'sstatus_codeattribute). This behavior can be disabled per-endpoint withcatch_hathor_exceptions=FalseValidationErrormessages are sanitized to only include field paths and messages (e.g.,age: Input should be a valid integer), not raw model internals"Request body is not valid JSON"instead of the rawJSONDecodeErrormessagemax_body_sizeparameter (default 1MB), returning HTTP 413 when exceededValueErrorimmediatelyNoneTypefromOptional[...]unions and raisesTypeErrorfor any other non-BaseModel type in a response model union$defsname collisions in the OpenAPI generator raiseValueErrorinstead of silently overwritingresponse_modelincludesHealthcheckStrictFailResponseso the OpenAPI spec documents thestrict_status_code=1behaviorvalidate_addresserror responses use a stable'invalid_address'error code instead of leaking Python exception class names (e.g.,'ScriptError','InvalidAddress')RequestModelbase class removedVersionResource, typo fix (OpenSPI -> OpenAPI) in CLI help, type annotation added tovalidate_address.render_GETChecklist
master, confirm this code is production-ready and can be included in future releases as soon as it gets mergedvalidate_addresserror responses now returnerror: 'invalid_address'instead of the Python exception class name — clients matching on specific error strings will need updating