From aab1c77c847b49a352fb5c8c55626a3587b2e591 Mon Sep 17 00:00:00 2001 From: Dom Harrington Date: Thu, 26 Oct 2017 15:12:12 -0700 Subject: [PATCH] Make sure enums are passed through --- .../lib/parameters-to-json-schema.test.js | 32 +++++++++++++++++++ .../src/lib/parameters-to-json-schema.js | 1 + 2 files changed, 33 insertions(+) diff --git a/packages/api-explorer-ui/__tests__/lib/parameters-to-json-schema.test.js b/packages/api-explorer-ui/__tests__/lib/parameters-to-json-schema.test.js index cae6b80d8..51fd6ba03 100644 --- a/packages/api-explorer-ui/__tests__/lib/parameters-to-json-schema.test.js +++ b/packages/api-explorer-ui/__tests__/lib/parameters-to-json-schema.test.js @@ -107,6 +107,38 @@ test('it should work for request body inline', () => { ]); }); +test('should pass through enum', () => { + expect( + parametersToJsonSchema({ + parameters: [ + { + in: 'header', + name: 'Accept', + required: false, + schema: { + type: 'string', + enum: ['application/json', 'application/xml'], + } + }, + ], + }), + ).toEqual([ + { + label: 'Headers', + type: 'header', + schema: { + type: 'object', + properties: { + Accept: { + type: 'string', + enum: ['application/json', 'application/xml'], + } + }, + required: [], + }, + }, + ]); +}); test.skip('it should work for top-level request body $ref', () => { expect( parametersToJsonSchema( diff --git a/packages/api-explorer-ui/src/lib/parameters-to-json-schema.js b/packages/api-explorer-ui/src/lib/parameters-to-json-schema.js index 264280754..b3a29e633 100644 --- a/packages/api-explorer-ui/src/lib/parameters-to-json-schema.js +++ b/packages/api-explorer-ui/src/lib/parameters-to-json-schema.js @@ -45,6 +45,7 @@ module.exports = pathOperation => { schema.type = 'array'; schema.items = current.schema.items; } + if (current.schema.enum) schema.enum = current.schema.enum; } prev[current.name] = schema;