Repository navigation
Port reflectapi-ex features and enhance ResponseError trait checks - #265
Merged
Merged
Conversation
…s greater level of checking for returned status codes
There was a problem hiding this comment.
Claude Code Review
This repository is configured for manual code reviews. Comment @claude review for a one-time review, or @claude review always to subscribe this PR to a review on every future push.
Tip: disable this comment in your organization's Code Review settings.
… foundations to make this type feasible
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.
Summary
New wire types, an opt-in
conventionsmodule, aResponseErrortrait replacingStatusCode, and stricter build checks. The guide gains an API design standard written as numbered rules, with lints that check a schema against it. Most of this was proven in a downstream extension crate first, and is ported here so services can share it.Wire types
Bounded<T, MIN, MAX>andBoundedMax<T, MAX>: a string or collection with a checked length. A request with another length is refused with400before the handler runs, and every client checks the bounds before sending:bounded()orbounded.try().min_length/max_length.reflectapi::Boundeditself.Raw<T>(featurejson): aTkept as the JSON it arrived as, to store or forward unchanged, withpeekto read a few fields. Under MessagePack it is converted at the edge.Encoded<T>(featurejson): a typed value carried as an opaque string, such as a page cursor: JSON, then base64url. Encoded, not secret.EmptyderivesCopyandHash.fixedSizeArray().reflectapi::conventions(featureconventions)pagination:PageRequest { cursor, limit },ForwardPaginatedList,NonPaginatedList, all keeping their items underitems. The cursor can be typed,PageRequest<Encoded<Cursor>>, while clients still see a string.identity:Identity<I>andIdentityData<I, D>.conflict: anifclause on writes,{"if": {"exists": "replace"}, …}.Conditional<T, If>through aliases such asInsertOrElse,UpdateOrElseandRemoveOrElse.conflict::actions.…OrElseRequiredtwin of each alias serves the sets without a default.Idempotentmarks the sets safe to process twice.conflict::matchingadds conditions on existence or edition.lints: one function per rule of the design standard, forBuilder::validate, or all of them throughlints::ALL. Each error names its rule in the newValidationError::rulefield and links to it. What they check:create/delete/upsert, nosearch-by-….kind; fields and enum values in snake_case.x-prefix.EnumorStructsuffix; at most two modules; nomodelsorerrorsmodule.Breaking changes
ResponseError, and derives it with#[derive(reflectapi::ResponseError)]. It providesstatus()andheaders(), withOutput + Serializeas supertraits. The derive refuses, at compile time, statuses a route's error must not use.#[derive(reflectapi::StatusCode)]becomes#[derive(reflectapi::ResponseError)], with the same attributes.impl StatusCodethat overridesresponse_headersbecomes animpl ResponseErrorwithstatusandheaders.StatusCodeis deprecated. An impl of it withoutresponse_headersstill compiles, with a warning. It is removed in the next breaking release, andBox<E>then forwardsResponseErrorasArc<E>does.build()refuses schemas whose clients would lose data or fail to compile:Option;Fixes
Nis no longer found inside a type namedNode.NonZeroU8…NonZeroU128and no plain integer of its width no longer crashes OpenAPI generation.Docs
docs/src/design/standard.md): 156 rules, each a MUST, SHOULD or MAY statement with a stable id such asapi-filter-bounds-together.docs/serve.pyserves the whole site locally with live reload.llms.txtpoints agents to the standard.docs/proposals/.Tests
RawandBoundedin both formats,ResponseError, the build checks, and each lint against a route that breaks its rule and an API that follows them all.cargo test --workspace --all-features, clippy, the book's doctests and the docs build all pass.Notes for review
bench/formats/and the standard's text. The code to review is mostlybounded.rs,raw.rs,encoded.rs,transcode.rs,conventions/,builder/result.rs,builder/mod.rsandcodegen/.ResponseErrorandEncodedwill 404 until this is released.