ajv-validator / ajv-validator/ajv

Question: how to get enum definition values from referenced schema

Abierto
#2,234 0 comentarios 0 reacciones 0 asignados Ver en GitHub
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 are you using? Does the issue happen if you use the latest version?**
8.12.0

**Ajv options object**

```
{ verbose: true }
```

**JSON Schema**

```
const schema = {
$schema: "https://json-schema.org/draft/2020-12/schema",
$id: "main_schema",
title: "Main List",
type: "array",
items: {
type: "object",
properties: {
route: {
type: ["string", "null"],
title: "Route",
description: "Route",
$ref: "shared_schema#/definitions/routes",
}
},
required: ["route"]
}
};

const shared_schema = {
$id: "shared_schema",
title: "MyProject shared values",
definitions: {
routes: {
enum: [
"ROUTE1",
"ROUTE2",
"ROUTE3"
],
errorMessage:
"Route must be an allowed value: ${/definitions.routes.enum.join(', ')}"
}
}
};

```

**Sample data**

```
const data = [{route: "INVALID"}]

```

**Your code**

```
const ajv = ajvError(new Ajv({ verbose: true }));
ajv.addSchema(shared_schema, "shared_schema").compile(shared_schema);
const valid = ajv.validate(schema, data);

```

**Validation result, data AFTER validation, error messages**

```
Route must be an allowed value: undefined

```

**What results did you expect?**
```
Route must be an allowed value: ROUTE1, ROUTE2, ROUTE3
```
**Are you going to resolve the issue?**
```
No
```

I am unable to get list of allowed values. Tried a lot of things, this might now be the correct syntax to get the reference but that's what i want to figure out.

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.