openapi-sampler
Advanced tools
Comparing version
@@ -570,3 +570,14 @@ (function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.OpenAPISampler = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){ | ||
if (schema && _typeof(schema.properties) === 'object') { | ||
var requiredKeys = Array.isArray(schema.required) ? schema.required : []; | ||
var requiredKeyDict = requiredKeys.reduce(function (dict, key) { | ||
dict[key] = true; | ||
return dict; | ||
}, {}); | ||
Object.keys(schema.properties).forEach(function (propertyName) { | ||
// skip before traverse that could be costly | ||
if (options.skipNonRequired && !requiredKeyDict.hasOwnProperty(propertyName)) { | ||
return; | ||
} | ||
var sample = (0, _traverse.traverse)(schema.properties[propertyName], options, spec); | ||
@@ -573,0 +584,0 @@ if (options.skipReadOnly && sample.readOnly) { |
{ | ||
"name": "openapi-sampler", | ||
"version": "1.0.0-beta.13", | ||
"version": "1.0.0-beta.14", | ||
"description": "Tool for generation samples based on OpenAPI payload/response schema", | ||
@@ -19,3 +19,3 @@ "main": "dist/openapi-sampler.js", | ||
"type": "git", | ||
"url": "https://github.com/APIs-guru/openapi-sampler/openapi-sampler.git" | ||
"url": "https://github.com/APIs-guru/openapi-sampler.git" | ||
}, | ||
@@ -32,5 +32,5 @@ "keywords": [ | ||
"bugs": { | ||
"url": "https://github.com/APIs-guru/openapi-sampler/openapi-sampler/issues" | ||
"url": "https://github.com/APIs-guru/openapi-sampler/issues" | ||
}, | ||
"homepage": "https://github.com/APIs-guru/openapi-sampler/openapi-sampler", | ||
"homepage": "https://github.com/APIs-guru/openapi-sampler/", | ||
"devDependencies": { | ||
@@ -83,4 +83,3 @@ "babel-core": "^6.26.3", | ||
"vinyl-buffer": "^1.0.1", | ||
"vinyl-source-stream": "^2.0.0", | ||
"watchify": "^3.11.0" | ||
"vinyl-source-stream": "^2.0.0" | ||
}, | ||
@@ -87,0 +86,0 @@ "dependencies": { |
@@ -44,2 +44,4 @@ # openapi-sampler | ||
Available options: | ||
- **skipNonRequired** - `boolean` | ||
Don't include non-required object properties not specified in [`required` property of the schema object](https://swagger.io/docs/specification/data-models/data-types/#required) | ||
- **skipReadOnly** - `boolean` | ||
@@ -46,0 +48,0 @@ Don't include `readOnly` object properties |
@@ -5,3 +5,14 @@ import { traverse } from '../traverse'; | ||
if (schema && typeof schema.properties === 'object') { | ||
let requiredKeys = (Array.isArray(schema.required) ? schema.required : []); | ||
let requiredKeyDict = requiredKeys.reduce((dict, key) => { | ||
dict[key] = true; | ||
return dict; | ||
}, {}); | ||
Object.keys(schema.properties).forEach(propertyName => { | ||
// skip before traverse that could be costly | ||
if (options.skipNonRequired && !requiredKeyDict.hasOwnProperty(propertyName)) { | ||
return; | ||
} | ||
const sample = traverse(schema.properties[propertyName], options, spec); | ||
@@ -8,0 +19,0 @@ if (options.skipReadOnly && sample.readOnly) { |
@@ -80,2 +80,15 @@ import { sampleObject} from '../../src/samplers/object'; | ||
}); | ||
it('should skip non-required properties if skipNonRequired=true', () => { | ||
res = sampleObject({ | ||
properties: { | ||
a: {type: 'string'}, | ||
b: {type: 'integer'} | ||
}, | ||
required: ['a'] | ||
}, {skipNonRequired: true}); | ||
expect(res).to.deep.equal({ | ||
a: 'string' | ||
}); | ||
}); | ||
}); |
Sorry, the diff of this file is not supported yet
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
No website
QualityPackage does not have a website.
Found 1 instance in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
332817
6.52%47
-2.08%2100
1.45%0
-100%1
-50%65
3.17%