3.11.97 • Published 1 year ago

@taktikorg/corrupti-commodi v3.11.97

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year 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 - @taktikorg/corrupti-commodi.com

Installation

npm install @taktikorg/corrupti-commodi

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('@taktikorg/corrupti-commodi')

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('@taktikorg/corrupti-commodi')

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('@taktikorg/corrupti-commodi')

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)
reactgenericslrufnmatchArray.prototype.containspackage managerdom-testing-libraryvalidation-0astresolvetouchclirequestschemaprotocol-buffersmonorepofileES2023optimistdescriptorswalklockfileprotoasserttapeHyBipicomatchchromedeepsharedarraybufferio-tses-abstractReactiveExtensionsWeakSetRxJSaccessordynamodb0rssTypeBoxclassnameestreeutilityformatenvironmentpurehasOwnArray.prototype.flatrgbjsreadablestreamfastifytypedarraysendertoArrayfspnpm9sharedES3randoms3Object.definePropertyFloat32Arrayavafastcopycryptodiffebshas-ownsortfindLastIndexclass-validatorBigInt64Arraydatehttpsfpsquerystringa11yshellinspectbundlingdebugtrimEndbabel-coresliceloggingstringifiershammatchesReflect.getPrototypeOfcloudfrontanimationutilitiesstarterObject.fromEntriesdirtoSortedenumerableremoveCSSES6groupBytakeincludescallcreateprototypeglobal objectglobal this valuechineseredirectcircularshebanglocalgetroutingES2020typed arraysinatrainternal slotentriesUint8ArrayArrayBuffer.prototype.sliceairbnbcodestrimStartdropvariablespipeperformantpropsomedeepcopysetenvironmentstsforEachnpmtacitmobilearteast-asian-widthECMAScript 2023dependenciesBigUint64Array@@toStringTagvestECMAScript 5ajvObject.valuesparserbuffer256streamstyletddidentifiersStreamecmascripttranspileres2015efficientfunctionsxtermbyteLengthregularlengthjsonschemaassertionwaitjsonWebSockethelperiteratorwgetsyntaxerrorStreamshasOwnPropertyflagsRxforkdeletedependency managerdatatermttyweakmapreal-timeemrObject.iseslintconfigECMAScript 2022flatMapwidthoncecolorstypeofclientidclassessearchcallbindpoint-freetextkeychaishimspringconcattc39extraspecimmerfast-cloneexpressl10nreducerES2017stringletzxES7directoryWebSocketsmoveArray.prototype.filterpropertyhtmlES2016StyleSheetreuseimportfastcloneSetregular expressionsvpcECMAScript 2019flattenstylingfast-deep-copykoreanaccessibilityregular expressionwarningserializerecursivees-shim APImapdeep-copypathreadponyfillupgetPrototypeOfmatchperformancefastform-validationECMAScriptsesmrupopmotionvaluestransportgroupstyled-componentspackagereducecolumnsbuffersespreeeslintcommandbinduser-streamsawesomesaucegetoptbinbanneroutputes-shimsiamcollection.es6electronJSONroutecommandernpmignoreyupObject.getPrototypeOflistenersYAMLendpointdataViewutilreduxrequirei18nhttpframerstyleguideexecnegativetoolsArrayBufferprivate datafetch
3.11.97

1 year ago

3.10.97

1 year ago

3.10.96

1 year ago

3.10.95

1 year ago

3.10.94

1 year ago

3.10.93

1 year ago

3.10.92

1 year ago

3.10.91

1 year ago

3.9.91

1 year ago

3.9.90

1 year ago

3.8.90

1 year ago

3.8.89

1 year ago

3.8.88

1 year ago

3.8.87

1 year ago

3.8.86

1 year ago

3.8.85

1 year ago

3.8.84

1 year ago

3.7.84

1 year ago

3.7.83

1 year ago

3.7.82

1 year ago

3.7.81

1 year ago

3.7.80

1 year ago

3.7.79

1 year ago

3.6.79

1 year ago

3.6.78

1 year ago

3.6.77

1 year ago

3.6.76

1 year ago

3.6.75

1 year ago

3.6.74

1 year ago

3.6.73

1 year ago

3.6.72

1 year ago

3.6.71

1 year ago

3.6.70

1 year ago

3.6.69

1 year ago

3.6.68

1 year ago

3.6.67

1 year ago

3.6.66

1 year ago

3.6.65

1 year ago

3.6.64

1 year ago

3.6.63

1 year ago

3.5.63

1 year ago

3.5.62

1 year ago

3.5.61

1 year ago

3.5.60

1 year ago

3.5.59

1 year ago

3.5.58

1 year ago

3.5.57

1 year ago

3.5.56

1 year ago

3.5.55

1 year ago

3.5.54

1 year ago

3.4.54

1 year ago

3.4.53

1 year ago

3.4.52

1 year ago

3.4.51

1 year ago

3.4.50

1 year ago

3.4.49

1 year ago

3.4.48

1 year ago

3.4.47

1 year ago

3.4.46

1 year ago

3.4.45

1 year ago

3.4.44

1 year ago

3.4.43

1 year ago

3.3.43

1 year ago

3.3.42

1 year ago

3.3.41

1 year ago

3.3.40

1 year ago

3.3.39

1 year ago

3.3.38

1 year ago

3.3.37

1 year ago

3.3.36

1 year ago

3.3.35

1 year ago

3.3.34

1 year ago

3.3.33

1 year ago

3.3.32

1 year ago

3.3.31

1 year ago

3.3.30

1 year ago

3.3.29

1 year ago

2.3.29

1 year ago

2.3.28

1 year ago

2.3.27

1 year ago

2.3.26

1 year ago

2.2.26

1 year ago

2.2.25

1 year ago

2.1.25

1 year ago

2.1.24

1 year ago

2.1.23

1 year ago

2.1.22

1 year ago

2.1.21

1 year ago

2.1.20

1 year ago

2.1.19

1 year ago

2.1.18

1 year ago

2.1.17

1 year ago

2.1.16

1 year ago

2.1.15

1 year ago

2.1.14

1 year ago

2.1.13

1 year ago

2.1.12

1 year ago

2.1.11

1 year ago

2.1.10

1 year ago

2.1.9

1 year ago

2.1.8

1 year ago

2.1.7

1 year ago

2.1.6

1 year ago

2.1.5

1 year ago

2.1.4

1 year ago

2.0.4

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago