From d9d0403d45ef432f008a1d10e94144dacd585a09 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Thu, 24 Sep 2026 18:22:21 +0300 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat(limits):=20publish=20the=20hol?= =?UTF-8?q?iday=20PATCH=20bound,=20raise=20the=20profile=20section=20cap?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `UpdateHoliday.name` now carries the same published `max_length` its create twin does, so a client validates a PATCH against the same bound the server re-checks — the runtime refusal was already there, only the contract was silent. `MAX_PROFILE_COURSES` goes 20 -> 100: the profile course block became one row per section, and a teacher's sections are their courses multiplied by the classes they teach, so the course-era figure truncated a real timetable. It stays a cap on the response, not on membership — `/courses/me` and `/classes/me` carry the full lists, and the bound is published so a client can page for the rest. --- README.md | 2 +- src/constant.rs | 10 +++++++--- src/web/holidays.rs | 7 +++---- tests/spec_bounds.rs | 6 ++++++ 4 files changed, 17 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 8db2046..5b3c85e 100644 --- a/README.md +++ b/README.md @@ -733,7 +733,7 @@ drift from it**, which is enforced rather than asked for: and fails unless each one is either referenced by `src/web/limits.rs` or listed as a deliberate exclusion *with a reason*. A new constant breaks the suite until someone decides, consciously, whether clients need it. -- `tests/spec_bounds.rs` builds the OpenAPI document, reads all 241 published +- `tests/spec_bounds.rs` builds the OpenAPI document, reads all 242 published bounds back out of the emitted JSON, and asserts each equals its constant. This exists because utoipa's `#[schema(max_length = …)]` accepts a **literal only** — a `const` there does not compile — so the annotations are diff --git a/src/constant.rs b/src/constant.rs index 8bbf8a4..bf40d81 100644 --- a/src/constant.rs +++ b/src/constant.rs @@ -41,10 +41,14 @@ pub const MAX_DISPLAY_NAME_LEN: usize = 50; pub const MAX_BIO_LEN: usize = 500; pub const MAX_ADDRESS_LEN: usize = 500; -/// How many course and class references one profile read embeds. A cap on the +/// How many **section** rows one profile read embeds — the block is one row +/// per section, so this counts sections, not catalogue courses. A cap on the /// response, not on membership — the full lists stay at `/courses/me` and -/// `/classes/me`. -pub const MAX_PROFILE_COURSES: usize = 20; +/// `/classes/me`. 100 because a teacher's sections are their courses +/// multiplied by the classes they teach, so the course-era figure truncated a +/// real timetable, while one course row's own cap (`MAX_COURSE_SECTIONS`) +/// bounds only a single row. +pub const MAX_PROFILE_COURSES: usize = 100; pub const MAX_PROFILE_CLASSES: usize = 5; /// RFC 5321's practical upper bound for a full address. diff --git a/src/web/holidays.rs b/src/web/holidays.rs index cdbc2ef..151ba9d 100644 --- a/src/web/holidays.rs +++ b/src/web/holidays.rs @@ -54,10 +54,9 @@ struct CreateHoliday { #[derive(Deserialize, ToSchema)] struct UpdateHoliday { - /// New name, held to the same bound as `POST` — the `HolidayName` newtype - /// re-checks it. No `maxLength` here: a published bound needs its own row - /// in the OpenAPI bounds table, and `CreateHoliday.name` already carries - /// this one. + /// New name, held to the same published bound as `POST` — and still + /// re-checked by the `HolidayName` newtype at runtime. + #[schema(max_length = 100)] name: Option, #[schema(example = 1_793_318_400_000_i64)] starts_at: Option, diff --git a/tests/spec_bounds.rs b/tests/spec_bounds.rs index 4cac23c..8c52715 100644 --- a/tests/spec_bounds.rs +++ b/tests/spec_bounds.rs @@ -1201,6 +1201,12 @@ fn expectations() -> Vec<(&'static str, &'static str, &'static str, i64)> { "maxLength", MAX_HOLIDAY_NAME_LEN as i64, ), + ( + "UpdateHoliday", + "name", + "maxLength", + MAX_HOLIDAY_NAME_LEN as i64, + ), ("CreateSlot", "topic", "maxLength", MAX_SESSION_TOPIC_LEN as i64), // The offering spine (course × grade_level templates) and the // per-class instance overrides: same bounds as the catalog course