Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Quality of life #68

Merged
merged 4 commits into from
Jun 8, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
132 changes: 118 additions & 14 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ export default function init (config) {

// Load documentation from service, if available.
const doc = service.docs;
const idName = service.id || 'id';
const idType = doc.idType || 'integer';
let version = config.versionPrefix ? path.match(config.versionPrefix) : null;
version = version ? ' ' + version[0] : '';
const apiPath = path.replace(config.prefix, '');
Expand All @@ -94,12 +96,16 @@ export default function init (config) {
}

const pathObj = rootDoc.paths;
const withIdKey = `/${path}/{${service.id || 'id'}}`;
const withIdKey = `/${path}/{${idName}}`;
const withoutIdKey = `/${path}`;
const securities = doc.securities || [];

if (typeof doc.definition !== 'undefined') {
rootDoc.definitions[tag] = doc.definition;
rootDoc.definitions[`${tag} list`] = {
type: 'array',
items: doc.definition
};
}

if (typeof doc.definitions !== 'undefined') {
Expand All @@ -112,6 +118,38 @@ export default function init (config) {
pathObj[withoutIdKey].get = utils.operation('find', service, {
tags: [tag],
description: 'Retrieves a list of all resources from the service.',
parameters: [
{
description: 'Number of results to return',
in: 'query',
name: '$limit',
type: 'integer'
},
{
description: 'Number of results to skip',
in: 'query',
name: '$skip',
type: 'integer'
},
{
description: 'Property to sort results',
in: 'query',
name: '$sort',
type: 'string'
}
],
responses: {
'200': {
description: 'success',
schema: {'$ref': '#/definitions/' + `${tag} list`}
},
'500': {
description: 'general error'
},
'401': {
description: 'not authenticated'
}
},
produces: rootDoc.produces,
consumes: rootDoc.consumes,
security: securities.indexOf('find') > -1 ? security : {}
Expand All @@ -128,12 +166,22 @@ export default function init (config) {
description: `ID of ${model} to return`,
in: 'path',
required: true,
name: 'resourceId',
type: 'integer'
name: idName,
type: idType
}],
responses: {
'200': {
description: 'success'
description: 'success',
schema: {'$ref': '#/definitions/' + tag}
},
'500': {
description: 'general error'
},
'401': {
description: 'not authenticated'
},
'404': {
description: 'not found'
}
},
produces: rootDoc.produces,
Expand All @@ -152,8 +200,19 @@ export default function init (config) {
in: 'body',
name: 'body',
required: true,
schema: {'$ref': '#/definitions/' + model}
schema: {'$ref': '#/definitions/' + tag}
}],
responses: {
'201': {
description: 'created'
},
'500': {
description: 'general error'
},
'401': {
description: 'not authenticated'
}
},
produces: rootDoc.produces,
consumes: rootDoc.consumes,
security: securities.indexOf('create') > -1 ? security : {}
Expand All @@ -170,14 +229,29 @@ export default function init (config) {
description: 'ID of ' + model + ' to return',
in: 'path',
required: true,
name: 'resourceId',
type: 'integer'
name: idName,
type: idType
}, {
in: 'body',
name: 'body',
required: true,
schema: {'$ref': '#/definitions/' + model}
schema: {'$ref': '#/definitions/' + tag}
}],
responses: {
'200': {
description: 'success',
schema: {'$ref': '#/definitions/' + tag}
},
'500': {
description: 'general error'
},
'401': {
description: 'not authenticated'
},
'404': {
description: 'not found'
}
},
produces: rootDoc.produces,
consumes: rootDoc.consumes,
security: securities.indexOf('update') > -1 ? security : {}
Expand All @@ -194,14 +268,29 @@ export default function init (config) {
description: 'ID of ' + model + ' to return',
in: 'path',
required: true,
name: 'resourceId',
type: 'integer'
name: idName,
type: idType
}, {
in: 'body',
name: 'body',
required: true,
schema: {'$ref': '#/definitions/' + model}
schema: {'$ref': '#/definitions/' + tag}
}],
responses: {
'200': {
description: 'success',
schema: {'$ref': '#/definitions/' + tag}
},
'500': {
description: 'general error'
},
'401': {
description: 'not authenticated'
},
'404': {
description: 'not found'
}
},
produces: rootDoc.produces,
consumes: rootDoc.consumes,
security: securities.indexOf('patch') > -1 ? security : {}
Expand All @@ -218,9 +307,24 @@ export default function init (config) {
description: 'ID of ' + model + ' to return',
in: 'path',
required: true,
name: 'resourceId',
type: 'integer'
name: idName,
type: idType
}],
responses: {
'200': {
description: 'success',
schema: {'$ref': '#/definitions/' + tag}
},
'500': {
description: 'general error'
},
'401': {
description: 'not authenticated'
},
'404': {
description: 'not found'
}
},
produces: rootDoc.produces,
consumes: rootDoc.consumes,
security: securities.indexOf('remove') > -1 ? security : {}
Expand Down