Package Exports
- @har-sdk/openapi-sampler
- @har-sdk/openapi-sampler/dist/bundle.esm5.js
- @har-sdk/openapi-sampler/dist/bundle.umd.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@har-sdk/openapi-sampler) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
@har-sdk/openapi-sampler
Tool for generation samples based on OpenAPI payload/response schema
Features
- deterministic (given a particular input, will always produce the same output)
- Supports
allOf
- Supports
additionalProperties
- Uses
default
,const
,enum
andexamples
where possible - Full array support: supports
minItems
, and tuples (items
as an array) - Supports
minLength
,maxLength
,min
,max
,exclusiveMinimum
,exclusiveMaximum
- Supports the next
string
formats:- password
- date-time
- date
- ipv4
- ipv6
- hostname
- uri
- Infers schema type automatically following same rules as json-schema-faker
- Support for
$ref
resolving
Installation
Install using npm
npm i --save @har-sdk/openapi-sampler
or using yarn
yarn add @har-sdk/openapi-sampler
Then require it in your code:
import { sample } from '@har-sdk/openapi-sampler';
Usage
sample(schema, [options], [spec])
- schema (required) -
object
A OpenAPI Schema Object - 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 '@har-sdk/openapi-sampler';
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' }