| 177 | } |
| 178 | |
| 179 | _setupValidation() { |
| 180 | |
| 181 | const validation = this.settings.validate; |
| 182 | if (this.method === 'get') { |
| 183 | validation.payload = null; |
| 184 | } |
| 185 | |
| 186 | this._assert(!validation.params || this.params.length, 'Cannot set path parameters validations without path parameters'); |
| 187 | |
| 188 | for (const type of ['headers', 'params', 'query', 'payload', 'state']) { |
| 189 | validation[type] = Validation.compile(validation[type], this.settings.validate.validator, this.realm, this._core); |
| 190 | } |
| 191 | |
| 192 | if (this.settings.response.schema !== undefined || |
| 193 | this.settings.response.status) { |
| 194 | |
| 195 | this.settings.response._validate = true; |
| 196 | |
| 197 | const rule = this.settings.response.schema; |
| 198 | this.settings.response.status = this.settings.response.status ?? {}; |
| 199 | const statuses = Object.keys(this.settings.response.status); |
| 200 | |
| 201 | if (rule === true && |
| 202 | !statuses.length) { |
| 203 | |
| 204 | this.settings.response._validate = false; |
| 205 | } |
| 206 | else { |
| 207 | this.settings.response.schema = Validation.compile(rule, this.settings.validate.validator, this.realm, this._core); |
| 208 | for (const code of statuses) { |
| 209 | this.settings.response.status[code] = Validation.compile(this.settings.response.status[code], this.settings.validate.validator, this.realm, this._core); |
| 210 | } |
| 211 | } |
| 212 | } |
| 213 | } |
| 214 | |
| 215 | rebuild(event) { |
| 216 | |