From 23d413f13b8a37e6294f0a88a77f8b8ae6b318aa Mon Sep 17 00:00:00 2001 From: vroudge Date: Mon, 6 Nov 2017 12:02:24 +0100 Subject: [PATCH 1/2] Support 201 / empty body --- src/db/fixtures.js | 2 ++ src/utils/createRouterFromSwagger.js | 29 ++++++++++++++++++---------- 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/src/db/fixtures.js b/src/db/fixtures.js index 15337e0..21fe36a 100644 --- a/src/db/fixtures.js +++ b/src/db/fixtures.js @@ -47,6 +47,8 @@ export const createFixturesFromDefinitions = (db, definitions) => { * @returns {{}} */ const generateOneFixture = (db, model) => { + console.log(model); + const { type, modelName } = model; switch (type) { diff --git a/src/utils/createRouterFromSwagger.js b/src/utils/createRouterFromSwagger.js index 06772c4..a041b81 100644 --- a/src/utils/createRouterFromSwagger.js +++ b/src/utils/createRouterFromSwagger.js @@ -79,10 +79,10 @@ const addMethodsToRouter = (db, router, { route, routerMethods, pathOptions }) = */ const responseGetter = (db, responses) => { let body; - const defaultSuccess = responses[200] || responses[204]; + const defaultSuccess = responses[200] || responses[201] || responses[204]; return ((ctx) => { - if (defaultSuccess) { + if (defaultSuccess && defaultSuccess.schema) { const objectRef = getReferencesAndCount(defaultSuccess.schema); const collection = findCollection(db, objectRef.object); @@ -94,15 +94,24 @@ const responseGetter = (db, responses) => { ) ) , objectRef.fixtureCount); + if (defaultSuccess.schema.type === 'array') { + ctx.body = body; + } + else if (defaultSuccess.schema['$ref']) { + ctx.body = body[0]; + } + return; + } else if (defaultSuccess) { + const possibleCodes = [200, 201, 204]; + for (const code of possibleCodes){ + if(responses[code]){ + ctx.status = code; + break; + } + } + return; } - if (defaultSuccess.schema.type === 'array') { - ctx.body = body; - } - else if (defaultSuccess.schema['$ref']) { - ctx.body = body[0]; - } else { - ctx.throw('Unsupported format! Can you create an issue in Github about that?') - } + ctx.throw('Unsupported format! Can you create an issue in Github about that?') }); From 74ea3fa60311b0048fdd98bad1bfcb0758abe51d Mon Sep 17 00:00:00 2001 From: vroudge Date: Mon, 6 Nov 2017 12:03:40 +0100 Subject: [PATCH 2/2] remove console.log --- src/db/fixtures.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/db/fixtures.js b/src/db/fixtures.js index 21fe36a..15337e0 100644 --- a/src/db/fixtures.js +++ b/src/db/fixtures.js @@ -47,8 +47,6 @@ export const createFixturesFromDefinitions = (db, definitions) => { * @returns {{}} */ const generateOneFixture = (db, model) => { - console.log(model); - const { type, modelName } = model; switch (type) {