Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
8876104
fix test using random free port for dashboard API
marle3003 Nov 11, 2025
ff01fbe
add API title to HTTP event request parameter
marle3003 Nov 12, 2025
df12510
improve lock mechanism in JavaScript
marle3003 Nov 12, 2025
d8e9f3e
fix tests
marle3003 Nov 12, 2025
0cc96d2
fix faker
marle3003 Nov 12, 2025
3fe7d1f
add missing function
marle3003 Nov 12, 2025
0807e7e
add API link to HTTP request view
marle3003 Nov 12, 2025
e95319a
fix sorting parameters
marle3003 Nov 13, 2025
bb915ee
fix sorting parameters
marle3003 Nov 13, 2025
58919d6
Bump github.com/blevesearch/bleve_index_api from 1.2.10 to 1.2.11
dependabot[bot] Nov 14, 2025
0662e0d
Bump vue from 3.5.23 to 3.5.24 in /webui
dependabot[bot] Nov 14, 2025
fba0914
Merge pull request #745 from marle3003/dependabot/npm_and_yarn/webui/…
github-actions[bot] Nov 14, 2025
3c85c54
Bump js-yaml from 4.1.0 to 4.1.1 in /webui
dependabot[bot] Nov 14, 2025
8b26479
Merge pull request #747 from marle3003/dependabot/npm_and_yarn/webui/…
github-actions[bot] Nov 14, 2025
34878df
Bump @types/node from 24.10.0 to 24.10.1 in /webui
dependabot[bot] Nov 14, 2025
a484550
Merge pull request #746 from marle3003/dependabot/npm_and_yarn/webui/…
github-actions[bot] Nov 14, 2025
b2d4fa9
Bump @rushstack/eslint-patch from 1.14.1 to 1.15.0 in /webui
dependabot[bot] Nov 14, 2025
e1a6d78
Merge pull request #744 from marle3003/dependabot/npm_and_yarn/webui/…
github-actions[bot] Nov 14, 2025
98c1376
Improve JavaScript handling for HTTP responses and shared values
marle3003 Nov 16, 2025
52eaeb5
Merge remote-tracking branch 'origin/develop' into develop
marle3003 Nov 16, 2025
e4c02ff
revert test
marle3003 Nov 16, 2025
e1e37db
Merge branch 'develop' into dependabot/go_modules/develop/github.com/…
marle3003 Nov 16, 2025
350af6b
fix response header and data processing from JavaScript
marle3003 Nov 19, 2025
dd30509
fix refactoring JavaScript event handler
marle3003 Nov 19, 2025
93dfb4c
Merge branch 'develop' into dependabot/go_modules/develop/github.com/…
marle3003 Nov 19, 2025
38662d7
Merge pull request #739 from marle3003/dependabot/go_modules/develop/…
github-actions[bot] Nov 19, 2025
19c23d4
Bump github.com/evanw/esbuild from 0.25.12 to 0.27.0
dependabot[bot] Nov 19, 2025
ce7b55c
Merge pull request #740 from marle3003/dependabot/go_modules/develop/…
github-actions[bot] Nov 19, 2025
eb60df3
Bump github.com/blevesearch/bleve/v2 from 2.5.4 to 2.5.5
dependabot[bot] Nov 19, 2025
5cc25d0
Merge pull request #741 from marle3003/dependabot/go_modules/develop/…
github-actions[bot] Nov 19, 2025
51a4408
Bump golang.org/x/text from 0.30.0 to 0.31.0
dependabot[bot] Nov 19, 2025
3833303
Merge pull request #743 from marle3003/dependabot/go_modules/develop/…
github-actions[bot] Nov 19, 2025
408bffb
Bump golang.org/x/net from 0.46.0 to 0.47.0
dependabot[bot] Nov 19, 2025
9bb6405
Merge pull request #742 from marle3003/dependabot/go_modules/develop/…
github-actions[bot] Nov 19, 2025
595b988
fix Kafka ApiVersion response when client is ahead
marle3003 Nov 20, 2025
2780d01
Merge remote-tracking branch 'origin/develop' into develop
marle3003 Nov 20, 2025
7cb581c
Bump vue-tsc from 3.1.3 to 3.1.4 in /webui
dependabot[bot] Nov 21, 2025
e209d39
Merge pull request #752 from marle3003/dependabot/npm_and_yarn/webui/…
github-actions[bot] Nov 21, 2025
59ce913
Bump vite from 7.2.2 to 7.2.4 in /webui
dependabot[bot] Nov 21, 2025
74ef594
Merge pull request #751 from marle3003/dependabot/npm_and_yarn/webui/…
github-actions[bot] Nov 21, 2025
5e05636
Bump @vitejs/plugin-vue from 6.0.1 to 6.0.2 in /webui
dependabot[bot] Nov 21, 2025
0c800f5
Merge pull request #753 from marle3003/dependabot/npm_and_yarn/webui/…
github-actions[bot] Nov 21, 2025
8b5fbbd
add XML support in Kafka
marle3003 Nov 25, 2025
c459018
Merge remote-tracking branch 'origin/develop' into develop
marle3003 Nov 25, 2025
852ca4b
improve example data API
marle3003 Nov 25, 2025
117ceff
Merge branch 'main' into develop
marle3003 Nov 25, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions acceptance/mail_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ type MailSuite struct{ BaseSuite }

func (suite *MailSuite) SetupSuite() {
cfg := static.NewConfig()
port := try.GetFreePort()
cfg.Api.Port = fmt.Sprintf("%v", port)
wd, err := os.Getwd()
require.NoError(suite.T(), err)
cfg.ConfigFile = path.Join(wd, "mokapi.yaml")
Expand All @@ -47,16 +49,16 @@ func (suite *MailSuite) TestSendMail() {
require.NoError(suite.T(), err)

// test mail API
try.GetRequest(suite.T(), "http://localhost:8080/api/services/mail/Mokapi%20MailServer/mailboxes", nil,
try.GetRequest(suite.T(), fmt.Sprintf("http://localhost:%v/api/services/mail/Mokapi%%20MailServer/mailboxes", suite.cfg.Api.Port), nil,
try.HasStatusCode(200),
try.HasBody(`[{"name":"[email protected]","numMessages":1}]`),
)
try.GetRequest(suite.T(), "http://localhost:8080/api/services/mail/Mokapi%20MailServer/mailboxes/[email protected]", nil,
try.GetRequest(suite.T(), fmt.Sprintf("http://localhost:%v/api/services/mail/Mokapi%%20MailServer/mailboxes/[email protected]", suite.cfg.Api.Port), nil,
try.HasStatusCode(200),
try.HasBody(`{"name":"[email protected]","numMessages":1,"folders":["INBOX"]}`),
)
var messageId string
try.GetRequest(suite.T(), "http://localhost:8080/api/services/mail/Mokapi%20MailServer/mailboxes/[email protected]/messages", nil,
try.GetRequest(suite.T(), fmt.Sprintf("http://localhost:%v/api/services/mail/Mokapi%%20MailServer/mailboxes/[email protected]/messages", suite.cfg.Api.Port), nil,
try.HasStatusCode(200),
try.AssertBody(func(t *testing.T, body string) {
var v any
Expand All @@ -73,7 +75,7 @@ func (suite *MailSuite) TestSendMail() {
messageId = m["messageId"].(string)
}),
)
try.GetRequest(suite.T(), "http://localhost:8080/api/services/mail/messages/"+messageId, nil,
try.GetRequest(suite.T(), fmt.Sprintf("http://localhost:%v/api/services/mail/messages/%v", suite.cfg.Api.Port, messageId), nil,
try.HasStatusCode(200),
try.AssertBody(func(t *testing.T, body string) {
var v any
Expand Down Expand Up @@ -209,16 +211,16 @@ It can be any text data.
require.NoError(suite.T(), err)

// test mail API
try.GetRequest(suite.T(), "http://localhost:8080/api/services/mail/Mokapi%20MailServer%20Old/mailboxes", nil,
try.GetRequest(suite.T(), fmt.Sprintf("http://localhost:%v/api/services/mail/Mokapi%%20MailServer%%20Old/mailboxes", suite.cfg.Api.Port), nil,
try.HasStatusCode(200),
try.HasBody(`[{"name":"[email protected]","numMessages":1}]`),
)
try.GetRequest(suite.T(), "http://localhost:8080/api/services/mail/Mokapi%20MailServer%20Old/mailboxes/[email protected]", nil,
try.GetRequest(suite.T(), fmt.Sprintf("http://localhost:%v/api/services/mail/Mokapi%%20MailServer%%20Old/mailboxes/[email protected]", suite.cfg.Api.Port), nil,
try.HasStatusCode(200),
try.HasBody(`{"name":"[email protected]","numMessages":1,"folders":["INBOX"]}`),
)
var messageId string
try.GetRequest(suite.T(), "http://localhost:8080/api/services/mail/Mokapi%20MailServer%20Old/mailboxes/[email protected]/messages", nil,
try.GetRequest(suite.T(), fmt.Sprintf("http://localhost:%v/api/services/mail/Mokapi%%20MailServer%%20Old/mailboxes/[email protected]/messages", suite.cfg.Api.Port), nil,
try.HasStatusCode(200),
try.AssertBody(func(t *testing.T, body string) {
var v any
Expand All @@ -235,7 +237,7 @@ It can be any text data.
messageId = m["messageId"].(string)
}),
)
try.GetRequest(suite.T(), "http://localhost:8080/api/services/mail/messages/"+messageId, nil,
try.GetRequest(suite.T(), fmt.Sprintf("http://localhost:%v/api/services/mail/messages/%v", suite.cfg.Api.Port, messageId), nil,
try.HasStatusCode(200),
try.AssertBody(func(t *testing.T, body string) {
var v any
Expand Down
4 changes: 2 additions & 2 deletions api/handler_kafka.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ func (h *handler) handleKafka(w http.ResponseWriter, r *http.Request) {
}
c := store.NewClient(k.Store, h.app.Monitor.Kafka)
ct := media.ParseContentType(r.Header.Get("Content-Type"))
result, err := c.Write(topicName, records, &ct)
result, err := c.Write(topicName, records, ct)
if err != nil {
if errors.Is(err, store.TopicNotFound) || errors.Is(err, store.PartitionNotFound) {
writeError(w, err, http.StatusNotFound)
Expand Down Expand Up @@ -288,7 +288,7 @@ func (h *handler) handleKafka(w http.ResponseWriter, r *http.Request) {
}
c := store.NewClient(k.Store, h.app.Monitor.Kafka)
ct := media.ParseContentType(r.Header.Get("Content-Type"))
result, err := c.Write(topicName, records, &ct)
result, err := c.Write(topicName, records, ct)
if err != nil {
if errors.Is(err, store.TopicNotFound) || errors.Is(err, store.PartitionNotFound) {
writeError(w, err, http.StatusNotFound)
Expand Down
4 changes: 2 additions & 2 deletions api/handler_kafka_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -661,7 +661,7 @@ func TestHandler_KafkaAPI(t *testing.T) {
Key: "foo",
Value: map[string]interface{}{"value": "bar"},
},
}, &ct)
}, ct)

return app
},
Expand Down Expand Up @@ -700,7 +700,7 @@ func TestHandler_KafkaAPI(t *testing.T) {
Key: "foo",
Value: map[string]interface{}{"value": "bar"},
},
}, &ct)
}, ct)

return app
},
Expand Down
28 changes: 24 additions & 4 deletions api/handler_schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ type schemaInfo struct {

type requestExample struct {
Name string
Path []string
Format string
Schema interface{}
ContentTypes []string
Expand Down Expand Up @@ -61,10 +62,20 @@ func (h *handler) getExampleData(w http.ResponseWriter, r *http.Request) {
re.ContentTypes = []string{"application/json"}
}

req := &generator.Request{}
if re.Name != "" {
req.Path = []string{re.Name}
} else if re.Path != nil {
req.Path = re.Path
}

var s *jsonSchema.Schema
switch t := re.Schema.(type) {
case *openApiSchema.Schema:
s = openApiSchema.ConvertToJsonSchema(t)
if t.Xml != nil && t.Xml.Name != "" {
req.Path = append(req.Path, t.Xml.Name)
}
case *avro.Schema:
s = avro.ConvertToJsonSchema(t)
default:
Expand All @@ -75,11 +86,9 @@ func (h *handler) getExampleData(w http.ResponseWriter, r *http.Request) {
return
}
}
req.Schema = s

rnd, err := generator.New(&generator.Request{
Path: []string{re.Name},
Schema: s,
})
rnd, err := generator.New(req)
if err != nil {
http.Error(w, err.Error(), http.StatusBadRequest)
return
Expand Down Expand Up @@ -254,6 +263,11 @@ func (r *requestExample) UnmarshalJSON(data []byte) error {
return err
}
r.Name = t.(string)
case "path":
err = d.Decode(&r.Path)
if err != nil {
return err
}
case "format":
t, err = d.Token()
if err != nil {
Expand All @@ -270,6 +284,12 @@ func (r *requestExample) UnmarshalJSON(data []byte) error {
if err != nil {
return err
}
default:
var discard json.RawMessage
err = d.Decode(&discard)
if err != nil {
return err
}
}
}

Expand Down
23 changes: 23 additions & 0 deletions api/handler_schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,29 @@ func TestHandler_Schema_Example(t *testing.T) {
)
},
},
{
name: "pet with path",
app: &runtime.App{},
fn: func(t *testing.T, h http.Handler, app *runtime.App) {
try.Handler(t,
http.MethodGet,
"http://foo.api/api/schema/example",
nil,
`{"path": ["pet", "category", "name"], "schema": {"type": ["string"]}, "contentTypes": ["application/json"]}`,
h,
try.HasStatusCode(200),
try.HasHeader("Content-Type", "application/json"),
try.AssertBody(func(t *testing.T, body string) {
var data []map[string]any
err := json.Unmarshal([]byte(body), &data)
require.NoError(t, err)
b, err := base64.StdEncoding.DecodeString(data[0]["value"].(string))
require.NoError(t, err)
require.Equal(t, `"turtle"`, string(b))
}),
)
},
},
}

for _, tc := range testcases {
Expand Down
11 changes: 10 additions & 1 deletion engine/common/host.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,15 @@ type JobOptions struct {

type Host interface {
Logger
SetEventLogger(func(level, message string))

Every(every string, do func(), opt JobOptions) (int, error)
Cron(expr string, do func(), opt JobOptions) (int, error)
Cancel(jobId int) error

OpenFile(file string, hint string) (*dynamic.Config, error)

On(event string, do func(args ...interface{}) (bool, error), tags map[string]string)
On(event string, do EventHandler, tags map[string]string)

KafkaClient() KafkaClient
HttpClient(HttpClientOptions) HttpClient
Expand Down Expand Up @@ -182,3 +184,10 @@ type Store interface {
Keys() []string
Namespace(name string) Store
}

type EventHandler func(ctx *EventContext) (bool, error)

type EventContext struct {
EventLogger func(level, message string)
Args []any
}
42 changes: 27 additions & 15 deletions engine/common/http.go
Original file line number Diff line number Diff line change
@@ -1,40 +1,50 @@
package common

import (
"fmt"
"reflect"
"strings"
)

type EventResponse struct {
Headers map[string]string `json:"headers"`
StatusCode int `json:"statusCode"`
Body string `json:"body"`
Data interface{} `json:"data"`
Headers map[string]any `json:"headers"`
StatusCode int `json:"statusCode"`
Body string `json:"body"`
Data any `json:"data"`
}

type EventRequest struct {
Method string `json:"method"`
Url Url `json:"url"`
Body interface{} `json:"body"`
Path map[string]interface{} `json:"path"`
Query map[string]interface{} `json:"query"`
Header map[string]interface{} `json:"header"`
Cookie map[string]interface{} `json:"cookie"`
QueryString any `json:"querystring"`
Method string `json:"method"`
Url Url `json:"url"`
Body interface{} `json:"body"`
Path map[string]any `json:"path"`
Query map[string]any `json:"query"`
Header map[string]any `json:"header"`
Cookie map[string]any `json:"cookie"`
QueryString any `json:"querystring"`

Api string `json:"api"`
Key string `json:"key"`
OperationId string `json:"operationId"`
}

type Url struct {
Scheme string `json:"scheme"`
Host string `json:"host"`
Port int `json:"port"`
Path string `json:"path"`
Query string `json:"query"`
}

func (r *EventRequest) String() string {
return r.Method + " " + r.Url.String()
s := r.Method + " " + r.Url.String()
if r.Api != "" {
s += fmt.Sprintf(" [API: %s]", r.Api)
}
if r.OperationId != "" {
s += fmt.Sprintf(" [OperationId: %s]", r.OperationId)
}
return s
}

func (u Url) String() string {
Expand All @@ -45,15 +55,17 @@ func (u Url) String() string {
}
sb.WriteString(u.Host)
sb.WriteString(u.Path)
sb.WriteString("?" + u.Query)
if len(u.Query) > 0 {
sb.WriteString("?" + u.Query)
}
return sb.String()
}

func (r *EventResponse) HasBody() bool {
return len(r.Body) > 0 || r.Data != nil
}

func EventHandler(req *EventRequest, res *EventResponse, resources interface{}) (bool, error) {
func HttpEventHandler(req *EventRequest, res *EventResponse, resources interface{}) (bool, error) {
resource := getResource(req.Url, resources)
if resource == nil {
return false, nil
Expand Down
5 changes: 3 additions & 2 deletions engine/common/http_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package common

import (
"github.com/stretchr/testify/require"
"testing"

"github.com/stretchr/testify/require"
)

func TestEventRequest_String(t *testing.T) {
Expand Down Expand Up @@ -58,7 +59,7 @@ func TestHttpResource(t *testing.T) {
Url: tc.url,
}
res := &EventResponse{}
b, err := EventHandler(req, res, tc.resource)
b, err := HttpEventHandler(req, res, tc.resource)
tc.test(t, b, res.Data, err)
})
}
Expand Down
Loading
Loading