Validation applies invalid default value when using `$ref` and `anyOf`
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 3/5
- Tiempo estimado
- 1-2 días
- Aptitud para principiantes
- 52/100
Línea de trabajo
Start with jsonschema.generate_validator and the default-value handling introduced in commit 66242c398399dc1663dc6874826e61c1d0cac194. Reproduce the issue with the metaschema and string_array_schema shown in the report, then inspect the generated validator around the $ref and anyOf paths. Done means validation no longer inserts items=true into the existing schema and the final validation rejects an empty string.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
I'm using a validator to check my schemas against JSON Schema Draft-07 schema (http://json-schema.org/draft-07/schema), and found that validation method incorrectly applies default to validated table.
Reproduction:
local cjson = require "cjson"
local jsonschema = require "jsonschema"
-- simplified metaschema, stripped so that it contains only elements that generate invalid valdiator code
local metaschema = [[
{
"definitions": {
"schemaArray": {
"type": "array",
"minItems": 1,
"items": { "$ref": "#" }
}
},
"properties": {
"items": {
"anyOf": [
{ "$ref": "#" },
{ "$ref": "#/definitions/schemaArray" }
],
"default": true
}
}
}
]]
local metaschema_validator = jsonschema.generate_validator(cjson.decode(metaschema))
local string_array_schema = {
type = "array",
items = { type = "string", minLength = 1 }
}
print("BEFORE> ", cjson.encode(string_array_schema))
metaschema_validator(string_array_schema)
print("AFTER> ", cjson.encode(string_array_schema))
local string_array_validator = jsonschema.generate_validator(string_array_schema)
print(string_array_validator({ "" }))
Result:
BEFORE> {"items":{"minLength":1,"type":"string"},"type":"array"}
AFTER> {"items":{"items":true,"minLength":1,"type":"string"},"type":"array"}
true
Adding "items":true is invalid here and breaks source schema - it makes it accept invalid inputs (the last output line should say falsefailed to validate item 1: string too short, expected at least 1, got 0).
This error is caused by handing of default values added in https://github.com/api7/jsonschema/commit/66242c398399dc1663dc6874826e61c1d0cac194. Generated code looks like this:
-- we're validating "items" object, i.e. {"minLength":1,"type":"string"}
local propvalue = p_1["items"]
if propvalue ~= nil then
-- nested validation is skipped because there is no nested "items" key
-- ...
end
if propvalue == nil then
-- and here validator breaks valdiated object
p_1["items"] = true
end
- Lenguaje dominante
- Lua
- Estrellas
- 136
- Forks
- 29
- Métricas de merge de PR
- Sin PR fusionados en 30 d
Preparar el entorno
Este proyecto no incluye contenedor de desarrollo, Dockerfile ni guía de contribución, así que la configuración corre por tu cuenta: empieza por su README y consulta nuestra guía para la primera contribución para los pasos generales.
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de api7/jsonschema
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
api7/jsonschema#95 ·
-
Dificultad 3/5 1-2 días Aptitud para principiantes 52/100
api7/jsonschema#105 ·
-
Dificultad 4/5 3-5 días Aptitud para principiantes 20/100
api7/jsonschema#93 ·
-
Dificultad 3/5 1-2 días Aptitud para principiantes 35/100
api7/jsonschema#92 ·
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 42/100
api7/jsonschema#91 ·
Todos los issues de api7/jsonschema
Issues similares
-
clangd_extensions.nvim and alabaster.nvim: "p00f" username now belongs to a different account (repo-jacking risk)Posiblemente ocupada Un pull request vinculado a esta issue está abierto o ya se fusionó. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 85/100
AstroNvim/astrocommunity#1802 ·
-
Bug era/hc Miscellaneous Task
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 64/100
-
engine priority: 3 - wishlist wontfix
Dificultad 1/5 Menos de una hora Aptitud para principiantes 90/100
panel-attack/panel-game#780 ·