moleculer-auto-openapi icon indicating copy to clipboard operation
moleculer-auto-openapi copied to clipboard

Module can't handle middleware aliases with no endpoint

Open cintolas opened this issue 2 years ago • 0 comments

The doc compiler will fail with the following route

aliases: { "GET /": [ (req, res) => { if(req.token) { res.redirect("./session"); return; } res.redirect("./auth"); } ],

The issue is the array has no final endpoint. Everything is done in the middleware

Is there a way around this? Currently, the UI will simply crash and fail

It fails in the following function

` buildActionRouteStructFromAliases(route, routes) { for (const alias in route.aliases) { const aliasInfo = route.aliases[alias]; let actionType = aliasInfo.type;

    let action = "";
    if (aliasInfo.action) {
      action = aliasInfo.action;
    } else if (Array.isArray(aliasInfo)) {
      action = aliasInfo[aliasInfo.length - 1]
    } else if (typeof aliasInfo !== "string") {
      action = UNRESOLVED_ACTION_NAME;
    } else {
      action = aliasInfo;
    }


   /**** FAILS HERE SINCE ACTION IS A FUNCTION, NOT A STRING *****/
  /**** WORKAROUND, IGNORE IT ****/
  // if(typeof action !== "string")
  //      continue;
  /***** END WORKAROUND *********/


    // support actions like multipart:import.proceedFile
    if (action.includes(":")) {
      ([actionType, action] = action.split(":"));
    }

    if (!routes[action]) {
      routes[action] = {
        actionType,
        params: {},
        paths: [],
        openapi: null,
      };
    }

    routes[action].paths.push({
      base: route.path || "",
      alias,
      autoAliases: route.autoAliases,
      openapi: aliasInfo.openapi || null,
    });
  }

`

cintolas avatar Nov 29 '23 01:11 cintolas