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/db.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{}
|
|
1
|
+
{"tmc":{"openapi":"3.0.3","info":{"title":"TMC Automation API Docs (v1)","version":"1.8.1"},"servers":[{"url":"https://api.tmcng.net/api/v1"}],"tags":[{"name":"User","description":"Users APIs"},{"name":"MembershipRequest","description":"Handle request of users to become a member"}],"components":{"schemas":{"MessageResponse":{"type":"object","properties":{"message":{"type":"string"}},"required":["message"]},"User.OtpResponse":{"type":"object","properties":{"token":{"type":"string"}},"required":["token"]},"User.SignupOptions":{"type":"object","properties":{"emailAddress":{"type":"string"},"password":{"type":"string"},"surname":{"type":"string"},"othernames":{"type":"string"},"country":{"type":"string"},"address":{"type":"string"},"phoneNumber":{"type":"string"}},"required":["emailAddress","password","surname","othernames","country","address","phoneNumber"]},"User.Profile":{"type":"object","properties":{"user_id":{"type":"string"},"email_address":{"type":"string"},"scopes":{"type":"array","items":{"type":"number","enum":[0,1,2,3,4,5]}},"name":{"type":"string"},"surname":{"type":"string"},"othernames":{"type":"string"},"country":{"type":"string"},"state":{"type":"string"},"local_government_area":{"type":"string"},"branch":{"type":"string"},"address":{"type":"string"},"phone_number":{"type":"string"},"date_of_birth":{"type":"string"},"state_of_origin":{"type":"string"},"lga_of_origin":{"type":"string"},"whatsapp_number":{"type":"string"},"genotype":{"type":"string"},"blood_group":{"type":"string"},"specific_ailment":{"type":"string"},"hospital":{"type":"string"},"qualification":{"type":"string"},"occupation":{"type":"string"},"specialization":{"type":"string"},"years_of_experience":{"type":"number"},"membership_duration":{"type":"number"}},"required":["user_id","email_address","scopes","name","surname","othernames","country","state","local_government_area","branch","address","phone_number","date_of_birth","state_of_origin","lga_of_origin","whatsapp_number","genotype","blood_group","specific_ailment","hospital","qualification","occupation","specialization","years_of_experience","membership_duration"]},"User.LoginResponse":{"type":"object","properties":{"userId":{"type":"string"},"token":{"type":"string"}},"required":["userId","token"]},"User.MembershipStatusResponse":{"type":"object","properties":{"status":{"type":"string","enum":["Member","NonMember","Pending","Denied"]}},"required":["status"]},"User.AuthenticationResponse":{"type":"object","properties":{"authenticated":{"type":"boolean"},"userId":{"type":"string"}},"required":["authenticated","userId"]},"User.InitialLoadData":{"type":"object","properties":{"profile":{"$ref":"#/components/schemas/User.Profile"},"membershipStatus":{"type":"string","enum":["Member","NonMember","Pending","Denied"]}},"required":["profile","membershipStatus"]},"User.OtpValidationResponse":{"type":"object","properties":{"validated":{"type":"boolean"},"message":{"type":"string"}},"required":["validated","message"]},"User.SignupResponse":{"type":"object","properties":{"message":{"type":"string"},"data":{"type":"object","properties":{"userId":{"type":"string"}},"required":["userId"]}},"required":["message"]},"Database.DbAccessTokens":{"type":"object","properties":{"id":{"type":"number"},"token":{"type":"string"},"user_id":{"type":"string"},"created_at":{"type":"string"}},"required":["id","token","user_id","created_at"]},"Database.DbApp":{"type":"object","properties":{"id":{"type":"number"},"property":{"type":"string"},"value":{"type":"string"}},"required":["id","property","value"]},"Database.DbMembershipRequests":{"type":"object","properties":{"id":{"type":"number"},"user_id":{"type":"string"},"state":{"type":"string"},"local_government_area":{"type":"string"},"branch":{"type":"string"},"date_of_birth":{"type":"string"},"state_of_origin":{"type":"string"},"lga_of_origin":{"type":"string"},"whatsapp_number":{"type":"string"},"genotype":{"type":"string"},"blood_group":{"type":"string"},"specific_ailment":{"type":"string"},"hospital":{"type":"string"},"qualification":{"type":"string"},"occupation":{"type":"string"},"specialization":{"type":"string"},"years_of_experience":{"type":"number"},"membership_duration":{"type":"number"},"reviewed_by":{"type":"string"},"status":{"type":"string"},"reviewed_at":{"type":"string"},"created_at":{"type":"string"}},"required":["id","user_id","state","local_government_area","branch","date_of_birth","state_of_origin","lga_of_origin","whatsapp_number","genotype","blood_group","specific_ailment","hospital","qualification","occupation","specialization","years_of_experience","membership_duration","status","created_at"]},"Database.DbOtps":{"type":"object","properties":{"id":{"type":"number"},"token":{"type":"string"},"otp":{"type":"string"},"created_at":{"type":"string"}},"required":["id","token","otp","created_at"]},"Database.DbUsers":{"type":"object","properties":{"id":{"type":"number"},"user_id":{"type":"string"},"membership_id":{"type":"string"},"email_address":{"type":"string"},"surname":{"type":"string"},"othernames":{"type":"string"},"phone_number":{"type":"string"},"password":{"type":"string"},"country":{"type":"string"},"local_government_area":{"type":"string"},"scopes":{"type":"string"},"state":{"type":"string"},"branch":{"type":"string"},"address":{"type":"string"},"date_of_birth":{"type":"string"},"state_of_origin":{"type":"string"},"lga_of_origin":{"type":"string"},"whatsapp_number":{"type":"string"},"genotype":{"type":"string"},"blood_group":{"type":"string"},"specific_ailment":{"type":"string"},"hospital":{"type":"string"},"qualification":{"type":"string"},"occupation":{"type":"string"},"specialization":{"type":"string"},"years_of_experience":{"type":"number"},"membership_duration":{"type":"number"},"created_at":{"type":"string"},"updated_at":{"type":"string"}},"required":["id","email_address","surname","othernames","phone_number","password","country","local_government_area","state","branch","address","date_of_birth","state_of_origin","lga_of_origin","whatsapp_number","genotype","blood_group","specific_ailment","hospital","qualification","occupation","specialization","years_of_experience","membership_duration","created_at","updated_at"]},"MembershipRequest.CreateOptions":{"type":"object","properties":{"state":{"type":"string"},"local_government_area":{"type":"string"},"branch":{"type":"string"},"date_of_birth":{"type":"string"},"state_of_origin":{"type":"string"},"lga_of_origin":{"type":"string"},"whatsapp_number":{"type":"string"},"genotype":{"type":"string"},"blood_group":{"type":"string"},"specific_ailment":{"type":"string"},"hospital":{"type":"string"},"qualification":{"type":"string"},"occupation":{"type":"string"},"specialization":{"type":"string"},"years_of_experience":{"type":"number"},"membership_duration":{"type":"number"}},"required":["state","local_government_area","branch","date_of_birth","state_of_origin","lga_of_origin","whatsapp_number","genotype","blood_group","specific_ailment","hospital","qualification","occupation","specialization","years_of_experience","membership_duration"]},"MembershipRequest.ReviewResponse":{"type":"object","properties":{"status":{"type":"string","enum":["Denied","Approved"]},"approved":{"type":"boolean"},"data":{"$ref":"#/components/schemas/MembershipRequest.ReviewResponseData"}},"required":["status","approved"]},"MembershipRequest.ReviewResponseData":{"type":"object","properties":{"membershipId":{"type":"string"}},"required":["membershipId"]},"Email.Email":{"type":"object","properties":{"from":{"type":"string"},"to":{"type":"string"},"subject":{"type":"string"},"body":{"type":"string"}},"required":["from","to","subject","body"]},"Email.SendEmailResponse":{"type":"object","properties":{"sent":{"type":"boolean"},"message":{"type":"string"}},"required":["sent","message"]},"Database.Column":{"type":"object","properties":{"Field":{"type":"string"},"Type":{"type":"string"},"Null":{"type":"string"},"Key":{"type":"string"},"Default":{"type":"string"},"Extra":{"type":"string"}},"required":["Field","Type","Null","Key","Extra"]},"Database.AccessTokens":{"type":"string","enum":["access_tokens","id","token","user_id","created_at"]},"Database.App":{"type":"string","enum":["app","id","property","value"]},"Database.MembershipRequests":{"type":"string","enum":["membership_requests","id","user_id","state","local_government_area","branch","date_of_birth","state_of_origin","lga_of_origin","whatsapp_number","genotype","blood_group","specific_ailment","hospital","qualification","occupation","specialization","years_of_experience","membership_duration","reviewed_by","status","reviewed_at","created_at"]},"Database.Otps":{"type":"string","enum":["otps","id","token","otp","created_at"]},"Database.Users":{"type":"string","enum":["users","id","user_id","membership_id","email_address","surname","othernames","phone_number","password","country","local_government_area","scopes","state","branch","address","date_of_birth","state_of_origin","lga_of_origin","whatsapp_number","genotype","blood_group","specific_ailment","hospital","qualification","occupation","specialization","years_of_experience","membership_duration","created_at","updated_at"]},"Aw.Bx.Cy.E":{"type":"object","properties":{"fgh":{"type":"string"}},"required":["fgh"]},"Aw.Bx.Cy.Dz.J":{"type":"object","properties":{"fghlll":{"type":"string"}},"required":["fghlll"]},"Update.Manifest":{"type":"object","properties":{"version":{"type":"string"}},"required":["version"]},"Update.UpdateConfig":{"type":"object","properties":{"scripts":{"type":"array","items":{"type":"string"}},"commit":{"type":"string"}}}},"securitySchemes":{"bearerAuth":{"type":"http","scheme":"bearer","bearerFormat":"JWT"}},"responses":{"BadRequest":{"description":"Error occurred in request","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string","example":"Error occurred in request"}}}}}}},"parameters":{}},"paths":{"/user/login":{"post":{"tags":["User"],"summary":"Login to user account","operationId":"postUserLogin","requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","properties":{"email_address":{"type":"string"},"password":{"type":"string"}},"required":["email_address","password"]}}}},"responses":{"200":{"description":"","content":{"application/json":{"schema":{"$ref":"#/components/schemas/User.LoginResponse"}}}},"400":{"$ref":"#/components/responses/BadRequest"}}}},"/user/generate-otp":{"post":{"tags":["User"],"summary":"Generate OTP to be sent to user's email address when creating new account","operationId":"postUserGenerateOtp","requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","properties":{"email_address":{"type":"string"}},"required":["email_address"]}}}},"responses":{"200":{"description":"","content":{"application/json":{"schema":{"$ref":"#/components/schemas/User.OtpResponse"}}}},"400":{"$ref":"#/components/responses/BadRequest"}}}},"/user/validate-otp":{"post":{"tags":["User"],"summary":"Validate OTP sent by user to server","operationId":"postUserValidateOtp","requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","properties":{"token":{"type":"string"},"user_otp":{"type":"string"}},"required":["token","user_otp"]}}}},"responses":{"200":{"description":"","content":{"application/json":{"schema":{"$ref":"#/components/schemas/User.OtpValidationResponse"}}}},"400":{"$ref":"#/components/responses/BadRequest"}}}},"/user/create":{"post":{"tags":["User"],"summary":"Create new user account","operationId":"postUserCreate","requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","properties":{"surname":{"type":"string"},"othernames":{"type":"string"},"email_address":{"type":"string","format":"email"},"country":{"type":"string"},"address":{"type":"string"},"phone_number":{"type":"string"},"password":{"type":"string","minLength":8}},"required":["surname","othernames","email_address","country","address","phone_number","password"]}}}},"responses":{"200":{"description":"","content":{"application/json":{"schema":{"$ref":"#/components/schemas/User.SignupResponse"}}}},"400":{"$ref":"#/components/responses/BadRequest"}}}},"/user/profile":{"get":{"tags":["User"],"summary":"Get user profile","description":"```Scopes: []```","operationId":"getUserProfile","security":[{"bearerAuth":[]}],"responses":{"200":{"description":"","content":{"application/json":{"schema":{"$ref":"#/components/schemas/User.Profile"}}}},"400":{"$ref":"#/components/responses/BadRequest"}}}},"/user/initial-load-data":{"get":{"tags":["User"],"summary":"Get all common data needed to load frontend pages","description":"```Scopes: []```","operationId":"getUserInitialLoadData","security":[{"bearerAuth":[]}],"responses":{"200":{"description":"","content":{"application/json":{"schema":{"$ref":"#/components/schemas/User.InitialLoadData"}}}},"400":{"$ref":"#/components/responses/BadRequest"}}}},"/user/update-scopes/{userId}":{"post":{"tags":["User"],"summary":"Updates scopes of user","description":"```Scopes: [Scope.Developer]```","operationId":"postUserUpdateScopesByUserId","security":[{"bearerAuth":[]}],"parameters":[{"name":"userId","description":"User ID of the user whose scopes are to be updated","in":"path","required":true,"schema":{"type":"string"}}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","properties":{"scopes":{"type":"string"}},"required":["scopes"]}}}},"responses":{"200":{"description":"","content":{"application/json":{"schema":{"$ref":"#/components/schemas/MessageResponse"}}}},"400":{"$ref":"#/components/responses/BadRequest"}}}},"/user/membership-status":{"get":{"tags":["User"],"summary":"Get membership status of user","description":"```Scopes: []```","operationId":"getUserMembershipStatus","security":[{"bearerAuth":[]}],"responses":{"200":{"description":"","content":{"application/json":{"schema":{"$ref":"#/components/schemas/User.MembershipStatusResponse"}}}},"400":{"$ref":"#/components/responses/BadRequest"}}}},"/user/membership-request/create":{"post":{"tags":["MembershipRequest"],"summary":"Create new membership request","description":"```Scopes: []```","operationId":"postUserMembershipRequestCreate","security":[{"bearerAuth":[]}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","properties":{"state":{"type":"string"},"local_government_area":{"type":"string"},"branch":{"type":"string"},"date_of_birth":{"type":"string"},"state_of_origin":{"type":"string"},"lga_of_origin":{"type":"string"},"whatsapp_number":{"type":"string"},"genotype":{"type":"string"},"blood_group":{"type":"string"},"specific_ailment":{"type":"string"},"hospital":{"type":"string"},"qualification":{"type":"string"},"occupation":{"type":"string"},"specialization":{"type":"string"},"years_of_experience":{"type":"number"},"membership_duration":{"type":"number"}},"required":["state","local_government_area","branch","date_of_birth","state_of_origin","lga_of_origin","whatsapp_number","genotype","blood_group","specific_ailment","hospital","qualification","occupation","specialization","years_of_experience","membership_duration"]}}}},"responses":{"200":{"description":"","content":{"application/json":{"schema":{"$ref":"#/components/schemas/MessageResponse"}}}},"400":{"$ref":"#/components/responses/BadRequest"}}}},"/user/membership-request/data":{"get":{"tags":["MembershipRequest"],"summary":"Membership request data","description":"```Scopes: []```","operationId":"getUserMembershipRequestData","security":[{"bearerAuth":[]}],"responses":{"200":{"description":"","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Database.DbMembershipRequests"}}}},"400":{"$ref":"#/components/responses/BadRequest"}}}},"/user/membership-request/pending-requests":{"get":{"tags":["MembershipRequest"],"summary":"All pending requests to be reviewed by an admin user","description":"```Scopes: [Clearance.from(Scope.BranchExecutive)]```","operationId":"getUserMembershipRequestPendingRequests","security":[{"bearerAuth":[]}],"responses":{"200":{"description":"","content":{"application/json":{"schema":{"type":"array","items":{"$ref":"#/components/schemas/Database.DbMembershipRequests"}}}}},"400":{"$ref":"#/components/responses/BadRequest"}}}},"/user/membership-request/review/{requesterId}":{"post":{"tags":["MembershipRequest"],"summary":"All pending requests to be reviewed by an admin user","description":"```Scopes: [Clearance.from(Scope.BranchExecutive)]```","operationId":"postUserMembershipRequestReviewByRequesterId","security":[{"bearerAuth":[]}],"parameters":[{"name":"requesterId","description":"User ID of the user that made the membership request","in":"path","required":true,"schema":{"type":"string"}}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","properties":{"status":{"type":"string","enum":["Denied","Approved"]}},"required":["status"]}}}},"responses":{"200":{"description":"","content":{"application/json":{"schema":{"$ref":"#/components/schemas/MembershipRequest.ReviewResponse"}}}},"400":{"$ref":"#/components/responses/BadRequest"}}}},"/user/membership-request/list":{"get":{"tags":["MembershipRequest"],"summary":"All pending requests in database","description":"```Scopes: [Scope.Developer]```","operationId":"getUserMembershipRequestList","security":[{"bearerAuth":[]}],"responses":{"200":{"description":"","content":{"application/json":{"schema":{"type":"array","items":{"$ref":"#/components/schemas/Database.DbMembershipRequests"}}}}},"400":{"$ref":"#/components/responses/BadRequest"}}}}}}}
|
|
@@ -22,14 +22,11 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
22
22
|
__setModuleDefault(result, mod);
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
-
};
|
|
28
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.
|
|
26
|
+
exports.renderTypeRefMD = exports.JSONStringify = exports.getEndpointDetails = exports.capitalize = exports.yamlStringToJson = exports.isYamlString = exports.isJson = void 0;
|
|
27
|
+
exports.getNestedValue = getNestedValue;
|
|
30
28
|
const regex_1 = require("./regex");
|
|
31
29
|
const yaml = __importStar(require("js-yaml"));
|
|
32
|
-
const lodash_1 = __importDefault(require("lodash"));
|
|
33
30
|
const isJson = (value) => {
|
|
34
31
|
return ["object"].includes(typeof value) && !(value instanceof Blob);
|
|
35
32
|
};
|
|
@@ -64,8 +61,6 @@ const capitalize = (text) => {
|
|
|
64
61
|
return capitalizedWord;
|
|
65
62
|
};
|
|
66
63
|
exports.capitalize = capitalize;
|
|
67
|
-
const getSharedComponentName = (componentName, componentType) => `IApi${(0, exports.capitalize)(componentName)}`;
|
|
68
|
-
exports.getSharedComponentName = getSharedComponentName;
|
|
69
64
|
const getEndpointDetails = (path, method) => {
|
|
70
65
|
const pathParts = path.split("/");
|
|
71
66
|
let name = `${(0, exports.capitalize)(method)}`;
|
|
@@ -105,125 +100,46 @@ const getEndpointDetails = (path, method) => {
|
|
|
105
100
|
return { name, variables, pathParts };
|
|
106
101
|
};
|
|
107
102
|
exports.getEndpointDetails = getEndpointDetails;
|
|
108
|
-
const
|
|
109
|
-
let
|
|
110
|
-
|
|
111
|
-
let
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
pathToComponentParts.shift();
|
|
118
|
-
const pathToComponent = pathToComponentParts.join(".");
|
|
119
|
-
const component = lodash_1.default.get(apiDoc, pathToComponent, null);
|
|
120
|
-
// console.log("Type schema 3", pathToComponentParts);
|
|
121
|
-
if (component) {
|
|
122
|
-
if (component === null || component === void 0 ? void 0 : component.name) {
|
|
123
|
-
overrideName = component.name;
|
|
124
|
-
}
|
|
125
|
-
componentName = pathToComponentParts[pathToComponentParts.length - 1];
|
|
126
|
-
// Reference component via import instead of parsing
|
|
127
|
-
type += `${(options === null || options === void 0 ? void 0 : options.noSharedImport) ? "" : "Shared."}${(0, exports.getSharedComponentName)(componentName)}`;
|
|
128
|
-
// type += `${parseSchemaToType(apiDoc, component, "", isRequired)}`;
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
else {
|
|
132
|
-
type += "";
|
|
133
|
-
//TODO $ref is a uri - use axios to fetch doc
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
else if (schema.anyOf) {
|
|
137
|
-
type += `(${schema.anyOf
|
|
138
|
-
.map((v) => (0, exports.parseSchemaToType)(apiDoc, v, "", isRequired, options))
|
|
139
|
-
.join("|")})`;
|
|
140
|
-
}
|
|
141
|
-
else if (schema.oneOf) {
|
|
142
|
-
type += `(${schema.oneOf
|
|
143
|
-
.map((v) => (0, exports.parseSchemaToType)(apiDoc, v, "", isRequired, options))
|
|
144
|
-
.join("|")})`;
|
|
145
|
-
}
|
|
146
|
-
else if (schema.allOf) {
|
|
147
|
-
type += `(${schema.allOf
|
|
148
|
-
.map((v) => (0, exports.parseSchemaToType)(apiDoc, v, "", isRequired, options))
|
|
149
|
-
.join("&")})`;
|
|
150
|
-
}
|
|
151
|
-
else if (schema.items) {
|
|
152
|
-
type += `${(0, exports.parseSchemaToType)(apiDoc, schema.items, "", false, options)}[]`;
|
|
103
|
+
const JSONStringify = (obj, indent = 1) => {
|
|
104
|
+
let result = "{";
|
|
105
|
+
const keys = Object.keys(obj);
|
|
106
|
+
for (let i = 0; i < keys.length; i++) {
|
|
107
|
+
const key = keys[i];
|
|
108
|
+
const value = obj[key];
|
|
109
|
+
result += "\n" + " ".repeat(indent) + key + ": ";
|
|
110
|
+
if (typeof value === "object" && value !== null) {
|
|
111
|
+
result += "" + (0, exports.JSONStringify)(value, indent + 1);
|
|
153
112
|
}
|
|
154
|
-
else
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
objKeys.forEach((key) => {
|
|
160
|
-
var _a;
|
|
161
|
-
typeCnt += `${(0, exports.parseSchemaToType)(apiDoc, (_a = schema.properties) === null || _a === void 0 ? void 0 : _a[key], key, requiredKeys.includes(key), options)}`;
|
|
162
|
-
});
|
|
163
|
-
if (typeCnt.length > 0) {
|
|
164
|
-
type += `{\n${typeCnt}}`;
|
|
165
|
-
}
|
|
166
|
-
else {
|
|
167
|
-
type += "{[k: string]: any}";
|
|
168
|
-
}
|
|
113
|
+
else {
|
|
114
|
+
result += value
|
|
115
|
+
.split("\n")
|
|
116
|
+
.filter((line) => line.trim() !== "")
|
|
117
|
+
.join(`\n${" ".repeat(indent)}`);
|
|
169
118
|
}
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
if (schema.enum.length > 1)
|
|
173
|
-
type += "(";
|
|
174
|
-
type += schema.enum
|
|
175
|
-
.map((v) => `"${v}"`)
|
|
176
|
-
.join("|")
|
|
177
|
-
.toString();
|
|
178
|
-
if (schema.enum.length > 1)
|
|
179
|
-
type += ")";
|
|
180
|
-
}
|
|
181
|
-
else if (["string", "integer", "number", "array", "boolean"].includes(schema.type)) {
|
|
182
|
-
if (["integer", "number"].includes(schema.type)) {
|
|
183
|
-
type += `number`;
|
|
184
|
-
}
|
|
185
|
-
else if (schema.type === "array") {
|
|
186
|
-
//Since we would have already parsed the arrays keys above "schema.items" if it exists
|
|
187
|
-
type += "any[]";
|
|
188
|
-
/* if (schema.items) {
|
|
189
|
-
type += `${parseSchemaToType(
|
|
190
|
-
apiDoc,
|
|
191
|
-
schema.items,
|
|
192
|
-
"",
|
|
193
|
-
false,
|
|
194
|
-
options
|
|
195
|
-
)}[]`;
|
|
196
|
-
} else {
|
|
197
|
-
type += "any[]";
|
|
198
|
-
} */
|
|
199
|
-
}
|
|
200
|
-
else {
|
|
201
|
-
type += schema.type;
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
else if (schema.type === "object") {
|
|
205
|
-
//Since we would have already parsed the object keys above "schema.properties" if it exists
|
|
206
|
-
if (schema.additionalProperties) {
|
|
207
|
-
type += `{[k: string]: ${(0, exports.parseSchemaToType)(apiDoc, schema.additionalProperties, "", true, options) || "any"}}`;
|
|
208
|
-
}
|
|
209
|
-
else {
|
|
210
|
-
type += "{[k: string]: any}";
|
|
211
|
-
}
|
|
212
|
-
}
|
|
119
|
+
if (i < keys.length - 1) {
|
|
120
|
+
result += ", ";
|
|
213
121
|
}
|
|
214
122
|
}
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
const nullable = (schema === null || schema === void 0 ? void 0 : schema.nullable) ? " | null" : "";
|
|
225
|
-
return type.length > 0
|
|
226
|
-
? `${typeName}${type}${nullable}${_name ? ";\n" : ""}`
|
|
227
|
-
: "";
|
|
123
|
+
result += `\n${" ".repeat(indent - 1)}}`;
|
|
124
|
+
return result;
|
|
125
|
+
};
|
|
126
|
+
exports.JSONStringify = JSONStringify;
|
|
127
|
+
const renderTypeRefMD = (typeRef, indent = 1) => {
|
|
128
|
+
return `\n\`\`\`typescript\n${" ".repeat(indent)} ${typeRef
|
|
129
|
+
.split("\n")
|
|
130
|
+
.filter((line) => line.trim() !== "")
|
|
131
|
+
.join(`\n${" ".repeat(indent)} `)}\n\`\`\``;
|
|
228
132
|
};
|
|
229
|
-
exports.
|
|
133
|
+
exports.renderTypeRefMD = renderTypeRefMD;
|
|
134
|
+
function getNestedValue(obj, path) {
|
|
135
|
+
// Split the path string into an array of keys
|
|
136
|
+
const keys = path.split(".");
|
|
137
|
+
// Use the reduce method to navigate the object
|
|
138
|
+
return keys.reduce((currentObj, key) => {
|
|
139
|
+
// If the current object is not null or undefined,
|
|
140
|
+
// return the value of the next key. Otherwise, return undefined.
|
|
141
|
+
return currentObj && currentObj[key] !== undefined
|
|
142
|
+
? currentObj[key]
|
|
143
|
+
: undefined;
|
|
144
|
+
}, obj);
|
|
145
|
+
}
|