|
| 1 | +import testRule from './__helpers__/testRule'; |
| 2 | +import { DiagnosticSeverity } from '@stoplight/types'; |
| 3 | + |
| 4 | +testRule('xgen-IPA-107-put-method-response-code-is-200', [ |
| 5 | + { |
| 6 | + name: 'valid methods', |
| 7 | + document: { |
| 8 | + paths: { |
| 9 | + '/resource/{id}': { |
| 10 | + put: { |
| 11 | + responses: { |
| 12 | + 200: {}, |
| 13 | + 400: {}, |
| 14 | + 500: {}, |
| 15 | + }, |
| 16 | + }, |
| 17 | + }, |
| 18 | + '/resource/{id}/singleton': { |
| 19 | + put: { |
| 20 | + responses: { |
| 21 | + 200: {}, |
| 22 | + 400: {}, |
| 23 | + 500: {}, |
| 24 | + }, |
| 25 | + }, |
| 26 | + }, |
| 27 | + }, |
| 28 | + }, |
| 29 | + errors: [], |
| 30 | + }, |
| 31 | + { |
| 32 | + name: 'invalid methods', |
| 33 | + document: { |
| 34 | + paths: { |
| 35 | + '/resourceOne/{id}': { |
| 36 | + put: { |
| 37 | + responses: { |
| 38 | + 201: {}, |
| 39 | + 400: {}, |
| 40 | + 500: {}, |
| 41 | + }, |
| 42 | + }, |
| 43 | + }, |
| 44 | + '/resourceTwo/{id}': { |
| 45 | + put: { |
| 46 | + responses: { |
| 47 | + 400: {}, |
| 48 | + 500: {}, |
| 49 | + }, |
| 50 | + }, |
| 51 | + }, |
| 52 | + '/resourceThree/{id}': { |
| 53 | + put: { |
| 54 | + responses: { |
| 55 | + 200: {}, |
| 56 | + 201: {}, |
| 57 | + 400: {}, |
| 58 | + 500: {}, |
| 59 | + }, |
| 60 | + }, |
| 61 | + }, |
| 62 | + '/resource/{id}/singleton': { |
| 63 | + put: { |
| 64 | + responses: { |
| 65 | + 202: {}, |
| 66 | + 400: {}, |
| 67 | + 500: {}, |
| 68 | + }, |
| 69 | + }, |
| 70 | + }, |
| 71 | + }, |
| 72 | + }, |
| 73 | + errors: [ |
| 74 | + { |
| 75 | + code: 'xgen-IPA-107-put-method-response-code-is-200', |
| 76 | + message: |
| 77 | + 'The Update method response status code should be 200 OK. This method either lacks a 200 OK response or defines a different 2xx status code. http://go/ipa-spectral#IPA-107', |
| 78 | + path: ['paths', '/resourceOne/{id}', 'put'], |
| 79 | + severity: DiagnosticSeverity.Warning, |
| 80 | + }, |
| 81 | + { |
| 82 | + code: 'xgen-IPA-107-put-method-response-code-is-200', |
| 83 | + message: |
| 84 | + 'The Update method response status code should be 200 OK. This method either lacks a 200 OK response or defines a different 2xx status code. http://go/ipa-spectral#IPA-107', |
| 85 | + path: ['paths', '/resourceTwo/{id}', 'put'], |
| 86 | + severity: DiagnosticSeverity.Warning, |
| 87 | + }, |
| 88 | + { |
| 89 | + code: 'xgen-IPA-107-put-method-response-code-is-200', |
| 90 | + message: |
| 91 | + 'The Update method response status code should be 200 OK. This method either lacks a 200 OK response or defines a different 2xx status code. http://go/ipa-spectral#IPA-107', |
| 92 | + path: ['paths', '/resourceThree/{id}', 'put'], |
| 93 | + severity: DiagnosticSeverity.Warning, |
| 94 | + }, |
| 95 | + { |
| 96 | + code: 'xgen-IPA-107-put-method-response-code-is-200', |
| 97 | + message: |
| 98 | + 'The Update method response status code should be 200 OK. This method either lacks a 200 OK response or defines a different 2xx status code. http://go/ipa-spectral#IPA-107', |
| 99 | + path: ['paths', '/resource/{id}/singleton', 'put'], |
| 100 | + severity: DiagnosticSeverity.Warning, |
| 101 | + }, |
| 102 | + ], |
| 103 | + }, |
| 104 | + { |
| 105 | + name: 'invalid method with exception', |
| 106 | + document: { |
| 107 | + paths: { |
| 108 | + '/resourceOne/{id}': { |
| 109 | + put: { |
| 110 | + responses: { |
| 111 | + 201: {}, |
| 112 | + 400: {}, |
| 113 | + 500: {}, |
| 114 | + }, |
| 115 | + 'x-xgen-IPA-exception': { |
| 116 | + 'xgen-IPA-107-put-method-response-code-is-200': 'reason', |
| 117 | + }, |
| 118 | + }, |
| 119 | + }, |
| 120 | + '/resourceTwo/{id}': { |
| 121 | + put: { |
| 122 | + responses: { |
| 123 | + 400: {}, |
| 124 | + 500: {}, |
| 125 | + }, |
| 126 | + 'x-xgen-IPA-exception': { |
| 127 | + 'xgen-IPA-107-put-method-response-code-is-200': 'reason', |
| 128 | + }, |
| 129 | + }, |
| 130 | + }, |
| 131 | + '/resource/{id}/singleton': { |
| 132 | + put: { |
| 133 | + responses: { |
| 134 | + 202: {}, |
| 135 | + 400: {}, |
| 136 | + 500: {}, |
| 137 | + }, |
| 138 | + 'x-xgen-IPA-exception': { |
| 139 | + 'xgen-IPA-107-put-method-response-code-is-200': 'reason', |
| 140 | + }, |
| 141 | + }, |
| 142 | + }, |
| 143 | + }, |
| 144 | + }, |
| 145 | + errors: [], |
| 146 | + }, |
| 147 | +]); |
| 148 | + |
| 149 | +testRule('xgen-IPA-107-patch-method-response-code-is-200', [ |
| 150 | + { |
| 151 | + name: 'valid methods', |
| 152 | + document: { |
| 153 | + paths: { |
| 154 | + '/resource/{id}': { |
| 155 | + patch: { |
| 156 | + responses: { |
| 157 | + 200: {}, |
| 158 | + 400: {}, |
| 159 | + 500: {}, |
| 160 | + }, |
| 161 | + }, |
| 162 | + }, |
| 163 | + '/resource/{id}/singleton': { |
| 164 | + patch: { |
| 165 | + responses: { |
| 166 | + 200: {}, |
| 167 | + 400: {}, |
| 168 | + 500: {}, |
| 169 | + }, |
| 170 | + }, |
| 171 | + }, |
| 172 | + }, |
| 173 | + }, |
| 174 | + errors: [], |
| 175 | + }, |
| 176 | + { |
| 177 | + name: 'invalid methods', |
| 178 | + document: { |
| 179 | + paths: { |
| 180 | + '/resourceOne/{id}': { |
| 181 | + patch: { |
| 182 | + responses: { |
| 183 | + 201: {}, |
| 184 | + 400: {}, |
| 185 | + 500: {}, |
| 186 | + }, |
| 187 | + }, |
| 188 | + }, |
| 189 | + '/resourceTwo/{id}': { |
| 190 | + patch: { |
| 191 | + responses: { |
| 192 | + 400: {}, |
| 193 | + 500: {}, |
| 194 | + }, |
| 195 | + }, |
| 196 | + }, |
| 197 | + '/resourceThree/{id}': { |
| 198 | + patch: { |
| 199 | + responses: { |
| 200 | + 200: {}, |
| 201 | + 201: {}, |
| 202 | + 400: {}, |
| 203 | + 500: {}, |
| 204 | + }, |
| 205 | + }, |
| 206 | + }, |
| 207 | + '/resource/{id}/singleton': { |
| 208 | + patch: { |
| 209 | + responses: { |
| 210 | + 202: {}, |
| 211 | + 400: {}, |
| 212 | + 500: {}, |
| 213 | + }, |
| 214 | + }, |
| 215 | + }, |
| 216 | + }, |
| 217 | + }, |
| 218 | + errors: [ |
| 219 | + { |
| 220 | + code: 'xgen-IPA-107-patch-method-response-code-is-200', |
| 221 | + message: |
| 222 | + 'The Update method response status code should be 200 OK. This method either lacks a 200 OK response or defines a different 2xx status code. http://go/ipa-spectral#IPA-107', |
| 223 | + path: ['paths', '/resourceOne/{id}', 'patch'], |
| 224 | + severity: DiagnosticSeverity.Warning, |
| 225 | + }, |
| 226 | + { |
| 227 | + code: 'xgen-IPA-107-patch-method-response-code-is-200', |
| 228 | + message: |
| 229 | + 'The Update method response status code should be 200 OK. This method either lacks a 200 OK response or defines a different 2xx status code. http://go/ipa-spectral#IPA-107', |
| 230 | + path: ['paths', '/resourceTwo/{id}', 'patch'], |
| 231 | + severity: DiagnosticSeverity.Warning, |
| 232 | + }, |
| 233 | + { |
| 234 | + code: 'xgen-IPA-107-patch-method-response-code-is-200', |
| 235 | + message: |
| 236 | + 'The Update method response status code should be 200 OK. This method either lacks a 200 OK response or defines a different 2xx status code. http://go/ipa-spectral#IPA-107', |
| 237 | + path: ['paths', '/resourceThree/{id}', 'patch'], |
| 238 | + severity: DiagnosticSeverity.Warning, |
| 239 | + }, |
| 240 | + { |
| 241 | + code: 'xgen-IPA-107-patch-method-response-code-is-200', |
| 242 | + message: |
| 243 | + 'The Update method response status code should be 200 OK. This method either lacks a 200 OK response or defines a different 2xx status code. http://go/ipa-spectral#IPA-107', |
| 244 | + path: ['paths', '/resource/{id}/singleton', 'patch'], |
| 245 | + severity: DiagnosticSeverity.Warning, |
| 246 | + }, |
| 247 | + ], |
| 248 | + }, |
| 249 | + { |
| 250 | + name: 'invalid method with exception', |
| 251 | + document: { |
| 252 | + paths: { |
| 253 | + '/resourceOne/{id}': { |
| 254 | + patch: { |
| 255 | + responses: { |
| 256 | + 201: {}, |
| 257 | + 400: {}, |
| 258 | + 500: {}, |
| 259 | + }, |
| 260 | + 'x-xgen-IPA-exception': { |
| 261 | + 'xgen-IPA-107-patch-method-response-code-is-200': 'reason', |
| 262 | + }, |
| 263 | + }, |
| 264 | + }, |
| 265 | + '/resourceTwo/{id}': { |
| 266 | + patch: { |
| 267 | + responses: { |
| 268 | + 400: {}, |
| 269 | + 500: {}, |
| 270 | + }, |
| 271 | + 'x-xgen-IPA-exception': { |
| 272 | + 'xgen-IPA-107-patch-method-response-code-is-200': 'reason', |
| 273 | + }, |
| 274 | + }, |
| 275 | + }, |
| 276 | + '/resource/{id}/singleton': { |
| 277 | + patch: { |
| 278 | + responses: { |
| 279 | + 202: {}, |
| 280 | + 400: {}, |
| 281 | + 500: {}, |
| 282 | + }, |
| 283 | + 'x-xgen-IPA-exception': { |
| 284 | + 'xgen-IPA-107-patch-method-response-code-is-200': 'reason', |
| 285 | + }, |
| 286 | + }, |
| 287 | + }, |
| 288 | + }, |
| 289 | + }, |
| 290 | + errors: [], |
| 291 | + }, |
| 292 | +]); |
0 commit comments