From 670adcc9ff23814665eb02d13e002c601f416ced Mon Sep 17 00:00:00 2001 From: gal-cohen-payu-gpo Date: Mon, 13 Jan 2025 17:10:50 +0200 Subject: [PATCH 1/2] fix: add readme explanation about ajv coerceTypes configuration --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 7152e81..3b32e21 100644 --- a/README.md +++ b/README.md @@ -160,7 +160,7 @@ Arguments, options and response are the same as for the `buildSchemaSync` method - Objects - it is important to set any objects with the property `type: object` inside your swagger file, although it isn't a must in the Swagger (OpenAPI) spec in order to validate it accurately with [ajv](https://www.npmjs.com/package/ajv) it must be marked as `object` - Response validator does not support readOnly attribute - +- The Ajv flag `coerceTypes: "array"` enables type coercion for fields defined as arrays in the schema. It will attempt to parse values into arrays when possible (e.g., `1` → `[1]`, `"[1,2,3]"` → `[1,2,3]`). ## Open api 3 - known issues - supporting inheritance with discriminator , only if the ancestor object is the discriminator. - The discriminator supports in the inheritance chain stop when getting to a child with no discriminator (a leaf in the inheritance tree), meaning a leaf can't have a field which starts a new inheritance tree. From 209b9e3eb09c52dd84a548e2d59e37aca7c6d016 Mon Sep 17 00:00:00 2001 From: gal-cohen-payu-gpo Date: Mon, 13 Jan 2025 20:25:26 +0200 Subject: [PATCH 2/2] fix: add readme explanation about ajv coerceTypes configuration --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 3b32e21..abf0290 100644 --- a/README.md +++ b/README.md @@ -160,7 +160,7 @@ Arguments, options and response are the same as for the `buildSchemaSync` method - Objects - it is important to set any objects with the property `type: object` inside your swagger file, although it isn't a must in the Swagger (OpenAPI) spec in order to validate it accurately with [ajv](https://www.npmjs.com/package/ajv) it must be marked as `object` - Response validator does not support readOnly attribute -- The Ajv flag `coerceTypes: "array"` enables type coercion for fields defined as arrays in the schema. It will attempt to parse values into arrays when possible (e.g., `1` → `[1]`, `"[1,2,3]"` → `[1,2,3]`). +- It uses the Ajv `coerceTypes: "array"` flag, which enables type coercion for fields defined as arrays in the schema. This means values will be automatically parsed into arrays when possible. For example, `1` becomes `[1]`, and `"[1,2,3]"` becomes `[1, 2, 3]`. ## Open api 3 - known issues - supporting inheritance with discriminator , only if the ancestor object is the discriminator. - The discriminator supports in the inheritance chain stop when getting to a child with no discriminator (a leaf in the inheritance tree), meaning a leaf can't have a field which starts a new inheritance tree.