## sway
A library that simplifies [OpenAPI](https://www.openapis.org/) integrations.
* [sway](#module_sway)
* [.ApiDefinition](#module_sway.ApiDefinition)
* [new ApiDefinition(definition, definitionRemotesResolved, definitionFullyResolved, references, options)](#new_module_sway.ApiDefinition_new)
* [.getOperation(idOrPathOrReq, [method])](#module_sway.ApiDefinition+getOperation) ⇒ [Operation](#module_sway.Operation)
* [.getOperations([path])](#module_sway.ApiDefinition+getOperations) ⇒ [Array.<Operation>](#module_sway.Operation)
* [.getOperationsByTag([tag])](#module_sway.ApiDefinition+getOperationsByTag) ⇒ [Array.<Operation>](#module_sway.Operation)
* [.getPath(pathOrReq)](#module_sway.ApiDefinition+getPath) ⇒ [Path](#module_sway.Path)
* [.getPaths()](#module_sway.ApiDefinition+getPaths) ⇒ [Array.<Path>](#module_sway.Path)
* [.registerFormat(name, validator)](#module_sway.ApiDefinition+registerFormat)
* [.registerFormatGenerator(name, formatGenerator)](#module_sway.ApiDefinition+registerFormatGenerator)
* [.registerValidator(validator)](#module_sway.ApiDefinition+registerValidator)
* [.unregisterFormat(name)](#module_sway.ApiDefinition+unregisterFormat)
* [.unregisterFormatGenerator(name)](#module_sway.ApiDefinition+unregisterFormatGenerator)
* [.validate()](#module_sway.ApiDefinition+validate) ⇒ [ValidationResults](#module_sway.ValidationResults)
* [.CreateOptions](#module_sway.CreateOptions) : object
* [.DocumentValidationFunction](#module_sway.DocumentValidationFunction) ⇒ [ValidationResults](#module_sway.ValidationResults)
* [.Operation](#module_sway.Operation)
* [new Operation(pathObject, method, definition, definitionFullyResolved, pathToDefinition)](#new_module_sway.Operation_new)
* [.getParameter(name, [location])](#module_sway.Operation+getParameter) ⇒ [Parameter](#module_sway.Parameter)
* [.getParameters()](#module_sway.Operation+getParameters) ⇒ [Array.<Parameter>](#module_sway.Parameter)
* [.getResponse([statusCode])](#module_sway.Operation+getResponse) ⇒ [Response](#module_sway.Response)
* [.getResponses()](#module_sway.Operation+getResponses) ⇒ [Array.<Response>](#module_sway.Response)
* [.getSecurity()](#module_sway.Operation+getSecurity) ⇒ Array.<object>
* [.validateRequest(req, [options])](#module_sway.Operation+validateRequest) ⇒ [ValidationResults](#module_sway.ValidationResults)
* [.validateResponse(res, [options])](#module_sway.Operation+validateResponse) ⇒ [ValidationResults](#module_sway.ValidationResults)
* [.Parameter](#module_sway.Parameter)
* [new Parameter(opOrPathObject, definition, definitionFullyResolved, pathToDefinition)](#new_module_sway.Parameter_new)
* [.getSample()](#module_sway.Parameter+getSample) ⇒ \*
* [.getValue(req)](#module_sway.Parameter+getValue) ⇒ [ParameterValue](#module_sway.ParameterValue)
* [.ParameterValue](#module_sway.ParameterValue)
* [new ParameterValue(parameterObject, raw)](#new_module_sway.ParameterValue_new)
* [.Path](#module_sway.Path)
* [new Path(apiDefinition, path, definition, definitionFullyResolved, pathToDefinition)](#new_module_sway.Path_new)
* [.getOperation(idOrMethod)](#module_sway.Path+getOperation) ⇒ [Array.<Operation>](#module_sway.Operation)
* [.getOperations()](#module_sway.Path+getOperations) ⇒ [Array.<Operation>](#module_sway.Operation)
* [.getOperationsByTag(tag)](#module_sway.Path+getOperationsByTag) ⇒ [Array.<Operation>](#module_sway.Operation)
* [.getParameters()](#module_sway.Path+getParameters) ⇒ [Array.<Parameter>](#module_sway.Parameter)
* [.RequestValidationFunction](#module_sway.RequestValidationFunction) ⇒ [ValidationResults](#module_sway.ValidationResults)
* [.RequestValidationOptions](#module_sway.RequestValidationOptions) : object
* [.Response](#module_sway.Response)
* [new Response(operationObject, statusCode, definition, definitionFullyResolved, pathToDefinition)](#new_module_sway.Response_new)
* [.getExample([mimeType])](#module_sway.Response+getExample) ⇒ string
* [.getSample()](#module_sway.Response+getSample) ⇒ \*
* [.validateResponse(res, [options])](#module_sway.Response+validateResponse) ⇒ [ValidationResults](#module_sway.ValidationResults)
* [.ResponseValidationFunction](#module_sway.ResponseValidationFunction) ⇒ [ValidationResults](#module_sway.ValidationResults)
* [.ResponseValidationOptions](#module_sway.ResponseValidationOptions) : object
* [.ServerResponseWrapper](#module_sway.ServerResponseWrapper) : object
* [.ValidationEntry](#module_sway.ValidationEntry) : object
* [.ValidationResults](#module_sway.ValidationResults) : object
* [.create(options)](#module_sway.create) ⇒ [Promise.<ApiDefinition>](#module_sway.ApiDefinition)
### sway.ApiDefinition
**Kind**: static class of [sway](#module_sway)
**Properties**
| Name | Type | Description |
| --- | --- | --- |
| customFormats | object | The key/value pair of custom formats *(The keys are the format name and the values are async functions. See [ZSchema Custom Formats](https://github.com/zaggino/z-schema#register-a-custom-format))* |
| customFormatGenerators | object | The key/value pair of custom format generators *(The keys are the format name and the values are functions. See [json-schema-mocker Custom Format](https://github.com/json-schema-faker/json-schema-faker#custom-formats))* |
| customValidators | [Array.<DocumentValidationFunction>](#module_sway.DocumentValidationFunction) | The array of custom validators |
| definition | object | The original OpenAPI definition |
| definitionRemotesResolved | object | The OpenAPI definition with only its remote references resolved *(This means all references to external/remote documents are replaced with its dereferenced value but all local references are left unresolved.)* |
| definitionFullyResolved | object | The OpenAPI definition with all of its resolvable references resolved *(This means that all resolvable references are replaced with their dereferenced value.)* |
| documentationUrl | string | The URL to the OpenAPI documentation |
| pathObjects | [Array.<Path>](#module_sway.Path) | The unique `Path` objects |
| options | object | The options passed to the constructor |
| references | object | The reference metadata *(See [JsonRefs~ResolvedRefDetails](https://github.com/whitlockjc/json-refs/blob/master/docs/API.md#module_JsonRefs..ResolvedRefDetails))* |
| version | string | The OpenAPI version |
* [.ApiDefinition](#module_sway.ApiDefinition)
* [new ApiDefinition(definition, definitionRemotesResolved, definitionFullyResolved, references, options)](#new_module_sway.ApiDefinition_new)
* [.getOperation(idOrPathOrReq, [method])](#module_sway.ApiDefinition+getOperation) ⇒ [Operation](#module_sway.Operation)
* [.getOperations([path])](#module_sway.ApiDefinition+getOperations) ⇒ [Array.<Operation>](#module_sway.Operation)
* [.getOperationsByTag([tag])](#module_sway.ApiDefinition+getOperationsByTag) ⇒ [Array.<Operation>](#module_sway.Operation)
* [.getPath(pathOrReq)](#module_sway.ApiDefinition+getPath) ⇒ [Path](#module_sway.Path)
* [.getPaths()](#module_sway.ApiDefinition+getPaths) ⇒ [Array.<Path>](#module_sway.Path)
* [.registerFormat(name, validator)](#module_sway.ApiDefinition+registerFormat)
* [.registerFormatGenerator(name, formatGenerator)](#module_sway.ApiDefinition+registerFormatGenerator)
* [.registerValidator(validator)](#module_sway.ApiDefinition+registerValidator)
* [.unregisterFormat(name)](#module_sway.ApiDefinition+unregisterFormat)
* [.unregisterFormatGenerator(name)](#module_sway.ApiDefinition+unregisterFormatGenerator)
* [.validate()](#module_sway.ApiDefinition+validate) ⇒ [ValidationResults](#module_sway.ValidationResults)
#### new ApiDefinition(definition, definitionRemotesResolved, definitionFullyResolved, references, options)
The OpenAPI Definition object.
**Note:** Do not use directly.
**Extra Properties:** Other than the documented properties, this object also exposes all properties of the
[OpenAPI Object](https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.0.md#openapi-object).
| Param | Type | Description |
| --- | --- | --- |
| definition | object | The original OpenAPI definition |
| definitionRemotesResolved | object | The OpenAPI definition with all of its remote references resolved |
| definitionFullyResolved | object | The OpenAPI definition with all of its references resolved |
| references | object | The location and resolution of the resolved references in the OpenAPI definition |
| options | object | The options passed to ApiDefinition.create |
#### apiDefinition.getOperation(idOrPathOrReq, [method]) ⇒ [Operation](#module_sway.Operation)
Returns the operation for the given path and operation.
**Note:** Below is the list of properties used when `reqOrPath` is an `http.ClientRequest` *(or equivalent)*:
* `method`
* `originalUrl`
* `url`
*(See: [https://nodejs.org/api/http.html#http_class_http_clientrequest](https://nodejs.org/api/http.html#http_class_http_clientrequest))*
**Kind**: instance method of [ApiDefinition](#module_sway.ApiDefinition)
**Returns**: [Operation](#module_sway.Operation) - The `Operation` for the provided operation id, or path and method or `undefined` if
there is no operation for that operation id, or path and method combination
| Param | Type | Description |
| --- | --- | --- |
| idOrPathOrReq | string | object | The OpenAPI operation id, path string or the http client request *(or equivalent)* |
| [method] | string | The OpenAPI operation method _(not used when providing an operation id)_ |
#### apiDefinition.getOperations([path]) ⇒ [Array.<Operation>](#module_sway.Operation)
Returns all operations for the provided path or all operations in the API.
**Kind**: instance method of [ApiDefinition](#module_sway.ApiDefinition)
**Returns**: [Array.<Operation>](#module_sway.Operation) - All `Operation` objects for the provided path or all API operations
| Param | Type | Description |
| --- | --- | --- |
| [path] | string | The OpenAPI path |
#### apiDefinition.getOperationsByTag([tag]) ⇒ [Array.<Operation>](#module_sway.Operation)
Returns all operations for the provided tag.
**Kind**: instance method of [ApiDefinition](#module_sway.ApiDefinition)
**Returns**: [Array.<Operation>](#module_sway.Operation) - All `Operation` objects for the provided tag
| Param | Type | Description |
| --- | --- | --- |
| [tag] | string | The OpenAPI tag |
#### apiDefinition.getPath(pathOrReq) ⇒ [Path](#module_sway.Path)
Returns the path object for the given path or request.
**Note:** Below is the list of properties used when `reqOrPath` is an `http.ClientRequest` *(or equivalent)*:
* `originalUrl`
* `url`
*(See: [https://nodejs.org/api/http.html#http_class_http_clientrequest](https://nodejs.org/api/http.html#http_class_http_clientrequest))*
**Kind**: instance method of [ApiDefinition](#module_sway.ApiDefinition)
**Returns**: [Path](#module_sway.Path) - The corresponding `Path` object for the requested path or request
| Param | Type | Description |
| --- | --- | --- |
| pathOrReq | string | object | The OpenAPI path string or the http client request *(or equivalent)* |
#### apiDefinition.getPaths() ⇒ [Array.<Path>](#module_sway.Path)
Returns all path objects for the OpenAPI definition.
**Kind**: instance method of [ApiDefinition](#module_sway.ApiDefinition)
**Returns**: [Array.<Path>](#module_sway.Path) - The `Path` objects
#### apiDefinition.registerFormat(name, validator)
Registers a custom format.
**Kind**: instance method of [ApiDefinition](#module_sway.ApiDefinition)
| Param | Type | Description |
| --- | --- | --- |
| name | string | The name of the format |
| validator | function | The format validator *(See [ZSchema Custom Format](https://github.com/zaggino/z-schema#register-a-custom-format))* |
#### apiDefinition.registerFormatGenerator(name, formatGenerator)
Registers a custom format generator.
**Kind**: instance method of [ApiDefinition](#module_sway.ApiDefinition)
| Param | Type | Description |
| --- | --- | --- |
| name | string | The name of the format |
| formatGenerator | function | The format generator *(See [json-schema-mocker Custom Format](https://github.com/json-schema-faker/json-schema-faker#custom-formats))* |
#### apiDefinition.registerValidator(validator)
Registers a custom validator.
**Kind**: instance method of [ApiDefinition](#module_sway.ApiDefinition)
**Throws**:
- TypeError If the validator is not a function
| Param | Type | Description |
| --- | --- | --- |
| validator | [DocumentValidationFunction](#module_sway.DocumentValidationFunction) | The validator |
#### apiDefinition.unregisterFormat(name)
Unregisters a custom format.
**Kind**: instance method of [ApiDefinition](#module_sway.ApiDefinition)
| Param | Type | Description |
| --- | --- | --- |
| name | string | The name of the format |
#### apiDefinition.unregisterFormatGenerator(name)
Unregisters a custom format generator.
**Kind**: instance method of [ApiDefinition](#module_sway.ApiDefinition)
| Param | Type | Description |
| --- | --- | --- |
| name | string | The name of the format generator |
#### apiDefinition.validate() ⇒ [ValidationResults](#module_sway.ValidationResults)
Performs validation of the OpenAPI definition.
**Kind**: instance method of [ApiDefinition](#module_sway.ApiDefinition)
**Returns**: [ValidationResults](#module_sway.ValidationResults) - The validation results
### sway.CreateOptions : object
Options used when creating the `ApiDefinition`.
**Kind**: static typedef of [sway](#module_sway)
**Properties**
| Name | Type | Description |
| --- | --- | --- |
| definition | object | string | The OpenAPI definition location or structure |
| jsonRefs | object | *(See [JsonRefs~JsonRefsOptions](https://github.com/whitlockjc/json-refs/blob/master/docs/API.md#module_JsonRefs..JsonRefsOptions))* |
| customFormats | object | The key/value pair of custom formats *(The keys are the format name and the values are async functions. See [ZSchema Custom Formats](https://github.com/zaggino/z-schema#register-a-custom-format))* |
| customFormatGenerators | object | The key/value pair of custom format generators *(The keys are the format name and the values are functions. See [json-schema-mocker Custom Format](https://github.com/json-schema-faker/json-schema-faker#custom-formats))* |
| customValidators | [Array.<DocumentValidationFunction>](#module_sway.DocumentValidationFunction) | The custom validators |
### sway.DocumentValidationFunction ⇒ [ValidationResults](#module_sway.ValidationResults)
Function used for custom validation of OpenAPI documents
**Kind**: static typedef of [sway](#module_sway)
**Returns**: [ValidationResults](#module_sway.ValidationResults) - The validation results
| Param | Type | Description |
| --- | --- | --- |
| apiDefinition | [ApiDefinition](#module_sway.ApiDefinition) | The `ApiDefinition` object |
### sway.Operation
**Kind**: static class of [sway](#module_sway)
**Properties**
| Name | Type | Description |
| --- | --- | --- |
| definition | object | The operation definition *(The raw operation definition __after__ remote references were resolved)* |
| definitionFullyResolved | object | The operation definition with all of its resolvable references resolved |
| method | string | The HTTP method for this operation |
| pathObject | [Path](#module_sway.Path) | The `Path` object |
| pathToDefinition | Array.<string> | The path segments to the operation definition |
| parameterObjects | [Array.<Parameter>](#module_sway.Parameter) | The `Parameter` objects |
| ptr | string | The JSON Pointer to the operation |
| securityDefinitions | object | The security definitions used by this operation |
* [.Operation](#module_sway.Operation)
* [new Operation(pathObject, method, definition, definitionFullyResolved, pathToDefinition)](#new_module_sway.Operation_new)
* [.getParameter(name, [location])](#module_sway.Operation+getParameter) ⇒ [Parameter](#module_sway.Parameter)
* [.getParameters()](#module_sway.Operation+getParameters) ⇒ [Array.<Parameter>](#module_sway.Parameter)
* [.getResponse([statusCode])](#module_sway.Operation+getResponse) ⇒ [Response](#module_sway.Response)
* [.getResponses()](#module_sway.Operation+getResponses) ⇒ [Array.<Response>](#module_sway.Response)
* [.getSecurity()](#module_sway.Operation+getSecurity) ⇒ Array.<object>
* [.validateRequest(req, [options])](#module_sway.Operation+validateRequest) ⇒ [ValidationResults](#module_sway.ValidationResults)
* [.validateResponse(res, [options])](#module_sway.Operation+validateResponse) ⇒ [ValidationResults](#module_sway.ValidationResults)
#### new Operation(pathObject, method, definition, definitionFullyResolved, pathToDefinition)
The OpenAPI Operation object.
**Note:** Do not use directly.
**Extra Properties:** Other than the documented properties, this object also exposes all properties of the
[OpenAPI Operation Object](https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.0.md#operationObject).
| Param | Type | Description |
| --- | --- | --- |
| pathObject | [Path](#module_sway.Path) | The Path object |
| method | string | The operation method |
| definition | object | The operation definition *(The raw operation definition __after__ remote references were resolved)* |
| definitionFullyResolved | object | The operation definition with all of its resolvable references resolved |
| pathToDefinition | Array.<string> | The path segments to the operation definition |
#### operation.getParameter(name, [location]) ⇒ [Parameter](#module_sway.Parameter)
Returns the parameter with the provided name and location when provided.
**Kind**: instance method of [Operation](#module_sway.Operation)
**Returns**: [Parameter](#module_sway.Parameter) - The `Parameter` matching the location and name combination or `undefined` if there
is no match
| Param | Type | Description |
| --- | --- | --- |
| name | string | The name of the parameter |
| [location] | string | The location *(`in`)* of the parameter *(Used for disambiguation)* |
#### operation.getParameters() ⇒ [Array.<Parameter>](#module_sway.Parameter)
Returns all parameters for the operation.
**Kind**: instance method of [Operation](#module_sway.Operation)
**Returns**: [Array.<Parameter>](#module_sway.Parameter) - All `Parameter` objects for the operation
#### operation.getResponse([statusCode]) ⇒ [Response](#module_sway.Response)
Returns the response for the requested status code or the default response *(if available)* if none is provided.
**Kind**: instance method of [Operation](#module_sway.Operation)
**Returns**: [Response](#module_sway.Response) - The `Response` or `undefined` if one cannot be found
| Param | Type | Default | Description |
| --- | --- | --- | --- |
| [statusCode] | number | string | 'default' | The status code |
#### operation.getResponses() ⇒ [Array.<Response>](#module_sway.Response)
Returns all responses for the operation.
**Kind**: instance method of [Operation](#module_sway.Operation)
**Returns**: [Array.<Response>](#module_sway.Response) - All `Response` objects for the operation
#### operation.getSecurity() ⇒ Array.<object>
Returns the composite security definitions for this operation.
The difference between this API and `this.security` is that `this.security` is the raw `security` value for the
operation where as this API will return the global `security` value when available and this operation's security
is undefined.
**Kind**: instance method of [Operation](#module_sway.Operation)
**Returns**: Array.<object> - The security for this operation
#### operation.validateRequest(req, [options]) ⇒ [ValidationResults](#module_sway.ValidationResults)
Validates the request.
**Note:** Below is the list of `req` properties used *(req should be an `http.ClientRequest` or equivalent)*:
* `body`: Used for `body` and `formData` parameters
* `files`: Used for `formData` parameters whose `type` is `file`
* `headers`: Used for `header` parameters and consumes
* `originalUrl`: used for `path` parameters
* `query`: Used for `query` parameters
* `url`: used for `path` parameters
For `path` parameters, we will use the operation's `regexp` property to parse out path parameters using the
`originalUrl` or `url` property.
*(See: [https://nodejs.org/api/http.html#http_class_http_clientrequest](https://nodejs.org/api/http.html#http_class_http_clientrequest))*
**Kind**: instance method of [Operation](#module_sway.Operation)
**Returns**: [ValidationResults](#module_sway.ValidationResults) - The validation results
| Param | Type | Description |
| --- | --- | --- |
| req | object | The http client request *(or equivalent)* |
| [options] | [RequestValidationOptions](#module_sway.RequestValidationOptions) | The validation options |
#### operation.validateResponse(res, [options]) ⇒ [ValidationResults](#module_sway.ValidationResults)
Validates the response.
**Kind**: instance method of [Operation](#module_sway.Operation)
**Returns**: [ValidationResults](#module_sway.ValidationResults) - The validation results
| Param | Type | Description |
| --- | --- | --- |
| res | [ServerResponseWrapper](#module_sway.ServerResponseWrapper) | The response or response like object |
| [options] | [ResponseValidationOptions](#module_sway.ResponseValidationOptions) | The validation options |
### sway.Parameter
**Kind**: static class of [sway](#module_sway)
**Properties**
| Name | Type | Description |
| --- | --- | --- |
| definition | object | The parameter definition *(The raw parameter definition __after__ remote references were resolved)* |
| definitionFullyResolved | object | The parameter definition with all of its resolvable references resolved |
| operationObject | [Operation](#module_sway.Operation) | The `Operation` object the parameter belongs to *(Can be `undefined` for path-level parameters)* |
| pathObject | [Path](#module_sway.Path) | The `Path` object the parameter belongs to |
| pathToDefinition | Array.<string> | The path segments to the parameter definition |
| ptr | string | The JSON Pointer to the parameter definition |
| schema | object | The JSON Schema for the parameter *(For non-body parameters, this is a computed value)* |
* [.Parameter](#module_sway.Parameter)
* [new Parameter(opOrPathObject, definition, definitionFullyResolved, pathToDefinition)](#new_module_sway.Parameter_new)
* [.getSample()](#module_sway.Parameter+getSample) ⇒ \*
* [.getValue(req)](#module_sway.Parameter+getValue) ⇒ [ParameterValue](#module_sway.ParameterValue)
#### new Parameter(opOrPathObject, definition, definitionFullyResolved, pathToDefinition)
The OpenAPI Parameter object.
**Note:** Do not use directly.
**Extra Properties:** Other than the documented properties, this object also exposes all properties of the
[OpenAPI Parameter Object](https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.0.md#parameterObject).
| Param | Type | Description |
| --- | --- | --- |
| opOrPathObject | [Operation](#module_sway.Operation) | [Path](#module_sway.Path) | The `Operation` or `Path` object |
| definition | object | The parameter definition *(The raw parameter definition __after__ remote references were resolved)* |
| definitionFullyResolved | object | The parameter definition with all of its resolvable references resolved |
| pathToDefinition | Array.<string> | The path segments to the parameter definition |
#### parameter.getSample() ⇒ \*
Returns a sample value for the parameter based on its schema;
**Kind**: instance method of [Parameter](#module_sway.Parameter)
**Returns**: \* - The sample value
#### parameter.getValue(req) ⇒ [ParameterValue](#module_sway.ParameterValue)
Returns the parameter value from the request.
**Note:** Below is the list of `req` properties used *(req should be an `http.ClientRequest` or equivalent)*:
* `body`: Used for `body` and `formData` parameters
* `files`: Used for `formData` parameters whose `type` is `file`
* `headers`: Used for `header` parameters
* `originalUrl`: used for `path` parameters
* `query`: Used for `query` parameters
* `url`: used for `path` parameters
For `path` parameters, we will use the operation's `regexp` property to parse out path parameters using the
`originalUrl` or `url` property.
*(See: [https://nodejs.org/api/http.html#http_class_http_clientrequest](https://nodejs.org/api/http.html#http_class_http_clientrequest))*
**Kind**: instance method of [Parameter](#module_sway.Parameter)
**Returns**: [ParameterValue](#module_sway.ParameterValue) - The parameter value object
**Throws**:
- Error If the `in` value of the parameter's schema is not valid or if the `req` property to retrieve the
parameter is missing
| Param | Type | Description |
| --- | --- | --- |
| req | object | The http client request *(or equivalent)* |
### sway.ParameterValue
**Kind**: static class of [sway](#module_sway)
**Properties**
| Name | Type | Description |
| --- | --- | --- |
| error | Error | The error(s) encountered during processing/validating the parameter value |
| parameterObject | [Parameter](#module_sway.Parameter) | The `Parameter` object |
| raw | \* | The original parameter value *(Does not take default values into account)* |
| valid | boolean | Whether or not this parameter is valid based on its JSON Schema |
| value | \* | The processed value *(Takes default values into account and does type coercion when necessary and possible)*. This can the original value in the event that processing the value is impossible *(missing schema type)* or `undefined` if processing the value failed *(invalid types, etc.)*. |
#### new ParameterValue(parameterObject, raw)
Object representing a parameter value.
**Note:** Do not use directly.
| Param | Type | Description |
| --- | --- | --- |
| parameterObject | [Parameter](#module_sway.Parameter) | The `Parameter` object |
| raw | \* | The original/raw value |
### sway.Path
**Kind**: static class of [sway](#module_sway)
**Properties**
| Name | Type | Description |
| --- | --- | --- |
| apiDefinition | [ApiDefinition](#module_sway.ApiDefinition) | The `ApiDefinition` object |
| definition | object | The path definition *(The raw path definition __after__ remote references were resolved)* |
| definitionFullyResolved | object | The path definition with all of its resolvable references resolved |
| operationObjects | [Array.<Operation>](#module_sway.Operation) | The `Operation` objects |
| parameterObjects | [Array.<Parameter>](#module_sway.Parameter) | The path-level `Parameter` objects |
| path | string | The path string |
| pathToDefinition | Array.<string> | The path segments to the path definition |
| ptr | ptr | The JSON Pointer to the path |
| regexp | regexp | The `RegExp` used to match request paths against this path |
* [.Path](#module_sway.Path)
* [new Path(apiDefinition, path, definition, definitionFullyResolved, pathToDefinition)](#new_module_sway.Path_new)
* [.getOperation(idOrMethod)](#module_sway.Path+getOperation) ⇒ [Array.<Operation>](#module_sway.Operation)
* [.getOperations()](#module_sway.Path+getOperations) ⇒ [Array.<Operation>](#module_sway.Operation)
* [.getOperationsByTag(tag)](#module_sway.Path+getOperationsByTag) ⇒ [Array.<Operation>](#module_sway.Operation)
* [.getParameters()](#module_sway.Path+getParameters) ⇒ [Array.<Parameter>](#module_sway.Parameter)
#### new Path(apiDefinition, path, definition, definitionFullyResolved, pathToDefinition)
The Path object.
**Note:** Do not use directly.
**Extra Properties:** Other than the documented properties, this object also exposes all properties of the
[OpenAPI Path Object](https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.0.md#pathItemObject).
| Param | Type | Description |
| --- | --- | --- |
| apiDefinition | [ApiDefinition](#module_sway.ApiDefinition) | The `ApiDefinition` object |
| path | string | The path string |
| definition | object | The path definition *(The raw path definition __after__ remote references were resolved)* |
| definitionFullyResolved | object | The path definition with all of its resolvable references resolved |
| pathToDefinition | Array.<string> | The path segments to the path definition |
#### path.getOperation(idOrMethod) ⇒ [Array.<Operation>](#module_sway.Operation)
Return the operation for this path and operation id or method.
**Kind**: instance method of [Path](#module_sway.Path)
**Returns**: [Array.<Operation>](#module_sway.Operation) - The `Operation` objects for this path and method or `undefined` if there is no
operation for the provided method
| Param | Type | Description |
| --- | --- | --- |
| idOrMethod | string | The operation id or method |
#### path.getOperations() ⇒ [Array.<Operation>](#module_sway.Operation)
Return the operations for this path.
**Kind**: instance method of [Path](#module_sway.Path)
**Returns**: [Array.<Operation>](#module_sway.Operation) - The `Operation` objects for this path
#### path.getOperationsByTag(tag) ⇒ [Array.<Operation>](#module_sway.Operation)
Return the operations for this path and tag.
**Kind**: instance method of [Path](#module_sway.Path)
**Returns**: [Array.<Operation>](#module_sway.Operation) - The `Operation` objects for this path and tag
| Param | Type | Description |
| --- | --- | --- |
| tag | string | The tag |
#### path.getParameters() ⇒ [Array.<Parameter>](#module_sway.Parameter)
Return the parameters for this path.
**Kind**: instance method of [Path](#module_sway.Path)
**Returns**: [Array.<Parameter>](#module_sway.Parameter) - The `Parameter` objects for this path
### sway.RequestValidationFunction ⇒ [ValidationResults](#module_sway.ValidationResults)
Request validation function.
**Kind**: static typedef of [sway](#module_sway)
**Returns**: [ValidationResults](#module_sway.ValidationResults) - The validation results
| Param | Type | Description |
| --- | --- | --- |
| res | [ServerResponseWrapper](#module_sway.ServerResponseWrapper) | The response or response like object |
| def | [Response](#module_sway.Response) | The `Response` definition _(useful primarily when calling `Operation#validateResponse` as `Response#validateResponse` the caller should have access to the `Response` object already.)_ |
### sway.RequestValidationOptions : object
Request validation options.
**Kind**: static typedef of [sway](#module_sway)
**Properties**
| Name | Type | Default | Description |
| --- | --- | --- | --- |
| strictMode | boolean | object | false | Enablement of strict mode validation. If `strictMode` is a `boolean` and is `true`, all form fields, headers and query parameters **must** be defined in the OpenAPI document for this operation. If `strictMode` is an `object`, the keys correspond to the `in` property values of the [OpenAPI Parameter Object](https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.0.md#parameterObject) and its value is a `boolean` that when `true` turns on strict mode validation for the request location matching the key. Valid keys are `formData`, `header` and `query`. _(`body` and `path` are not necessary since `body` strict mode is possible via its schema and `path` is **always** required.)_ |
| customValidators | [RequestValidationFunction](#module_sway.RequestValidationFunction) | | The custom validators |
### sway.Response
**Kind**: static class of [sway](#module_sway)
**Properties**
| Name | Type | Description |
| --- | --- | --- |
| definition | object | The response definition *(The raw responsedefinition __after__ remote references were resolved)* |
| definitionFullyResolved | object | The response definition with all of its resolvable references resolved |
| operationObject | [Operation](#module_sway.Operation) | The Operation object |
| pathToDefinition | Array.<string> | The path segments to the path definition |
| ptr | string | The JSON Pointer to the response definition |
| statusCode | string | The status code |
* [.Response](#module_sway.Response)
* [new Response(operationObject, statusCode, definition, definitionFullyResolved, pathToDefinition)](#new_module_sway.Response_new)
* [.getExample([mimeType])](#module_sway.Response+getExample) ⇒ string
* [.getSample()](#module_sway.Response+getSample) ⇒ \*
* [.validateResponse(res, [options])](#module_sway.Response+validateResponse) ⇒ [ValidationResults](#module_sway.ValidationResults)
#### new Response(operationObject, statusCode, definition, definitionFullyResolved, pathToDefinition)
The OpenAPI Response object.
**Note:** Do not use directly.
**Extra Properties:** Other than the documented properties, this object also exposes all properties of the
[OpenAPI Response Object](https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.0.md#responseObject).
| Param | Type | Description |
| --- | --- | --- |
| operationObject | [Operation](#module_sway.Operation) | The `Operation` object |
| statusCode | string | The status code |
| definition | object | The response definition *(The raw response definition __after__ remote references were resolved)* |
| definitionFullyResolved | object | The response definition with all of its resolvable references resolved |
| pathToDefinition | Array.<string> | The path segments to the path definition |
#### response.getExample([mimeType]) ⇒ string
Returns the response example for the mime-type.
**Kind**: instance method of [Response](#module_sway.Response)
**Returns**: string - The response example as a string or `undefined` if the response code and/or mime-type is missing
| Param | Type | Description |
| --- | --- | --- |
| [mimeType] | string | The mime type |
#### response.getSample() ⇒ \*
Returns a sample value.
**Kind**: instance method of [Response](#module_sway.Response)
**Returns**: \* - The sample value for the response, which can be undefined if the response schema is not provided
#### response.validateResponse(res, [options]) ⇒ [ValidationResults](#module_sway.ValidationResults)
Validates the response.
**Kind**: instance method of [Response](#module_sway.Response)
**Returns**: [ValidationResults](#module_sway.ValidationResults) - The validation results
| Param | Type | Description |
| --- | --- | --- |
| res | [ServerResponseWrapper](#module_sway.ServerResponseWrapper) | The response or response like object |
| [options] | [ResponseValidationOptions](#module_sway.ResponseValidationOptions) | The validation options |
### sway.ResponseValidationFunction ⇒ [ValidationResults](#module_sway.ValidationResults)
Response validation function.
**Kind**: static typedef of [sway](#module_sway)
**Returns**: [ValidationResults](#module_sway.ValidationResults) - The validation results
| Param | Type | Description |
| --- | --- | --- |
| req | object | The http client request *(or equivalent)* |
| op | [Operation](#module_sway.Operation) | The `Operation` object for the request |
### sway.ResponseValidationOptions : object
Response validation options.
**Kind**: static typedef of [sway](#module_sway)
**Properties**
| Name | Type | Default | Description |
| --- | --- | --- | --- |
| strictMode | boolean | object | false | Enablement of strict mode validation. If `strictMode` is a `boolean` and is `true`, all form fields, headers and query parameters **must** be defined in the OpenAPI definition for this operation. If `strictMode` is an `object`, the keys correspond to the `in` property values of the [OpenAPI Parameter Object](https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#parameterObject) and its value is a `boolean` that when `true` turns on strict mode validation for the request location matching the key. Valid keys are `header`. _(`body`, `query` and `path` are not necessary since `body` strict mode is possible via its schema and `path`, `query` do not matter for responses.)_ |
| customValidators | [RequestValidationFunction](#module_sway.RequestValidationFunction) | | The custom validators |
### sway.ServerResponseWrapper : object
Server response wrapper.
Since the low level `http.ServerResponse` object is not always guaranteed and even if it is, there is no public way
to gather the necessary parts of the response to perform validation, this object encapsulates the required response
information to perform response validation.
**Kind**: static typedef of [sway](#module_sway)
**Properties**
| Name | Type | Default | Description |
| --- | --- | --- | --- |
| body | \* | | The response body |
| encoding | string | | The encoding of the body when the body is a `Buffer` |
| headers | object | | The response headers |
| statusCode | number | string | default | The response status code |
### sway.ValidationEntry : object
Validation error/warning object.
When this object is created as a result of JSON Schema validation, this object is created by
[z-schema](https://github.com/zaggino/z-schema) and it owns the structure so there can be extra properties not
documented below.
**Kind**: static typedef of [sway](#module_sway)
**Properties**
| Name | Type | Description |
| --- | --- | --- |
| code | string | The code used to identify the error/warning |
| error | string | Whenever there is an upstream `Error` encountered, its message is here |
| errors | [Array.<ValidationEntry>](#module_sway.ValidationEntry) | The nested error(s) encountered during validation |
| lineage | Array.<string> | Contains the composition lineage for circular composition errors |
| message | string | The human readable description of the error/warning |
| name | string | The header name for header validation errors |
| params | array | The parameters used when validation failed *(This is a z-schema construct and is only set for JSON Schema validation errors.)* |
| path | Array.<string> | The path to the location in the document where the error/warning occurred |
| schemaId | string | The schema id *(This is a z-schema construct and is only set for JSON Schema validation errors and when its value is not `undefined`.) |
### sway.ValidationResults : object
Validation results object.
**Kind**: static typedef of [sway](#module_sway)
**Properties**
| Name | Type | Description |
| --- | --- | --- |
| errors | [Array.<ValidationEntry>](#module_sway.ValidationEntry) | The validation errors |
| warnings | [Array.<ValidationEntry>](#module_sway.ValidationEntry) | The validation warnings |
### sway.create(options) ⇒ [Promise.<ApiDefinition>](#module_sway.ApiDefinition)
Creates an ApiDefinition object from the provided OpenAPI definition.
**Kind**: static method of [sway](#module_sway)
**Returns**: [Promise.<ApiDefinition>](#module_sway.ApiDefinition) - The promise
| Param | Type | Description |
| --- | --- | --- |
| options | [CreateOptions](#module_sway.CreateOptions) | The options for loading the definition(s) |
**Example**
```js
Sway.create({
definition: 'https://raw.githubusercontent.com/OAI/OpenAPI-Specification/master/examples/v3.0/petstore.yaml'
})
.then(function (apiDefinition) {
console.log('Documentation URL: ', apiDefinition.documentationUrl);
}, function (err) {
console.error(err.stack);
});
```