openapi-enforcer
Advanced tools
Comparing version 1.13.3 to 1.14.0
@@ -7,2 +7,17 @@ # Change Log | ||
## 1.14.0 | ||
### Added | ||
- **Create Random String with Pattern** | ||
- Schemas of type string with a defined pattern did not allow for values to be generated. Now schema's with patterns can be randomly generated. | ||
### Fixed | ||
- **Random Number Generator** | ||
When generating a random number from a schema it was possible that the randomly generated value would not fall within the expected minimum / maximum range. This is fixed. | ||
## 1.13.3 | ||
@@ -9,0 +24,0 @@ |
@@ -0,0 +0,0 @@ ;(function () { |
{ | ||
"name": "openapi-enforcer", | ||
"version": "1.13.3", | ||
"version": "1.14.0", | ||
"description": "Library for validating, parsing, and formatting data against open api schemas.", | ||
@@ -52,3 +52,3 @@ "main": "index.js", | ||
"coveralls": "^3.1.0", | ||
"mocha": "^5.2.0", | ||
"mocha": "^8.3.0", | ||
"nyc": "^14.1.1" | ||
@@ -58,4 +58,5 @@ }, | ||
"axios": "^0.21.1", | ||
"json-schema-ref-parser": "^6.1.0" | ||
"json-schema-ref-parser": "^6.1.0", | ||
"randexp": "^0.5.3" | ||
} | ||
} |
@@ -398,2 +398,3 @@ /** | ||
matches = matches.map(v => v === 'integer' ? 'number' : v); | ||
if (matches.includes('any')) return true; | ||
if (matches.includes(definitionType)) return true; | ||
@@ -400,0 +401,0 @@ |
@@ -673,3 +673,3 @@ /** | ||
type: 'array', | ||
items: 'string', | ||
items: { type: 'string' }, | ||
errors: ({ definition, exception, parent }) => { | ||
@@ -1003,2 +1003,6 @@ const additionalProperties = parent.definition.additionalProperties; | ||
if (names.length === 1) result.discriminator = names[0]; | ||
// if (names.length === 1) result.discriminator = { | ||
// propertyName: names[0], | ||
// mapping: mappings | ||
// }; | ||
if (names.length > 1) exception.message('Unable to merge multiple discriminator values into one'); | ||
@@ -1209,2 +1213,5 @@ if (mappingConflicts.length > 0) exception.message('Conflicting discriminator mappings attempt to map different values to same name'); | ||
function serializeSchema (schema, exception, dataTypes, serializedSchemas) { | ||
if (schema.pattern) { | ||
schema.pattern = schema.pattern.source; | ||
} | ||
if (!serializedSchemas) { | ||
@@ -1211,0 +1218,0 @@ serializedSchemas = [schema]; |
@@ -18,2 +18,3 @@ /** | ||
'use strict'; | ||
const RandExp = require("randexp"); | ||
const util = require('../util'); | ||
@@ -168,4 +169,18 @@ | ||
const multipleOf = schema.hasOwnProperty('multipleOf') ? schema.multipleOf : 0; | ||
const min = schema.hasOwnProperty('minimum') ? schema.minimum : -1 * Math.floor(options.numberVariation * .25); | ||
const max = schema.hasOwnProperty('maximum') ? schema.maximum : Math.ceil(options.numberVariation * .75); | ||
const hasMin = schema.hasOwnProperty('minimum') | ||
const hasMax = schema.hasOwnProperty('maximum') | ||
let min, max; | ||
if (hasMin && !hasMax) { | ||
min = schema.minimum | ||
max = min + options.numberVariation | ||
} else if (!hasMin && hasMax) { | ||
max = schema.maximum | ||
min = max - options.numberVariation | ||
} else if (hasMin && hasMax) { | ||
min = schema.minimum | ||
max = schema.maximum | ||
} else { | ||
min = -1 * Math.floor(options.numberVariation * .25); | ||
max = Math.ceil(options.numberVariation * .75); | ||
} | ||
parent[property] = randomNumber({min, max, multipleOf, exclusiveMin, exclusiveMax, decimalPlaces}); | ||
@@ -175,3 +190,3 @@ | ||
if (schema.hasOwnProperty('pattern')) { | ||
warn.message('Cannot generate random value that matches a pattern'); | ||
parent[property] = new RandExp(schema.pattern).gen(); | ||
} else { | ||
@@ -178,0 +193,0 @@ const options = {}; |
@@ -420,2 +420,4 @@ /** | ||
if (max < min) throw Error('Maximum value must be greater than or equal to minimum value') | ||
if (isNumber(multipleOf) && multipleOf > 0) { | ||
@@ -428,5 +430,6 @@ const modMin = min % multipleOf; | ||
const index = Math.round(Math.random() * (max - min) / multipleOf); | ||
return index * multipleOf; | ||
let index = Math.round(Math.random() * (max - min) / multipleOf); | ||
return (index + min) * multipleOf; | ||
} else { | ||
@@ -433,0 +436,0 @@ const multiplier = minIsNumber && maxIsNumber ? max - min : spread; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
1508532
20561
3
+ Addedrandexp@^0.5.3
+ Addeddrange@1.1.1(transitive)
+ Addedrandexp@0.5.3(transitive)
+ Addedret@0.2.2(transitive)