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 CHANGED
@@ -1,6 +1,6 @@
1
1
  # Openapi-sync
2
2
 
3
- **Openapi-sync** leverages the power of OpenAPI schemas, just like Swagger UI, Postman, Redoc, and other popular tools. This package automates the creation of endpoint URIs and all defined types (including shared types) in a simple and developer-friendly manner and ensures your API remains up-to-date by checking for updates at intervals or right before committing your code (pre-commit).
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 a reference.
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: Automatically generate endpoint URIs from your OpenAPI schema.
36
- - Types Generation: Generate all defined types, including shared types, from your OpenAPI schema.
37
- - CLI Commands: Use the command-line interface to regenerate files at any time—on app start, pre-commit, or whenever needed.
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.$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,7 +1,7 @@
1
1
  {
2
2
  "name": "openapi-sync",
3
- "version": "1.0.14",
4
- "description": "sync openapi variables",
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": {