@sleeksky/alt-swagger 2.3.2 → 2.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/index.js +22 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sleeksky/alt-swagger",
3
- "version": "2.3.2",
3
+ "version": "2.5.0",
4
4
  "description": "Quickly spec your APIs for Swagger / OpenAPI interface",
5
5
  "main": "./src/index.js",
6
6
  "scripts": {
package/src/index.js CHANGED
@@ -65,10 +65,11 @@ function api(opt) {
65
65
  const tag = (str) => { spec.tags = [str]; return ext; };
66
66
  const summary = (str) => { spec.summary = str; return ext; };
67
67
  const desc = (str) => { spec.description = str; return ext; };
68
+ const security = (str) => { spec.security = [ { [str]: []}]; return ext; }
68
69
  const deprecate = () => { spec.deprecated = true; return ext; };
69
70
  const remove = () => { _.unset(paths, `${pathClean(opt.path)}.${opt.method}`); };
70
71
 
71
- Object.assign(ext, { req, res, query, header, tag, summary, desc, deprecate, remove });
72
+ Object.assign(ext, { req, res, query, header, tag, summary, desc, deprecate, remove, security });
72
73
 
73
74
  // support all ext in parameters
74
75
  Object.keys(ext).forEach(k => {
@@ -109,6 +110,24 @@ function del(path = "", opt = {}) {
109
110
  return api(opt);
110
111
  }
111
112
 
113
+ function remove({path=null, tag=null}) {
114
+ if (path) _.unset(paths, `${pathClean(path)}`);
115
+ if (tag) {
116
+ // remote all the paths with this tag
117
+ Object.keys(paths).forEach(p => {
118
+ Object.keys(paths[p]).forEach(method => {
119
+ if (paths[p][method].tags && paths[p][method].tags.includes(tag)) _.unset(paths[p], method);
120
+ })
121
+ });
122
+ }
123
+ }
124
+
125
+ function security(name, {type = "http", schema = "bearer", bearerFormat = null, required = true}) {
126
+ components.securitySchemes = components.securitySchemes || {};
127
+ components.securitySchemes[name] = { type, scheme: schema, bearerFormat, "in": "header", required };
128
+ return `#/components/securitySchemes/${name}`;
129
+ }
130
+
112
131
  function _ref({ type, name, def }) {
113
132
  components[type] = components[type] || {};
114
133
  components[type][name] = def;
@@ -145,6 +164,8 @@ module.exports = {
145
164
  put,
146
165
  patch,
147
166
  del,
167
+ security,
148
168
  swaggerDoc,
149
169
  reset,
170
+ remove,
150
171
  };