Type enum-valued fields (visibility, data_type, authority kind) as enums in OpenAPI #29
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?
Context
Several enum-valued fields are emitted in the OpenAPI document as bare
string, so the generated TypeScript client (web/src/api/schema.d.ts) types them asstringrather than a literal union. The frontend then carriesas-casts to the real union at each use site:AdminObjectView.visibility/PublicView.visibility→string. Castas Visibilityinweb/src/objects/visibility-badge.tsx,object-detail.tsx, andpublish-control.tsx(milestones 1 & 3).FieldDefinitionView.data_type→string(the frontend switches on it infield-input.tsx).AuthorityView.kind/FieldDefinitionView.authority_kind→string.These are almost certainly annotated
#[schema(value_type = String)](or similar) on the Rust side, which flattens the enum to a string in the schema.What to do
Where the Rust enum is a fixed, closed set (
Visibility= draft/internal/public;FieldType's data_type tag;AuthorityKind= person/organisation/place), let utoipa emit a proper string enum (e.g. deriveToSchemaon the enum so the schema lists the allowed values) instead of a barestring. Then regenerateweb/src/api/schema.d.ts— the generated types become literal unions and the frontendas Visibility/data_typecasts can be removed.Acceptance
visibility,data_type, and authoritykind(string enums).schema.d.tstypes them as unions; the frontend casts drop; web typecheck/tests stay green.References
crates/api/src/admin_objects.rs,admin_authorities.rs,public.rs;domain::{Visibility, FieldType, AuthorityKind}(all haveas_str/from_db+ serde lowercase).fieldsmap typing). Both are "tighten the generated client contract" cleanups.