Skip to content

Commit

Permalink
Update docs to correct middleware.
Browse files Browse the repository at this point in the history
The middleware array property is a child of a handler's `metadata` 
object, not a top-level property.  Updated the docs to reflect this.
  • Loading branch information
JaredReisinger committed Jul 12, 2018
1 parent dfe1886 commit c764689
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 6 deletions.
21 changes: 19 additions & 2 deletions README.md
Expand Up @@ -152,7 +152,9 @@ const model = swatch({
default: 'New User',
},
],
middleware: [middlewareFn],
metadata: {
middleware: [middlewareFn],
},
},
});
```
Expand All @@ -174,7 +176,7 @@ The following properties can be set:
|:--- |:--- |:---
|`handler` | Yes | The API handler. Must be a function.
|`args` | No | Function arguments. Must be an array. See below for more information.
|`middleware` | No | An array of functions to run as middleware. Accepts request context and callback function as params. Throw on error to abort request handler.
|`metadata` | No | An object with additional information about the handler (see below).

If the `args` array is present, it must match the function in arity (i.e., the
number of arguments declared in the function must match the number of elements
Expand All @@ -194,6 +196,14 @@ If an element is an object, then the following properties are valid:
If an element is a string "argName", then it is considered equivalent to the
object `{ name: "argName" }`.

If the `metadata` object is present, the following sub-properties can be set:

| Property | Required | Description
|:--- |:--- |:---
|`noAuth` | No | A boolean that indicates whether the authAdapter (if any is defined by [swatchKoa](../swatchjs-koa) or [swatchExpress](../swatchjs-express) options) should be skipped for this particular method handler. Defaults to `false`.
|`middleware` | No | An array of functions to run as middleware. Accepts request context and callback function as params. Throw on error to abort request handler.


## Runtime errors

The following errors will be generated during runtime (when invoking the handler):
Expand Down Expand Up @@ -241,6 +251,13 @@ Each object will contain the following properties:
|:--- |:--- |
|`name` | The name of the method. This is the same as the key in the API object. |
|`handle` | A function used to execute the method handler. See [The `handle` function](#the-handle-function) below. |
|`metadata` | An object with additional data about the method handler. |

The `metadata` object will contain the following properties:

| Property | Description |
|:--- |:--- |
|`noAuth` | A boolean that describes whether `noAuth` was set on the method handler. |
|`middleware` | An array of functions to execute as middleware before the method handler. |

### The `handle` function
Expand Down
30 changes: 26 additions & 4 deletions docs/index.html
Expand Up @@ -324,10 +324,9 @@ <h2>Declaring API methods (the more descriptive way)</h2>
<td>Function arguments. Must be an array. See below for more information.</td>
</tr>
<tr>
<td><code>middleware</code></td>
<td><code>metadata</code></td>
<td>No</td>
<td>An array of functions to run as middleware. Accepts request context and callback
function as params. Throw on error to abort request handler.</td>
<td>An object with additional information about the handler (see below).</td>
</tr>
</tbody>
</table>
Expand Down Expand Up @@ -377,6 +376,29 @@ <h2>Declaring API methods (the more descriptive way)</h2>
</table>
<p>If an element is a string "argName", then it is considered equivalent to the object <code>{ name: "argName" }</code>.</p>

<p>If the <code>metadata</code> object is present, the following sub-properties can be set:</p>
<table class="uk-table uk-table-striped">
<thead class="thead-default">
<tr>
<th>Property</th>
<th>Required?</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>noAuth</code></td>
<td>No</td>
<td>A boolean that indicates whether the authAdapter (if any is defined by swatchKoa or swatchExpress options) should be skipped for this particular method handler. Defaults to <code>false</code>.</td>
</tr>
<tr>
<td><code>middleware</code></td>
<td>No</td>
<td>An array of functions to run as middleware. Accepts request context and callback
function as params. Throw on error to abort request handler.</td>
</tr>
</tbody>
</table>

<br>
</div>
Expand Down Expand Up @@ -416,4 +438,4 @@ <h5 class="footer uk-heading-line uk-text-center"><span>Created by <a style="tex
</script>
</body>

</html>
</html>

0 comments on commit c764689

Please sign in to comment.