validator validate tutorial regular minlength length example regex json schema jsonschema

validate - Usando RegEx en el esquema JSON



json schema validator length (2)

Para probar un valor de cadena (no un nombre de propiedad) contra un RegEx, debe usar la palabra clave "pattern" :

{ "type": "object", "properties": { "progBinaryName": { "type": "string", "pattern": "^[A-Za-z0-9 -_]+_Prog//.(exe|EXE)$" } } }

PD: si desea que el patrón coincida con la clave de la propiedad (no el valor), entonces debe usar "patternProperties" (es como "properties" , pero la clave es un RegEx).

Intentar escribir un esquema JSON que usa RegEx para validar un valor de un elemento.

Tenga un elemento llamado progBinaryName cuyo valor deba cumplir con esta cadena RegEx "^[A-Za-z0-9 -_]+_Prog//.(exe|EXE)$" .

No se pueden encontrar tutoriales o ejemplos que realmente expliquen el uso de RegEx en un esquema JSON.

Cualquier ayuda / información sería muy apreciada!

Gracias: D

JSON SCHEMA

{ "name": "string", "properties": { "progName": { "type": "string", "description": "Program Name", "required": true }, "ID": { "type": "string", "description": "Identifier", "required": true }, "progVer": { "type": "string", "description": "Version number", "required": true }, "progBinaryName": { "type": "string", "description": "Actual name of binary", "patternProperties": { "progBinaryName": "^[A-Za-z0-9 -_]+_Prog//.(exe|EXE)$" }, "required": true } } }

ERRORES:

¡Advertencia! Mejor revisa tu JSON.

La instancia no es un tipo requerido - http://json-schema.org/draft-03/hyper-schema#

El esquema es JSON válido, pero no es un esquema válido.

Resultados de la validación: fallo

[ { "level" : "warning", "schema" : { "loadingURI" : "#", "pointer" : "" }, "domain" : "syntax", "message" : "unknown keyword(s) found; ignored", "ignored" : [ "name" ] }, { "level" : "error", "domain" : "syntax", "schema" : { "loadingURI" : "#", "pointer" : "/properties/ID" }, "keyword" : "required", "message" : "value has incorrect type", "expected" : [ "array" ], "found" : "boolean" }, { "level" : "error", "domain" : "syntax", "schema" : { "loadingURI" : "#", "pointer" : "/properties/progBinaryName" }, "keyword" : "required", "message" : "value has incorrect type", "expected" : [ "array" ], "found" : "boolean" }, { "level" : "error", "schema" : { "loadingURI" : "#", "pointer" : "/properties/progBinaryName/patternProperties/progBinaryName" }, "domain" : "syntax", "message" : "JSON value is not a JSON Schema: not an object", "found" : "string" }, { "level" : "error", "domain" : "syntax", "schema" : { "loadingURI" : "#", "pointer" : "/properties/progName" }, "keyword" : "required", "message" : "value has incorrect type", "expected" : [ "array" ], "found" : "boolean" }, { "level" : "error", "domain" : "syntax", "schema" : { "loadingURI" : "#", "pointer" : "/properties/progVer" }, "keyword" : "required", "message" : "value has incorrect type", "expected" : [ "array" ], "found" : "boolean" } ]

Problem with schema#/properties/progBinaryName/patternProperties/progBinaryName : Instance is not a required type Reported by http://json-schema.org/draft-03/hyper-schema# Attribute "type" (["object"])


Su sintaxis de esquema JSON es incorrecta. Cambio

"patternProperties": { "progBinaryName": "^[A-Za-z0-9 -_]+_Prog//.(exe|EXE)$" }

a

"patternProperties": { "^[A-Za-z0-9 -_]+_Prog//.(exe|EXE)$": {} }