Browse Source

fix(grpcgw): make sure grpc gw generated fields in original case

GRPC Gateway after upgrade started to generate field names in camelCase.
Mustafa ARICI 4 years ago
parent
commit
2197e9a44c
6 changed files with 60 additions and 51 deletions
  1. 1 1
      Makefile
  2. 13 13
      api/pb/auth.swagger.json
  3. 3 3
      api/pb/network.swagger.json
  4. 19 19
      api/pb/user.swagger.json
  5. 14 14
      api/pb/vpn.swagger.json
  6. 10 1
      api/rest.go

+ 1 - 1
Makefile

@@ -25,7 +25,7 @@ bundle-webui:
 	cp -r webui/ovpm/build/* bundle
 
 bundle-swagger: proto
-	protoc -I./api/pb -I/usr/local/include/ --openapiv2_out=./api/pb --openapiv2_opt logtostderr=true user.proto vpn.proto network.proto auth.proto
+	protoc -I./api/pb -I/usr/local/include/ --openapiv2_out=json_names_for_fields=false:./api/pb --openapiv2_opt logtostderr=true user.proto vpn.proto network.proto auth.proto
 
 bundle: clean-bundle bundle-webui bundle-swagger
 	go-bindata -pkg bundle -o bundle/bindata.go bundle/...

+ 13 - 13
api/pb/auth.swagger.json

@@ -78,43 +78,43 @@
         "username": {
           "type": "string"
         },
-        "serverSerialNumber": {
+        "server_serial_number": {
           "type": "string"
         },
         "cert": {
           "type": "string"
         },
-        "createdAt": {
+        "created_at": {
           "type": "string"
         },
-        "ipNet": {
+        "ip_net": {
           "type": "string"
         },
-        "noGw": {
+        "no_gw": {
           "type": "boolean"
         },
-        "hostId": {
+        "host_id": {
           "type": "integer",
           "format": "int64"
         },
-        "isAdmin": {
+        "is_admin": {
           "type": "boolean"
         },
-        "isConnected": {
+        "is_connected": {
           "type": "boolean"
         },
-        "connectedSince": {
+        "connected_since": {
           "type": "string"
         },
-        "bytesSent": {
+        "bytes_sent": {
           "type": "string",
           "format": "uint64"
         },
-        "bytesReceived": {
+        "bytes_received": {
           "type": "string",
           "format": "uint64"
         },
-        "expiresAt": {
+        "expires_at": {
           "type": "string"
         },
         "description": {
@@ -147,7 +147,7 @@
         "user": {
           "$ref": "#/definitions/UserResponseUser"
         },
-        "isRoot": {
+        "is_root": {
           "type": "boolean"
         }
       }
@@ -155,7 +155,7 @@
     "protobufAny": {
       "type": "object",
       "properties": {
-        "typeUrl": {
+        "type_url": {
           "type": "string"
         },
         "value": {

+ 3 - 3
api/pb/network.swagger.json

@@ -232,10 +232,10 @@
         "type": {
           "type": "string"
         },
-        "createdAt": {
+        "created_at": {
           "type": "string"
         },
-        "associatedUsernames": {
+        "associated_usernames": {
           "type": "array",
           "items": {
             "type": "string"
@@ -362,7 +362,7 @@
     "protobufAny": {
       "type": "object",
       "properties": {
-        "typeUrl": {
+        "type_url": {
           "type": "string"
         },
         "value": {

+ 19 - 19
api/pb/user.swagger.json

@@ -206,43 +206,43 @@
         "username": {
           "type": "string"
         },
-        "serverSerialNumber": {
+        "server_serial_number": {
           "type": "string"
         },
         "cert": {
           "type": "string"
         },
-        "createdAt": {
+        "created_at": {
           "type": "string"
         },
-        "ipNet": {
+        "ip_net": {
           "type": "string"
         },
-        "noGw": {
+        "no_gw": {
           "type": "boolean"
         },
-        "hostId": {
+        "host_id": {
           "type": "integer",
           "format": "int64"
         },
-        "isAdmin": {
+        "is_admin": {
           "type": "boolean"
         },
-        "isConnected": {
+        "is_connected": {
           "type": "boolean"
         },
-        "connectedSince": {
+        "connected_since": {
           "type": "string"
         },
-        "bytesSent": {
+        "bytes_sent": {
           "type": "string",
           "format": "uint64"
         },
-        "bytesReceived": {
+        "bytes_received": {
           "type": "string",
           "format": "uint64"
         },
-        "expiresAt": {
+        "expires_at": {
           "type": "string"
         },
         "description": {
@@ -286,14 +286,14 @@
         "password": {
           "type": "string"
         },
-        "noGw": {
+        "no_gw": {
           "type": "boolean"
         },
-        "hostId": {
+        "host_id": {
           "type": "integer",
           "format": "int64"
         },
-        "isAdmin": {
+        "is_admin": {
           "type": "boolean"
         },
         "description": {
@@ -320,7 +320,7 @@
     "pbUserGenConfigResponse": {
       "type": "object",
       "properties": {
-        "clientConfig": {
+        "client_config": {
           "type": "string"
         }
       }
@@ -356,14 +356,14 @@
         "gwpref": {
           "$ref": "#/definitions/UserUpdateRequestGWPref"
         },
-        "hostId": {
+        "host_id": {
           "type": "integer",
           "format": "int64"
         },
-        "staticPref": {
+        "static_pref": {
           "$ref": "#/definitions/UserUpdateRequestStaticPref"
         },
-        "adminPref": {
+        "admin_pref": {
           "$ref": "#/definitions/UserUpdateRequestAdminPref"
         },
         "description": {
@@ -374,7 +374,7 @@
     "protobufAny": {
       "type": "object",
       "properties": {
-        "typeUrl": {
+        "type_url": {
           "type": "string"
         },
         "value": {

+ 14 - 14
api/pb/vpn.swagger.json

@@ -135,22 +135,22 @@
         "port": {
           "type": "string"
         },
-        "protoPref": {
+        "proto_pref": {
           "$ref": "#/definitions/pbVPNProto"
         },
-        "ipBlock": {
+        "ip_block": {
           "type": "string"
         },
         "dns": {
           "type": "string"
         },
-        "keepalivePeriod": {
+        "keepalive_period": {
           "type": "string"
         },
-        "keepaliveTimeout": {
+        "keepalive_timeout": {
           "type": "string"
         },
-        "useLzo": {
+        "use_lzo": {
           "type": "boolean"
         }
       }
@@ -185,7 +185,7 @@
         "name": {
           "type": "string"
         },
-        "serialNumber": {
+        "serial_number": {
           "type": "string"
         },
         "hostname": {
@@ -197,7 +197,7 @@
         "cert": {
           "type": "string"
         },
-        "caCert": {
+        "ca_cert": {
           "type": "string"
         },
         "net": {
@@ -206,7 +206,7 @@
         "mask": {
           "type": "string"
         },
-        "createdAt": {
+        "created_at": {
           "type": "string"
         },
         "proto": {
@@ -215,13 +215,13 @@
         "dns": {
           "type": "string"
         },
-        "expiresAt": {
+        "expires_at": {
           "type": "string"
         },
-        "caExpiresAt": {
+        "ca_expires_at": {
           "type": "string"
         },
-        "useLzo": {
+        "use_lzo": {
           "type": "boolean"
         }
       }
@@ -229,13 +229,13 @@
     "pbVPNUpdateRequest": {
       "type": "object",
       "properties": {
-        "ipBlock": {
+        "ip_block": {
           "type": "string"
         },
         "dns": {
           "type": "string"
         },
-        "lzoPref": {
+        "lzo_pref": {
           "$ref": "#/definitions/pbVPNLZOPref"
         }
       }
@@ -246,7 +246,7 @@
     "protobufAny": {
       "type": "object",
       "properties": {
-        "typeUrl": {
+        "type_url": {
           "type": "string"
         },
         "value": {

+ 10 - 1
api/rest.go

@@ -2,6 +2,7 @@ package api
 
 import (
 	"fmt"
+	"google.golang.org/protobuf/encoding/protojson"
 	"net/http"
 	"strings"
 
@@ -26,7 +27,15 @@ func NewRESTServer(grpcPort string) (http.Handler, context.CancelFunc, error) {
 	}
 	endPoint := fmt.Sprintf("localhost:%s", grpcPort)
 	ctx = NewOriginTypeContext(ctx, OriginTypeREST)
-	gmux := runtime.NewServeMux(runtime.WithMarshalerOption(runtime.MIMEWildcard, &runtime.JSONPb{}))
+	gmux := runtime.NewServeMux(runtime.WithMarshalerOption(runtime.MIMEWildcard, &runtime.JSONPb{
+		MarshalOptions: protojson.MarshalOptions{
+			UseProtoNames:   true,
+			EmitUnpopulated: true,
+		},
+		UnmarshalOptions: protojson.UnmarshalOptions{
+			DiscardUnknown: true,
+		},
+	}))
 	opts := []grpc.DialOption{grpc.WithInsecure()}
 	err := pb.RegisterVPNServiceHandlerFromEndpoint(ctx, gmux, endPoint, opts)
 	if err != nil {