Skip to content

Commit 509707a

Browse files
CLOUDP-303615: IPA - Update check if resource is singleton (#469)
1 parent a260a2a commit 509707a

15 files changed

+516
-221
lines changed

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

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,6 @@ testRule('xgen-IPA-104-resource-has-GET', [
4343
'/custom:method': {
4444
post: {},
4545
},
46-
'/singleton': {
47-
get: {},
48-
},
4946
},
5047
},
5148
errors: [],
@@ -87,8 +84,8 @@ testRule('xgen-IPA-104-resource-has-GET', [
8784
'/custom:method': {
8885
post: {},
8986
},
90-
'/singleton': {
91-
patch: {},
87+
'/standardWithoutSubResource': {
88+
get: {},
9289
},
9390
},
9491
},
@@ -120,7 +117,7 @@ testRule('xgen-IPA-104-resource-has-GET', [
120117
{
121118
code: 'xgen-IPA-104-resource-has-GET',
122119
message: 'APIs must provide a get method for resources. http://go/ipa/104',
123-
path: ['paths', '/singleton'],
120+
path: ['paths', '/standardWithoutSubResource'],
124121
severity: DiagnosticSeverity.Warning,
125122
},
126123
],

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ testRule('xgen-IPA-104-get-method-returns-single-resource', [
7373
},
7474
},
7575
},
76-
'/singleton': {
76+
'/resource/{id}/singleton': {
7777
get: {
7878
responses: {
7979
200: {
@@ -127,7 +127,7 @@ testRule('xgen-IPA-104-get-method-returns-single-resource', [
127127
},
128128
},
129129
},
130-
'/arraySingleton': {
130+
'/resource/{id}/arraySingleton': {
131131
get: {
132132
responses: {
133133
200: {
@@ -142,7 +142,7 @@ testRule('xgen-IPA-104-get-method-returns-single-resource', [
142142
},
143143
},
144144
},
145-
'/paginatedSingleton': {
145+
'/resource/{id}/paginatedSingleton': {
146146
get: {
147147
responses: {
148148
200: {
@@ -194,10 +194,10 @@ testRule('xgen-IPA-104-get-method-returns-single-resource', [
194194
{
195195
code: 'xgen-IPA-104-get-method-returns-single-resource',
196196
message:
197-
'Get methods should return data for a single resource. This method returns an array or a paginated response. http://go/ipa/104',
197+
'Get methods for singleton resource should return data for a single resource. This method returns an array or a paginated response. If this is not a singleton resource, please implement all standard methods. http://go/ipa/104',
198198
path: [
199199
'paths',
200-
'/arraySingleton',
200+
'/resource/{id}/arraySingleton',
201201
'get',
202202
'responses',
203203
'200',
@@ -209,10 +209,10 @@ testRule('xgen-IPA-104-get-method-returns-single-resource', [
209209
{
210210
code: 'xgen-IPA-104-get-method-returns-single-resource',
211211
message:
212-
'Get methods should return data for a single resource. This method returns an array or a paginated response. http://go/ipa/104',
212+
'Get methods for singleton resource should return data for a single resource. This method returns an array or a paginated response. If this is not a singleton resource, please implement all standard methods. http://go/ipa/104',
213213
path: [
214214
'paths',
215-
'/paginatedSingleton',
215+
'/resource/{id}/paginatedSingleton',
216216
'get',
217217
'responses',
218218
'200',
@@ -245,7 +245,7 @@ testRule('xgen-IPA-104-get-method-returns-single-resource', [
245245
},
246246
},
247247
},
248-
'/paginatedSingleton': {
248+
'/resource/{id}/paginatedSingleton': {
249249
get: {
250250
responses: {
251251
200: {

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

Lines changed: 43 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,10 @@ testRule('xgen-IPA-104-get-method-response-code-is-200', [
3131
},
3232
},
3333
},
34-
'/singleton': {
34+
'/resource/{id}/singleton': {
3535
get: {
3636
responses: {
37+
200: {},
3738
400: {},
3839
500: {},
3940
},
@@ -47,8 +48,8 @@ testRule('xgen-IPA-104-get-method-response-code-is-200', [
4748
name: 'invalid methods',
4849
document: {
4950
paths: {
50-
'/resource1': { get: { responses: {} } },
51-
'/resource1/{id}': {
51+
'/resourceOne': { get: { responses: {} } },
52+
'/resourceOne/{id}': {
5253
get: {
5354
responses: {
5455
201: {},
@@ -57,17 +58,17 @@ testRule('xgen-IPA-104-get-method-response-code-is-200', [
5758
},
5859
},
5960
},
60-
'/resource2': { get: { responses: {} } },
61-
'/resource2/{id}': {
61+
'/resourceTwo': { get: { responses: {} } },
62+
'/resourceTwo/{id}': {
6263
get: {
6364
responses: {
6465
400: {},
6566
500: {},
6667
},
6768
},
6869
},
69-
'/resource3': { get: { responses: {} } },
70-
'/resource3/{id}': {
70+
'/resourceThree': { get: { responses: {} } },
71+
'/resourceThree/{id}': {
7172
get: {
7273
responses: {
7374
200: {},
@@ -77,28 +78,44 @@ testRule('xgen-IPA-104-get-method-response-code-is-200', [
7778
},
7879
},
7980
},
81+
'/resource/{id}/singleton': {
82+
get: {
83+
responses: {
84+
202: {},
85+
400: {},
86+
500: {},
87+
},
88+
},
89+
},
8090
},
8191
},
8292
errors: [
8393
{
8494
code: 'xgen-IPA-104-get-method-response-code-is-200',
8595
message:
8696
'The Get method must return a 200 OK response. This method either lacks a 200 OK response or defines a different 2xx status code. http://go/ipa/104',
87-
path: ['paths', '/resource1/{id}', 'get'],
97+
path: ['paths', '/resourceOne/{id}', 'get'],
98+
severity: DiagnosticSeverity.Warning,
99+
},
100+
{
101+
code: 'xgen-IPA-104-get-method-response-code-is-200',
102+
message:
103+
'The Get method must return a 200 OK response. This method either lacks a 200 OK response or defines a different 2xx status code. http://go/ipa/104',
104+
path: ['paths', '/resourceTwo/{id}', 'get'],
88105
severity: DiagnosticSeverity.Warning,
89106
},
90107
{
91108
code: 'xgen-IPA-104-get-method-response-code-is-200',
92109
message:
93110
'The Get method must return a 200 OK response. This method either lacks a 200 OK response or defines a different 2xx status code. http://go/ipa/104',
94-
path: ['paths', '/resource2/{id}', 'get'],
111+
path: ['paths', '/resourceThree/{id}', 'get'],
95112
severity: DiagnosticSeverity.Warning,
96113
},
97114
{
98115
code: 'xgen-IPA-104-get-method-response-code-is-200',
99116
message:
100117
'The Get method must return a 200 OK response. This method either lacks a 200 OK response or defines a different 2xx status code. http://go/ipa/104',
101-
path: ['paths', '/resource3/{id}', 'get'],
118+
path: ['paths', '/resource/{id}/singleton', 'get'],
102119
severity: DiagnosticSeverity.Warning,
103120
},
104121
],
@@ -107,8 +124,8 @@ testRule('xgen-IPA-104-get-method-response-code-is-200', [
107124
name: 'invalid method with exception',
108125
document: {
109126
paths: {
110-
'/resource1': { get: { responses: {} } },
111-
'/resource1/{id}': {
127+
'/resourceOne': { get: { responses: {} } },
128+
'/resourceOne/{id}': {
112129
get: {
113130
responses: {
114131
201: {},
@@ -120,10 +137,22 @@ testRule('xgen-IPA-104-get-method-response-code-is-200', [
120137
},
121138
},
122139
},
123-
'/resource2': { get: { responses: {} } },
124-
'/resource2/{id}': {
140+
'/resourceTwo': { get: { responses: {} } },
141+
'/resourceTwo/{id}': {
142+
get: {
143+
responses: {
144+
400: {},
145+
500: {},
146+
},
147+
'x-xgen-IPA-exception': {
148+
'xgen-IPA-104-get-method-response-code-is-200': 'reason',
149+
},
150+
},
151+
},
152+
'/resource/{id}/singleton': {
125153
get: {
126154
responses: {
155+
202: {},
127156
400: {},
128157
500: {},
129158
},

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

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ testRule('xgen-IPA-113-singleton-must-not-have-id', [
66
name: 'valid resources',
77
document: {
88
paths: {
9-
'/standard': {
9+
'/resource': {
1010
post: {},
1111
get: {
1212
responses: {
@@ -26,7 +26,7 @@ testRule('xgen-IPA-113-singleton-must-not-have-id', [
2626
},
2727
},
2828
},
29-
'/standard/{exampleId}': {
29+
'/resource/{exampleId}': {
3030
get: {
3131
responses: {
3232
200: {
@@ -47,7 +47,7 @@ testRule('xgen-IPA-113-singleton-must-not-have-id', [
4747
patch: {},
4848
delete: {},
4949
},
50-
'/singleton1': {
50+
'/resource/{exampleId}/singletonOne': {
5151
get: {
5252
responses: {
5353
200: {
@@ -65,7 +65,7 @@ testRule('xgen-IPA-113-singleton-must-not-have-id', [
6565
},
6666
},
6767
},
68-
'/singleton2': {
68+
'/resource/{exampleId}/singletonTwo': {
6969
get: {
7070
responses: {
7171
200: {
@@ -92,7 +92,7 @@ testRule('xgen-IPA-113-singleton-must-not-have-id', [
9292
name: 'invalid resources',
9393
document: {
9494
paths: {
95-
'/singleton1': {
95+
'/resource/{exampleId}/singletonOne': {
9696
get: {
9797
responses: {
9898
200: {
@@ -111,7 +111,7 @@ testRule('xgen-IPA-113-singleton-must-not-have-id', [
111111
},
112112
},
113113
},
114-
'/singleton2': {
114+
'/resource/{exampleId}/singletonTwo': {
115115
get: {
116116
responses: {
117117
200: {
@@ -130,7 +130,7 @@ testRule('xgen-IPA-113-singleton-must-not-have-id', [
130130
},
131131
},
132132
},
133-
'/singleton3': {
133+
'/resource/{exampleId}/singletonThree': {
134134
get: {
135135
responses: {
136136
200: {
@@ -164,19 +164,19 @@ testRule('xgen-IPA-113-singleton-must-not-have-id', [
164164
{
165165
code: 'xgen-IPA-113-singleton-must-not-have-id',
166166
message: 'Singleton resources must not have a user-provided or system-generated ID. http://go/ipa/113',
167-
path: ['paths', '/singleton1'],
167+
path: ['paths', '/resource/{exampleId}/singletonOne'],
168168
severity: DiagnosticSeverity.Warning,
169169
},
170170
{
171171
code: 'xgen-IPA-113-singleton-must-not-have-id',
172172
message: 'Singleton resources must not have a user-provided or system-generated ID. http://go/ipa/113',
173-
path: ['paths', '/singleton2'],
173+
path: ['paths', '/resource/{exampleId}/singletonTwo'],
174174
severity: DiagnosticSeverity.Warning,
175175
},
176176
{
177177
code: 'xgen-IPA-113-singleton-must-not-have-id',
178178
message: 'Singleton resources must not have a user-provided or system-generated ID. http://go/ipa/113',
179-
path: ['paths', '/singleton3'],
179+
path: ['paths', '/resource/{exampleId}/singletonThree'],
180180
severity: DiagnosticSeverity.Warning,
181181
},
182182
],
@@ -185,7 +185,7 @@ testRule('xgen-IPA-113-singleton-must-not-have-id', [
185185
name: 'invalid resources with exceptions',
186186
document: {
187187
paths: {
188-
'/singleton1': {
188+
'/resource/{exampleId}/singletonOne': {
189189
'x-xgen-IPA-exception': {
190190
'xgen-IPA-113-singleton-must-not-have-id': 'reason',
191191
},

0 commit comments

Comments
 (0)