openapi-sync 2.1.4 → 2.1.5
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/dist/Openapi-sync/index.d.ts +3 -0
- package/dist/Openapi-sync/state.d.ts +4 -0
- package/dist/helpers.d.ts +12 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +18 -0
- package/dist/openapi.sync.sample.d.ts +1 -0
- package/dist/openapi.sync.sample.js +2 -7
- package/dist/regex.d.ts +2 -0
- package/dist/types.d.ts +113 -0
- package/package.json +23 -4
- package/dist/Openapi-sync/components/helpers.js +0 -145
- package/dist/Openapi-sync/components/regex.js +0 -5
- package/dist/Openapi-sync/test.js +0 -709
- package/helpers.ts +0 -128
- package/regex.ts +0 -2
- package/types.ts +0 -139
|
@@ -0,0 +1,12 @@
|
|
|
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/index.d.ts
ADDED
package/dist/index.js
CHANGED
|
@@ -1,4 +1,18 @@
|
|
|
1
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
2
16
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
17
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
18
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -18,6 +32,10 @@ const dotenv_1 = __importDefault(require("dotenv"));
|
|
|
18
32
|
const path_1 = __importDefault(require("path"));
|
|
19
33
|
const fs_1 = __importDefault(require("fs"));
|
|
20
34
|
const state_1 = require("./Openapi-sync/state");
|
|
35
|
+
// Re-export modules for user consumption
|
|
36
|
+
__exportStar(require("./types"), exports);
|
|
37
|
+
__exportStar(require("./helpers"), exports);
|
|
38
|
+
__exportStar(require("./regex"), exports);
|
|
21
39
|
dotenv_1.default.config();
|
|
22
40
|
const rootUsingCwd = process.cwd();
|
|
23
41
|
const Init = (options) => __awaiter(void 0, void 0, void 0, function* () {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,9 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
// TypeScript config file for openapi-sync
|
|
3
|
-
// To use this file, install a TypeScript loader:
|
|
4
|
-
// npm install --save-dev esbuild-register (recommended - fastest & lightest)
|
|
5
|
-
// or: npm install --save-dev tsx
|
|
6
|
-
// or: npm install --save-dev @swc/register
|
|
7
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
3
|
const config = {
|
|
9
4
|
refetchInterval: 5000,
|
|
@@ -16,7 +11,7 @@ const config = {
|
|
|
16
11
|
types: {
|
|
17
12
|
name: {
|
|
18
13
|
prefix: "",
|
|
19
|
-
format: (source, data) => {
|
|
14
|
+
format: (source, data, defaultName) => {
|
|
20
15
|
if (source === "shared") {
|
|
21
16
|
return `${data.name}`;
|
|
22
17
|
}
|
|
@@ -45,7 +40,7 @@ const config = {
|
|
|
45
40
|
name: {
|
|
46
41
|
prefix: "",
|
|
47
42
|
useOperationId: true,
|
|
48
|
-
format: ({ method, path, summary, operationId }) => {
|
|
43
|
+
format: ({ method, path, summary, operationId }, defaultName) => {
|
|
49
44
|
if (path === "/")
|
|
50
45
|
return "root";
|
|
51
46
|
return path.replace(/\//g, "_").replace(/{|}/g, "");
|
package/dist/regex.d.ts
ADDED
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
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/package.json
CHANGED
|
@@ -1,9 +1,31 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "openapi-sync",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.5",
|
|
4
4
|
"description": "A developer-friendly tool designed to keep your API up-to-date by leveraging OpenAPI schemas. It automates the generation of endpoint URIs and type definitions, including shared types, directly from your OpenAPI specification.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"require": "./dist/index.js",
|
|
11
|
+
"import": "./dist/index.js"
|
|
12
|
+
},
|
|
13
|
+
"./types": {
|
|
14
|
+
"types": "./dist/types.d.ts",
|
|
15
|
+
"require": "./dist/types.js",
|
|
16
|
+
"import": "./dist/types.js"
|
|
17
|
+
},
|
|
18
|
+
"./helpers": {
|
|
19
|
+
"types": "./dist/helpers.d.ts",
|
|
20
|
+
"require": "./dist/helpers.js",
|
|
21
|
+
"import": "./dist/helpers.js"
|
|
22
|
+
},
|
|
23
|
+
"./regex": {
|
|
24
|
+
"types": "./dist/regex.d.ts",
|
|
25
|
+
"require": "./dist/regex.js",
|
|
26
|
+
"import": "./dist/regex.js"
|
|
27
|
+
}
|
|
28
|
+
},
|
|
7
29
|
"bin": {
|
|
8
30
|
"openapi-sync": "./bin/cli.js"
|
|
9
31
|
},
|
|
@@ -24,9 +46,6 @@
|
|
|
24
46
|
"bin",
|
|
25
47
|
"dist",
|
|
26
48
|
"db.json",
|
|
27
|
-
"types.ts",
|
|
28
|
-
"helpers.ts",
|
|
29
|
-
"regex.ts",
|
|
30
49
|
"LICENSE",
|
|
31
50
|
"README.md",
|
|
32
51
|
"package.json"
|
|
@@ -1,145 +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 (typeof value === "object" && value !== null) {
|
|
111
|
-
result += "" + (0, exports.JSONStringify)(value, indent + 1);
|
|
112
|
-
}
|
|
113
|
-
else {
|
|
114
|
-
result += value
|
|
115
|
-
.split("\n")
|
|
116
|
-
.filter((line) => line.trim() !== "")
|
|
117
|
-
.join(`\n${" ".repeat(indent)}`);
|
|
118
|
-
}
|
|
119
|
-
if (i < keys.length - 1) {
|
|
120
|
-
result += ", ";
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
result += `\n${" ".repeat(indent - 1)}}`;
|
|
124
|
-
return result;
|
|
125
|
-
};
|
|
126
|
-
exports.JSONStringify = JSONStringify;
|
|
127
|
-
const renderTypeRefMD = (typeRef, indent = 1) => {
|
|
128
|
-
return `\n\`\`\`typescript\n${" ".repeat(indent)} ${typeRef
|
|
129
|
-
.split("\n")
|
|
130
|
-
.filter((line) => line.trim() !== "")
|
|
131
|
-
.join(`\n${" ".repeat(indent)} `)}\n\`\`\``;
|
|
132
|
-
};
|
|
133
|
-
exports.renderTypeRefMD = renderTypeRefMD;
|
|
134
|
-
function getNestedValue(obj, path) {
|
|
135
|
-
// Split the path string into an array of keys
|
|
136
|
-
const keys = path.split(".");
|
|
137
|
-
// Use the reduce method to navigate the object
|
|
138
|
-
return keys.reduce((currentObj, key) => {
|
|
139
|
-
// If the current object is not null or undefined,
|
|
140
|
-
// return the value of the next key. Otherwise, return undefined.
|
|
141
|
-
return currentObj && currentObj[key] !== undefined
|
|
142
|
-
? currentObj[key]
|
|
143
|
-
: undefined;
|
|
144
|
-
}, obj);
|
|
145
|
-
}
|