Repository navigation
Description
When Connexion's request validation rejects a request, FOCA puts the validator's message as detail in the 400 response. This happens with exceptions.validation_details, which is the default. The message comes from jsonschema, via Connexion 2, and quotes the rejected value. For parameters, it also includes the schema. For example, on dev:
- Body
{"age": "abc"}againsttype: integer:"detail": "'abc' is not of type 'integer' - 'age'". - Query
?mode=abcagainstenum: [a, b]:"detail": "'abc' is not one of ['a', 'b']\n\nFailed validating 'enum' in schema:\n {'type': 'string', 'enum': ['a', 'b']}\n\nOn instance:\n 'abc'". - Body with an unexpected key:
"detail": "Additional properties are not allowed ('abc' was unexpected)".
The errors member that FOCA adds says the same without quoting values, e.g., {"detail": "Must be of type integer.", "pointer": "#/age", "code": "invalid-type"}.
Quoting request values back to the caller is unnecessary. It can reflect content into responses and logs of intermediaries, and it shows schema internals. FOCA's own logs already avoid the values (they log the field locations and codes). The only alternative today, validation_details: false, drops detail and errors altogether.
The message is passed through by FOCA (foca/api/validation.py, foca/errors/exceptions.py), so FOCA can fix it without changing Connexion.
Do:
- Add an option to
exceptionsthat replaces the validator's message indetailwith one built from the invalid fields, without values. For example:Invalid fields: #/age (invalid-type). Theerrorsmember stays as it is. - Keep the current behaviour as the default, because apps' tests assert the validator's messages (proTES, cloud-registry). Recommend the option in the docs.
- Tests: body, parameter and unknown-parameter rejections, with the option on and off.
- Docs: the configuration reference for
exceptions, and the migration guide to 0.22.
Acceptance criteria
- With the option set, no
400response from request validation quotes a value of the request indetail. - Without it, responses are unchanged.
- The option is documented, including when to use it.
Activity
fix: name invalid fields in the detail