1.6.1 • Published 1 year ago

openapi-sampler v1.6.1

Weekly downloads
171,428
License
MIT
Repository
github
Last release
1 year 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-clientjak-redockentico-kontent-docs-redockentico-cloud-docs-redochuma-redoch1-cli-ext-root-openapi-generatorlinks_removed_widdershinsmarketplace-event-tracking-apilp-redoc@whitepages/redoc@varkes/api-server@varkes/app-connector-client@therockstorm/oas-markdown@tibco-software/cli-plugin-asyncapi@tokend/redoc@tkrullmann/redoc@thelias/redoc@up9/redoc@xyd-js/openapi@zalastax/nolb-openaapifireasyncapi-docgenapibook-genericfumadocs-openapidydx-widdershinsechoapi-openapi-docerchoc-redoc@abios/abios-redoc1-0-5-hai-aage-dekhte-hein-kya-aat-hai@btodell/asyncapi-react-component@chargeover/redoc@benmarch/redoc@barchart/documentation-generatordemo-cxcbandwidth-redocaws-simplify@arthurparahyba/html-schema-template@arthurparahyba/html-template@asyncapi/nunjucks-filters@asyncapi/react-component@asyncapi/markdown-template@asyncapi/generator-filters@aleung/redoctf-seyna-redocmy-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-extendedredoc-ld
1.6.1

1 year ago

1.6.0

1 year ago

1.5.1

2 years ago

1.5.0

2 years ago

1.4.0

2 years ago

1.3.1

3 years ago

1.3.0

4 years ago

1.2.3

4 years ago

1.2.2

4 years ago

1.2.0

4 years ago

1.2.1

4 years ago

1.1.1

4 years ago

1.1.0

4 years ago

1.0.1

5 years ago

1.0.0

5 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

8 years ago

1.0.0-beta.11

8 years ago

1.0.0-beta.10

8 years ago

1.0.0-beta.9

8 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

9 years ago

0.4.0

9 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

10 years ago

0.1.1

10 years ago

0.1.0

10 years ago

0.0.3

10 years ago

0.0.2

10 years ago

0.0.1

10 years ago