-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Completion of remaining JSON:API Errors.ErrorObjects Ruels and Test C…
…ases - Fully implemented and documented Spectral rules for JSON:API Errors.ErrorObjects as per JSON:API Specifications. - Each rule checks specific aspects of the error objects, ensuring adherence to standards like array structure, member types, and URI formats. - Added comprehensive test cases for all rules covering both positive and negative scenarios. This includes checks for array structures, object member validation, type enforcement, and specific member values. - Enhanced documentation with detail jsdocs for key areas including helper functions, complex rule logic, JSONPath expressions, and individual test cases. This aims to improve code readability and maintainability. - Included specific test documents for both valid and invalid API structures to validate each rule thoroughly. - Conducted rigorous testing to ensure all rules and test cases function as expected, with a focus on reliability and accuracy in error object validation. This commit represents a complete and robust solution for validation JSON:API error objects, ensuring compliance with the JSON:API specification and enhacning the overall quality of API error handling.
- Loading branch information
Showing
15 changed files
with
3,376 additions
and
152 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
199 changes: 199 additions & 0 deletions
199
test/docs/errors/errorObjects/invalidApiDocumentItemsCodeType.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,199 @@ | ||
/* eslint-env mocha */ | ||
/* eslint-disable quotes */ | ||
const invalidApiDocumentItemsCodeType = { | ||
"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" | ||
} | ||
// Other user attributes... | ||
} | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
"examples": { | ||
"user": { | ||
"summary": "User Example", | ||
"value": { | ||
"data": { | ||
"id": "12345", | ||
"type": "user", | ||
"attributes": { | ||
"name": "John Doe", | ||
"email": "[email protected]" | ||
// Other user attributes... | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
"400": { | ||
"description": "Bad Request", | ||
"content": { | ||
"application/vnd.api+json": { | ||
"schema": { | ||
"$ref": "#/components/schemas/JsonApiError" | ||
} | ||
} | ||
} | ||
}, | ||
"404": { | ||
"description": "User Not Found", | ||
"content": { | ||
"application/vnd.api+json": { | ||
"schema": { | ||
"$ref": "#/components/schemas/JsonApiError" | ||
} | ||
} | ||
} | ||
}, | ||
"500": { | ||
"description": "Internal Server Error", | ||
"content": { | ||
"application/vnd.api+json": { | ||
"schema": { | ||
"$ref": "#/components/schemas/JsonApiError" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
"components": { | ||
"schemas": { | ||
"Test": { | ||
"type": "object", | ||
"properties": { | ||
"test": { | ||
"type": "string" | ||
} | ||
} | ||
}, | ||
"JsonApiError": { | ||
"type": "object", | ||
"properties": { | ||
"errors": { | ||
"type": "array", | ||
"items": { | ||
"$ref": "#/components/schemas/ErrorObject" | ||
} | ||
} | ||
} | ||
}, | ||
"ErrorObject": { | ||
"type": "object", | ||
"properties": { | ||
"id": { | ||
"type": "string" | ||
}, | ||
"links": { | ||
"type": "object", | ||
"properties": { | ||
"about": { | ||
"type": "string", | ||
"format": "uri" | ||
}, | ||
"type": { | ||
"type": "string", | ||
"format": "uri" | ||
} | ||
} | ||
}, | ||
"status": { | ||
"type": "string" | ||
}, | ||
"code": { | ||
// Original: "string" | ||
"type": "object" | ||
}, | ||
"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" | ||
] | ||
} | ||
} | ||
} | ||
}; | ||
|
||
export default invalidApiDocumentItemsCodeType; |
199 changes: 199 additions & 0 deletions
199
test/docs/errors/errorObjects/invalidApiDocumentItemsDetailType.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,199 @@ | ||
/* eslint-env mocha */ | ||
/* eslint-disable quotes */ | ||
const invalidApiDocumentItemsDetailType = { | ||
"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" | ||
} | ||
// Other user attributes... | ||
} | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
"examples": { | ||
"user": { | ||
"summary": "User Example", | ||
"value": { | ||
"data": { | ||
"id": "12345", | ||
"type": "user", | ||
"attributes": { | ||
"name": "John Doe", | ||
"email": "[email protected]" | ||
// Other user attributes... | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
"400": { | ||
"description": "Bad Request", | ||
"content": { | ||
"application/vnd.api+json": { | ||
"schema": { | ||
"$ref": "#/components/schemas/JsonApiError" | ||
} | ||
} | ||
} | ||
}, | ||
"404": { | ||
"description": "User Not Found", | ||
"content": { | ||
"application/vnd.api+json": { | ||
"schema": { | ||
"$ref": "#/components/schemas/JsonApiError" | ||
} | ||
} | ||
} | ||
}, | ||
"500": { | ||
"description": "Internal Server Error", | ||
"content": { | ||
"application/vnd.api+json": { | ||
"schema": { | ||
"$ref": "#/components/schemas/JsonApiError" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
"components": { | ||
"schemas": { | ||
"Test": { | ||
"type": "object", | ||
"properties": { | ||
"test": { | ||
"type": "string" | ||
} | ||
} | ||
}, | ||
"JsonApiError": { | ||
"type": "object", | ||
"properties": { | ||
"errors": { | ||
"type": "array", | ||
"items": { | ||
"$ref": "#/components/schemas/ErrorObject" | ||
} | ||
} | ||
} | ||
}, | ||
"ErrorObject": { | ||
"type": "object", | ||
"properties": { | ||
"id": { | ||
"type": "string" | ||
}, | ||
"links": { | ||
"type": "object", | ||
"properties": { | ||
"about": { | ||
"type": "string", | ||
"format": "uri" | ||
}, | ||
"type": { | ||
"type": "string", | ||
"format": "uri" | ||
} | ||
} | ||
}, | ||
"status": { | ||
"type": "string" | ||
}, | ||
"code": { | ||
"type": "string" | ||
}, | ||
"title": { | ||
"type": "string" | ||
}, | ||
"detail": { | ||
// Orinigal: "string" | ||
"type": "object" | ||
}, | ||
"source": { | ||
"type": "object", | ||
"properties": { | ||
"pointer": { | ||
"type": "string" | ||
}, | ||
"parameter": { | ||
"type": "string" | ||
}, | ||
"header": { | ||
"type": "string" | ||
} | ||
} | ||
}, | ||
"meta": { | ||
"type": "object", | ||
"additionalProperties": true | ||
} | ||
}, | ||
"required": [ | ||
"detail" | ||
] | ||
} | ||
} | ||
} | ||
}; | ||
|
||
export default invalidApiDocumentItemsDetailType; |
Oops, something went wrong.