1.6.1 • Published 6 months ago

openapi-sampler v1.6.1

Weekly downloads
171,428
License
MIT
Repository
github
Last release
6 months ago

openapi-sampler

Travis build status Coverage Status Dependency Status devDependency Status

Tool for generation samples based on OpenAPI payload/response schema

Features

  • Deterministic (given a particular input, will always produce the same output)
  • Supports compound keywords: allOf, oneOf, anyOf, if/then/else
  • Supports additionalProperties with x-additionalPropertiesName
  • Uses const, examples, enum and default 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, (limited) pattern
  • Supports the following string formats:
    • email
    • 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)

Installation

Install using npm

npm install openapi-sampler

or using yarn

yarn add 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 in required property of the schema object
    • skipReadOnly - boolean Don't include readOnly object properties
    • skipWriteOnly - boolean Don't include writeOnly object properties
    • quiet - boolean Don't log console warning messages
  • spec - whole specification where the schema is taken from. Required only when schema may contain $ref. spec must not contain any external references

Example

const 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' }
openapi-typescript-node-merged-latest1@agendrix/redoc@yelloan/redocopenapi-typescript-node-sku1@ipublicweb/ipublicweb-count-apiredoc-side_endpointsmarketplace-redocwiddershins-osisoft@redoc/redoc-pro@adaliszk/redoc-extendeddbx-redoc@infinitebrahmanuniverse/nolb-opena@redocly/christi@redocly/redoc-int@everything-registry/sub-chunk-2381@fakeyanss/redoc-zhlane-test@redocly/spot-experimentalswagger-snippetswagger-snippet-wishwiddershinswiddershins-brunomartinspro-devwiddershins-docswiddershins-xwallet-service-tushar-myntrawhispergridvarkes-app-connector-client@codedown/redoc@comet-cli/adapter-openapi@deuex-solutions/redoc@benmarch/redocjak-redockentico-kontent-docs-redockentico-cloud-docs-redoctf-seyna-redoc@arthurparahyba/html-schema-template@arthurparahyba/html-template@asyncapi/react-component@asyncapi/nunjucks-filters@asyncapi/markdown-template@asyncapi/generator-filters@aleung/redoc@barchart/documentation-generator@btodell/asyncapi-react-component@chargeover/redoc1-0-5-hai-aage-dekhte-hein-kya-aat-hai@abios/abios-redoc@ecollect/redoc@flussonic/redoc@emanager/asyncapi-react-component@fuma-docs/openapi@ingoclaro/redoc@kyma-project/asyncapi-react@lagoni/jmeter-template@leoendless/redoc@ioxio/redoc@netronk/gen-openapi@fakeyanss/redoc@kineticdata/redoc@jmendiara/redoc@ilinyhsergey/openapi-codegen@hyperone/cli-ext-root-openapi-generator@incognia/redoc@saasify/redoc@redocly/reference-docs@redocly/spot@redocly/openapi-docs@redocly/mock-server@rmelasavvi/redoc@stardustai/redoc@sctg/openapi-snippetmy-package-yertlemyntra-tushar-petstorenayi-waali-file-mein-krreopenapi3-generatoropenapi3-generator-altopenapi-snippetopenapi-typescript-node-bookstoreopenapi-ui-distotx-redocopenapi-axios-mock-adapteropenapi-codegenopenapi-commanderopenapi-json-mock-serveropenapi-to-nolink-markdownosisoft.widdershinsrosetta-node-sdksample-accekjsdkfjbskf-sdf-oauth2-projectnest-redoc-try-outnestjs-redoc-try-outnestjs-redoc-try-out-extendedpetstore-myntra-tushar-checkpetstore2pizzalol-redocpulsedocsredocredoc-asyncapiredoc-asyncapi-api-docsredoc-etnredoc-extended
1.6.1

6 months ago

1.6.0

7 months ago

1.5.1

1 year ago

1.5.0

1 year ago

1.4.0

2 years ago

1.3.1

2 years ago

1.3.0

3 years ago

1.2.3

3 years ago

1.2.2

3 years ago

1.2.0

3 years ago

1.2.1

3 years ago

1.1.1

4 years ago

1.1.0

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago

1.0.0-beta.18

5 years ago

1.0.0-beta.17

5 years ago

1.0.0-beta.16

5 years ago

1.0.0-beta.15

6 years ago

1.0.0-beta.14

7 years ago

1.0.0-beta.13

7 years ago

1.0.0-beta.12

7 years ago

1.0.0-beta.11

7 years ago

1.0.0-beta.10

7 years ago

1.0.0-beta.9

7 years ago

1.0.0-beta.8

8 years ago

1.0.0-beta.7

8 years ago

1.0.0-beta.6

8 years ago

1.0.0-beta.5

8 years ago

1.0.0-beta.4

8 years ago

1.0.0-beta.3

8 years ago

1.0.0-beta.2

8 years ago

1.0.0-beta.1

8 years ago

1.0.0-beta.0

8 years ago

0.4.3

8 years ago

0.4.2

8 years ago

0.4.1

8 years ago

0.4.0

8 years ago

0.3.3

9 years ago

0.3.2

9 years ago

0.3.1

9 years ago

0.3.0

9 years ago

0.2.0

9 years ago

0.1.2

9 years ago

0.1.1

9 years ago

0.1.0

9 years ago

0.0.3

9 years ago

0.0.2

9 years ago

0.0.1

9 years ago