From c62f4c2daaefc8932d155e3602d30d01cf22aeb4 Mon Sep 17 00:00:00 2001 From: Joel Bryan Juliano Date: Tue, 17 Sep 2024 22:42:09 +0200 Subject: [PATCH] simplify api server request template by using Dynamic maps --- deps/pkl/APIServerRequest.pkl | 22 +++---------------- .../APIServerRequest.pkl.go | 8 +++---- .../APIServerRequestData.pkl.go | 10 --------- .../APIServerRequestHeader.pkl.go | 8 ------- .../APIServerRequestParams.pkl.go | 8 ------- gen/api_server_request/init.pkl.go | 3 --- 6 files changed, 7 insertions(+), 52 deletions(-) delete mode 100644 gen/api_server_request/APIServerRequestData.pkl.go delete mode 100644 gen/api_server_request/APIServerRequestHeader.pkl.go delete mode 100644 gen/api_server_request/APIServerRequestParams.pkl.go diff --git a/deps/pkl/APIServerRequest.pkl b/deps/pkl/APIServerRequest.pkl index 969c3f9..12e831e 100644 --- a/deps/pkl/APIServerRequest.pkl +++ b/deps/pkl/APIServerRequest.pkl @@ -4,22 +4,6 @@ module org.kdeps.pkl.APIServerRequest import "package://pkg.pkl-lang.org/pkl-go/pkl.golang@0.5.0#/go.pkl" -class APIServerRequestParams { - name: String - value: String -} - -class APIServerRequestData { - name: String - type: String - value: Any -} - -class APIServerRequestHeader { - name: String - value: Any -} - hidden apiMethodRegex = Regex(#"^(?i:(GET|POST|PUT|PATCH|DELETE|HEAD))"#) hidden isValidHTTPMethod = (str) -> if (str.matches(apiMethodRegex)) @@ -28,7 +12,7 @@ hidden isValidHTTPMethod = (str) -> throw("Error: Invalid HTTP method. The provided HTTP method is not supported. Please use one of the following methods: GET, POST, PUT, PATCH, DELETE, or HEAD.") url: Uri -data: Listing? method: String(isValidHTTPMethod) -params: Listing? -headers: Listing? +data: String? +params: Mapping? +headers: Mapping? diff --git a/gen/api_server_request/APIServerRequest.pkl.go b/gen/api_server_request/APIServerRequest.pkl.go index cbf01ff..899cf2c 100644 --- a/gen/api_server_request/APIServerRequest.pkl.go +++ b/gen/api_server_request/APIServerRequest.pkl.go @@ -10,13 +10,13 @@ import ( type APIServerRequest struct { Url string `pkl:"url"` - Data *[]*APIServerRequestData `pkl:"data"` - Method string `pkl:"method"` - Params *[]*APIServerRequestParams `pkl:"params"` + Data *string `pkl:"data"` + + Params *map[string]string `pkl:"params"` - Headers *[]*APIServerRequestHeader `pkl:"headers"` + Headers *map[string]string `pkl:"headers"` } // LoadFromPath loads the pkl module at the given path and evaluates it into a APIServerRequest diff --git a/gen/api_server_request/APIServerRequestData.pkl.go b/gen/api_server_request/APIServerRequestData.pkl.go deleted file mode 100644 index 61c0397..0000000 --- a/gen/api_server_request/APIServerRequestData.pkl.go +++ /dev/null @@ -1,10 +0,0 @@ -// Code generated from Pkl module `org.kdeps.pkl.APIServerRequest`. DO NOT EDIT. -package apiserverrequest - -type APIServerRequestData struct { - Name string `pkl:"name"` - - Type string `pkl:"type"` - - Value any `pkl:"value"` -} diff --git a/gen/api_server_request/APIServerRequestHeader.pkl.go b/gen/api_server_request/APIServerRequestHeader.pkl.go deleted file mode 100644 index 02e3179..0000000 --- a/gen/api_server_request/APIServerRequestHeader.pkl.go +++ /dev/null @@ -1,8 +0,0 @@ -// Code generated from Pkl module `org.kdeps.pkl.APIServerRequest`. DO NOT EDIT. -package apiserverrequest - -type APIServerRequestHeader struct { - Name string `pkl:"name"` - - Value any `pkl:"value"` -} diff --git a/gen/api_server_request/APIServerRequestParams.pkl.go b/gen/api_server_request/APIServerRequestParams.pkl.go deleted file mode 100644 index 819f2e3..0000000 --- a/gen/api_server_request/APIServerRequestParams.pkl.go +++ /dev/null @@ -1,8 +0,0 @@ -// Code generated from Pkl module `org.kdeps.pkl.APIServerRequest`. DO NOT EDIT. -package apiserverrequest - -type APIServerRequestParams struct { - Name string `pkl:"name"` - - Value string `pkl:"value"` -} diff --git a/gen/api_server_request/init.pkl.go b/gen/api_server_request/init.pkl.go index ef167af..7f3f416 100644 --- a/gen/api_server_request/init.pkl.go +++ b/gen/api_server_request/init.pkl.go @@ -5,7 +5,4 @@ import "github.com/apple/pkl-go/pkl" func init() { pkl.RegisterMapping("org.kdeps.pkl.APIServerRequest", APIServerRequest{}) - pkl.RegisterMapping("org.kdeps.pkl.APIServerRequest#APIServerRequestData", APIServerRequestData{}) - pkl.RegisterMapping("org.kdeps.pkl.APIServerRequest#APIServerRequestParams", APIServerRequestParams{}) - pkl.RegisterMapping("org.kdeps.pkl.APIServerRequest#APIServerRequestHeader", APIServerRequestHeader{}) }