@zapier/spectral-api-ruleset
Advanced tools
Comparing version 0.0.4 to 0.0.5
# @zapier/spectral-api-ruleset | ||
## 0.0.5 | ||
### Patch Changes | ||
- 479700f: Add field names in snake case checks | ||
## 0.0.4 | ||
@@ -4,0 +10,0 @@ |
@@ -71,2 +71,29 @@ 'use strict'; | ||
function isObject(value) { | ||
return typeof value === 'object' && value !== null && !Array.isArray(value); | ||
} | ||
const fieldNamesInSnakeCase = value => { | ||
let fieldsWithErrors = []; | ||
let snakeCaseRegex = new RegExp('^[a-z][a-z{0-9}]*(?:_[a-z{0-9}]+)*$'); | ||
if (isObject(value)) { | ||
for (var key in value) { | ||
if (snakeCaseRegex.test(key) === false) { | ||
fieldsWithErrors.push(key); | ||
} | ||
} | ||
} else { | ||
if (snakeCaseRegex.test(value) === false) { | ||
fieldsWithErrors.push(value); | ||
} | ||
} | ||
if (fieldsWithErrors.length > 0) { | ||
return [{ | ||
message: `Field names must be in snake case, found fields using other formats: ${fieldsWithErrors}` | ||
}]; | ||
} | ||
}; | ||
const UNWANTED_SORTING_PARAMETERS = ['sort_by', 'ordering']; | ||
@@ -98,2 +125,32 @@ const ruleset = { | ||
} | ||
}, | ||
'query-field-names': { | ||
description: 'All query parameters should be in snake_case.', | ||
documentationUrl: 'https://engineering.zapier.com/guides/api-design-guidelines/field-names/', | ||
given: '$.paths[*][*].parameters[*].name', | ||
message: '{{error}}', | ||
severity: 'error', | ||
then: { | ||
function: fieldNamesInSnakeCase | ||
} | ||
}, | ||
'components-field-names': { | ||
description: 'All response properties should be in snake_case.', | ||
documentationUrl: 'https://engineering.zapier.com/guides/api-design-guidelines/field-names/', | ||
given: '$.components.schemas[*].properties', | ||
message: '{{error}}', | ||
severity: 'error', | ||
then: { | ||
function: fieldNamesInSnakeCase | ||
} | ||
}, | ||
'response-field-names': { | ||
description: 'All response properties should be in snake_case.', | ||
documentationUrl: 'https://engineering.zapier.com/guides/api-design-guidelines/field-names/', | ||
given: '$.paths[*][*].responses[*].content[*].schema..properties', | ||
message: '{{error}}', | ||
severity: 'error', | ||
then: { | ||
function: fieldNamesInSnakeCase | ||
} | ||
} | ||
@@ -100,0 +157,0 @@ } |
@@ -71,2 +71,29 @@ 'use strict'; | ||
function isObject(value) { | ||
return typeof value === 'object' && value !== null && !Array.isArray(value); | ||
} | ||
const fieldNamesInSnakeCase = value => { | ||
let fieldsWithErrors = []; | ||
let snakeCaseRegex = new RegExp('^[a-z][a-z{0-9}]*(?:_[a-z{0-9}]+)*$'); | ||
if (isObject(value)) { | ||
for (var key in value) { | ||
if (snakeCaseRegex.test(key) === false) { | ||
fieldsWithErrors.push(key); | ||
} | ||
} | ||
} else { | ||
if (snakeCaseRegex.test(value) === false) { | ||
fieldsWithErrors.push(value); | ||
} | ||
} | ||
if (fieldsWithErrors.length > 0) { | ||
return [{ | ||
message: `Field names must be in snake case, found fields using other formats: ${fieldsWithErrors}` | ||
}]; | ||
} | ||
}; | ||
const UNWANTED_SORTING_PARAMETERS = ['sort_by', 'ordering']; | ||
@@ -98,2 +125,32 @@ const ruleset = { | ||
} | ||
}, | ||
'query-field-names': { | ||
description: 'All query parameters should be in snake_case.', | ||
documentationUrl: 'https://engineering.zapier.com/guides/api-design-guidelines/field-names/', | ||
given: '$.paths[*][*].parameters[*].name', | ||
message: '{{error}}', | ||
severity: 'error', | ||
then: { | ||
function: fieldNamesInSnakeCase | ||
} | ||
}, | ||
'components-field-names': { | ||
description: 'All response properties should be in snake_case.', | ||
documentationUrl: 'https://engineering.zapier.com/guides/api-design-guidelines/field-names/', | ||
given: '$.components.schemas[*].properties', | ||
message: '{{error}}', | ||
severity: 'error', | ||
then: { | ||
function: fieldNamesInSnakeCase | ||
} | ||
}, | ||
'response-field-names': { | ||
description: 'All response properties should be in snake_case.', | ||
documentationUrl: 'https://engineering.zapier.com/guides/api-design-guidelines/field-names/', | ||
given: '$.paths[*][*].responses[*].content[*].schema..properties', | ||
message: '{{error}}', | ||
severity: 'error', | ||
then: { | ||
function: fieldNamesInSnakeCase | ||
} | ||
} | ||
@@ -100,0 +157,0 @@ } |
@@ -63,2 +63,29 @@ import _ from 'lodash'; | ||
function isObject(value) { | ||
return typeof value === 'object' && value !== null && !Array.isArray(value); | ||
} | ||
const fieldNamesInSnakeCase = value => { | ||
let fieldsWithErrors = []; | ||
let snakeCaseRegex = new RegExp('^[a-z][a-z{0-9}]*(?:_[a-z{0-9}]+)*$'); | ||
if (isObject(value)) { | ||
for (var key in value) { | ||
if (snakeCaseRegex.test(key) === false) { | ||
fieldsWithErrors.push(key); | ||
} | ||
} | ||
} else { | ||
if (snakeCaseRegex.test(value) === false) { | ||
fieldsWithErrors.push(value); | ||
} | ||
} | ||
if (fieldsWithErrors.length > 0) { | ||
return [{ | ||
message: `Field names must be in snake case, found fields using other formats: ${fieldsWithErrors}` | ||
}]; | ||
} | ||
}; | ||
const UNWANTED_SORTING_PARAMETERS = ['sort_by', 'ordering']; | ||
@@ -90,2 +117,32 @@ const ruleset = { | ||
} | ||
}, | ||
'query-field-names': { | ||
description: 'All query parameters should be in snake_case.', | ||
documentationUrl: 'https://engineering.zapier.com/guides/api-design-guidelines/field-names/', | ||
given: '$.paths[*][*].parameters[*].name', | ||
message: '{{error}}', | ||
severity: 'error', | ||
then: { | ||
function: fieldNamesInSnakeCase | ||
} | ||
}, | ||
'components-field-names': { | ||
description: 'All response properties should be in snake_case.', | ||
documentationUrl: 'https://engineering.zapier.com/guides/api-design-guidelines/field-names/', | ||
given: '$.components.schemas[*].properties', | ||
message: '{{error}}', | ||
severity: 'error', | ||
then: { | ||
function: fieldNamesInSnakeCase | ||
} | ||
}, | ||
'response-field-names': { | ||
description: 'All response properties should be in snake_case.', | ||
documentationUrl: 'https://engineering.zapier.com/guides/api-design-guidelines/field-names/', | ||
given: '$.paths[*][*].responses[*].content[*].schema..properties', | ||
message: '{{error}}', | ||
severity: 'error', | ||
then: { | ||
function: fieldNamesInSnakeCase | ||
} | ||
} | ||
@@ -92,0 +149,0 @@ } |
{ | ||
"name": "@zapier/spectral-api-ruleset", | ||
"version": "0.0.4", | ||
"version": "0.0.5", | ||
"description": "Node package with Spectral ruleset for Zapier API Guidelines.", | ||
@@ -5,0 +5,0 @@ "repository": "https://gitlab.com/zapier/spectral-api-ruleset/-/tree/main", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
20892
13
444
0