|
| 1 | +import testRule from './__helpers__/testRule'; |
| 2 | +import { DiagnosticSeverity } from '@stoplight/types'; |
| 3 | + |
| 4 | +testRule('xgen-IPA-102-collection-identifier-camelCase', [ |
| 5 | + { |
| 6 | + name: 'valid camelCase identifiers', |
| 7 | + document: { |
| 8 | + paths: { |
| 9 | + '/api/v2/atlas/test': {}, |
| 10 | + '/users': {}, |
| 11 | + '/resourceGroups': {}, |
| 12 | + '/userProfiles': {}, |
| 13 | + '/api/v1/test': {}, |
| 14 | + }, |
| 15 | + }, |
| 16 | + errors: [], |
| 17 | + }, |
| 18 | + { |
| 19 | + name: 'valid camelCase with path parameters', |
| 20 | + document: { |
| 21 | + paths: { |
| 22 | + '/resourceGroups/{groupId}': {}, |
| 23 | + '/users/{userId}/userProfiles': {}, |
| 24 | + }, |
| 25 | + }, |
| 26 | + errors: [], |
| 27 | + }, |
| 28 | + { |
| 29 | + name: 'valid paths with custom methods (only checking identifier part)', |
| 30 | + document: { |
| 31 | + paths: { |
| 32 | + '/resources:any_Custom_Method': {}, |
| 33 | + }, |
| 34 | + }, |
| 35 | + errors: [], |
| 36 | + }, |
| 37 | + { |
| 38 | + name: 'invalid PascalCase instead of camelCase', |
| 39 | + document: { |
| 40 | + paths: { |
| 41 | + '/Resources': {}, |
| 42 | + }, |
| 43 | + }, |
| 44 | + errors: [ |
| 45 | + { |
| 46 | + code: 'xgen-IPA-102-collection-identifier-camelCase', |
| 47 | + message: |
| 48 | + "Collection identifiers must be in camelCase. Path segment 'Resources' in path '/Resources' is not in camelCase. http://go/ipa/102", |
| 49 | + path: ['paths', '/Resources'], |
| 50 | + severity: DiagnosticSeverity.Warning, |
| 51 | + }, |
| 52 | + ], |
| 53 | + }, |
| 54 | + { |
| 55 | + name: 'invalid with snake_case instead of camelCase', |
| 56 | + document: { |
| 57 | + paths: { |
| 58 | + '/resource_groups': {}, |
| 59 | + }, |
| 60 | + }, |
| 61 | + errors: [ |
| 62 | + { |
| 63 | + code: 'xgen-IPA-102-collection-identifier-camelCase', |
| 64 | + message: |
| 65 | + "Collection identifiers must be in camelCase. Path segment 'resource_groups' in path '/resource_groups' is not in camelCase. http://go/ipa/102", |
| 66 | + path: ['paths', '/resource_groups'], |
| 67 | + severity: DiagnosticSeverity.Warning, |
| 68 | + }, |
| 69 | + ], |
| 70 | + }, |
| 71 | + { |
| 72 | + name: 'invalid with kebab-case instead of camelCase', |
| 73 | + document: { |
| 74 | + paths: { |
| 75 | + '/resource-groups': {}, |
| 76 | + }, |
| 77 | + }, |
| 78 | + errors: [ |
| 79 | + { |
| 80 | + code: 'xgen-IPA-102-collection-identifier-camelCase', |
| 81 | + message: |
| 82 | + "Collection identifiers must be in camelCase. Path segment 'resource-groups' in path '/resource-groups' is not in camelCase. http://go/ipa/102", |
| 83 | + path: ['paths', '/resource-groups'], |
| 84 | + severity: DiagnosticSeverity.Warning, |
| 85 | + }, |
| 86 | + ], |
| 87 | + }, |
| 88 | + { |
| 89 | + name: 'invalid resource path with invalid casing but valid custom method', |
| 90 | + document: { |
| 91 | + paths: { |
| 92 | + '/Resources:createResource': {}, |
| 93 | + }, |
| 94 | + }, |
| 95 | + errors: [ |
| 96 | + { |
| 97 | + code: 'xgen-IPA-102-collection-identifier-camelCase', |
| 98 | + message: |
| 99 | + "Collection identifiers must be in camelCase. Path segment 'Resources' in path '/Resources:createResource' is not in camelCase. http://go/ipa/102", |
| 100 | + path: ['paths', '/Resources:createResource'], |
| 101 | + severity: DiagnosticSeverity.Warning, |
| 102 | + }, |
| 103 | + ], |
| 104 | + }, |
| 105 | + { |
| 106 | + name: 'invalid with consecutive uppercase letters', |
| 107 | + document: { |
| 108 | + paths: { |
| 109 | + '/resourcesAPI': {}, |
| 110 | + }, |
| 111 | + }, |
| 112 | + errors: [ |
| 113 | + { |
| 114 | + code: 'xgen-IPA-102-collection-identifier-camelCase', |
| 115 | + message: |
| 116 | + "Collection identifiers must be in camelCase. Path segment 'resourcesAPI' in path '/resourcesAPI' is not in camelCase. http://go/ipa/102", |
| 117 | + path: ['paths', '/resourcesAPI'], |
| 118 | + severity: DiagnosticSeverity.Warning, |
| 119 | + }, |
| 120 | + ], |
| 121 | + }, |
| 122 | + { |
| 123 | + name: 'valid with path-level exception', |
| 124 | + document: { |
| 125 | + paths: { |
| 126 | + '/resource_groups': { |
| 127 | + 'x-xgen-IPA-exception': { |
| 128 | + 'xgen-IPA-102-collection-identifier-camelCase': 'Legacy API path that cannot be changed', |
| 129 | + }, |
| 130 | + }, |
| 131 | + }, |
| 132 | + }, |
| 133 | + errors: [], |
| 134 | + }, |
| 135 | + { |
| 136 | + name: 'reports violations for paths with double slashes', |
| 137 | + document: { |
| 138 | + paths: { |
| 139 | + '/api//users': {}, |
| 140 | + '/resources///{resourceId}': {}, |
| 141 | + '//doubleSlashAtStart': {}, |
| 142 | + }, |
| 143 | + }, |
| 144 | + errors: [ |
| 145 | + { |
| 146 | + code: 'xgen-IPA-102-collection-identifier-camelCase', |
| 147 | + message: |
| 148 | + "Collection identifiers must be in camelCase. Path '/api//users' contains double slashes (//) which is not allowed. http://go/ipa/102", |
| 149 | + path: ['paths', '/api//users'], |
| 150 | + severity: DiagnosticSeverity.Warning, |
| 151 | + }, |
| 152 | + { |
| 153 | + code: 'xgen-IPA-102-collection-identifier-camelCase', |
| 154 | + message: |
| 155 | + "Collection identifiers must be in camelCase. Path '/resources///{resourceId}' contains double slashes (//) which is not allowed. http://go/ipa/102", |
| 156 | + path: ['paths', '/resources///{resourceId}'], |
| 157 | + severity: DiagnosticSeverity.Warning, |
| 158 | + }, |
| 159 | + { |
| 160 | + code: 'xgen-IPA-102-collection-identifier-camelCase', |
| 161 | + message: |
| 162 | + "Collection identifiers must be in camelCase. Path '//doubleSlashAtStart' contains double slashes (//) which is not allowed. http://go/ipa/102", |
| 163 | + path: ['paths', '//doubleSlashAtStart'], |
| 164 | + severity: DiagnosticSeverity.Warning, |
| 165 | + }, |
| 166 | + ], |
| 167 | + }, |
| 168 | + { |
| 169 | + name: 'handles paths with trailing slashes', |
| 170 | + document: { |
| 171 | + paths: { |
| 172 | + '/api/users/': {}, |
| 173 | + '/resources/{resourceId}/': {}, |
| 174 | + }, |
| 175 | + }, |
| 176 | + errors: [], |
| 177 | + }, |
| 178 | + { |
| 179 | + name: 'detects multiple failures across a single path', |
| 180 | + document: { |
| 181 | + paths: { |
| 182 | + '/API/Resource_groups/{userId}/User-profiles': {}, |
| 183 | + }, |
| 184 | + }, |
| 185 | + errors: [ |
| 186 | + { |
| 187 | + code: 'xgen-IPA-102-collection-identifier-camelCase', |
| 188 | + message: |
| 189 | + "Collection identifiers must be in camelCase. Path segment 'API' in path '/API/Resource_groups/{userId}/User-profiles' is not in camelCase. http://go/ipa/102", |
| 190 | + path: ['paths', '/API/Resource_groups/{userId}/User-profiles'], |
| 191 | + severity: DiagnosticSeverity.Warning, |
| 192 | + }, |
| 193 | + { |
| 194 | + code: 'xgen-IPA-102-collection-identifier-camelCase', |
| 195 | + message: |
| 196 | + "Collection identifiers must be in camelCase. Path segment 'Resource_groups' in path '/API/Resource_groups/{userId}/User-profiles' is not in camelCase. http://go/ipa/102", |
| 197 | + path: ['paths', '/API/Resource_groups/{userId}/User-profiles'], |
| 198 | + severity: DiagnosticSeverity.Warning, |
| 199 | + }, |
| 200 | + { |
| 201 | + code: 'xgen-IPA-102-collection-identifier-camelCase', |
| 202 | + message: |
| 203 | + "Collection identifiers must be in camelCase. Path segment 'User-profiles' in path '/API/Resource_groups/{userId}/User-profiles' is not in camelCase. http://go/ipa/102", |
| 204 | + path: ['paths', '/API/Resource_groups/{userId}/User-profiles'], |
| 205 | + severity: DiagnosticSeverity.Warning, |
| 206 | + }, |
| 207 | + ], |
| 208 | + }, |
| 209 | + { |
| 210 | + name: 'handles mixed valid and invalid segments with custom methods', |
| 211 | + document: { |
| 212 | + paths: { |
| 213 | + '/api/Valid/Invalid_resource/{id}:validCustomMethod': {}, |
| 214 | + }, |
| 215 | + }, |
| 216 | + errors: [ |
| 217 | + { |
| 218 | + code: 'xgen-IPA-102-collection-identifier-camelCase', |
| 219 | + message: |
| 220 | + "Collection identifiers must be in camelCase. Path segment 'Valid' in path '/api/Valid/Invalid_resource/{id}:validCustomMethod' is not in camelCase. http://go/ipa/102", |
| 221 | + path: ['paths', '/api/Valid/Invalid_resource/{id}:validCustomMethod'], |
| 222 | + severity: DiagnosticSeverity.Warning, |
| 223 | + }, |
| 224 | + { |
| 225 | + code: 'xgen-IPA-102-collection-identifier-camelCase', |
| 226 | + message: |
| 227 | + "Collection identifiers must be in camelCase. Path segment 'Invalid_resource' in path '/api/Valid/Invalid_resource/{id}:validCustomMethod' is not in camelCase. http://go/ipa/102", |
| 228 | + path: ['paths', '/api/Valid/Invalid_resource/{id}:validCustomMethod'], |
| 229 | + severity: DiagnosticSeverity.Warning, |
| 230 | + }, |
| 231 | + ], |
| 232 | + }, |
| 233 | + { |
| 234 | + name: 'handles double slashes with invalid segments - both issues reported', |
| 235 | + document: { |
| 236 | + paths: { |
| 237 | + '/api//Invalid_segment//resources': {}, |
| 238 | + }, |
| 239 | + }, |
| 240 | + errors: [ |
| 241 | + { |
| 242 | + code: 'xgen-IPA-102-collection-identifier-camelCase', |
| 243 | + message: |
| 244 | + "Collection identifiers must be in camelCase. Path '/api//Invalid_segment//resources' contains double slashes (//) which is not allowed. http://go/ipa/102", |
| 245 | + path: ['paths', '/api//Invalid_segment//resources'], |
| 246 | + severity: DiagnosticSeverity.Warning, |
| 247 | + }, |
| 248 | + { |
| 249 | + code: 'xgen-IPA-102-collection-identifier-camelCase', |
| 250 | + message: |
| 251 | + "Collection identifiers must be in camelCase. Path segment 'Invalid_segment' in path '/api//Invalid_segment//resources' is not in camelCase. http://go/ipa/102", |
| 252 | + path: ['paths', '/api//Invalid_segment//resources'], |
| 253 | + severity: DiagnosticSeverity.Warning, |
| 254 | + }, |
| 255 | + ], |
| 256 | + }, |
| 257 | +]); |
0 commit comments