@devinnn/docdrift 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.
@@ -0,0 +1,181 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.detectOpenApiSpecDrift = detectOpenApiSpecDrift;
7
+ const node_fs_1 = __importDefault(require("node:fs"));
8
+ const node_path_1 = __importDefault(require("node:path"));
9
+ const exec_1 = require("../utils/exec");
10
+ const fs_1 = require("../utils/fs");
11
+ const json_1 = require("../utils/json");
12
+ const fetch_1 = require("../utils/fetch");
13
+ function responseFields(spec) {
14
+ const fields = new Set();
15
+ const paths = spec?.paths ?? {};
16
+ for (const [pathName, methods] of Object.entries(paths)) {
17
+ for (const [method, methodDef] of Object.entries(methods)) {
18
+ const schema = methodDef?.responses?.["200"]?.content?.["application/json"]?.schema;
19
+ const properties = schema?.properties ?? {};
20
+ for (const key of Object.keys(properties)) {
21
+ fields.add(`${String(method).toUpperCase()} ${pathName}: ${key}`);
22
+ }
23
+ }
24
+ }
25
+ return fields;
26
+ }
27
+ function summarizeSpecDelta(previousSpec, currentSpec) {
28
+ const previous = responseFields(previousSpec);
29
+ const current = responseFields(currentSpec);
30
+ const added = [...current].filter((item) => !previous.has(item)).sort();
31
+ const removed = [...previous].filter((item) => !current.has(item)).sort();
32
+ const lines = [];
33
+ if (added.length) {
34
+ lines.push(`Added response fields (${added.length}):`);
35
+ lines.push(...added.map((value) => `+ ${value}`));
36
+ }
37
+ if (removed.length) {
38
+ lines.push(`Removed response fields (${removed.length}):`);
39
+ lines.push(...removed.map((value) => `- ${value}`));
40
+ }
41
+ if (!lines.length) {
42
+ return "OpenAPI changed, but no top-level response field changes were detected in 200 responses.";
43
+ }
44
+ return lines.join("\n");
45
+ }
46
+ async function getCurrentSpecContent(current, evidenceDir, logPath) {
47
+ const evidenceFiles = [];
48
+ if (current.type === "url") {
49
+ const content = await (0, fetch_1.fetchSpec)(current.url);
50
+ return { content, evidenceFiles };
51
+ }
52
+ if (current.type === "local") {
53
+ if (!node_fs_1.default.existsSync(current.path)) {
54
+ throw new Error(`OpenAPI local path not found: ${current.path}`);
55
+ }
56
+ const content = node_fs_1.default.readFileSync(current.path, "utf8");
57
+ return { content, evidenceFiles };
58
+ }
59
+ // current.type === "export"
60
+ const exportResult = await (0, exec_1.execCommand)(current.command);
61
+ node_fs_1.default.writeFileSync(logPath, [
62
+ `$ ${current.command}`,
63
+ `exitCode: ${exportResult.exitCode}`,
64
+ "\n--- stdout ---",
65
+ exportResult.stdout,
66
+ "\n--- stderr ---",
67
+ exportResult.stderr,
68
+ ].join("\n"), "utf8");
69
+ evidenceFiles.push(logPath);
70
+ if (exportResult.exitCode !== 0) {
71
+ throw new Error(`OpenAPI export failed: ${exportResult.stderr}`);
72
+ }
73
+ if (!node_fs_1.default.existsSync(current.outputPath)) {
74
+ throw new Error(`OpenAPI export did not create: ${current.outputPath}`);
75
+ }
76
+ const content = node_fs_1.default.readFileSync(current.outputPath, "utf8");
77
+ return { content, evidenceFiles };
78
+ }
79
+ async function detectOpenApiSpecDrift(config, evidenceDir) {
80
+ if (config.format !== "openapi3") {
81
+ return {
82
+ hasDrift: false,
83
+ summary: `Format ${config.format} is not openapi3`,
84
+ evidenceFiles: [],
85
+ impactedDocs: [],
86
+ };
87
+ }
88
+ (0, fs_1.ensureDir)(evidenceDir);
89
+ const logPath = node_path_1.default.join(evidenceDir, "openapi3-export.log");
90
+ let currentContent;
91
+ let evidenceFiles;
92
+ try {
93
+ const result = await getCurrentSpecContent(config.current, evidenceDir, logPath);
94
+ currentContent = result.content;
95
+ evidenceFiles = result.evidenceFiles;
96
+ }
97
+ catch (err) {
98
+ const msg = err instanceof Error ? err.message : String(err);
99
+ return {
100
+ hasDrift: true,
101
+ summary: `OpenAPI current spec failed: ${msg}`,
102
+ evidenceFiles: [logPath],
103
+ impactedDocs: [config.published],
104
+ signal: {
105
+ kind: "weak_evidence",
106
+ tier: 2,
107
+ confidence: 0.35,
108
+ evidence: [logPath],
109
+ },
110
+ };
111
+ }
112
+ if (!node_fs_1.default.existsSync(config.published)) {
113
+ return {
114
+ hasDrift: true,
115
+ summary: "OpenAPI published file missing",
116
+ evidenceFiles,
117
+ impactedDocs: [config.published],
118
+ signal: {
119
+ kind: "weak_evidence",
120
+ tier: 2,
121
+ confidence: 0.35,
122
+ evidence: evidenceFiles,
123
+ },
124
+ };
125
+ }
126
+ const publishedRaw = node_fs_1.default.readFileSync(config.published, "utf8");
127
+ let currentJson;
128
+ let publishedJson;
129
+ try {
130
+ currentJson = JSON.parse(currentContent);
131
+ publishedJson = JSON.parse(publishedRaw);
132
+ }
133
+ catch {
134
+ return {
135
+ hasDrift: true,
136
+ summary: "OpenAPI invalid JSON",
137
+ evidenceFiles,
138
+ impactedDocs: [config.published],
139
+ signal: {
140
+ kind: "weak_evidence",
141
+ tier: 2,
142
+ confidence: 0.35,
143
+ evidence: evidenceFiles,
144
+ },
145
+ };
146
+ }
147
+ const normalizedCurrent = (0, json_1.stableStringify)(currentJson);
148
+ const normalizedPublished = (0, json_1.stableStringify)(publishedJson);
149
+ if (normalizedCurrent === normalizedPublished) {
150
+ return {
151
+ hasDrift: false,
152
+ summary: "No OpenAPI drift detected",
153
+ evidenceFiles,
154
+ impactedDocs: [config.published],
155
+ };
156
+ }
157
+ const summary = summarizeSpecDelta(publishedJson, currentJson);
158
+ const diffPath = node_path_1.default.join(evidenceDir, "openapi3.diff.txt");
159
+ node_fs_1.default.writeFileSync(diffPath, [
160
+ "# OpenAPI Drift Summary",
161
+ summary,
162
+ "",
163
+ "# Published (normalized)",
164
+ normalizedPublished,
165
+ "",
166
+ "# Current (normalized)",
167
+ normalizedCurrent,
168
+ ].join("\n"), "utf8");
169
+ return {
170
+ hasDrift: true,
171
+ summary,
172
+ evidenceFiles: [...evidenceFiles, diffPath],
173
+ impactedDocs: [config.published],
174
+ signal: {
175
+ kind: "openapi_diff",
176
+ tier: 1,
177
+ confidence: 0.95,
178
+ evidence: [diffPath],
179
+ },
180
+ };
181
+ }
@@ -0,0 +1,193 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ var __importDefault = (this && this.__importDefault) || function (mod) {
36
+ return (mod && mod.__esModule) ? mod : { "default": mod };
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.detectPostmanSpecDrift = detectPostmanSpecDrift;
40
+ const node_fs_1 = __importDefault(require("node:fs"));
41
+ const node_path_1 = __importDefault(require("node:path"));
42
+ const fs_1 = require("../utils/fs");
43
+ const json_1 = require("../utils/json");
44
+ const fetch_1 = require("../utils/fetch");
45
+ function extractEndpoints(collection) {
46
+ const endpoints = new Set();
47
+ const info = collection?.info ?? collection?.information;
48
+ const items = collection?.item ?? [];
49
+ function walk(items, prefix = "") {
50
+ for (const item of items) {
51
+ if (!item)
52
+ continue;
53
+ const name = item.name ?? item.id ?? "";
54
+ if (item.request) {
55
+ const req = typeof item.request === "string" ? { url: item.request, method: "GET" } : item.request;
56
+ const url = req?.url?.raw ?? req?.url ?? "";
57
+ const method = (req?.method ?? "GET").toUpperCase();
58
+ if (url) {
59
+ endpoints.add(`${method} ${url}`);
60
+ }
61
+ }
62
+ else if (item.item) {
63
+ walk(item.item, `${prefix}/${name}`);
64
+ }
65
+ }
66
+ }
67
+ walk(Array.isArray(items) ? items : [items]);
68
+ return endpoints;
69
+ }
70
+ async function getCurrentContent(config) {
71
+ const current = config.current;
72
+ if (current.type === "url") {
73
+ return (0, fetch_1.fetchSpec)(current.url);
74
+ }
75
+ if (current.type === "local") {
76
+ if (!node_fs_1.default.existsSync(current.path)) {
77
+ throw new Error(`Postman collection path not found: ${current.path}`);
78
+ }
79
+ return node_fs_1.default.readFileSync(current.path, "utf8");
80
+ }
81
+ const { execCommand } = await Promise.resolve().then(() => __importStar(require("../utils/exec")));
82
+ const result = await execCommand(current.command);
83
+ if (result.exitCode !== 0) {
84
+ throw new Error(`Postman export failed: ${result.stderr}`);
85
+ }
86
+ if (!node_fs_1.default.existsSync(current.outputPath)) {
87
+ throw new Error(`Postman export did not create: ${current.outputPath}`);
88
+ }
89
+ return node_fs_1.default.readFileSync(current.outputPath, "utf8");
90
+ }
91
+ async function detectPostmanSpecDrift(config, evidenceDir) {
92
+ if (config.format !== "postman") {
93
+ return {
94
+ hasDrift: false,
95
+ summary: `Format ${config.format} is not postman`,
96
+ evidenceFiles: [],
97
+ impactedDocs: [],
98
+ };
99
+ }
100
+ (0, fs_1.ensureDir)(evidenceDir);
101
+ let currentContent;
102
+ try {
103
+ currentContent = await getCurrentContent(config);
104
+ }
105
+ catch (err) {
106
+ const msg = err instanceof Error ? err.message : String(err);
107
+ const logPath = node_path_1.default.join(evidenceDir, "postman-export.log");
108
+ node_fs_1.default.writeFileSync(logPath, msg, "utf8");
109
+ return {
110
+ hasDrift: true,
111
+ summary: `Postman current spec failed: ${msg}`,
112
+ evidenceFiles: [logPath],
113
+ impactedDocs: [config.published],
114
+ signal: {
115
+ kind: "weak_evidence",
116
+ tier: 2,
117
+ confidence: 0.35,
118
+ evidence: [logPath],
119
+ },
120
+ };
121
+ }
122
+ if (!node_fs_1.default.existsSync(config.published)) {
123
+ return {
124
+ hasDrift: true,
125
+ summary: "Postman published file missing",
126
+ evidenceFiles: [],
127
+ impactedDocs: [config.published],
128
+ signal: {
129
+ kind: "weak_evidence",
130
+ tier: 2,
131
+ confidence: 0.35,
132
+ evidence: [],
133
+ },
134
+ };
135
+ }
136
+ const publishedRaw = node_fs_1.default.readFileSync(config.published, "utf8");
137
+ let currentJson;
138
+ let publishedJson;
139
+ try {
140
+ currentJson = JSON.parse(currentContent);
141
+ publishedJson = JSON.parse(publishedRaw);
142
+ }
143
+ catch {
144
+ return {
145
+ hasDrift: true,
146
+ summary: "Postman collection invalid JSON",
147
+ evidenceFiles: [],
148
+ impactedDocs: [config.published],
149
+ signal: {
150
+ kind: "weak_evidence",
151
+ tier: 2,
152
+ confidence: 0.35,
153
+ evidence: [],
154
+ },
155
+ };
156
+ }
157
+ const currentEndpoints = extractEndpoints(currentJson);
158
+ const publishedEndpoints = extractEndpoints(publishedJson);
159
+ const added = [...currentEndpoints].filter((e) => !publishedEndpoints.has(e)).sort();
160
+ const removed = [...publishedEndpoints].filter((e) => !currentEndpoints.has(e)).sort();
161
+ if (added.length === 0 && removed.length === 0) {
162
+ return {
163
+ hasDrift: false,
164
+ summary: "No Postman collection drift detected",
165
+ evidenceFiles: [],
166
+ impactedDocs: [config.published],
167
+ };
168
+ }
169
+ const lines = [];
170
+ if (added.length) {
171
+ lines.push(`Added endpoints (${added.length}):`);
172
+ lines.push(...added.map((v) => `+ ${v}`));
173
+ }
174
+ if (removed.length) {
175
+ lines.push(`Removed endpoints (${removed.length}):`);
176
+ lines.push(...removed.map((v) => `- ${v}`));
177
+ }
178
+ const summary = lines.join("\n");
179
+ const diffPath = node_path_1.default.join(evidenceDir, "postman.diff.txt");
180
+ node_fs_1.default.writeFileSync(diffPath, ["# Postman Drift Summary", summary, "", "# Current endpoints", (0, json_1.stableStringify)([...currentEndpoints].sort()), "", "# Published endpoints", (0, json_1.stableStringify)([...publishedEndpoints].sort())].join("\n"), "utf8");
181
+ return {
182
+ hasDrift: true,
183
+ summary,
184
+ evidenceFiles: [diffPath],
185
+ impactedDocs: [config.published],
186
+ signal: {
187
+ kind: "postman_diff",
188
+ tier: 1,
189
+ confidence: 0.95,
190
+ evidence: [diffPath],
191
+ },
192
+ };
193
+ }
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getSpecDetector = getSpecDetector;
4
+ exports.getSupportedFormats = getSupportedFormats;
5
+ const openapi_1 = require("./openapi");
6
+ const swagger2_1 = require("./swagger2");
7
+ const graphql_1 = require("./graphql");
8
+ const fern_1 = require("./fern");
9
+ const postman_1 = require("./postman");
10
+ const registry = {
11
+ openapi3: openapi_1.detectOpenApiSpecDrift,
12
+ swagger2: swagger2_1.detectSwagger2SpecDrift,
13
+ graphql: graphql_1.detectGraphQLSpecDrift,
14
+ fern: fern_1.detectFernSpecDrift,
15
+ postman: postman_1.detectPostmanSpecDrift,
16
+ };
17
+ function getSpecDetector(format) {
18
+ const detector = registry[format];
19
+ if (!detector) {
20
+ throw new Error(`Unknown spec format: ${format}`);
21
+ }
22
+ return detector;
23
+ }
24
+ function getSupportedFormats() {
25
+ return Object.keys(registry);
26
+ }
@@ -0,0 +1,229 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ var __importDefault = (this && this.__importDefault) || function (mod) {
36
+ return (mod && mod.__esModule) ? mod : { "default": mod };
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.detectSwagger2SpecDrift = detectSwagger2SpecDrift;
40
+ const node_fs_1 = __importDefault(require("node:fs"));
41
+ const node_path_1 = __importDefault(require("node:path"));
42
+ const fs_1 = require("../utils/fs");
43
+ const json_1 = require("../utils/json");
44
+ const fetch_1 = require("../utils/fetch");
45
+ function resolveRef(spec, ref) {
46
+ if (!ref || !ref.startsWith("#/"))
47
+ return null;
48
+ const parts = ref.slice(2).split("/");
49
+ let cur = spec;
50
+ for (const p of parts) {
51
+ cur = cur?.[p];
52
+ }
53
+ return cur;
54
+ }
55
+ function getResponseFieldsSwagger2(spec) {
56
+ const fields = new Set();
57
+ const paths = spec?.paths ?? {};
58
+ const definitions = spec?.definitions ?? {};
59
+ for (const [pathName, pathItem] of Object.entries(paths)) {
60
+ const item = pathItem;
61
+ for (const method of ["get", "post", "put", "patch", "delete"]) {
62
+ const op = item[method];
63
+ if (!op)
64
+ continue;
65
+ const res = op.responses?.["200"];
66
+ if (!res)
67
+ continue;
68
+ let schema = res.schema;
69
+ if (schema?.$ref) {
70
+ schema = resolveRef({ paths, definitions }, schema.$ref) ?? schema;
71
+ }
72
+ const properties = schema?.properties ?? {};
73
+ for (const key of Object.keys(properties)) {
74
+ fields.add(`${method.toUpperCase()} ${pathName}: ${key}`);
75
+ }
76
+ }
77
+ }
78
+ return fields;
79
+ }
80
+ function summarizeSwagger2Delta(previousSpec, currentSpec) {
81
+ const previous = getResponseFieldsSwagger2(previousSpec);
82
+ const current = getResponseFieldsSwagger2(currentSpec);
83
+ const added = [...current].filter((item) => !previous.has(item)).sort();
84
+ const removed = [...previous].filter((item) => !current.has(item)).sort();
85
+ const lines = [];
86
+ if (added.length) {
87
+ lines.push(`Added response fields (${added.length}):`);
88
+ lines.push(...added.map((value) => `+ ${value}`));
89
+ }
90
+ if (removed.length) {
91
+ lines.push(`Removed response fields (${removed.length}):`);
92
+ lines.push(...removed.map((value) => `- ${value}`));
93
+ }
94
+ if (!lines.length) {
95
+ return "Swagger 2 changed, but no top-level response field changes were detected in 200 responses.";
96
+ }
97
+ return lines.join("\n");
98
+ }
99
+ async function getCurrentContent(config) {
100
+ const current = config.current;
101
+ if (current.type === "url") {
102
+ return (0, fetch_1.fetchSpec)(current.url);
103
+ }
104
+ if (current.type === "local") {
105
+ if (!node_fs_1.default.existsSync(current.path)) {
106
+ throw new Error(`Swagger 2 local path not found: ${current.path}`);
107
+ }
108
+ return node_fs_1.default.readFileSync(current.path, "utf8");
109
+ }
110
+ // export: run command then read outputPath
111
+ const { execCommand } = await Promise.resolve().then(() => __importStar(require("../utils/exec")));
112
+ const result = await execCommand(current.command);
113
+ if (result.exitCode !== 0) {
114
+ throw new Error(`Swagger 2 export failed: ${result.stderr}`);
115
+ }
116
+ if (!node_fs_1.default.existsSync(current.outputPath)) {
117
+ throw new Error(`Swagger 2 export did not create: ${current.outputPath}`);
118
+ }
119
+ return node_fs_1.default.readFileSync(current.outputPath, "utf8");
120
+ }
121
+ async function detectSwagger2SpecDrift(config, evidenceDir) {
122
+ if (config.format !== "swagger2") {
123
+ return {
124
+ hasDrift: false,
125
+ summary: `Format ${config.format} is not swagger2`,
126
+ evidenceFiles: [],
127
+ impactedDocs: [],
128
+ };
129
+ }
130
+ (0, fs_1.ensureDir)(evidenceDir);
131
+ let currentContent;
132
+ try {
133
+ currentContent = await getCurrentContent(config);
134
+ }
135
+ catch (err) {
136
+ const msg = err instanceof Error ? err.message : String(err);
137
+ const logPath = node_path_1.default.join(evidenceDir, "swagger2-export.log");
138
+ node_fs_1.default.writeFileSync(logPath, msg, "utf8");
139
+ return {
140
+ hasDrift: true,
141
+ summary: `Swagger 2 current spec failed: ${msg}`,
142
+ evidenceFiles: [logPath],
143
+ impactedDocs: [config.published],
144
+ signal: {
145
+ kind: "weak_evidence",
146
+ tier: 2,
147
+ confidence: 0.35,
148
+ evidence: [logPath],
149
+ },
150
+ };
151
+ }
152
+ if (!node_fs_1.default.existsSync(config.published)) {
153
+ return {
154
+ hasDrift: true,
155
+ summary: "Swagger 2 published file missing",
156
+ evidenceFiles: [],
157
+ impactedDocs: [config.published],
158
+ signal: {
159
+ kind: "weak_evidence",
160
+ tier: 2,
161
+ confidence: 0.35,
162
+ evidence: [],
163
+ },
164
+ };
165
+ }
166
+ const publishedRaw = node_fs_1.default.readFileSync(config.published, "utf8");
167
+ let currentJson;
168
+ let publishedJson;
169
+ try {
170
+ currentJson = JSON.parse(currentContent);
171
+ publishedJson = JSON.parse(publishedRaw);
172
+ }
173
+ catch {
174
+ return {
175
+ hasDrift: true,
176
+ summary: "Swagger 2 invalid JSON",
177
+ evidenceFiles: [],
178
+ impactedDocs: [config.published],
179
+ signal: {
180
+ kind: "weak_evidence",
181
+ tier: 2,
182
+ confidence: 0.35,
183
+ evidence: [],
184
+ },
185
+ };
186
+ }
187
+ if (currentJson.swagger !== "2.0") {
188
+ return {
189
+ hasDrift: false,
190
+ summary: "Not a Swagger 2.0 spec",
191
+ evidenceFiles: [],
192
+ impactedDocs: [],
193
+ };
194
+ }
195
+ const normalizedCurrent = (0, json_1.stableStringify)(currentJson);
196
+ const normalizedPublished = (0, json_1.stableStringify)(publishedJson);
197
+ if (normalizedCurrent === normalizedPublished) {
198
+ return {
199
+ hasDrift: false,
200
+ summary: "No Swagger 2 drift detected",
201
+ evidenceFiles: [],
202
+ impactedDocs: [config.published],
203
+ };
204
+ }
205
+ const summary = summarizeSwagger2Delta(publishedJson, currentJson);
206
+ const diffPath = node_path_1.default.join(evidenceDir, "swagger2.diff.txt");
207
+ node_fs_1.default.writeFileSync(diffPath, [
208
+ "# Swagger 2 Drift Summary",
209
+ summary,
210
+ "",
211
+ "# Published (normalized)",
212
+ normalizedPublished,
213
+ "",
214
+ "# Current (normalized)",
215
+ normalizedCurrent,
216
+ ].join("\n"), "utf8");
217
+ return {
218
+ hasDrift: true,
219
+ summary,
220
+ evidenceFiles: [diffPath],
221
+ impactedDocs: [config.published],
222
+ signal: {
223
+ kind: "swagger2_diff",
224
+ tier: 1,
225
+ confidence: 0.95,
226
+ evidence: [diffPath],
227
+ },
228
+ };
229
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });