openapi-sync 1.0.15 → 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.
@@ -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.$ref) {
99
- if (schema.$ref[0] === "#") {
100
- let pathToComponentParts = (schema.$ref || "").split("/");
101
- pathToComponentParts.shift();
102
- const pathToComponent = pathToComponentParts.join(".");
103
- const component = lodash_1.default.get(apiDoc, pathToComponent, null);
104
- if (component) {
105
- const componentName = pathToComponentParts[pathToComponentParts.length - 1];
106
- // Reference component via import instead of parsing
107
- type += `${(options === null || options === void 0 ? void 0 : options.noSharedImport) ? "" : "Shared."}${(0, exports.getSharedComponentName)(componentName)}`;
108
- // type += `${parseSchemaToType(apiDoc, component, "", isRequired)}`;
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
- else {
112
- type += "";
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
- else if (["integer", "number"].includes(schema.type)) {
132
- type += `number`;
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 (schema.type === "array") {
135
- if (schema.items) {
136
- type += `${(0, exports.parseSchemaToType)(apiDoc, schema.items, "", false, options)}[]`;
128
+ else if (["string", "integer", "number", "array"].includes(schema.type)) {
129
+ if (schema.type === "string") {
130
+ type += `string`;
137
131
  }
138
- else {
139
- type += "any[]";
132
+ else if (["integer", "number"].includes(schema.type)) {
133
+ type += `number`;
140
134
  }
141
- }
142
- }
143
- else if (schema.type === "object") {
144
- if (schema.properties) {
145
- //parse object key one at a time
146
- const objKeys = Object.keys(schema.properties);
147
- const requiredKeys = schema.required || [];
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
- else {
157
- type += "object";
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,6 +1,6 @@
1
1
  {
2
2
  "name": "openapi-sync",
3
- "version": "1.0.15",
3
+ "version": "1.0.17",
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",