|
| 1 | +import testRule from './__helpers__/testRule'; |
| 2 | +import { DiagnosticSeverity } from '@stoplight/types'; |
| 3 | + |
| 4 | +testRule('xgen-IPA-102-path-alternate-resource-name-path-param', [ |
| 5 | + { |
| 6 | + name: 'valid paths - api/atlas/v2', |
| 7 | + document: { |
| 8 | + paths: { |
| 9 | + '/api/atlas/v2/resourceName': {}, |
| 10 | + '/api/atlas/v2/resourceName/{pathParam}': {}, |
| 11 | + '/api/atlas/v2/resourceName1/{pathParam}/resourceName2': {}, |
| 12 | + '/api/atlas/v2/resourceName1/{pathParam1p}/resourceName2/{pathParam2}': {}, |
| 13 | + '/api/atlas/v2/resourceName/{pathParam}:method': {}, |
| 14 | + '/api/atlas/v2/custom:method': {}, |
| 15 | + '/api/atlas/v2': {}, |
| 16 | + }, |
| 17 | + }, |
| 18 | + errors: [], |
| 19 | + }, |
| 20 | + { |
| 21 | + name: 'valid paths - api/atlas/v2/unauth', |
| 22 | + document: { |
| 23 | + paths: { |
| 24 | + '/api/atlas/v2/unauth/resourceName': {}, |
| 25 | + '/api/atlas/v2/unauth/resourceName/{pathParam}': {}, |
| 26 | + '/api/atlas/v2/unauth/resourceName1/{pathParam}/resourceName2': {}, |
| 27 | + '/api/atlas/v2/unauth/resourceName1/{pathParam1p}/resourceName2/{pathParam2}': {}, |
| 28 | + '/api/atlas/v2/unauth/resourceName/{pathParam}:method': {}, |
| 29 | + '/api/atlas/v2/unauth/custom:method': {}, |
| 30 | + '/api/atlas/v2/unauth': {}, |
| 31 | + }, |
| 32 | + }, |
| 33 | + errors: [], |
| 34 | + }, |
| 35 | + { |
| 36 | + name: 'invalid paths - api/atlas/v2', |
| 37 | + document: { |
| 38 | + paths: { |
| 39 | + '/api/atlas/v2/resourceName1/resourceName2': {}, |
| 40 | + '/api/atlas/v2/resourceName/{pathParam1}/{pathParam2}': {}, |
| 41 | + '/api/atlas/v2/resourceName1/{pathParam1}/resourceName2/resourceName3': {}, |
| 42 | + '/api/atlas/v2/resourceName1/{pathParam1}/resourceName2/{pathParam2}/{pathParam3}': {}, |
| 43 | + '/api/atlas/v2/{pathParam}': {}, |
| 44 | + '/api/atlas/v2/{pathParam1}/{pathParam2}': {}, |
| 45 | + }, |
| 46 | + }, |
| 47 | + errors: [ |
| 48 | + { |
| 49 | + code: 'xgen-IPA-102-path-alternate-resource-name-path-param', |
| 50 | + message: 'API paths must alternate between resource name and path params. http://go/ipa/102', |
| 51 | + path: ['paths', '/api/atlas/v2/resourceName1/resourceName2'], |
| 52 | + severity: DiagnosticSeverity.Warning, |
| 53 | + }, |
| 54 | + { |
| 55 | + code: 'xgen-IPA-102-path-alternate-resource-name-path-param', |
| 56 | + message: 'API paths must alternate between resource name and path params. http://go/ipa/102', |
| 57 | + path: ['paths', '/api/atlas/v2/resourceName/{pathParam1}/{pathParam2}'], |
| 58 | + severity: DiagnosticSeverity.Warning, |
| 59 | + }, |
| 60 | + { |
| 61 | + code: 'xgen-IPA-102-path-alternate-resource-name-path-param', |
| 62 | + message: 'API paths must alternate between resource name and path params. http://go/ipa/102', |
| 63 | + path: ['paths', '/api/atlas/v2/resourceName1/{pathParam1}/resourceName2/resourceName3'], |
| 64 | + severity: DiagnosticSeverity.Warning, |
| 65 | + }, |
| 66 | + { |
| 67 | + code: 'xgen-IPA-102-path-alternate-resource-name-path-param', |
| 68 | + message: 'API paths must alternate between resource name and path params. http://go/ipa/102', |
| 69 | + path: ['paths', '/api/atlas/v2/resourceName1/{pathParam1}/resourceName2/{pathParam2}/{pathParam3}'], |
| 70 | + severity: DiagnosticSeverity.Warning, |
| 71 | + }, |
| 72 | + { |
| 73 | + code: 'xgen-IPA-102-path-alternate-resource-name-path-param', |
| 74 | + message: 'API paths must alternate between resource name and path params. http://go/ipa/102', |
| 75 | + path: ['paths', '/api/atlas/v2/{pathParam}'], |
| 76 | + severity: DiagnosticSeverity.Warning, |
| 77 | + }, |
| 78 | + { |
| 79 | + code: 'xgen-IPA-102-path-alternate-resource-name-path-param', |
| 80 | + message: 'API paths must alternate between resource name and path params. http://go/ipa/102', |
| 81 | + path: ['paths', '/api/atlas/v2/{pathParam1}/{pathParam2}'], |
| 82 | + severity: DiagnosticSeverity.Warning, |
| 83 | + }, |
| 84 | + ], |
| 85 | + }, |
| 86 | + { |
| 87 | + name: 'invalid paths - api/atlas/v2/unauth', |
| 88 | + document: { |
| 89 | + paths: { |
| 90 | + '/api/atlas/v2/unauth/resourceName1/resourceName2': {}, |
| 91 | + '/api/atlas/v2/unauth/resourceName/{pathParam1}/{pathParam2}': {}, |
| 92 | + '/api/atlas/v2/unauth/resourceName1/{pathParam1}/resourceName2/resourceName3': {}, |
| 93 | + '/api/atlas/v2/unauth/resourceName1/{pathParam1}/resourceName2/{pathParam2}/{pathParam3}': {}, |
| 94 | + '/api/atlas/v2/unauth/{pathParam}': {}, |
| 95 | + '/api/atlas/v2/unauth/{pathParam1}/{pathParam2}': {}, |
| 96 | + }, |
| 97 | + }, |
| 98 | + errors: [ |
| 99 | + { |
| 100 | + code: 'xgen-IPA-102-path-alternate-resource-name-path-param', |
| 101 | + message: 'API paths must alternate between resource name and path params. http://go/ipa/102', |
| 102 | + path: ['paths', '/api/atlas/v2/unauth/resourceName1/resourceName2'], |
| 103 | + severity: DiagnosticSeverity.Warning, |
| 104 | + }, |
| 105 | + { |
| 106 | + code: 'xgen-IPA-102-path-alternate-resource-name-path-param', |
| 107 | + message: 'API paths must alternate between resource name and path params. http://go/ipa/102', |
| 108 | + path: ['paths', '/api/atlas/v2/unauth/resourceName/{pathParam1}/{pathParam2}'], |
| 109 | + severity: DiagnosticSeverity.Warning, |
| 110 | + }, |
| 111 | + { |
| 112 | + code: 'xgen-IPA-102-path-alternate-resource-name-path-param', |
| 113 | + message: 'API paths must alternate between resource name and path params. http://go/ipa/102', |
| 114 | + path: ['paths', '/api/atlas/v2/unauth/resourceName1/{pathParam1}/resourceName2/resourceName3'], |
| 115 | + severity: DiagnosticSeverity.Warning, |
| 116 | + }, |
| 117 | + { |
| 118 | + code: 'xgen-IPA-102-path-alternate-resource-name-path-param', |
| 119 | + message: 'API paths must alternate between resource name and path params. http://go/ipa/102', |
| 120 | + path: ['paths', '/api/atlas/v2/unauth/resourceName1/{pathParam1}/resourceName2/{pathParam2}/{pathParam3}'], |
| 121 | + severity: DiagnosticSeverity.Warning, |
| 122 | + }, |
| 123 | + { |
| 124 | + code: 'xgen-IPA-102-path-alternate-resource-name-path-param', |
| 125 | + message: 'API paths must alternate between resource name and path params. http://go/ipa/102', |
| 126 | + path: ['paths', '/api/atlas/v2/unauth/{pathParam}'], |
| 127 | + severity: DiagnosticSeverity.Warning, |
| 128 | + }, |
| 129 | + { |
| 130 | + code: 'xgen-IPA-102-path-alternate-resource-name-path-param', |
| 131 | + message: 'API paths must alternate between resource name and path params. http://go/ipa/102', |
| 132 | + path: ['paths', '/api/atlas/v2/unauth/{pathParam1}/{pathParam2}'], |
| 133 | + severity: DiagnosticSeverity.Warning, |
| 134 | + }, |
| 135 | + ], |
| 136 | + }, |
| 137 | +]); |
0 commit comments