You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Jan 20, 2024. It is now read-only.
Accepts the RAML schema as the first argument, method and path in subsequent arguments (mostly for debugging) and options as the final argument.
58
+
Accepts [webapi-parser](https://github.com/raml-org/webapi-parser)`Operation` object as first argument, path string as second argument, method name as third and options object as final argument.
67
59
68
60
**Options**
69
61
70
-
*`ajv` Custom [Ajv](https://github.com/epoberezkin/ajv) instance to be used for JSON validation
62
+
*`ajv` Custom [Ajv](https://github.com/epoberezkin/ajv) instance to be used to validate query strings, request headers and request bodied (url-encoded, form-data, json)
*`discardUnknownHeaders` Discard undefined header parameters (always includes known headers) (default: `true`)
@@ -76,32 +68,19 @@ Accepts the RAML schema as the first argument, method and path in subsequent arg
76
68
*`limit` The [maximum bytes](https://github.com/expressjs/body-parser#limit-2) for XML, JSON and URL-encoded endpoints (default: `'100kb'`)
77
69
*`parameterLimit` The [maximum number](https://github.com/expressjs/body-parser#parameterlimit) of URL-encoded parameters (default: `1000`)
78
70
*`busboyLimits` The multipart limits defined by [Busboy](https://github.com/mscdex/busboy#busboy-methods)
79
-
*`RAMLVersion` The RAML version passed to [raml-validate](https://github.com/mulesoft/node-raml-validate) (default: `'RAML08'`)
80
71
81
72
### Adding JSON schemas
82
73
83
74
If you are using external JSON schemas with `$ref`, you can add them to the module before you compile the middleware. Use `handler.addJsonSchema(schema, key)` to compile automatically when used.
84
75
85
76
`handler.addJsonSchema()` accepts a third (optional) `options` argument. Supported `options` are:
86
-
*`ajv` Custom [Ajv](https://github.com/epoberezkin/ajv) instance. E.g. `handler.addJsonSchema(schema, key, {ajv: myAjvInstance})`. The provided ajv instance can later be passed as an option to the handler to perform JSON validation.
77
+
*`ajv` Custom [Ajv](https://github.com/epoberezkin/ajv) instance. E.g. `handler.addJsonSchema(schema, key, {ajv: myAjvInstance})`. The provided ajv instance can later be passed as an option to the handler to perform validation.
87
78
88
79
### Validation Errors
89
80
90
81
The library intercepts incoming requests and does validation. It will respond with `400`, `406` or `415` error instances from [http-errors](https://github.com/jshttp/http-errors). Validation errors are attached to `400` instances and noted using `ramlValidation = true` and `requestErrors = []` (an array of errors that were found, compatible with [request-error-handler](https://github.com/mulesoft-labs/node-request-error-handler)).
91
82
92
-
The errors object format is:
93
-
94
-
```ts
95
-
interfaceError {
96
-
type:'json'|'form'|'headers'|'query'|'xml'
97
-
message:string
98
-
keyword:string
99
-
dataPath:string
100
-
data:any
101
-
schema:any
102
-
meta?:Object
103
-
}
104
-
```
83
+
See [the code](https://github.com/mulesoft-labs/osprey-method-handler/blob/7adb162035e4e593a5bbda8b3e83b1996adc2174/osprey-method-handler.js#L705-L751) for a complete list of errors formats.
105
84
106
85
**Please note:** XML validation does not have a way to get the `keyword`, `dataPath`, `data` or `schema`. Instead, it has a `meta` object that contains information from `libxmljs` (`domain`, `code`, `level`, `column`, `line`).
0 commit comments