-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updated some unit test and address PR comments
- Loading branch information
1 parent
83fdedb
commit 1cd62da
Showing
4 changed files
with
360 additions
and
128 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -1,7 +1,7 @@ | ||
rules: | ||
##### General ##### | ||
sps-no-collection-paging-capability: | ||
description: Response bodies from collection endpoints must offer paging capability. | ||
description: "Response bodies from collection endpoints must offer paging capability." | ||
severity: error | ||
given: $.paths[?([email protected](/.*\/\{[^}]+\}$/))].get.responses['200'].content.application/json.schema.properties | ||
then: | ||
|
@@ -14,7 +14,7 @@ rules: | |
|
||
##### Root Element ##### | ||
sps-collection-missing-results-array: | ||
description: Response bodies must have a root element called results and is an array of objects. | ||
description: "Response bodies must have a root element called results and is an array of objects." | ||
severity: error | ||
given: $.paths[?([email protected](/.*\/\{[^}]+\}$/))].get.responses['200'].content.application/json.schema.properties.results | ||
then: | ||
|
@@ -29,7 +29,7 @@ rules: | |
|
||
##### Pagination ##### | ||
sps-missing-pagination-query-parameters: | ||
description: 'Collection GET endpoints must support pagination using query parameters: limit, offset, cursor.' | ||
description: "Collection GET endpoints must support pagination using query parameters. Offset or cursor based pagination is required." | ||
severity: error | ||
given: $.paths[?([email protected](/.*\/\{[^}]+\}$/))].get | ||
then: | ||
|
@@ -40,23 +40,29 @@ rules: | |
type: array | ||
items: | ||
type: object | ||
contains: | ||
type: object | ||
properties: | ||
name: | ||
type: string | ||
required: | ||
- name | ||
minItems: 3 | ||
contains: | ||
anyOf: | ||
- properties: | ||
const: limit | ||
in: | ||
const: query | ||
allOf: | ||
- anyOf: | ||
- contains: | ||
type: object | ||
properties: | ||
name: | ||
const: offset | ||
- properties: | ||
name: | ||
const: limit | ||
- properties: | ||
in: | ||
const: query | ||
- contains: | ||
type: object | ||
properties: | ||
name: | ||
const: cursor | ||
in: | ||
const: query | ||
|
||
sps-post-request-body-missing-paging-object: | ||
description: "POST collection endpoints MUST have a request body schema that includes paging parameters." | ||
|
@@ -70,7 +76,7 @@ rules: | |
|
||
##### FILTERING ##### | ||
sps-disallow-resource-identifier-filtering: | ||
description: "Resource identifier filtering is not allowed. Use the resource identifier in the URL path." | ||
description: "Resource identifier filtering is not allowed as a query parameter. Use the resource identifier in the URL path." | ||
severity: warn | ||
given: $.paths..get.parameters.[?(@.in=='query' && @.name=='id')] | ||
then: | ||
|
@@ -79,35 +85,37 @@ rules: | |
functionOptions: | ||
notMatch: "^id$" | ||
|
||
sps-unreasonable-query-parameters-limit: | ||
description: "Filtering query parameters SHOULD have a reasonable limit, no more than 12." | ||
severity: warn | ||
given: $.paths..get | ||
then: | ||
function: schema | ||
functionOptions: | ||
dialect: "draft2020-12" | ||
schema: | ||
type: object | ||
properties: | ||
parameters: | ||
type: array | ||
minContains: 0 | ||
maxContains: 12 | ||
contains: | ||
type: object | ||
properties: | ||
in: | ||
const: query | ||
# Commented out because | ||
# https://github.com/SPSCommerce/sps-api-standards/pull/86#discussion_r1680361945 | ||
# sps-unreasonable-query-parameters-limit: | ||
# description: "Filtering query parameters SHOULD have a reasonable limit, no more than 12." | ||
# severity: warn | ||
# given: $.paths..get | ||
# then: | ||
# function: schema | ||
# functionOptions: | ||
# schema: | ||
# type: object | ||
# properties: | ||
# parameters: | ||
# type: array | ||
# minContains: 0 | ||
# maxContains: 12 | ||
# contains: | ||
# type: object | ||
# properties: | ||
# in: | ||
# const: query | ||
|
||
# This rule might need to be reworked. | ||
# Hybird filter is possible but it should error if root level filter exist with hybird filter. | ||
sps-multiple-filter-parameters: | ||
description: "Ensures the 'filter' query parameter is specified only once." | ||
description: "The 'filter' query parameter MUST be specified only once." | ||
severity: error | ||
given: $.paths..get | ||
then: | ||
function: schema | ||
functionOptions: | ||
dialect: "draft2020-12" | ||
schema: | ||
type: object | ||
properties: | ||
|
@@ -125,12 +133,12 @@ rules: | |
|
||
##### SORTING ##### | ||
sps-sorting-parameters-only-get-requests: | ||
description: "Sorting query parameters SHOULD only be used with GET endpoints." | ||
description: "Non-GET endpoints MUST NOT have sorting query parameters. Parameter names such as sort, sorting, orderBy, etc." | ||
severity: error | ||
given: $.paths.*[?(@property!='get')].parameters.[?(@.in=='query')] | ||
then: | ||
field: "name" | ||
function: pattern | ||
functionOptions: | ||
notMatch: "^sort|sorting|sort_by|order|ordering|order_by$" | ||
notMatch: "^sort|sorting|sortBy|order|ordering|orderBy$" | ||
|
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.