Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

287
Vistas
Json Schema: Validating Arrays

I'm trying to validate a schema that includes two keys, tags and parameters, which are intended to be arrays of arbitrary key-value pairs. For some reason, though, I can't get anything I specify for these two keys to fail validation (I'm using the nodejs library ajv).

Here is the schema definition:

var cfStackSchema = {
  name: { type: "string" },
  application: { type: "string" },
  account: { type: "string" },
  environment: { type: "string" },
  tags: { 
    type: "array",
    items: {
      type: "object",
      patternProperties: {
        "^[a-zA-z0-9]$": { type: "string" }
      },
      additionalProperties: false
    },
    additionalItems: false
  },
  parameters: { 
    type: "array",
    items: {
      type: "object",
      patternProperties: {
        "^[a-zA-z0-9]$": { type: "string" }
      },
      additionalProperties: false
    },
    additionalItems: false
  },
  deps: { type: "array", items: { type: "string" } },
  required: ["name", "account", "environment", "parameters", "application"]
};

And here is a test object. I'm passing parameters here as a simple string, intending it to fail validation, but it actually passes:

var spec = { name: "test", 
            account: "test", 
            environment: "test",
            parameters: "test",
            application: "test"
          };

Here is the code I'm using to validate:

  var ajv = new Ajv({ useDefaults: true });
  var validate = ajv.compile(cfStackSchema);
  if (!validate(spec)) {
    throw new Error('Stack does not match schema!')
  }
over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

You just need to put the properties inside of a properties object

var cfStackSchema = {
  properties: {
    name: { type: "string" },
    application: { type: "string" },
    account: { type: "string" },
    environment: { type: "string" },
    tags: { 
      type: "array",
      items: {
        type: "object",
        patternProperties: {
          "^[a-zA-z0-9]$": { type: "string" }
        },
        additionalProperties: false
      },
      additionalItems: false
    },
    parameters: { 
      type: "array",
      items: {
        type: "object",
        patternProperties: {
          "^[a-zA-z0-9]$": { type: "string" }
        },
        additionalProperties: false
      },
      additionalItems: false
    },
    deps: { type: "array", items: { type: "string" } },
  },
  required: ["name", "account", "environment", "parameters", "application"]
};
over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda