Skip to content

Commit b7e9ff2

Browse files
committed
Enhance documentation generation with parameter details and return types for GLS functions
1 parent 4974033 commit b7e9ff2

4 files changed

Lines changed: 375 additions & 7 deletions

File tree

actions/gls-action/scripts/generateDocs.ts

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,54 @@ interface FunctionDefinition {
255255
}
256256

257257
async function generateFunctions(sdk: ActionSdk): Promise<string> {
258+
function getParamInfo(signature: string, paramName: string): { optional: boolean; type: string | null } {
259+
const paramsMatch = signature.match(/\((.*)\)/s);
260+
if (!paramsMatch) {
261+
return {optional: false, type: null};
262+
}
263+
264+
const params = paramsMatch[1].split(",");
265+
266+
for (const param of params) {
267+
const trimmed = param.trim();
268+
269+
// Match: name?: type OR name: type
270+
const match = trimmed.match(new RegExp(`${paramName}\s*(\\?)?\\s*:\\s*(.+)`));
271+
if (match) {
272+
const isOptional = match[1] === "?";
273+
const type = match[2].trim();
274+
275+
return {
276+
optional: isOptional,
277+
type
278+
};
279+
}
280+
}
281+
282+
return {optional: false, type: null};
283+
}
284+
285+
function generateMarkdownTable(headers: string[], rows: string[][]) {
286+
const headerRow = `| ${headers.join(' | ')} |`;
287+
const separator = `| ${headers.map(() => '---').join(' | ')} |`;
288+
const bodyRows = rows.map(row => `| ${row.join(' | ')} |`);
289+
290+
return [headerRow, separator, ...bodyRows].join('\n');
291+
}
292+
function getLinkFromType(typeName?: string) {
293+
if (!typeName || !typeName.startsWith("GLS_")) return typeName
294+
switch (typeName) { // Some edge cases
295+
case "SHIPMENT_UNIT_SERVICE": {
296+
typeName = "SHIPMENT_UNIT$Service"
297+
break
298+
}
299+
}
300+
const normalizedName = typeName.toLowerCase()
301+
.replace(/-/g, "_")
302+
.replace(/\$/g, "");
303+
return `[${typeName}](./types.mdx#${normalizedName})`
304+
}
305+
258306
async function loadFunctions(modules: Record<string, () => Promise<unknown>>) {
259307
for (const path in modules) {
260308

@@ -343,9 +391,33 @@ All shipment functions accept a common set of parameters in addition to their ty
343391
displayMessages: definition.displayMessage
344392
}
345393

394+
const headers = ["Parameter", "Name", "Type", "Required", "Description"]
395+
396+
let rows = []
397+
398+
definition.parameters.forEach(param => {
399+
const paramInfo = getParamInfo(definition.signature, param.runtimeName);
400+
401+
paramInfo.type = getLinkFromType(paramInfo.type);
402+
403+
rows.push([
404+
param.runtimeName,
405+
param.name[0].content,
406+
paramInfo.type?.replace(/\|/g, "\\|") || "Unknown",
407+
paramInfo.optional ? "No" : "Yes",
408+
param.description[0].content
409+
])
410+
})
411+
346412
generatedDoc += `
347413
### \`${definition.runtimeName}\`
348414
415+
${generateMarkdownTable(headers, rows)}
416+
417+
Return Type: ${getLinkFromType(definition.signature.split("):")[1].trim())}
418+
419+
#
420+
349421
${definition.documentation?.at(0).content || ""}
350422
351423
<FunctionCard definition={

actions/gls-action/src/functions/services/createShopReturnShipment.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,17 +42,17 @@ export default (sdk: ActionSdk) => {
4242
signature: `(numberOfLabels: number, ${DEFAULT_SIGNATURE_FOR_SERVICES}, returnQR: "PDF" | "PNG" | "ZPL"): GLS_CREATE_PARCELS_RESPONSE`,
4343
parameters: [
4444
{
45-
runtimeName: "parcelShopId",
45+
runtimeName: "numberOfLabels",
4646
name: [
4747
{
4848
code: "en-US",
49-
content: "Parcel shop Id",
49+
content: "The number of labels",
5050
}
5151
],
5252
description: [
5353
{
5454
code: "en-US",
55-
content: "The ID of the parcel shop where the shipment should be delivered.",
55+
content: "The number of labels to be created for the return shipment.",
5656
}
5757
]
5858
},

actions/gls-action/src/functions/utils/createAddress.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export default (sdk: ActionSdk) => {
1818
content: "Create address"
1919
}
2020
],
21-
signature: "Name1: string, CountryCode: string, City: string, Street: string, ZIPCode: string, Name2?: string, Name3?: string, Province?: string, StreetNumber?: string, ContactPerson?: string, FixedLinePhonenumber?: string, MobilePhonenumber?: string, Email?: string): GLS_ADDRESS",
21+
signature: "(Name1: string, CountryCode: string, City: string, Street: string, ZIPCode: string, Name2?: string, Name3?: string, Province?: string, StreetNumber?: string, ContactPerson?: string, FixedLinePhonenumber?: string, MobilePhonenumber?: string, Email?: string): GLS_ADDRESS",
2222
name: [
2323
{
2424
code: "en-US",

0 commit comments

Comments
 (0)