ajv-validator / ajv-validator/ajv

Support OpenAPI 3.0 `discriminator.mapping`

オープン
#2,003 コメント 10 件 リアクション 7 件 担当者 0 名 GitHub で見る
enhancement
主要言語
TypeScript
スター
14.8k
フォーク
1k
PR マージ指標
30日以内にマージされた PR はありません

説明

**What version of Ajv you are you using?**

8.11.0

**What problem do you want to solve?**

I'd like to validate JSON schema extracted from OpenAPI 3.0 that includes `discriminator.mapping`. Currently having it will make AJV throw a unavoidable `discriminator: mapping is not supported` error. Example code that throws:

```js
import Ajv from "ajv";

const schema = {
type: "object",
properties: {
type: {
type: "string"
},
value: {
oneOf: [
{type: "string"},
{type: "number"},
],
discriminator: {
propertyName: "type",
mapping: {
string: {type: "string"},
number: {type: "number"},
},
},
},
},
};

const ajv = new Ajv({discriminator: true});
const validate = ajv.compile(schema); // Error: discriminator: mapping is not supported
console.info(validate({type: "string", value: "foo"}));
```

**What do you think is the correct solution to problem?**

Either implement `discriminator.mapping` [as described here](https://swagger.io/specification/#discriminator-object) or alternatively gracefully ignore the presence of it so user code can implement this feature itself.

**Will you be able to implement it?**

I could probably make it gracefully ignore the property.

コントリビューションガイド

コントリビューションガイドを開く

評価

この issue はまだ評価されていません。

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。