fix: #674 Use JSON options for API handler
Some checks failed
Build & Release pipeline / build (push) Has been cancelled
DevSkim / DevSkim (push) Has been cancelled

This commit is contained in:
jamesread
2025-10-27 20:40:15 +00:00
parent d54f2307c7
commit 6c6d07bf4f
3 changed files with 15 additions and 1 deletions

View File

@@ -127,6 +127,7 @@ require (
github.com/stoewer/go-strcase v1.3.1 // indirect
github.com/tetratelabs/wazero v1.9.0 // indirect
github.com/vbatts/tar-split v0.12.1 // indirect
go.akshayshah.org/connectproto v0.6.0 // indirect
go.lsp.dev/jsonrpc2 v0.10.0 // indirect
go.lsp.dev/pkg v0.0.0-20210717090340-384b27a52fb2 // indirect
go.lsp.dev/protocol v0.12.0 // indirect

View File

@@ -262,6 +262,8 @@ github.com/vbatts/tar-split v0.12.1/go.mod h1:eF6B6i6ftWQcDqEn3/iGFRFRo8cBIMSJVO
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
go.akshayshah.org/connectproto v0.6.0 h1:tqmysQF2AfvUeYS03mRAAZTFpiQeXqhGIDnH1GO2D2U=
go.akshayshah.org/connectproto v0.6.0/go.mod h1:uA9TR/6MhBlLn0fh8VXRyL26EKTJlimWao4jbz7JHbA=
go.lsp.dev/jsonrpc2 v0.10.0 h1:Pr/YcXJoEOTMc/b6OTmcR1DPJ3mSWl/SWiU1Cct6VmI=
go.lsp.dev/jsonrpc2 v0.10.0/go.mod h1:fmEzIdXPi/rf6d4uFcayi8HpFP1nBF99ERP1htC72Ac=
go.lsp.dev/pkg v0.0.0-20210717090340-384b27a52fb2 h1:hCzQgh6UcwbKgNSRurYWSqh8MufqRRPODRBblutn4TE=

View File

@@ -5,6 +5,7 @@ import (
"encoding/json"
"connectrpc.com/connect"
"google.golang.org/protobuf/encoding/protojson"
apiv1 "github.com/OliveTin/OliveTin/gen/olivetin/api/v1"
apiv1connect "github.com/OliveTin/OliveTin/gen/olivetin/api/v1/apiv1connect"
@@ -20,6 +21,7 @@ import (
entities "github.com/OliveTin/OliveTin/internal/entities"
executor "github.com/OliveTin/OliveTin/internal/executor"
installationinfo "github.com/OliveTin/OliveTin/internal/installationinfo"
connectproto "go.akshayshah.org/connectproto"
)
type oliveTinAPI struct {
@@ -870,5 +872,14 @@ func newServer(ex *executor.Executor) *oliveTinAPI {
func GetNewHandler(ex *executor.Executor) (string, http.Handler) {
server := newServer(ex)
return apiv1connect.NewOliveTinApiServiceHandler(server)
jsonOpt := connectproto.WithJSON(
protojson.MarshalOptions{
EmitUnpopulated: true, // https://github.com/OliveTin/OliveTin/issues/674
},
protojson.UnmarshalOptions{
DiscardUnknown: true,
},
)
return apiv1connect.NewOliveTinApiServiceHandler(server, jsonOpt)
}