:capital_abcd: Tool for generation samples based on OpenAPI(fka Swagger) payload/response schema
Tool for generation samples based on OpenAPI payload/response schema
allOf
, oneOf
, anyOf
, if/then/else
additionalProperties
with x-additionalPropertiesName
const
, examples
, enum
and default
where possible - in this ordercontains
, minItems
, maxItems
, and tuples (items
as an array)minLength
, maxLength
, min
, max
, exclusiveMinimum
, exclusiveMaximum
, (limited) pattern
string
formats:
$ref
resolvingInstall using npm
npm install openapi-sampler
or using yarn
yarn add openapi-sampler
Then require it in your code:
var OpenAPISampler = require('openapi-sampler');
OpenAPISampler.sample(schema, [options], [spec])
object
An OpenAPI Schema Object or a JSON Schema Draft 7 document.object
Available options:
boolean
Don't include non-required object properties not specified in required
property of the schema object
boolean
Don't include readOnly
object propertiesboolean
Don't include writeOnly
object propertiesboolean
Don't log console warning messages$ref
. spec must not contain any external referencesconst OpenAPISampler = require('.');
OpenAPISampler.sample({
type: 'object',
properties: {
a: {type: 'integer', minimum: 10},
b: {type: 'string', format: 'password', minLength: 10},
c: {type: 'boolean', readOnly: true}
}
}, {skipReadOnly: true});
// { a: 10, b: 'pa$$word_q' }