2.1.4 • Published 11 days ago

@teamteanpm2024/hic-molestias-ipsum v2.1.4

Weekly downloads
-
License
MIT
Repository
github
Last release
11 days ago

OpenAPI-Enforcer

Tools for using the Open API Specification (OAS)

Supports OAS 2.0 (formerly Swagger) and OAS 3.x.x

Features

  • Create an API.
  • Validate your OAS documents.
  • Serialize, deserialize, and validate values against OAS schemas.
  • Identify the operation associated with a request.
  • Parse, deserialize, and validate request parameters.
  • Facilitated response building.
  • Generate random valid values for a schema.
  • Plugin environment for custom document validation and extended functionality including custom data type formats.

Website - @teamteanpm2024/hic-molestias-ipsum.com

Installation

npm install @teamteanpm2024/hic-molestias-ipsum

Examples

Loading and Validating a Document

Use the Enforcer to load and resolve all $ref values and then to validate the complete document.

const Enforcer = require('@teamteanpm2024/hic-molestias-ipsum')

async function run () {
  const [openapi, error, warning] = await Enforcer('./path/to/openapi.yml', {
    fullResult: true
  })
  if (error !== undefined) console.error(error)
  if (warning !== undefined) console.warn(warning)
  if (openapi !== undefined) console.log('Document is valid')
}

run.catch(console.error)

Processing an Incoming Request

const Enforcer = require('@teamteanpm2024/hic-molestias-ipsum')

async function run () {
  // Because we don't specify `fullResult: true`, any errors will throw an exception and
  // warnings will be logged to the console.
  const openapi = await Enforcer('./path/to/openapi.yml')

  // If the request is valid then the req object will contain the parsed and validated request.
  // If it is invalid then the error will contain details about what was wrong with the
  // request and these details are safe to return to the client that made the request.
  const [ req, error ] = openapi.request({
    method: 'POST',
    path: '/tasks',
    // the body should be parsed by a JSON.parse() prior to passing in (if applicable).
    body: { task: 'Buy Milk', quantity: 2 }
  })

  // You can use the req.operation property to look at the properties from your OpenAPI document.
  // A good use of this is to look at the operationId you defined there to determine which path
  // is being used to handle the request.
  if (req.operaton.operationId === 'my-operation-id') {
    // ... additional request processing
  }
}

run.catch(console.error)

Producing a Valid Result

const Enforcer = require('@teamteanpm2024/hic-molestias-ipsum')

async function run () {
  const openapi = await Enforcer('./path/to/openapi.yml')

  const [ req ] = openapi.request({
    method: 'POST',
    path: '/tasks',
    // the body should be parsed by a JSON.parse() prior to passing in (if applicable).
    body: { task: 'Buy Milk', quantity: 2 }
  })

  const body = { id: 1, task: 'Buy Milk', quantity: 2, dateCompleted: null }
  const headers = {}

  // This will validate the response code, body, and headers. It will also correctly serialize
  // the body and headers for sending to the client that made the request. Using this method
  // you'll never send back a response that does not match what your OpenAPI document defines.
  const [ res, error ] = req.response(200, body, headers)
  console.log(res.body, res.headers)
}

run.catch(console.error)
yamllookdiffthrottlestyleiterateflagsomevarfastclonedebuggerECMAScript 2023full-widthautoprefixerisConcatSpreadablepopmotionkoreandefinePropertynegativebusyargvbootstrap cssObject.keysnpmdatafantasy-landpropertieses2015Streamshebangsanitizedragsimpledbcollection.es6Float32Arraytypejson-schemacreateinspectproxytrimRightless cssestreevariables in csseveryloggingregular expressionObject.getPrototypeOfrmdirmoveclass-validatorrfc4122patchjsonpathStyleSheetauthES5accessorsortedindicatorinterruptscopytouchanimationmomentarraysinferenceObject.assignposeelectronjavascriptescapea11yweakmapmixinseslintconfigtypesafefast-copydommake dirastES2022pathmochatrimEndtypescompareapiPromisecoreflatMapjQuerytsmkdirpwarningmatchstringifierUint8ClampedArrayhas-ownshimawsidlevpctoArraycall-boundreducechineseutil.inspectObjectfullwidthtrimLeftreal-timebddutilityRegExp#flagsSetcss lessreadablestreamnativecliwordwrappluginagentmapes2018RegExp.prototype.flagshardlinkscloudformationgesturesequalityiterationbannerreadinputdeterministicmetadataformatpromisesvariablesreact-hooksArray.prototype.flattenreactviewsafemkdirsansicsssnscallbackschemeentriesinternalspeedes8curriedredactchromiumswfconsolenamecolumnsbluebirdWebSocketdirenvfindamazonopenserializevalidatorsortES2016elbhigher-ordertoStringTagendpointes2017ES2021definetapeextendTypeScriptRFC-6455passwordUint32ArraymimetypescloudwatchsetPrototypeOfgetPrototypeOfjasminewaapicore-jsObservablecolumntestingphone[[Prototype]]ReactiveXgetterBigInt64Arraypicomatchprivate dataargumentsuperagentwidthtyped arraycolourcompile lesswritebreakpushmimeflattenES2019sanitizationimmerloadbalancingpolyfillES2020typedxtermnegative zeroiteratorassertjsdomhelperskarmacallbindmacosconstWeakSetdotenvinstallerMapexecbyteaccessibilityrdswebstringifyebssymlinkslockfilemodulesArray.prototype.flatframerbindprototoolsObject.entriesstatelessspinnerelasticachetypanionextensionUint16ArrayURLSearchParamsdirectorytacitwalkingjson-schema-validationsetImmediateavamapreducefast-deep-copydatastructureperformancevalidatergbECMAScript 2019performantsqsfindLastgetintrinsictimeoffsetuuidcloneencryptionnodeqsform-validationhasjsxcharactersvalidvalidationSymbol.toStringTagspinnersFloat64ArrayruntimeTypedArrayletcodesgroupargscensorspringwaitdeepbyteOffsetcallboundgroupBylesscssfolderregular expressionstraverseshamsyntaxerrorES2018hookformfastcopyregularclassnameenumerablecjkbundlingtypedarrayutilvisualpackage managerhooksspecjsonschemajwtsequencestarterECMAScript 3dynamodbwordbreak256getOwnPropertyDescriptorArray.prototype.filterECMAScript 2015upl10nintrinsicfetchRxJSformslintslotlinuxminimalfilterparsingbabelsesconcatMapdebugramdaESnexteventEmitterpackage.jsonassertionquerysigtermbound__proto__emitserializationsettingsfileES3toSorteddependencieseslintpluginoncecontainstypedarraysbufferbabel-coreoutputcollectioncircularinstallqueueobjectcommandercryptoieESrobustgetoptgetES2017reuseAsyncIteratorfunctionalmrutc39typeerrorgradients cssinvarianterror-handlingdataviewwatchlanguagesearchharmonyzeroJSONcloudsearchloges5progressflatemrmime-dbArray.prototype.containsarraybufferchaies-shim APIdatepropertypersistentbuffersquerystringrm -frReflect.getPrototypeOfbrowserlistsharedarraybufferajvcommand-linecolorRxextrasameValueZeroguidpackagesvest.envarktype-0arrayloadingquotecomputed-typeskinesishandlersUint8Arraylengthtesterwritabledescriptiondropexitconnectcharacterredux-toolkitframeworkchromepipeObject.isuser-streamsawesomesaucepromisecode pointssigintlistenersUnderscorecalliamless.jsECMAScript 7bcryptSymbolshellstreams2s3nodejssetterwgetjestArrayefficientfunctionsfastratelimitshrinkwraphttpsHyBifromreact-testing-libraryhttpstylesfpscachedescriptorfunctionlimitedfind-upless compilerasciiprotobufwatchFiletriminternal slotregexpReactiveExtensionsbatchrmlook-upfigletmobileprivatevaluesgradients css3glacierartreadableparserrecursivedescriptorsmergejsrequestjsonfast-deep-cloneesreducerdom-testing-librarysliceownwhichdataViewunicodeasynclimitprototypeconsumeString.prototype.trimtypeoflinkinpositiveECMAScript 2016css variablefastifystreamES2015streamsmakeexpressionArrayBuffer#sliceArray.prototype.flatMapWeakMapcurlargparseworkflowbundlernumberdeepcopyES8tasksyntaxpnpm9optionfseventscloudtraileventDispatcherendermonorepoInt16Arraybrowserreact animationtest@@toStringTagdependency managernopesignalsmatchAllrandomimportfast-clonestyleguidestringenvironmentwalkmatchesbootstrap lessfile systempreserve-symlinks$.extendpoint-freeoptimistbrowserslistpyyamlbeanstalkrangeerrorloggerthroatstylesheetcolorsxssuninstalllinewrapYAMLes-shimsairbnbassertsmodulehasOwnPropertywatchingwindowses-abstractthreechannelgdprCSSlastsymlinkjapanesefindLastIndexremoveemojiqueueMicrotask0prefixstructuredClonelrueventsimportexportwafInt8ArrayassignkeytrimStartparsehashECMAScript 2017ArrayBuffer.prototype.sliceMicrosoftpropobjomitsharedECMAScript 2022io-tsutilitiesimmutableduplexWebSocketsFunction.prototype.namezodauthenticationfssuperstructless mixinscss nestingArray.prototype.findLastTypeBoxECMAScript 6exit-codeawaiteast-asian-widthPushroute53ec2configlazywraptddObject.fromEntriesconfigurablelibphonenumbertelephoneecmascriptfullisresolveBigUint64ArrayparentwatcherhasOwnfpforEachbalancednested csscall-bindES7transpileoperating-systempreprocessortslibponyfilljsdiffincludessideObject.definePropertyURLdayjstakeformattingpuredeep-copycloudfrontclassnamesweaksetECMAScript 2021deleteurlconcatsignal
2.1.4

11 days ago

2.1.3

12 days ago

2.1.2

13 days ago

2.1.1

14 days ago

1.1.1

15 days ago

1.0.1

16 days ago

1.0.0

16 days ago