Skip to content

Commit d99ae29

Browse files
CLOUDP-302984: Address comments
1 parent c7c7b28 commit d99ae29

File tree

4 files changed

+19
-46
lines changed

4 files changed

+19
-46
lines changed

tools/spectral/ipa/__tests__/getResourceIsNotPaginated.test.js renamed to tools/spectral/ipa/__tests__/getMethodReturnsSingleResource.test.js

Lines changed: 14 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ const componentSchemas = {
2323
},
2424
};
2525

26-
testRule('xgen-IPA-104-GET-resource-not-paginated', [
26+
testRule('xgen-IPA-104-get-method-returns-single-resource', [
2727
{
2828
name: 'valid resources',
2929
document: {
@@ -97,21 +97,6 @@ testRule('xgen-IPA-104-GET-resource-not-paginated', [
9797
name: 'invalid resources',
9898
document: {
9999
paths: {
100-
'/arrayResource': {
101-
get: {
102-
responses: {
103-
200: {
104-
content: {
105-
'application/vnd.atlas.2024-08-05+json': {
106-
schema: {
107-
$ref: '#/components/schemas/PaginatedSchema',
108-
},
109-
},
110-
},
111-
},
112-
},
113-
},
114-
},
115100
'/arrayResource/{id}': {
116101
get: {
117102
responses: {
@@ -127,21 +112,6 @@ testRule('xgen-IPA-104-GET-resource-not-paginated', [
127112
},
128113
},
129114
},
130-
'/paginatedResource': {
131-
get: {
132-
responses: {
133-
200: {
134-
content: {
135-
'application/vnd.atlas.2024-08-05+json': {
136-
schema: {
137-
$ref: '#/components/schemas/PaginatedSchema',
138-
},
139-
},
140-
},
141-
},
142-
},
143-
},
144-
},
145115
'/paginatedResource/{id}': {
146116
get: {
147117
responses: {
@@ -192,7 +162,7 @@ testRule('xgen-IPA-104-GET-resource-not-paginated', [
192162
},
193163
errors: [
194164
{
195-
code: 'xgen-IPA-104-GET-resource-not-paginated',
165+
code: 'xgen-IPA-104-get-method-returns-single-resource',
196166
message:
197167
'Get methods should return data for a single resource. This method returns an array or a paginated response. http://go/ipa/104',
198168
path: [
@@ -207,7 +177,7 @@ testRule('xgen-IPA-104-GET-resource-not-paginated', [
207177
severity: DiagnosticSeverity.Warning,
208178
},
209179
{
210-
code: 'xgen-IPA-104-GET-resource-not-paginated',
180+
code: 'xgen-IPA-104-get-method-returns-single-resource',
211181
message:
212182
'Get methods should return data for a single resource. This method returns an array or a paginated response. http://go/ipa/104',
213183
path: [
@@ -222,7 +192,7 @@ testRule('xgen-IPA-104-GET-resource-not-paginated', [
222192
severity: DiagnosticSeverity.Warning,
223193
},
224194
{
225-
code: 'xgen-IPA-104-GET-resource-not-paginated',
195+
code: 'xgen-IPA-104-get-method-returns-single-resource',
226196
message:
227197
'Get methods should return data for a single resource. This method returns an array or a paginated response. http://go/ipa/104',
228198
path: [
@@ -237,7 +207,7 @@ testRule('xgen-IPA-104-GET-resource-not-paginated', [
237207
severity: DiagnosticSeverity.Warning,
238208
},
239209
{
240-
code: 'xgen-IPA-104-GET-resource-not-paginated',
210+
code: 'xgen-IPA-104-get-method-returns-single-resource',
241211
message:
242212
'Get methods should return data for a single resource. This method returns an array or a paginated response. http://go/ipa/104',
243213
path: [
@@ -254,35 +224,38 @@ testRule('xgen-IPA-104-GET-resource-not-paginated', [
254224
],
255225
},
256226
{
257-
name: 'invalid resource with exception',
227+
name: 'invalid resources with exceptions',
258228
document: {
259229
paths: {
260-
'/arrayResource': {
230+
'/arrayResource/{id}': {
261231
get: {
262232
responses: {
263233
200: {
264234
content: {
265235
'application/vnd.atlas.2024-08-05+json': {
236+
'x-xgen-IPA-exception': {
237+
'xgen-IPA-104-get-method-returns-single-resource': 'reason',
238+
},
266239
schema: {
267-
$ref: '#/components/schemas/PaginatedSchema',
240+
$ref: '#/components/schemas/ArraySchema',
268241
},
269242
},
270243
},
271244
},
272245
},
273246
},
274247
},
275-
'/arrayResource/{id}': {
248+
'/paginatedSingleton': {
276249
get: {
277250
responses: {
278251
200: {
279252
content: {
280253
'application/vnd.atlas.2024-08-05+json': {
281254
'x-xgen-IPA-exception': {
282-
'xgen-IPA-104-GET-resource-not-paginated': 'reason',
255+
'xgen-IPA-104-get-method-returns-single-resource': 'reason',
283256
},
284257
schema: {
285-
$ref: '#/components/schemas/ArraySchema',
258+
$ref: '#/components/schemas/PaginatedSchema',
286259
},
287260
},
288261
},

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
functions:
55
- eachResourceHasGetMethod
6-
- getResourceIsNotPaginated
6+
- getMethodReturnsSingleResource
77

88
rules:
99
xgen-IPA-104-resource-has-GET:
@@ -14,10 +14,10 @@ rules:
1414
then:
1515
field: '@key'
1616
function: 'eachResourceHasGetMethod'
17-
xgen-IPA-104-GET-resource-not-paginated:
17+
xgen-IPA-104-get-method-returns-single-resource:
1818
description: 'The purpose of the get method is to return data from a single resource. http://go/ipa/104'
1919
message: '{{error}} http://go/ipa/104'
2020
severity: warn
2121
given: '$.paths[*].get'
2222
then:
23-
function: 'getResourceIsNotPaginated'
23+
function: 'getMethodReturnsSingleResource'

tools/spectral/ipa/rulesets/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ For rule definitions, see [IPA-104.yaml](https://github.com/mongodb/openapi/blob
3131
| Rule Name | Description | Severity |
3232
| --------------------------------------- | ----------------------------------------------------------------------------------------- | -------- |
3333
| xgen-IPA-104-resource-has-GET | APIs must provide a get method for resources. http://go/ipa/104 | warn |
34-
| xgen-IPA-104-GET-resource-not-paginated | The purpose of the get method is to return data from a single resource. http://go/ipa/104 | warn |
34+
| xgen-IPA-104-get-method-returns-single-resource | The purpose of the get method is to return data from a single resource. http://go/ipa/104 | warn |
3535

3636
### IPA-109
3737

tools/spectral/ipa/rulesets/functions/getResourceIsNotPaginated.js renamed to tools/spectral/ipa/rulesets/functions/getMethodReturnsSingleResource.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { hasException } from './utils/exceptions.js';
55
import { schemaIsArray, schemaIsPaginated } from './utils/schemaUtils.js';
66
import { resolveObject } from './utils/componentUtils.js';
77

8-
const RULE_NAME = 'xgen-IPA-104-GET-resource-not-paginated';
8+
const RULE_NAME = 'xgen-IPA-104-get-method-returns-single-resource';
99
const ERROR_MESSAGE_STANDARD_RESOURCE =
1010
'Get methods should return data for a single resource. This method returns an array or a paginated response.';
1111

0 commit comments

Comments
 (0)