1.5.0 • Published 4 days ago

openapi-sampler v1.5.0

Weekly downloads
171,428
License
MIT
Repository
github
Last release
4 days 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-zhpizzalol-redocpulsedocssimplify-codegensimplify-openapirosetta-node-sdkpetstore-myntra-tushar-checkredoc-extendedredoc-ldredoc-linkredoc-mod-libredoc-react18redoc_customredocredoc-asyncapiredoc-asyncapi-api-docsredoc-etntf-seyna-redocsample-accekjsdkfjbskf-sdf-oauth2-projectswagger-snippetswagger-snippet-wishdydx-widdershinsfumadocs-openapimy-package-yertlelp-redoclinks_removed_widdershinslane-testnayi-waali-file-mein-krrenestjs-redoc-try-outnestjs-redoc-try-out-extendedredocnh1-cli-ext-root-openapi-generatorhuma-redockentico-cloud-docs-redockentico-kontent-docs-redocjak-redocmyntra-tushar-petstoreosisoft.widdershinspetstore2openapi3-generatoropenapi3-generator-altopenapi-codegenopenapi-commanderopenapi-axios-mock-adapteropenapi-json-mock-serveropenapi-typescript-node-bookstoreopenapi-ui-distopenapi-to-nolink-markdownopenapi-snippetotx-redoc@fuma-docs/openapi@hyperone/cli-ext-root-openapi-generator@ilinyhsergey/openapi-codegendemo-cxc@ingoclaro/redoc@jmendiara/redoc@kineticdata/redocwallet-service-tushar-myntravarkes-app-connector-clientwiddershinswiddershins-brunomartinspro-devwiddershins-docswiddershins-x@incognia/redoc@ioxio/redoc@leoendless/redoc@kyma-project/asyncapi-react@lagoni/jmeter-template@rmelasavvi/redoc@redocly/reference-docs@redocly/spot@redocly/spot-experimental@redocly/mock-server@redocly/openapi-docs@ecollect/redoc@saasify/redoc@flussonic/redoc@stardustai/redoc@tokend/redoc@synx-ai/oas3-mdx@synx-ai/openapi2md@tkrullmann/redoc@zalastax/nolb-opena@fakeyanss/redoc1-0-5-hai-aage-dekhte-hein-kya-aat-hai
1.5.0

4 days ago

1.4.0

5 months ago

1.3.1

1 year ago

1.3.0

2 years ago

1.2.3

2 years ago

1.2.2

2 years ago

1.2.0

2 years ago

1.2.1

2 years ago

1.1.1

2 years ago

1.1.0

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago

1.0.0-beta.18

4 years ago

1.0.0-beta.17

4 years ago

1.0.0-beta.16

4 years ago

1.0.0-beta.15

5 years ago

1.0.0-beta.14

6 years ago

1.0.0-beta.13

6 years ago

1.0.0-beta.12

6 years ago

1.0.0-beta.11

6 years ago

1.0.0-beta.10

6 years ago

1.0.0-beta.9

6 years ago

1.0.0-beta.8

6 years ago

1.0.0-beta.7

7 years ago

1.0.0-beta.6

7 years ago

1.0.0-beta.5

7 years ago

1.0.0-beta.4

7 years ago

1.0.0-beta.3

7 years ago

1.0.0-beta.2

7 years ago

1.0.0-beta.1

7 years ago

1.0.0-beta.0

7 years ago

0.4.3

7 years ago

0.4.2

7 years ago

0.4.1

7 years ago

0.4.0

7 years ago

0.3.3

7 years ago

0.3.2

8 years ago

0.3.1

8 years ago

0.3.0

8 years ago

0.2.0

8 years ago

0.1.2

8 years ago

0.1.1

8 years ago

0.1.0

8 years ago

0.0.3

8 years ago

0.0.2

8 years ago

0.0.1

8 years ago