openapi-sync 2.1.10 → 2.1.12

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.
@@ -1,4 +0,0 @@
1
- import { IOpenApiSpec } from "../types";
2
- export declare const setState: (key: string, value: IOpenApiSpec) => void;
3
- export declare const getState: (key: string) => IOpenApiSpec | undefined;
4
- export declare const resetState: () => void;
@@ -1,37 +0,0 @@
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.resetState = exports.getState = exports.setState = void 0;
7
- const path_1 = __importDefault(require("path"));
8
- const fs_1 = __importDefault(require("fs"));
9
- const dbPath = path_1.default.join(__dirname, "../", "../db.json");
10
- if (!fs_1.default.existsSync(dbPath)) {
11
- fs_1.default.writeFileSync(dbPath, "{}");
12
- }
13
- let db = {};
14
- try {
15
- db = require(dbPath);
16
- }
17
- catch (error) {
18
- db = {};
19
- }
20
- let state = db || {};
21
- const updateDB = (data) => {
22
- fs_1.default.writeFileSync(dbPath, JSON.stringify(data));
23
- };
24
- const setState = (key, value) => {
25
- state[key] = value;
26
- updateDB(state);
27
- };
28
- exports.setState = setState;
29
- const getState = (key) => {
30
- return state[key];
31
- };
32
- exports.getState = getState;
33
- const resetState = () => {
34
- state = {};
35
- updateDB(state);
36
- };
37
- exports.resetState = resetState;
package/dist/helpers.d.ts DELETED
@@ -1,12 +0,0 @@
1
- export declare const isJson: (value: any) => boolean;
2
- export declare const isYamlString: (fileContent: string) => boolean;
3
- export declare const yamlStringToJson: (fileContent: string) => any;
4
- export declare const capitalize: (text: string) => string;
5
- export declare const getEndpointDetails: (path: string, method: string) => {
6
- name: string;
7
- variables: string[];
8
- pathParts: string[];
9
- };
10
- export declare const JSONStringify: (obj: Record<string, any>, indent?: number) => string;
11
- export declare const renderTypeRefMD: (typeRef: string, indent?: number) => string;
12
- export declare function getNestedValue<T>(obj: object, path: string): T | undefined;
package/dist/helpers.js DELETED
@@ -1,161 +0,0 @@
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 (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.renderTypeRefMD = exports.JSONStringify = exports.getEndpointDetails = exports.capitalize = exports.yamlStringToJson = exports.isYamlString = exports.isJson = void 0;
27
- exports.getNestedValue = getNestedValue;
28
- const regex_1 = require("./regex");
29
- const yaml = __importStar(require("js-yaml"));
30
- const isJson = (value) => {
31
- return ["object"].includes(typeof value) && !(value instanceof Blob);
32
- };
33
- exports.isJson = isJson;
34
- const isYamlString = (fileContent) => {
35
- try {
36
- yaml.load(fileContent);
37
- return true;
38
- }
39
- catch (en) {
40
- const e = en;
41
- if (e instanceof yaml.YAMLException) {
42
- return false;
43
- }
44
- else {
45
- throw e;
46
- }
47
- }
48
- };
49
- exports.isYamlString = isYamlString;
50
- const yamlStringToJson = (fileContent) => {
51
- if ((0, exports.isYamlString)(fileContent)) {
52
- const content = yaml.load(fileContent);
53
- const jsonString = JSON.stringify(content, null, 2);
54
- const json = JSON.parse(jsonString);
55
- return json;
56
- }
57
- };
58
- exports.yamlStringToJson = yamlStringToJson;
59
- const capitalize = (text) => {
60
- const capitalizedWord = text.substring(0, 1).toUpperCase() + text.substring(1);
61
- return capitalizedWord;
62
- };
63
- exports.capitalize = capitalize;
64
- const getEndpointDetails = (path, method) => {
65
- const pathParts = path.split("/");
66
- let name = `${(0, exports.capitalize)(method)}`;
67
- const variables = [];
68
- pathParts.forEach((part) => {
69
- // check if part is a variable
70
- //api/{userId}
71
- if (part[0] === "{" && part[part.length - 1] === "}") {
72
- const s = part.replace(/{/, "").replace(/}/, "");
73
- variables.push(s);
74
- part = `$${s}`;
75
- }
76
- //api/<userId>
77
- else if (part[0] === "<" && part[part.length - 1] === ">") {
78
- const s = part.replace(/</, "").replace(/>/, "");
79
- variables.push(s);
80
- part = `$${s}`;
81
- }
82
- //api/:userId
83
- else if (part[0] === ":") {
84
- const s = part.replace(/:/, "");
85
- variables.push(s);
86
- part = `$${s}`;
87
- }
88
- // parse to variable name
89
- let partVal = "";
90
- part.split("").forEach((char) => {
91
- let c = char;
92
- if (!regex_1.variableNameChar.test(char))
93
- c = "/";
94
- partVal += c;
95
- });
96
- partVal.split("/").forEach((val) => {
97
- name += (0, exports.capitalize)(val);
98
- });
99
- });
100
- return { name, variables, pathParts };
101
- };
102
- exports.getEndpointDetails = getEndpointDetails;
103
- const JSONStringify = (obj, indent = 1) => {
104
- let result = "{";
105
- const keys = Object.keys(obj);
106
- for (let i = 0; i < keys.length; i++) {
107
- const key = keys[i];
108
- const value = obj[key];
109
- result += "\n" + " ".repeat(indent) + key + ": ";
110
- if (Array.isArray(value)) {
111
- result += "[";
112
- for (let j = 0; j < value.length; j++) {
113
- const item = value[j];
114
- if (typeof item === "object" && item !== null) {
115
- result += (0, exports.JSONStringify)(item, indent + 1);
116
- }
117
- else {
118
- result += typeof item === "string" ? `"${item}"` : item;
119
- }
120
- if (j < value.length - 1) {
121
- result += ", ";
122
- }
123
- }
124
- result += "]";
125
- }
126
- else if (typeof value === "object" && value !== null) {
127
- result += "" + (0, exports.JSONStringify)(value, indent + 1);
128
- }
129
- else {
130
- result += value
131
- .split("\n")
132
- .filter((line) => line.trim() !== "")
133
- .join(`\n${" ".repeat(indent)}`);
134
- }
135
- if (i < keys.length - 1) {
136
- result += ", ";
137
- }
138
- }
139
- result += `\n${" ".repeat(indent - 1)}}`;
140
- return result;
141
- };
142
- exports.JSONStringify = JSONStringify;
143
- const renderTypeRefMD = (typeRef, indent = 1) => {
144
- return `\n\`\`\`typescript\n${" ".repeat(indent)} ${typeRef
145
- .split("\n")
146
- .filter((line) => line.trim() !== "")
147
- .join(`\n${" ".repeat(indent)} `)}\n\`\`\``;
148
- };
149
- exports.renderTypeRefMD = renderTypeRefMD;
150
- function getNestedValue(obj, path) {
151
- // Split the path string into an array of keys
152
- const keys = path.split(".");
153
- // Use the reduce method to navigate the object
154
- return keys.reduce((currentObj, key) => {
155
- // If the current object is not null or undefined,
156
- // return the value of the next key. Otherwise, return undefined.
157
- return currentObj && currentObj[key] !== undefined
158
- ? currentObj[key]
159
- : undefined;
160
- }, obj);
161
- }
@@ -1 +0,0 @@
1
- export {};
@@ -1,89 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const config = {
4
- refetchInterval: 5000,
5
- folder: "/inputed/path/",
6
- api: {
7
- example1: "https://raw.githubusercontent.com/OAI/OpenAPI-Specification/main/examples/v3.0/petstore.json",
8
- example2: "https://raw.githubusercontent.com/OAI/OpenAPI-Specification/main/examples/v3.0/petstore.yaml",
9
- },
10
- server: 0,
11
- // Configuration for excluding endpoints from code generation
12
- types: {
13
- name: {
14
- prefix: "",
15
- useOperationId: true, // Use operationId for type naming when available
16
- format: (source, data, defaultName) => {
17
- if (source === "shared") {
18
- return `${data.name}`;
19
- }
20
- else if (source === "endpoint") {
21
- // Use operationId if available, otherwise fall back to path-based naming
22
- if (data.operationId) {
23
- return `${data.operationId}${data.code}${data.type}`;
24
- }
25
- return `${data.method.toLowerCase()}${data
26
- .path.replace(/\//g, "_")
27
- .replace(/{|}/g, "")}${data.code}${data.type}`;
28
- }
29
- },
30
- },
31
- doc: {
32
- disable: true,
33
- },
34
- },
35
- endpoints: {
36
- value: {
37
- replaceWords: [
38
- {
39
- replace: "/api/v\\d/",
40
- with: "",
41
- },
42
- ],
43
- includeServer: true,
44
- type: "object",
45
- },
46
- name: {
47
- prefix: "",
48
- useOperationId: true,
49
- format: ({ method, path, summary, operationId }, defaultName) => {
50
- if (path === "/")
51
- return "root";
52
- return path.replace(/\//g, "_").replace(/{|}/g, "");
53
- },
54
- },
55
- doc: {
56
- disable: false,
57
- showCurl: true,
58
- },
59
- exclude: {
60
- // Exclude endpoints by tags
61
- tags: ["deprecated", "internal"],
62
- // Exclude individual endpoints by path and method
63
- endpoints: [
64
- // Exact path match
65
- { path: "/admin/users", method: "DELETE" },
66
- // Regex pattern match
67
- { regex: "^/internal/.*", method: "GET" },
68
- { regex: ".*/debug$", method: "GET" },
69
- // Don't specify method to exclude all methods
70
- { path: "/debug/logs" },
71
- ],
72
- },
73
- include: {
74
- // Include endpoints by tags
75
- tags: ["public"],
76
- // Include individual endpoints by path and method
77
- endpoints: [
78
- // Exact path match
79
- { path: "/public/users", method: "GET" },
80
- // Regex pattern match
81
- { regex: "^/public/.*", method: "GET" },
82
- { regex: ".*/logs$", method: "GET" },
83
- // Don't specify method to include all methods
84
- { path: "/public/logs" },
85
- ],
86
- },
87
- },
88
- };
89
- module.exports = config;
package/dist/regex.d.ts DELETED
@@ -1,2 +0,0 @@
1
- export declare const variableName: RegExp;
2
- export declare const variableNameChar: RegExp;
package/dist/regex.js DELETED
@@ -1,5 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.variableNameChar = exports.variableName = void 0;
4
- exports.variableName = /^[A-Za-z_$][A-Za-z0-9_$]*$/;
5
- exports.variableNameChar = /[A-Za-z0-9_$]/;
package/dist/types.js DELETED
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });