From 272a3dc2e3ecdec6d6e7cad5d2e3ab3d7e25df35 Mon Sep 17 00:00:00 2001 From: Mike Kistler Date: Mon, 15 May 2023 15:40:08 -0700 Subject: [PATCH] Check nextLink is format: url --- functions/pagination-response.js | 5 ++++ test/pagination-response.test.js | 42 ++++++++++++++++++++++++++++---- 2 files changed, 42 insertions(+), 5 deletions(-) diff --git a/functions/pagination-response.js b/functions/pagination-response.js index b6ea019..3ef3a93 100644 --- a/functions/pagination-response.js +++ b/functions/pagination-response.js @@ -59,6 +59,11 @@ module.exports = (operation, _opts, paths) => { message: `\`${nextLinkName}\` property in pageable response should be type: string`, path: [...path, 'responses', resp, 'schema', 'properties', nextLinkName, 'type'], }); + } else if (responseSchema.properties[nextLinkName].format !== 'url') { + errors.push({ + message: `\`${nextLinkName}\` property in pageable response should be format: url`, + path: [...path, 'responses', resp, 'schema', 'properties', nextLinkName, 'format'], + }); } if (responseSchema.required?.includes(nextLinkName)) { errors.push({ diff --git a/test/pagination-response.test.js b/test/pagination-response.test.js index b9c51ce..803a10c 100644 --- a/test/pagination-response.test.js +++ b/test/pagination-response.test.js @@ -68,6 +68,7 @@ test('az-pagination-response should find errors in value property', () => { }, nextLink: { type: 'string', + format: 'url', }, }, required: ['value'], @@ -91,6 +92,7 @@ test('az-pagination-response should find errors in value property', () => { }, nextLink: { type: 'string', + format: 'url', }, }, }, @@ -113,6 +115,7 @@ test('az-pagination-response should find errors in value property', () => { }, nextLink: { type: 'string', + format: 'url', }, }, required: ['value'], @@ -164,6 +167,29 @@ test('az-pagination-response should find errors in nextLink property', () => { }, }, }, + '/test5a': { + get: { + responses: { + 200: { + description: 'Success', + schema: { + properties: { + value: { + type: 'array', + }, + nextLink: { + type: 'string', + }, + }, + required: ['value'], + }, + }, + }, + 'x-ms-pageable': { + nextLinkName: 'nextLink', + }, + }, + }, '/test6': { get: { responses: { @@ -176,6 +202,7 @@ test('az-pagination-response should find errors in nextLink property', () => { }, nextPage: { type: 'string', + format: 'url', }, }, required: ['value', 'nextPage'], @@ -213,13 +240,15 @@ test('az-pagination-response should find errors in nextLink property', () => { }, }; return linter.run(oasDoc).then((results) => { - expect(results.length).toBe(3); + expect(results.length).toBe(4); expect(results[0].path.join('.')).toBe('paths./test5.get.responses.200.schema.properties.nextLink.type'); expect(results[0].message).toBe('`nextLink` property in pageable response should be type: string'); - expect(results[1].path.join('.')).toBe('paths./test6.get.responses.200.schema.required'); - expect(results[1].message).toBe('`nextPage` property in pageable response should be optional.'); - expect(results[2].path.join('.')).toBe('paths./test7.get.responses.200.schema.properties'); - expect(results[2].message).toBe('Response body schema of pageable response should contain top-level property `nextLink`'); + expect(results[1].path.join('.')).toBe('paths./test5a.get.responses.200.schema.properties.nextLink'); + expect(results[1].message).toBe('`nextLink` property in pageable response should be format: url'); + expect(results[2].path.join('.')).toBe('paths./test6.get.responses.200.schema.required'); + expect(results[2].message).toBe('`nextPage` property in pageable response should be optional.'); + expect(results[3].path.join('.')).toBe('paths./test7.get.responses.200.schema.properties'); + expect(results[3].message).toBe('Response body schema of pageable response should contain top-level property `nextLink`'); }); }); @@ -240,6 +269,7 @@ test('az-pagination-response should find no errors', () => { }, nextLink: { type: 'string', + format: 'url', }, }, required: ['value'], @@ -264,6 +294,7 @@ test('az-pagination-response should find no errors', () => { }, nextLink: { type: 'string', + format: 'url', }, }, required: ['value'], @@ -288,6 +319,7 @@ test('az-pagination-response should find no errors', () => { }, nextPage: { type: 'string', + format: 'url', }, }, required: ['value'],