Skip to content

Test #597

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

Closed
wants to merge 3 commits into from
Closed

Test #597

Show file tree
Hide file tree
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
93 changes: 47 additions & 46 deletions tools/spectral/ipa/rulesets/IPA-112.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,34 +7,34 @@ functions:
- IPA112BooleanFieldNamesAvoidIsPrefix

rules:
xgen-IPA-112-avoid-project-field-names:
description: |
Schema field names should avoid using "project", "projects", or "projectId".

##### Implementation details
Rule checks for the following conditions:
- Searches through all schemas in the API definition
- Identifies property names that match "project" (case-insensitive)
- Ignores fields where prohibited words appear with specified words (e.g., "gcpProjectId")
- Reports any instances where these field names are used
- Suggests using "group", "groups", or "groupId" as alternatives
message: '{{error}} https://mdb.link/mongodb-atlas-openapi-validation#xgen-IPA-112-avoid-project-field-names'
severity: warn
given:
- '$.components.schemas..properties'
- '$.paths..requestBody.content[?(@property.match(/json$/i))].schema..properties'
- '$.paths..responses..content[?(@property.match(/json$/i))].schema..properties'
then:
field: '@key'
function: 'IPA112AvoidProjectFieldNames'
functionOptions:
prohibitedFieldNames:
- name: 'project'
alternative: ['group']
- name: 'projects'
alternative: ['groups']
ignore:
- 'gcp'
# xgen-IPA-112-avoid-project-field-names:
# description: |
# Schema field names should avoid using "project", "projects", or "projectId".
#
# ##### Implementation details
# Rule checks for the following conditions:
# - Searches through all schemas in the API definition
# - Identifies property names that match "project" (case-insensitive)
# - Ignores fields where prohibited words appear with specified words (e.g., "gcpProjectId")
# - Reports any instances where these field names are used
# - Suggests using "group", "groups", or "groupId" as alternatives
# message: '{{error}} https://mdb.link/mongodb-atlas-openapi-validation#xgen-IPA-112-avoid-project-field-names'
# severity: warn
# given:
# - '$.components.schemas..properties'
# - '$.paths..requestBody.content[?(@property.match(/json$/i))].schema..properties'
# - '$.paths..responses..content[?(@property.match(/json$/i))].schema..properties'
# then:
# field: '@key'
# function: 'IPA112AvoidProjectFieldNames'
# functionOptions:
# prohibitedFieldNames:
# - name: 'project'
# alternative: ['group']
# - name: 'projects'
# alternative: ['groups']
# ignore:
# - 'gcp'
xgen-IPA-112-field-names-are-camel-case:
description: |
Schema field names should be in camelCase format.
Expand All @@ -46,28 +46,29 @@ rules:
- Reports any instances where these field names are not in camelCase format
message: '{{error}} https://mdb.link/mongodb-atlas-openapi-validation#xgen-IPA-112-field-names-are-camel-case'
severity: warn
resolved: false
given:
- '$.components.schemas..properties'
- '$.paths..requestBody.content[?(@property.match(/json$/i))].schema..properties'
- '$.paths..responses..content[?(@property.match(/json$/i))].schema..properties'
then:
field: '@key'
function: 'IPA112FieldNamesAreCamelCase'
xgen-IPA-112-boolean-field-names-avoid-is-prefix:
description: |
Boolean field names should avoid the "is" prefix.

##### Implementation details
Rule checks for the following conditions:
- Applies only to properties with type 'boolean'
- Identifies property names that start with "is" followed by an uppercase letter
- Suggests using the direct adjective form instead (e.g., "disabled" instead of "isDisabled")
message: '{{error}} https://mdb.link/mongodb-atlas-openapi-validation#xgen-IPA-112-boolean-field-names-avoid-is-prefix'
severity: warn
given:
- '$.components.schemas..properties'
- '$.paths..requestBody.content[?(@property.match(/json$/i))].schema..properties'
- '$.paths..responses..content[?(@property.match(/json$/i))].schema..properties'
then:
field: '@key'
function: 'IPA112BooleanFieldNamesAvoidIsPrefix'
# xgen-IPA-112-boolean-field-names-avoid-is-prefix:
# description: |
# Boolean field names should avoid the "is" prefix.
#
# ##### Implementation details
# Rule checks for the following conditions:
# - Applies only to properties with type 'boolean'
# - Identifies property names that start with "is" followed by an uppercase letter
# - Suggests using the direct adjective form instead (e.g., "disabled" instead of "isDisabled")
# message: '{{error}} https://mdb.link/mongodb-atlas-openapi-validation#xgen-IPA-112-boolean-field-names-avoid-is-prefix'
# severity: warn
# given:
# - '$.components.schemas..properties'
# - '$.paths..requestBody.content[?(@property.match(/json$/i))].schema..properties'
# - '$.paths..responses..content[?(@property.match(/json$/i))].schema..properties'
# then:
# field: '@key'
# function: 'IPA112BooleanFieldNamesAvoidIsPrefix'
24 changes: 0 additions & 24 deletions tools/spectral/ipa/rulesets/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -451,19 +451,6 @@ Rule checks for the following conditions:

Rules are based on [http://go/ipa/IPA-112](http://go/ipa/IPA-112).

#### xgen-IPA-112-avoid-project-field-names

![warn](https://img.shields.io/badge/warning-yellow)
Schema field names should avoid using "project", "projects", or "projectId".

##### Implementation details
Rule checks for the following conditions:
- Searches through all schemas in the API definition
- Identifies property names that match "project" (case-insensitive)
- Ignores fields where prohibited words appear with specified words (e.g., "gcpProjectId")
- Reports any instances where these field names are used
- Suggests using "group", "groups", or "groupId" as alternatives

#### xgen-IPA-112-field-names-are-camel-case

![warn](https://img.shields.io/badge/warning-yellow)
Expand All @@ -475,17 +462,6 @@ Rule checks for the following conditions:
- Identifies property names that are not in camelCase format
- Reports any instances where these field names are not in camelCase format

#### xgen-IPA-112-boolean-field-names-avoid-is-prefix

![warn](https://img.shields.io/badge/warning-yellow)
Boolean field names should avoid the "is" prefix.

##### Implementation details
Rule checks for the following conditions:
- Applies only to properties with type 'boolean'
- Identifies property names that start with "is" followed by an uppercase letter
- Suggests using the direct adjective form instead (e.g., "disabled" instead of "isDisabled")



### IPA-113
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,10 @@ import { resolveObject } from './utils/componentUtils.js';

const RULE_NAME = 'xgen-IPA-112-field-names-are-camel-case';

export default (input, options, { path, documentInventory }) => {
export default (input, _, { path, documentInventory }) => {
const oas = documentInventory.unresolved;
const property = resolveObject(oas, path);

// Skip schema references ($ref):
// Referenced schemas are validated separately to prevent duplicate violations
if (!property) {
return;
}

if (hasException(property, RULE_NAME)) {
collectException(property, RULE_NAME, path);
return;
Expand Down
Loading