openapi-sync 1.0.14 → 1.0.17
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 +5 -5
- package/dist/Openapi-sync/components/helpers.js +56 -54
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Openapi-sync
|
|
2
2
|
|
|
3
|
-
**Openapi-sync**
|
|
3
|
+
**Openapi-sync** is 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. Whether you need real-time synchronization before commits or periodic updates, openapi-sync ensures your API structure is always current and consistent. With an easy-to-use CLI, this tool integrates seamlessly into your development workflow, making API maintenance simpler and more reliable.
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
@@ -12,7 +12,7 @@ npm install openapi-sync
|
|
|
12
12
|
|
|
13
13
|
## Configuration
|
|
14
14
|
|
|
15
|
-
Create an `openapi.sync.json` file at the root of your project to configure openapi-sync. You can use the provided `openapi.sync.sample.json` as
|
|
15
|
+
Create an `openapi.sync.json` file at the root of your project to configure openapi-sync. You can use the provided [`openapi.sync.sample.json`](https://github.com/akintomiwa-fisayo/openapi-sync/blob/master/openapi.sync.sample.json) as reference.
|
|
16
16
|
|
|
17
17
|
## Usage
|
|
18
18
|
|
|
@@ -32,6 +32,6 @@ You can also add it as a script in your package.json for easy access:
|
|
|
32
32
|
|
|
33
33
|
## Features
|
|
34
34
|
|
|
35
|
-
- Endpoint URI Generation:
|
|
36
|
-
-
|
|
37
|
-
- CLI Commands:
|
|
35
|
+
- Automated Endpoint URI Generation: Effortlessly generate endpoint URIs from your OpenAPI schema.
|
|
36
|
+
- Type Generation: Automatically create all types defined in your API schema, including shared types, for better code consistency.
|
|
37
|
+
- Flexible CLI Commands: Sync your API at any point in the development process on app start, pre-commit, or via manual triggers.
|
|
@@ -95,66 +95,68 @@ exports.getEndpointDetails = getEndpointDetails;
|
|
|
95
95
|
const parseSchemaToType = (apiDoc, schema, name, isRequired, options) => {
|
|
96
96
|
let typeName = name ? `\t${name}${isRequired ? "" : "?"}: ` : "";
|
|
97
97
|
let type = "";
|
|
98
|
-
if (schema
|
|
99
|
-
if (schema.$ref
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
98
|
+
if (schema) {
|
|
99
|
+
if (schema.$ref) {
|
|
100
|
+
if (schema.$ref[0] === "#") {
|
|
101
|
+
let pathToComponentParts = (schema.$ref || "").split("/");
|
|
102
|
+
pathToComponentParts.shift();
|
|
103
|
+
const pathToComponent = pathToComponentParts.join(".");
|
|
104
|
+
const component = lodash_1.default.get(apiDoc, pathToComponent, null);
|
|
105
|
+
if (component) {
|
|
106
|
+
const componentName = pathToComponentParts[pathToComponentParts.length - 1];
|
|
107
|
+
// Reference component via import instead of parsing
|
|
108
|
+
type += `${(options === null || options === void 0 ? void 0 : options.noSharedImport) ? "" : "Shared."}${(0, exports.getSharedComponentName)(componentName)}`;
|
|
109
|
+
// type += `${parseSchemaToType(apiDoc, component, "", isRequired)}`;
|
|
110
|
+
}
|
|
109
111
|
}
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
//TODO $ref is a uri - use axios to fetch doc
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
else if (schema.type) {
|
|
117
|
-
if (schema.enum && schema.enum.length > 0) {
|
|
118
|
-
if (schema.enum.length > 1)
|
|
119
|
-
type += "(";
|
|
120
|
-
type += schema.enum
|
|
121
|
-
.map((v) => `"${v}"`)
|
|
122
|
-
.join("|")
|
|
123
|
-
.toString();
|
|
124
|
-
if (schema.enum.length > 1)
|
|
125
|
-
type += ")";
|
|
126
|
-
}
|
|
127
|
-
else if (["string", "integer", "number", "array"].includes(schema.type)) {
|
|
128
|
-
if (schema.type === "string") {
|
|
129
|
-
type += `string`;
|
|
112
|
+
else {
|
|
113
|
+
type += "";
|
|
114
|
+
//TODO $ref is a uri - use axios to fetch doc
|
|
130
115
|
}
|
|
131
|
-
|
|
132
|
-
|
|
116
|
+
}
|
|
117
|
+
else if (schema.type) {
|
|
118
|
+
if (schema.enum && schema.enum.length > 0) {
|
|
119
|
+
if (schema.enum.length > 1)
|
|
120
|
+
type += "(";
|
|
121
|
+
type += schema.enum
|
|
122
|
+
.map((v) => `"${v}"`)
|
|
123
|
+
.join("|")
|
|
124
|
+
.toString();
|
|
125
|
+
if (schema.enum.length > 1)
|
|
126
|
+
type += ")";
|
|
133
127
|
}
|
|
134
|
-
else if (
|
|
135
|
-
if (schema.
|
|
136
|
-
type +=
|
|
128
|
+
else if (["string", "integer", "number", "array"].includes(schema.type)) {
|
|
129
|
+
if (schema.type === "string") {
|
|
130
|
+
type += `string`;
|
|
137
131
|
}
|
|
138
|
-
else {
|
|
139
|
-
type +=
|
|
132
|
+
else if (["integer", "number"].includes(schema.type)) {
|
|
133
|
+
type += `number`;
|
|
140
134
|
}
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
let typeCnt = "";
|
|
149
|
-
objKeys.forEach((key) => {
|
|
150
|
-
var _a;
|
|
151
|
-
typeCnt += `${(0, exports.parseSchemaToType)(apiDoc, (_a = schema.properties) === null || _a === void 0 ? void 0 : _a[key], key, requiredKeys.includes(key), options)}`;
|
|
152
|
-
});
|
|
153
|
-
if (typeCnt.length > 0) {
|
|
154
|
-
type += `{\n${typeCnt}}`;
|
|
135
|
+
else if (schema.type === "array") {
|
|
136
|
+
if (schema.items) {
|
|
137
|
+
type += `${(0, exports.parseSchemaToType)(apiDoc, schema.items, "", false, options)}[]`;
|
|
138
|
+
}
|
|
139
|
+
else {
|
|
140
|
+
type += "any[]";
|
|
141
|
+
}
|
|
155
142
|
}
|
|
156
|
-
|
|
157
|
-
|
|
143
|
+
}
|
|
144
|
+
else if (schema.type === "object") {
|
|
145
|
+
if (schema.properties) {
|
|
146
|
+
//parse object key one at a time
|
|
147
|
+
const objKeys = Object.keys(schema.properties);
|
|
148
|
+
const requiredKeys = schema.required || [];
|
|
149
|
+
let typeCnt = "";
|
|
150
|
+
objKeys.forEach((key) => {
|
|
151
|
+
var _a;
|
|
152
|
+
typeCnt += `${(0, exports.parseSchemaToType)(apiDoc, (_a = schema.properties) === null || _a === void 0 ? void 0 : _a[key], key, requiredKeys.includes(key), options)}`;
|
|
153
|
+
});
|
|
154
|
+
if (typeCnt.length > 0) {
|
|
155
|
+
type += `{\n${typeCnt}}`;
|
|
156
|
+
}
|
|
157
|
+
else {
|
|
158
|
+
type += "object";
|
|
159
|
+
}
|
|
158
160
|
}
|
|
159
161
|
}
|
|
160
162
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "openapi-sync",
|
|
3
|
-
"version": "1.0.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "1.0.17",
|
|
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
7
|
"bin": {
|