|
| 1 | +import testRule from './__helpers__/testRule'; |
| 2 | +import { DiagnosticSeverity } from '@stoplight/types'; |
| 3 | + |
| 4 | +const componentSchemas = { |
| 5 | + schemas: { |
| 6 | + SchemaRequest: { |
| 7 | + type: 'object', |
| 8 | + }, |
| 9 | + Schema: { |
| 10 | + type: 'object', |
| 11 | + }, |
| 12 | + }, |
| 13 | +}; |
| 14 | +testRule('xgen-IPA-106-create-method-request-body-is-get-method-response', [ |
| 15 | + { |
| 16 | + name: 'valid methods', |
| 17 | + document: { |
| 18 | + components: componentSchemas, |
| 19 | + paths: { |
| 20 | + '/resource': { |
| 21 | + post: { |
| 22 | + requestBody: { |
| 23 | + content: { |
| 24 | + 'application/vnd.atlas.2023-01-01+json': { |
| 25 | + schema: { |
| 26 | + $ref: '#/components/schemas/SchemaRequest', |
| 27 | + }, |
| 28 | + }, |
| 29 | + 'application/vnd.atlas.2024-01-01+json': { |
| 30 | + schema: { |
| 31 | + $ref: '#/components/schemas/SchemaRequest', |
| 32 | + }, |
| 33 | + }, |
| 34 | + }, |
| 35 | + }, |
| 36 | + }, |
| 37 | + }, |
| 38 | + '/resource/{id}': { |
| 39 | + get: { |
| 40 | + responses: { |
| 41 | + 200: { |
| 42 | + content: { |
| 43 | + 'application/vnd.atlas.2023-01-01+json': { |
| 44 | + schema: { |
| 45 | + $ref: '#/components/schemas/Schema', |
| 46 | + }, |
| 47 | + }, |
| 48 | + }, |
| 49 | + }, |
| 50 | + }, |
| 51 | + }, |
| 52 | + }, |
| 53 | + '/resource/{id}:customMethod': { |
| 54 | + post: { |
| 55 | + requestBody: { |
| 56 | + content: { |
| 57 | + 'application/vnd.atlas.2023-01-01+json': { |
| 58 | + schema: { |
| 59 | + $ref: '#/components/schemas/Schema', |
| 60 | + }, |
| 61 | + }, |
| 62 | + 'application/vnd.atlas.2024-01-01+json': { |
| 63 | + schema: { |
| 64 | + $ref: '#/components/schemas/SchemaRequest', |
| 65 | + }, |
| 66 | + }, |
| 67 | + }, |
| 68 | + }, |
| 69 | + }, |
| 70 | + }, |
| 71 | + } |
| 72 | + }, |
| 73 | + errors: [], |
| 74 | + }, |
| 75 | + { |
| 76 | + name: 'invalid methods', |
| 77 | + document: { |
| 78 | + components: componentSchemas, |
| 79 | + paths: { |
| 80 | + '/resource': { |
| 81 | + post: { |
| 82 | + requestBody: { |
| 83 | + content: { |
| 84 | + 'application/vnd.atlas.2023-01-01+json': { |
| 85 | + schema: { |
| 86 | + $ref: '#/components/schemas/Schema', |
| 87 | + }, |
| 88 | + }, |
| 89 | + }, |
| 90 | + }, |
| 91 | + }, |
| 92 | + }, |
| 93 | + '/resource2': { |
| 94 | + post: { |
| 95 | + requestBody: { |
| 96 | + content: { |
| 97 | + 'application/vnd.atlas.2023-01-01+json': { |
| 98 | + schema: { |
| 99 | + $ref: '#/components/schemas/Schema', |
| 100 | + }, |
| 101 | + }, |
| 102 | + 'application/vnd.atlas.2024-01-01+json': { |
| 103 | + schema: { |
| 104 | + $ref: '#/components/schemas/Schema', |
| 105 | + }, |
| 106 | + }, |
| 107 | + }, |
| 108 | + }, |
| 109 | + }, |
| 110 | + }, |
| 111 | + '/resource3': { |
| 112 | + post: { |
| 113 | + requestBody: { |
| 114 | + content: { |
| 115 | + 'application/vnd.atlas.2023-01-01+json': { |
| 116 | + schema: { |
| 117 | + type: 'object', |
| 118 | + }, |
| 119 | + }, |
| 120 | + }, |
| 121 | + }, |
| 122 | + }, |
| 123 | + }, |
| 124 | + }, |
| 125 | + }, |
| 126 | + errors: [ |
| 127 | + { |
| 128 | + code: 'xgen-IPA-106-create-method-request-body-is-get-method-response', |
| 129 | + message: 'The response body schema must reference a schema with a Request suffix. http://go/ipa/106', |
| 130 | + path: ['paths', '/resource', 'post', 'requestBody', 'content', 'application/vnd.atlas.2023-01-01+json'], |
| 131 | + severity: DiagnosticSeverity.Warning, |
| 132 | + }, |
| 133 | + { |
| 134 | + code: 'xgen-IPA-106-create-method-request-body-is-get-method-response', |
| 135 | + message: 'The response body schema must reference a schema with a Request suffix. http://go/ipa/106', |
| 136 | + path: ['paths', '/resource', 'post', 'requestBody', 'content', 'application/vnd.atlas.2024-01-01+json'], |
| 137 | + severity: DiagnosticSeverity.Warning, |
| 138 | + }, |
| 139 | + { |
| 140 | + code: 'xgen-IPA-106-create-method-request-body-is-get-method-response', |
| 141 | + message: 'The response body schema must reference a schema with a Request suffix. http://go/ipa/106', |
| 142 | + path: ['paths', '/resource2', 'post', 'requestBody', 'content', 'application/vnd.atlas.2023-01-01+json'], |
| 143 | + severity: DiagnosticSeverity.Warning, |
| 144 | + }, |
| 145 | + { |
| 146 | + code: 'xgen-IPA-106-create-method-request-body-is-get-method-response', |
| 147 | + message: 'The response body schema must reference a schema with a Request suffix. http://go/ipa/106', |
| 148 | + path: ['paths', '/resource2', 'post', 'requestBody', 'content', 'application/vnd.atlas.2024-01-01+json'], |
| 149 | + severity: DiagnosticSeverity.Warning, |
| 150 | + }, |
| 151 | + { |
| 152 | + code: 'xgen-IPA-106-create-method-request-body-is-get-method-response', |
| 153 | + message: 'The response body schema is defined inline and must reference a predefined schema. http://go/ipa/106', |
| 154 | + path: ['paths', '/resource3', 'post', 'requestBody', 'content', 'application/vnd.atlas.2023-01-01+json'], |
| 155 | + severity: DiagnosticSeverity.Warning, |
| 156 | + }, |
| 157 | + ], |
| 158 | + }, |
| 159 | + { |
| 160 | + name: 'invalid method with exception', |
| 161 | + document: { |
| 162 | + components: componentSchemas, |
| 163 | + paths: { |
| 164 | + '/resource': { |
| 165 | + post: { |
| 166 | + requestBody: { |
| 167 | + content: { |
| 168 | + 'application/vnd.atlas.2023-01-01+json': { |
| 169 | + schema: { |
| 170 | + $ref: '#/components/schemas/Schema', |
| 171 | + }, |
| 172 | + 'x-xgen-IPA-exception': { |
| 173 | + 'xgen-IPA-106-create-method-request-body-is-get-method-response': 'reason', |
| 174 | + }, |
| 175 | + }, |
| 176 | + 'application/vnd.atlas.2024-01-01+json': { |
| 177 | + schema: { |
| 178 | + type: 'array', |
| 179 | + items: { |
| 180 | + $ref: '#/components/schemas/Schema', |
| 181 | + }, |
| 182 | + }, |
| 183 | + 'x-xgen-IPA-exception': { |
| 184 | + 'xgen-IPA-106-create-method-request-body-is-get-method-response': 'reason', |
| 185 | + }, |
| 186 | + }, |
| 187 | + }, |
| 188 | + }, |
| 189 | + }, |
| 190 | + }, |
| 191 | + '/resource2': { |
| 192 | + post: { |
| 193 | + requestBody: { |
| 194 | + content: { |
| 195 | + 'application/vnd.atlas.2023-01-01+json': { |
| 196 | + schema: { |
| 197 | + $ref: '#/components/schemas/Schema', |
| 198 | + }, |
| 199 | + 'x-xgen-IPA-exception': { |
| 200 | + 'xgen-IPA-106-create-method-request-body-is-get-method-response': 'reason', |
| 201 | + }, |
| 202 | + }, |
| 203 | + 'application/vnd.atlas.2024-01-01+json': { |
| 204 | + schema: { |
| 205 | + $ref: '#/components/schemas/Schema', |
| 206 | + }, |
| 207 | + 'x-xgen-IPA-exception': { |
| 208 | + 'xgen-IPA-106-create-method-request-body-is-get-method-response': 'reason', |
| 209 | + }, |
| 210 | + }, |
| 211 | + }, |
| 212 | + }, |
| 213 | + }, |
| 214 | + }, |
| 215 | + '/resource3': { |
| 216 | + post: { |
| 217 | + requestBody: { |
| 218 | + content: { |
| 219 | + 'application/vnd.atlas.2023-01-01+json': { |
| 220 | + schema: { |
| 221 | + type: 'object', |
| 222 | + }, |
| 223 | + 'x-xgen-IPA-exception': { |
| 224 | + 'xgen-IPA-106-create-method-request-body-is-get-method-response': 'reason', |
| 225 | + }, |
| 226 | + }, |
| 227 | + }, |
| 228 | + }, |
| 229 | + }, |
| 230 | + }, |
| 231 | + }, |
| 232 | + }, |
| 233 | + errors: [], |
| 234 | + }, |
| 235 | +]); |
0 commit comments