openapi-sync 2.0.0 → 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 +29 -6
- package/dist/Openapi-sync/index.js +309 -67
- package/dist/Openapi-sync/state.js +3 -0
- package/dist/Openapi-sync/test.js +709 -0
- package/package.json +3 -2
- package/types.ts +31 -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"}}}}}}}
|
|
@@ -23,7 +23,8 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.JSONStringify = exports.getEndpointDetails = exports.capitalize = exports.yamlStringToJson = exports.isYamlString = exports.isJson = void 0;
|
|
26
|
+
exports.renderTypeRefMD = exports.JSONStringify = exports.getEndpointDetails = exports.capitalize = exports.yamlStringToJson = exports.isYamlString = exports.isJson = void 0;
|
|
27
|
+
exports.getNestedValue = getNestedValue;
|
|
27
28
|
const regex_1 = require("./regex");
|
|
28
29
|
const yaml = __importStar(require("js-yaml"));
|
|
29
30
|
const isJson = (value) => {
|
|
@@ -99,24 +100,46 @@ const getEndpointDetails = (path, method) => {
|
|
|
99
100
|
return { name, variables, pathParts };
|
|
100
101
|
};
|
|
101
102
|
exports.getEndpointDetails = getEndpointDetails;
|
|
102
|
-
const JSONStringify = (obj) => {
|
|
103
|
+
const JSONStringify = (obj, indent = 1) => {
|
|
103
104
|
let result = "{";
|
|
104
105
|
const keys = Object.keys(obj);
|
|
105
106
|
for (let i = 0; i < keys.length; i++) {
|
|
106
107
|
const key = keys[i];
|
|
107
108
|
const value = obj[key];
|
|
108
|
-
result += key + ": ";
|
|
109
|
+
result += "\n" + " ".repeat(indent) + key + ": ";
|
|
109
110
|
if (typeof value === "object" && value !== null) {
|
|
110
|
-
result += (0, exports.JSONStringify)(value);
|
|
111
|
+
result += "" + (0, exports.JSONStringify)(value, indent + 1);
|
|
111
112
|
}
|
|
112
113
|
else {
|
|
113
|
-
result += value
|
|
114
|
+
result += value
|
|
115
|
+
.split("\n")
|
|
116
|
+
.filter((line) => line.trim() !== "")
|
|
117
|
+
.join(`\n${" ".repeat(indent)}`);
|
|
114
118
|
}
|
|
115
119
|
if (i < keys.length - 1) {
|
|
116
120
|
result += ", ";
|
|
117
121
|
}
|
|
118
122
|
}
|
|
119
|
-
result += "}
|
|
123
|
+
result += `\n${" ".repeat(indent - 1)}}`;
|
|
120
124
|
return result;
|
|
121
125
|
};
|
|
122
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\`\`\``;
|
|
132
|
+
};
|
|
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
|
+
}
|