-
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.
API-30 FetchingData.FetchingResources (#55)
* Initial Setup * Feat: Adding New Spectral Ruleset This commit introduces a new set of Spectral rules specifically tailored for validating JSON:API v1.0 Fetching Data - Fetching Resources within an OpenAPI Document. Key highlights include: - Creation of Spectral rules to ensure compliance with JSON:API v1.0 standards, focusing on Fetching Resources specifications. - Validating that a server MUST supprt fetching resource data for every URL that is provided to a strict format. These additions significantly improve our capability to automatically validate and ensure the consistency of API responses with the JSON:API v1.0 standard. * Enhance: refactored valid OpenAPI Template This document serves as a standardized template for verifying positive test scenarios in ruleset development. To ensure that the document can be tested against multiple rulesets, the design and endpoints were refactored. This document is now closer to adhering to JSON:API v1.0 specifications. Covered sections include: - ContentNegotiation.ClientResponsibilities - ContentNegotiation.ServerResponsibilities - DocumentStructure - DocumentStructure.TopLevel - DocumentStructure.ResourceObjects - DocumentStructure.ResourceObjects.Attributes - DocumentStructure.Links - DocumentStructure.MetaInformation - DocumentStructure.MemberNames - FetchingData.FetchingResources - FetchingData.Sorting - FetchingData.Pagination - FetchingData.Filtering - Errors.ProcessingErrors - Errors.ErrorObjects * Feat: Test Case Completion This commit marks the completion of detailed test cases for all of the JSON:API v1.0 Fetching Data - Fetching Resources ruleset. These updates significantly improve the robustness and relaibility of the JSON:API v1.0 specifications for Fetching Resources validation process. * Feat: Passing/Failing OpenAPI Documents for Spectral CLI Testing - These two files provides a way to test all the created rules for both positive and negative scenarios. - Created a failing-rules.yaml which generates a way to trigger all the rules to display the error message - Updated the passing-rules.yaml to adhere to the specifications of JSON:API v1.0 for Fetching Resources.
- Loading branch information
Showing
12 changed files
with
6,210 additions
and
2 deletions.
There are no files selected for viewing
1,262 changes: 1,262 additions & 0 deletions
1,262
cliTest/fetchingData/fetchingResources/failing-rules.yaml
Large diffs are not rendered by default.
Oops, something went wrong.
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
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,82 @@ | ||
// Fetching Data - Fetching Resources - https://jsonapi.org/format/1.0/#fetching-resources | ||
|
||
// All rules in the file MUST have corresponding tests | ||
|
||
import { truthy } from '@stoplight/spectral-functions'; | ||
|
||
export default { | ||
documentationUrl: 'https://jsonapi.org/format/1.0/#fetching-resources', | ||
rules: { | ||
|
||
/** | ||
* Ensure top-level resposnes include a `self` link in a `links` object | ||
*/ | ||
'fetching-data-fetching-resources-top-level-links': { | ||
description: 'Ensure top-level resposnes include a `self` link in a `links` object', | ||
message: `{{path}} - {{description}}`, | ||
severity: 'error', | ||
given: "$.paths.*.*.responses.*.content['application/vnd.api+json'].schema.properties.links.properties", | ||
then: { | ||
field: 'self', | ||
function: truthy | ||
} | ||
}, | ||
|
||
/** | ||
* Checks for the presence of a `self` link in each resource object within a single responses | ||
*/ | ||
'fetching-data-fetching-resources-single-level-self-link': { | ||
description: 'Ensure single resource object responses include a `self` link in a `links` object', | ||
message: `{{path}} - {{description}}`, | ||
severity: 'error', | ||
given: "$.paths.*.*.responses.*.content['application/vnd.api+json'].schema.properties.data.properties.links.properties", | ||
then: { | ||
field: 'self', | ||
function: truthy | ||
} | ||
}, | ||
|
||
/** | ||
* Ensures that relationship objects within each resource in responses has a `related` link | ||
*/ | ||
'fetching-data-fetching-resources-single-relationship-level-related-link': { | ||
description: 'Ensure relationship objects in responses include a `related` link', | ||
message: `{{path}} - {{description}}`, | ||
severity: 'error', | ||
given: "$.paths.*.*.responses.*.content['application/vnd.api+json'].schema.properties.data.properties.relationships.properties.*.properties", | ||
then: { | ||
field: 'related', | ||
function: truthy | ||
} | ||
}, | ||
|
||
/** | ||
* Checks for the presence of a `self` link in each resource object within array responses | ||
*/ | ||
'fetching-data-fetching-resources-array-level-self-link': { | ||
description: 'Ensure single resource object responses include a `self` link in a `links` object', | ||
message: `{{path}} - {{description}}`, | ||
severity: 'error', | ||
given: "$.paths.*.*.responses.*.content['application/vnd.api+json'].schema.properties.data.items.properties.links.properties", | ||
then: { | ||
field: 'self', | ||
function: truthy | ||
} | ||
}, | ||
|
||
/** | ||
* Ensures that relationship objects within each resource in array responses has a `related` link | ||
*/ | ||
'fetching-data-fetching-resources-array-relationship-level-related-link': { | ||
description: 'Ensure relationship objects in each resource in array resposnes include a `related` link', | ||
message: `{{path}} - {{description}}`, | ||
severity: 'error', | ||
given: "$.paths.*.*.responses.*.content['application/vnd.api+json'].schema.properties.data.items.properties.relationships.properties.*.properties", | ||
then: { | ||
field: 'related', | ||
function: truthy | ||
} | ||
} | ||
|
||
} | ||
}; |
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,8 @@ | ||
# Fetching Data | ||
# https://jsonapi.org/format/1.0/#fetching | ||
|
||
# *-ruleset.yaml files generally SHOULD NOT contain any testable rules. | ||
# all rules in this file MUST have corresponding tests. | ||
|
||
extends: | ||
- jsonapi-fetching-data-fetching-resources.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
Oops, something went wrong.