@sleeksky/alt-swagger 2.3.1 → 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 +17 -6
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sleeksky/alt-swagger",
3
- "version": "2.3.1",
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
@@ -22,11 +22,14 @@ function server(url, description) {
22
22
  }
23
23
 
24
24
  function api(opt) {
25
- const spec = { parameters: [], responses: {}, description: "" };
26
- const pathParams = pathParameters(opt.path);
27
- if (pathParams.length > 0) spec.parameters = pathParams;
28
-
29
- _.set(paths, `${pathClean(opt.path)}.${opt.method}`, spec);
25
+ let path = `${pathClean(opt.path)}.${opt.method}`;
26
+ let spec = _.get(paths, path, false);
27
+ if (!spec) {
28
+ spec = { parameters: [], responses: {}, description: "" };
29
+ const pathParams = pathParameters(opt.path);
30
+ if (pathParams.length > 0) spec.parameters = pathParams;
31
+ _.set(paths, path, spec);
32
+ }
30
33
 
31
34
  let ext = {};
32
35
 
@@ -62,10 +65,11 @@ function api(opt) {
62
65
  const tag = (str) => { spec.tags = [str]; return ext; };
63
66
  const summary = (str) => { spec.summary = str; return ext; };
64
67
  const desc = (str) => { spec.description = str; return ext; };
68
+ const security = (str) => { spec.security = [ { [str]: []}]; return ext; }
65
69
  const deprecate = () => { spec.deprecated = true; return ext; };
66
70
  const remove = () => { _.unset(paths, `${pathClean(opt.path)}.${opt.method}`); };
67
71
 
68
- 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 });
69
73
 
70
74
  // support all ext in parameters
71
75
  Object.keys(ext).forEach(k => {
@@ -106,6 +110,12 @@ function del(path = "", opt = {}) {
106
110
  return api(opt);
107
111
  }
108
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
+
109
119
  function _ref({ type, name, def }) {
110
120
  components[type] = components[type] || {};
111
121
  components[type][name] = def;
@@ -142,6 +152,7 @@ module.exports = {
142
152
  put,
143
153
  patch,
144
154
  del,
155
+ security,
145
156
  swaggerDoc,
146
157
  reset,
147
158
  };