Problem · target: how to find missing required fields in api requests
Negative Tests for Form submission API: What to Assert
User wants to know which fields are required, and to test that omitting them fails.
Direct answer
Invalid payloads slip through because the schema is only used to validate requests, never to produce the negative cases, and Form submission API has 9 constraints that nobody is testing.
This covers contract violations rather than memory-safety bugs, so a fuzzer is still the right tool when the defect class is a parser crash.
The engine rejected the violating row for Form submission API with "CHECK constraint failed: forms_fields_check", which is the error the API should return to the client instead of a success response.
Data as of 2026-11-18 · source: 14 Stack Overflow questions, msw at 128,057,365 monthly downloads · negative-case messages reproduced by executing the fixture against a local SQL engine (Node.js v24.22.0, engine 3.53.4) at 2026-11-18T11:53:54.233Z
What actually goes wrong — Form submission
The failure is rarely a crash. The API accepts the payload, returns 200, and stores a row that violates a rule the schema promised to enforce. For Form submission API, the reference engine rejected the bad row with "NOT NULL constraint failed: forms.key" — that is the message the API should have surfaced to the client instead of a success response.
The four failure modes
Invalid payloads cluster into four families, and the Form submission API fixture exercises all of them. Missing required fields, wrong types, out-of-range values and values outside a declared enum. Each family maps to a distinct engine error, and each family needs a distinct assertion in the test suite.
What the boundary probes look like
For Form submission API, the range probe on forms.fields sits one step outside the boundary. The constraint is "fields" > 0 and the probe value is 0. The engine said "CHECK constraint failed: forms_fields_check". A test that asserts a 4xx response for this value is asserting that the constraint the schema declares is actually enforced at the edge.
The assertion you actually want
Assert on the response code and on the error body, not on the absence of a crash. For the Form submission API fixture, the assertion that catches a regression is a request carrying fields=0, expecting a 4xx status and an error body that names the field. A test that only asserts "the request failed" passes even when the API fails for the wrong reason.
Where a fuzzing tool is the wrong answer
Unstructured fuzzing finds crashes, which is a different job from finding contract violations. For Form submission API, a schema-derived negative set covers the cases a fuzzer would take hours to stumble into, and each one has a deterministic expected response. Reach for a fuzzer when the bug class is a parser crash, not when the bug class is a contract the API forgot to enforce.
| Failure class | Column | SQLSTATE | Error name | Engine message (verbatim) |
|---|---|---|---|---|
| Missing required field | forms.key | 23502 | not_null_violation | NOT NULL constraint failed: forms.key |
| Out-of-contract value | forms.fields | 23514 | check_violation | CHECK constraint failed: forms_fields_check |
| Dangling foreign key | submissions.form_id | 23503 | foreign_key_violation | FOREIGN KEY constraint failed |
| Table | Column | Declared rule | Probe value | Why it is invalid |
|---|---|---|---|---|
| forms | fields | > 0 | 0 | not strictly positive |
npx --yes @wenlu8848/schemaseed validate --input ./prob_forms.openapi.yaml
Download prob_forms.openapi.yaml
openapi: "3.0.3"
info:
title: "Form submission API"
version: "1.0.0"
description: "The payload column is json, so a submission missing a required field is a schema-level invalid instance rather than a SQL error. The fields count is strictly positive, which catches a form defined with no inputs. The form key is unique and is what the public URL resolves against. The foreign key means every submission needs a form row."
paths: {}
x-domain-id: "prob_forms"
x-dialect: "postgres"
components:
schemas:
forms:
type: "object"
x-primary-key: "id"
required: ["id", "key", "fields"]
properties:
id:
type: "string"
format: "uuid"
key:
type: "string"
x-unique: true
fields:
type: "integer"
minimum: 1
submissions:
type: "object"
x-primary-key: "id"
required: ["id", "form_id", "payload", "submitted_at"]
properties:
id:
type: "string"
format: "uuid"
form_id:
$ref: "#/components/schemas/forms"
payload:
type: "object"
submitted_at:
type: "string"
format: "date-time"
Frequently asked questions
- How many invalid cases do I actually need?
- One per constraint class, not one per field. The Form submission API fixture declares its rules across 2 tables and 7 columns, and the table above lists the probe value for each.
- Should I fuzz instead?
- Only for crashes. A schema-derived negative set covers every declaration in Form submission API deterministically, with an expected response for each.
- What status code should the API return?
- Your API decides that, consistently. The generator hands you the violating value and the constraint it breaks — forms.fields on this fixture — so the assertion can name the field.
- Do I need to write the assertions by hand?
- No. The negative instances come from the schema. For Form submission API the first probe is forms.fields = 0, and the engine replied "CHECK constraint failed: forms_fields_check".
Run it against your own schema
SchemaSeed is MIT licensed and free: unlimited local generation, no account, no telemetry and no usage limit. It reads your schema file on your own machine, so nothing is uploaded anywhere. If it saves you time, you can support the project.
Get SchemaSeed — free Support the project
Questions: support@schemaseed.drz8848.win