Skip to content

Commit 7d50c71

Browse files
fix(ipa): include schema descriptions in IPA117 rules
1 parent 21b84d9 commit 7d50c71

7 files changed

+101
-1
lines changed

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ testRule('xgen-IPA-117-description-ends-with-period', [
88
components: {
99
schemas: {
1010
Schema: {
11+
description: 'Description.',
1112
properties: {
1213
id: {
1314
description: 'Description.',
@@ -25,6 +26,7 @@ testRule('xgen-IPA-117-description-ends-with-period', [
2526
components: {
2627
schemas: {
2728
Schema: {
29+
description: 'Description',
2830
properties: {
2931
noPeriod: {
3032
description: 'Description',
@@ -35,6 +37,12 @@ testRule('xgen-IPA-117-description-ends-with-period', [
3537
},
3638
},
3739
errors: [
40+
{
41+
code: 'xgen-IPA-117-description-ends-with-period',
42+
message: 'Descriptions must end with a full stop(.).',
43+
path: ['components', 'schemas', 'Schema'],
44+
severity: DiagnosticSeverity.Error,
45+
},
3846
{
3947
code: 'xgen-IPA-117-description-ends-with-period',
4048
message: 'Descriptions must end with a full stop(.).',
@@ -49,6 +57,7 @@ testRule('xgen-IPA-117-description-ends-with-period', [
4957
components: {
5058
schemas: {
5159
Schema: {
60+
description: 'Description\n| Table |',
5261
properties: {
5362
noPeriod: {
5463
description: 'Description\n| Table |',
@@ -66,6 +75,10 @@ testRule('xgen-IPA-117-description-ends-with-period', [
6675
components: {
6776
schemas: {
6877
Schema: {
78+
description: 'Description',
79+
'x-xgen-IPA-exception': {
80+
'xgen-IPA-117-description-ends-with-period': 'reason',
81+
},
6982
properties: {
7083
noPeriod: {
7184
description: 'Description',

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ testRule('xgen-IPA-117-description-must-not-use-html', [
77
document: {
88
components: {
99
schemas: {
10+
description: 'Must be < 250 characters.',
1011
Schema: {
1112
properties: {
1213
valid: {
@@ -31,6 +32,7 @@ testRule('xgen-IPA-117-description-must-not-use-html', [
3132
components: {
3233
schemas: {
3334
Schema: {
35+
description: '<a>Description</a>',
3436
properties: {
3537
html: {
3638
description: '<a>Description</a>',
@@ -50,6 +52,12 @@ testRule('xgen-IPA-117-description-must-not-use-html', [
5052
},
5153
},
5254
errors: [
55+
{
56+
code: 'xgen-IPA-117-description-must-not-use-html',
57+
message: 'Descriptions must not use raw HTML.',
58+
path: ['components', 'schemas', 'Schema'],
59+
severity: DiagnosticSeverity.Error,
60+
},
5361
{
5462
code: 'xgen-IPA-117-description-must-not-use-html',
5563
message: 'Descriptions must not use raw HTML.',
@@ -83,6 +91,10 @@ testRule('xgen-IPA-117-description-must-not-use-html', [
8391
components: {
8492
schemas: {
8593
Schema: {
94+
description: '<a>Description</a>',
95+
'x-xgen-IPA-exception': {
96+
'xgen-IPA-117-description-must-not-use-html': 'reason',
97+
},
8698
properties: {
8799
html: {
88100
description: '<a>Description</a>',

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ testRule('xgen-IPA-117-description-should-not-use-inline-links', [
88
components: {
99
schemas: {
1010
Schema: {
11+
description: 'Description.',
1112
properties: {
1213
valid: {
1314
description: 'Description.',
@@ -37,6 +38,7 @@ testRule('xgen-IPA-117-description-should-not-use-inline-links', [
3738
components: {
3839
schemas: {
3940
Schema: {
41+
description: 'Hello [world](https://www.mongodb.com).',
4042
properties: {
4143
invalidLink: {
4244
description: 'Hello [world](https://www.mongodb.com).',
@@ -50,6 +52,13 @@ testRule('xgen-IPA-117-description-should-not-use-inline-links', [
5052
},
5153
},
5254
errors: [
55+
{
56+
code: 'xgen-IPA-117-description-should-not-use-inline-links',
57+
message:
58+
'Descriptions should not include inline links. Use the externalDocumentation property instead, see https://swagger.io/specification/#external-documentation-object.',
59+
path: ['components', 'schemas', 'Schema'],
60+
severity: DiagnosticSeverity.Error,
61+
},
5362
{
5463
code: 'xgen-IPA-117-description-should-not-use-inline-links',
5564
message:
@@ -72,6 +81,10 @@ testRule('xgen-IPA-117-description-should-not-use-inline-links', [
7281
components: {
7382
schemas: {
7483
Schema: {
84+
description: 'Hello [world](https://www.mongodb.com).',
85+
'x-xgen-IPA-exception': {
86+
'xgen-IPA-117-description-should-not-use-inline-links': 'reason',
87+
},
7588
properties: {
7689
invalidLink: {
7790
description: 'Hello [world](https://www.mongodb.com).',

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ testRule('xgen-IPA-117-description-should-not-use-inline-tables', [
88
components: {
99
schemas: {
1010
Schema: {
11+
description: 'Schema for request | response',
1112
properties: {
1213
valid: {
1314
description: 'Description.',
@@ -28,6 +29,7 @@ testRule('xgen-IPA-117-description-should-not-use-inline-tables', [
2829
components: {
2930
schemas: {
3031
Schema: {
32+
description: '|Title|\n|-----|\n|Description|',
3133
properties: {
3234
table: {
3335
description: '|Title|\n|-----|\n|Description|',
@@ -50,6 +52,13 @@ testRule('xgen-IPA-117-description-should-not-use-inline-tables', [
5052
},
5153
},
5254
errors: [
55+
{
56+
code: 'xgen-IPA-117-description-should-not-use-inline-tables',
57+
message:
58+
'Descriptions should not include inline tables. Tables may not work well with all tools, in particular generated client code.',
59+
path: ['components', 'schemas', 'Schema'],
60+
severity: DiagnosticSeverity.Error,
61+
},
5362
{
5463
code: 'xgen-IPA-117-description-should-not-use-inline-tables',
5564
message:
@@ -93,6 +102,10 @@ testRule('xgen-IPA-117-description-should-not-use-inline-tables', [
93102
components: {
94103
schemas: {
95104
Schema: {
105+
description: '|Title|\n|-----|\n|Description|',
106+
'x-xgen-IPA-exception': {
107+
'xgen-IPA-117-description-should-not-use-inline-tables': 'reason',
108+
},
96109
properties: {
97110
table: {
98111
description: '|Title|\n|-----|\n|Description|',

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ testRule('xgen-IPA-117-description-starts-with-uppercase', [
88
components: {
99
schemas: {
1010
Schema: {
11+
description: 'Description',
1112
properties: {
1213
id: {
1314
description: 'Description',
@@ -25,6 +26,7 @@ testRule('xgen-IPA-117-description-starts-with-uppercase', [
2526
components: {
2627
schemas: {
2728
Schema: {
29+
description: 'description',
2830
properties: {
2931
noUpperCase: {
3032
description: 'description',
@@ -35,6 +37,12 @@ testRule('xgen-IPA-117-description-starts-with-uppercase', [
3537
},
3638
},
3739
errors: [
40+
{
41+
code: 'xgen-IPA-117-description-starts-with-uppercase',
42+
message: 'Descriptions must start with Uppercase.',
43+
path: ['components', 'schemas', 'Schema'],
44+
severity: DiagnosticSeverity.Error,
45+
},
3846
{
3947
code: 'xgen-IPA-117-description-starts-with-uppercase',
4048
message: 'Descriptions must start with Uppercase.',
@@ -49,6 +57,10 @@ testRule('xgen-IPA-117-description-starts-with-uppercase', [
4957
components: {
5058
schemas: {
5159
Schema: {
60+
description: 'description',
61+
'x-xgen-IPA-exception': {
62+
'xgen-IPA-117-description-starts-with-uppercase': 'reason',
63+
},
5264
properties: {
5365
noUpperCase: {
5466
description: 'description',

tools/spectral/ipa/ipa-spectral.yaml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,3 +148,32 @@ overrides:
148148
- '**#/components/schemas/AWSHardwareSpec20240805/properties/ebsVolumeType'
149149
rules:
150150
xgen-IPA-112-field-names-are-camel-case: 'off'
151+
- files: # To be removed in CLOUDP-338116
152+
- '**#/components/schemas/AtlasResourcePolicyAuditForNdsGroup'
153+
- '**#/components/schemas/AtlasResourcePolicyAuditForOrg'
154+
- '**#/components/schemas/ChartsAudit'
155+
- '**#/components/schemas/DefaultLimit'
156+
- '**#/components/schemas/ObjectCreated'
157+
- '**#/components/schemas/PinnedNamespaces'
158+
- '**#/components/schemas/RequestAccepted'
159+
- '**#/components/schemas/StreamsStartStreamProcessorWith'
160+
- '**#/components/schemas/TextSearchIndexCreateRequest'
161+
- '**#/components/schemas/VectorSearchIndexCreateRequest'
162+
- '**#/components/schemas/AtlasTenantClusterUpgradeRequest20240805'
163+
- '**#/components/schemas/StreamsModifyStreamProcessor'
164+
- '**#/components/schemas/EventTypeDetails'
165+
- '**#/components/schemas/LegacyAtlasTenantClusterUpgradeRequest'
166+
rules:
167+
xgen-IPA-117-description-ends-with-period: 'off'
168+
- files: # To be removed in CLOUDP-338116
169+
- '**#/components/schemas/CustomCriteriaView'
170+
- '**#/components/schemas/ExtraRetentionSetting'
171+
- '**#/components/schemas/MetricDataPoint'
172+
- '**#/components/schemas/MetricDataPoint_Atlas'
173+
- '**#/components/schemas/DateCriteriaView'
174+
rules:
175+
xgen-IPA-117-description-starts-with-uppercase: 'off'
176+
- files:
177+
- '**#/components/schemas/NewRelic'
178+
rules:
179+
xgen-IPA-117-description-must-not-use-html: 'off'

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,21 @@ functions:
1515
aliases:
1616
OperationObject:
1717
- '$.paths[*][get,put,post,delete,options,head,patch,trace]'
18+
RequiredDescribableObjects:
19+
- '$.tags[*]'
20+
- '#OperationObject'
21+
- '#OperationObject.parameters[*]'
22+
- '#OperationObject..content..properties[*]'
23+
- '$.components.schemas..properties[*]'
24+
- '$.components.parameters[*]'
1825
DescribableObjects:
1926
- '$.tags[*]'
2027
- '#OperationObject'
2128
- '#OperationObject.parameters[*]'
2229
- '#OperationObject..content..properties[*]'
2330
- '$.components.schemas..properties[*]'
2431
- '$.components.parameters[*]'
32+
- '$.components.schemas[*]'
2533

2634
rules:
2735
xgen-IPA-117-description:
@@ -41,7 +49,7 @@ rules:
4149
severity: error
4250
given:
4351
- '$.info'
44-
- '#DescribableObjects'
52+
- '#RequiredDescribableObjects'
4553
then:
4654
function: 'IPA117HasDescription'
4755
xgen-IPA-117-description-starts-with-uppercase:

0 commit comments

Comments
 (0)