ajv-validator / ajv-validator/ajv

Support for 'readyOnly'

Abierto
#2,097 4 comentarios 7 reacciones 0 asignados Ver en GitHub
enhancement
Lenguaje dominante
TypeScript
Estrellas
14.8k
Forks
1k
Métricas de merge de PR
Sin PR fusionados en 30 d

Descripción

**What version of Ajv you are you using?**

8.4.0

**What problem do you want to solve?**

json-schema has a `readOnly` property. This is _super handy_ because a really common use-case is for json-schema to describe an entity (lets say 'an article') and that schema to be re-used for both `GET` and `PUT` requests.

But if that schema has an `id` field, you kinda want to omit that on `PUT`. A different option to handle this is to have 2 schemas, or make `id` non-required, but the former is a pain to maintain, and the latter makes it somewhat inaccurate.

The `readOnly` annotation captures this use-case really well, so if there's a way we can tell Ajv: validate, but use the 'readOnly' case, it should remove those properties before validating.

**What do you think is the correct solution to problem?**

Not familiar enough with Ajv internals

**Will you be able to implement it?**

Unlikely =(

Guía de contribución

Abrir la guía de contribución

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.