Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add spectral rules #20 #229

Merged
merged 5 commits into from
Aug 19, 2024
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
106 changes: 106 additions & 0 deletions .spectral.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
# Source: https://docs.stoplight.io/docs/spectral/4dec24461f3af-open-api-rules
extends:
- spectral:oas
rules:
# API 버전 규칙 : v로 시작하고 숫자와 점으로 이루어져야 함
api-version-convention:
description: API version should follow the convention
given: $.info.version
severity: error
then:
function: pattern
functionOptions:
match: "^v[0-9\\.]+$"
message: API version should follow the convention v1, v2.1, v3.0.1, etc.

# 모든 엔드포인트는 tags를 포함해야 함
operation-tags-convention:
description: All Operation should include tags
given: $.paths[*][*]
severity: error
then:
- field: tags
function: truthy
message: Tags are required

# 모든 엔드포인트는 operationId를 포함해야 함 (.WithName 으로 지정)
operation-operationid-convention:
description: All Operation should include operationId
given: $.paths[*][*]
severity: error
then:
- field: operationId
function: truthy
message: OperationId is required

# 모든 엔드포인트는 summary와 description을 포함해야 함
operation-summary-description-convention:
description: All Operation should include summary and description
given: $.paths[*][*]
severity: error
then:
- field: 'summary'
function: truthy
message: Summary is required
- field: 'description'
function: truthy
message: Description is required

# Post 요청의 경우 requestbody가 정의되어 있어야함
operation-request-convention:
description: Post Operation should include request body
given: $.paths[*].post
severity: error
then:
- field: requestBody
function: truthy
message: Request body is required

# Get 요청의 경우 parameters가 정의되어 있어야함
# 규칙관리를 위해 각주만 유지, spectral(path-params)에서 이미 검사중임

# 응답이 정의되어 있어야함
operation-response-convention:
description: All Operation should include response
given: $.paths[*][*]
severity: error
then:
- field: responses
function: truthy
message: Responses are required

# 응답 코드 규칙 : 200, 401, 500 응답 코드가 있어야 함
operation-responsecode-convention:
description: All Operation response should include 200, 401, 500
given: $.paths[*][*].responses
severity: error
then:
- field: '200'
function: truthy
message: Response 200 is required
- field: '401'
function: truthy
message: Response 401 is required
- field: '500'
function: truthy
message: Response 500 is required

# 모든 응답 코드는 descriptioin을 포함해야함
operation-responsedetail-description-convention:
description: All Operation response should include description
given: $.paths[*][*].responses[*]
severity: error
then:
- field: 'description'
function: truthy
message: Description is required

# 401을 제외한 모든 응답 코드는 content를 포함해야함
operation-responsedetail-content-convention:
description: All Operation response might include content, except 401
given: $.paths[*][*].responses[?(@property != '401')]
severity: error
then:
- field: 'content'
function: truthy
message: Content is required
Loading