Skip to content

Contextual REST companions#1513

Open
sebaciv wants to merge 3 commits into
masterfrom
ctx-companions
Open

Contextual REST companions#1513
sebaciv wants to merge 3 commits into
masterfrom
ctx-companions

Conversation

@sebaciv

@sebaciv sebaciv commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

Adds contextual and custom-implicits REST companion APIs to udash-rest, together with their ScalaDoc, unit tests, and guide documentation.

New companions

Contextual APIs — let a server-side method implementation receive request-scoped context (e.g. the authenticated user) that never appears in the client-facing interface:

  • WithCtx[Ctx, R] and the CtxTask[T] = WithCtx[Ctx, Task[T]] alias, with CtxTaskOps combinators and a CtxTaskCompanion factory; NoCtx marks the context-free client side.
  • ContextualServerRestApis[Implicits, Ctx] — companions for server-only contextual APIs (ServerApiCompanion, ServerApiImplCompanion).
  • ContextualServerAndClientRestApis[Implicits] — companions for contextual APIs shared between server and client (the client fixes the context to NoCtx).

Custom-implicits companions — packaged companion sets bound to a user-supplied implicits bundle, so custom serialization/schema is threaded into macro derivation without per-shape boilerplate:

  • RestApisWithCustomImplicits[Implicits] — ApiCompanion / NoDocApiCompanion / ServerApiCompanion / ClientApiCompanion.
  • ApiDataWithCustomImplicits[Implicits] — data-type companions: ApiDataCompanion, ApiDataCompanionWithDeps, ApiSealedCaseCompanion, ApiSealedSubHierarchyCompanion, and poly companions (PolyApiDataCompanion, PolyObjectApiDataCompanion, Poly2ApiDataCompanion).

Supporting helpers: RestNamedValueEnumCompanion, HasRestSchema, RestFlattenedStructure, CaseNameValidatingCodec.

Documentation (ScalaDoc)

  • ScalaDoc for all of the above, with usage examples.
  • Examples use DefaultRestImplicits (which already supports both Task and Future).

Tests

Unit tests for the new companions (run on JVM, cross-compile on JS):

  • WithCtx / CtxTaskOps / CtxTaskCompanion combinators
  • Contextual server-only and server+client (NoCtx) round-trips
  • RestApisWithCustomImplicits round-trip + OpenAPI generation
  • ApiDataWithCustomImplicits: sealed-case, sealed-subhierarchy, poly (1-arg / object / 2-arg) and WithDeps companions
  • RestNamedValueEnumCompanion schema, CaseNameValidatingCodec discriminator validation, and RestFlattenedStructure.caseRestSchema

The tests deliberately use a type with no default serialization whose codec/schema is provided only through injected implicits — verifying that a custom implicits bundle is actually collected by the derivation macros.

Guide (rest.md)

  • New "Contextual REST APIs" section (WithCtx / CtxTask, server Ctx vs client NoCtx).
  • Documented RestApisWithCustomImplicits / ApiDataWithCustomImplicits in the custom-serialization section.
  • Fixed a stale MonixRestImplicits example link.

@sebaciv
sebaciv requested a review from ddworak July 3, 2026 14:49
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.

1 participant