mirror of
https://github.com/Azure/cosmos-explorer.git
synced 2025-12-22 02:11:29 +00:00
Setup Namespaces
This commit is contained in:
@@ -1,9 +1,12 @@
|
|||||||
/// <reference types="node" />
|
/// <reference types="node" />
|
||||||
|
|
||||||
const { writeFileSync } = require("fs");
|
const { writeFileSync } = require("fs");
|
||||||
const schema = require("./schema.json");
|
const schema = require("./schema.json");
|
||||||
|
|
||||||
const file: string[] = [""];
|
const file: string[] = [""];
|
||||||
|
|
||||||
|
const namespaces: { [key: string]: string[] } = {};
|
||||||
|
|
||||||
const propertyMap: { [key: string]: string } = {
|
const propertyMap: { [key: string]: string } = {
|
||||||
integer: "number"
|
integer: "number"
|
||||||
};
|
};
|
||||||
@@ -16,6 +19,14 @@ function refToType(path: string | undefined) {
|
|||||||
return "unknown";
|
return "unknown";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function camelize(str: string) {
|
||||||
|
return str
|
||||||
|
.replace(/(?:^\w|[A-Z]|\b\w)/g, function(word: any, index: any) {
|
||||||
|
return index === 0 ? word.toLowerCase() : word.toUpperCase();
|
||||||
|
})
|
||||||
|
.replace(/\s+/g, "");
|
||||||
|
}
|
||||||
|
|
||||||
function bodyParam(parameter: any) {
|
function bodyParam(parameter: any) {
|
||||||
if (!parameter) {
|
if (!parameter) {
|
||||||
return "";
|
return "";
|
||||||
@@ -131,9 +142,13 @@ async function main() {
|
|||||||
const bodyParameter = operation.parameters.find(
|
const bodyParameter = operation.parameters.find(
|
||||||
(parameter: any) => parameter.in === "body" && parameter.required === true
|
(parameter: any) => parameter.in === "body" && parameter.required === true
|
||||||
);
|
);
|
||||||
file.push(`
|
const [namespace, operationName] = operation.operationId.split("_");
|
||||||
|
if (namespaces[namespace] === undefined) {
|
||||||
|
namespaces[namespace] = [];
|
||||||
|
}
|
||||||
|
namespaces[namespace].push(`
|
||||||
/* ${operation.description} */
|
/* ${operation.description} */
|
||||||
export async function ${operation.operationId} (
|
async ${camelize(operationName)} (
|
||||||
${parametersFromPath(path)}
|
${parametersFromPath(path)}
|
||||||
${bodyParam(bodyParameter)}
|
${bodyParam(bodyParameter)}
|
||||||
) : Promise<${responseType(operation)}> {
|
) : Promise<${responseType(operation)}> {
|
||||||
@@ -145,6 +160,12 @@ async function main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (const namespace in namespaces) {
|
||||||
|
file.push(`export const ${namespace} = {`);
|
||||||
|
file.push(namespaces[namespace].join(",\n"));
|
||||||
|
file.push(`}\n`);
|
||||||
|
}
|
||||||
|
|
||||||
writeFileSync("./models.ts", file.join(""));
|
writeFileSync("./models.ts", file.join(""));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user