Skip to content

Commit

Permalink
Feat: Provided a way to test a valid/invalid OpenApi Document against…
Browse files Browse the repository at this point in the history
… the rules created using Spectrals CLI command.
  • Loading branch information
ezenity committed Dec 1, 2023
1 parent 1adfb06 commit bb0d476
Show file tree
Hide file tree
Showing 2 changed files with 398 additions and 0 deletions.
204 changes: 204 additions & 0 deletions cliTest/errorsErrorObject/failing-rules.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,204 @@
# This OpenAPI Document provides a way of testing all the rules for `jsonapi-errors-error-object.js`
# using Spectrals CLI Command
#
# Usage:
# spectral lint cliTest/errorsErrorObject/failing-rules.yaml --ruleset rules/jsonapi-errors-error-object.js
#
# This document will generate `22 errors` as expected for each rule.
openapi: 3.1.0
info:
title: User Information API
version: 1.0.0
description: API for retrieving user information
paths:
/users/{userId}:
get:
tags:
- users
summary: Get User by ID
description: Retrieves information for a specific user by their ID.
operationId: getUserById
parameters:
- name: userId
in: path
required: true
description: Unique identifier of the user
schema:
type: string
responses:
'200':
description: Successful response with user information
content:
application/vnd.api+json:
schema:
type: object
properties:
data:
type: object
properties:
id:
type: string
type:
type: string
enum:
- user
attributes:
type: object
properties:
name:
type: string
email:
type: string
examples:
user:
summary: User Example
value:
data:
id: '12345'
type: user
attributes:
name: John Doe
email: [email protected]
'400':
description: Bad Request
content:
application/vnd.api+json:
schema:
type: object
properties:
errors:
type: string
items:
type: object
properties:
idd:
type: string
id:
type: object
links:
type: string
properties:
about:
type: object
format: urie
aboutt:
type: string
format: uri
type:
type: object
format: urii
status:
type: object
code:
type: object
title:
type: object
detail:
type: object
source:
type: string
properties:
pointer:
type: object
parameter:
type: object
header:
type: object
headerr:
type: string
meta:
type: string
additionalProperties: true
required:
- detail
'404':
description: User Not Found
content:
application/vnd.api+json:
schema:
type: object
properties:
errors:
type: array
items:
type: object
properties:
id:
type: string
links:
type: object
properties:
about:
type: string
format: uri
status:
type: string
code:
type: string
title:
type: string
detail:
type: string
source:
type: object
properties:
pointer:
type: string
parameter:
type: string
header:
type: string
meta:
type: object
additionalProperties: true
required:
- detail
'500':
description: Internal Server Error
content:
application/vnd.api+json:
schema:
type: object
properties:
errors:
type: array
items:
type: object
properties:
id:
type: string
links:
type: object
properties:
about:
type: string
format: uri
status:
type: string
code:
type: string
title:
type: string
detail:
type: string
source:
type: object
properties:
pointer:
type: string
parameter:
type: string
header:
type: string
meta:
type: object
additionalProperties: true
required:
- detail
components:
schemas:
Test:
type: object
properties:
test:
type: string
194 changes: 194 additions & 0 deletions cliTest/errorsErrorObject/passing-rules.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,194 @@
# This OpenAPI Document provides a way of testing all the rules for `jsonapi-errors-error-object.js`
# using Spectrals CLI Command
#
# Usage:
# spectral lint cliTest/errorsErrorObject/passing-rules.yaml --ruleset rules/jsonapi-errors-error-object.js
#
# This document will generate `0 errors` as expected for each rule.
openapi: 3.1.0
info:
title: User Information API
version: 1.0.0
description: API for retrieving user information
paths:
/users/{userId}:
get:
tags:
- users
summary: Get User by ID
description: Retrieves information for a specific user by their ID.
operationId: getUserById
parameters:
- name: userId
in: path
required: true
description: Unique identifier of the user
schema:
type: string
responses:
'200':
description: Successful response with user information
content:
application/vnd.api+json:
schema:
type: object
properties:
data:
type: object
properties:
id:
type: string
type:
type: string
enum:
- user
attributes:
type: object
properties:
name:
type: string
email:
type: string
examples:
user:
summary: User Example
value:
data:
id: '12345'
type: user
attributes:
name: John Doe
email: [email protected]
'400':
description: Bad Request
content:
application/vnd.api+json:
schema:
type: object
properties:
errors:
type: array
items:
type: object
properties:
id:
type: string
links:
type: object
properties:
about:
type: string
format: uri
status:
type: string
code:
type: string
title:
type: string
detail:
type: string
source:
type: object
properties:
pointer:
type: string
parameter:
type: string
header:
type: string
meta:
type: object
additionalProperties: true
required:
- detail
'404':
description: User Not Found
content:
application/vnd.api+json:
schema:
type: object
properties:
errors:
type: array
items:
type: object
properties:
id:
type: string
links:
type: object
properties:
about:
type: string
format: uri
status:
type: string
code:
type: string
title:
type: string
detail:
type: string
source:
type: object
properties:
pointer:
type: string
parameter:
type: string
header:
type: string
meta:
type: object
additionalProperties: true
required:
- detail
'500':
description: Internal Server Error
content:
application/vnd.api+json:
schema:
type: object
properties:
errors:
type: array
items:
type: object
properties:
id:
type: string
links:
type: object
properties:
about:
type: string
format: uri
status:
type: string
code:
type: string
title:
type: string
detail:
type: string
source:
type: object
properties:
pointer:
type: string
parameter:
type: string
header:
type: string
meta:
type: object
additionalProperties: true
required:
- detail
components:
schemas:
Test:
type: object
properties:
test:
type: string

0 comments on commit bb0d476

Please sign in to comment.