schema-utils
Advanced tools
Comparing version 3.1.2 to 3.2.0
@@ -5,2 +5,9 @@ # Changelog | ||
## [3.2.0](https://github.com/webpack/schema-utils/compare/v3.1.2...v3.2.0) (2023-06-07) | ||
### Features | ||
* implement `undefinedAsNull` keyword for `enum` type ([#176](https://github.com/webpack/schema-utils/issues/176)) ([95826eb](https://github.com/webpack/schema-utils/commit/95826eb9e14bc4b10ab95f962ac2bdca447880a3)) | ||
### [3.1.2](https://github.com/webpack/schema-utils/compare/v3.1.1...v3.1.2) (2023-04-15) | ||
@@ -7,0 +14,0 @@ |
@@ -11,2 +11,3 @@ export type JSONSchema4 = import("json-schema").JSONSchema4; | ||
link?: string | undefined; | ||
undefinedAsNull?: boolean | undefined; | ||
}; | ||
@@ -37,2 +38,3 @@ export type Schema = (JSONSchema4 | JSONSchema6 | JSONSchema7) & Extend; | ||
* @property {string=} link | ||
* @property {boolean=} undefinedAsNull | ||
*/ | ||
@@ -39,0 +41,0 @@ /** @typedef {(JSONSchema4 | JSONSchema6 | JSONSchema7) & Extend} Schema */ |
@@ -16,2 +16,4 @@ "use strict"; | ||
var _undefinedAsNull = _interopRequireDefault(require("./keywords/undefinedAsNull")); | ||
var _ValidationError = _interopRequireDefault(require("./ValidationError")); | ||
@@ -50,4 +52,6 @@ | ||
// Use CommonJS require for ajv libs so TypeScript consumers aren't locked into esModuleInterop (see #110). | ||
const Ajv = require("ajv"); | ||
// eslint-disable-next-line global-require | ||
const Ajv = require("ajv"); // eslint-disable-next-line global-require | ||
const ajvKeywords = require("ajv-keywords"); | ||
@@ -63,2 +67,3 @@ | ||
(0, _absolutePath.default)(ajv); | ||
(0, _undefinedAsNull.default)(ajv); | ||
return ajv; | ||
@@ -81,2 +86,3 @@ }); | ||
* @property {string=} link | ||
* @property {boolean=} undefinedAsNull | ||
*/ | ||
@@ -83,0 +89,0 @@ |
@@ -504,6 +504,12 @@ "use strict"; | ||
if (schema.enum) { | ||
return ( | ||
/** @type {Array<any>} */ | ||
schema.enum.map(item => JSON.stringify(item)).join(" | ") | ||
); | ||
const enumValues = | ||
/** @type {Array<any>} */ | ||
schema.enum.map(item => { | ||
if (item === null && schema.undefinedAsNull) { | ||
return `${JSON.stringify(item)} | undefined`; | ||
} | ||
return JSON.stringify(item); | ||
}).join(" | "); | ||
return `${enumValues}`; | ||
} | ||
@@ -510,0 +516,0 @@ |
{ | ||
"name": "schema-utils", | ||
"version": "3.1.2", | ||
"version": "3.2.0", | ||
"description": "webpack Validation Utils", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
83407
18
1838