openapi-sync 1.0.20 → 1.0.22
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.
|
@@ -106,7 +106,7 @@ const getEndpointDetails = (path, method) => {
|
|
|
106
106
|
};
|
|
107
107
|
exports.getEndpointDetails = getEndpointDetails;
|
|
108
108
|
const parseSchemaToType = (apiDoc, schema, name, isRequired, options) => {
|
|
109
|
-
let typeName = name ? `\t${name}${isRequired ? "" : "?"}: ` : "";
|
|
109
|
+
let typeName = name ? `\t"${name}"${isRequired ? "" : "?"}: ` : "";
|
|
110
110
|
let type = "";
|
|
111
111
|
if (schema) {
|
|
112
112
|
if (schema.$ref) {
|
|
@@ -127,6 +127,40 @@ const parseSchemaToType = (apiDoc, schema, name, isRequired, options) => {
|
|
|
127
127
|
//TODO $ref is a uri - use axios to fetch doc
|
|
128
128
|
}
|
|
129
129
|
}
|
|
130
|
+
else if (schema.anyOf) {
|
|
131
|
+
type += `(${schema.anyOf
|
|
132
|
+
.map((v) => (0, exports.parseSchemaToType)(apiDoc, v, "", isRequired, options))
|
|
133
|
+
.join("|")})`;
|
|
134
|
+
}
|
|
135
|
+
else if (schema.oneOf) {
|
|
136
|
+
type += `(${schema.oneOf
|
|
137
|
+
.map((v) => (0, exports.parseSchemaToType)(apiDoc, v, "", isRequired, options))
|
|
138
|
+
.join("|")})`;
|
|
139
|
+
}
|
|
140
|
+
else if (schema.allOf) {
|
|
141
|
+
type += `(${schema.allOf
|
|
142
|
+
.map((v) => (0, exports.parseSchemaToType)(apiDoc, v, "", isRequired, options))
|
|
143
|
+
.join("&")})`;
|
|
144
|
+
}
|
|
145
|
+
else if (schema.items) {
|
|
146
|
+
type += `${(0, exports.parseSchemaToType)(apiDoc, schema.items, "", false, options)}[]`;
|
|
147
|
+
}
|
|
148
|
+
else if (schema.properties) {
|
|
149
|
+
//parse object key one at a time
|
|
150
|
+
const objKeys = Object.keys(schema.properties);
|
|
151
|
+
const requiredKeys = schema.required || [];
|
|
152
|
+
let typeCnt = "";
|
|
153
|
+
objKeys.forEach((key) => {
|
|
154
|
+
var _a;
|
|
155
|
+
typeCnt += `${(0, exports.parseSchemaToType)(apiDoc, (_a = schema.properties) === null || _a === void 0 ? void 0 : _a[key], key, requiredKeys.includes(key), options)}`;
|
|
156
|
+
});
|
|
157
|
+
if (typeCnt.length > 0) {
|
|
158
|
+
type += `{\n${typeCnt}}`;
|
|
159
|
+
}
|
|
160
|
+
else {
|
|
161
|
+
type += "{[k: string]: any}";
|
|
162
|
+
}
|
|
163
|
+
}
|
|
130
164
|
else if (schema.type) {
|
|
131
165
|
if (schema.enum && schema.enum.length > 0) {
|
|
132
166
|
if (schema.enum.length > 1)
|
|
@@ -138,42 +172,47 @@ const parseSchemaToType = (apiDoc, schema, name, isRequired, options) => {
|
|
|
138
172
|
if (schema.enum.length > 1)
|
|
139
173
|
type += ")";
|
|
140
174
|
}
|
|
141
|
-
else if (["string", "integer", "number", "array"].includes(schema.type)) {
|
|
142
|
-
if (schema.type
|
|
143
|
-
type += `string`;
|
|
144
|
-
}
|
|
145
|
-
else if (["integer", "number"].includes(schema.type)) {
|
|
175
|
+
else if (["string", "integer", "number", "array", "boolean"].includes(schema.type)) {
|
|
176
|
+
if (["integer", "number"].includes(schema.type)) {
|
|
146
177
|
type += `number`;
|
|
147
178
|
}
|
|
148
179
|
else if (schema.type === "array") {
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
180
|
+
//Since we would have already parsed the arrays keys above "schema.items" if it exists
|
|
181
|
+
type += "any[]";
|
|
182
|
+
/* if (schema.items) {
|
|
183
|
+
type += `${parseSchemaToType(
|
|
184
|
+
apiDoc,
|
|
185
|
+
schema.items,
|
|
186
|
+
"",
|
|
187
|
+
false,
|
|
188
|
+
options
|
|
189
|
+
)}[]`;
|
|
190
|
+
} else {
|
|
191
|
+
type += "any[]";
|
|
192
|
+
} */
|
|
193
|
+
}
|
|
194
|
+
else {
|
|
195
|
+
type += schema.type;
|
|
155
196
|
}
|
|
156
197
|
}
|
|
157
198
|
else if (schema.type === "object") {
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
var _a;
|
|
165
|
-
typeCnt += `${(0, exports.parseSchemaToType)(apiDoc, (_a = schema.properties) === null || _a === void 0 ? void 0 : _a[key], key, requiredKeys.includes(key), options)}`;
|
|
166
|
-
});
|
|
167
|
-
if (typeCnt.length > 0) {
|
|
168
|
-
type += `{\n${typeCnt}}`;
|
|
169
|
-
}
|
|
170
|
-
else {
|
|
171
|
-
type += "object";
|
|
172
|
-
}
|
|
199
|
+
//Since we would have already parsed the object keys above "schema.properties" if it exists
|
|
200
|
+
if (schema.additionalProperties) {
|
|
201
|
+
type += `{[k: string]: ${(0, exports.parseSchemaToType)(apiDoc, schema.additionalProperties, "", true, options)}}`;
|
|
202
|
+
}
|
|
203
|
+
else {
|
|
204
|
+
type += "{[k: string]: any}";
|
|
173
205
|
}
|
|
174
206
|
}
|
|
175
207
|
}
|
|
176
208
|
}
|
|
177
|
-
|
|
209
|
+
else {
|
|
210
|
+
//Default type to string if no schema provided
|
|
211
|
+
type = "string";
|
|
212
|
+
}
|
|
213
|
+
const nullable = (schema === null || schema === void 0 ? void 0 : schema.nullable) ? " | null" : "";
|
|
214
|
+
return type.length > 0
|
|
215
|
+
? `${typeName}${type}${nullable}${name ? ";\n" : ""}`
|
|
216
|
+
: "";
|
|
178
217
|
};
|
|
179
218
|
exports.parseSchemaToType = parseSchemaToType;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "openapi-sync",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.22",
|
|
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",
|