mirror of https://gitee.com/bigwinds/arangodb
Add support for Swagger tags
This commit is contained in:
parent
cd98d53ec4
commit
9a81d2cb63
|
@ -49,6 +49,14 @@ const PARSED_JSON_MIME = (function (mime) {
|
|||
]));
|
||||
}(MIME_JSON));
|
||||
|
||||
const repeat = (times, value) => {
|
||||
const arr = Array(times);
|
||||
for (let i = 0; i < times; i++) {
|
||||
arr[i] = value;
|
||||
}
|
||||
return arr;
|
||||
};
|
||||
|
||||
module.exports = exports =
|
||||
class SwaggerContext {
|
||||
constructor (path) {
|
||||
|
@ -75,6 +83,7 @@ module.exports = exports =
|
|||
this._pathParams = new Map();
|
||||
this._pathParamNames = [];
|
||||
this._pathTokens = tokenize(path, this);
|
||||
this._tags = new Set();
|
||||
}
|
||||
|
||||
header (...args) {
|
||||
|
@ -262,6 +271,18 @@ module.exports = exports =
|
|||
return this;
|
||||
}
|
||||
|
||||
tag (...tags) {
|
||||
tags = check(
|
||||
'endpoint.tag',
|
||||
tags,
|
||||
[...repeat(Math.max(1, tags.length), ['tag', 'string'])]
|
||||
);
|
||||
for (const tag of tags) {
|
||||
this._tags.add(tag);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
deprecated (...args) {
|
||||
const [flag] = check(
|
||||
'endpoint.summary',
|
||||
|
@ -284,6 +305,9 @@ module.exports = exports =
|
|||
for (const response of swaggerObj._responses.entries()) {
|
||||
this._responses.set(response[0], response[1]);
|
||||
}
|
||||
for (const tag of swaggerObj._tags) {
|
||||
this._tags.add(tag);
|
||||
}
|
||||
if (!this._bodyParam && swaggerObj._bodyParam) {
|
||||
this._bodyParam = swaggerObj._bodyParam;
|
||||
}
|
||||
|
@ -335,6 +359,9 @@ module.exports = exports =
|
|||
if (this._summary) {
|
||||
operation.summary = this._summary;
|
||||
}
|
||||
if (this._tags) {
|
||||
operation.tags = Array.from(this._tags);
|
||||
}
|
||||
if (this._bodyParam) {
|
||||
operation.consumes = (
|
||||
this._bodyParam.contentTypes
|
||||
|
|
|
@ -21,6 +21,9 @@ const router = createRouter();
|
|||
module.exports = router;
|
||||
|
||||
|
||||
router.tag('<%= document %>');
|
||||
|
||||
|
||||
router.get(function (req, res) {
|
||||
res.send(<%= documents %>.all());
|
||||
}, 'list')
|
||||
|
|
|
@ -20,6 +20,10 @@ const HTTP_CONFLICT = status('conflict');
|
|||
const router = createRouter();
|
||||
module.exports = router;
|
||||
|
||||
|
||||
router.tag('<%= document %>');
|
||||
|
||||
|
||||
const New<%= model %> = Object.assign({}, <%= model %>, {
|
||||
schema: Object.assign({}, <%= model %>.schema, {
|
||||
_from: joi.string(),
|
||||
|
|
Loading…
Reference in New Issue