|
| 1 | +# Source: https://docs.stoplight.io/docs/spectral/4dec24461f3af-open-api-rules |
| 2 | +extends: |
| 3 | + - spectral:oas |
| 4 | +rules: |
| 5 | + # API 버전 규칙 : v로 시작하고 숫자와 점으로 이루어져야 함 |
| 6 | + api-version-convention: |
| 7 | + description: API version should follow the convention |
| 8 | + given: $.info.version |
| 9 | + severity: error |
| 10 | + then: |
| 11 | + function: pattern |
| 12 | + functionOptions: |
| 13 | + match: "^v[0-9\\.]+$" |
| 14 | + message: API version should follow the convention v1, v2.1, v3.0.1, etc. |
| 15 | + |
| 16 | + # 모든 엔드포인트는 tags를 포함해야 함 |
| 17 | + operation-tags-convention: |
| 18 | + description: All Operation should include tags |
| 19 | + given: $.paths[*][*] |
| 20 | + severity: error |
| 21 | + then: |
| 22 | + - field: tags |
| 23 | + function: truthy |
| 24 | + message: Tags are required |
| 25 | + |
| 26 | + # 모든 엔드포인트는 operationId를 포함해야 함 (.WithName 으로 지정) |
| 27 | + operation-operationid-convention: |
| 28 | + description: All Operation should include operationId |
| 29 | + given: $.paths[*][*] |
| 30 | + severity: error |
| 31 | + then: |
| 32 | + - field: operationId |
| 33 | + function: truthy |
| 34 | + message: OperationId is required |
| 35 | + |
| 36 | + # 모든 엔드포인트는 summary와 description을 포함해야 함 |
| 37 | + operation-summary-description-convention: |
| 38 | + description: All Operation should include summary and description |
| 39 | + given: $.paths[*][*] |
| 40 | + severity: error |
| 41 | + then: |
| 42 | + - field: 'summary' |
| 43 | + function: truthy |
| 44 | + message: Summary is required |
| 45 | + - field: 'description' |
| 46 | + function: truthy |
| 47 | + message: Description is required |
| 48 | + |
| 49 | + # 응답이 정의되어 있어야함 |
| 50 | + operation-response-convention: |
| 51 | + description: All Operation should include response |
| 52 | + given: $.paths[*][*] |
| 53 | + severity: error |
| 54 | + then: |
| 55 | + - field: responses |
| 56 | + function: truthy |
| 57 | + message: Responses are required |
| 58 | + |
| 59 | + # 응답 코드 규칙 : 200, 401, 500 응답 코드가 있어야 함 |
| 60 | + operation-responsecode-convention: |
| 61 | + description: All Operation response should include 200, 401, 500 |
| 62 | + given: $.paths[*][*].responses |
| 63 | + severity: error |
| 64 | + then: |
| 65 | + - field: '200' |
| 66 | + function: truthy |
| 67 | + message: Response 200 is required |
| 68 | + - field: '401' |
| 69 | + function: truthy |
| 70 | + message: Response 401 is required |
| 71 | + - field: '500' |
| 72 | + function: truthy |
| 73 | + message: Response 500 is required |
| 74 | + |
| 75 | + # 401을 제외한 모든 응답 코드는 content를 포함해야함 |
| 76 | + operation-responsedetail-content-convention: |
| 77 | + description: All Operation response might include content, except 401 |
| 78 | + given: $.paths[*][*].responses[?(@property != '401')] |
| 79 | + severity: error |
| 80 | + then: |
| 81 | + - field: 'content' |
| 82 | + function: truthy |
| 83 | + message: Content is required |
0 commit comments