Skip to content

Commit 27655d4

Browse files
fixes
1 parent 5eb15d3 commit 27655d4

File tree

4 files changed

+25
-15
lines changed

4 files changed

+25
-15
lines changed

tools/spectral/ipa/__tests__/IPA121DateTimeFieldsMentionISO8601.test.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ testRule('xgen-IPA-121-date-time-fields-mention-iso-8601', [
2626
TestParameter: {
2727
name: 'createdAt',
2828
in: 'query',
29+
description: 'The creation timestamp in ISO 8601 format in UTC.',
2930
schema: {
3031
type: 'string',
3132
format: 'date-time',
32-
description: 'The creation timestamp in ISO 8601 format in UTC.',
3333
},
3434
},
3535
},
@@ -82,10 +82,10 @@ testRule('xgen-IPA-121-date-time-fields-mention-iso-8601', [
8282
TestParameter: {
8383
name: 'createdAt',
8484
in: 'query',
85+
description: 'The creation timestamp',
8586
schema: {
8687
type: 'string',
8788
format: 'date-time',
88-
description: 'The creation timestamp',
8989
},
9090
},
9191
},
@@ -127,7 +127,7 @@ testRule('xgen-IPA-121-date-time-fields-mention-iso-8601', [
127127
code: 'xgen-IPA-121-date-time-fields-mention-iso-8601',
128128
message:
129129
'API producers must use ISO 8601 date-time format in UTC for all timestamps. Fields must note ISO 8601 in their description.',
130-
path: ['components', 'parameters', 'TestParameter', 'schema'],
130+
path: ['components', 'parameters', 'TestParameter'],
131131
severity: DiagnosticSeverity.Warning,
132132
},
133133
],
@@ -154,13 +154,13 @@ testRule('xgen-IPA-121-date-time-fields-mention-iso-8601', [
154154
TestParameter: {
155155
name: 'createdAt',
156156
in: 'query',
157+
description: 'The creation timestamp',
157158
schema: {
158159
type: 'string',
159160
format: 'date-time',
160-
description: 'The creation timestamp',
161-
'x-xgen-IPA-exception': {
162-
'xgen-IPA-121-date-time-fields-mention-iso-8601': 'Legacy field format',
163-
},
161+
},
162+
'x-xgen-IPA-exception': {
163+
'xgen-IPA-121-date-time-fields-mention-iso-8601': 'Legacy field format',
164164
},
165165
},
166166
},
@@ -178,19 +178,19 @@ testRule('xgen-IPA-121-date-time-fields-mention-iso-8601', [
178178
{
179179
name: 'since',
180180
in: 'query',
181+
description: 'Filter resources created since this ISO 8601 timestamp in UTC',
181182
schema: {
182183
type: 'string',
183184
format: 'date-time',
184-
description: 'Filter resources created since this ISO 8601 timestamp in UTC',
185185
},
186186
},
187187
{
188188
name: 'until',
189189
in: 'query',
190+
description: 'Filter resources created until this timestamp', // Missing ISO 8601 and UTC
190191
schema: {
191192
type: 'string',
192193
format: 'date-time',
193-
description: 'Filter resources created until this timestamp', // Missing ISO 8601 and UTC
194194
},
195195
},
196196
],
@@ -203,7 +203,7 @@ testRule('xgen-IPA-121-date-time-fields-mention-iso-8601', [
203203
code: 'xgen-IPA-121-date-time-fields-mention-iso-8601',
204204
message:
205205
'API producers must use ISO 8601 date-time format in UTC for all timestamps. Fields must note ISO 8601 in their description.',
206-
path: ['paths', '/resources', 'get', 'parameters', '1', 'schema'],
206+
path: ['paths', '/resources', 'get', 'parameters', '1'],
207207
severity: DiagnosticSeverity.Warning,
208208
},
209209
],

tools/spectral/ipa/rulesets/IPA-121.yaml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@ rules:
88
xgen-IPA-121-date-time-fields-mention-iso-8601:
99
description: |
1010
Fields with format="date-time" should mention ISO 8601 and UTC in their description.
11+
It collects adoption metrics at schema property level and parameter level
1112
message: '{{error}} https://mdb.link/mongodb-atlas-openapi-validation#xgen-IPA-121-date-time-fields-mention-iso-8601'
1213
given:
13-
- $.paths..parameters[*].schema
14-
- $.components.parameters.*.schema
14+
- $.paths..parameters[*]
15+
- $.components.parameters[*]
1516
- $.components.schemas..properties[*]
1617
- $.paths..requestBody..schema..properties[*]
1718
- $.paths..responses..schema..properties[*]

tools/spectral/ipa/rulesets/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -810,6 +810,7 @@ Rules are based on [http://go/ipa/IPA-121](http://go/ipa/IPA-121).
810810

811811
![warn](https://img.shields.io/badge/warning-yellow)
812812
Fields with format="date-time" should mention ISO 8601 and UTC in their description.
813+
It collects adoption metrics at schema property level and parameter level
813814

814815

815816

tools/spectral/ipa/rulesets/functions/IPA121DateTimeFieldsMentionISO8601.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const ERROR_MESSAGE =
99
export default (input, options, { path, documentInventory }) => {
1010
const oas = documentInventory.unresolved;
1111
const propertyObject = resolveObject(oas, path);
12-
12+
const fieldType = path[path.length - 2];
1313
// Not to duplicate the check for referenced schemas
1414
if (!propertyObject) {
1515
return;
@@ -20,8 +20,16 @@ export default (input, options, { path, documentInventory }) => {
2020
return;
2121
}
2222

23-
if (input.format === 'date-time') {
24-
if (!input.description?.includes('ISO 8601') && !input.description?.includes('UTC')) {
23+
let format;
24+
let description = input.description;
25+
if (fieldType === 'parameters') {
26+
format = input.schema?.format;
27+
} else if (fieldType === 'properties') {
28+
format = input.format;
29+
}
30+
31+
if (format === 'date-time') {
32+
if (!description?.includes('ISO 8601') && !description?.includes('UTC')) {
2533
return collectAndReturnViolation(path, RULE_NAME, [
2634
{
2735
path,

0 commit comments

Comments
 (0)