|
| 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-request-suffixed-object', [ |
| 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 | + post: { |
| 40 | + requestBody: { |
| 41 | + content: { |
| 42 | + 'application/vnd.atlas.2023-01-01+json': { |
| 43 | + schema: { |
| 44 | + $ref: '#/components/schemas/SchemaRequest', |
| 45 | + }, |
| 46 | + }, |
| 47 | + 'application/vnd.atlas.2024-01-01+json': { |
| 48 | + schema: { |
| 49 | + $ref: '#/components/schemas/SchemaRequest', |
| 50 | + }, |
| 51 | + }, |
| 52 | + }, |
| 53 | + }, |
| 54 | + }, |
| 55 | + }, |
| 56 | + '/resource/{id}:customMethod': { |
| 57 | + post: { |
| 58 | + requestBody: { |
| 59 | + content: { |
| 60 | + 'application/vnd.atlas.2023-01-01+json': { |
| 61 | + schema: { |
| 62 | + $ref: '#/components/schemas/Schema', |
| 63 | + }, |
| 64 | + }, |
| 65 | + 'application/vnd.atlas.2024-01-01+json': { |
| 66 | + schema: { |
| 67 | + $ref: '#/components/schemas/SchemaRequest', |
| 68 | + }, |
| 69 | + }, |
| 70 | + }, |
| 71 | + }, |
| 72 | + }, |
| 73 | + }, |
| 74 | + }, |
| 75 | + }, |
| 76 | + errors: [], |
| 77 | + }, |
| 78 | + { |
| 79 | + name: 'invalid methods', |
| 80 | + document: { |
| 81 | + components: componentSchemas, |
| 82 | + paths: { |
| 83 | + '/resource': { |
| 84 | + post: { |
| 85 | + requestBody: { |
| 86 | + content: { |
| 87 | + 'application/vnd.atlas.2023-01-01+json': { |
| 88 | + schema: { |
| 89 | + $ref: '#/components/schemas/Schema', |
| 90 | + }, |
| 91 | + }, |
| 92 | + }, |
| 93 | + }, |
| 94 | + }, |
| 95 | + }, |
| 96 | + '/resource/{id}': { |
| 97 | + post: { |
| 98 | + requestBody: { |
| 99 | + content: { |
| 100 | + 'application/vnd.atlas.2023-01-01+json': { |
| 101 | + schema: { |
| 102 | + $ref: '#/components/schemas/Schema', |
| 103 | + }, |
| 104 | + }, |
| 105 | + }, |
| 106 | + }, |
| 107 | + }, |
| 108 | + }, |
| 109 | + '/resource2': { |
| 110 | + post: { |
| 111 | + requestBody: { |
| 112 | + content: { |
| 113 | + 'application/vnd.atlas.2023-01-01+json': { |
| 114 | + schema: { |
| 115 | + $ref: '#/components/schemas/Schema', |
| 116 | + }, |
| 117 | + }, |
| 118 | + 'application/vnd.atlas.2024-01-01+json': { |
| 119 | + schema: { |
| 120 | + $ref: '#/components/schemas/Schema', |
| 121 | + }, |
| 122 | + }, |
| 123 | + }, |
| 124 | + }, |
| 125 | + }, |
| 126 | + }, |
| 127 | + }, |
| 128 | + }, |
| 129 | + errors: [ |
| 130 | + { |
| 131 | + code: 'xgen-IPA-106-create-method-request-body-is-request-suffixed-object', |
| 132 | + message: 'Response body for the Create method should refer to Request suffixed schema. http://go/ipa/106', |
| 133 | + path: ['paths', '/resource', 'post', 'requestBody', 'content', 'application/vnd.atlas.2023-01-01+json'], |
| 134 | + severity: DiagnosticSeverity.Warning, |
| 135 | + }, |
| 136 | + { |
| 137 | + code: 'xgen-IPA-106-create-method-request-body-is-request-suffixed-object', |
| 138 | + message: 'Response body for the Create method should refer to Request suffixed schema. http://go/ipa/106', |
| 139 | + path: ['paths', '/resource/{id}', 'post', 'requestBody', 'content', 'application/vnd.atlas.2023-01-01+json'], |
| 140 | + severity: DiagnosticSeverity.Warning, |
| 141 | + }, |
| 142 | + { |
| 143 | + code: 'xgen-IPA-106-create-method-request-body-is-request-suffixed-object', |
| 144 | + message: 'Response body for the Create method should refer to Request suffixed schema. http://go/ipa/106', |
| 145 | + path: ['paths', '/resource2', 'post', 'requestBody', 'content', 'application/vnd.atlas.2023-01-01+json'], |
| 146 | + severity: DiagnosticSeverity.Warning, |
| 147 | + }, |
| 148 | + { |
| 149 | + code: 'xgen-IPA-106-create-method-request-body-is-request-suffixed-object', |
| 150 | + message: 'Response body for the Create method should refer to Request suffixed schema. http://go/ipa/106', |
| 151 | + path: ['paths', '/resource2', 'post', 'requestBody', 'content', 'application/vnd.atlas.2024-01-01+json'], |
| 152 | + severity: DiagnosticSeverity.Warning, |
| 153 | + }, |
| 154 | + ], |
| 155 | + }, |
| 156 | + { |
| 157 | + name: 'invalid method with exception', |
| 158 | + document: { |
| 159 | + components: componentSchemas, |
| 160 | + paths: { |
| 161 | + '/resource': { |
| 162 | + post: { |
| 163 | + requestBody: { |
| 164 | + content: { |
| 165 | + 'application/vnd.atlas.2023-01-01+json': { |
| 166 | + schema: { |
| 167 | + $ref: '#/components/schemas/Schema', |
| 168 | + }, |
| 169 | + }, |
| 170 | + 'x-xgen-IPA-exception': { |
| 171 | + 'xgen-IPA-106-create-method-request-body-is-request-suffixed-object': 'reason', |
| 172 | + }, |
| 173 | + }, |
| 174 | + }, |
| 175 | + }, |
| 176 | + }, |
| 177 | + }, |
| 178 | + }, |
| 179 | + errors: [], |
| 180 | + }, |
| 181 | +]); |
0 commit comments