codegen: a declared id:integer is server-assigned and out of the create body (#302) - #311
Merged
Merged
Conversation
…ta (#302) docs/ai/00-designing.md promises `omit id` and `declare id:integer` behave identically — both a server-assigned auto-increment pk, out of the create body. Codegen violated its own doc: a declared integer id stayed required in the Model/{Entity}Request, the insert did `id: Set(item.id)`, OpenAPI advertised it as client-writable, and testgen posted it — so `POST` without id got 422. Route the server-assigned decision (synthetic OR declared integer) through one discriminator, `Entity::id_is_server_assigned`, so every surface agrees: - genroute: Model + {Entity}Request drop id (`#[serde(default)]`); insert leaves it `NotSet` (active_sets AND active_sets_pinning) - openapi: a declared integer id is `readOnly` on the component and excluded from the create request schema - testgen: the create probe omits id; the id-echo asserts a server-assigned pk instead of a client value; removed the now-unnecessary tenancy pk-override A declared string/uuid id stays client-supplied (byte-identical, verified). Also fix two stale testgen comments: a same-module FK violation is 422 JC0422 (not 500 JC0510) since #296.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #302 — the anchor of the docs↔codegen conformance sweep.
docs/ai/00-designing.md:155promises 'omit id OR declare it as integer → server-assigned BIGSERIAL, out of the create body.' The generator honored that only for an omitted id; a declaredid: integerleaked into the create body as required client data (id: Set(item.id)), so a client couldn't POST and let the DB assign — and fixed-body bulk create collided on the pk.Fix: one shared discriminator
Entity::id_is_server_assigned()(true for omitted OR declared-integer; false for string/uuid), routed through six codegen sites — model/DTO id-default, bothactive_setsvariants, OpenAPIwalk_schemas+request_schema, and testgen. A server-assigned id is#[serde(default)]/NotSet/readOnlyand dropped from probe bodies;string/uuidpks are byte-identical (verified by scaffolding both and diffing). Deletedtenancy_create_pk_override(the seed-dodge that was masking this green). Also corrected two stale 500-JC0510 testgen comments to 422-JC0422 (#296).585 lib tests + integration/doc pass; 4 golden tests updated to the corrected contract, 1 new test added. No version bump.