Incorrect / misleading error information provided when validating request body

Abierto
#730 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
4/5
Tiempo estimado
3-5 días
Aptitud para principiantes
45/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Estancado
Stack tecnológico
node.js, openapi, typescript

Línea de trabajo

Start with the linked example repository: run npm ci and npm run test as described, then inspect api.test.ts and its failing validation cases. Trace how the project validates request bodies against shared Datum schemas and constructs instancePath, schemaPath, and the errors array. Done means failures identify the correct fields and multiple invalid fields produce separate errors.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

Version: 5.10.6

Scenario:

  • The OpenAPI spec denotes a requestBody with multiple composite "datum" fields that have a common Datum schema also defined in the OpenAPI spec (there are three of these in my example).
  • The Datum schema has fields value (of type number) and unit (of type enum defined in the OpenAPI spec).
  • The example repo for this is here: https://github.com/markgreenwood/openapi-backend-validation-bug

Expected behavior:

  • A composite field that fails to validate should report an error with instancePath and schemaPath that 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 behavior:

  • If any fields using the Datum schema OTHER than the first one in the spec are provided non-numeric values, the error's schemaPath reports validation failure with the name of the FIRST field listed that uses the Datum schema, not the one that actually failed validation. (In the example, if weightis provided a non-numeric value, the schemaPath incorrectly reports distance as 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 weight and temperature are provided non-numeric values, but only one error is reported and its schemaPath incorrectly reports distance as being invalid.)

Steps to reproduce:

  • Clone or fork the example repo, install dependencies with npm ci, and then run api.test.ts using npm run test. Two of the tests describing the expected behavior above should fail.
Lenguaje dominante
TypeScript
Estrellas
689
Forks
97
Merge medio
2 h 36 min
PR fusionados (30 d)
11

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de openapistack/openapi-backend

Todos los issues de openapistack/openapi-backend

Issues similares

Más issues de TypeScript

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.