Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@zapier/spectral-api-ruleset

Package Overview
Dependencies
Maintainers
0
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@zapier/spectral-api-ruleset - npm Package Compare versions

Comparing version 0.0.4 to 0.0.5

dist/declarations/src/functions/fieldNamesInSnakeCase.d.ts

6

CHANGELOG.md
# @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 @@ }

2

package.json
{
"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",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc