ajv-validator / ajv-validator/ajv

Question: how to get enum definition values from referenced schema

Aperta
#2,234 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub
Lingua principale
TypeScript
Stelle
14.8k
Fork
1k
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

**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.

Guida per i contributori

Apri la guida per i contributori

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.