Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions conformance/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# Conformance vectors

Language-neutral test data every http-error package must pass, so the same
error produces the same response in every language. Each package's test suite
reads these files directly; a change here runs every language's CI.

## `vectors/problem-details.json`

Three sections:

- **`serialize`**: each case gives an error's `input` data and either the
`expected` response or an `error`.
- `input` members are the error's options: `status`, `message`, `title`,
`detail`, `type`, `instance`, `extensions`, `headers` and `expose`. A
missing member means the option is not set.
- `expected.status` is the response status; `expected.expose` is the error's
`expose` value; `expected.headers` is the complete set of response headers,
names lowercased, one value per name (no case repeats a header);
`expected.body` is the JSON response body. Compare bodies as JSON values:
member order is not significant.
- `error: "invalid status"` means constructing the error must fail.
- **`parse`**: each case gives a response `input` (`status` and the raw `body`
text) and the `expected` error read from it: `status`, `expose`, `title`,
`detail`, `type` and `instance` when present, and the remaining members as
`extensions`. The error's internal message is not pinned.
- **`defaults`**: for every status from 400 to 599, the `title` and `detail`
an error gets when neither is set and its message is not exposed.

The rules the cases pin:

- `status` is an integer from 400 to 599 and defaults to 500.
- `expose` defaults to true for 4xx and false for 5xx.
- `detail` is the explicit `detail` when given, else the `message` when the
error is exposed and the message is not empty, else the status's default.
- An empty string for `title`, `type`, `instance` or `message` counts as not
set, and so does an empty parsed `title` or `detail`.
- An extension named `type`, `status`, `title`, `detail` or `instance` is never
serialized. Any other member, `__proto__` included, is.
- `content-type` defaults to `application/problem+json`.
- Parsing ignores a leading UTF-8 byte-order mark. It takes the body's
`status` when it is a JSON number whose value is an integer from 400 to 599
(`404`, `404.0` and `4.04e2` all count), else the response's status, else
500. A member of the wrong JSON type, or `null`, is ignored.
- A parsed `detail` is the error's message, not an explicit detail: like any
message, it is public only when the error is exposed, so a 5xx problem's
detail is replaced by the default.
- A body that is not a JSON object with a non-null `status`, `title` or `type`
member gives an unexposed error with the default title and detail.
Loading
Loading