Jaycean commented on a change in pull request #1245:
URL: https://github.com/apache/apisix-dashboard/pull/1245#discussion_r556280298



##########
File path: api/internal/handler/route_export/route_export.go
##########
@@ -0,0 +1,298 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package route_export
+
+import (
+       "encoding/json"
+       "reflect"
+       "regexp"
+       "strings"
+
+       "github.com/apisix/manager-api/internal/core/entity"
+       "github.com/apisix/manager-api/internal/core/store"
+       "github.com/apisix/manager-api/internal/handler"
+       "github.com/apisix/manager-api/internal/log"
+       "github.com/getkin/kin-openapi/openapi3"
+       "github.com/gin-gonic/gin"
+       "github.com/shiningrush/droplet"
+       "github.com/shiningrush/droplet/wrapper"
+       wgin "github.com/shiningrush/droplet/wrapper/gin"
+)
+
+type Handler struct {
+       routeStore store.Interface
+}
+
+func NewHandler() (handler.RouteRegister, error) {
+       return &Handler{
+               routeStore: store.GetStore(store.HubKeyRoute),
+       }, nil
+}
+
+func (h *Handler) ApplyRoute(r *gin.Engine) {
+       r.POST("/apisix/admin/routes/export/:ids", wgin.Wraps(h.ExportRoutes,
+               wrapper.InputType(reflect.TypeOf(ExportInput{}))))
+}
+
+type ExportInput struct {
+       IDs string `auto_read:"ids,path"`
+}
+
+func (h *Handler) ExportRoutes(c droplet.Context) (interface{}, error) {
+       input := c.Input().(*ExportInput)
+       ids := strings.Split(input.IDs, ",")
+       routes := []*entity.Route{}
+       for _, id := range ids {
+               route, err := h.routeStore.Get(id)
+               if err != nil {
+                       return nil, err
+               }
+               routes = append(routes, route.(*entity.Route))
+       }
+       return routeToOpenApi3(routes), nil
+}
+
+type AuthType string
+
+const (
+       BasicAuth AuthType = "basic-auth"
+       KeyAuth   AuthType = "key-auth"
+       JWTAuth   AuthType = "jwt-auth"
+)
+
+var (
+       openApi = "3.0.0"
+       title   = "Routes Export"
+)
+
+func routeToOpenApi3(routes []*entity.Route) *openapi3.Swagger {
+       paths := openapi3.Paths{}
+       pathItem := &openapi3.PathItem{}
+       path := openapi3.Operation{}
+       paramsRefs := []*openapi3.ParameterRef{}
+       requestBody := &openapi3.RequestBody{}
+       components := &openapi3.Components{}
+       secSchemas := openapi3.SecuritySchemes{}
+       for _, route := range routes {
+               extensions := make(map[string]interface{})
+               path.Summary = route.Desc
+               path.OperationID = route.Name
+               if route.Upstream != nil {
+                       extensions["x-apisix-upstream"] = route.Upstream
+               }
+               if route.Host != "" {
+                       extensions["x-apisix-host"] = route.Host
+               }
+               if route.Hosts != nil {
+                       extensions["x-apisix-hosts"] = route.Hosts
+               }
+               if route.Labels != nil {
+                       extensions["x-apisix-labels"] = route.Labels
+               }
+               if route.RemoteAddr != "" {
+                       extensions["x-apisix-remoteAddr"] = route.RemoteAddr
+               }
+               if route.RemoteAddrs != nil {
+                       extensions["x-apisix-remoteAddrs"] = route.RemoteAddrs
+               }
+               if route.FilterFunc != "" {
+                       extensions["x-apisix-filterFunc"] = route.FilterFunc
+               }
+               if route.ServiceID != nil {
+                       extensions["x-apisix-serviceID"] = route.ServiceID
+               }
+               if route.UpstreamID != nil {
+                       extensions["x-apisix-upstreamID"] = route.UpstreamID
+               }

Review comment:
       There is a problem here. I'll modify the code and reprocess the data of 
upstream and plugin.




----------------------------------------------------------------
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:
[email protected]


Reply via email to