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