Skip to content

Commit 0374a81

Browse files
CLOUDP-304053: IPA-106:Create - The resource must be the request body (exclude readOnly:true and writeOnly:true) (#541)
1 parent 3cd6df5 commit 0374a81

10 files changed

+357
-226
lines changed

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

Lines changed: 35 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,15 @@ const componentSchemas = {
66
SchemaOne: {
77
type: 'string',
88
},
9-
SchemaTwo: {
9+
SchemaTwoRequest: {
1010
type: 'object',
1111
properties: {
1212
name: {
1313
type: 'string',
14-
readOnly: true,
14+
writeOnly: true,
15+
},
16+
otherThing: {
17+
type: 'string',
1518
},
1619
},
1720
},
@@ -29,12 +32,15 @@ const componentSchemas = {
2932
},
3033
},
3134
},
32-
SchemaFour: {
35+
SchemaTwoResponse: {
3336
type: 'object',
3437
properties: {
3538
name: {
3639
type: 'string',
37-
writeOnly: true,
40+
readOnly: true,
41+
},
42+
otherThing: {
43+
type: 'string',
3844
},
3945
},
4046
},
@@ -132,12 +138,12 @@ testRule('xgen-IPA-106-create-method-request-body-is-get-method-response', [
132138
content: {
133139
'application/vnd.atlas.2023-01-01+json': {
134140
schema: {
135-
$ref: '#/components/schemas/SchemaTwo',
141+
$ref: '#/components/schemas/SchemaTwoRequest',
136142
},
137143
},
138144
'application/vnd.atlas.2024-01-01+json': {
139145
schema: {
140-
$ref: '#/components/schemas/SchemaTwo',
146+
$ref: '#/components/schemas/SchemaTwoRequest',
141147
},
142148
},
143149
},
@@ -151,7 +157,12 @@ testRule('xgen-IPA-106-create-method-request-body-is-get-method-response', [
151157
content: {
152158
'application/vnd.atlas.2023-01-01+json': {
153159
schema: {
154-
$ref: '#/components/schemas/SchemaFour',
160+
$ref: '#/components/schemas/SchemaTwoResponse',
161+
},
162+
},
163+
'application/vnd.atlas.2024-01-01+json': {
164+
schema: {
165+
$ref: '#/components/schemas/SchemaTwoResponse',
155166
},
156167
},
157168
},
@@ -244,7 +255,7 @@ testRule('xgen-IPA-106-create-method-request-body-is-get-method-response', [
244255
content: {
245256
'application/vnd.atlas.2023-01-01+json': {
246257
schema: {
247-
$ref: '#/components/schemas/SchemaTwo',
258+
$ref: '#/components/schemas/SchemaTwoRequest',
248259
},
249260
},
250261
},
@@ -258,12 +269,12 @@ testRule('xgen-IPA-106-create-method-request-body-is-get-method-response', [
258269
content: {
259270
'application/vnd.atlas.2023-01-01+json': {
260271
schema: {
261-
$ref: '#/components/schemas/SchemaTwo',
272+
$ref: '#/components/schemas/SchemaTwoResponse',
262273
},
263274
},
264275
'application/vnd.atlas.2024-01-01+json': {
265276
schema: {
266-
$ref: '#/components/schemas/SchemaTwo',
277+
$ref: '#/components/schemas/SchemaTwoResponse',
267278
},
268279
},
269280
},
@@ -382,56 +393,56 @@ testRule('xgen-IPA-106-create-method-request-body-is-get-method-response', [
382393
{
383394
code: 'xgen-IPA-106-create-method-request-body-is-get-method-response',
384395
message:
385-
'The request body schema properties must match the response body schema properties of the Get method. http://go/ipa/106',
396+
'The request body schema properties must match the response body schema properties of the Get method. http://go/ipa-spectral#IPA-106',
386397
path: ['paths', '/resource', 'post', 'requestBody', 'content', 'application/vnd.atlas.2023-01-01+json'],
387398
severity: DiagnosticSeverity.Warning,
388399
},
389400
{
390401
code: 'xgen-IPA-106-create-method-request-body-is-get-method-response',
391402
message:
392-
'The request body schema properties must match the response body schema properties of the Get method. http://go/ipa/106',
403+
'The request body schema properties must match the response body schema properties of the Get method. http://go/ipa-spectral#IPA-106',
393404
path: ['paths', '/resource', 'post', 'requestBody', 'content', 'application/vnd.atlas.2024-01-01+json'],
394405
severity: DiagnosticSeverity.Warning,
395406
},
396407
{
397408
code: 'xgen-IPA-106-create-method-request-body-is-get-method-response',
398409
message:
399-
'The request body schema properties must match the response body schema properties of the Get method. http://go/ipa/106',
410+
'The request body schema properties must match the response body schema properties of the Get method. http://go/ipa-spectral#IPA-106',
400411
path: ['paths', '/resourceTwo', 'post', 'requestBody', 'content', 'application/vnd.atlas.2023-01-01+json'],
401412
severity: DiagnosticSeverity.Warning,
402413
},
403414
{
404415
code: 'xgen-IPA-106-create-method-request-body-is-get-method-response',
405416
message:
406-
'The request body schema properties must match the response body schema properties of the Get method. http://go/ipa/106',
417+
'The request body schema properties must match the response body schema properties of the Get method. http://go/ipa-spectral#IPA-106',
407418
path: ['paths', '/resourceTwo', 'post', 'requestBody', 'content', 'application/vnd.atlas.2024-01-01+json'],
408419
severity: DiagnosticSeverity.Warning,
409420
},
410421
{
411422
code: 'xgen-IPA-106-create-method-request-body-is-get-method-response',
412423
message:
413-
'The request body schema properties must match the response body schema properties of the Get method. http://go/ipa/106',
424+
'The request body schema properties must match the response body schema properties of the Get method. http://go/ipa-spectral#IPA-106',
414425
path: ['paths', '/resourceThree', 'post', 'requestBody', 'content', 'application/vnd.atlas.2023-01-01+json'],
415426
severity: DiagnosticSeverity.Warning,
416427
},
417428
{
418429
code: 'xgen-IPA-106-create-method-request-body-is-get-method-response',
419430
message:
420-
'Could not validate that the Create request body schema matches the response schema of the Get method. The Get method does not have a schema. http://go/ipa/106',
431+
'Could not validate that the Create request body schema matches the response schema of the Get method. The Get method does not have a schema. http://go/ipa-spectral#IPA-106',
421432
path: ['paths', '/resourceFour', 'post', 'requestBody', 'content', 'application/vnd.atlas.2023-01-01+json'],
422433
severity: DiagnosticSeverity.Warning,
423434
},
424435
{
425436
code: 'xgen-IPA-106-create-method-request-body-is-get-method-response',
426437
message:
427-
'The request body schema properties must match the response body schema properties of the Get method. http://go/ipa/106',
438+
'The request body schema properties must match the response body schema properties of the Get method. http://go/ipa-spectral#IPA-106',
428439
path: ['paths', '/resourceCircular', 'post', 'requestBody', 'content', 'application/vnd.atlas.2023-01-01+json'],
429440
severity: DiagnosticSeverity.Warning,
430441
},
431442
{
432443
code: 'xgen-IPA-106-create-method-request-body-is-get-method-response',
433444
message:
434-
'The request body schema properties must match the response body schema properties of the Get method. http://go/ipa/106',
445+
'The request body schema properties must match the response body schema properties of the Get method. http://go/ipa-spectral#IPA-106',
435446
path: ['paths', '/resourceCircular', 'post', 'requestBody', 'content', 'application/vnd.atlas.2024-01-01+json'],
436447
severity: DiagnosticSeverity.Warning,
437448
},
@@ -481,14 +492,14 @@ testRule('xgen-IPA-106-create-method-request-body-is-get-method-response', [
481492
{
482493
code: 'xgen-IPA-106-create-method-request-body-is-get-method-response',
483494
message:
484-
'The request body schema properties must match the response body schema properties of the Get method. http://go/ipa/106',
495+
'The request body schema properties must match the response body schema properties of the Get method. http://go/ipa-spectral#IPA-106',
485496
path: ['paths', '/animalResource', 'post', 'requestBody', 'content', 'application/vnd.atlas.2023-01-01+json'],
486497
severity: DiagnosticSeverity.Warning,
487498
},
488499
{
489500
code: 'xgen-IPA-106-create-method-request-body-is-get-method-response',
490501
message:
491-
'The request body schema properties must match the response body schema properties of the Get method. http://go/ipa/106',
502+
'The request body schema properties must match the response body schema properties of the Get method. http://go/ipa-spectral#IPA-106',
492503
path: ['paths', '/animalResource', 'post', 'requestBody', 'content', 'application/vnd.atlas.2024-01-01+json'],
493504
severity: DiagnosticSeverity.Warning,
494505
},
@@ -511,14 +522,6 @@ testRule('xgen-IPA-106-create-method-request-body-is-get-method-response', [
511522
'xgen-IPA-106-create-method-request-body-is-get-method-response': 'reason',
512523
},
513524
},
514-
'application/vnd.atlas.2024-01-01+json': {
515-
schema: {
516-
$ref: '#/components/schemas/SchemaOne',
517-
},
518-
'x-xgen-IPA-exception': {
519-
'xgen-IPA-106-create-method-request-body-is-get-method-response': 'reason',
520-
},
521-
},
522525
},
523526
},
524527
},
@@ -530,7 +533,7 @@ testRule('xgen-IPA-106-create-method-request-body-is-get-method-response', [
530533
content: {
531534
'application/vnd.atlas.2023-01-01+json': {
532535
schema: {
533-
$ref: '#/components/schemas/SchemaTwo',
536+
$ref: '#/components/schemas/SchemaThree',
534537
},
535538
},
536539
},
@@ -544,15 +547,15 @@ testRule('xgen-IPA-106-create-method-request-body-is-get-method-response', [
544547
content: {
545548
'application/vnd.atlas.2023-01-01+json': {
546549
schema: {
547-
$ref: '#/components/schemas/SchemaTwo',
550+
$ref: '#/components/schemas/SchemaTwoRequest',
548551
},
549552
'x-xgen-IPA-exception': {
550553
'xgen-IPA-106-create-method-request-body-is-get-method-response': 'reason',
551554
},
552555
},
553556
'application/vnd.atlas.2024-01-01+json': {
554557
schema: {
555-
$ref: '#/components/schemas/SchemaTwo',
558+
$ref: '#/components/schemas/SchemaTwoRequest',
556559
},
557560
'x-xgen-IPA-exception': {
558561
'xgen-IPA-106-create-method-request-body-is-get-method-response': 'reason',
@@ -569,43 +572,7 @@ testRule('xgen-IPA-106-create-method-request-body-is-get-method-response', [
569572
content: {
570573
'application/vnd.atlas.2023-01-01+json': {
571574
schema: {
572-
$ref: '#/components/schemas/SchemaThree',
573-
},
574-
},
575-
},
576-
},
577-
},
578-
},
579-
},
580-
'/resourceThree': {
581-
post: {
582-
requestBody: {
583-
content: {
584-
'application/vnd.atlas.2023-01-01+json': {
585-
schema: {
586-
$ref: '#/components/schemas/SchemaOne',
587-
},
588-
'x-xgen-IPA-exception': {
589-
'xgen-IPA-106-create-method-request-body-is-get-method-response': 'reason',
590-
},
591-
},
592-
'application/vnd.atlas.2024-01-01+json': {
593-
schema: {
594-
$ref: '#/components/schemas/SchemaThree',
595-
},
596-
},
597-
},
598-
},
599-
},
600-
},
601-
'/resourceThree/{id}': {
602-
get: {
603-
responses: {
604-
200: {
605-
content: {
606-
'application/vnd.atlas.2023-01-01+json': {
607-
schema: {
608-
$ref: '#/components/schemas/SchemaThree',
575+
$ref: '#/components/schemas/SchemaTwoResponse',
609576
},
610577
},
611578
},

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

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -154,31 +154,36 @@ testRule('xgen-IPA-106-create-method-request-body-is-request-suffixed-object', [
154154
errors: [
155155
{
156156
code: 'xgen-IPA-106-create-method-request-body-is-request-suffixed-object',
157-
message: 'The response body schema must reference a schema with a Request suffix. http://go/ipa/106',
157+
message:
158+
'The response body schema must reference a schema with a Request suffix. http://go/ipa-spectral#IPA-106',
158159
path: ['paths', '/resource', 'post', 'requestBody', 'content', 'application/vnd.atlas.2023-01-01+json'],
159160
severity: DiagnosticSeverity.Warning,
160161
},
161162
{
162163
code: 'xgen-IPA-106-create-method-request-body-is-request-suffixed-object',
163-
message: 'The response body schema must reference a schema with a Request suffix. http://go/ipa/106',
164+
message:
165+
'The response body schema must reference a schema with a Request suffix. http://go/ipa-spectral#IPA-106',
164166
path: ['paths', '/resource', 'post', 'requestBody', 'content', 'application/vnd.atlas.2024-01-01+json'],
165167
severity: DiagnosticSeverity.Warning,
166168
},
167169
{
168170
code: 'xgen-IPA-106-create-method-request-body-is-request-suffixed-object',
169-
message: 'The response body schema must reference a schema with a Request suffix. http://go/ipa/106',
171+
message:
172+
'The response body schema must reference a schema with a Request suffix. http://go/ipa-spectral#IPA-106',
170173
path: ['paths', '/resourceTwo', 'post', 'requestBody', 'content', 'application/vnd.atlas.2023-01-01+json'],
171174
severity: DiagnosticSeverity.Warning,
172175
},
173176
{
174177
code: 'xgen-IPA-106-create-method-request-body-is-request-suffixed-object',
175-
message: 'The response body schema must reference a schema with a Request suffix. http://go/ipa/106',
178+
message:
179+
'The response body schema must reference a schema with a Request suffix. http://go/ipa-spectral#IPA-106',
176180
path: ['paths', '/resourceTwo', 'post', 'requestBody', 'content', 'application/vnd.atlas.2024-01-01+json'],
177181
severity: DiagnosticSeverity.Warning,
178182
},
179183
{
180184
code: 'xgen-IPA-106-create-method-request-body-is-request-suffixed-object',
181-
message: 'The response body schema is defined inline and must reference a predefined schema. http://go/ipa/106',
185+
message:
186+
'The response body schema is defined inline and must reference a predefined schema. http://go/ipa-spectral#IPA-106',
182187
path: ['paths', '/resourceThree', 'post', 'requestBody', 'content', 'application/vnd.atlas.2023-01-01+json'],
183188
severity: DiagnosticSeverity.Warning,
184189
},

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -152,14 +152,14 @@ testRule('xgen-IPA-106-create-method-request-has-no-readonly-fields', [
152152
{
153153
code: 'xgen-IPA-106-create-method-request-has-no-readonly-fields',
154154
message:
155-
'The Create method request object must not include input fields (readOnly properties). Found readOnly property at: id. http://go/ipa/106',
155+
'The Create method request object must not include input fields (readOnly properties). Found readOnly property at: id. http://go/ipa-spectral#IPA-106',
156156
path: ['paths', '/resource', 'post', 'requestBody', 'content', 'application/vnd.atlas.2023-01-01+json'],
157157
severity: DiagnosticSeverity.Warning,
158158
},
159159
{
160160
code: 'xgen-IPA-106-create-method-request-has-no-readonly-fields',
161161
message:
162-
'The Create method request object must not include input fields (readOnly properties). Found readOnly property at one of the inline schemas. http://go/ipa/106',
162+
'The Create method request object must not include input fields (readOnly properties). Found readOnly property at one of the inline schemas. http://go/ipa-spectral#IPA-106',
163163
path: ['paths', '/resource', 'post', 'requestBody', 'content', 'application/vnd.atlas.2024-01-01+json'],
164164
severity: DiagnosticSeverity.Warning,
165165
},
@@ -192,7 +192,7 @@ testRule('xgen-IPA-106-create-method-request-has-no-readonly-fields', [
192192
{
193193
code: 'xgen-IPA-106-create-method-request-has-no-readonly-fields',
194194
message:
195-
'The Create method request object must not include input fields (readOnly properties). Found readOnly property at: user.userId. http://go/ipa/106',
195+
'The Create method request object must not include input fields (readOnly properties). Found readOnly property at: user.userId. http://go/ipa-spectral#IPA-106',
196196
path: ['paths', '/resource', 'post', 'requestBody', 'content', 'application/vnd.atlas.2023-01-01+json'],
197197
severity: DiagnosticSeverity.Warning,
198198
},
@@ -225,7 +225,7 @@ testRule('xgen-IPA-106-create-method-request-has-no-readonly-fields', [
225225
{
226226
code: 'xgen-IPA-106-create-method-request-has-no-readonly-fields',
227227
message:
228-
'The Create method request object must not include input fields (readOnly properties). Found readOnly property at: items.items.itemId. http://go/ipa/106',
228+
'The Create method request object must not include input fields (readOnly properties). Found readOnly property at: items.items.itemId. http://go/ipa-spectral#IPA-106',
229229
path: ['paths', '/resource', 'post', 'requestBody', 'content', 'application/vnd.atlas.2023-01-01+json'],
230230
severity: DiagnosticSeverity.Warning,
231231
},

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,21 +74,21 @@ testRule('xgen-IPA-106-create-method-response-code-is-201', [
7474
{
7575
code: 'xgen-IPA-106-create-method-response-code-is-201',
7676
message:
77-
'The Create method must return a 201 Created response. This method either lacks a 201 Created response or defines a different 2xx status code. http://go/ipa/106',
77+
'The Create method must return a 201 Created response. This method either lacks a 201 Created response or defines a different 2xx status code. http://go/ipa-spectral#IPA-106',
7878
path: ['paths', '/resourceOne', 'post'],
7979
severity: DiagnosticSeverity.Warning,
8080
},
8181
{
8282
code: 'xgen-IPA-106-create-method-response-code-is-201',
8383
message:
84-
'The Create method must return a 201 Created response. This method either lacks a 201 Created response or defines a different 2xx status code. http://go/ipa/106',
84+
'The Create method must return a 201 Created response. This method either lacks a 201 Created response or defines a different 2xx status code. http://go/ipa-spectral#IPA-106',
8585
path: ['paths', '/resourceTwo', 'post'],
8686
severity: DiagnosticSeverity.Warning,
8787
},
8888
{
8989
code: 'xgen-IPA-106-create-method-response-code-is-201',
9090
message:
91-
'The Create method must return a 201 Created response. This method either lacks a 201 Created response or defines a different 2xx status code. http://go/ipa/106',
91+
'The Create method must return a 201 Created response. This method either lacks a 201 Created response or defines a different 2xx status code. http://go/ipa-spectral#IPA-106',
9292
path: ['paths', '/resourceThree', 'post'],
9393
severity: DiagnosticSeverity.Warning,
9494
},

0 commit comments

Comments
 (0)