From a7f71d66f200db9041e6584d35bdb46a40f3cd66 Mon Sep 17 00:00:00 2001
From: Doug Mealing
Date: Fri, 13 Nov 2026 12:50:50 -0500
Subject: [PATCH 1/5] fix: generated create routes store only client-settable
fields (1.2.x security)
Python 1.2.1 stopped its generated routes from handing raw request input to
the repository. The same audit found related create-path holes in 1.2.0 in
the other four ports; this closes each in its own idiom. Server-owned values
are dropped silently, never answered with 400.
- Java (codegen-spring): create strips a generated id, readOnly and derived
fields; a TPH per-subtype create also strips the body discriminator and
sibling-subtype fields.
- Kotlin (codegen-kotlin): create skips readOnly/derived columns; a TPH
per-subtype create writes only the route subtype's own columns.
- C# (MetaObjects.Codegen): every readOnly property shape gets a private
setter; create resets a generated id, the TPH discriminator and M:N
navigations before Add.
- TypeScript (codegen-ts): the update schema omits primary-key fields, so
PUT/PATCH can no longer re-key a row with an assigned key.
Proof: new shared api-contract scenarios (core + TPH input-server-owned,
TPH foreign discriminator) and a readOnly `role` field in secret-fields, run
in every port's generated lane and the reference lanes; a new `unset`
assertion key in all five harnesses. In-memory test repositories now store
what they are handed, so the scenarios fail on the 1.2.0 generators.
Proposed versions (not published): npm 1.2.2, NuGet 1.2.2, Maven 8.2.2;
PyPI unchanged at 1.2.1. metamodelVersion unchanged.
---
CHANGELOG.md | 44 ++++++
bun.lock | 28 ++--
client/web/packages/react/package.json | 2 +-
client/web/packages/runtime-web/package.json | 2 +-
client/web/packages/tanstack/package.json | 2 +-
docs/CONFORMANCE.md | 10 +-
docs/features/generated-mutations.md | 13 ++
docs/llms/llms-full.txt | 18 +--
docs/llms/llms.txt | 14 +-
.../codegen/templates/zod-validators.ts | 9 ++
.../.metaobjects/.gen-state/.hashes.json | 2 +-
.../codegen/templates/zod-validators.ts | 9 ++
.../generated/csharp/SubscriberRoutes.g.cs | 2 +
examples/showcase/jvm/pom.xml | 2 +-
examples/showcase/site-payload.json | 6 +-
fixtures/api-contract-conformance/README.md | 8 +-
.../scenarios/input-server-owned-dropped.yaml | 85 +++++++++++
.../secret-fields/README.md | 5 +-
.../secret-fields/meta.json | 1 +
.../scenarios/read-omits-credential.yaml | 3 +
.../scenarios/write-ignores-excluded.yaml | 15 +-
.../secret-fields/seed.json | 4 +-
.../api-contract-conformance/tph/README.md | 4 +-
...h-input-foreign-discriminator-dropped.yaml | 44 ++++++
.../tph-input-server-owned-dropped.yaml | 72 ++++++++++
server/csharp/Directory.Build.props | 2 +-
.../ServerOwnedCreateInputTests.cs | 134 ++++++++++++++++++
.../Generators/EntityGenerator.cs | 42 +++---
.../Generators/RoutesGenerator.cs | 49 ++++++-
.../Api/ApiContractAssertions.cs | 13 ++
.../ApiContractSecretFieldsConformanceTest.cs | 5 +-
.../Api/SecretFieldsFixture.cs | 3 +-
.../Api/TphReferenceServer.cs | 7 +
server/java/codegen-base/pom.xml | 2 +-
.../codegen-kotlin-exposed1x-check/pom.xml | 2 +-
server/java/codegen-kotlin/pom.xml | 2 +-
.../kotlin/KotlinSpringControllerGenerator.kt | 12 +-
.../kotlin/KotlinServerOwnedInputTest.kt | 89 ++++++++++++
.../acme/auth/AuthController.kt | 6 -
server/java/codegen-mustache/pom.xml | 2 +-
server/java/codegen-plantuml/pom.xml | 2 +-
server/java/codegen-spring/pom.xml | 2 +-
.../spring/SpringControllerGenerator.java | 62 +++++++-
.../spring/SpringSecretFieldsCodegenTest.java | 7 +-
.../SpringServerOwnedInputCodegenTest.java | 104 ++++++++++++++
server/java/core-spring/pom.xml | 2 +-
server/java/integration-tests-kotlin/pom.xml | 2 +-
.../kotlin/api/ApiContractAssertions.kt | 11 +-
.../GeneratedAuthorControllerHarness.kt | 3 +
.../GeneratedSecretFieldsControllerHarness.kt | 9 +-
.../GeneratedTphControllerHarness.kt | 3 +
server/java/integration-tests/pom.xml | 2 +-
.../api/ApiContractAssertions.java | 13 +-
.../GeneratedAccountControllerHarness.java | 5 +-
.../GeneratedAuthorControllerHarness.java | 5 +-
.../InMemoryAccountRepositorySource.java | 11 +-
.../InMemoryAuthorRepositorySource.java | 6 +-
.../GeneratedTphControllerHarness.java | 5 +-
.../InMemoryAuthRepositorySource.java | 11 +-
server/java/maven-plugin/pom.xml | 2 +-
server/java/metadata-ktx/pom.xml | 2 +-
server/java/metadata/pom.xml | 2 +-
server/java/om/pom.xml | 2 +-
server/java/omdb-ktx/pom.xml | 2 +-
server/java/omdb/pom.xml | 2 +-
server/java/pom.xml | 2 +-
server/java/render/pom.xml | 2 +-
server/java/spring-boot-starter/pom.xml | 2 +-
.../src/metaobjects/codegen/KNOWN_GAPS.md | 12 ++
.../integration/api_contract_assertions.py | 15 +-
.../generated_secret_fields_app.py | 2 +-
.../test_api_contract_tph_generated.py | 12 ++
.../packages/ai-runtime/package.json | 2 +-
server/typescript/packages/cli/package.json | 2 +-
.../packages/codegen-ts-react/package.json | 2 +-
.../packages/codegen-ts-tanstack/package.json | 2 +-
.../packages/codegen-ts/package.json | 2 +-
.../src/templates/zod-validators.ts | 9 ++
.../__snapshots__/reporting-docs.test.ts.snap | 66 ++++-----
.../test/templates/zod-validators.test.ts | 16 +++
.../packages/docs-site/package.json | 2 +-
.../src/api-contract-scenario.ts | 12 ++
...contract-secret-fields-generated-server.ts | 7 +-
.../src/api-contract-server.ts | 19 ++-
.../typescript/packages/metadata/package.json | 2 +-
.../packages/migrate-ts/package.json | 2 +-
.../typescript/packages/render/package.json | 2 +-
.../packages/runtime-ts/package.json | 2 +-
server/typescript/packages/sdk/package.json | 2 +-
.../src/templates/zod-validators.ts | 9 ++
90 files changed, 1070 insertions(+), 188 deletions(-)
create mode 100644 fixtures/api-contract-conformance/scenarios/input-server-owned-dropped.yaml
create mode 100644 fixtures/api-contract-conformance/tph/scenarios/tph-input-foreign-discriminator-dropped.yaml
create mode 100644 fixtures/api-contract-conformance/tph/scenarios/tph-input-server-owned-dropped.yaml
create mode 100644 server/csharp/MetaObjects.Codegen.Tests/ServerOwnedCreateInputTests.cs
create mode 100644 server/java/codegen-kotlin/src/test/kotlin/com/metaobjects/generator/kotlin/KotlinServerOwnedInputTest.kt
create mode 100644 server/java/codegen-spring/src/test/java/com/metaobjects/generator/spring/SpringServerOwnedInputCodegenTest.java
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 9fe7ecc774..6cacd80255 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -10,6 +10,50 @@ here.**
## [Unreleased]
+_Proposed as npm `1.2.2` (all 14 `@metaobjectsdev/*` packages), NuGet `1.2.2` and Maven Central
+`8.2.2`; `1.2.1` was spent by the Python-only release. PyPI stays at `1.2.1`: no Python product
+file changes. No vocabulary or `metamodelVersion` change._
+
+### Security
+
+- **Generated create routes in Java, Kotlin and C#, and TypeScript updates, let a client write
+ fields it must never set.** The same class of hole the Python 1.2.1 patch closed, found by an
+ audit of the other four ports after it. Every adopter serving these generated routes should
+ upgrade and regenerate; an ejected (owned) generator needs the same change made by hand.
+
+ - **Java (`codegen-spring`).** The create route passed the bound DTO to the repository as
+ sent, so a client `id` on a generated key and a `@mutability: readOnly` or derived field
+ reached it. On a TPH per-subtype route the body's discriminator and a sibling subtype's
+ columns did too. The route now rebuilds the DTO with each of those components set to null
+ before the repository call; the route's subtype still comes from the URL.
+ - **Kotlin (`codegen-kotlin`).** The create route wrote `readOnly` and derived columns from the
+ body, and a TPH per-subtype route wrote a sibling subtype's columns. It now writes only the
+ route subtype's own settable columns.
+ - **C# (`MetaObjects.Codegen`).** The create route bound the EF Core entity from the body, so a
+ client `id` on a generated key was inserted, a TPH create stored the body's discriminator (a
+ POST to the Bridge route could create a Copay row), and a TPH subtype's `readOnly` field and
+ an M:N navigation graph were written. The route now resets the generated key and the
+ discriminator to their defaults and empties the M:N navigations before `Add`, and a
+ `readOnly` property of every shape, a TPH subtype's included, has a private setter, which
+ System.Text.Json does not bind.
+ - **TypeScript (`codegen-ts`).** The `UpdateSchema` kept an assigned (non-generated)
+ primary key, so a PUT or PATCH could re-key the row. The update schema now leaves out every
+ primary-key field; the insert schema still takes an assigned key, which is the caller's on
+ create.
+
+ Each of these values is dropped silently, never answered with a 400. A key the model does not
+ declare is dropped silently in TypeScript, C# and Python. In Java and Kotlin the answer to an
+ undeclared key is the host's Jackson `ObjectMapper`'s: Spring Boot's default ignores it, and a
+ plain `ObjectMapper` (`FAIL_ON_UNKNOWN_PROPERTIES` on) answers 400. This patch leaves that as
+ it was.
+
+ Gated by the shared api-contract scenarios `input-server-owned-dropped`,
+ `tph-input-server-owned-dropped` and `tph-input-foreign-discriminator-dropped`, and a `readOnly`
+ `role` on the `secret-fields` corpus, in every port's generated lane and in the reference lanes.
+ Python's generated TPH routes answer a foreign body discriminator with a 400 rather than
+ dropping it (nothing is stored); its runner skips that one scenario, recorded in the Python
+ codegen `KNOWN_GAPS.md`.
+
## [1.2.1] — Python only
_PyPI `1.2.1` only. npm, NuGet and Maven Central stay at `1.2.0` (`8.2.0`): none of them has a
diff --git a/bun.lock b/bun.lock
index 195e182cb8..9def0b0bbb 100644
--- a/bun.lock
+++ b/bun.lock
@@ -43,7 +43,7 @@
},
"client/web/packages/react": {
"name": "@metaobjectsdev/react",
- "version": "1.2.0",
+ "version": "1.2.2",
"dependencies": {
"@metaobjectsdev/runtime-web": "workspace:*",
"react-easy-crop": "^6.2.3",
@@ -73,7 +73,7 @@
},
"client/web/packages/runtime-web": {
"name": "@metaobjectsdev/runtime-web",
- "version": "1.2.0",
+ "version": "1.2.2",
"dependencies": {
"@metaobjectsdev/metadata": "workspace:*",
"qs": "^6.13.0",
@@ -86,7 +86,7 @@
},
"client/web/packages/tanstack": {
"name": "@metaobjectsdev/tanstack",
- "version": "1.2.0",
+ "version": "1.2.2",
"dependencies": {
"@metaobjectsdev/runtime-web": "workspace:*",
},
@@ -113,7 +113,7 @@
},
"server/typescript/packages/ai-runtime": {
"name": "@metaobjectsdev/ai-runtime",
- "version": "1.2.0",
+ "version": "1.2.2",
"dependencies": {
"@metaobjectsdev/metadata": "workspace:*",
"@metaobjectsdev/render": "workspace:*",
@@ -134,7 +134,7 @@
},
"server/typescript/packages/cli": {
"name": "@metaobjectsdev/cli",
- "version": "1.2.0",
+ "version": "1.2.2",
"bin": {
"meta": "./dist/bin/meta.js",
},
@@ -179,7 +179,7 @@
},
"server/typescript/packages/codegen-ts": {
"name": "@metaobjectsdev/codegen-ts",
- "version": "1.2.0",
+ "version": "1.2.2",
"dependencies": {
"@biomejs/js-api": "^0.7.0",
"@biomejs/wasm-nodejs": "^1.9.4",
@@ -224,7 +224,7 @@
},
"server/typescript/packages/codegen-ts-react": {
"name": "@metaobjectsdev/codegen-ts-react",
- "version": "1.2.0",
+ "version": "1.2.2",
"dependencies": {
"@metaobjectsdev/codegen-ts": "workspace:*",
"@metaobjectsdev/metadata": "workspace:*",
@@ -242,7 +242,7 @@
},
"server/typescript/packages/codegen-ts-tanstack": {
"name": "@metaobjectsdev/codegen-ts-tanstack",
- "version": "1.2.0",
+ "version": "1.2.2",
"dependencies": {
"@metaobjectsdev/codegen-ts": "workspace:*",
"@metaobjectsdev/metadata": "workspace:*",
@@ -274,7 +274,7 @@
},
"server/typescript/packages/docs-site": {
"name": "@metaobjectsdev/docs-site",
- "version": "1.2.0",
+ "version": "1.2.2",
"dependencies": {
"@metaobjectsdev/metadata": "workspace:*",
"@metaobjectsdev/render": "workspace:*",
@@ -326,7 +326,7 @@
},
"server/typescript/packages/metadata": {
"name": "@metaobjectsdev/metadata",
- "version": "1.2.0",
+ "version": "1.2.2",
"dependencies": {
"yaml": "^2.9.0",
},
@@ -339,7 +339,7 @@
},
"server/typescript/packages/migrate-ts": {
"name": "@metaobjectsdev/migrate-ts",
- "version": "1.2.0",
+ "version": "1.2.2",
"dependencies": {
"@iarna/toml": "^2.2.5",
"@metaobjectsdev/metadata": "workspace:*",
@@ -366,7 +366,7 @@
},
"server/typescript/packages/render": {
"name": "@metaobjectsdev/render",
- "version": "1.2.0",
+ "version": "1.2.2",
"dependencies": {
"mustache": "^4.2.0",
"nunjucks": "^3.2.4",
@@ -380,7 +380,7 @@
},
"server/typescript/packages/runtime-ts": {
"name": "@metaobjectsdev/runtime-ts",
- "version": "1.2.0",
+ "version": "1.2.2",
"dependencies": {
"@metaobjectsdev/metadata": "workspace:*",
"@metaobjectsdev/render": "workspace:*",
@@ -419,7 +419,7 @@
},
"server/typescript/packages/sdk": {
"name": "@metaobjectsdev/sdk",
- "version": "1.2.0",
+ "version": "1.2.2",
"dependencies": {
"@metaobjectsdev/metadata": "workspace:*",
"yaml": "^2.9.0",
diff --git a/client/web/packages/react/package.json b/client/web/packages/react/package.json
index 389f907df0..5ccfeff21f 100644
--- a/client/web/packages/react/package.json
+++ b/client/web/packages/react/package.json
@@ -1,6 +1,6 @@
{
"name": "@metaobjectsdev/react",
- "version": "1.2.0",
+ "version": "1.2.2",
"description": "React runtime for metaobjects: useEntityForm hook and CurrencyInput component.",
"type": "module",
"main": "./dist/index.js",
diff --git a/client/web/packages/runtime-web/package.json b/client/web/packages/runtime-web/package.json
index 0ba383763c..ae0c6e4348 100644
--- a/client/web/packages/runtime-web/package.json
+++ b/client/web/packages/runtime-web/package.json
@@ -1,6 +1,6 @@
{
"name": "@metaobjectsdev/runtime-web",
- "version": "1.2.0",
+ "version": "1.2.2",
"description": "Pure framework-agnostic browser core for metaobjects: currency, filter URL serialization, fetcher contract types.",
"type": "module",
"main": "./dist/index.js",
diff --git a/client/web/packages/tanstack/package.json b/client/web/packages/tanstack/package.json
index a1fb67dd6e..b524804714 100644
--- a/client/web/packages/tanstack/package.json
+++ b/client/web/packages/tanstack/package.json
@@ -1,6 +1,6 @@
{
"name": "@metaobjectsdev/tanstack",
- "version": "1.2.0",
+ "version": "1.2.2",
"description": "TanStack runtime for metaobjects: EntityFetcherProvider, EntityGrid, default cell renderers.",
"type": "module",
"main": "./dist/index.js",
diff --git a/docs/CONFORMANCE.md b/docs/CONFORMANCE.md
index 36834aadbc..a9a3d02f5e 100644
--- a/docs/CONFORMANCE.md
+++ b/docs/CONFORMANCE.md
@@ -36,7 +36,7 @@ regenerate with `ls -d fixtures//*/ | wc -l` for directory-shaped corpor
| [`fixtures/extract-conformance/`](../fixtures/extract-conformance/) | 58 | ✓ | ✓ | inherits the shared JVM engine | ✓ | ✓ |
| [`fixtures/output-prompt-conformance/`](../fixtures/output-prompt-conformance/) | 17 | ✓ | ✓ | ✓ | ✓ | ✓ |
| [`fixtures/persistence-conformance/`](../fixtures/persistence-conformance/) | 59 (53 query + 6 migration) | all 59; the 24 `report-*` and the `-15` decimal scenarios also on SQLite, MySQL and D1, `decimal-exact` also on MySQL (a scenario's `engines:` key is exact) | 53 query (migrations TS-only, ADR-0015); the `report-*` and `engines:` scenarios also on SQLite and MySQL | 53 query (via Exposed); the `report-*` and `engines:` scenarios also on SQLite and MySQL | 53 query; the `report-*` and `engines:` scenarios also on SQLite and MySQL | 53 query (pg8000); the `report-*` and `engines:` scenarios also on SQLite (`sqlite3`) and MySQL (PyMySQL) |
-| [`fixtures/api-contract-conformance/`](../fixtures/api-contract-conformance/) | 119 (31 core + 10 tph + 9 m2m + 5 jsonb + 2 write-through + 2 secret-fields + 12 projection + 37 report + 11 decimal) | ✓ (Fastify reference + generated lane); `report/` and `decimal/` also on SQLite, MySQL and D1 | ✓ (embedded HTTP + JDBC); `report/` and `decimal/` generated controllers over OMDB on Postgres, SQLite and MySQL | ✓ (embedded HTTP + Exposed); `report/` and `decimal/` also on SQLite and MySQL | ✓ (Kestrel + Npgsql); `report/` and `decimal/` also on SQLite and MySQL | ✓ (FastAPI + pg8000); `report/` and `decimal/` also on SQLite and MySQL |
+| [`fixtures/api-contract-conformance/`](../fixtures/api-contract-conformance/) | 122 (32 core + 12 tph + 9 m2m + 5 jsonb + 2 write-through + 2 secret-fields + 12 projection + 37 report + 11 decimal) | ✓ (Fastify reference + generated lane); `report/` and `decimal/` also on SQLite, MySQL and D1 | ✓ (embedded HTTP + JDBC); `report/` and `decimal/` generated controllers over OMDB on Postgres, SQLite and MySQL | ✓ (embedded HTTP + Exposed); `report/` and `decimal/` also on SQLite and MySQL | ✓ (Kestrel + Npgsql); `report/` and `decimal/` also on SQLite and MySQL | ✓ (FastAPI + pg8000); `report/` and `decimal/` also on SQLite and MySQL |
| [`fixtures/decimal-wire/`](../fixtures/decimal-wire/) | 1 vector file (format, parse, filter operand, 15-digit read) | ✓ (`runtime-ts` and the generated helper) | ✓ (`CanonicalDecimal`) | ✓ (the generated wire file) | ✓ (`DecimalWire`) | ✓ (`decimal_wire`) |
| [`fixtures/validation-conformance/`](../fixtures/validation-conformance/) | 42 cases | ✓ (generated Zod + run-time `runValidators`) | ✓ | ✓ | ✓ | ✓ (generated Pydantic + run-time `run_validators`) |
| [`fixtures/registry-conformance/`](../fixtures/registry-conformance/) | 1 canonical manifest | ✓ (reference emitter) | ✓ | ✓ | ✓ | ✓ |
@@ -366,9 +366,9 @@ REAL, a MySQL `DECIMAL` keeps its scale, a MySQL `DATETIME` is the UTC wall cloc
`report-relative-date` carries a per-engine seed (`seed-data-engine`). `op: relate` and the
write ops stay Postgres-only. See [features/reporting.md](features/reporting.md#what-the-corpus-gates).
-### `fixtures/api-contract-conformance/` (119)
+### `fixtures/api-contract-conformance/` (122)
-All 119 scenarios → [features/api-contract.md](features/api-contract.md) (cross-port
+All 122 scenarios → [features/api-contract.md](features/api-contract.md) (cross-port
REST API URL grammar + JSON wire format). Verifies every backend's emitted CRUD
routes answer identically over HTTP — list / get / create / patch+put / delete,
plus pagination (`limit`/`offset`), sort (`sort=field:dir`), the `withCount=1`
@@ -378,7 +378,7 @@ status codes.
The corpus also covers the 9 cross-port filter operators (`eq`, `ne`, `gt`,
`gte`, `lt`, `lte`, `in`, `like`, `isNull`) plus the implicit-AND combinator
and 2 error shapes (`invalid_filter_field` / `invalid_filter_op`) under the
-URL grammar `?filter[][]=` (FR-009). On top of the 31 core
+URL grammar `?filter[][]=` (FR-009). On top of the 32 core
scenarios the corpus carries eight sub-corpora — `tph/` (10, single-table
inheritance; a subtype decimal filters and refuses extra digits), `m2m/` (9 — 3 plain, 5 gating TPH x M:N together, the combination
each corpus alone could not reach, and 1 pinning the collection-URL spelling),
@@ -611,7 +611,7 @@ files into a real Cube.
## Orphaned fixtures (tested but not yet documented)
The fixtures in the nine corpora mapped above (metamodel 421 + yaml 16 + verify 45
-+ render 18 + persistence 59 + api-contract 119 + source-resolution 25 + scope 10 +
++ render 18 + persistence 59 + api-contract 122 + source-resolution 25 + scope 10 +
dependency 37) each map to a feature doc, and so do the two requirement corpora, `shared-model-conformance` and the
`cube-model` corpus, whose case lists live in their own READMEs. None are orphaned today. The remaining
corpora in the totals table gate tooling contracts (registry manifests, provider
diff --git a/docs/features/generated-mutations.md b/docs/features/generated-mutations.md
index 3a367bbb6f..9f3c6bab48 100644
--- a/docs/features/generated-mutations.md
+++ b/docs/features/generated-mutations.md
@@ -66,6 +66,19 @@ but the semantics are one contract — call them **PATCH-1..7** (FR-035):
- **PATCH-7 (verbs).** At the HTTP tier both `PATCH` and `PUT` route to the update
handler with partial-merge semantics. True PUT-as-full-replace is out of scope.
+**Create stores only what a client may set, in every port.** A generated create route
+never writes a client-sent value for a server-generated primary key (`@generation`
+`increment` or `uuid`), a `@mutability: "readOnly"` or `origin.*`-derived field, the TPH
+discriminator (a per-subtype route takes the subtype from the URL), a column only a
+sibling subtype declares, or (C#) an M:N navigation graph. Each is dropped silently, not
+answered with a 400. An assigned key (no `@generation`) is the caller's on create, and
+on update it is the primary key like any other, so it is left out of the TypeScript
+`UpdateSchema` too. A key the entity does not declare is dropped in TypeScript,
+C# and Python; in Java and Kotlin that answer belongs to the host's Jackson
+`ObjectMapper` (Spring Boot's default ignores it, a plain `ObjectMapper` answers 400).
+Gated cross-port by `fixtures/api-contract-conformance/scenarios/input-server-owned-dropped.yaml`
+and the `tph/` and `secret-fields/` input scenarios.
+
The generated update does **not** guard against a concurrent write: two callers
patching the same row both succeed, and the last one wins. Adding that guard is
adopter-owned — see [Optimistic concurrency](#optimistic-concurrency-adopter-owned).
diff --git a/docs/llms/llms-full.txt b/docs/llms/llms-full.txt
index 69e45e8a2c..8cdb51cbc6 100644
--- a/docs/llms/llms-full.txt
+++ b/docs/llms/llms-full.txt
@@ -1,6 +1,6 @@
# MetaObjects -- Full Reference Corpus
-> Coding agents get context — rules files, memories, MCP servers — and context is advisory: nothing fails when the code stops matching it. MetaObjects gives your agent one typed model of your application — data, API, UI, prompt payloads, and what the software is supposed to do — generates each layer's code from it in TypeScript, Java, Kotlin, C# and Python with no proprietary runtime in the output, and fails your build when generated code, a prompt, or a claimed capability drifts from that model. Your hand-written logic stays yours. Apache 2.0. Shipping at `1.2.0` on npm and `8.2.0` on Maven Central.
+> Coding agents get context — rules files, memories, MCP servers — and context is advisory: nothing fails when the code stops matching it. MetaObjects gives your agent one typed model of your application — data, API, UI, prompt payloads, and what the software is supposed to do — generates each layer's code from it in TypeScript, Java, Kotlin, C# and Python with no proprietary runtime in the output, and fails your build when generated code, a prompt, or a claimed capability drifts from that model. Your hand-written logic stays yours. Apache 2.0. Shipping at `1.2.2` on npm and `8.2.2` on Maven Central.
**Note for AI assistants:** This file is the concatenated reference material for MetaObjects, intended to be loaded as LLM context. For the short index, see [llms.txt](https://metaobjects.dev/llms.txt). For the canonical spec and source, see the [GitHub repo](https://github.com/metaobjectsdev/metaobjects). When this file is out of date relative to the GitHub source, the GitHub source wins.
@@ -39,7 +39,7 @@ If you are an AI assistant helping someone adopt MetaObjects, do this **first**
1. **Install the port's package:**
- TypeScript / Node: `npm i -D @metaobjectsdev/cli @metaobjectsdev/codegen-ts @metaobjectsdev/metadata typescript @types/better-sqlite3`, then `npm i @metaobjectsdev/runtime-ts drizzle-orm zod fastify better-sqlite3` (SQLite; use `pg` and `@types/pg` for Postgres). The generated files import `drizzle-orm`, `zod`, `fastify` and a driver, and `npm` does not add them for you.
- - Java / Kotlin: add `com.metaobjects:metaobjects-metadata`, `com.metaobjects:metaobjects-codegen-spring` (Java) or `com.metaobjects:metaobjects-codegen-kotlin` (Kotlin), and `com.metaobjects:metaobjects-maven-plugin`, all at `8.2.0`.
+ - Java / Kotlin: add `com.metaobjects:metaobjects-metadata`, `com.metaobjects:metaobjects-codegen-spring` (Java) or `com.metaobjects:metaobjects-codegen-kotlin` (Kotlin), and `com.metaobjects:metaobjects-maven-plugin`, all at `8.2.2`.
- Python: `pip install metaobjects`
- C#: install the MetaObjects .NET tool (invoked as `dotnet meta`).
2. **Run `meta init`** (the Node `meta` CLI). It works in any project that has Node — including a JVM or Python project with a TypeScript frontend. It scaffolds a slim always-on `.metaobjects/AGENTS.md` + `.metaobjects/CLAUDE.md` (auto-wired via an `@.metaobjects/AGENTS.md` import line into the project's root `CLAUDE.md`/`AGENTS.md`, so it loads automatically) plus six `metaobjects-*` Claude Code skills under `.claude/skills/`, carrying only the project's language reference fragments. Re-run `meta init --refresh-docs` to update the agent docs after a CLI upgrade. (The Node `meta` CLI is the single agent-context scaffolder for every backend, by design — ADR-0033; the JVM/Python/C# CLIs deliberately redirect to it. For a non-Node project, scaffold just the agent context with `npx meta agent-docs --server `.)
@@ -125,11 +125,11 @@ Today the TypeScript toolchain publishes and TypeScript and Python projects cons
| Language | Status | Notes |
|---|---|---|
-| TypeScript | Reference implementation, npm `1.2.0` | All six pillars, and the only port that prints the requirements authoring lint and publishes shared models. 2500+ tests passing. Owns the canonical schema-migration toolchain used by every port (ADR-0015). Bun-first dev. |
-| Java | Maven Central `8.2.0` | Spring REST + DTO + repository-interface codegen, OMDB runtime persistence (pure data-access) with Spring-tx. Fully green across all conformance corpora. |
-| Kotlin | Maven Central `8.2.0` | KotlinPoet codegen + Exposed runtime + `metadata-ktx` facade. Ships via the Java reactor. |
-| C# | NuGet `1.2.0` (.NET tool) | Loader + canonical serializer + EF Core + ASP.NET codegen + render/verify. `dotnet meta` tool. |
-| Python | PyPI `1.2.0` | Loader + serializer + render + verify + codegen + `ObjectManager` runtime. Fully green across all corpora. |
+| TypeScript | Reference implementation, npm `1.2.2` | All six pillars, and the only port that prints the requirements authoring lint and publishes shared models. 2500+ tests passing. Owns the canonical schema-migration toolchain used by every port (ADR-0015). Bun-first dev. |
+| Java | Maven Central `8.2.2` | Spring REST + DTO + repository-interface codegen, OMDB runtime persistence (pure data-access) with Spring-tx. Fully green across all conformance corpora. |
+| Kotlin | Maven Central `8.2.2` | KotlinPoet codegen + Exposed runtime + `metadata-ktx` facade. Ships via the Java reactor. |
+| C# | NuGet `1.2.2` (.NET tool) | Loader + canonical serializer + EF Core + ASP.NET codegen + render/verify. `dotnet meta` tool. |
+| Python | PyPI `1.2.1` | Loader + serializer + render + verify + codegen + `ObjectManager` runtime. Fully green across all corpora. |
Conformance fixtures live at [`fixtures/`](https://github.com/metaobjectsdev/metaobjects/tree/main/fixtures). Every port runs the shared corpus byte-identically: metamodel (`conformance/`, 314 fixtures), render, persistence (Testcontainers Postgres, with an `op: roundtrip` gate so every `field.*` subtype write+read round-trips on every port), api-contract (41 scenarios — 26 core plus TPH / M:N / jsonb / write-through — two lanes: a reference server AND each port's generated API booted over HTTP), registry (byte-matched metamodel-vocabulary manifest, live + green in all five ports), and yaml/verify.
@@ -182,7 +182,7 @@ Universal web client (`client/web/packages/`): `@metaobjectsdev/runtime-web`, `@
## Java / Kotlin Maven coordinates
-All published to Maven Central under `com.metaobjects:*` at `8.2.0`:
+All published to Maven Central under `com.metaobjects:*` at `8.2.2`:
- `metaobjects-metadata`, `metaobjects-metadata-ktx`
- `metaobjects-codegen-base`, `metaobjects-codegen-mustache`, `metaobjects-codegen-spring`, `metaobjects-codegen-kotlin`, `metaobjects-codegen-plantuml`
@@ -219,7 +219,7 @@ Project marker directory: `.metaobjects/`.
## Quickstart (Java / Kotlin)
-Add the Maven coordinates above at `8.2.0`. Run codegen with `mvn metaobjects:generate` and codegen-drift checks with `mvn metaobjects:verify`. Configure generators (including Kotlin generators, which run through the same goal) on the `metaobjects-maven-plugin`. See [`server/java/`](https://github.com/metaobjectsdev/metaobjects/tree/main/server/java) and [`server/java/codegen-kotlin/README.md`](https://github.com/metaobjectsdev/metaobjects/tree/main/server/java/codegen-kotlin).
+Add the Maven coordinates above at `8.2.2`. Run codegen with `mvn metaobjects:generate` and codegen-drift checks with `mvn metaobjects:verify`. Configure generators (including Kotlin generators, which run through the same goal) on the `metaobjects-maven-plugin`. See [`server/java/`](https://github.com/metaobjectsdev/metaobjects/tree/main/server/java) and [`server/java/codegen-kotlin/README.md`](https://github.com/metaobjectsdev/metaobjects/tree/main/server/java/codegen-kotlin).
---
diff --git a/docs/llms/llms.txt b/docs/llms/llms.txt
index 60e67dfb70..4bc81990aa 100644
--- a/docs/llms/llms.txt
+++ b/docs/llms/llms.txt
@@ -1,6 +1,6 @@
# MetaObjects
-> MetaObjects gives your coding agent one typed model of your application: data, API, UI, prompt payloads, and what the software is supposed to do. It generates each layer's code from that model in TypeScript, Java, Kotlin, C# and Python, with no proprietary runtime in the output. Your build fails when generated code, a prompt or a claimed capability stops matching the model. Rules files and memories are only advice, because nothing fails when the code drifts from them. Your hand-written logic stays yours. Apache 2.0. Shipping at `1.2.0` on npm and `8.2.0` on Maven Central.
+> MetaObjects gives your coding agent one typed model of your application: data, API, UI, prompt payloads, and what the software is supposed to do. It generates each layer's code from that model in TypeScript, Java, Kotlin, C# and Python, with no proprietary runtime in the output. Your build fails when generated code, a prompt or a claimed capability stops matching the model. Rules files and memories are only advice, because nothing fails when the code drifts from them. Your hand-written logic stays yours. Apache 2.0. Shipping at `1.2.2` on npm and `8.2.2` on Maven Central.
**One typed model of your app** — data, API, UI, prompt payloads, and what it is supposed to do — that your agent reads and writes. Two things happen to it.
@@ -26,7 +26,7 @@ If you are an AI assistant helping someone adopt MetaObjects in their project, d
1. **Install the port's package** for the project's stack:
- **TypeScript / Node**: `npm i -D @metaobjectsdev/cli @metaobjectsdev/codegen-ts @metaobjectsdev/metadata typescript @types/better-sqlite3`, then `npm i @metaobjectsdev/runtime-ts drizzle-orm zod fastify better-sqlite3` (SQLite; use `pg` and `@types/pg` for Postgres). The generated files import `drizzle-orm`, `zod`, `fastify` and a driver, and `npm` does not add them for you.
- - **Java / Kotlin**: add the Maven dependencies `com.metaobjects:metaobjects-metadata`, `com.metaobjects:metaobjects-codegen-spring` (Java) or `com.metaobjects:metaobjects-codegen-kotlin` (Kotlin), and the `com.metaobjects:metaobjects-maven-plugin`, all at `8.2.0`.
+ - **Java / Kotlin**: add the Maven dependencies `com.metaobjects:metaobjects-metadata`, `com.metaobjects:metaobjects-codegen-spring` (Java) or `com.metaobjects:metaobjects-codegen-kotlin` (Kotlin), and the `com.metaobjects:metaobjects-maven-plugin`, all at `8.2.2`.
- **Python**: `pip install metaobjects`
- **C#**: install the MetaObjects .NET tool (`dotnet tool install` the MetaObjects CLI tool; invoked as `dotnet meta`).
@@ -65,10 +65,10 @@ MetaObjects pillars are capabilities of one metadata model, not separate product
**Sharing a model across your own projects** — today the TypeScript toolchain publishes and TypeScript and Python projects consume, from an installed npm or Python package or over a `path` dependency (a sibling checkout or submodule); Java, Kotlin and C# arrive in Phase 2. One project publishes part of its model with the `sharedModelFile()` generator; another declares it under `dependencies` in `.metaobjects/config.json`, runs `meta deps sync` to commit a hash-locked snapshot, and builds on it with `extends` and references. When the publisher's model moves, `meta verify --deps` reports it instead of two copies drifting apart.
-## Implementations (npm `1.2.0` / Maven Central `8.2.0`)
+## Implementations (npm `1.2.2` / Maven Central `8.2.2`)
-- [TypeScript](https://github.com/metaobjectsdev/metaobjects/tree/main/server/typescript): the reference implementation. Published to npm at `1.2.0` across 14 `@metaobjectsdev/*` packages on the `latest` tag. 2500+ tests passing across the workspace. Bun-first dev workflow. Owns the canonical schema-migration toolchain used by every port (ADR-0015).
-- [Java](https://github.com/metaobjectsdev/metaobjects/tree/main/server/java): 14 publishable Maven modules under `com.metaobjects:*` at `8.2.0` on Maven Central (15 artifacts with the parent POM). Spring REST + DTO + repository-interface codegen, OMDB runtime persistence (pure data-access) with Spring-tx, full FR-003 + FR-006 + FR-010/011 + FR-018 + FR5 family. Fully green across all conformance corpora.
+- [TypeScript](https://github.com/metaobjectsdev/metaobjects/tree/main/server/typescript): the reference implementation. Published to npm at `1.2.2` across 14 `@metaobjectsdev/*` packages on the `latest` tag. 2500+ tests passing across the workspace. Bun-first dev workflow. Owns the canonical schema-migration toolchain used by every port (ADR-0015).
+- [Java](https://github.com/metaobjectsdev/metaobjects/tree/main/server/java): 14 publishable Maven modules under `com.metaobjects:*` at `8.2.2` on Maven Central (15 artifacts with the parent POM). Spring REST + DTO + repository-interface codegen, OMDB runtime persistence (pure data-access) with Spring-tx, full FR-003 + FR-006 + FR-010/011 + FR-018 + FR5 family. Fully green across all conformance corpora.
- [Kotlin](https://github.com/metaobjectsdev/metaobjects/tree/main/server/java/codegen-kotlin): a Kotlin codegen pipeline on KotlinPoet plus `metadata-ktx` — a Kotlin facade over the Java MetaObjects core. Ships via the Java reactor (`metaobjects-metadata-ktx`, `metaobjects-codegen-kotlin`). Persistence-conformance runs against Testcontainers Postgres through Exposed.
- [C#](https://github.com/metaobjectsdev/metaobjects/tree/main/server/csharp): loader + canonical serializer + EF Core + ASP.NET codegen + render/verify. The `dotnet meta` tool ships `gen` and the codegen-side `verify` subverbs (`--codegen`, `--templates`); schema migration is Node `meta` only (ADR-0015).
- [Python](https://github.com/metaobjectsdev/metaobjects/tree/main/server/python): loader + canonical serializer + conformance + render + verify + codegen + an `ObjectManager` runtime layer. The `metaobjects` console-script ships `gen` and codegen-side `verify`. Fully green across all conformance corpora.
@@ -82,7 +82,7 @@ MetaObjects deliberately does **not** ship one universal binary. Schema operatio
- Codegen is **opt-in**: no port ships a default generator suite, `meta init` scaffolds `generators: []`, and `meta gen --list` is the catalog (`--probe` reports how many files each generator would emit for your model)
- Project marker directory: `.metaobjects/`
- Install (TypeScript reference): `npm install -D @metaobjectsdev/cli` (or `bun add @metaobjectsdev/cli`)
-- Install (Java): `com.metaobjectsmetaobjects-metadata8.2.0` plus per-concern artifacts (`metaobjects-codegen-spring`, `metaobjects-omdb`, `metaobjects-maven-plugin`, etc.)
+- Install (Java): `com.metaobjectsmetaobjects-metadata8.2.2` plus per-concern artifacts (`metaobjects-codegen-spring`, `metaobjects-omdb`, `metaobjects-maven-plugin`, etc.)
- Install (Kotlin): same Maven coordinates — add `metaobjects-metadata-ktx` and `metaobjects-codegen-kotlin` to a JVM/Kotlin project.
- Install (Python): `pip install metaobjects`
- Install (C#): the MetaObjects .NET tool, invoked as `dotnet meta`.
@@ -128,7 +128,7 @@ Universal web-client under `client/web/packages/`:
## Java / Kotlin Maven coordinates
-All published to Maven Central under `com.metaobjects:*` at `8.2.0`:
+All published to Maven Central under `com.metaobjects:*` at `8.2.2`:
- `metaobjects-metadata`, `metaobjects-metadata-ktx`
- `metaobjects-codegen-base`, `metaobjects-codegen-mustache`, `metaobjects-codegen-spring`, `metaobjects-codegen-kotlin`, `metaobjects-codegen-plantuml`
diff --git a/examples/advanced-modeling/codegen/templates/zod-validators.ts b/examples/advanced-modeling/codegen/templates/zod-validators.ts
index ea4945feae..95992cf0c9 100644
--- a/examples/advanced-modeling/codegen/templates/zod-validators.ts
+++ b/examples/advanced-modeling/codegen/templates/zod-validators.ts
@@ -393,6 +393,7 @@ export function insertSchemaFields(obj: MetaObject): SchemaFieldShape[] {
*/
export function updateSchemaFields(obj: MetaObject): SchemaFieldShape[] {
const autoGenPkFields = autoGenPkFieldNames(obj);
+ const pkFields = primaryKeyFieldNames(obj);
const tphPin = tphDiscriminatorPin(obj);
const out: SchemaFieldShape[] = [];
for (const child of obj.fields()) {
@@ -408,6 +409,10 @@ export function updateSchemaFields(obj: MetaObject): SchemaFieldShape[] {
// edit form for an entity carrying one. Clearing counts as a write, so the
// FR-035 present-null arm never reaches it either.
if (isWriteOnceMutability(child)) continue;
+ // SECURITY (1.2.x): a primary-key field is the row's identity, which the URL names. An
+ // ASSIGNED key leaves the update shape exactly like a generated one, so a client-sent
+ // key is stripped and can never re-key the row.
+ if (pkFields.has(child.name)) continue;
// TPH subtype discriminator: omitted from the update schema entirely.
if (tphPin !== undefined && child.name === tphPin.fieldName) continue;
const autoSet = child.attr(FIELD_ATTR_AUTO_SET);
@@ -491,6 +496,10 @@ export function renderZodValidators(obj: MetaObject, ctx?: RenderContext): Code
// below; a value presented on PATCH is stripped, not 400'd (see
// updateSchemaFields for the grounding).
if (isWriteOnceMutability(child)) continue;
+ // SECURITY (1.2.x): the row's identity is the URL's. An ASSIGNED primary key leaves the
+ // update shape too (a generated one never entered it), so a client-sent key is stripped
+ // on PUT/PATCH and can never re-key the row. Mirrors updateSchemaFields.
+ if (pkFields.has(child.name)) continue;
// Update schema: @autoSet onCreate → omit entirely; onUpdate → transform
if (autoSet === AUTO_SET_ON_CREATE) {
diff --git a/examples/showcase/.metaobjects/.gen-state/.hashes.json b/examples/showcase/.metaobjects/.gen-state/.hashes.json
index 131a0265b9..84023e786a 100644
--- a/examples/showcase/.metaobjects/.gen-state/.hashes.json
+++ b/examples/showcase/.metaobjects/.gen-state/.hashes.json
@@ -4,7 +4,7 @@
"generated/csharp/SubscriberBlurbPayload.g.cs": "29eb3a6ce64496ffe734cba55d0213994316b4281d3fa6791917393bae36c9ed",
"generated/csharp/SubscriberFilterAllowlist.g.cs": "3839b04884e4e393d4f7d7bf4c7d4fe5b3852bd3a92b1ecb282cb8935a3c98e5",
"generated/csharp/SubscriberNames.g.cs": "c2cf0248c2ecde155ec2623604771e39bed23783603d6f18a2ed82967227a732",
- "generated/csharp/SubscriberRoutes.g.cs": "15450e230d396a739d789340c42488da354c22265193b5ac61b074b0ba6fb1ff",
+ "generated/csharp/SubscriberRoutes.g.cs": "d05912d0a76b52334857796a42b2919be8709997d6c073c11d2c44590fe686a9",
"generated/python/Subscriber.py": "9dd4c0acea47f99d1daf79930f9de2e400f30780ebce6c63f023be528a72b762",
"generated/python/SubscriberBlurbPayload.py": "a5ef8a08e63efbe0f73e39a21a368cff5150c68cc8beeea6e8aab0c755f8bbdd",
"generated/python/__init__.py": "daa04cec586768866d0996c779f62073e6773fe63750ff668327991fac2fd0f5",
diff --git a/examples/showcase/codegen/templates/zod-validators.ts b/examples/showcase/codegen/templates/zod-validators.ts
index ea4945feae..95992cf0c9 100644
--- a/examples/showcase/codegen/templates/zod-validators.ts
+++ b/examples/showcase/codegen/templates/zod-validators.ts
@@ -393,6 +393,7 @@ export function insertSchemaFields(obj: MetaObject): SchemaFieldShape[] {
*/
export function updateSchemaFields(obj: MetaObject): SchemaFieldShape[] {
const autoGenPkFields = autoGenPkFieldNames(obj);
+ const pkFields = primaryKeyFieldNames(obj);
const tphPin = tphDiscriminatorPin(obj);
const out: SchemaFieldShape[] = [];
for (const child of obj.fields()) {
@@ -408,6 +409,10 @@ export function updateSchemaFields(obj: MetaObject): SchemaFieldShape[] {
// edit form for an entity carrying one. Clearing counts as a write, so the
// FR-035 present-null arm never reaches it either.
if (isWriteOnceMutability(child)) continue;
+ // SECURITY (1.2.x): a primary-key field is the row's identity, which the URL names. An
+ // ASSIGNED key leaves the update shape exactly like a generated one, so a client-sent
+ // key is stripped and can never re-key the row.
+ if (pkFields.has(child.name)) continue;
// TPH subtype discriminator: omitted from the update schema entirely.
if (tphPin !== undefined && child.name === tphPin.fieldName) continue;
const autoSet = child.attr(FIELD_ATTR_AUTO_SET);
@@ -491,6 +496,10 @@ export function renderZodValidators(obj: MetaObject, ctx?: RenderContext): Code
// below; a value presented on PATCH is stripped, not 400'd (see
// updateSchemaFields for the grounding).
if (isWriteOnceMutability(child)) continue;
+ // SECURITY (1.2.x): the row's identity is the URL's. An ASSIGNED primary key leaves the
+ // update shape too (a generated one never entered it), so a client-sent key is stripped
+ // on PUT/PATCH and can never re-key the row. Mirrors updateSchemaFields.
+ if (pkFields.has(child.name)) continue;
// Update schema: @autoSet onCreate → omit entirely; onUpdate → transform
if (autoSet === AUTO_SET_ON_CREATE) {
diff --git a/examples/showcase/generated/csharp/SubscriberRoutes.g.cs b/examples/showcase/generated/csharp/SubscriberRoutes.g.cs
index ffb1ed369c..9987f12b3c 100644
--- a/examples/showcase/generated/csharp/SubscriberRoutes.g.cs
+++ b/examples/showcase/generated/csharp/SubscriberRoutes.g.cs
@@ -100,6 +100,8 @@ await db.Subscribers.FindAsync(id) is { } found
try { input = System.Text.Json.JsonSerializer.Deserialize(__body.RootElement.GetRawText(), jsonOpts); }
catch (System.Text.Json.JsonException) { return Results.BadRequest(new { error = "validation" }); }
if (input is null) return Results.BadRequest(new { error = "validation" });
+ // Server-owned: a generated key, the TPH discriminator and M:N navigations are not settable by the client; the value is ignored.
+ input.Id = default!;
var __vr = new System.Collections.Generic.List();
if (!System.ComponentModel.DataAnnotations.Validator.TryValidateObject(
input, new System.ComponentModel.DataAnnotations.ValidationContext(input), __vr, true))
diff --git a/examples/showcase/jvm/pom.xml b/examples/showcase/jvm/pom.xml
index f41163da7d..6dcd77e740 100644
--- a/examples/showcase/jvm/pom.xml
+++ b/examples/showcase/jvm/pom.xml
@@ -23,7 +23,7 @@
- 8.2.0
+ 8.2.2UTF-8
diff --git a/examples/showcase/site-payload.json b/examples/showcase/site-payload.json
index 237e16a881..6667d82a4f 100644
--- a/examples/showcase/site-payload.json
+++ b/examples/showcase/site-payload.json
@@ -1,9 +1,9 @@
{
"registries": {
- "npm": "1.2.0",
+ "npm": "1.2.2",
"pypi": "1.2.1",
- "nuget": "1.2.0",
- "maven": "8.2.0",
+ "nuget": "1.2.2",
+ "maven": "8.2.2",
"metamodel": "1.2"
},
"counts": {
diff --git a/fixtures/api-contract-conformance/README.md b/fixtures/api-contract-conformance/README.md
index 7574beeab5..da4c8f44e1 100644
--- a/fixtures/api-contract-conformance/README.md
+++ b/fixtures/api-contract-conformance/README.md
@@ -35,6 +35,7 @@ fixtures/api-contract-conformance/
├── patch-empty-noop.yaml # FR-037 PATCH-5 a patch stripping to zero assignments is a no-op read-back
├── writeonce-patch-stripped.yaml # FR-037 R1 @mutability:"writeOnce" — stripped on PATCH, never rejected
├── autoset-patch.yaml # #203 @autoSet — PATCH bumps onUpdate, leaves onCreate alone
+ ├── input-server-owned-dropped.yaml # 1.2.x security: a client id / undeclared key never reaches storage
├── delete-204-and-404.yaml
├── invalid-sort-400.yaml
├── filter-eq.yaml # FR-009 filter operators
@@ -52,13 +53,13 @@ fixtures/api-contract-conformance/
└── filter-invalid-value.yaml # uncoercible value → 400; the fourth envelope, previously ungated
```
-Beside the 31 core scenarios above sit eight **sub-corpora**, each a directory with its
-own `meta.json`, `seed.json`, `scenarios/` and `README.md` (88 scenarios in all, 119 with the
+Beside the 32 core scenarios above sit eight **sub-corpora**, each a directory with its
+own `meta.json`, `seed.json`, `scenarios/` and `README.md` (90 scenarios in all, 122 with the
core):
| Directory | Scenarios | Gates | Lanes |
|---|---|---|---|
-| `tph/` | 10 | single-table inheritance | both |
+| `tph/` | 12 | single-table inheritance | both |
| `m2m/` | 9 | M:N traversal, and TPH x M:N together | both |
| `jsonb/` | 5 | typed value-object columns, and the numbers inside them (a double stays a JSON number; a decimal is a canonical string, option A of the 1.1.0 review) | both |
| `write-through/` | 2 | an entity that writes a table and reads a view | generated only |
@@ -121,6 +122,7 @@ requests:
| `empty` | the response body is empty / null (204 No Content) |
| `fieldsEqual`| the response body is an object; assert the listed field names are all equal to **each other** (raw, field-vs-field — no literal, so timestamp non-determinism is a non-issue). Used by the `@autoSet` gate (#203/ADR-0045). |
| `fieldsNotEqual`| the response body is an object; assert the two listed fields **differ** from each other. Used by the `@autoSet` gate (e.g. after a PATCH, `autoCreatedAt` (onCreate, preserved) != `autoUpdatedAt` (onUpdate, bumped)). |
+| `unset` | the response body is an object; each listed key is **missing or `null`** on it. Used by the input scenarios (`input-server-owned-dropped`, `tph-input-server-owned-dropped`): a value the client was not allowed to set never reached storage, so it never comes back in the echo. Missing and `null` are both accepted because a port's row shape decides whether an unset column is present as `null`. |
Runners are responsible for normalizing `createdAt` (and any other
non-deterministic fields) before comparison. The keys listed above are
diff --git a/fixtures/api-contract-conformance/scenarios/input-server-owned-dropped.yaml b/fixtures/api-contract-conformance/scenarios/input-server-owned-dropped.yaml
new file mode 100644
index 0000000000..597ed1b0cc
--- /dev/null
+++ b/fixtures/api-contract-conformance/scenarios/input-server-owned-dropped.yaml
@@ -0,0 +1,85 @@
+name: input-server-owned-dropped
+description: >
+ A write route hands storage only what the client may set (the 1.2.x security fix). A
+ client-sent `id` on a server-generated key, a key the entity does not declare (`isAdmin`)
+ and, on update, a `writeOnce` field are all DROPPED SILENTLY: the request answers as if the
+ key were absent (201/200, never 400), and none of them reaches storage. This is the rule
+ TypeScript has always followed and Python adopted in 1.2.1.
+
+ Each body carries an ordinary settable field DELIBERATELY: it is applied, and that pairing
+ is what makes the assertion about the server-owned keys and not about the request being
+ ignored whole. `unset` asserts the undeclared key is not echoed back (a stored key would
+ be), and the GETs of the client's ids prove no row was written or re-keyed under them.
+requests:
+ - id: r1
+ method: POST
+ path: /api/authors
+ body:
+ id: 999
+ name: "Barbara Liskov"
+ createdAt: "2026-02-01T10:00:00"
+ isAdmin: true
+ expect:
+ status: 201
+ body:
+ row:
+ name: "Barbara Liskov"
+ hasId: true
+ unset: [isAdmin]
+ - id: r2
+ method: GET
+ path: /api/authors/999
+ expect:
+ status: 404
+ - id: r3
+ method: PATCH
+ path: /api/authors/1
+ body:
+ id: 998
+ name: "Ada L. (input probe)"
+ isAdmin: true
+ expect:
+ status: 200
+ body:
+ row:
+ id: 1
+ name: "Ada L. (input probe)"
+ unset: [isAdmin]
+ - id: r4
+ method: PUT
+ path: /api/authors/2
+ body:
+ id: 997
+ name: "Alan T. (input probe)"
+ createdAt: "2026-01-02T10:00:00"
+ issuedCurrency: "JPY"
+ isAdmin: true
+ expect:
+ status: 200
+ body:
+ row:
+ id: 2
+ name: "Alan T. (input probe)"
+ # writeOnce: frozen after create, so the PUT's value never lands.
+ issuedCurrency: "GBP"
+ unset: [isAdmin]
+ - id: r5
+ method: GET
+ path: /api/authors/998
+ expect:
+ status: 404
+ - id: r6
+ method: GET
+ path: /api/authors/997
+ expect:
+ status: 404
+ - id: r7
+ method: GET
+ path: /api/authors/1
+ expect:
+ status: 200
+ body:
+ row:
+ id: 1
+ name: "Ada L. (input probe)"
+ unset: [isAdmin]
diff --git a/fixtures/api-contract-conformance/secret-fields/README.md b/fixtures/api-contract-conformance/secret-fields/README.md
index 29bc632038..ef23edf18d 100644
--- a/fixtures/api-contract-conformance/secret-fields/README.md
+++ b/fixtures/api-contract-conformance/secret-fields/README.md
@@ -1,8 +1,8 @@
# `api-contract-conformance/secret-fields/` — #484 credentials and excluded fields
Cross-port REST contract for the fields a generated API must not expose or accept: a
-field excluded from forms (`@formExclude`) and a credential (a field that declares a
-`view.password`).
+field excluded from forms (`@formExclude`), a credential (a field that declares a
+`view.password`) and a server-owned `@mutability: readOnly` field.
The model is one `Account`:
@@ -11,6 +11,7 @@ The model is one `Account`:
| `name` | (nothing) | accepted | returned |
| `tokenHash` | `@formExclude: true` | **ignored** | returned |
| `pinHash` | child `view.password` | **ignored** | **never returned** |
+| `role` | `@mutability: readOnly` | **ignored** | returned |
## The contract
diff --git a/fixtures/api-contract-conformance/secret-fields/meta.json b/fixtures/api-contract-conformance/secret-fields/meta.json
index d47906d8ad..d000a949a6 100644
--- a/fixtures/api-contract-conformance/secret-fields/meta.json
+++ b/fixtures/api-contract-conformance/secret-fields/meta.json
@@ -10,6 +10,7 @@
{ "field.string": { "name": "name", "@required": true, "@maxLength": 100, "@filterable": true, "@sortable": true } },
{ "field.string": { "name": "tokenHash", "@maxLength": 100, "@formExclude": true } },
{ "field.string": { "name": "pinHash", "@maxLength": 100, "children": [ { "view.password": {} } ] } },
+ { "field.string": { "name": "role", "@maxLength": 20, "@mutability": "readOnly" } },
{ "identity.primary": { "name": "id", "@fields": "id", "@generation": "increment" } }
]
}}
diff --git a/fixtures/api-contract-conformance/secret-fields/scenarios/read-omits-credential.yaml b/fixtures/api-contract-conformance/secret-fields/scenarios/read-omits-credential.yaml
index 92f48eb50f..f62e03a4dc 100644
--- a/fixtures/api-contract-conformance/secret-fields/scenarios/read-omits-credential.yaml
+++ b/fixtures/api-contract-conformance/secret-fields/scenarios/read-omits-credential.yaml
@@ -18,6 +18,7 @@ requests:
id: 1
name: "Ada Lovelace"
tokenHash: "token-hash-1"
+ role: "member"
- id: r2
method: GET
path: /api/accounts?sort=id
@@ -28,6 +29,8 @@ requests:
- id: 1
name: "Ada Lovelace"
tokenHash: "token-hash-1"
+ role: "member"
- id: 2
name: "Alan Turing"
tokenHash: "token-hash-2"
+ role: "owner"
diff --git a/fixtures/api-contract-conformance/secret-fields/scenarios/write-ignores-excluded.yaml b/fixtures/api-contract-conformance/secret-fields/scenarios/write-ignores-excluded.yaml
index 05f5e36306..d0c81f9a47 100644
--- a/fixtures/api-contract-conformance/secret-fields/scenarios/write-ignores-excluded.yaml
+++ b/fixtures/api-contract-conformance/secret-fields/scenarios/write-ignores-excluded.yaml
@@ -1,8 +1,8 @@
name: write-ignores-excluded
description: >
- A field excluded from forms (`@formExclude`) or marked as a credential (`view.password`)
- is not writable through the generated routes: create, PATCH and PUT all leave it as it
- was. The value is IGNORED, never rejected (HTTP 200/201, not 400), the same rule as
+ A field excluded from forms (`@formExclude`), marked as a credential (`view.password`) or
+ declared `@mutability: readOnly` (`role`) is not writable through the generated routes:
+ create, PATCH and PUT all leave it as it was. The value is IGNORED, never rejected (HTTP 200/201, not 400), the same rule as
`@mutability: writeOnce` on PATCH (`writeonce-patch-stripped`), because a generated
edit form submits every field it was given.
@@ -19,6 +19,7 @@ requests:
name: "Ada L. (probe)"
tokenHash: "forged"
pinHash: "forged"
+ role: "admin"
expect:
status: 200
body:
@@ -26,6 +27,7 @@ requests:
id: 1
name: "Ada L. (probe)"
tokenHash: "token-hash-1"
+ role: "member"
- id: r2
method: PUT
path: /api/accounts/2
@@ -33,6 +35,7 @@ requests:
name: "Alan T. (probe)"
tokenHash: "forged"
pinHash: "forged"
+ role: "admin"
expect:
status: 200
body:
@@ -40,6 +43,7 @@ requests:
id: 2
name: "Alan T. (probe)"
tokenHash: "token-hash-2"
+ role: "owner"
- id: r3
method: POST
path: /api/accounts
@@ -47,6 +51,7 @@ requests:
name: "Grace Hopper"
tokenHash: "forged"
pinHash: "forged"
+ role: "admin"
expect:
status: 201
body:
@@ -54,6 +59,8 @@ requests:
name: "Grace Hopper"
# Never written: the column stays null, and `forged` never landed.
tokenHash: null
+ # readOnly is server-owned: a create cannot set it either (1.2.x security fix).
+ role: null
hasId: true
- id: r4
method: PATCH
@@ -63,6 +70,7 @@ requests:
name: "Ada L. (probe 2)"
tokenHash: null
pinHash: null
+ role: null
expect:
status: 200
body:
@@ -70,3 +78,4 @@ requests:
id: 1
name: "Ada L. (probe 2)"
tokenHash: "token-hash-1"
+ role: "member"
diff --git a/fixtures/api-contract-conformance/secret-fields/seed.json b/fixtures/api-contract-conformance/secret-fields/seed.json
index 6697ba1fcb..13b7225941 100644
--- a/fixtures/api-contract-conformance/secret-fields/seed.json
+++ b/fixtures/api-contract-conformance/secret-fields/seed.json
@@ -1,6 +1,6 @@
{
"rows": [
- { "id": 1, "name": "Ada Lovelace", "tokenHash": "token-hash-1", "pinHash": "pin-hash-1" },
- { "id": 2, "name": "Alan Turing", "tokenHash": "token-hash-2", "pinHash": "pin-hash-2" }
+ { "id": 1, "name": "Ada Lovelace", "tokenHash": "token-hash-1", "pinHash": "pin-hash-1", "role": "member" },
+ { "id": 2, "name": "Alan Turing", "tokenHash": "token-hash-2", "pinHash": "pin-hash-2", "role": "owner" }
]
}
diff --git a/fixtures/api-contract-conformance/tph/README.md b/fixtures/api-contract-conformance/tph/README.md
index 5c45a2231f..86a18dbb4e 100644
--- a/fixtures/api-contract-conformance/tph/README.md
+++ b/fixtures/api-contract-conformance/tph/README.md
@@ -49,7 +49,9 @@ tph/
├── tph-writeonce-patch-stripped.yaml # FR-037: inherited @mutability "writeOnce" stripped on the per-subtype PATCH
├── tph-update-explicit-null-clears.yaml # FR-035 tristate: present null clears; omitted @required untouched; null on @required → 400
├── tph-create-constraint-violation.yaml # FR-036: per-subtype CREATE validates against the annotated Dto
- └── tph-update-constraint-violation.yaml # FR-036: per-subtype PATCH validates each PRESENT value
+ ├── tph-update-constraint-violation.yaml # FR-036: per-subtype PATCH validates each PRESENT value
+ ├── tph-input-server-owned-dropped.yaml # 1.2.x security: client id, sibling column, undeclared key never stored
+ └── tph-input-foreign-discriminator-dropped.yaml # 1.2.x security: the subtype comes from the URL, never the body
```
`meta.json` declares the `acme::auth` package:
diff --git a/fixtures/api-contract-conformance/tph/scenarios/tph-input-foreign-discriminator-dropped.yaml b/fixtures/api-contract-conformance/tph/scenarios/tph-input-foreign-discriminator-dropped.yaml
new file mode 100644
index 0000000000..e4290f706d
--- /dev/null
+++ b/fixtures/api-contract-conformance/tph/scenarios/tph-input-foreign-discriminator-dropped.yaml
@@ -0,0 +1,44 @@
+name: tph-input-foreign-discriminator-dropped
+description: >
+ A per-subtype route takes the row's subtype from the URL, never from the body (the 1.2.x
+ security fix). A `type` naming a different subtype, sent to the Bridge route, is DROPPED
+ SILENTLY on create and on update: the created row is a Bridge, no Copay row appears, and an
+ updated Bridge stays a Bridge. Python's generated TPH routes answer this body with 400 rather
+ than dropping it; that runner skips this scenario (see the Python codegen KNOWN_GAPS.md).
+requests:
+ - id: r1
+ method: POST
+ path: /api/auths/bridge
+ body:
+ type: "Copay"
+ reference: "REF-DISC"
+ quantity: 4
+ expect:
+ status: 201
+ body:
+ row: { type: "Bridge", reference: "REF-DISC", quantity: 4 }
+ hasId: true
+ - id: r2
+ method: GET
+ path: /api/auths/copay?filter[reference][eq]=REF-DISC
+ expect:
+ status: 200
+ body:
+ length: 0
+ - id: r3
+ method: PATCH
+ path: /api/auths/bridge/1
+ body:
+ type: "Copay"
+ reference: "REF-1-DISC"
+ expect:
+ status: 200
+ body:
+ row: { id: 1, type: "Bridge", reference: "REF-1-DISC" }
+ - id: r4
+ method: GET
+ path: /api/auths/copay?filter[reference][eq]=REF-1-DISC
+ expect:
+ status: 200
+ body:
+ length: 0
diff --git a/fixtures/api-contract-conformance/tph/scenarios/tph-input-server-owned-dropped.yaml b/fixtures/api-contract-conformance/tph/scenarios/tph-input-server-owned-dropped.yaml
new file mode 100644
index 0000000000..f70f85e341
--- /dev/null
+++ b/fixtures/api-contract-conformance/tph/scenarios/tph-input-server-owned-dropped.yaml
@@ -0,0 +1,72 @@
+name: tph-input-server-owned-dropped
+description: >
+ The per-subtype write routes hand storage only what the client may set, the same rule as
+ `input-server-owned-dropped` in the core corpus (the 1.2.x security fix). A client-sent `id`
+ on the generated key, a key the hierarchy does not declare (`isAdmin`), a column only a
+ SIBLING subtype declares (`copayAmount` sent to the Bridge route) and, on update, a
+ `writeOnce` field are all DROPPED SILENTLY (201/200, never 400): the row keeps its
+ server-assigned id and nothing it may not set is echoed back. A body discriminator is
+ `tph-input-foreign-discriminator-dropped`.
+requests:
+ - id: r1
+ method: POST
+ path: /api/auths/bridge
+ body:
+ id: 999
+ reference: "REF-INPUT"
+ quantity: 3
+ copayAmount: "7.77"
+ isAdmin: true
+ expect:
+ status: 201
+ body:
+ row: { type: "Bridge", reference: "REF-INPUT", quantity: 3 }
+ hasId: true
+ unset: [isAdmin, copayAmount]
+ - id: r2
+ method: GET
+ path: /api/auths/999
+ expect:
+ status: 404
+ - id: r3
+ method: GET
+ path: /api/auths/copay?filter[copayAmount][eq]=7.77
+ expect:
+ status: 200
+ body:
+ length: 0
+ - id: r4
+ method: PATCH
+ path: /api/auths/bridge/1
+ body:
+ id: 998
+ reference: "REF-1-INPUT"
+ issuedCurrency: "JPY"
+ isAdmin: true
+ expect:
+ status: 200
+ body:
+ row: { id: 1, type: "Bridge", reference: "REF-1-INPUT", issuedCurrency: "USD" }
+ unset: [isAdmin]
+ - id: r5
+ method: PUT
+ path: /api/auths/copay/2
+ body:
+ id: 997
+ reference: "REF-2-INPUT"
+ isAdmin: true
+ expect:
+ status: 200
+ body:
+ row: { id: 2, type: "Copay", reference: "REF-2-INPUT" }
+ unset: [isAdmin]
+ - id: r6
+ method: GET
+ path: /api/auths/998
+ expect:
+ status: 404
+ - id: r7
+ method: GET
+ path: /api/auths/997
+ expect:
+ status: 404
diff --git a/server/csharp/Directory.Build.props b/server/csharp/Directory.Build.props
index 64e1f7c16b..9c9c41a6c0 100644
--- a/server/csharp/Directory.Build.props
+++ b/server/csharp/Directory.Build.props
@@ -8,7 +8,7 @@
-->
- 1.2.0
+ 1.2.2Doug MealingDoug Mealing LLCMetaObjects
diff --git a/server/csharp/MetaObjects.Codegen.Tests/ServerOwnedCreateInputTests.cs b/server/csharp/MetaObjects.Codegen.Tests/ServerOwnedCreateInputTests.cs
new file mode 100644
index 0000000000..4fb3855300
--- /dev/null
+++ b/server/csharp/MetaObjects.Codegen.Tests/ServerOwnedCreateInputTests.cs
@@ -0,0 +1,134 @@
+// ServerOwnedCreateInputTests — a generated create hands storage ONLY what the client may set.
+// The HTTP behaviour is gated by the api-contract corpus (`input-server-owned-dropped`,
+// `tph-input-server-owned-dropped`, secret-fields); this pins the emission: the generated key,
+// the TPH discriminator and the M:N navigations are reset before `Add`, and a readOnly field of
+// EVERY shape (including a TPH subtype's own) is declared with a private setter.
+
+using MetaObjects.Codegen;
+using MetaObjects.Codegen.Generators;
+using MetaObjects.Loader;
+using MetaObjects.Meta;
+using Xunit;
+
+namespace MetaObjects.Codegen.Tests;
+
+public class ServerOwnedCreateInputTests
+{
+ private const string PlainModel = """
+ { "metadata.root": { "package": "acme::input", "children": [
+ { "object.entity": { "name": "Post", "children": [
+ { "source.rdb": { "@table": "posts" } },
+ { "field.long": { "name": "id" } },
+ { "field.string": { "name": "title", "@maxLength": 100 } },
+ { "field.string": { "name": "role", "@maxLength": 20, "@mutability": "readOnly" } },
+ { "field.enum": { "name": "stage", "@values": ["Draft", "Live"], "@mutability": "readOnly" } },
+ { "relationship.association": { "name": "tags", "@cardinality": "many", "@objectRef": "Tag", "@through": "PostTag" } },
+ { "identity.primary": { "@fields": "id", "@generation": "increment" } }
+ ]}},
+ { "object.entity": { "name": "Tag", "children": [
+ { "source.rdb": { "@table": "tags" } },
+ { "field.long": { "name": "id" } },
+ { "identity.primary": { "@fields": "id", "@generation": "increment" } }
+ ]}},
+ { "object.entity": { "name": "PostTag", "children": [
+ { "source.rdb": { "@table": "post_tags" } },
+ { "field.long": { "name": "postId" } },
+ { "field.long": { "name": "tagId" } },
+ { "identity.primary": { "@fields": ["postId", "tagId"] } },
+ { "identity.reference": { "name": "fkPost", "@fields": "postId", "@references": "Post" } },
+ { "identity.reference": { "name": "fkTag", "@fields": "tagId", "@references": "Tag" } }
+ ]}}
+ ]}}
+ """;
+
+ private const string AssignedKeyModel = """
+ { "metadata.root": { "package": "acme::input", "children": [
+ { "object.entity": { "name": "Code", "children": [
+ { "source.rdb": { "@table": "codes" } },
+ { "field.string": { "name": "id", "@maxLength": 20 } },
+ { "identity.primary": { "@fields": "id", "@generation": "assigned" } }
+ ]}}
+ ]}}
+ """;
+
+ private const string TphModel = """
+ { "metadata.root": { "package": "acme::input", "children": [
+ { "object.entity": { "name": "Thing", "@discriminator": "kind", "children": [
+ { "source.rdb": { "@table": "things" } },
+ { "field.long": { "name": "id" } },
+ { "field.enum": { "name": "kind", "@values": ["A", "B"] } },
+ { "identity.primary": { "@fields": "id", "@generation": "increment" } }
+ ]}},
+ { "object.entity": { "name": "AThing", "extends": "Thing", "@discriminatorValue": "A", "children": [
+ { "field.string": { "name": "note", "@maxLength": 20 } },
+ { "field.string": { "name": "grade", "@maxLength": 20, "@mutability": "readOnly" } }
+ ]}},
+ { "object.entity": { "name": "BThing", "extends": "Thing", "@discriminatorValue": "B", "children": [
+ { "field.int": { "name": "qty" } }
+ ]}}
+ ]}}
+ """;
+
+ private static string Emit(string model, string generator, string file)
+ {
+ var r = new MetaDataLoader().Load([new InMemoryStringSource(model, id: "input.json")]);
+ Assert.Empty(r.Errors);
+ var ctx = new GenContext
+ {
+ Entities = r.Root.Objects(),
+ Root = r.Root,
+ Config = new GenConfig { OutDir = "/tmp", Namespace = "Acme.Generated", ColumnNamingStrategy = ColumnNamingStrategy.Literal },
+ };
+ IGenerator g = generator == "routes" ? new RoutesGenerator() : new EntityGenerator();
+ return g.Generate(ctx).Single(f => f.Path == file).Content;
+ }
+
+ [Fact]
+ public void Create_resets_a_generated_key_and_empties_navigations_before_Add()
+ {
+ var src = Emit(PlainModel, "routes", "PostRoutes.g.cs");
+ var post = src[src.IndexOf("app.MapPost(", StringComparison.Ordinal)..];
+ var reset = post.IndexOf("input.Id = default!;", StringComparison.Ordinal);
+ var tags = post.IndexOf("input.Tags = new System.Collections.Generic.List();", StringComparison.Ordinal);
+ var add = post.IndexOf("db.Posts.Add(input);", StringComparison.Ordinal);
+ Assert.True(reset >= 0 && tags >= 0 && add > reset && add > tags, post);
+ }
+
+ [Fact]
+ public void An_assigned_key_is_the_callers_and_is_not_reset()
+ {
+ var src = Emit(AssignedKeyModel, "routes", "CodeRoutes.g.cs");
+ Assert.DoesNotContain("input.Id = default!;", src);
+ Assert.DoesNotContain("Server-owned", src);
+ }
+
+ [Fact]
+ public void A_readOnly_field_of_every_shape_has_a_private_setter()
+ {
+ var src = Emit(PlainModel, "entity", "Post.g.cs");
+ Assert.Contains("Role { get; private set; }", src);
+ Assert.Contains("Stage { get; private set; }", src);
+ Assert.Contains("Title { get; set; }", src);
+ }
+
+ [Fact]
+ public void A_tph_subtype_readOnly_field_has_a_private_setter()
+ {
+ var src = Emit(TphModel, "entity", "AThing.g.cs");
+ Assert.Contains("Grade { get; private set; }", src);
+ Assert.Contains("Note { get; set; }", src);
+ }
+
+ [Fact]
+ public void Tph_subtype_create_resets_the_key_and_pins_the_discriminator_to_the_route_subtype()
+ {
+ var src = Emit(TphModel, "routes", "ThingRoutes.g.cs");
+ var start = src.IndexOf("app.MapPost(prefix + \"/things/a\"", StringComparison.Ordinal);
+ var end = src.IndexOf("app.MapPost(prefix + \"/things/b\"", StringComparison.Ordinal);
+ Assert.True(start >= 0 && end > start, src);
+ var a = src[start..end];
+ Assert.Contains("input.Id = default!;", a);
+ Assert.Contains("input.Kind = default!;", a);
+ Assert.True(a.IndexOf("input.Kind = default!;", StringComparison.Ordinal) < a.IndexOf(".Add(input);", StringComparison.Ordinal), a);
+ }
+}
diff --git a/server/csharp/MetaObjects.Codegen/Generators/EntityGenerator.cs b/server/csharp/MetaObjects.Codegen/Generators/EntityGenerator.cs
index 810c3c78e7..b278fac020 100644
--- a/server/csharp/MetaObjects.Codegen/Generators/EntityGenerator.cs
+++ b/server/csharp/MetaObjects.Codegen/Generators/EntityGenerator.cs
@@ -626,9 +626,9 @@ protected virtual string TphSubtypeScalarProperty(
// A NON-required decimal array is nullable (no initializer) so PATCH null / an omitted
// POST value stays a NULL column instead of failing as a required collection.
if (IsDecimalWireField(field) && !CSharpNaming.IsRequired(entity, field))
- arr.Append($" public IList<{baseType}>? {propName} {{ get; set; }}");
+ arr.Append($" public IList<{baseType}>? {propName} {{ {SetterFor(field)} }}");
else
- arr.Append($" public IList<{baseType}> {propName} {{ get; set; }} = new List<{baseType}>();");
+ arr.Append($" public IList<{baseType}> {propName} {{ {SetterFor(field)} }} = new List<{baseType}>();");
return arr.ToString();
}
@@ -653,7 +653,7 @@ protected virtual string TphSubtypeScalarProperty(
var init = defaultInit.Length > 0
? defaultInit
: (required && !isValue ? " = default!;" : string.Empty);
- sb.Append($" public {baseType}{nullable} {propName} {{ get; set; }}{init}");
+ sb.Append($" public {baseType}{nullable} {propName} {{ {SetterFor(field)} }}{init}");
return sb.ToString();
}
@@ -665,9 +665,9 @@ protected virtual string TphSubtypeEnumProperty(MetaObject entity, MetaField fie
var propName = PropertyName(field);
var colAttr = $" [Column({CSharpNaming.ColumnRef(entity, field, strategy, config.IncludeNames)})]\n";
if (field.ResolvedIsArray()) // ADR-0039: resolving — array-ness inheritable via extends
- return $"{colAttr} public IList<{typeName}> {propName} {{ get; set; }} = new List<{typeName}>();";
+ return $"{colAttr} public IList<{typeName}> {propName} {{ {SetterFor(field)} }} = new List<{typeName}>();";
var nullable = CSharpNaming.IsRequired(entity, field) ? "" : "?";
- return $"{colAttr} public {typeName}{nullable} {propName} {{ get; set; }}";
+ return $"{colAttr} public {typeName}{nullable} {propName} {{ {SetterFor(field)} }}";
}
// The directly-extended entity (the metadata `extends` target) of a TPH subtype — the
@@ -1528,10 +1528,10 @@ protected virtual string EnumProperty(
var propName = PropertyName(field);
var colAttr = withAttributes ? $" [Column({CSharpNaming.ColumnRef(entity, field, strategy, config.IncludeNames)})]\n" : "";
if (field.ResolvedIsArray()) // ADR-0039: resolving — array-ness inheritable via extends
- return $"{colAttr} public IList<{typeName}> {propName} {{ get; set; }} = new List<{typeName}>();";
+ return $"{colAttr} public IList<{typeName}> {propName} {{ {SetterFor(field)} }} = new List<{typeName}>();";
var required = CSharpNaming.IsRequired(entity, field);
var type = required ? typeName : typeName + "?";
- return $"{colAttr} public {type} {propName} {{ get; set; }}";
+ return $"{colAttr} public {type} {propName} {{ {SetterFor(field)} }}";
}
// A scalar property. withAttributes adds the EF-mapping annotations ([Key] for a
@@ -1589,9 +1589,9 @@ protected virtual string ScalarProperty(
// NON-required value-object array is nullable so a null member is omitted on the wire.
var omittable = valueObject && _wire.NullMembers == NullMemberForm.Omit;
if ((IsDecimalWireField(field) || omittable) && !CSharpNaming.IsRequired(owner, field))
- arr.Append($" public IList<{baseType}>? {propName} {{ get; set; }}");
+ arr.Append($" public IList<{baseType}>? {propName} {{ {SetterFor(field)} }}");
else
- arr.Append($" public IList<{baseType}> {propName} {{ get; set; }} = new List<{baseType}>();");
+ arr.Append($" public IList<{baseType}> {propName} {{ {SetterFor(field)} }} = new List<{baseType}>();");
return arr.ToString();
}
@@ -1660,11 +1660,21 @@ protected virtual string ScalarProperty(
// the column from UPDATE). `writeOnce` keeps a PUBLIC setter on purpose — the caller
// must be able to supply it on insert; freezing it afterwards is the DbContext's
// SetAfterSaveBehavior(Ignore), not the property's job.
- var setter = field.IsReadOnlyMutability ? "get; private set;" : "get; set;";
+ var setter = SetterFor(field);
sb.Append($" public {type} {propName} {{ {setter} }}{init}");
return sb.ToString();
}
+ // FR-037 R1 / SECURITY (1.2.x) — the accessor pair of a mapped property. A `readOnly` field
+ // takes a PRIVATE setter on EVERY property shape (scalar, enum, array, value object, map; plain
+ // entity or TPH subtype): EF materializes it on read and application code cannot write it, so
+ // the generated create route's body binding (System.Text.Json skips a non-public setter) can
+ // never hand a client-supplied value to storage. Before 1.2.x only the plain scalar shape did,
+ // so a readOnly enum, array, value-object, map or TPH-subtype field was writable on create.
+ // `writeOnce` keeps a PUBLIC setter on purpose (the caller supplies it on insert).
+ private static string SetterFor(MetaField field) =>
+ field.IsReadOnlyMutability ? "get; private set;" : "get; set;";
+
// String length + pattern DataAnnotations for a string scalar, combining the field
// @maxLength attr with validator.length (@min/@max) and validator.regex (@pattern).
//
@@ -1889,11 +1899,11 @@ protected static string EscapeAttrString(string s)
// null-vs-empty distinction (EF re-serializes the empty list to `[]` on write).
if (field.ResolvedIsArray()) // ADR-0039: resolving — array-ness inheritable via extends
return required
- ? $" public ICollection<{typeName}> {propName} {{ get; set; }} = new List<{typeName}>();"
- : $" public ICollection<{typeName}>? {propName} {{ get; set; }}";
+ ? $" public ICollection<{typeName}> {propName} {{ {SetterFor(field)} }} = new List<{typeName}>();"
+ : $" public ICollection<{typeName}>? {propName} {{ {SetterFor(field)} }}";
return required
- ? $" public {typeName} {propName} {{ get; set; }} = default!;"
- : $" public {typeName}? {propName} {{ get; set; }}";
+ ? $" public {typeName} {propName} {{ {SetterFor(field)} }} = default!;"
+ : $" public {typeName}? {propName} {{ {SetterFor(field)} }}";
}
// A property for a field.map (an open-keyed map). Emits a single
@@ -1922,8 +1932,8 @@ protected string MapProperty(MetaObject owner, MetaField field, GenContext ctx,
var required = CSharpNaming.IsRequired(owner, field);
var colAttr = withAttributes ? $" [Column({CSharpNaming.ColumnRef(owner, field, ctx.Config.ColumnNamingStrategy, ctx.Config.IncludeNames)})]\n" : "";
return required
- ? $"{colAttr} public Dictionary {propName} {{ get; set; }} = new();"
- : $"{colAttr} public Dictionary? {propName} {{ get; set; }}";
+ ? $"{colAttr} public Dictionary {propName} {{ {SetterFor(field)} }} = new();"
+ : $"{colAttr} public Dictionary? {propName} {{ {SetterFor(field)} }}";
}
// The CLR scalar type for a projection field whose value is a MIN/MAX aggregate:
diff --git a/server/csharp/MetaObjects.Codegen/Generators/RoutesGenerator.cs b/server/csharp/MetaObjects.Codegen/Generators/RoutesGenerator.cs
index f254e8ec63..da52168a24 100644
--- a/server/csharp/MetaObjects.Codegen/Generators/RoutesGenerator.cs
+++ b/server/csharp/MetaObjects.Codegen/Generators/RoutesGenerator.cs
@@ -418,7 +418,8 @@ protected virtual EmittedFile GenerateStandardRoutes(MetaObject entity, GenConte
AppendCreateHandler(sb, "/" + route, cls, dbSet, requiredKeys,
CreatedResult("prefix + \"/" + route + "\"", "input", credentials), voFields, mapVoFields, autoSetFields,
writeThrough ? (readDbSet, pkProp!, route) : null, parseBody: HasDecimalField(entity),
- deniedFields.Select(f => CSharpNaming.Pascal(f.Name)).ToList(), credentials);
+ deniedFields.Select(f => CSharpNaming.Pascal(f.Name)).ToList(), credentials,
+ ServerOwnedCreateResets(entity, ctx.Root));
// PATCH + PUT share the same handler — TS reference exposes both verbs, and both
// return the updated row (HTTP 200), matching the cross-port api-contract.
@@ -988,7 +989,8 @@ private static void AppendCreateHandler(
(string ReadDbSet, string PkProp, string Route)? reRead = null,
bool parseBody = false,
IReadOnlyList? deniedNavs = null,
- IReadOnlyList? credentials = null)
+ IReadOnlyList? credentials = null,
+ IReadOnlyList? serverOwned = null)
{
// A decimal field can refuse its value while the body is bound (out of declared range, not a
// number). The framework's own binding answers that with a bare 400 and no body, so an entity
@@ -997,6 +999,7 @@ private static void AppendCreateHandler(
{
sb.AppendLine($" app.MapPost(prefix + \"{mapPath}\", async ({cls} input, AppDbContext db) =>");
sb.AppendLine(" {");
+ AppendCreateServerOwned(sb, serverOwned);
AppendCreateIgnoreDenied(sb, deniedNavs);
AppendCreateValidation(sb);
AppendCreateVoValidation(sb, voFields, mapVoFields);
@@ -1033,6 +1036,7 @@ private static void AppendCreateHandler(
sb.AppendLine(" try { input = System.Text.Json.JsonSerializer.Deserialize<" + cls + ">(__body.RootElement.GetRawText(), jsonOpts); }");
sb.AppendLine(" catch (System.Text.Json.JsonException) { return Results.BadRequest(new { error = \"validation\" }); }");
sb.AppendLine(" if (input is null) return Results.BadRequest(new { error = \"validation\" });");
+ AppendCreateServerOwned(sb, serverOwned);
AppendCreateIgnoreDenied(sb, deniedNavs);
AppendCreateValidation(sb);
AppendCreateVoValidation(sb, voFields, mapVoFields);
@@ -1067,6 +1071,44 @@ private static void AppendCreatePersist(
}
}
+ // SECURITY (1.2.x) — a generated create hands storage ONLY what the client may set. The body is
+ // bound straight onto the EF entity, so every member the server owns is reset before validation
+ // and `Add`, and the request answers as if the key were absent (never a 400):
+ // - a server-generated primary key (@generation increment|uuid): default, so EF generates it;
+ // - the TPH discriminator on a per-subtype route: default, so EF's discriminator value
+ // generator stamps the route subtype's own @discriminatorValue (the route is its only source);
+ // - M:N navigation collections: emptied, else `Add` would insert a client-sent related graph.
+ // A readOnly field needs no line here: the entity declares it with a private setter, which
+ // System.Text.Json never binds (EntityGenerator.SetterFor).
+ private static void AppendCreateServerOwned(StringBuilder sb, IReadOnlyList? statements)
+ {
+ if (statements is null || statements.Count == 0) return;
+ sb.AppendLine(" // Server-owned: a generated key, the TPH discriminator and M:N navigations are not settable by the client; the value is ignored.");
+ foreach (var st in statements) sb.AppendLine(" " + st);
+ }
+
+ // The reset statements AppendCreateServerOwned emits for one entity (empty when it has none, so an
+ // entity with an assigned key, no navigation and no discriminator keeps its output byte-identical).
+ // A TPH subtype class declares no M:N property of its own — the navigations it carries are its
+ // discriminator base class's — so a subtype route passes that base as navOwner.
+ private static List ServerOwnedCreateResets(MetaObject entity, MetaRoot root, string? discProp = null, MetaObject? navOwner = null)
+ {
+ var list = new List();
+ if (entity.PrimaryIdentity() is MetaPrimaryIdentity pk
+ && pk.Generation is MetaObjects.Core.Identity.IdentityConstants.GENERATION_INCREMENT
+ or MetaObjects.Core.Identity.IdentityConstants.GENERATION_UUID
+ && pk.Fields is [var keyName]
+ && entity.Fields().FirstOrDefault(f => f.Name == keyName) is { } keyField)
+ list.Add($"input.{CSharpNaming.Pascal(keyField.Name)} = default!;");
+ if (discProp is not null) list.Add($"input.{discProp} = default!;");
+ foreach (var nav in M2MNavigationBuilder.For(navOwner ?? entity, root, _ => { }))
+ {
+ var target = CSharpNaming.Pascal(nav.Target.Name);
+ list.Add($"input.{CSharpNaming.Pascal(nav.Name)} = new System.Collections.Generic.List<{target}>();");
+ }
+ return list;
+ }
+
// #484 — a write-denied key (@formExclude or credential) on a create body is IGNORED, never
// rejected: the bound value is reset to the CLR default (unset / null) before validation.
private static void AppendCreateIgnoreDenied(StringBuilder sb, IReadOnlyList? deniedNavs)
@@ -1448,7 +1490,8 @@ private static void AppendTphSubtypeRoutes(
AppendCreateHandler(sb, "/" + subRoute, subCls, dbSet, requiredKeys,
CreatedResult("prefix + \"/" + subRoute + "/\" + input." + pkProp, "input", credentials), [], mapVoFields, autoSetFields,
parseBody: HasDecimalField(st.Entity),
- deniedNavs: deniedFields.Select(f => CSharpNaming.Pascal(f.Name)).ToList(), credentials: credentials);
+ deniedNavs: deniedFields.Select(f => CSharpNaming.Pascal(f.Name)).ToList(), credentials: credentials,
+ serverOwned: ServerOwnedCreateResets(st.Entity, root, discProp, hierarchy[0]));
// Per-subtype update (PATCH + PUT): partial merge of the JSON body onto the scoped
// entity, NEVER touching the PK or the discriminator. Cross-subtype id → 404.
diff --git a/server/csharp/MetaObjects.IntegrationTests/Api/ApiContractAssertions.cs b/server/csharp/MetaObjects.IntegrationTests/Api/ApiContractAssertions.cs
index e6bc127b54..13ca20b229 100644
--- a/server/csharp/MetaObjects.IntegrationTests/Api/ApiContractAssertions.cs
+++ b/server/csharp/MetaObjects.IntegrationTests/Api/ApiContractAssertions.cs
@@ -151,6 +151,19 @@ public static void AssertResponse(string scenarioName, ApiRequest request, int s
$"{scenarioName} / {request.Id}: expected row.{kvp.Key}={Render(kvp.Value)}, got {Render(actual)}");
}
}
+ // Each listed key is missing or null: a value the client may not set never reached storage.
+ // (Missing-or-null, not strictly missing: ports differ on echoing an unset column as null.)
+ if (want.TryGetValue("unset", out var unsetObj) && unsetObj is List
*/
final class InMemoryAuthRepositorySource {
@@ -100,7 +100,9 @@ public Optional findByIdAndType(Long id, String discriminator) {
@Override
public AuthDto createWithType(String discriminator, AuthDto dto) {
- // Discriminator injected from the URL — dto.type() is intentionally ignored.
+ // A naive adopter repository: it trusts what it is handed (the id and the DTO's own
+ // discriminator when present, falling back to the URL's), so a value the controller
+ // forwarded from the request body is stored and the shared scenarios can see it.
// `type` is a value-constrained enum (field.enum discriminator), so coerce the
// String URL discriminator into the generated AuthType (its members ARE the
// discriminator values).
@@ -109,7 +111,8 @@ public AuthDto createWithType(String discriminator, AuthDto dto) {
// AuthDto.stampForInsert(dto) before calling createWithType — the repo just
// persists the incoming (already-stamped) autoCreatedAt/autoUpdatedAt verbatim.
AuthDto saved = new AuthDto(
- nextId.getAndIncrement(), AuthDto.AuthType.valueOf(discriminator), dto.reference(),
+ dto.id() != null ? dto.id() : Long.valueOf(nextId.getAndIncrement()),
+ dto.type() != null ? dto.type() : AuthDto.AuthType.valueOf(discriminator), dto.reference(),
// FR-037 R1: writeOnce IS bound on create — settable exactly once.
dto.issuedCurrency(),
dto.autoCreatedAt(), dto.autoUpdatedAt(),
diff --git a/server/java/maven-plugin/pom.xml b/server/java/maven-plugin/pom.xml
index 69c6963f79..56bdbcc152 100644
--- a/server/java/maven-plugin/pom.xml
+++ b/server/java/maven-plugin/pom.xml
@@ -2,7 +2,7 @@
metaobjectscom.metaobjects
- 8.2.0
+ 8.2.24.0.0
diff --git a/server/java/metadata-ktx/pom.xml b/server/java/metadata-ktx/pom.xml
index e902e8fc06..7c16b99371 100644
--- a/server/java/metadata-ktx/pom.xml
+++ b/server/java/metadata-ktx/pom.xml
@@ -7,7 +7,7 @@
com.metaobjectsmetaobjects
- 8.2.0
+ 8.2.2metaobjects-metadata-ktx
diff --git a/server/java/metadata/pom.xml b/server/java/metadata/pom.xml
index d0290e656b..c2716046fd 100644
--- a/server/java/metadata/pom.xml
+++ b/server/java/metadata/pom.xml
@@ -4,7 +4,7 @@
com.metaobjectsmetaobjects
- 8.2.0
+ 8.2.2metaobjects-metadata
diff --git a/server/java/om/pom.xml b/server/java/om/pom.xml
index e03690a86d..c33e76ccc6 100644
--- a/server/java/om/pom.xml
+++ b/server/java/om/pom.xml
@@ -5,7 +5,7 @@
com.metaobjectsmetaobjects
- 8.2.0
+ 8.2.2metaobjects-om
diff --git a/server/java/omdb-ktx/pom.xml b/server/java/omdb-ktx/pom.xml
index d5261ce1bd..07d9832f74 100644
--- a/server/java/omdb-ktx/pom.xml
+++ b/server/java/omdb-ktx/pom.xml
@@ -7,7 +7,7 @@
com.metaobjectsmetaobjects
- 8.2.0
+ 8.2.2metaobjects-omdb-ktx
diff --git a/server/java/omdb/pom.xml b/server/java/omdb/pom.xml
index ae699c85ce..4744ad6944 100644
--- a/server/java/omdb/pom.xml
+++ b/server/java/omdb/pom.xml
@@ -4,7 +4,7 @@
com.metaobjectsmetaobjects
- 8.2.0
+ 8.2.2metaobjects-omdb
diff --git a/server/java/pom.xml b/server/java/pom.xml
index b3f5c3595c..29ddd9fd55 100644
--- a/server/java/pom.xml
+++ b/server/java/pom.xml
@@ -2,7 +2,7 @@
4.0.0com.metaobjectsmetaobjects
- 8.2.0
+ 8.2.2pomMetaObjects CoreUniversal metadata-driven development platform
diff --git a/server/java/render/pom.xml b/server/java/render/pom.xml
index 26f3dc66ab..a62d2e77cc 100644
--- a/server/java/render/pom.xml
+++ b/server/java/render/pom.xml
@@ -6,7 +6,7 @@
com.metaobjectsmetaobjects
- 8.2.0
+ 8.2.2metaobjects-render
diff --git a/server/java/spring-boot-starter/pom.xml b/server/java/spring-boot-starter/pom.xml
index c131688526..62abe5f9ee 100644
--- a/server/java/spring-boot-starter/pom.xml
+++ b/server/java/spring-boot-starter/pom.xml
@@ -6,7 +6,7 @@
com.metaobjectsmetaobjects
- 8.2.0
+ 8.2.2metaobjects-spring-boot-starter
diff --git a/server/python/src/metaobjects/codegen/KNOWN_GAPS.md b/server/python/src/metaobjects/codegen/KNOWN_GAPS.md
index 1b300bfa6f..a8c8385253 100644
--- a/server/python/src/metaobjects/codegen/KNOWN_GAPS.md
+++ b/server/python/src/metaobjects/codegen/KNOWN_GAPS.md
@@ -54,6 +54,18 @@ import wiring itself (`from ._entity import `), which still needs
path-resolution/import-base machinery; the config's per-target `outDir` is the
prerequisite that is now in place.
+## TPH body discriminator: 400, not a silent drop
+
+**Status:** known divergence, out of scope for the 1.2.x input patch.
+
+A per-subtype write route (`POST /api/auths/bridge`) validates the request body with
+that subtype's model, whose discriminator accepts only the route's own value. A body
+that names another subtype (`"type": "Copay"`) is answered `400 {"error":"validation"}`.
+Nothing is stored, so this is not a security hole, but the other ports drop the key
+and create the row with the route's subtype. The shared
+`tph-input-foreign-discriminator-dropped` scenario asserts the drop, and this port's
+runner skips it with this reason (`tests/integration/test_api_contract_tph_generated.py`).
+
## FR-015 stored-procedure callables are NOT generated by this port
**Contract.** FR-015 gives a `source.rdb @kind: storedProc` / `tableFunction` a generated
diff --git a/server/python/tests/integration/api_contract_assertions.py b/server/python/tests/integration/api_contract_assertions.py
index 11a6f33445..fac4b8ccce 100644
--- a/server/python/tests/integration/api_contract_assertions.py
+++ b/server/python/tests/integration/api_contract_assertions.py
@@ -1,7 +1,7 @@
"""Assertion engine for api-contract-conformance scenarios.
The vocabulary (``equals`` / ``length`` / ``ids`` / ``names`` / ``row`` /
-``hasId`` / ``envelope`` / ``error`` / ``field`` / ``empty``) is the cross-port contract —
+``unset`` / ``hasId`` / ``envelope`` / ``error`` / ``field`` / ``empty``) is the cross-port contract —
every per-port runner must implement these keys identically. See
``fixtures/api-contract-conformance/README.md``.
@@ -202,6 +202,19 @@ def assert_response(
f"but both = {a_value!r}"
)
+ if "unset" in expect_body:
+ # Each listed key is missing or null: a value the client may not set never reached
+ # storage. (Missing-or-null: ports differ on echoing an unset column as null.)
+ if not isinstance(body, dict):
+ raise AssertionError(
+ f"{scenario_name} / {request_id}: expected object for unset, got: {body!r}"
+ )
+ stored = [k for k in expect_body["unset"] if body.get(k) is not None]
+ if stored:
+ raise AssertionError(
+ f"{scenario_name} / {request_id}: expected {stored!r} unset, got: {body!r}"
+ )
+
if expect_body.get("hasId") is True:
if not isinstance(body, dict):
raise AssertionError(
diff --git a/server/python/tests/integration/generated_secret_fields_app.py b/server/python/tests/integration/generated_secret_fields_app.py
index 61d9eb9a4e..3a6a1f2f1c 100644
--- a/server/python/tests/integration/generated_secret_fields_app.py
+++ b/server/python/tests/integration/generated_secret_fields_app.py
@@ -28,7 +28,7 @@
from .corpus_config import attach_corpus_wire
from .generated_router_app import InMemoryAuthorRepository
-COLUMNS = ("id", "name", "tokenHash", "pinHash")
+COLUMNS = ("id", "name", "tokenHash", "pinHash", "role")
def load_account(meta_json: Path) -> MetaObject:
diff --git a/server/python/tests/integration/test_api_contract_tph_generated.py b/server/python/tests/integration/test_api_contract_tph_generated.py
index 7305eb6b78..b84fb01b84 100644
--- a/server/python/tests/integration/test_api_contract_tph_generated.py
+++ b/server/python/tests/integration/test_api_contract_tph_generated.py
@@ -55,6 +55,16 @@ def _load_scenarios() -> list[tuple[str, dict[str, Any]]]:
_SCENARIOS = _load_scenarios()
+
+# Scenarios this port's generated routes answer differently, each with its reason. The routes
+# validate the body's discriminator against the route's subtype and answer 400 rather than
+# dropping it; nothing is stored either way. See codegen/KNOWN_GAPS.md.
+_PORT_SKIPS: dict[str, str] = {
+ "tph-input-foreign-discriminator-dropped": (
+ "a body discriminator naming another subtype is a 400 here, not a silent drop "
+ "(KNOWN_GAPS.md: TPH body discriminator)"
+ ),
+}
_APP, _REPO = build_generated_tph_app(_TPH_DIR)
_CLIENT = TestClient(_APP)
@@ -65,6 +75,8 @@ def _load_scenarios() -> list[tuple[str, dict[str, Any]]]:
ids=[name for name, _ in _SCENARIOS],
)
def test_api_contract_tph_generated_scenario(scenario_name: str, scenario: dict[str, Any]) -> None:
+ if scenario_name in _PORT_SKIPS:
+ pytest.skip(_PORT_SKIPS[scenario_name])
_REPO.reset()
_REPO.seed(_SEED["auths"])
for req in scenario.get("requests", []):
diff --git a/server/typescript/packages/ai-runtime/package.json b/server/typescript/packages/ai-runtime/package.json
index 9ff757cf29..69fc612d73 100644
--- a/server/typescript/packages/ai-runtime/package.json
+++ b/server/typescript/packages/ai-runtime/package.json
@@ -1,6 +1,6 @@
{
"name": "@metaobjectsdev/ai-runtime",
- "version": "1.2.0",
+ "version": "1.2.2",
"description": "LLM call loop + typed-trace recorder adapters for MetaObjects: provider-neutral LlmClient seam, callLlm bridge, Composite/Langfuse/OTel recorders.",
"type": "module",
"main": "./dist/index.js",
diff --git a/server/typescript/packages/cli/package.json b/server/typescript/packages/cli/package.json
index b1f41e6d4e..f1e3c07511 100644
--- a/server/typescript/packages/cli/package.json
+++ b/server/typescript/packages/cli/package.json
@@ -1,6 +1,6 @@
{
"name": "@metaobjectsdev/cli",
- "version": "1.2.0",
+ "version": "1.2.2",
"description": "CLI for MetaObjects: scaffold, codegen, migrate, and drift-detection commands.",
"type": "module",
"main": "./dist/src/index.js",
diff --git a/server/typescript/packages/codegen-ts-react/package.json b/server/typescript/packages/codegen-ts-react/package.json
index 00d66c8985..343bdd944d 100644
--- a/server/typescript/packages/codegen-ts-react/package.json
+++ b/server/typescript/packages/codegen-ts-react/package.json
@@ -1,6 +1,6 @@
{
"name": "@metaobjectsdev/codegen-ts-react",
- "version": "1.2.0",
+ "version": "1.2.2",
"description": "React codegen for metaobjects — emits .form.tsx files using react-hook-form and @metaobjectsdev/react helpers.",
"type": "module",
"main": "./dist/index.js",
diff --git a/server/typescript/packages/codegen-ts-tanstack/package.json b/server/typescript/packages/codegen-ts-tanstack/package.json
index 6ae9c41926..07dd6d0ca9 100644
--- a/server/typescript/packages/codegen-ts-tanstack/package.json
+++ b/server/typescript/packages/codegen-ts-tanstack/package.json
@@ -1,6 +1,6 @@
{
"name": "@metaobjectsdev/codegen-ts-tanstack",
- "version": "1.2.0",
+ "version": "1.2.2",
"description": "TanStack codegen for metaobjects — TanStack Query hooks for every entity, plus TanStack Table column definitions and grid-state hooks for entities declaring a layout.dataGrid.",
"type": "module",
"main": "./dist/index.js",
diff --git a/server/typescript/packages/codegen-ts/package.json b/server/typescript/packages/codegen-ts/package.json
index cb52ec1a11..0785f3400e 100644
--- a/server/typescript/packages/codegen-ts/package.json
+++ b/server/typescript/packages/codegen-ts/package.json
@@ -1,6 +1,6 @@
{
"name": "@metaobjectsdev/codegen-ts",
- "version": "1.2.0",
+ "version": "1.2.2",
"description": "TypeScript codegen engine for MetaObjects — emits Drizzle, Zod, and Fastify artifacts.",
"type": "module",
"main": "./dist/index.js",
diff --git a/server/typescript/packages/codegen-ts/src/templates/zod-validators.ts b/server/typescript/packages/codegen-ts/src/templates/zod-validators.ts
index e6a526d36d..abaa2520ba 100644
--- a/server/typescript/packages/codegen-ts/src/templates/zod-validators.ts
+++ b/server/typescript/packages/codegen-ts/src/templates/zod-validators.ts
@@ -393,6 +393,7 @@ export function insertSchemaFields(obj: MetaObject): SchemaFieldShape[] {
*/
export function updateSchemaFields(obj: MetaObject): SchemaFieldShape[] {
const autoGenPkFields = autoGenPkFieldNames(obj);
+ const pkFields = primaryKeyFieldNames(obj);
const tphPin = tphDiscriminatorPin(obj);
const out: SchemaFieldShape[] = [];
for (const child of obj.fields()) {
@@ -408,6 +409,10 @@ export function updateSchemaFields(obj: MetaObject): SchemaFieldShape[] {
// edit form for an entity carrying one. Clearing counts as a write, so the
// FR-035 present-null arm never reaches it either.
if (isWriteOnceMutability(child)) continue;
+ // SECURITY (1.2.x): a primary-key field is the row's identity, which the URL names. An
+ // ASSIGNED key leaves the update shape exactly like a generated one, so a client-sent
+ // key is stripped and can never re-key the row.
+ if (pkFields.has(child.name)) continue;
// TPH subtype discriminator: omitted from the update schema entirely.
if (tphPin !== undefined && child.name === tphPin.fieldName) continue;
const autoSet = child.attr(FIELD_ATTR_AUTO_SET);
@@ -491,6 +496,10 @@ export function renderZodValidators(obj: MetaObject, ctx?: RenderContext): Code
// below; a value presented on PATCH is stripped, not 400'd (see
// updateSchemaFields for the grounding).
if (isWriteOnceMutability(child)) continue;
+ // SECURITY (1.2.x): the row's identity is the URL's. An ASSIGNED primary key leaves the
+ // update shape too (a generated one never entered it), so a client-sent key is stripped
+ // on PUT/PATCH and can never re-key the row. Mirrors updateSchemaFields.
+ if (pkFields.has(child.name)) continue;
// Update schema: @autoSet onCreate → omit entirely; onUpdate → transform
if (autoSet === AUTO_SET_ON_CREATE) {
diff --git a/server/typescript/packages/codegen-ts/test/__snapshots__/reporting-docs.test.ts.snap b/server/typescript/packages/codegen-ts/test/__snapshots__/reporting-docs.test.ts.snap
index d5a0163053..cc8e306f31 100644
--- a/server/typescript/packages/codegen-ts/test/__snapshots__/reporting-docs.test.ts.snap
+++ b/server/typescript/packages/codegen-ts/test/__snapshots__/reporting-docs.test.ts.snap
@@ -204,36 +204,36 @@ Generated API reference for this project; call these exactly as written. Imports
\`import { Program, ProgramInsertSchema, ProgramUpdateSchema } from "./Program"\`
- \`interface Program { id: number; title?: string; createdAt?: string }\` — The typed shape of a Program row, generated from its metadata.
- \`ProgramInsertSchema: ZodType<{ id: number; title?: string; createdAt?: string }>\` — Zod schema validating the body of a create / POST request (auto-generated PKs excluded).
-- \`ProgramUpdateSchema: ZodType<{ id?: number; title?: string; createdAt?: string }>\` — Zod schema validating the body of an update / PATCH request (all fields optional).
+- \`ProgramUpdateSchema: ZodType<{ title?: string; createdAt?: string }>\` — Zod schema validating the body of an update / PATCH request (all fields optional).
\`import { findProgramById, listPrograms, createProgram, updateProgram, deleteProgramById } from "./Program.queries"\`
- \`findProgramById(db: Db, id: number): Promise\` — Fetch a single Program by its primary key; null when not found.
- \`listPrograms(db: Db, opts?: { limit?: number; offset?: number }): Promise\` — List Program rows with optional limit/offset paging.
- \`createProgram(db: Db, data: { id: number; title?: string; createdAt?: string }): Promise\` — Validate (via ProgramInsertSchema) and insert a new Program. [throws: ZodError when data fails ProgramInsertSchema validation.]
-- \`updateProgram(db: Db, id: number, patch: { id?: number; title?: string; createdAt?: string }): Promise\` — Partially update a Program by primary key — writes only the assigned fields; null when not found. A renamed/dropped field is a compile error. [throws: ZodError when the patch fails ProgramUpdateSchema validation.]
+- \`updateProgram(db: Db, id: number, patch: { title?: string; createdAt?: string }): Promise\` — Partially update a Program by primary key — writes only the assigned fields; null when not found. A renamed/dropped field is a compile error. [throws: ZodError when the patch fails ProgramUpdateSchema validation.]
- \`deleteProgramById(db: Db, id: number): Promise\` — Delete a Program by primary key; true when a row was removed.
\`import { programRoutes } from "./Program.routes"\`
- \`GET /api/programs -> { id: number; title?: string; createdAt?: string }\` — List Program (supports filter/sort/paging query params).
- \`GET /api/programs/:id -> { id: number; title?: string; createdAt?: string }\` — Fetch a single Program by id (404 when not found).
- \`POST /api/programs body: { id: number; title?: string; createdAt?: string }\` — Create a Program (body validated by ProgramInsertSchema).
-- \`PATCH /api/programs/:id body: { id?: number; title?: string; createdAt?: string }\` — Partially update a Program by id (body validated by ProgramUpdateSchema).
-- \`PUT /api/programs/:id body: { id?: number; title?: string; createdAt?: string }\` — PUT alias of PATCH — the same handler and partial body (validated by ProgramUpdateSchema).
+- \`PATCH /api/programs/:id body: { title?: string; createdAt?: string }\` — Partially update a Program by id (body validated by ProgramUpdateSchema).
+- \`PUT /api/programs/:id body: { title?: string; createdAt?: string }\` — PUT alias of PATCH — the same handler and partial body (validated by ProgramUpdateSchema).
- \`DELETE /api/programs/:id\` — Delete a Program by id.
\`import { registerProgramRoutes } from "./Program.routes.hono"\`
- \`GET /api/programs -> { id: number; title?: string; createdAt?: string }\` — [Hono] List Program (filter/sort/paging query params).
- \`GET /api/programs/:id -> { id: number; title?: string; createdAt?: string }\` — [Hono] Fetch a single Program by id (404 when not found).
- \`POST /api/programs body: { id: number; title?: string; createdAt?: string }\` — [Hono] Create a Program (body validated by ProgramInsertSchema).
-- \`PATCH /api/programs/:id body: { id?: number; title?: string; createdAt?: string }\` — [Hono] Partially update a Program by id (body validated by ProgramUpdateSchema).
-- \`PUT /api/programs/:id body: { id?: number; title?: string; createdAt?: string }\` — [Hono] PUT alias of PATCH — the same handler and partial body (validated by ProgramUpdateSchema).
+- \`PATCH /api/programs/:id body: { title?: string; createdAt?: string }\` — [Hono] Partially update a Program by id (body validated by ProgramUpdateSchema).
+- \`PUT /api/programs/:id body: { title?: string; createdAt?: string }\` — [Hono] PUT alias of PATCH — the same handler and partial body (validated by ProgramUpdateSchema).
- \`DELETE /api/programs/:id\` — [Hono] Delete a Program by id.
Example:
\`\`\`ts
const created = await createProgram(db, { id: 1 });
const found = await findProgramById(db, created.id);
-const updated = await updateProgram(db, created.id, { id: 1 });
+const updated = await updateProgram(db, created.id, { title: "…" });
const removed = await deleteProgramById(db, created.id);
\`\`\`
@@ -242,37 +242,37 @@ const removed = await deleteProgramById(db, created.id);
\`import { Purchase, PurchaseInsertSchema, PurchaseUpdateSchema, purchasesRelations } from "./Purchase"\`
- \`interface Purchase { id: number; programId?: number; customerEmail?: string; amountCents?: number; status?: string; refunded?: boolean; purchasedAt?: string; purchasedOn?: string }\` — The typed shape of a Purchase row, generated from its metadata.
- \`PurchaseInsertSchema: ZodType<{ id: number; programId?: number; customerEmail?: string; amountCents?: number; status?: string; refunded?: boolean; purchasedAt?: string; purchasedOn?: string }>\` — Zod schema validating the body of a create / POST request (auto-generated PKs excluded).
-- \`PurchaseUpdateSchema: ZodType<{ id?: number; programId?: number; customerEmail?: string; amountCents?: number; status?: string; refunded?: boolean; purchasedAt?: string; purchasedOn?: string }>\` — Zod schema validating the body of an update / PATCH request (all fields optional).
+- \`PurchaseUpdateSchema: ZodType<{ programId?: number; customerEmail?: string; amountCents?: number; status?: string; refunded?: boolean; purchasedAt?: string; purchasedOn?: string }>\` — Zod schema validating the body of an update / PATCH request (all fields optional).
- \`const purchasesRelations { program?: Program (1:1 / N:1) }\` — Drizzle relations() for Purchase — register it with your schema, then traverse via the relational query API (db.query.purchases.findMany({ with: { … } })).
\`import { findPurchaseById, listPurchases, createPurchase, updatePurchase, deletePurchaseById } from "./Purchase.queries"\`
- \`findPurchaseById(db: Db, id: number): Promise\` — Fetch a single Purchase by its primary key; null when not found.
- \`listPurchases(db: Db, opts?: { limit?: number; offset?: number }): Promise\` — List Purchase rows with optional limit/offset paging.
- \`createPurchase(db: Db, data: { id: number; programId?: number; customerEmail?: string; amountCents?: number; status?: string; refunded?: boolean; purchasedAt?: string; purchasedOn?: string }): Promise\` — Validate (via PurchaseInsertSchema) and insert a new Purchase. [throws: ZodError when data fails PurchaseInsertSchema validation.]
-- \`updatePurchase(db: Db, id: number, patch: { id?: number; programId?: number; customerEmail?: string; amountCents?: number; status?: string; refunded?: boolean; purchasedAt?: string; purchasedOn?: string }): Promise\` — Partially update a Purchase by primary key — writes only the assigned fields; null when not found. A renamed/dropped field is a compile error. [throws: ZodError when the patch fails PurchaseUpdateSchema validation.]
+- \`updatePurchase(db: Db, id: number, patch: { programId?: number; customerEmail?: string; amountCents?: number; status?: string; refunded?: boolean; purchasedAt?: string; purchasedOn?: string }): Promise\` — Partially update a Purchase by primary key — writes only the assigned fields; null when not found. A renamed/dropped field is a compile error. [throws: ZodError when the patch fails PurchaseUpdateSchema validation.]
- \`deletePurchaseById(db: Db, id: number): Promise\` — Delete a Purchase by primary key; true when a row was removed.
\`import { purchaseRoutes } from "./Purchase.routes"\`
- \`GET /api/purchases -> { id: number; programId?: number; customerEmail?: string; amountCents?: number; status?: string; refunded?: boolean; purchasedAt?: string; purchasedOn?: string }\` — List Purchase (supports filter/sort/paging query params).
- \`GET /api/purchases/:id -> { id: number; programId?: number; customerEmail?: string; amountCents?: number; status?: string; refunded?: boolean; purchasedAt?: string; purchasedOn?: string }\` — Fetch a single Purchase by id (404 when not found).
- \`POST /api/purchases body: { id: number; programId?: number; customerEmail?: string; amountCents?: number; status?: string; refunded?: boolean; purchasedAt?: string; purchasedOn?: string }\` — Create a Purchase (body validated by PurchaseInsertSchema).
-- \`PATCH /api/purchases/:id body: { id?: number; programId?: number; customerEmail?: string; amountCents?: number; status?: string; refunded?: boolean; purchasedAt?: string; purchasedOn?: string }\` — Partially update a Purchase by id (body validated by PurchaseUpdateSchema).
-- \`PUT /api/purchases/:id body: { id?: number; programId?: number; customerEmail?: string; amountCents?: number; status?: string; refunded?: boolean; purchasedAt?: string; purchasedOn?: string }\` — PUT alias of PATCH — the same handler and partial body (validated by PurchaseUpdateSchema).
+- \`PATCH /api/purchases/:id body: { programId?: number; customerEmail?: string; amountCents?: number; status?: string; refunded?: boolean; purchasedAt?: string; purchasedOn?: string }\` — Partially update a Purchase by id (body validated by PurchaseUpdateSchema).
+- \`PUT /api/purchases/:id body: { programId?: number; customerEmail?: string; amountCents?: number; status?: string; refunded?: boolean; purchasedAt?: string; purchasedOn?: string }\` — PUT alias of PATCH — the same handler and partial body (validated by PurchaseUpdateSchema).
- \`DELETE /api/purchases/:id\` — Delete a Purchase by id.
\`import { registerPurchaseRoutes } from "./Purchase.routes.hono"\`
- \`GET /api/purchases -> { id: number; programId?: number; customerEmail?: string; amountCents?: number; status?: string; refunded?: boolean; purchasedAt?: string; purchasedOn?: string }\` — [Hono] List Purchase (filter/sort/paging query params).
- \`GET /api/purchases/:id -> { id: number; programId?: number; customerEmail?: string; amountCents?: number; status?: string; refunded?: boolean; purchasedAt?: string; purchasedOn?: string }\` — [Hono] Fetch a single Purchase by id (404 when not found).
- \`POST /api/purchases body: { id: number; programId?: number; customerEmail?: string; amountCents?: number; status?: string; refunded?: boolean; purchasedAt?: string; purchasedOn?: string }\` — [Hono] Create a Purchase (body validated by PurchaseInsertSchema).
-- \`PATCH /api/purchases/:id body: { id?: number; programId?: number; customerEmail?: string; amountCents?: number; status?: string; refunded?: boolean; purchasedAt?: string; purchasedOn?: string }\` — [Hono] Partially update a Purchase by id (body validated by PurchaseUpdateSchema).
-- \`PUT /api/purchases/:id body: { id?: number; programId?: number; customerEmail?: string; amountCents?: number; status?: string; refunded?: boolean; purchasedAt?: string; purchasedOn?: string }\` — [Hono] PUT alias of PATCH — the same handler and partial body (validated by PurchaseUpdateSchema).
+- \`PATCH /api/purchases/:id body: { programId?: number; customerEmail?: string; amountCents?: number; status?: string; refunded?: boolean; purchasedAt?: string; purchasedOn?: string }\` — [Hono] Partially update a Purchase by id (body validated by PurchaseUpdateSchema).
+- \`PUT /api/purchases/:id body: { programId?: number; customerEmail?: string; amountCents?: number; status?: string; refunded?: boolean; purchasedAt?: string; purchasedOn?: string }\` — [Hono] PUT alias of PATCH — the same handler and partial body (validated by PurchaseUpdateSchema).
- \`DELETE /api/purchases/:id\` — [Hono] Delete a Purchase by id.
Example:
\`\`\`ts
const created = await createPurchase(db, { id: 1 });
const found = await findPurchaseById(db, created.id);
-const updated = await updatePurchase(db, created.id, { id: 1 });
+const updated = await updatePurchase(db, created.id, { programId: 1 });
const removed = await deletePurchaseById(db, created.id);
\`\`\`
@@ -281,36 +281,36 @@ const removed = await deletePurchaseById(db, created.id);
\`import { WorkoutEvent, WorkoutEventInsertSchema, WorkoutEventUpdateSchema } from "./WorkoutEvent"\`
- \`interface WorkoutEvent { id: number; programId?: number; customerEmail?: string; weekNumber?: number; dayNumber?: number; eventType?: string; occurredAt?: string }\` — The typed shape of a WorkoutEvent row, generated from its metadata.
- \`WorkoutEventInsertSchema: ZodType<{ id: number; programId?: number; customerEmail?: string; weekNumber?: number; dayNumber?: number; eventType?: string; occurredAt?: string }>\` — Zod schema validating the body of a create / POST request (auto-generated PKs excluded).
-- \`WorkoutEventUpdateSchema: ZodType<{ id?: number; programId?: number; customerEmail?: string; weekNumber?: number; dayNumber?: number; eventType?: string; occurredAt?: string }>\` — Zod schema validating the body of an update / PATCH request (all fields optional).
+- \`WorkoutEventUpdateSchema: ZodType<{ programId?: number; customerEmail?: string; weekNumber?: number; dayNumber?: number; eventType?: string; occurredAt?: string }>\` — Zod schema validating the body of an update / PATCH request (all fields optional).
\`import { findWorkoutEventById, listWorkoutEvents, createWorkoutEvent, updateWorkoutEvent, deleteWorkoutEventById } from "./WorkoutEvent.queries"\`
- \`findWorkoutEventById(db: Db, id: number): Promise\` — Fetch a single WorkoutEvent by its primary key; null when not found.
- \`listWorkoutEvents(db: Db, opts?: { limit?: number; offset?: number }): Promise\` — List WorkoutEvent rows with optional limit/offset paging.
- \`createWorkoutEvent(db: Db, data: { id: number; programId?: number; customerEmail?: string; weekNumber?: number; dayNumber?: number; eventType?: string; occurredAt?: string }): Promise\` — Validate (via WorkoutEventInsertSchema) and insert a new WorkoutEvent. [throws: ZodError when data fails WorkoutEventInsertSchema validation.]
-- \`updateWorkoutEvent(db: Db, id: number, patch: { id?: number; programId?: number; customerEmail?: string; weekNumber?: number; dayNumber?: number; eventType?: string; occurredAt?: string }): Promise\` — Partially update a WorkoutEvent by primary key — writes only the assigned fields; null when not found. A renamed/dropped field is a compile error. [throws: ZodError when the patch fails WorkoutEventUpdateSchema validation.]
+- \`updateWorkoutEvent(db: Db, id: number, patch: { programId?: number; customerEmail?: string; weekNumber?: number; dayNumber?: number; eventType?: string; occurredAt?: string }): Promise\` — Partially update a WorkoutEvent by primary key — writes only the assigned fields; null when not found. A renamed/dropped field is a compile error. [throws: ZodError when the patch fails WorkoutEventUpdateSchema validation.]
- \`deleteWorkoutEventById(db: Db, id: number): Promise\` — Delete a WorkoutEvent by primary key; true when a row was removed.
\`import { workoutEventRoutes } from "./WorkoutEvent.routes"\`
- \`GET /api/workout_events -> { id: number; programId?: number; customerEmail?: string; weekNumber?: number; dayNumber?: number; eventType?: string; occurredAt?: string }\` — List WorkoutEvent (supports filter/sort/paging query params).
- \`GET /api/workout_events/:id -> { id: number; programId?: number; customerEmail?: string; weekNumber?: number; dayNumber?: number; eventType?: string; occurredAt?: string }\` — Fetch a single WorkoutEvent by id (404 when not found).
- \`POST /api/workout_events body: { id: number; programId?: number; customerEmail?: string; weekNumber?: number; dayNumber?: number; eventType?: string; occurredAt?: string }\` — Create a WorkoutEvent (body validated by WorkoutEventInsertSchema).
-- \`PATCH /api/workout_events/:id body: { id?: number; programId?: number; customerEmail?: string; weekNumber?: number; dayNumber?: number; eventType?: string; occurredAt?: string }\` — Partially update a WorkoutEvent by id (body validated by WorkoutEventUpdateSchema).
-- \`PUT /api/workout_events/:id body: { id?: number; programId?: number; customerEmail?: string; weekNumber?: number; dayNumber?: number; eventType?: string; occurredAt?: string }\` — PUT alias of PATCH — the same handler and partial body (validated by WorkoutEventUpdateSchema).
+- \`PATCH /api/workout_events/:id body: { programId?: number; customerEmail?: string; weekNumber?: number; dayNumber?: number; eventType?: string; occurredAt?: string }\` — Partially update a WorkoutEvent by id (body validated by WorkoutEventUpdateSchema).
+- \`PUT /api/workout_events/:id body: { programId?: number; customerEmail?: string; weekNumber?: number; dayNumber?: number; eventType?: string; occurredAt?: string }\` — PUT alias of PATCH — the same handler and partial body (validated by WorkoutEventUpdateSchema).
- \`DELETE /api/workout_events/:id\` — Delete a WorkoutEvent by id.
\`import { registerWorkoutEventRoutes } from "./WorkoutEvent.routes.hono"\`
- \`GET /api/workout_events -> { id: number; programId?: number; customerEmail?: string; weekNumber?: number; dayNumber?: number; eventType?: string; occurredAt?: string }\` — [Hono] List WorkoutEvent (filter/sort/paging query params).
- \`GET /api/workout_events/:id -> { id: number; programId?: number; customerEmail?: string; weekNumber?: number; dayNumber?: number; eventType?: string; occurredAt?: string }\` — [Hono] Fetch a single WorkoutEvent by id (404 when not found).
- \`POST /api/workout_events body: { id: number; programId?: number; customerEmail?: string; weekNumber?: number; dayNumber?: number; eventType?: string; occurredAt?: string }\` — [Hono] Create a WorkoutEvent (body validated by WorkoutEventInsertSchema).
-- \`PATCH /api/workout_events/:id body: { id?: number; programId?: number; customerEmail?: string; weekNumber?: number; dayNumber?: number; eventType?: string; occurredAt?: string }\` — [Hono] Partially update a WorkoutEvent by id (body validated by WorkoutEventUpdateSchema).
-- \`PUT /api/workout_events/:id body: { id?: number; programId?: number; customerEmail?: string; weekNumber?: number; dayNumber?: number; eventType?: string; occurredAt?: string }\` — [Hono] PUT alias of PATCH — the same handler and partial body (validated by WorkoutEventUpdateSchema).
+- \`PATCH /api/workout_events/:id body: { programId?: number; customerEmail?: string; weekNumber?: number; dayNumber?: number; eventType?: string; occurredAt?: string }\` — [Hono] Partially update a WorkoutEvent by id (body validated by WorkoutEventUpdateSchema).
+- \`PUT /api/workout_events/:id body: { programId?: number; customerEmail?: string; weekNumber?: number; dayNumber?: number; eventType?: string; occurredAt?: string }\` — [Hono] PUT alias of PATCH — the same handler and partial body (validated by WorkoutEventUpdateSchema).
- \`DELETE /api/workout_events/:id\` — [Hono] Delete a WorkoutEvent by id.
Example:
\`\`\`ts
const created = await createWorkoutEvent(db, { id: 1 });
const found = await findWorkoutEventById(db, created.id);
-const updated = await updateWorkoutEvent(db, created.id, { id: 1 });
+const updated = await updateWorkoutEvent(db, created.id, { programId: 1 });
const removed = await deleteWorkoutEventById(db, created.id);
\`\`\`
"
@@ -343,7 +343,7 @@ import { createProgram, findProgramById, updateProgram, deleteProgramById } from
const created = await createProgram(db, { id: 1 });
const found = await findProgramById(db, created.id);
-const updated = await updateProgram(db, created.id, { id: 1 });
+const updated = await updateProgram(db, created.id, { title: "…" });
const removed = await deleteProgramById(db, created.id);
\`\`\`
@@ -413,7 +413,6 @@ Request body (data):
| Field | Type | Required | Notes |
|---|---|---|---|
-| \`id\` | \`number\` | | |
| \`title\` | \`string\` | | |
| \`createdAt\` | \`string\` | | |
@@ -495,7 +494,6 @@ Request body:
| Field | Type | Required | Notes |
|---|---|---|---|
-| \`id\` | \`number\` | | |
| \`title\` | \`string\` | | |
| \`createdAt\` | \`string\` | | |
@@ -513,7 +511,6 @@ Request body:
| Field | Type | Required | Notes |
|---|---|---|---|
-| \`id\` | \`number\` | | |
| \`title\` | \`string\` | | |
| \`createdAt\` | \`string\` | | |
@@ -597,7 +594,6 @@ Request body:
| Field | Type | Required | Notes |
|---|---|---|---|
-| \`id\` | \`number\` | | |
| \`title\` | \`string\` | | |
| \`createdAt\` | \`string\` | | |
@@ -615,7 +611,6 @@ Request body:
| Field | Type | Required | Notes |
|---|---|---|---|
-| \`id\` | \`number\` | | |
| \`title\` | \`string\` | | |
| \`createdAt\` | \`string\` | | |
@@ -661,7 +656,6 @@ Accepted fields:
| Field | Type | Required | Notes |
|---|---|---|---|
-| \`id\` | \`number\` | | |
| \`title\` | \`string\` | | |
| \`createdAt\` | \`string\` | | |
"
@@ -694,7 +688,7 @@ import { createPurchase, findPurchaseById, updatePurchase, deletePurchaseById }
const created = await createPurchase(db, { id: 1 });
const found = await findPurchaseById(db, created.id);
-const updated = await updatePurchase(db, created.id, { id: 1 });
+const updated = await updatePurchase(db, created.id, { programId: 1 });
const removed = await deletePurchaseById(db, created.id);
\`\`\`
@@ -790,7 +784,6 @@ Request body (data):
| Field | Type | Required | Notes |
|---|---|---|---|
-| \`id\` | \`number\` | | |
| \`programId\` | \`number\` | | |
| \`customerEmail\` | \`string\` | | |
| \`amountCents\` | \`number\` | | |
@@ -892,7 +885,6 @@ Request body:
| Field | Type | Required | Notes |
|---|---|---|---|
-| \`id\` | \`number\` | | |
| \`programId\` | \`number\` | | |
| \`customerEmail\` | \`string\` | | |
| \`amountCents\` | \`number\` | | |
@@ -915,7 +907,6 @@ Request body:
| Field | Type | Required | Notes |
|---|---|---|---|
-| \`id\` | \`number\` | | |
| \`programId\` | \`number\` | | |
| \`customerEmail\` | \`string\` | | |
| \`amountCents\` | \`number\` | | |
@@ -1019,7 +1010,6 @@ Request body:
| Field | Type | Required | Notes |
|---|---|---|---|
-| \`id\` | \`number\` | | |
| \`programId\` | \`number\` | | |
| \`customerEmail\` | \`string\` | | |
| \`amountCents\` | \`number\` | | |
@@ -1042,7 +1032,6 @@ Request body:
| Field | Type | Required | Notes |
|---|---|---|---|
-| \`id\` | \`number\` | | |
| \`programId\` | \`number\` | | |
| \`customerEmail\` | \`string\` | | |
| \`amountCents\` | \`number\` | | |
@@ -1098,7 +1087,6 @@ Accepted fields:
| Field | Type | Required | Notes |
|---|---|---|---|
-| \`id\` | \`number\` | | |
| \`programId\` | \`number\` | | |
| \`customerEmail\` | \`string\` | | |
| \`amountCents\` | \`number\` | | |
@@ -1150,7 +1138,7 @@ import { createWorkoutEvent, findWorkoutEventById, updateWorkoutEvent, deleteWor
const created = await createWorkoutEvent(db, { id: 1 });
const found = await findWorkoutEventById(db, created.id);
-const updated = await updateWorkoutEvent(db, created.id, { id: 1 });
+const updated = await updateWorkoutEvent(db, created.id, { programId: 1 });
const removed = await deleteWorkoutEventById(db, created.id);
\`\`\`
@@ -1228,7 +1216,6 @@ Request body (data):
| Field | Type | Required | Notes |
|---|---|---|---|
-| \`id\` | \`number\` | | |
| \`programId\` | \`number\` | | |
| \`customerEmail\` | \`string\` | | |
| \`weekNumber\` | \`number\` | | |
@@ -1326,7 +1313,6 @@ Request body:
| Field | Type | Required | Notes |
|---|---|---|---|
-| \`id\` | \`number\` | | |
| \`programId\` | \`number\` | | |
| \`customerEmail\` | \`string\` | | |
| \`weekNumber\` | \`number\` | | |
@@ -1348,7 +1334,6 @@ Request body:
| Field | Type | Required | Notes |
|---|---|---|---|
-| \`id\` | \`number\` | | |
| \`programId\` | \`number\` | | |
| \`customerEmail\` | \`string\` | | |
| \`weekNumber\` | \`number\` | | |
@@ -1448,7 +1433,6 @@ Request body:
| Field | Type | Required | Notes |
|---|---|---|---|
-| \`id\` | \`number\` | | |
| \`programId\` | \`number\` | | |
| \`customerEmail\` | \`string\` | | |
| \`weekNumber\` | \`number\` | | |
@@ -1470,7 +1454,6 @@ Request body:
| Field | Type | Required | Notes |
|---|---|---|---|
-| \`id\` | \`number\` | | |
| \`programId\` | \`number\` | | |
| \`customerEmail\` | \`string\` | | |
| \`weekNumber\` | \`number\` | | |
@@ -1524,7 +1507,6 @@ Accepted fields:
| Field | Type | Required | Notes |
|---|---|---|---|
-| \`id\` | \`number\` | | |
| \`programId\` | \`number\` | | |
| \`customerEmail\` | \`string\` | | |
| \`weekNumber\` | \`number\` | | |
diff --git a/server/typescript/packages/codegen-ts/test/templates/zod-validators.test.ts b/server/typescript/packages/codegen-ts/test/templates/zod-validators.test.ts
index 5b237c0213..ed91c3a735 100644
--- a/server/typescript/packages/codegen-ts/test/templates/zod-validators.test.ts
+++ b/server/typescript/packages/codegen-ts/test/templates/zod-validators.test.ts
@@ -356,6 +356,22 @@ describe("renderZodValidators", () => {
expect(update).toContain("name");
});
+ test("SECURITY 1.2.x: an ASSIGNED primary key is in the Insert schema and OUT of the Update schema", () => {
+ // The URL names the row on PUT/PATCH. An assigned key (no @generation) is the caller's on
+ // create, but leaving it in the update shape let a client-sent `code` re-key the row.
+ const coupon = metaObject(OBJECT_SUBTYPE_ENTITY, "Coupon");
+ coupon.addChild(metaField(FIELD_SUBTYPE_STRING, "code"));
+ coupon.addChild(metaField(FIELD_SUBTYPE_STRING, "label"));
+ const primary = meta(new TypeId(TYPE_IDENTITY, IDENTITY_SUBTYPE_PRIMARY), "primary");
+ primary.setAttr("fields", ["code"]);
+ coupon.addChild(primary);
+ const out = renderZodValidators(coupon).toString();
+ expect(schemaBody(out, "CouponInsertSchema")).toContain("code");
+ const update = schemaBody(out, "CouponUpdateSchema");
+ expect(update).not.toContain("code");
+ expect(update).toContain("label");
+ });
+
test("FR-037 R1: no @mutability (⇒ readWrite) is in BOTH schemas — the no-churn default", () => {
const out = customerWithMutability(undefined, "lifetimeValue");
expect(schemaBody(out, "CustomerInsertSchema")).toContain("lifetimeValue");
diff --git a/server/typescript/packages/docs-site/package.json b/server/typescript/packages/docs-site/package.json
index a559b1c5e1..c99675193e 100644
--- a/server/typescript/packages/docs-site/package.json
+++ b/server/typescript/packages/docs-site/package.json
@@ -1,6 +1,6 @@
{
"name": "@metaobjectsdev/docs-site",
- "version": "1.2.0",
+ "version": "1.2.2",
"description": "HTML documentation-site generator for metaobjects models — a browsable multi-page site (nav, search, per-object/package pages, kind-aware ER diagrams). Powers the `docs-site` generator (`docsSiteFile()`).",
"type": "module",
"main": "./dist/index.js",
diff --git a/server/typescript/packages/integration-tests/src/api-contract-scenario.ts b/server/typescript/packages/integration-tests/src/api-contract-scenario.ts
index 41ea9becb3..ca329a6eb9 100644
--- a/server/typescript/packages/integration-tests/src/api-contract-scenario.ts
+++ b/server/typescript/packages/integration-tests/src/api-contract-scenario.ts
@@ -26,6 +26,10 @@ export interface ExpectBody {
namesUnordered?: string[];
row?: Record;
hasId?: boolean;
+ /** The response body is an object and each listed key is MISSING or `null` on it: a value
+ * the client was not allowed to set never reached storage, so it never comes back in the
+ * echo (the 1.2.x input scenarios). */
+ unset?: string[];
/** Assert the listed RESPONSE fields all equal EACH OTHER (never a literal) —
* format-agnostic. Used by @autoSet scenarios to prove two stamped columns
* hold the same value without pinning the exact timestamp. */
@@ -283,6 +287,14 @@ export function assertResponse(
if (typeof row["id"] !== "number")
throw new Error(`${scenarioName} / ${request.id}: expected numeric id in body, got: ${stringify(body)}`);
}
+ if (want.unset) {
+ if (body === null || typeof body !== "object" || Array.isArray(body))
+ throw new Error(`${scenarioName} / ${request.id}: expected object for unset, got: ${stringify(body)}`);
+ const row = body as Record;
+ const stored = want.unset.filter((k) => row[k] !== undefined && row[k] !== null);
+ if (stored.length > 0)
+ throw new Error(`${scenarioName} / ${request.id}: expected ${stored.join(", ")} unset, got: ${stringify(body)}`);
+ }
if (want.fieldsEqual) {
const row = body as Record;
// Compare the raw response fields to EACH OTHER (format-agnostic) — every
diff --git a/server/typescript/packages/integration-tests/src/api-contract-secret-fields-generated-server.ts b/server/typescript/packages/integration-tests/src/api-contract-secret-fields-generated-server.ts
index 59885dde10..dbf642ed62 100644
--- a/server/typescript/packages/integration-tests/src/api-contract-secret-fields-generated-server.ts
+++ b/server/typescript/packages/integration-tests/src/api-contract-secret-fields-generated-server.ts
@@ -65,7 +65,7 @@ const READ_PATHS = {
};
export interface SecretFieldsSeed {
- rows: Array<{ id: number; name: string; tokenHash: string; pinHash: string }>;
+ rows: Array<{ id: number; name: string; tokenHash: string; pinHash: string; role: string }>;
}
export interface GeneratedSecretFieldsServerHandle {
@@ -124,7 +124,8 @@ export const db = drizzle(pool);
"id" bigserial PRIMARY KEY,
"name" varchar(100) NOT NULL,
"token_hash" varchar(100),
- "pin_hash" varchar(100)
+ "pin_hash" varchar(100),
+ "role" varchar(20)
);
CREATE OR REPLACE VIEW "v_account" AS SELECT "id", "name", "pin_hash" FROM "accounts";
CREATE TABLE IF NOT EXISTS "payers" ("id" bigserial PRIMARY KEY);
@@ -165,7 +166,7 @@ export const db = drizzle(pool);
for (const r of seed.rows)
await executeSql(
connectionUri,
- `INSERT INTO "accounts" ("id","name","token_hash","pin_hash") VALUES (${r.id}, ${str(r.name)}, ${str(r.tokenHash)}, ${str(r.pinHash)})`,
+ `INSERT INTO "accounts" ("id","name","token_hash","pin_hash","role") VALUES (${r.id}, ${str(r.name)}, ${str(r.tokenHash)}, ${str(r.pinHash)}, ${str(r.role)})`,
);
// The seed names ids explicitly; keep the sequence ahead of them for the POST scenarios.
await executeSql(connectionUri, `SELECT setval(pg_get_serial_sequence('accounts','id'), (SELECT MAX("id") FROM "accounts"));`);
diff --git a/server/typescript/packages/integration-tests/src/api-contract-server.ts b/server/typescript/packages/integration-tests/src/api-contract-server.ts
index 32cc2b3661..4342322804 100644
--- a/server/typescript/packages/integration-tests/src/api-contract-server.ts
+++ b/server/typescript/packages/integration-tests/src/api-contract-server.ts
@@ -188,6 +188,16 @@ export async function startServer(connectionUri: string, root: MetaRoot): Promis
return reply;
});
+ // The keys a client may write, as the generated routes' Insert/Update schemas have them: the
+ // server-generated `id`, the @autoSet columns and any key the entity does not declare are
+ // DROPPED silently (never 400'd), and `issuedCurrency` (writeOnce) is settable on create only.
+ const CREATE_KEYS = ["name", "bio", "createdAt", "issuedCurrency"] as const;
+ const UPDATE_KEYS = ["name", "bio", "createdAt"] as const;
+ const pick = (body: unknown, keys: readonly string[]): Record => {
+ const src = (body ?? {}) as Record;
+ return Object.fromEntries(keys.filter((k) => Object.hasOwn(src, k)).map((k) => [k, src[k]]));
+ };
+
// POST /api/authors
fastify.post(ROUTE_BASE, async (req, reply) => {
// #203 / ADR-0045 — the TS runtime ObjectManager does NOT stamp @autoSet
@@ -195,7 +205,7 @@ export async function startServer(connectionUri: string, root: MetaRoot): Promis
// the generated lane's InsertSchema. Both onCreate + onUpdate columns get the
// SAME captured now() on create; any caller-supplied value is ignored.
const now = new Date().toISOString();
- const body = { ...(req.body as Record), autoCreatedAt: now, autoUpdatedAt: now };
+ const body = { ...pick(req.body, CREATE_KEYS), autoCreatedAt: now, autoUpdatedAt: now };
const row = await om.create(ENTITY, body);
reply.code(201).send(row);
return reply;
@@ -215,12 +225,7 @@ export async function startServer(connectionUri: string, root: MetaRoot): Promis
// plain z.object() discards unknown keys). Dropping it also covers the
// present-NULL arm for free: clearing is a write, so an explicit null must
// not reach the column either.
- const {
- autoCreatedAt: _dropOnCreate,
- issuedCurrency: _dropWriteOnce,
- ...rest
- } = (req.body as Record) ?? {};
- const body = { ...rest, autoUpdatedAt: new Date().toISOString() };
+ const body = { ...pick(req.body, UPDATE_KEYS), autoUpdatedAt: new Date().toISOString() };
// A ValidationError (e.g. FR-035 present-null on a @required field) propagates
// to the shared setErrorHandler above → 400 {error:"validation"}.
const row = await om.update(ENTITY, Number(id), body, { ifMissing: "ignore" });
diff --git a/server/typescript/packages/metadata/package.json b/server/typescript/packages/metadata/package.json
index 48a941c10e..b2ecbeddb6 100644
--- a/server/typescript/packages/metadata/package.json
+++ b/server/typescript/packages/metadata/package.json
@@ -1,6 +1,6 @@
{
"name": "@metaobjectsdev/metadata",
- "version": "1.2.0",
+ "version": "1.2.2",
"description": "Metamodel loader, types, and constants for the MetaObjects standard.",
"type": "module",
"main": "./dist/index.js",
diff --git a/server/typescript/packages/migrate-ts/package.json b/server/typescript/packages/migrate-ts/package.json
index caf8274e57..c9340bfc10 100644
--- a/server/typescript/packages/migrate-ts/package.json
+++ b/server/typescript/packages/migrate-ts/package.json
@@ -1,6 +1,6 @@
{
"name": "@metaobjectsdev/migrate-ts",
- "version": "1.2.0",
+ "version": "1.2.2",
"description": "Schema migration tooling for MetaObjects: diff metadata vs DB and emit SQL for Postgres and SQLite.",
"type": "module",
"main": "./dist/index.js",
diff --git a/server/typescript/packages/render/package.json b/server/typescript/packages/render/package.json
index 0fc26e9170..fdc0d33c59 100644
--- a/server/typescript/packages/render/package.json
+++ b/server/typescript/packages/render/package.json
@@ -1,6 +1,6 @@
{
"name": "@metaobjectsdev/render",
- "version": "1.2.0",
+ "version": "1.2.2",
"description": "Deterministic text render engine for MetaObjects templates — Mustache (logic-less, the cross-port default) and Jinja (via nunjucks), provider-resolved partials, format-driven escaping, build-time payload drift check, zero core dependency.",
"type": "module",
"main": "./dist/index.js",
diff --git a/server/typescript/packages/runtime-ts/package.json b/server/typescript/packages/runtime-ts/package.json
index 376c24d585..c82fa8d88d 100644
--- a/server/typescript/packages/runtime-ts/package.json
+++ b/server/typescript/packages/runtime-ts/package.json
@@ -1,6 +1,6 @@
{
"name": "@metaobjectsdev/runtime-ts",
- "version": "1.2.0",
+ "version": "1.2.2",
"description": "Node-side runtime helpers for MetaObjects: Fastify route builders, Drizzle filter/sort integration, Kysely drivers.",
"type": "module",
"main": "./dist/index.js",
diff --git a/server/typescript/packages/sdk/package.json b/server/typescript/packages/sdk/package.json
index 511723b6a9..29428e2d67 100644
--- a/server/typescript/packages/sdk/package.json
+++ b/server/typescript/packages/sdk/package.json
@@ -1,6 +1,6 @@
{
"name": "@metaobjectsdev/sdk",
- "version": "1.2.0",
+ "version": "1.2.2",
"description": "Workspace helpers and agent-context assembly for MetaObjects projects.",
"type": "module",
"main": "./dist/index.js",
diff --git a/server/typescript/packages/test-generators/src/templates/zod-validators.ts b/server/typescript/packages/test-generators/src/templates/zod-validators.ts
index ea4945feae..95992cf0c9 100644
--- a/server/typescript/packages/test-generators/src/templates/zod-validators.ts
+++ b/server/typescript/packages/test-generators/src/templates/zod-validators.ts
@@ -393,6 +393,7 @@ export function insertSchemaFields(obj: MetaObject): SchemaFieldShape[] {
*/
export function updateSchemaFields(obj: MetaObject): SchemaFieldShape[] {
const autoGenPkFields = autoGenPkFieldNames(obj);
+ const pkFields = primaryKeyFieldNames(obj);
const tphPin = tphDiscriminatorPin(obj);
const out: SchemaFieldShape[] = [];
for (const child of obj.fields()) {
@@ -408,6 +409,10 @@ export function updateSchemaFields(obj: MetaObject): SchemaFieldShape[] {
// edit form for an entity carrying one. Clearing counts as a write, so the
// FR-035 present-null arm never reaches it either.
if (isWriteOnceMutability(child)) continue;
+ // SECURITY (1.2.x): a primary-key field is the row's identity, which the URL names. An
+ // ASSIGNED key leaves the update shape exactly like a generated one, so a client-sent
+ // key is stripped and can never re-key the row.
+ if (pkFields.has(child.name)) continue;
// TPH subtype discriminator: omitted from the update schema entirely.
if (tphPin !== undefined && child.name === tphPin.fieldName) continue;
const autoSet = child.attr(FIELD_ATTR_AUTO_SET);
@@ -491,6 +496,10 @@ export function renderZodValidators(obj: MetaObject, ctx?: RenderContext): Code
// below; a value presented on PATCH is stripped, not 400'd (see
// updateSchemaFields for the grounding).
if (isWriteOnceMutability(child)) continue;
+ // SECURITY (1.2.x): the row's identity is the URL's. An ASSIGNED primary key leaves the
+ // update shape too (a generated one never entered it), so a client-sent key is stripped
+ // on PUT/PATCH and can never re-key the row. Mirrors updateSchemaFields.
+ if (pkFields.has(child.name)) continue;
// Update schema: @autoSet onCreate → omit entirely; onUpdate → transform
if (autoSet === AUTO_SET_ON_CREATE) {
From 8e7a84c94e75f0cf0c146eb5aed5c87054b94251 Mon Sep 17 00:00:00 2001
From: Doug Mealing
Date: Fri, 13 Nov 2026 13:04:23 -0500
Subject: [PATCH 2/5] fix: keep a @required readOnly field creatable in C# and
Java generated create
Pre-gate review follow-ups to the 1.2.x create-input patch:
- C#: the required-key check skips readOnly fields (the private setter
never binds them), and create validation ignores a violation naming
only a @required readOnly member, as Java's SERVER_OWNED_ON_CREATE does.
- Java: the create-validation server-owned set covers every DTO component,
so a nulled readOnly or derived value-object column no longer 400s.
- TypeScript: drop the now-dead PK guard in the update-schema nullable arm
and list the PK rule in updateSchemaFields' doc comment.
---
CHANGELOG.md | 6 ++-
.../codegen/templates/zod-validators.ts | 7 ++-
.../codegen/templates/zod-validators.ts | 7 ++-
.../ServerOwnedCreateInputTests.cs | 31 +++++++++++++
.../Generators/RoutesGenerator.cs | 43 +++++++++++++++----
.../spring/SpringControllerGenerator.java | 4 +-
.../SpringServerOwnedInputCodegenTest.java | 29 +++++++++++++
.../src/templates/zod-validators.ts | 7 ++-
.../src/templates/zod-validators.ts | 7 ++-
9 files changed, 114 insertions(+), 27 deletions(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 6cacd80255..b81c89d1cd 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -25,7 +25,8 @@ file changes. No vocabulary or `metamodelVersion` change._
sent, so a client `id` on a generated key and a `@mutability: readOnly` or derived field
reached it. On a TPH per-subtype route the body's discriminator and a sibling subtype's
columns did too. The route now rebuilds the DTO with each of those components set to null
- before the repository call; the route's subtype still comes from the URL.
+ before the repository call; the route's subtype still comes from the URL. A `@required`
+ `readOnly` or derived value-object column no longer fails create validation once nulled.
- **Kotlin (`codegen-kotlin`).** The create route wrote `readOnly` and derived columns from the
body, and a TPH per-subtype route wrote a sibling subtype's columns. It now writes only the
route subtype's own settable columns.
@@ -35,7 +36,8 @@ file changes. No vocabulary or `metamodelVersion` change._
an M:N navigation graph were written. The route now resets the generated key and the
discriminator to their defaults and empties the M:N navigations before `Add`, and a
`readOnly` property of every shape, a TPH subtype's included, has a private setter, which
- System.Text.Json does not bind.
+ System.Text.Json does not bind. A `@required` `readOnly` field is therefore neither demanded
+ of the create body nor held to its `[Required]` there, so such an entity stays creatable.
- **TypeScript (`codegen-ts`).** The `UpdateSchema` kept an assigned (non-generated)
primary key, so a PUT or PATCH could re-key the row. The update schema now leaves out every
primary-key field; the insert schema still takes an assigned key, which is the caller's on
diff --git a/examples/advanced-modeling/codegen/templates/zod-validators.ts b/examples/advanced-modeling/codegen/templates/zod-validators.ts
index 95992cf0c9..1aafe1a916 100644
--- a/examples/advanced-modeling/codegen/templates/zod-validators.ts
+++ b/examples/advanced-modeling/codegen/templates/zod-validators.ts
@@ -386,6 +386,7 @@ export function insertSchemaFields(obj: MetaObject): SchemaFieldShape[] {
* The field SET the `UpdateSchema` accepts — same iteration + skip rules
* as `insertSchemaFields`, but mirroring the UpdateSchema branch of
* `renderZodValidators`:
+ * • a primary-key field is OMITTED, generated or assigned (the URL names the row);
* • a TPH subtype's @discriminator field is OMITTED (clients can't change subtype);
* • @autoSet onCreate fields are OMITTED (creation timestamps are immutable);
* • @autoSet onUpdate fields are present + optional (server fills them);
@@ -524,10 +525,8 @@ export function renderZodValidators(obj: MetaObject, ctx?: RenderContext): Code
// null — a present null CLEARS the column (`.set({field: null})` writes NULL).
// Keyed on required-ness, NOT fieldWillBeOptional: a required-with-@default
// field stays non-nullable so an explicit null on it is a 400 (validation),
- // never a silent clear. PK fields are excluded: their Drizzle column is
- // always not-null, so a nullable Zod type would fail `.set()`'s typecheck
- // (and NOT NULL at runtime) — see primaryKeyFieldNames.
- if (!isRequired(child) && !pkFields.has(child.name)) expr = code`${expr}.nullable()`;
+ // never a silent clear. PK fields never reach this branch (skipped above).
+ if (!isRequired(child)) expr = code`${expr}.nullable()`;
updateFieldLines.push(code` ${child.name}: ${expr}`);
}
}
diff --git a/examples/showcase/codegen/templates/zod-validators.ts b/examples/showcase/codegen/templates/zod-validators.ts
index 95992cf0c9..1aafe1a916 100644
--- a/examples/showcase/codegen/templates/zod-validators.ts
+++ b/examples/showcase/codegen/templates/zod-validators.ts
@@ -386,6 +386,7 @@ export function insertSchemaFields(obj: MetaObject): SchemaFieldShape[] {
* The field SET the `UpdateSchema` accepts — same iteration + skip rules
* as `insertSchemaFields`, but mirroring the UpdateSchema branch of
* `renderZodValidators`:
+ * • a primary-key field is OMITTED, generated or assigned (the URL names the row);
* • a TPH subtype's @discriminator field is OMITTED (clients can't change subtype);
* • @autoSet onCreate fields are OMITTED (creation timestamps are immutable);
* • @autoSet onUpdate fields are present + optional (server fills them);
@@ -524,10 +525,8 @@ export function renderZodValidators(obj: MetaObject, ctx?: RenderContext): Code
// null — a present null CLEARS the column (`.set({field: null})` writes NULL).
// Keyed on required-ness, NOT fieldWillBeOptional: a required-with-@default
// field stays non-nullable so an explicit null on it is a 400 (validation),
- // never a silent clear. PK fields are excluded: their Drizzle column is
- // always not-null, so a nullable Zod type would fail `.set()`'s typecheck
- // (and NOT NULL at runtime) — see primaryKeyFieldNames.
- if (!isRequired(child) && !pkFields.has(child.name)) expr = code`${expr}.nullable()`;
+ // never a silent clear. PK fields never reach this branch (skipped above).
+ if (!isRequired(child)) expr = code`${expr}.nullable()`;
updateFieldLines.push(code` ${child.name}: ${expr}`);
}
}
diff --git a/server/csharp/MetaObjects.Codegen.Tests/ServerOwnedCreateInputTests.cs b/server/csharp/MetaObjects.Codegen.Tests/ServerOwnedCreateInputTests.cs
index 4fb3855300..bc3d7dfbef 100644
--- a/server/csharp/MetaObjects.Codegen.Tests/ServerOwnedCreateInputTests.cs
+++ b/server/csharp/MetaObjects.Codegen.Tests/ServerOwnedCreateInputTests.cs
@@ -8,6 +8,8 @@
using MetaObjects.Codegen.Generators;
using MetaObjects.Loader;
using MetaObjects.Meta;
+using Microsoft.CodeAnalysis;
+using Microsoft.CodeAnalysis.CSharp;
using Xunit;
namespace MetaObjects.Codegen.Tests;
@@ -69,6 +71,18 @@ public class ServerOwnedCreateInputTests
]}}
""";
+ private const string RequiredReadOnlyModel = """
+ { "metadata.root": { "package": "acme::input", "children": [
+ { "object.entity": { "name": "Member", "children": [
+ { "source.rdb": { "@table": "members" } },
+ { "field.long": { "name": "id" } },
+ { "field.string": { "name": "title", "@required": true, "@maxLength": 100 } },
+ { "field.string": { "name": "role", "@required": true, "@maxLength": 20, "@mutability": "readOnly" } },
+ { "identity.primary": { "@fields": "id", "@generation": "increment" } }
+ ]}}
+ ]}}
+ """;
+
private static string Emit(string model, string generator, string file)
{
var r = new MetaDataLoader().Load([new InMemoryStringSource(model, id: "input.json")]);
@@ -119,6 +133,23 @@ public void A_tph_subtype_readOnly_field_has_a_private_setter()
Assert.Contains("Note { get; set; }", src);
}
+ [Fact]
+ public void A_required_readOnly_field_is_not_demanded_of_the_create_body()
+ {
+ // The client cannot set `role` (private setter), so the create must neither require its
+ // key nor reject the body over its [Required]: otherwise the entity could not be created.
+ var src = Emit(RequiredReadOnlyModel, "routes", "MemberRoutes.g.cs");
+ var post = src[src.IndexOf("app.MapPost(", StringComparison.Ordinal)..];
+ var req = post[post.IndexOf("foreach (var __req in", StringComparison.Ordinal)..];
+ req = req[..req.IndexOf('\n')];
+ Assert.Contains("\"title\"", req);
+ Assert.DoesNotContain("\"role\"", req);
+ Assert.Contains("System.Array.IndexOf(new[] { \"Role\" }, m) < 0", post);
+ var syntaxErrors = CSharpSyntaxTree.ParseText(src).GetDiagnostics()
+ .Where(d => d.Severity == DiagnosticSeverity.Error).Select(d => d.ToString()).ToList();
+ Assert.True(syntaxErrors.Count == 0, string.Join("\n", syntaxErrors));
+ }
+
[Fact]
public void Tph_subtype_create_resets_the_key_and_pins_the_discriminator_to_the_route_subtype()
{
diff --git a/server/csharp/MetaObjects.Codegen/Generators/RoutesGenerator.cs b/server/csharp/MetaObjects.Codegen/Generators/RoutesGenerator.cs
index da52168a24..d072dfc4dc 100644
--- a/server/csharp/MetaObjects.Codegen/Generators/RoutesGenerator.cs
+++ b/server/csharp/MetaObjects.Codegen/Generators/RoutesGenerator.cs
@@ -419,7 +419,7 @@ protected virtual EmittedFile GenerateStandardRoutes(MetaObject entity, GenConte
CreatedResult("prefix + \"/" + route + "\"", "input", credentials), voFields, mapVoFields, autoSetFields,
writeThrough ? (readDbSet, pkProp!, route) : null, parseBody: HasDecimalField(entity),
deniedFields.Select(f => CSharpNaming.Pascal(f.Name)).ToList(), credentials,
- ServerOwnedCreateResets(entity, ctx.Root));
+ ServerOwnedCreateResets(entity, ctx.Root), RequiredReadOnlyProps(entity));
// PATCH + PUT share the same handler — TS reference exposes both verbs, and both
// return the updated row (HTTP 200), matching the cross-port api-contract.
@@ -757,10 +757,23 @@ private static List RequiredCreateKeys(MetaObject obj, Func f.IsRequired && f.AutoSet is null && !f.IsDerived() && !isPkOrDisc(f))
+ // 1.2.x security — a readOnly field is never bound from the body (private setter),
+ // so demanding its key would make a @required readOnly entity uncreatable.
+ .Where(f => f.IsRequired && f.AutoSet is null && !f.IsDerived() && !f.IsReadOnlyMutability
+ && !isPkOrDisc(f))
.Select(f => f.Name)
.ToList();
+ // 1.2.x security — the CLR properties of the @required readOnly fields. The client cannot
+ // set them (private setter), so their [Required] describes the stored row, not the create
+ // body: the create validation ignores a violation that names only these members, as Java's
+ // SERVER_OWNED_ON_CREATE filter does. Empty for nearly every model → byte-identical output.
+ private static List RequiredReadOnlyProps(MetaObject obj) =>
+ obj.Fields()
+ .Where(f => f.IsRequired && f.IsReadOnlyMutability && !f.IsDerived())
+ .Select(f => CSharpNaming.Pascal(f.Name))
+ .ToList();
+
// Issue #203 — one @autoSet timestamp column the generated CRUD stamps with now().
// Nav is the PascalCase CLR property; NowExpr is the now() literal keyed off the
// COLUMN's temporal CLR type (generalizes beyond DateTimeOffset). OnUpdate columns
@@ -990,7 +1003,8 @@ private static void AppendCreateHandler(
bool parseBody = false,
IReadOnlyList? deniedNavs = null,
IReadOnlyList? credentials = null,
- IReadOnlyList? serverOwned = null)
+ IReadOnlyList? serverOwned = null,
+ IReadOnlyList? readOnlyRequired = null)
{
// A decimal field can refuse its value while the body is bound (out of declared range, not a
// number). The framework's own binding answers that with a bare 400 and no body, so an entity
@@ -1001,7 +1015,7 @@ private static void AppendCreateHandler(
sb.AppendLine(" {");
AppendCreateServerOwned(sb, serverOwned);
AppendCreateIgnoreDenied(sb, deniedNavs);
- AppendCreateValidation(sb);
+ AppendCreateValidation(sb, readOnlyRequired);
AppendCreateVoValidation(sb, voFields, mapVoFields);
AppendCreateAutoSet(sb, autoSetFields);
AppendCreatePersist(sb, dbSet, createdExpr, reRead, credentials ?? []);
@@ -1038,7 +1052,7 @@ private static void AppendCreateHandler(
sb.AppendLine(" if (input is null) return Results.BadRequest(new { error = \"validation\" });");
AppendCreateServerOwned(sb, serverOwned);
AppendCreateIgnoreDenied(sb, deniedNavs);
- AppendCreateValidation(sb);
+ AppendCreateValidation(sb, readOnlyRequired);
AppendCreateVoValidation(sb, voFields, mapVoFields);
AppendCreateAutoSet(sb, autoSetFields);
AppendCreatePersist(sb, dbSet, createdExpr, reRead, credentials ?? []);
@@ -1256,11 +1270,23 @@ private static void AppendJsonOptsLocal(StringBuilder sb)
// bound `input` and rejects a violating body with the cross-port {error:"validation"}
// envelope BEFORE the row is persisted (ASP.NET minimal-API model binding never runs
// DataAnnotations on its own). Assumes the bound local `input` is in scope.
- private static void AppendCreateValidation(StringBuilder sb)
+ // A violation naming only a @required readOnly member ()
+ // is ignored: the client cannot set that member, so it cannot satisfy the rule.
+ private static void AppendCreateValidation(StringBuilder sb, IReadOnlyList? readOnlyRequired = null)
{
sb.AppendLine(" var __vr = new System.Collections.Generic.List();");
sb.AppendLine(" if (!System.ComponentModel.DataAnnotations.Validator.TryValidateObject(");
- sb.AppendLine(" input, new System.ComponentModel.DataAnnotations.ValidationContext(input), __vr, true))");
+ if (readOnlyRequired is null || readOnlyRequired.Count == 0)
+ {
+ sb.AppendLine(" input, new System.ComponentModel.DataAnnotations.ValidationContext(input), __vr, true))");
+ }
+ else
+ {
+ var names = string.Join(", ", readOnlyRequired.Select(n => "\"" + n + "\""));
+ sb.AppendLine(" input, new System.ComponentModel.DataAnnotations.ValidationContext(input), __vr, true)");
+ sb.AppendLine($" && __vr.Exists(r => !System.Linq.Enumerable.Any(r.MemberNames)");
+ sb.AppendLine($" || System.Linq.Enumerable.Any(r.MemberNames, m => System.Array.IndexOf(new[] {{ {names} }}, m) < 0)))");
+ }
sb.AppendLine(" return Results.BadRequest(new { error = \"validation\" });");
}
@@ -1491,7 +1517,8 @@ private static void AppendTphSubtypeRoutes(
CreatedResult("prefix + \"/" + subRoute + "/\" + input." + pkProp, "input", credentials), [], mapVoFields, autoSetFields,
parseBody: HasDecimalField(st.Entity),
deniedNavs: deniedFields.Select(f => CSharpNaming.Pascal(f.Name)).ToList(), credentials: credentials,
- serverOwned: ServerOwnedCreateResets(st.Entity, root, discProp, hierarchy[0]));
+ serverOwned: ServerOwnedCreateResets(st.Entity, root, discProp, hierarchy[0]),
+ readOnlyRequired: RequiredReadOnlyProps(st.Entity));
// Per-subtype update (PATCH + PUT): partial merge of the JSON body onto the scoped
// entity, NEVER touching the PK or the discriminator. Cross-subtype id → 404.
diff --git a/server/java/codegen-spring/src/main/java/com/metaobjects/generator/spring/SpringControllerGenerator.java b/server/java/codegen-spring/src/main/java/com/metaobjects/generator/spring/SpringControllerGenerator.java
index 5d137a3a77..14c28fe19f 100644
--- a/server/java/codegen-spring/src/main/java/com/metaobjects/generator/spring/SpringControllerGenerator.java
+++ b/server/java/codegen-spring/src/main/java/com/metaobjects/generator/spring/SpringControllerGenerator.java
@@ -1605,7 +1605,9 @@ private static List serverOwnedOnCreate(MetaObject entity) {
java.util.Set denied = SpringGeneratorSupport.hierarchyWriteDeniedNames(entity);
List out = new ArrayList<>();
- for (MetaField f : SpringGeneratorSupport.scalarFields(entity)) {
+ // Every DTO component, not only scalars: the create strip (createDeniedNames) nulls a
+ // readOnly / derived value-object jsonb component too, so its @NotNull must be ignored here.
+ for (MetaField f : SpringGeneratorSupport.dtoComponentFields(entity)) {
// #484: a write-denied field is IGNORED on create, so a @NotNull on it describes the
// response shape and must not reject a body that (necessarily) omits it.
if (pkFields.contains(f.getName()) || AutoSetSupport.isAutoSet(f)
diff --git a/server/java/codegen-spring/src/test/java/com/metaobjects/generator/spring/SpringServerOwnedInputCodegenTest.java b/server/java/codegen-spring/src/test/java/com/metaobjects/generator/spring/SpringServerOwnedInputCodegenTest.java
index 0c9395161a..781a28767f 100644
--- a/server/java/codegen-spring/src/test/java/com/metaobjects/generator/spring/SpringServerOwnedInputCodegenTest.java
+++ b/server/java/codegen-spring/src/test/java/com/metaobjects/generator/spring/SpringServerOwnedInputCodegenTest.java
@@ -67,6 +67,24 @@ public class SpringServerOwnedInputCodegenTest extends SharedRegistryTestBase {
}
""";
+ private static final String VO = """
+ {
+ "metadata.root": { "package": "acme::own", "children": [
+ { "object.value": { "name": "Stamp", "children": [
+ { "field.string": { "name": "by" } }
+ ] } },
+ { "object.entity": { "name": "Note", "children": [
+ { "source.rdb": { "@table": "notes" } },
+ { "field.long": { "name": "id" } },
+ { "field.string": { "name": "body" } },
+ { "field.object": { "name": "stamp", "@objectRef": "Stamp", "@storage": "jsonb",
+ "@required": true, "@mutability": "readOnly" } },
+ { "identity.primary": { "name": "pk", "@fields": ["id"], "@generation": "increment" } }
+ ] } }
+ ] }
+ }
+ """;
+
private Path generate(String name, String fixture) throws Exception {
Path gen = tmp.newFolder("gen-" + name).toPath();
MetaDataLoader loader = SpringTestFixtures.loadFixture(tmp.newFolder("ws-" + name).toPath(), name, fixture);
@@ -91,6 +109,17 @@ public void plainCreateDropsTheGeneratedKeyAndReadOnlyField() throws Exception {
assertFalse("assigned key must be kept; saw:\n" + tag, tag.contains("dto = new TagDto("));
}
+ @Test
+ public void aRequiredReadOnlyValueObjectIsNulledAndItsNotNullIgnored() throws Exception {
+ Path gen = generate("vo", VO);
+ String controller = Files.readString(gen.resolve("acme/own/NoteController.java"));
+ assertTrue("readOnly VO component is nulled on create; saw:\n" + controller,
+ controller.contains("dto = new NoteDto(null, dto.body(), null);"));
+ // the strip nulls `stamp`, so its @NotNull must not turn every POST into a 400
+ assertTrue("stamp must be server-owned for create validation; saw:\n" + controller,
+ controller.matches("(?s).*SERVER_OWNED_ON_CREATE = Set\\.of\\([^)]*\"stamp\".*"));
+ }
+
@Test
public void tphCreateDropsKeyDiscriminatorReadOnlyAndSiblingColumns() throws Exception {
Path gen = generate("tph", TPH);
diff --git a/server/typescript/packages/codegen-ts/src/templates/zod-validators.ts b/server/typescript/packages/codegen-ts/src/templates/zod-validators.ts
index abaa2520ba..e21443f213 100644
--- a/server/typescript/packages/codegen-ts/src/templates/zod-validators.ts
+++ b/server/typescript/packages/codegen-ts/src/templates/zod-validators.ts
@@ -386,6 +386,7 @@ export function insertSchemaFields(obj: MetaObject): SchemaFieldShape[] {
* The field SET the `UpdateSchema` accepts — same iteration + skip rules
* as `insertSchemaFields`, but mirroring the UpdateSchema branch of
* `renderZodValidators`:
+ * • a primary-key field is OMITTED, generated or assigned (the URL names the row);
* • a TPH subtype's @discriminator field is OMITTED (clients can't change subtype);
* • @autoSet onCreate fields are OMITTED (creation timestamps are immutable);
* • @autoSet onUpdate fields are present + optional (server fills them);
@@ -524,10 +525,8 @@ export function renderZodValidators(obj: MetaObject, ctx?: RenderContext): Code
// null — a present null CLEARS the column (`.set({field: null})` writes NULL).
// Keyed on required-ness, NOT fieldWillBeOptional: a required-with-@default
// field stays non-nullable so an explicit null on it is a 400 (validation),
- // never a silent clear. PK fields are excluded: their Drizzle column is
- // always not-null, so a nullable Zod type would fail `.set()`'s typecheck
- // (and NOT NULL at runtime) — see primaryKeyFieldNames.
- if (!isRequired(child) && !pkFields.has(child.name)) expr = code`${expr}.nullable()`;
+ // never a silent clear. PK fields never reach this branch (skipped above).
+ if (!isRequired(child)) expr = code`${expr}.nullable()`;
updateFieldLines.push(code` ${child.name}: ${expr}`);
}
}
diff --git a/server/typescript/packages/test-generators/src/templates/zod-validators.ts b/server/typescript/packages/test-generators/src/templates/zod-validators.ts
index 95992cf0c9..1aafe1a916 100644
--- a/server/typescript/packages/test-generators/src/templates/zod-validators.ts
+++ b/server/typescript/packages/test-generators/src/templates/zod-validators.ts
@@ -386,6 +386,7 @@ export function insertSchemaFields(obj: MetaObject): SchemaFieldShape[] {
* The field SET the `UpdateSchema` accepts — same iteration + skip rules
* as `insertSchemaFields`, but mirroring the UpdateSchema branch of
* `renderZodValidators`:
+ * • a primary-key field is OMITTED, generated or assigned (the URL names the row);
* • a TPH subtype's @discriminator field is OMITTED (clients can't change subtype);
* • @autoSet onCreate fields are OMITTED (creation timestamps are immutable);
* • @autoSet onUpdate fields are present + optional (server fills them);
@@ -524,10 +525,8 @@ export function renderZodValidators(obj: MetaObject, ctx?: RenderContext): Code
// null — a present null CLEARS the column (`.set({field: null})` writes NULL).
// Keyed on required-ness, NOT fieldWillBeOptional: a required-with-@default
// field stays non-nullable so an explicit null on it is a 400 (validation),
- // never a silent clear. PK fields are excluded: their Drizzle column is
- // always not-null, so a nullable Zod type would fail `.set()`'s typecheck
- // (and NOT NULL at runtime) — see primaryKeyFieldNames.
- if (!isRequired(child) && !pkFields.has(child.name)) expr = code`${expr}.nullable()`;
+ // never a silent clear. PK fields never reach this branch (skipped above).
+ if (!isRequired(child)) expr = code`${expr}.nullable()`;
updateFieldLines.push(code` ${child.name}: ${expr}`);
}
}
From ab8b258360d8bd525a010ee1504f8adb6c6abd35 Mon Sep 17 00:00:00 2001
From: Doug Mealing
Date: Fri, 13 Nov 2026 13:19:24 -0500
Subject: [PATCH 3/5] no-mistakes(review): apply reviewer inline fixes
---
docs/features/generated-mutations.md | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/docs/features/generated-mutations.md b/docs/features/generated-mutations.md
index 9f3c6bab48..ef3f4a2684 100644
--- a/docs/features/generated-mutations.md
+++ b/docs/features/generated-mutations.md
@@ -71,9 +71,11 @@ never writes a client-sent value for a server-generated primary key (`@generatio
`increment` or `uuid`), a `@mutability: "readOnly"` or `origin.*`-derived field, the TPH
discriminator (a per-subtype route takes the subtype from the URL), a column only a
sibling subtype declares, or (C#) an M:N navigation graph. Each is dropped silently, not
-answered with a 400. An assigned key (no `@generation`) is the caller's on create, and
-on update it is the primary key like any other, so it is left out of the TypeScript
-`UpdateSchema` too. A key the entity does not declare is dropped in TypeScript,
+answered with a 400. An assigned key (no `@generation`) is the caller's on create in
+TypeScript, C#, Java and Python, and on update it is the primary key like any other, so it
+is left out of the TypeScript `UpdateSchema` too. (Kotlin's generated create is the
+exception: it never binds a declared key, assigned or not — `increment` is left to the
+column and a `uuid` key is minted app-side.) A key the entity does not declare is dropped in TypeScript,
C# and Python; in Java and Kotlin that answer belongs to the host's Jackson
`ObjectMapper` (Spring Boot's default ignores it, a plain `ObjectMapper` answers 400).
Gated cross-port by `fixtures/api-contract-conformance/scenarios/input-server-owned-dropped.yaml`
From 24ed0322a205df0d94dbcd05d7b77029bc6b4b2c Mon Sep 17 00:00:00 2001
From: Doug Mealing
Date: Fri, 13 Nov 2026 13:36:56 -0500
Subject: [PATCH 4/5] no-mistakes(review): Kotlin readOnly create fix + C#
reset skip
---
.../ServerOwnedCreateInputTests.cs | 71 ++++++++++++++++
.../Generators/RoutesGenerator.cs | 20 +++--
.../generator/kotlin/KotlinGenUtil.kt | 17 ++--
.../kotlin/KotlinServerOwnedCreateBindTest.kt | 84 +++++++++++++++++++
4 files changed, 179 insertions(+), 13 deletions(-)
create mode 100644 server/java/codegen-kotlin/src/test/kotlin/com/metaobjects/generator/kotlin/KotlinServerOwnedCreateBindTest.kt
diff --git a/server/csharp/MetaObjects.Codegen.Tests/ServerOwnedCreateInputTests.cs b/server/csharp/MetaObjects.Codegen.Tests/ServerOwnedCreateInputTests.cs
index bc3d7dfbef..aba045fa26 100644
--- a/server/csharp/MetaObjects.Codegen.Tests/ServerOwnedCreateInputTests.cs
+++ b/server/csharp/MetaObjects.Codegen.Tests/ServerOwnedCreateInputTests.cs
@@ -83,6 +83,28 @@ public class ServerOwnedCreateInputTests
]}}
""";
+ // A legal way to say "the server owns this": the generated increment key and the TPH
+ // discriminator are themselves @mutability: readOnly. The entity then declares both with
+ // PRIVATE setters (A_readOnly_field_of_every_shape_has_a_private_setter), so a create that
+ // reset them (`input.Id = default!;`) would not compile in the adopter's build — CS0122.
+ private const string ReadOnlyKeyAndDiscriminatorModel = """
+ { "metadata.root": { "package": "acme::input", "children": [
+ { "object.entity": { "name": "Seal", "@discriminator": "kind", "children": [
+ { "source.rdb": { "@table": "seals" } },
+ { "field.long": { "name": "id", "@mutability": "readOnly" } },
+ { "field.enum": { "name": "kind", "@values": ["A", "B"], "@mutability": "readOnly" } },
+ { "field.string": { "name": "label", "@maxLength": 40 } },
+ { "identity.primary": { "@fields": "id", "@generation": "increment" } }
+ ]}},
+ { "object.entity": { "name": "ASeal", "extends": "Seal", "@discriminatorValue": "A", "children": [
+ { "field.int": { "name": "qty" } }
+ ]}},
+ { "object.entity": { "name": "BSeal", "extends": "Seal", "@discriminatorValue": "B", "children": [
+ { "field.string": { "name": "note", "@maxLength": 40 } }
+ ]}}
+ ]}}
+ """;
+
private static string Emit(string model, string generator, string file)
{
var r = new MetaDataLoader().Load([new InMemoryStringSource(model, id: "input.json")]);
@@ -162,4 +184,53 @@ public void Tph_subtype_create_resets_the_key_and_pins_the_discriminator_to_the_
Assert.Contains("input.Kind = default!;", a);
Assert.True(a.IndexOf("input.Kind = default!;", StringComparison.Ordinal) < a.IndexOf(".Add(input);", StringComparison.Ordinal), a);
}
+
+ [Fact]
+ public void A_readOnly_key_and_readOnly_discriminator_get_no_reset_and_the_model_compiles()
+ {
+ // System.Text.Json never binds a private setter, so the resets would be redundant —
+ // and CS0122. Oracle: the Roslyn compile of the generated tree (the adopter's build);
+ // the wrong behavior rejected is `input.Id = default!;` / `input.Kind = default!;`
+ // assigning private-setter properties.
+ var r = new MetaDataLoader().Load([new InMemoryStringSource(ReadOnlyKeyAndDiscriminatorModel, id: "ro-key.json")]);
+ Assert.Empty(r.Errors);
+ var ctx = new GenContext
+ {
+ Entities = r.Root.Objects(),
+ Root = r.Root,
+ Config = new GenConfig { OutDir = "/tmp", Namespace = "Acme.Generated", ColumnNamingStrategy = ColumnNamingStrategy.Literal },
+ };
+ var sources = new EntityGenerator().Generate(ctx)
+ .Concat(new DbContextGenerator().Generate(ctx))
+ .Concat(new FilterAllowlistGenerator().Generate(ctx))
+ .Concat(new RoutesGenerator().Generate(ctx))
+ .ToList();
+ var routes = sources.Single(f => f.Path == "SealRoutes.g.cs").Content;
+ var post = routes[routes.IndexOf("app.MapPost(", StringComparison.Ordinal)..];
+ Assert.DoesNotContain("input.Id = default!;", post);
+ Assert.DoesNotContain("input.Kind = default!;", post);
+
+ var trees = sources
+ .Select(f => CSharpSyntaxTree.ParseText(f.Content, new CSharpParseOptions(LanguageVersion.CSharp12), path: f.Path))
+ .ToList();
+ var paths = new HashSet(StringComparer.OrdinalIgnoreCase);
+ var tpa = (string)AppContext.GetData("TRUSTED_PLATFORM_ASSEMBLIES")!;
+ foreach (var p in tpa.Split(Path.PathSeparator)) if (p.Length > 0) paths.Add(p);
+ paths.Add(typeof(Microsoft.EntityFrameworkCore.DbContext).Assembly.Location);
+ paths.Add(typeof(Microsoft.EntityFrameworkCore.ModelBuilder).Assembly.Location);
+ paths.Add(typeof(Microsoft.EntityFrameworkCore.RelationalDatabaseFacadeExtensions).Assembly.Location);
+ paths.Add(typeof(Microsoft.EntityFrameworkCore.PrimaryKeyAttribute).Assembly.Location);
+ paths.Add(typeof(MetaObjects.Codegen.Runtime.FilterParser).Assembly.Location);
+ var refs = paths.Where(File.Exists)
+ .Select(p => (MetadataReference)MetadataReference.CreateFromFile(p)).ToList();
+ var comp = CSharpCompilation.Create(
+ "ro_key_disc_compile_" + Guid.NewGuid().ToString("N"), trees, refs,
+ new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary));
+ var errors = comp.GetDiagnostics()
+ .Where(d => d.Severity == DiagnosticSeverity.Error)
+ .Select(d => $"{d.Id}: {d.GetMessage()} @ {d.Location}")
+ .ToList();
+ Assert.True(errors.Count == 0,
+ "readOnly key + readOnly discriminator model must compile:\n" + string.Join("\n", errors));
+ }
}
diff --git a/server/csharp/MetaObjects.Codegen/Generators/RoutesGenerator.cs b/server/csharp/MetaObjects.Codegen/Generators/RoutesGenerator.cs
index d072dfc4dc..067bcf96cf 100644
--- a/server/csharp/MetaObjects.Codegen/Generators/RoutesGenerator.cs
+++ b/server/csharp/MetaObjects.Codegen/Generators/RoutesGenerator.cs
@@ -596,6 +596,7 @@ protected virtual EmittedFile GenerateTphRoutes(MetaObject baseEntity, TphPlan t
bool hasItem = pkType is not null;
var discProp = CSharpNaming.Pascal(tph.DiscriminatorField);
+ var discField = baseEntity.FindField(tph.DiscriminatorField);
// #484 — the polymorphic base rows carry every subtype's columns, so a credential declared
// on the base OR on any subtype is omitted from them.
var baseCredentials = CredentialNames(baseEntity)
@@ -707,7 +708,7 @@ protected virtual EmittedFile GenerateTphRoutes(MetaObject baseEntity, TphPlan t
// --- Per-subtype CRUD sets ---
var hierarchy = tph.Subtypes.Select(s => s.Entity).Prepend(baseEntity).ToList();
foreach (var st in tph.Subtypes)
- AppendTphSubtypeRoutes(sb, st, hierarchy, ctx.Root, baseRoute, baseCls, dbSet, pkType!, pkProp!, discProp, ctx.Warn);
+ AppendTphSubtypeRoutes(sb, st, hierarchy, ctx.Root, baseRoute, baseCls, dbSet, pkType!, pkProp!, discProp, discField, ctx.Warn);
}
sb.AppendLine();
@@ -1104,17 +1105,22 @@ private static void AppendCreateServerOwned(StringBuilder sb, IReadOnlyList ServerOwnedCreateResets(MetaObject entity, MetaRoot root, string? discProp = null, MetaObject? navOwner = null)
+ // discriminator base class's — so a subtype route passes that base as navOwner. The key and
+ // discriminator resets are SKIPPED when that field is itself @mutability: readOnly: the entity
+ // declares it with a private setter (EntityGenerator.SetterFor), so the assignment would be
+ // CS0122 — and it is redundant, because System.Text.Json never binds a private setter.
+ private static List ServerOwnedCreateResets(MetaObject entity, MetaRoot root, MetaField? discField = null, MetaObject? navOwner = null)
{
var list = new List();
if (entity.PrimaryIdentity() is MetaPrimaryIdentity pk
&& pk.Generation is MetaObjects.Core.Identity.IdentityConstants.GENERATION_INCREMENT
or MetaObjects.Core.Identity.IdentityConstants.GENERATION_UUID
&& pk.Fields is [var keyName]
- && entity.Fields().FirstOrDefault(f => f.Name == keyName) is { } keyField)
+ && entity.Fields().FirstOrDefault(f => f.Name == keyName) is { } keyField
+ && !keyField.IsReadOnlyMutability)
list.Add($"input.{CSharpNaming.Pascal(keyField.Name)} = default!;");
- if (discProp is not null) list.Add($"input.{discProp} = default!;");
+ if (discField is not null && !discField.IsReadOnlyMutability)
+ list.Add($"input.{CSharpNaming.Pascal(discField.Name)} = default!;");
foreach (var nav in M2MNavigationBuilder.For(navOwner ?? entity, root, _ => { }))
{
var target = CSharpNaming.Pascal(nav.Target.Name);
@@ -1444,7 +1450,7 @@ private static void AppendPartialMergeLoop(
// that never touches the PK or the discriminator.
private static void AppendTphSubtypeRoutes(
StringBuilder sb, TphSubtypePlan st, IReadOnlyList hierarchy, MetaRoot root, string baseRoute, string baseCls, string dbSet,
- string pkType, string pkProp, string discProp, Action onWarn)
+ string pkType, string pkProp, string discProp, MetaField? discField, Action onWarn)
{
// #362 — field.object columns on a TPH subtype stay out of scope (Program D §6), but a
// field.map @objectRef is NOT: it reaches the settable set, so its value objects reach
@@ -1517,7 +1523,7 @@ private static void AppendTphSubtypeRoutes(
CreatedResult("prefix + \"/" + subRoute + "/\" + input." + pkProp, "input", credentials), [], mapVoFields, autoSetFields,
parseBody: HasDecimalField(st.Entity),
deniedNavs: deniedFields.Select(f => CSharpNaming.Pascal(f.Name)).ToList(), credentials: credentials,
- serverOwned: ServerOwnedCreateResets(st.Entity, root, discProp, hierarchy[0]),
+ serverOwned: ServerOwnedCreateResets(st.Entity, root, discField, hierarchy[0]),
readOnlyRequired: RequiredReadOnlyProps(st.Entity));
// Per-subtype update (PATCH + PUT): partial merge of the JSON body onto the scoped
diff --git a/server/java/codegen-kotlin/src/main/kotlin/com/metaobjects/generator/kotlin/KotlinGenUtil.kt b/server/java/codegen-kotlin/src/main/kotlin/com/metaobjects/generator/kotlin/KotlinGenUtil.kt
index 62b74b74fc..7c86b95c55 100644
--- a/server/java/codegen-kotlin/src/main/kotlin/com/metaobjects/generator/kotlin/KotlinGenUtil.kt
+++ b/server/java/codegen-kotlin/src/main/kotlin/com/metaobjects/generator/kotlin/KotlinGenUtil.kt
@@ -655,18 +655,23 @@ public object KotlinGenUtil {
/**
* True when [field] is SERVER-OWNED on create for [obj]: a component of [obj]'s
- * `increment`/`uuid` primary key (the store generates it), or an `@autoSet` column (the
- * CRUD path stamps it, issue #203). The caller never supplies either, so a create body
- * that omits one is correct — the complement of [isAssignedPrimaryKeyField]. Judged
- * against the entity being generated, not `field.parent`: a key idiomatically lives on
- * an abstract base and is inherited through `extends`.
+ * `increment`/`uuid` primary key (the store generates it), an `@autoSet` column (the
+ * CRUD path stamps it, issue #203), or — on an object with a WRITABLE rest surface —
+ * a `readOnly` or derived column (the create SECURITY skip never binds it). The caller
+ * never supplies any of these, so a create body that omits one is correct — the
+ * complement of [isAssignedPrimaryKeyField]. Judged against the entity being
+ * generated, not `field.parent`: a key idiomatically lives on an abstract base and is
+ * inherited through `extends`. A read-only projection keeps its non-null read shape:
+ * it has no create body to relax for.
*
* Mirrors the Java port's `SERVER_OWNED_ON_CREATE` set (SpringControllerGenerator).
*/
fun isServerOwnedOnCreate(field: MetaField<*>, obj: MetaObject): Boolean {
val pk = obj.primaryIdentity
if (pk != null && pk.isAutoGenerated && pk.fields.contains(field.name)) return true
- return autoSetPolicy(field) != null
+ if (autoSetPolicy(field) != null) return true
+ if (!com.metaobjects.generator.util.RestSurfaceGate.isWritable(obj)) return false
+ return isReadOnlyMutability(field) || isDerivedField(field)
}
/**
diff --git a/server/java/codegen-kotlin/src/test/kotlin/com/metaobjects/generator/kotlin/KotlinServerOwnedCreateBindTest.kt b/server/java/codegen-kotlin/src/test/kotlin/com/metaobjects/generator/kotlin/KotlinServerOwnedCreateBindTest.kt
new file mode 100644
index 0000000000..818265220b
--- /dev/null
+++ b/server/java/codegen-kotlin/src/test/kotlin/com/metaobjects/generator/kotlin/KotlinServerOwnedCreateBindTest.kt
@@ -0,0 +1,84 @@
+package com.metaobjects.generator.kotlin
+
+import com.fasterxml.jackson.databind.ObjectMapper
+import com.fasterxml.jackson.module.kotlin.registerKotlinModule
+import com.metaobjects.metadata.ktx.loadString
+import com.tschuchort.compiletesting.KotlinCompilation
+import com.tschuchort.compiletesting.SourceFile
+import jakarta.validation.Validation
+import java.nio.file.Files
+import kotlin.io.path.isRegularFile
+import kotlin.io.path.readText
+import kotlin.test.Test
+import kotlin.test.assertEquals
+import kotlin.test.assertNull
+import kotlin.test.assertTrue
+
+/**
+ * A `@required @mutability: readOnly` field must not make an entity UNCREATABLE (1.2.x):
+ * the create SECURITY skip drops the column from the insert, so the request-body data
+ * class must not demand the value either — nullable, default-null, no `@field:NotNull` —
+ * the same relaxation the generated key and `@autoSet` already get. The cross-port
+ * contract is `docs/features/generated-mutations.md` "Create stores only what a client
+ * may set": a body omitting a server-owned field is CORRECT, never a 400.
+ *
+ * Executes the two boundary stages a real Spring create runs, exactly as
+ * [ValidationConformanceTest] does: Jackson (jackson-module-kotlin, constructor binding)
+ * deserialization of the body onto the COMPILED generated data class, then the jakarta
+ * Validator over the bound instance. The insert-side drop (client value never stored) is
+ * gated by the api-contract `input-server-owned-dropped` scenarios. Oracle: the cross-port
+ * rule above; the wrong behavior rejected is the pre-fix 400 — a missing non-null creator
+ * parameter with no default, or a `@NotNull` violation on the omitted value.
+ */
+@OptIn(org.jetbrains.kotlin.compiler.plugin.ExperimentalCompilerApi::class)
+class KotlinServerOwnedCreateBindTest {
+
+ private val model = """{
+ "metadata.root": { "package": "acme::bind", "children": [
+ { "object.entity": { "name": "Doc", "children": [
+ { "source.rdb": { "@table": "docs" } },
+ { "field.long": { "name": "id" } },
+ { "field.string": { "name": "title", "@required": true, "@maxLength": 100 } },
+ { "field.string": { "name": "role", "@required": true, "@maxLength": 20, "@mutability": "readOnly" } },
+ { "identity.primary": { "@fields": "id", "@generation": "increment" } }
+ ] } }
+ ] }
+ }""".trimIndent()
+
+ @Test
+ fun `create body binds and validates with the readOnly field omitted and present`() {
+ val out = Files.createTempDirectory("kowned-bind-")
+ try {
+ val loader = loadString("owned-bind", model)
+ KotlinEntityGenerator().apply { setArgs(mapOf("outputDir" to out.toString())) }.execute(loader)
+
+ val sources = Files.walk(out).filter { it.isRegularFile() }.sorted().toList()
+ .map { path -> SourceFile.kotlin(path.parent.relativize(path).toString().replace('/', '_'), path.readText()) }
+ val compileResult = KotlinCompilation().apply {
+ this.sources = sources
+ inheritClassPath = true
+ messageOutputStream = System.out
+ }.compile()
+ assertEquals(KotlinCompilation.ExitCode.OK, compileResult.exitCode,
+ "generated Doc.kt failed to compile:\n${compileResult.messages}")
+
+ val docClass = compileResult.classLoader.loadClass("acme.bind.Doc")
+ val mapper = ObjectMapper().registerKotlinModule()
+ val validator = Validation.buildDefaultValidatorFactory().validator
+
+ // Omitted: pre-fix this cannot bind (non-null creator param, no default) → 400.
+ val omitted = mapper.readValue("""{"title":"t"}""", docClass)
+ assertTrue(validator.validate(omitted).isEmpty(), "omitted readOnly field must not be demanded")
+
+ // Present: binds (client value never reaches the insert — api-contract scenario)
+ // and validates; pre-fix the column skip then hit the NOT NULL column → 500.
+ val present = mapper.readValue("""{"title":"t","role":"evil"}""", docClass)
+ assertTrue(validator.validate(present).isEmpty(), "present readOnly value must not be rejected")
+
+ // The omitted binding relaxed the property: nullable, defaulted to null.
+ assertNull(docClass.getMethod("getRole").invoke(omitted))
+ } finally {
+ out.toFile().deleteRecursively()
+ }
+ }
+}
From ff49a2e9b5086fe5e3485ef00c4ecd5bbff9eb48 Mon Sep 17 00:00:00 2001
From: Doug Mealing
Date: Fri, 13 Nov 2026 14:40:39 -0500
Subject: [PATCH 5/5] no-mistakes(document): docs: finish stale corpus counts
from input fix
---
docs/CONFORMANCE.md | 4 ++--
docs/llms/llms-full.txt | 2 +-
docs/llms/llms.txt | 2 +-
3 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/docs/CONFORMANCE.md b/docs/CONFORMANCE.md
index a9a3d02f5e..b464a464a5 100644
--- a/docs/CONFORMANCE.md
+++ b/docs/CONFORMANCE.md
@@ -379,11 +379,11 @@ The corpus also covers the 9 cross-port filter operators (`eq`, `ne`, `gt`,
`gte`, `lt`, `lte`, `in`, `like`, `isNull`) plus the implicit-AND combinator
and 2 error shapes (`invalid_filter_field` / `invalid_filter_op`) under the
URL grammar `?filter[][]=` (FR-009). On top of the 32 core
-scenarios the corpus carries eight sub-corpora — `tph/` (10, single-table
+scenarios the corpus carries eight sub-corpora — `tph/` (12, single-table
inheritance; a subtype decimal filters and refuses extra digits), `m2m/` (9 — 3 plain, 5 gating TPH x M:N together, the combination
each corpus alone could not reach, and 1 pinning the collection-URL spelling),
`jsonb/` (5, typed value-object columns; numbers inside them: a double stays a JSON number, a decimal is the canonical string),
-`write-through/` (2, table-write + view-read entities), `secret-fields/` (2, #484: a `@formExclude` or credential `view.password` field is ignored on create, PATCH and PUT, and a credential is never returned), `projection/` (12, a
+`write-through/` (2, table-write + view-read entities), `secret-fields/` (2, #484 + the 1.2.x input gate: a `@formExclude` or credential `view.password` field is ignored on create, PATCH and PUT, a credential is never returned, and a `@mutability: readOnly` field is ignored on write too), `projection/` (12, a
read-only view answers reads and refuses writes with 405; a projection with no declared
identity has no item route; a projection keyed on a field not named `id` is addressed by
it, whether its identity names `@fields` or derives them; decimal and float fields filter), `decimal/` (11, ADR-0019 Amendment 1: a decimal, array element and undeclared-precision column included, is one
diff --git a/docs/llms/llms-full.txt b/docs/llms/llms-full.txt
index 8cdb51cbc6..a7db61dfcb 100644
--- a/docs/llms/llms-full.txt
+++ b/docs/llms/llms-full.txt
@@ -131,7 +131,7 @@ Today the TypeScript toolchain publishes and TypeScript and Python projects cons
| C# | NuGet `1.2.2` (.NET tool) | Loader + canonical serializer + EF Core + ASP.NET codegen + render/verify. `dotnet meta` tool. |
| Python | PyPI `1.2.1` | Loader + serializer + render + verify + codegen + `ObjectManager` runtime. Fully green across all corpora. |
-Conformance fixtures live at [`fixtures/`](https://github.com/metaobjectsdev/metaobjects/tree/main/fixtures). Every port runs the shared corpus byte-identically: metamodel (`conformance/`, 314 fixtures), render, persistence (Testcontainers Postgres, with an `op: roundtrip` gate so every `field.*` subtype write+read round-trips on every port), api-contract (41 scenarios — 26 core plus TPH / M:N / jsonb / write-through — two lanes: a reference server AND each port's generated API booted over HTTP), registry (byte-matched metamodel-vocabulary manifest, live + green in all five ports), and yaml/verify.
+Conformance fixtures live at [`fixtures/`](https://github.com/metaobjectsdev/metaobjects/tree/main/fixtures). Every port runs the shared corpus byte-identically: metamodel (`conformance/`, 314 fixtures), render, persistence (Testcontainers Postgres, with an `op: roundtrip` gate so every `field.*` subtype write+read round-trips on every port), api-contract (core REST contract + filter operators, plus TPH / M:N / jsonb / write-through and the other sub-corpora — two lanes: a reference server AND each port's generated API booted over HTTP), registry (byte-matched metamodel-vocabulary manifest, live + green in all five ports), and yaml/verify.
---
diff --git a/docs/llms/llms.txt b/docs/llms/llms.txt
index 4bc81990aa..cd6e4a15ec 100644
--- a/docs/llms/llms.txt
+++ b/docs/llms/llms.txt
@@ -45,7 +45,7 @@ This `llms.txt` is the short index; the deep, version-matched how-to is the scaf
## Spec and standard
- [Specification (canonical, target-agnostic)](https://github.com/metaobjectsdev/metaobjects/tree/main/spec): the normative metadata schema and semantics that every implementation must conform to.
-- [Conformance fixtures](https://github.com/metaobjectsdev/metaobjects/tree/main/fixtures): cross-port corpora — `conformance/` (metamodel, 314 fixtures), `render-conformance/`, `persistence-conformance/` (against Testcontainers Postgres, including an `op: roundtrip` gate so every `field.*` subtype write+read round-trips on every port), `api-contract-conformance/` (41 scenarios — 26 core REST contract + filter operators, plus TPH / M:N / jsonb / write-through — run in two lanes: a reference server AND each port's generated API booted over HTTP), `registry-conformance/` (byte-matched metamodel-vocabulary manifest, live + green in all five ports), and `yaml-conformance/` / `verify-conformance/`. Every port runs the shared corpus byte-identically.
+- [Conformance fixtures](https://github.com/metaobjectsdev/metaobjects/tree/main/fixtures): cross-port corpora — `conformance/` (metamodel, 314 fixtures), `render-conformance/`, `persistence-conformance/` (against Testcontainers Postgres, including an `op: roundtrip` gate so every `field.*` subtype write+read round-trips on every port), `api-contract-conformance/` (core REST contract + filter operators, plus TPH / M:N / jsonb / write-through and the other sub-corpora — run in two lanes: a reference server AND each port's generated API booted over HTTP), `registry-conformance/` (byte-matched metamodel-vocabulary manifest, live + green in all five ports), and `yaml-conformance/` / `verify-conformance/`. Every port runs the shared corpus byte-identically.
- [Roadmap](https://github.com/metaobjectsdev/metaobjects/issues?q=is%3Aissue+label%3AFR): current + planned work, tracked as GitHub issues labelled `FR` with milestones per release; [spec/roadmap.md](https://github.com/metaobjectsdev/metaobjects/blob/main/spec/roadmap.md) holds the direction and the index of feature specs.
## The six pillars