@jenjenjem/openapi-sampler
v1.0.1
Published
fork of openapi-sampler to apply randexp for string generator
Downloads
4
Maintainers
Readme
openapi-sampler with randexp generator
Fork of openapi-sampler with randexp generator
Features
- Deterministic (given a particular input, will always produce the same output)
- Supports compound keywords:
allOf
,oneOf
,anyOf
,if/then/else
- Supports
additionalProperties
withx-additionalPropertiesName
- Uses
const
,examples
,enum
anddefault
where possible - in this order - Good array support: supports
contains
,minItems
,maxItems
, and tuples (items
as an array) - Supports
minLength
,maxLength
,min
,max
,exclusiveMinimum
,exclusiveMaximum
- Supports the following
string
formats:- idn-email
- password
- date-time
- date
- time
- ipv4
- ipv6
- hostname
- idn-hostname
- uri
- uri-reference
- uri-template
- iri
- iri-reference
- uuid
- json-pointer
- relative-json-pointer
- regex
- Infers schema type automatically following same rules as json-schema-faker
- Support for
$ref
resolving - Has basic supports for JSON Schema draft 7 (thanks to @P0lip from @stoplightio for contributing)
- Supports regex strings through
format: "regex"
andpattern: "/.*/"
pattern
Installation
Install using npm
npm install @thatlook/openapi-sampler --save
or using yarn
yarn add @thatlook/openapi-sampler
Then require it in your code:
var OpenAPISampler = require('openapi-sampler');
Usage
OpenAPISampler.sample(schema, [options], [spec])
- schema (required) -
object
An OpenAPI Schema Object or a JSON Schema Draft 7 document. - options (optional) -
object
Available options:- skipNonRequired -
boolean
Don't include non-required object properties not specified inrequired
property of the schema object - skipReadOnly -
boolean
Don't includereadOnly
object properties - skipWriteOnly -
boolean
Don't includewriteOnly
object properties - quiet -
boolean
Don't log console warning messages
- skipNonRequired -
- spec - whole specification where the schema is taken from. Required only when schema may contain
$ref
. spec must not contain any external references
Example
import { sample } from '@thatlook/@openapi-sampler'
sample({
type: 'object',
properties: {
a: {type: 'integer', minimum: 10},
b: {type: 'string', format: 'password', minLength: 10},
c: {type: 'boolean', readOnly: true},
d: {type: 'string', pattern: '0[xX][0-9a-fA-F]{10}', format: 'regex' }
}
}, {skipReadOnly: true});
// { a: 10, b: 'pa$$word_q', c: true, d: '0x1234567890'}