serverless-openapi-documenter 0.1.2 → 0.1.4

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.
package/json/owasp.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "last_update_utc": "2026-06-23 16:23:09",
2
+ "last_update_utc": "2026-07-19 05:44:10",
3
3
  "headers": [
4
4
  {
5
5
  "name": "Cache-Control",
@@ -0,0 +1,8 @@
1
+ {
2
+ "url": "https://raw.githubusercontent.com/OWASP/www-project-secure-headers/refs/heads/master/ci/headers_add.json",
3
+ "repo": "OWASP/www-project-secure-headers",
4
+ "path": "ci/headers_add.json",
5
+ "branch": "master",
6
+ "commit": "0bdb31eeda228b04a2fc712a6aa89105cc3efa84",
7
+ "last_update_utc": "2026-07-19 05:44:10"
8
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "serverless-openapi-documenter",
3
- "version": "0.1.2",
3
+ "version": "0.1.4",
4
4
  "description": "Generate OpenAPI v3 documentation and Postman Collections from your Serverless Config",
5
5
  "main": "index.js",
6
6
  "keywords": [
@@ -38,7 +38,8 @@
38
38
  "serverless openapi"
39
39
  ],
40
40
  "scripts": {
41
- "test": "mocha --config './test/.mocharc.js'"
41
+ "test": "mocha --config './test/.mocharc.js'",
42
+ "update:owasp": "node scripts/update-owasp-headers.js"
42
43
  },
43
44
  "author": {
44
45
  "name": "Jared Evans"
@@ -53,21 +54,21 @@
53
54
  "license": "MIT",
54
55
  "dependencies": {
55
56
  "@apidevtools/json-schema-ref-parser": "^9.1.0",
56
- "@redocly/openapi-core": "^1.34.5",
57
- "@usebruno/converters": "^0.17.1",
57
+ "@redocly/openapi-core": "^1.34.15",
58
+ "@usebruno/converters": "^0.21.0",
58
59
  "chalk": "^4.1.2",
59
- "js-yaml": "^4.1.1",
60
+ "js-yaml": "^5.1.0",
60
61
  "json-schema-for-openapi": "^0.5.0",
61
- "openapi-to-postmanv2": "^6.0.0",
62
- "uuid": "^11.1.0"
62
+ "openapi-to-postmanv2": "^6.1.0",
63
+ "uuid": "^11.1.1"
63
64
  },
64
65
  "engines": {
65
66
  "node": ">=20"
66
67
  },
67
68
  "devDependencies": {
68
- "chai": "^4.5.0",
69
- "mocha": "^11.7.2",
70
- "nock": "^14.0.10",
71
- "sinon": "^21.0.0"
69
+ "chai": "^6.2.2",
70
+ "mocha": "^11.7.6",
71
+ "nock": "^14.0.15",
72
+ "sinon": "^22.0.0"
72
73
  }
73
74
  }
@@ -0,0 +1,107 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+
4
+ /**
5
+ * Refreshes the bundled OWASP Secure Headers data at `json/owasp.json`.
6
+ *
7
+ * This runs out-of-band (locally via `npm run update:owasp` or on a schedule in
8
+ * CI) rather than at document-generation time, so that the plugin never depends
9
+ * on a live third-party URL when a user builds their docs. The fetched commit
10
+ * SHA is recorded in `json/owasp.source.json` for provenance.
11
+ *
12
+ * Usage: node scripts/update-owasp-headers.js
13
+ */
14
+
15
+ const fs = require("fs");
16
+ const path = require("path");
17
+ const https = require("https");
18
+
19
+ const OWNER = "OWASP";
20
+ const REPO = "www-project-secure-headers";
21
+ const BRANCH = "master";
22
+ const FILE_PATH = "ci/headers_add.json";
23
+
24
+ const RAW_URL = `https://raw.githubusercontent.com/${OWNER}/${REPO}/refs/heads/${BRANCH}/${FILE_PATH}`;
25
+ const COMMITS_API = `https://api.github.com/repos/${OWNER}/${REPO}/commits?path=${encodeURIComponent(
26
+ FILE_PATH
27
+ )}&sha=${BRANCH}&per_page=1`;
28
+
29
+ const OUTPUT_FILE = path.join(__dirname, "..", "json", "owasp.json");
30
+ const SOURCE_FILE = path.join(__dirname, "..", "json", "owasp.source.json");
31
+
32
+ /**
33
+ * @param {string} url
34
+ * @returns {Promise<string>}
35
+ */
36
+ function get(url) {
37
+ return new Promise((resolve, reject) => {
38
+ https
39
+ .get(
40
+ url,
41
+ {
42
+ headers: {
43
+ // GitHub's API rejects requests without a User-Agent.
44
+ "User-Agent": "serverless-openapi-documenter-owasp-updater",
45
+ Accept: "application/vnd.github+json",
46
+ },
47
+ },
48
+ (res) => {
49
+ if (res.statusCode !== 200) {
50
+ res.resume();
51
+ reject(
52
+ new Error(`Request to ${url} failed with status ${res.statusCode}`)
53
+ );
54
+ return;
55
+ }
56
+
57
+ const data = [];
58
+ res.on("data", (chunk) => data.push(chunk));
59
+ res.on("end", () => resolve(Buffer.concat(data).toString()));
60
+ }
61
+ )
62
+ .on("error", reject);
63
+ });
64
+ }
65
+
66
+ async function main() {
67
+ console.log(`Fetching OWASP secure headers from ${RAW_URL}`);
68
+ const raw = await get(RAW_URL);
69
+
70
+ // Validate it parses before we overwrite the bundled copy.
71
+ const parsed = JSON.parse(raw);
72
+ if (!Array.isArray(parsed.headers)) {
73
+ throw new Error(
74
+ "Unexpected upstream format: expected a `headers` array in the response"
75
+ );
76
+ }
77
+
78
+ let sha = null;
79
+ try {
80
+ const commits = JSON.parse(await get(COMMITS_API));
81
+ sha = commits[0]?.sha ?? null;
82
+ } catch (err) {
83
+ console.warn(`Could not resolve source commit SHA: ${err.message}`);
84
+ }
85
+
86
+ // Re-serialize so the on-disk formatting is stable regardless of upstream
87
+ // whitespace, which keeps CI diffs meaningful.
88
+ fs.writeFileSync(OUTPUT_FILE, `${JSON.stringify(parsed, null, 2)}\n`);
89
+
90
+ const source = {
91
+ url: RAW_URL,
92
+ repo: `${OWNER}/${REPO}`,
93
+ path: FILE_PATH,
94
+ branch: BRANCH,
95
+ commit: sha,
96
+ last_update_utc: parsed.last_update_utc ?? null,
97
+ };
98
+ fs.writeFileSync(SOURCE_FILE, `${JSON.stringify(source, null, 2)}\n`);
99
+
100
+ console.log(`Wrote ${OUTPUT_FILE}`);
101
+ console.log(`Wrote ${SOURCE_FILE} (commit: ${sha ?? "unknown"})`);
102
+ }
103
+
104
+ main().catch((err) => {
105
+ console.error(err.message);
106
+ process.exit(1);
107
+ });
package/src/owasp.js CHANGED
@@ -1,7 +1,5 @@
1
1
  "use strict";
2
2
 
3
- const https = require("https");
4
-
5
3
  const defaultOWASP = require("../json/owasp.json");
6
4
 
7
5
  /**
@@ -91,39 +89,17 @@ class OWASP {
91
89
  };
92
90
  }
93
91
 
92
+ /**
93
+ * Populates the OWASP header defaults from the bundled `json/owasp.json`.
94
+ *
95
+ * The bundled file is kept up to date out-of-band by the `update:owasp`
96
+ * script and its scheduled GitHub Action, which fetch the latest upstream
97
+ * OWASP Secure Headers project data and open a PR with the diff. This keeps
98
+ * document generation deterministic and offline-capable rather than
99
+ * depending on a live third-party URL at runtime.
100
+ */
94
101
  async getLatest() {
95
- const headerJSON = await new Promise((resolve, reject) => {
96
- const req = https
97
- .get(
98
- "https://raw.githubusercontent.com/OWASP/www-project-secure-headers/refs/heads/master/ci/headers_add.json",
99
- (res) => {
100
- let data = [];
101
-
102
- if (res.statusCode !== 200) {
103
- resolve(defaultOWASP);
104
- }
105
-
106
- res.on("error", (err) => {
107
- resolve(defaultOWASP);
108
- });
109
-
110
- res.on("data", (chunk) => {
111
- data.push(chunk);
112
- });
113
-
114
- res.on("end", () => {
115
- resolve(JSON.parse(Buffer.concat(data).toString()));
116
- });
117
- }
118
- )
119
- .on("error", (err) => {
120
- resolve(defaultOWASP);
121
- });
122
-
123
- req.end();
124
- });
125
-
126
- this.populateDefaults(headerJSON);
102
+ this.populateDefaults(defaultOWASP);
127
103
  }
128
104
 
129
105
  /**