You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by GitBox <gi...@apache.org> on 2020/09/18 00:51:40 UTC

[GitHub] [apisix-dashboard] juzhiyuan commented on a change in pull request #485: feat: Route debug

juzhiyuan commented on a change in pull request #485:
URL: https://github.com/apache/apisix-dashboard/pull/485#discussion_r490637289



##########
File path: src/pages/Route/transform.ts
##########
@@ -252,3 +252,131 @@ export const transformRouteData = (data: RouteModule.Body) => {
     step3Data,
   };
 };
+
+export const transformRouteDebugData = (data: RouteModule.Body) => {
+  const {
+    name,
+    desc,
+    methods,
+    uris,
+    protocols,
+    // hosts,
+    vars,
+    // redirect,
+    url,
+  } = data;
+
+  const paths = {};
+  const tags: RouteModule.TagSchema[] = [
+    {
+      name: `Route-${name}`,
+      description: desc,
+    },
+  ];
+  const servers: RouteModule.Server[] = [];
+  const responses: RouteModule.ResponseSchema = {
+    // default response code
+    '200': {
+      description: 'successful operation',
+      content: {},
+    },
+    '400': {
+      description: 'Invalid parameter',
+      content: {},
+    },
+    '500': {
+      description: 'Internal Server Error',
+      content: {},
+    },
+  };
+  const params = transformVarsToRules(vars);
+  const formatParams = params.map((param) => {
+    const { position, operator } = param;
+    let paramPostion;
+
+    switch (position) {
+      case 'cookie':
+        paramPostion = 'cookie';
+        break;
+      case 'http':
+        paramPostion = 'header';
+        break;
+      case 'arg':
+        paramPostion = 'query';
+        break;
+      default:
+        break;
+    }
+    return {
+      name: param.name,
+      in: paramPostion,
+      description: `default value should ${operator} ${param.value}`,
+      required: true,
+      type: 'string',
+    };
+  });
+  const pathParams = {
+    name: 'pathParam',
+    in: 'path',
+    description: `enter your path param`,
+    required: true,
+    type: 'string',
+  };
+  const requestBodyMethod = ['POST', 'PUT', 'PATCH'];
+
+  protocols.forEach((protocol) => {
+    if (protocol !== 'websocket') {
+      servers.push({

Review comment:
       `push` will take some side effects, we would recommend using `concat` instead of `push`

##########
File path: src/pages/Route/transform.ts
##########
@@ -252,3 +252,131 @@ export const transformRouteData = (data: RouteModule.Body) => {
     step3Data,
   };
 };
+
+export const transformRouteDebugData = (data: RouteModule.Body) => {
+  const {
+    name,
+    desc,
+    methods,
+    uris,
+    protocols,
+    // hosts,
+    vars,
+    // redirect,
+    url,
+  } = data;
+
+  const paths = {};
+  const tags: RouteModule.TagSchema[] = [
+    {
+      name: `Route-${name}`,
+      description: desc,
+    },
+  ];
+  const servers: RouteModule.Server[] = [];
+  const responses: RouteModule.ResponseSchema = {
+    // default response code
+    '200': {
+      description: 'successful operation',
+      content: {},
+    },
+    '400': {
+      description: 'Invalid parameter',
+      content: {},
+    },
+    '500': {
+      description: 'Internal Server Error',
+      content: {},
+    },
+  };
+  const params = transformVarsToRules(vars);
+  const formatParams = params.map((param) => {
+    const { position, operator } = param;
+    let paramPostion;
+
+    switch (position) {
+      case 'cookie':
+        paramPostion = 'cookie';
+        break;
+      case 'http':
+        paramPostion = 'header';
+        break;
+      case 'arg':
+        paramPostion = 'query';
+        break;
+      default:
+        break;
+    }
+    return {
+      name: param.name,
+      in: paramPostion,
+      description: `default value should ${operator} ${param.value}`,
+      required: true,
+      type: 'string',
+    };
+  });
+  const pathParams = {
+    name: 'pathParam',
+    in: 'path',
+    description: `enter your path param`,
+    required: true,
+    type: 'string',
+  };
+  const requestBodyMethod = ['POST', 'PUT', 'PATCH'];
+
+  protocols.forEach((protocol) => {
+    if (protocol !== 'websocket') {
+      servers.push({
+        url: `${protocol}://${url}`,
+      });
+      // FIXME

Review comment:
       what happened here?

##########
File path: src/pages/Route/transform.ts
##########
@@ -252,3 +252,131 @@ export const transformRouteData = (data: RouteModule.Body) => {
     step3Data,
   };
 };
+
+export const transformRouteDebugData = (data: RouteModule.Body) => {
+  const {
+    name,
+    desc,
+    methods,
+    uris,
+    protocols,
+    // hosts,
+    vars,
+    // redirect,
+    url,
+  } = data;
+
+  const paths = {};
+  const tags: RouteModule.TagSchema[] = [
+    {
+      name: `Route-${name}`,
+      description: desc,
+    },
+  ];
+  const servers: RouteModule.Server[] = [];
+  const responses: RouteModule.ResponseSchema = {
+    // default response code
+    '200': {

Review comment:
       could we use `ok` here? https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/200

##########
File path: src/pages/Route/typing.d.ts
##########
@@ -157,5 +157,70 @@ declare namespace RouteModule {
       [name: string]: any;
     };
     script: Record<string, any>;
+    url?: string;
+  };
+
+  // for route debug
+  interface Server {

Review comment:
       please use `type` instead of `interface` to prevent from type override :D

##########
File path: api/route/route.go
##########
@@ -480,6 +482,58 @@ func findRoute(c *gin.Context) {
 	}
 }
 
+func getRouteAndApisixUrl(c *gin.Context) {

Review comment:
       could we use camelCase here? e.g `getRouteWithAPISIXURL` .




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org