openapi-sync 2.1.9 → 2.1.11
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/README.md +348 -17
- package/db.json +1 -1
- package/dist/index.d.mts +172 -0
- package/dist/index.d.ts +170 -4
- package/dist/index.js +56 -88
- package/dist/index.mjs +56 -0
- package/package.json +5 -7
- package/dist/Openapi-sync/index.d.ts +0 -3
- package/dist/Openapi-sync/index.js +0 -776
- package/dist/Openapi-sync/state.d.ts +0 -4
- package/dist/Openapi-sync/state.js +0 -37
- package/dist/helpers.d.ts +0 -12
- package/dist/helpers.js +0 -161
- package/dist/openapi.sync.sample.d.ts +0 -1
- package/dist/openapi.sync.sample.js +0 -55
- package/dist/regex.d.ts +0 -2
- package/dist/regex.js +0 -5
- package/dist/types.d.ts +0 -113
- package/dist/types.js +0 -2
|
@@ -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,55 +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
|
-
types: {
|
|
12
|
-
name: {
|
|
13
|
-
prefix: "",
|
|
14
|
-
format: (source, data, defaultName) => {
|
|
15
|
-
if (source === "shared") {
|
|
16
|
-
return `${data.name}`;
|
|
17
|
-
}
|
|
18
|
-
else if (source === "endpoint") {
|
|
19
|
-
return `${data.method.toLowerCase()}${data
|
|
20
|
-
.path.replace(/\//g, "_")
|
|
21
|
-
.replace(/{|}/g, "")}${data.code}${data.type}`;
|
|
22
|
-
}
|
|
23
|
-
},
|
|
24
|
-
},
|
|
25
|
-
doc: {
|
|
26
|
-
disable: true,
|
|
27
|
-
},
|
|
28
|
-
},
|
|
29
|
-
endpoints: {
|
|
30
|
-
value: {
|
|
31
|
-
replaceWords: [
|
|
32
|
-
{
|
|
33
|
-
replace: "/api/v\\d/",
|
|
34
|
-
with: "",
|
|
35
|
-
},
|
|
36
|
-
],
|
|
37
|
-
includeServer: true,
|
|
38
|
-
type: "object",
|
|
39
|
-
},
|
|
40
|
-
name: {
|
|
41
|
-
prefix: "",
|
|
42
|
-
useOperationId: true,
|
|
43
|
-
format: ({ method, path, summary, operationId }, defaultName) => {
|
|
44
|
-
if (path === "/")
|
|
45
|
-
return "root";
|
|
46
|
-
return path.replace(/\//g, "_").replace(/{|}/g, "");
|
|
47
|
-
},
|
|
48
|
-
},
|
|
49
|
-
doc: {
|
|
50
|
-
disable: false,
|
|
51
|
-
showCurl: true,
|
|
52
|
-
},
|
|
53
|
-
},
|
|
54
|
-
};
|
|
55
|
-
module.exports = config;
|
package/dist/regex.d.ts
DELETED
package/dist/regex.js
DELETED
package/dist/types.d.ts
DELETED
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
import { Method } from "axios";
|
|
2
|
-
export type IOpenApiSpec = Record<"openapi", string> & Record<string, any>;
|
|
3
|
-
export type IOpenApSchemaSpec = {
|
|
4
|
-
nullable?: boolean;
|
|
5
|
-
type: "string" | "integer" | "number" | "array" | "object" | "boolean" | "null" | any[];
|
|
6
|
-
example?: any;
|
|
7
|
-
enum?: string[];
|
|
8
|
-
format?: string;
|
|
9
|
-
items?: IOpenApSchemaSpec;
|
|
10
|
-
required?: string[];
|
|
11
|
-
description?: string;
|
|
12
|
-
$ref?: string;
|
|
13
|
-
properties?: Record<string, IOpenApSchemaSpec>;
|
|
14
|
-
additionalProperties?: IOpenApSchemaSpec;
|
|
15
|
-
anyOf?: IOpenApSchemaSpec[];
|
|
16
|
-
oneOf?: IOpenApSchemaSpec[];
|
|
17
|
-
allOf?: IOpenApSchemaSpec[];
|
|
18
|
-
};
|
|
19
|
-
export type IOpenApiParameterSpec = {
|
|
20
|
-
$ref?: string;
|
|
21
|
-
name: string;
|
|
22
|
-
in: string;
|
|
23
|
-
enum?: string[];
|
|
24
|
-
description?: string;
|
|
25
|
-
required?: boolean;
|
|
26
|
-
deprecated?: boolean;
|
|
27
|
-
allowEmptyValue?: boolean;
|
|
28
|
-
style?: string;
|
|
29
|
-
explode?: boolean;
|
|
30
|
-
allowReserved?: boolean;
|
|
31
|
-
schema?: IOpenApSchemaSpec;
|
|
32
|
-
example?: any;
|
|
33
|
-
examples?: any[];
|
|
34
|
-
};
|
|
35
|
-
export type IOpenApiMediaTypeSpec = {
|
|
36
|
-
schema?: IOpenApSchemaSpec;
|
|
37
|
-
example?: any;
|
|
38
|
-
examples?: any[];
|
|
39
|
-
encoding?: any;
|
|
40
|
-
};
|
|
41
|
-
export type IOpenApiRequestBodySpec = {
|
|
42
|
-
description?: string;
|
|
43
|
-
required?: boolean;
|
|
44
|
-
content: Record<string, IOpenApiMediaTypeSpec>;
|
|
45
|
-
};
|
|
46
|
-
export type IOpenApiResponseSpec = Record<string, IOpenApiRequestBodySpec>;
|
|
47
|
-
export type IConfigReplaceWord = {
|
|
48
|
-
/** string and regular expression as a string*/
|
|
49
|
-
replace: string;
|
|
50
|
-
with: string;
|
|
51
|
-
type?: "endpoint" | "type";
|
|
52
|
-
};
|
|
53
|
-
export type IConfigDoc = {
|
|
54
|
-
disable?: boolean;
|
|
55
|
-
showCurl?: boolean;
|
|
56
|
-
};
|
|
57
|
-
export type IConfig = {
|
|
58
|
-
refetchInterval?: number;
|
|
59
|
-
folder?: string;
|
|
60
|
-
api: Record<string, string>;
|
|
61
|
-
server?: number | string;
|
|
62
|
-
types?: {
|
|
63
|
-
name?: {
|
|
64
|
-
prefix?: string;
|
|
65
|
-
format?: (source: "shared" | "endpoint", data: {
|
|
66
|
-
name?: string;
|
|
67
|
-
type?: "response" | "dto" | "query";
|
|
68
|
-
code?: string;
|
|
69
|
-
method?: Method;
|
|
70
|
-
path?: string;
|
|
71
|
-
summary?: string;
|
|
72
|
-
}, defaultName: string) => string | null | undefined;
|
|
73
|
-
};
|
|
74
|
-
doc?: IConfigDoc;
|
|
75
|
-
};
|
|
76
|
-
endpoints?: {
|
|
77
|
-
value?: {
|
|
78
|
-
replaceWords?: IConfigReplaceWord[];
|
|
79
|
-
includeServer?: boolean;
|
|
80
|
-
type?: "string" | "object";
|
|
81
|
-
};
|
|
82
|
-
name?: {
|
|
83
|
-
format?: (data: {
|
|
84
|
-
method: Method;
|
|
85
|
-
path: string;
|
|
86
|
-
summary: string;
|
|
87
|
-
operationId: string;
|
|
88
|
-
}, defaultName: string) => string | null;
|
|
89
|
-
prefix?: string;
|
|
90
|
-
useOperationId?: boolean;
|
|
91
|
-
};
|
|
92
|
-
doc?: IConfigDoc;
|
|
93
|
-
};
|
|
94
|
-
};
|
|
95
|
-
export type IOpenApiSecuritySchemes = {
|
|
96
|
-
[key: string]: {
|
|
97
|
-
type: "http" | "apiKey" | "oauth2" | "openIdConnect" | "mutualTLS";
|
|
98
|
-
scheme?: "bearer" | "basic";
|
|
99
|
-
in?: "query" | "header" | "cookie";
|
|
100
|
-
flows?: {
|
|
101
|
-
authorizationCode: {
|
|
102
|
-
authorizationUrl: "https://example.com/auth";
|
|
103
|
-
tokenUrl: "https://example.com/token";
|
|
104
|
-
scopes: {
|
|
105
|
-
"read:data": "Grants read access";
|
|
106
|
-
};
|
|
107
|
-
};
|
|
108
|
-
};
|
|
109
|
-
bearerFormat?: "JWT";
|
|
110
|
-
openIdConnectUrl?: string;
|
|
111
|
-
name?: string;
|
|
112
|
-
};
|
|
113
|
-
};
|
package/dist/types.js
DELETED