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

fix: Optimize sps-paths-limit-sub-resources #80

Merged
merged 1 commit into from
Mar 13, 2024
Merged
Changes from all 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
19 changes: 8 additions & 11 deletions rulesets/src/url-structure.ruleset.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
rules:

sps-limit-path-size:
message: APIs SHOULD NOT expand their total URL length beyond a few hundred characters.
severity: warn
Expand Down Expand Up @@ -38,7 +37,7 @@ rules:
function: pattern
functionOptions:
match: api.spscommerce.com|api.sps-internal.com|localhost

sps-path-no-environment:
message: "API paths MUST NOT indicate environment names."
severity: error
Expand All @@ -56,7 +55,7 @@ rules:
then:
function: pattern
functionOptions:
notMatch: (?!https?://localhost)(https?://.*):(\d*)\/?(.*)
notMatch: (?!https?://localhost)(https?://.*):(\d*)\/?(.*)

sps-paths-expose-technology:
message: "A resource MUST NOT leak or expose format or technology-specific information at any point in the path."
Expand All @@ -80,7 +79,7 @@ rules:
message: "A resource containing multiple words MUST be separated using kebab-case (lower case and separated with hyphens)."
severity: error
given: $.paths[?(/^((?!_webhooks).)*$/i.test(@property))]~
then:
then:
function: pattern
# (\/[a-z]+_.) looks for any instance of a forward slash followed by a lowercase character followed by an underscore
# (\/([a-z]|[A-Z])+[A-Z])looks for any instance of a forward slash followed by a lowercase of uppercase character followed by an uppercase character
Expand Down Expand Up @@ -132,15 +131,15 @@ rules:
function: pattern
functionOptions:
notMatch: ^(.*{{1}.*){4,}

sps-paths-limit-sub-resources:
message: The hierarchy of nested resources SHOULD NOT contain more than 8 resource names in the path.
severity: warn
given: $.paths.*~
then:
function: pattern
functionOptions:
notMatch: ^(.*\/{1}.*){9,}
notMatch: ^([^/]*/){9,}

sps-paths-with-http-methods:
message: "A resource SHOULD NOT contain HTTP methods."
Expand Down Expand Up @@ -189,16 +188,16 @@ rules:
given: $.paths.*.*.parameters[?(@.in=='query')].required
then:
function: falsy

sps-query-params-no-api-keys:
message: "Query parameters MUST not contain sensitive information, like API tokens or keys."
severity: error
given: $.paths.*.*.parameters[?(@.in=='query')].name
then:
function: pattern
functionOptions:
functionOptions:
notMatch: "apiKey|token"

sps-query-params-not-in-path:
message: "Paths SHOULD NOT have query parameters in them. They should be defined separately in the OpenAPI."
severity: warn
Expand All @@ -207,5 +206,3 @@ rules:
function: pattern
functionOptions:
notMatch: \?


Loading