Skip to content

BE-859: Connect ProblemType and ProblemDetails - #9756

Merged
TimDiekmann merged 2 commits into
t/be-853-add-the-initial-problematic-cratefrom
t/be-353-connect-problem-types-and-details
Sep 16, 2026
Merged

TimDiekmann merged 2 commits into
t/be-853-add-the-initial-problematic-cratefrom
t/be-353-connect-problem-types-and-details

Conversation

@TimDiekmann

@TimDiekmann TimDiekmann commented Sep 16, 2026

Copy link
Copy Markdown
Member

🌟 What is the purpose of this PR?

Create problem occurrences from a shared ProblemType through calls such as INVALID_PARAMETERS.detail(message).instance(uri). These calls borrow the type URI and title from the definition, and callers can omit extensions without constructing NoExtensions.

🔗 Related links

Ignore BE-353

🚫 Blocked by

🔍 What does this change?

  • Add const conversions from &ProblemType and ProblemType to ProblemDetails, with empty extensions and omitted occurrence fields. Converting a reference borrows the metadata; converting an owned definition moves it.
  • Add .detail(), .instance(), and .extensions() to both types. Each call returns complete problem details, and replacing extensions can change their type.
  • Default the extension type to NoExtensions.
  • Support const construction through nightly const traits. The destruction bound applies to the old extension value when it is replaced; runtime calls support extensions with ordinary Drop implementations.
  • Document the methods with complete examples for borrowed explanations, owned instance URIs, and serialized extension members.
  • Use the fluent methods in existing serialization tests and check borrowed and owned strings with assert_matches!.

Pre-Merge Checklist 🚀

🚢 Has this modified a publishable library?

This PR:

  • modifies a Cargo-publishable library, but it is not yet ready to publish

📜 Does this require a change to the docs?

The changes in this PR:

  • require changes to docs which are made as part of this PR

🕸️ Does this require a change to the Turbo Graph?

The changes in this PR:

  • do not affect the execution graph

⚠️ Known issues

The crate requires nightly features const_convert, const_destruct, and const_trait_impl. Const callers use Cow::Borrowed(...) for string literals and enable const_convert and const_trait_impl. Runtime calls accept &str, String, and Cow.

🐾 Next steps

Connect problem definitions to OpenAPI and the public /v1 API in follow-up work.

🛡 What tests cover this?

  • Five doctests cover runtime and const construction, borrowed explanations, owned instance URIs, and serialized extension members.
  • A source-local unit test verifies that converting a reference borrows the definition's owned metadata strings.
  • The details_static_metadata integration test creates an occurrence through fluent calls, checks that the detail and instance borrow the original strings, and checks the serialized output.
  • All 30 crate tests pass, including extension-validation tests and JSON Schema snapshots. All five doctests, Clippy, Rustdoc, and formatting checks also pass.

❓ How to test this?

Run from the repository root with the pinned toolchain:

cargo nextest run -p problematic --all-features
cargo test -p problematic --all-features --doc
cargo clippy -p problematic --all-features --all-targets --no-deps -- -D warnings
RUSTDOCFLAGS='-D warnings' cargo doc -p problematic --all-features --no-deps
cargo fmt -p problematic --check

📹 Demo

let details = INVALID_PARAMETERS
    .detail("The limit must be a positive integer.")
    .instance("/problem-occurrences/42");

let details = details.extensions(extensions);

let details = ProblemDetails::from(&INVALID_PARAMETERS);

@TimDiekmann
TimDiekmann added this pull request to stack #9757 September 16, 2026 11:47
@vercel

vercel Bot commented Sep 16, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

4 Skipped Deployments
Project Deployment Actions Updated
hash Ignored Ignored Preview Sep 16, 2026 12:23pm UTC
hashdotdesign-tokens Ignored Ignored Preview Sep 16, 2026 12:23pm UTC
petrinaut Skipped Skipped Sep 16, 2026 12:23pm UTC
petrinaut-docs Skipped Skipped Sep 16, 2026 12:23pm UTC

Request Review

@vercel
vercel Bot temporarily deployed to Preview – petrinaut-docs September 16, 2026 11:47 Inactive
@vercel
vercel Bot temporarily deployed to Preview – petrinaut September 16, 2026 11:47 Inactive
@github-actions github-actions Bot added area/libs Relates to first-party libraries/crates/packages (area) area/tests New or updated tests labels Sep 16, 2026
@TimDiekmann TimDiekmann self-assigned this Sep 16, 2026
@TimDiekmann TimDiekmann changed the title Add const fluent construction for problem details BE-353: Connect ProblemType and ProblemDetails Sep 16, 2026
@vercel
vercel Bot temporarily deployed to Preview – petrinaut-docs September 16, 2026 12:22 Inactive
@vercel
vercel Bot temporarily deployed to Preview – petrinaut September 16, 2026 12:22 Inactive
@TimDiekmann
TimDiekmann marked this pull request as ready for review September 16, 2026 12:30
@cursor

cursor Bot commented Sep 16, 2026

Copy link
Copy Markdown

PR Summary

Low Risk
Library-only API ergonomics for HTTP problem details; no auth, persistence, or wire-format behavior changes beyond optional default type parameter.

Overview
Connects shared ProblemType definitions to RFC 9457 occurrences via From conversions and a fluent builder API, so callers can write INVALID_PARAMETERS.detail(msg).instance(uri) instead of manually copying metadata and NoExtensions.

ProblemDetails now defaults its extension type parameter to NoExtensions. Both ProblemType and ProblemDetails gain const detail, instance, and extensions methods; reference-based conversion borrows type URI/title from the definition when possible. The crate enables nightly const-trait features (const_convert, const_destruct, const_trait_impl) to support const construction.

Tests and doctests are updated to use the new API and assert borrowing behavior with assert_matches!.

Reviewed by Cursor Bugbot for commit a05f516. Bugbot is set up for automated code reviews on this repo. Configure here.

@TimDiekmann
TimDiekmann requested a review from a team September 16, 2026 12:31
@TimDiekmann TimDiekmann changed the title BE-353: Connect ProblemType and ProblemDetails BE-859: Connect ProblemType and ProblemDetails Sep 16, 2026
@TimDiekmann
TimDiekmann added this pull request to the merge queue Sep 16, 2026
Merged via the queue into main with commit 99c2ea6 Sep 16, 2026
62 checks passed
@TimDiekmann
TimDiekmann deleted the t/be-353-connect-problem-types-and-details branch September 16, 2026 15:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/libs Relates to first-party libraries/crates/packages (area) area/tests New or updated tests

Development

Successfully merging this pull request may close these issues.

2 participants