openapi-sync 1.0.25 → 2.0.1
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/db.json +1 -1
- package/dist/Openapi-sync/components/helpers.js +40 -124
- package/dist/Openapi-sync/index.js +528 -57
- package/dist/Openapi-sync/state.js +3 -0
- package/dist/Openapi-sync/test.js +709 -0
- package/dist/index.js +15 -2
- package/package.json +3 -1
- package/types.ts +124 -0
- /package/dist/{Openapi-sync/types.js → types.js} +0 -0
package/dist/index.js
CHANGED
|
@@ -21,7 +21,20 @@ dotenv_1.default.config();
|
|
|
21
21
|
const rootUsingCwd = process.cwd();
|
|
22
22
|
const Init = (options) => __awaiter(void 0, void 0, void 0, function* () {
|
|
23
23
|
// Load config file
|
|
24
|
-
|
|
24
|
+
let configJS, configJson;
|
|
25
|
+
try {
|
|
26
|
+
configJS = require(path_1.default.join(rootUsingCwd, "openapi.sync.js"));
|
|
27
|
+
}
|
|
28
|
+
catch (e) {
|
|
29
|
+
// console.log(e);
|
|
30
|
+
}
|
|
31
|
+
try {
|
|
32
|
+
configJson = require(path_1.default.join(rootUsingCwd, "openapi.sync.json"));
|
|
33
|
+
}
|
|
34
|
+
catch (e) {
|
|
35
|
+
// console.log(e);
|
|
36
|
+
}
|
|
37
|
+
const config = configJS || configJson;
|
|
25
38
|
const apiNames = Object.keys(config.api);
|
|
26
39
|
const refetchInterval = options &&
|
|
27
40
|
"refetchInterval" in options &&
|
|
@@ -32,7 +45,7 @@ const Init = (options) => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
32
45
|
for (let i = 0; i < apiNames.length; i += 1) {
|
|
33
46
|
const apiName = apiNames[i];
|
|
34
47
|
const apiUrl = config.api[apiName];
|
|
35
|
-
(0, Openapi_sync_1.default)(apiUrl, apiName, refetchInterval);
|
|
48
|
+
(0, Openapi_sync_1.default)(apiUrl, apiName, config, refetchInterval);
|
|
36
49
|
}
|
|
37
50
|
});
|
|
38
51
|
exports.Init = Init;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "openapi-sync",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.1",
|
|
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",
|
|
@@ -24,6 +24,7 @@
|
|
|
24
24
|
"bin",
|
|
25
25
|
"dist",
|
|
26
26
|
"db.json",
|
|
27
|
+
"types.ts",
|
|
27
28
|
"LICENSE",
|
|
28
29
|
"README.md",
|
|
29
30
|
"package.json"
|
|
@@ -46,6 +47,7 @@
|
|
|
46
47
|
"@redocly/openapi-core": "^1.19.0",
|
|
47
48
|
"axios": "^1.7.3",
|
|
48
49
|
"axios-retry": "^4.5.0",
|
|
50
|
+
"curl-generator": "^0.4.2",
|
|
49
51
|
"dotenv": "^16.4.5",
|
|
50
52
|
"js-yaml": "^4.1.0",
|
|
51
53
|
"lodash": "^4.17.21",
|
package/types.ts
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { Method } from "axios";
|
|
2
|
+
|
|
3
|
+
export type IOpenApiSpec = Record<"openapi", string> & Record<string, any>;
|
|
4
|
+
|
|
5
|
+
export type IOpenApSchemaSpec = {
|
|
6
|
+
nullable?: boolean;
|
|
7
|
+
type: "string" | "integer" | "number" | "array" | "object" | "boolean";
|
|
8
|
+
example?: any;
|
|
9
|
+
enum?: string[];
|
|
10
|
+
format?: string;
|
|
11
|
+
items?: IOpenApSchemaSpec;
|
|
12
|
+
required?: string[];
|
|
13
|
+
description?: string;
|
|
14
|
+
$ref?: string;
|
|
15
|
+
properties?: Record<string, IOpenApSchemaSpec>;
|
|
16
|
+
additionalProperties?: IOpenApSchemaSpec;
|
|
17
|
+
anyOf?: IOpenApSchemaSpec[];
|
|
18
|
+
oneOf?: IOpenApSchemaSpec[];
|
|
19
|
+
allOf?: IOpenApSchemaSpec[];
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export type IOpenApiParameterSpec = {
|
|
23
|
+
$ref?: string;
|
|
24
|
+
name: string;
|
|
25
|
+
in: string;
|
|
26
|
+
enum?: string[];
|
|
27
|
+
description?: string;
|
|
28
|
+
required?: boolean;
|
|
29
|
+
deprecated?: boolean;
|
|
30
|
+
allowEmptyValue?: boolean;
|
|
31
|
+
style?: string;
|
|
32
|
+
explode?: boolean;
|
|
33
|
+
allowReserved?: boolean;
|
|
34
|
+
schema?: IOpenApSchemaSpec;
|
|
35
|
+
example?: any;
|
|
36
|
+
examples?: any[];
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
export type IOpenApiMediaTypeSpec = {
|
|
40
|
+
schema?: IOpenApSchemaSpec;
|
|
41
|
+
example?: any;
|
|
42
|
+
examples?: any[];
|
|
43
|
+
encoding?: any;
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
export type IOpenApiRequestBodySpec = {
|
|
47
|
+
description?: string;
|
|
48
|
+
required?: boolean;
|
|
49
|
+
content: Record<string, IOpenApiMediaTypeSpec>;
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
export type IOpenApiResponseSpec = Record<string, IOpenApiRequestBodySpec>;
|
|
53
|
+
|
|
54
|
+
export type IConfigReplaceWord = {
|
|
55
|
+
/** string and regular expression as a string*/
|
|
56
|
+
replace: string;
|
|
57
|
+
with: string;
|
|
58
|
+
type?: "endpoint" | "type";
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
export type IConfigDoc = {
|
|
62
|
+
disable?: boolean;
|
|
63
|
+
showCurl?: boolean;
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
export type IConfig = {
|
|
67
|
+
refetchInterval?: number;
|
|
68
|
+
folder?: string;
|
|
69
|
+
api: Record<string, string>;
|
|
70
|
+
server?: number;
|
|
71
|
+
types?: {
|
|
72
|
+
name?: {
|
|
73
|
+
prefix?: string;
|
|
74
|
+
format?: (
|
|
75
|
+
source: "shared" | "endpoint",
|
|
76
|
+
data: {
|
|
77
|
+
name?: string;
|
|
78
|
+
////. endpoint source //////
|
|
79
|
+
type?: "response" | "dto" | "query";
|
|
80
|
+
code?: string;
|
|
81
|
+
method?: Method;
|
|
82
|
+
path?: string;
|
|
83
|
+
summary?: string;
|
|
84
|
+
}
|
|
85
|
+
) => string | null | undefined;
|
|
86
|
+
};
|
|
87
|
+
doc: IConfigDoc;
|
|
88
|
+
};
|
|
89
|
+
endpoints?: {
|
|
90
|
+
value?: {
|
|
91
|
+
replaceWords?: IConfigReplaceWord[];
|
|
92
|
+
includeServer?: boolean;
|
|
93
|
+
};
|
|
94
|
+
name?: {
|
|
95
|
+
format?: (data: {
|
|
96
|
+
method: Method;
|
|
97
|
+
path: string;
|
|
98
|
+
summary: string;
|
|
99
|
+
}) => string | null;
|
|
100
|
+
prefix?: string;
|
|
101
|
+
};
|
|
102
|
+
doc: IConfigDoc;
|
|
103
|
+
};
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
export type IOpenApiSecuritySchemes = {
|
|
107
|
+
[key: string]: {
|
|
108
|
+
type: "http" | "apiKey" | "oauth2" | "openIdConnect" | "mutualTLS";
|
|
109
|
+
scheme?: "bearer" | "basic";
|
|
110
|
+
in?: "query" | "header" | "cookie";
|
|
111
|
+
flows?: {
|
|
112
|
+
authorizationCode: {
|
|
113
|
+
authorizationUrl: "https://example.com/auth";
|
|
114
|
+
tokenUrl: "https://example.com/token";
|
|
115
|
+
scopes: {
|
|
116
|
+
"read:data": "Grants read access";
|
|
117
|
+
};
|
|
118
|
+
};
|
|
119
|
+
};
|
|
120
|
+
bearerFormat?: "JWT";
|
|
121
|
+
openIdConnectUrl?: string;
|
|
122
|
+
name?: string;
|
|
123
|
+
};
|
|
124
|
+
};
|
|
File without changes
|