Scenario:
- The OpenAPI spec denotes a
requestBodywith multiple composite "datum" fields that have a commonDatumschema also defined in the OpenAPI spec (there are three of these in my example). - The
Datumschema has fieldsvalue(of typenumber) andunit(of type enum defined in the OpenAPI spec). - The example repo for this is here: https://github.com/markgreenwood/openapi-backend-validation-bug
Expected:
- A composite field that fails to validate should report an error with
instancePathandschemaPaththat both reflect that field's identity (i.e. contain the name of the invalid field). - If multiple fields fail validation, there should be multiple errors that each contain the information described above.
Actual:
- If any fields using the
Datumschema OTHER than the first one in the spec are provided non-numeric values, the error'sschemaPathreports validation failure with the name of the FIRST field listed that uses theDatumschema, not the one that actually failed validation. (In the example, ifweightis provided a non-numeric value, theschemaPathincorrectly reportsdistanceas the culprit that failed validation.) - If multiple fields fail validation, the errors array only contains one error, not all the ones that failed to validate. (In one of the example tests, both
weightandtemperatureare provided non-numeric values, but only one error is reported and itsschemaPathincorrectly reportsdistanceas being invalid.)
Steps to reproduce:
- Clone or fork the example repo, install dependencies with
npm ci, and then runapi.test.tsusingnpm run test. Two of the tests describing the expected behavior above should fail.
- Clone the repository.
- Run the
api.test.ts(executenpm run test). - Two of the tests describing the expected behavior will fail.