@sleeksky/alt-swagger 2.3.2 → 2.4.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 +9 -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.4.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,12 @@ function del(path = "", opt = {}) {
109
110
  return api(opt);
110
111
  }
111
112
 
113
+ function security(name, {type = "http", schema = "bearer", bearerFormat = null, required = true}) {
114
+ components.securitySchemes = components.securitySchemes || {};
115
+ components.securitySchemes[name] = { type, scheme: schema, bearerFormat, "in": "header", required };
116
+ return `#/components/securitySchemes/${name}`;
117
+ }
118
+
112
119
  function _ref({ type, name, def }) {
113
120
  components[type] = components[type] || {};
114
121
  components[type][name] = def;
@@ -145,6 +152,7 @@ module.exports = {
145
152
  put,
146
153
  patch,
147
154
  del,
155
+ security,
148
156
  swaggerDoc,
149
157
  reset,
150
158
  };