Skip to content

Commit

Permalink
Support 201 / empty body
Browse files Browse the repository at this point in the history
  • Loading branch information
vroudge committed Nov 6, 2017
1 parent 97530ed commit 23d413f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
2 changes: 2 additions & 0 deletions src/db/fixtures.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ export const createFixturesFromDefinitions = (db, definitions) => {
* @returns {{}}
*/
const generateOneFixture = (db, model) => {
console.log(model);

const { type, modelName } = model;

switch (type) {
Expand Down
29 changes: 19 additions & 10 deletions src/utils/createRouterFromSwagger.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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?')

});

Expand Down

0 comments on commit 23d413f

Please sign in to comment.