Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,6 @@ testRule('xgen-IPA-104-resource-has-GET', [
'/custom:method': {
post: {},
},
'/singleton': {
get: {},
},
},
},
errors: [],
Expand Down Expand Up @@ -87,8 +84,8 @@ testRule('xgen-IPA-104-resource-has-GET', [
'/custom:method': {
post: {},
},
'/singleton': {
patch: {},
'/standardWithoutSubResource': {
get: {},
},
},
},
Expand Down Expand Up @@ -120,7 +117,7 @@ testRule('xgen-IPA-104-resource-has-GET', [
{
code: 'xgen-IPA-104-resource-has-GET',
message: 'APIs must provide a get method for resources. http://go/ipa/104',
path: ['paths', '/singleton'],
path: ['paths', '/standardWithoutSubResource'],
severity: DiagnosticSeverity.Warning,
},
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ testRule('xgen-IPA-104-get-method-returns-single-resource', [
},
},
},
'/singleton': {
'/resource/{id}/singleton': {
get: {
responses: {
200: {
Expand Down Expand Up @@ -127,7 +127,7 @@ testRule('xgen-IPA-104-get-method-returns-single-resource', [
},
},
},
'/arraySingleton': {
'/resource/{id}/arraySingleton': {
get: {
responses: {
200: {
Expand All @@ -142,7 +142,7 @@ testRule('xgen-IPA-104-get-method-returns-single-resource', [
},
},
},
'/paginatedSingleton': {
'/resource/{id}/paginatedSingleton': {
get: {
responses: {
200: {
Expand Down Expand Up @@ -194,10 +194,10 @@ testRule('xgen-IPA-104-get-method-returns-single-resource', [
{
code: 'xgen-IPA-104-get-method-returns-single-resource',
message:
'Get methods should return data for a single resource. This method returns an array or a paginated response. http://go/ipa/104',
'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',
path: [
'paths',
'/arraySingleton',
'/resource/{id}/arraySingleton',
'get',
'responses',
'200',
Expand All @@ -209,10 +209,10 @@ testRule('xgen-IPA-104-get-method-returns-single-resource', [
{
code: 'xgen-IPA-104-get-method-returns-single-resource',
message:
'Get methods should return data for a single resource. This method returns an array or a paginated response. http://go/ipa/104',
'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',
path: [
'paths',
'/paginatedSingleton',
'/resource/{id}/paginatedSingleton',
'get',
'responses',
'200',
Expand Down Expand Up @@ -245,7 +245,7 @@ testRule('xgen-IPA-104-get-method-returns-single-resource', [
},
},
},
'/paginatedSingleton': {
'/resource/{id}/paginatedSingleton': {
get: {
responses: {
200: {
Expand Down
57 changes: 43 additions & 14 deletions tools/spectral/ipa/__tests__/getResponseCodeShouldBe200OK.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,10 @@ testRule('xgen-IPA-104-get-method-response-code-is-200', [
},
},
},
'/singleton': {
'/resource/{id}/singleton': {
get: {
responses: {
200: {},
400: {},
500: {},
},
Expand All @@ -47,8 +48,8 @@ testRule('xgen-IPA-104-get-method-response-code-is-200', [
name: 'invalid methods',
document: {
paths: {
'/resource1': { get: { responses: {} } },
'/resource1/{id}': {
'/resourceOne': { get: { responses: {} } },
'/resourceOne/{id}': {
get: {
responses: {
201: {},
Expand All @@ -57,17 +58,17 @@ testRule('xgen-IPA-104-get-method-response-code-is-200', [
},
},
},
'/resource2': { get: { responses: {} } },
'/resource2/{id}': {
'/resourceTwo': { get: { responses: {} } },
'/resourceTwo/{id}': {
get: {
responses: {
400: {},
500: {},
},
},
},
'/resource3': { get: { responses: {} } },
'/resource3/{id}': {
'/resourceThree': { get: { responses: {} } },
'/resourceThree/{id}': {
get: {
responses: {
200: {},
Expand All @@ -77,28 +78,44 @@ testRule('xgen-IPA-104-get-method-response-code-is-200', [
},
},
},
'/resource/{id}/singleton': {
get: {
responses: {
202: {},
400: {},
500: {},
},
},
},
},
},
errors: [
{
code: 'xgen-IPA-104-get-method-response-code-is-200',
message:
'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',
path: ['paths', '/resource1/{id}', 'get'],
path: ['paths', '/resourceOne/{id}', 'get'],
severity: DiagnosticSeverity.Warning,
},
{
code: 'xgen-IPA-104-get-method-response-code-is-200',
message:
'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',
path: ['paths', '/resourceTwo/{id}', 'get'],
severity: DiagnosticSeverity.Warning,
},
{
code: 'xgen-IPA-104-get-method-response-code-is-200',
message:
'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',
path: ['paths', '/resource2/{id}', 'get'],
path: ['paths', '/resourceThree/{id}', 'get'],
severity: DiagnosticSeverity.Warning,
},
{
code: 'xgen-IPA-104-get-method-response-code-is-200',
message:
'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',
path: ['paths', '/resource3/{id}', 'get'],
path: ['paths', '/resource/{id}/singleton', 'get'],
severity: DiagnosticSeverity.Warning,
},
],
Expand All @@ -107,8 +124,8 @@ testRule('xgen-IPA-104-get-method-response-code-is-200', [
name: 'invalid method with exception',
document: {
paths: {
'/resource1': { get: { responses: {} } },
'/resource1/{id}': {
'/resourceOne': { get: { responses: {} } },
'/resourceOne/{id}': {
get: {
responses: {
201: {},
Expand All @@ -120,10 +137,22 @@ testRule('xgen-IPA-104-get-method-response-code-is-200', [
},
},
},
'/resource2': { get: { responses: {} } },
'/resource2/{id}': {
'/resourceTwo': { get: { responses: {} } },
'/resourceTwo/{id}': {
get: {
responses: {
400: {},
500: {},
},
'x-xgen-IPA-exception': {
'xgen-IPA-104-get-method-response-code-is-200': 'reason',
},
},
},
'/resource/{id}/singleton': {
get: {
responses: {
202: {},
400: {},
500: {},
},
Expand Down
22 changes: 11 additions & 11 deletions tools/spectral/ipa/__tests__/singletonHasNoId.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ testRule('xgen-IPA-113-singleton-must-not-have-id', [
name: 'valid resources',
document: {
paths: {
'/standard': {
'/resource': {
post: {},
get: {
responses: {
Expand All @@ -26,7 +26,7 @@ testRule('xgen-IPA-113-singleton-must-not-have-id', [
},
},
},
'/standard/{exampleId}': {
'/resource/{exampleId}': {
get: {
responses: {
200: {
Expand All @@ -47,7 +47,7 @@ testRule('xgen-IPA-113-singleton-must-not-have-id', [
patch: {},
delete: {},
},
'/singleton1': {
'/resource/{exampleId}/singletonOne': {
get: {
responses: {
200: {
Expand All @@ -65,7 +65,7 @@ testRule('xgen-IPA-113-singleton-must-not-have-id', [
},
},
},
'/singleton2': {
'/resource/{exampleId}/singletonTwo': {
get: {
responses: {
200: {
Expand All @@ -92,7 +92,7 @@ testRule('xgen-IPA-113-singleton-must-not-have-id', [
name: 'invalid resources',
document: {
paths: {
'/singleton1': {
'/resource/{exampleId}/singletonOne': {
get: {
responses: {
200: {
Expand All @@ -111,7 +111,7 @@ testRule('xgen-IPA-113-singleton-must-not-have-id', [
},
},
},
'/singleton2': {
'/resource/{exampleId}/singletonTwo': {
get: {
responses: {
200: {
Expand All @@ -130,7 +130,7 @@ testRule('xgen-IPA-113-singleton-must-not-have-id', [
},
},
},
'/singleton3': {
'/resource/{exampleId}/singletonThree': {
get: {
responses: {
200: {
Expand Down Expand Up @@ -164,19 +164,19 @@ testRule('xgen-IPA-113-singleton-must-not-have-id', [
{
code: 'xgen-IPA-113-singleton-must-not-have-id',
message: 'Singleton resources must not have a user-provided or system-generated ID. http://go/ipa/113',
path: ['paths', '/singleton1'],
path: ['paths', '/resource/{exampleId}/singletonOne'],
severity: DiagnosticSeverity.Warning,
},
{
code: 'xgen-IPA-113-singleton-must-not-have-id',
message: 'Singleton resources must not have a user-provided or system-generated ID. http://go/ipa/113',
path: ['paths', '/singleton2'],
path: ['paths', '/resource/{exampleId}/singletonTwo'],
severity: DiagnosticSeverity.Warning,
},
{
code: 'xgen-IPA-113-singleton-must-not-have-id',
message: 'Singleton resources must not have a user-provided or system-generated ID. http://go/ipa/113',
path: ['paths', '/singleton3'],
path: ['paths', '/resource/{exampleId}/singletonThree'],
severity: DiagnosticSeverity.Warning,
},
],
Expand All @@ -185,7 +185,7 @@ testRule('xgen-IPA-113-singleton-must-not-have-id', [
name: 'invalid resources with exceptions',
document: {
paths: {
'/singleton1': {
'/resource/{exampleId}/singletonOne': {
'x-xgen-IPA-exception': {
'xgen-IPA-113-singleton-must-not-have-id': 'reason',
},
Expand Down
Loading
Loading