|
| 1 | +import testRule from './__helpers__/testRule'; |
| 2 | +import { DiagnosticSeverity } from '@stoplight/types'; |
| 3 | + |
| 4 | +testRule('xgen-IPA-109-custom-method-identifier-format', [ |
| 5 | + { |
| 6 | + name: 'valid custom method formats', |
| 7 | + document: { |
| 8 | + paths: { |
| 9 | + '/resource:customMethod': {}, |
| 10 | + '/resource/{resourceId}:customMethod': {}, |
| 11 | + '/resource/{resourceId}/subresource:customMethod': {}, |
| 12 | + '/resource/{resourceId}/subresource/{resourceId}:customMethod': {}, |
| 13 | + '/resource/subresource/{resourceId}:customMethod': {}, |
| 14 | + '/resource/{resourceId}/subresource/{resourceId}/nested:customMethod': {}, |
| 15 | + '/resource/{resourceId}/subresource/{resourceId}/nested/{resourceId}:customMethod': {}, |
| 16 | + '/resource/subresource/nested/{resourceId}:customMethod': {}, |
| 17 | + }, |
| 18 | + }, |
| 19 | + errors: [], |
| 20 | + }, |
| 21 | + { |
| 22 | + name: 'invalid custom method formats not validated by this rule', |
| 23 | + document: { |
| 24 | + paths: { |
| 25 | + '/resources:custom&method': {}, |
| 26 | + '/resources:custom/method': {}, |
| 27 | + }, |
| 28 | + }, |
| 29 | + errors: [], |
| 30 | + }, |
| 31 | + { |
| 32 | + name: 'invalid custom method with exception', |
| 33 | + document: { |
| 34 | + paths: { |
| 35 | + '/resources/:customMethod': { |
| 36 | + 'x-xgen-IPA-exception': { |
| 37 | + 'xgen-IPA-109-custom-method-identifier-format': 'exception reason', |
| 38 | + }, |
| 39 | + }, |
| 40 | + '/resources:{resourceId}:customMethod': { |
| 41 | + 'x-xgen-IPA-exception': { |
| 42 | + 'xgen-IPA-109-custom-method-identifier-format': 'exception reason', |
| 43 | + }, |
| 44 | + }, |
| 45 | + }, |
| 46 | + }, |
| 47 | + errors: [], |
| 48 | + }, |
| 49 | + { |
| 50 | + name: 'invalid custom method formats', |
| 51 | + document: { |
| 52 | + paths: { |
| 53 | + '/resources/:customMethod': {}, |
| 54 | + '/resources:{resourceId}:customMethod': {}, |
| 55 | + '/resources/:{resourceId}:customMethod': {}, |
| 56 | + '/:customMethod': {}, |
| 57 | + '/resources/{resourceId}/:customMethod': {}, |
| 58 | + '/resources/{resourceId}:custom::Method': {}, |
| 59 | + }, |
| 60 | + }, |
| 61 | + errors: [ |
| 62 | + { |
| 63 | + code: 'xgen-IPA-109-custom-method-identifier-format', |
| 64 | + message: |
| 65 | + "The path /resources/:customMethod contains a '/' before a custom method. Custom methods should not start with a '/'.", |
| 66 | + path: ['paths', '/resources/:customMethod'], |
| 67 | + severity: DiagnosticSeverity.Error, |
| 68 | + }, |
| 69 | + { |
| 70 | + code: 'xgen-IPA-109-custom-method-identifier-format', |
| 71 | + message: 'Multiple colons found in "/resources:{resourceId}:customMethod"', |
| 72 | + path: ['paths', '/resources:{resourceId}:customMethod'], |
| 73 | + severity: DiagnosticSeverity.Error, |
| 74 | + }, |
| 75 | + { |
| 76 | + code: 'xgen-IPA-109-custom-method-identifier-format', |
| 77 | + message: 'Multiple colons found in "/resources/:{resourceId}:customMethod".', |
| 78 | + path: ['paths', '/resources/:{resourceId}:customMethod'], |
| 79 | + severity: DiagnosticSeverity.Error, |
| 80 | + }, |
| 81 | + { |
| 82 | + code: 'xgen-IPA-109-custom-method-identifier-format', |
| 83 | + message: |
| 84 | + "The path /:customMethod contains a '/' before a custom method. Custom methods should not start with a '/'.", |
| 85 | + path: ['paths', '/:customMethod'], |
| 86 | + severity: DiagnosticSeverity.Error, |
| 87 | + }, |
| 88 | + { |
| 89 | + code: 'xgen-IPA-109-custom-method-identifier-format', |
| 90 | + message: |
| 91 | + "The path /resources/{resourceId}/:customMethod contains a \'/\' before a custom method. Custom methods should not start with a \'/\'.", |
| 92 | + path: ['paths', '/resources/{resourceId}/:customMethod'], |
| 93 | + severity: DiagnosticSeverity.Error, |
| 94 | + }, |
| 95 | + { |
| 96 | + code: 'xgen-IPA-109-custom-method-identifier-format', |
| 97 | + message: 'Multiple colons found in "/resources/{resourceId}:custom::Method".', |
| 98 | + path: ['paths', '/resources/{resourceId}:custom::Method'], |
| 99 | + severity: DiagnosticSeverity.Error, |
| 100 | + }, |
| 101 | + ], |
| 102 | + }, |
| 103 | +]); |
0 commit comments