Decide OpenAPI schema strategy for domain newtypes (keep domain I/O-free)
#3
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
The
domaincrate is intentionally I/O-free (onlyuuid+serde). When real entities start surfacing through the API, newtypes likeOrgIdwill needutoipa::ToSchemato appear in the OpenAPI document — but we don't want to compromisedomain's purity.Decide the approach before the first entity lands:
utoipaderive indomain(it's a non-I/O, schema-only dependency).domainfree ofutoipaand defineToSchemawrappers/DTOs in theapicrate.Trade-off: A is less boilerplate but widens
domain's dependency surface; B keepsdomainminimal but adds a mapping layer. Pick one and document it in the architecture spec.Source: Foundation (Plan 0) final review — forward-looking.
Decision: Option A — allow the
utoipa::ToSchemaderive indomain.Rationale:
domainalready carriesserde/serde_json/time(data-shape deps, no real I/O), andutoipais a schema-description macro in that same family — not runtime I/O (no axum/sqlx).VisibilityandAuthorityKindalready deriveSerialize/Deserializewith#[serde(rename_all = "lowercase")], so addingToSchemais a one-word change that yields proper string enums with no duplicate enum set to maintain inapi. The mapping layer that Option B would add (parallel enums + domain→api conversion) isn't worth it for fixed ≤7-variant sets.Scope of the rule:
domainmay deriveToSchema(and use#[schema(...)]attrs) on pure data types. It must NOT gain runtime-I/O deps (axum, sqlx, etc.) — theapicrate still owns HTTP/DB concerns and its own request/response View DTOs.Implemented alongside #29 (enum-typing) and #24 (open-map
fields). Closing.