Skip to content

Commit fd9557e

Browse files
authored
Merge branch 'v0.11' into dependabot/go_modules/v0.11/github.com/bradleyfalzon/ghinstallation/v2-2.13.0
2 parents 5b2f10a + b6bf682 commit fd9557e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+2308
-790
lines changed

.github/actions/run-frontend-tests/action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ runs:
2323
run: docker load --input /tmp/mokapi.tar
2424
shell: bash
2525
- name: Run mokapi image
26-
run: docker run --name mokapi --rm -d -p 8090:8090 --mount type=bind,source=$(pwd)/examples/mokapi,target=/data --env MOKAPI_Log_Level=Debug --env MOKAPI_Api_Port=8090 --env MOKAPI_Providers_File_Directory=/data ${{ inputs.image-name }}
26+
run: docker run --name mokapi --rm -d -p 8090:8090 -p 8091:8091 --mount type=bind,source=$(pwd)/examples/mokapi,target=/data --env MOKAPI_Log_Level=Debug --env MOKAPI_Api_Port=8091 --env MOKAPI_Api_Path=/mokapi --env MOKAPI_Providers_File_Directory=/data ${{ inputs.image-name }}
2727
shell: bash
2828
- uses: actions/setup-node@v4
2929
with:

.goreleaser.windows.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ builds:
55
- CGO_ENABLED=0
66
ldflags:
77
- -X mokapi/version.BuildVersion={{ .Version }}
8+
- -X mokapi/version.BuildTime={{ .Date }}
89
main: ./cmd/mokapi
910
goos:
1011
- windows

.goreleaser.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ builds:
55
- CGO_ENABLED=0
66
ldflags:
77
- -X mokapi/version.BuildVersion={{ .Version }}
8+
- -X mokapi/version.BuildTime={{ .Date }}
89
main: ./cmd/mokapi
910
goos:
1011
- linux

acceptance/petstore/petstore.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,5 @@ export default async function() {
2929
}
3030
return false
3131
});
32-
await kafka.produceAsync({ topic: 'petstore.order-event' })
32+
await kafka.produceAsync({ topic: 'petstore.order-event', messages: [{partition: 0}] })
3333
}

acceptance/petstore_test.go

Lines changed: 86 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,97 @@ func (suite *PetStoreSuite) TestApi() {
3737
try.HasHeader("Access-Control-Allow-Origin", "*"))
3838
})
3939

40-
suite.T().Run("get service", func(t *testing.T) {
40+
suite.T().Run("get Swagger HTTP service", func(t *testing.T) {
4141
try.GetRequest(t, fmt.Sprintf("http://127.0.0.1:%v/api/services/http/Swagger%%20Petstore", suite.cfg.Api.Port),
4242
nil,
4343
try.HasStatusCode(http.StatusOK),
4444
try.BodyContains(`{"name":"Swagger Petstore","description":"This is a sample server Petstore server. You can find out more about `),
4545
try.BodyMatch(`"configs":\[{"id":".*","url":".*\/acceptance\/petstore\/openapi\.yml","provider":"file","time":".*"}\]`),
4646
)
4747
})
48+
49+
suite.T().Run("get AsyncAPI service", func(t *testing.T) {
50+
// ensure scripts are executed
51+
time.Sleep(3 * time.Second)
52+
53+
expected := map[string]interface{}{
54+
"version": "1.0.0",
55+
"name": "A sample AsyncApi Kafka streaming api",
56+
"description": "",
57+
"servers": []interface{}{
58+
map[string]interface{}{
59+
"description": "",
60+
"host": "127.0.0.1:19092",
61+
"name": "broker",
62+
},
63+
},
64+
65+
"topics": []interface{}{map[string]interface{}{
66+
"description": "",
67+
"messages": map[string]interface{}{
68+
"#/components/messages/order": map[string]interface{}{
69+
"contentType": "application/json",
70+
"header": map[string]interface{}{
71+
"schema": map[string]interface{}{
72+
"properties": map[string]interface{}{
73+
"number": map[string]interface{}{
74+
"type": "number",
75+
}, "test": map[string]interface{}{
76+
"type": "string",
77+
},
78+
}, "type": "object",
79+
},
80+
},
81+
"key": map[string]interface{}{
82+
"schema": map[string]interface{}{
83+
"type": "string",
84+
},
85+
},
86+
"payload": map[string]interface{}{
87+
"schema": map[string]interface{}{
88+
"properties": map[string]interface{}{
89+
"accepted": map[string]interface{}{
90+
"properties": map[string]interface{}{
91+
"timestamp": map[string]interface{}{"format": "date-time", "type": "string"},
92+
},
93+
"type": "object",
94+
},
95+
"completed": map[string]interface{}{
96+
"properties": map[string]interface{}{
97+
"timestamp": map[string]interface{}{"format": "date-time", "type": "string"},
98+
},
99+
"type": "object",
100+
},
101+
"id": map[string]interface{}{"type": "integer"},
102+
"placed": map[string]interface{}{
103+
"properties": map[string]interface{}{
104+
"petid": map[string]interface{}{"type": "integer"},
105+
"quantity": map[string]interface{}{"format": "int32", "type": "integer"},
106+
"ship-date": map[string]interface{}{"format": "date-time", "type": "string"},
107+
},
108+
"type": "object",
109+
},
110+
},
111+
"required": []interface{}{"id"},
112+
"type": "object",
113+
},
114+
},
115+
},
116+
},
117+
"name": "petstore.order-event",
118+
"partitions": []interface{}{
119+
map[string]interface{}{"id": float64(0), "leader": map[string]interface{}{"addr": "127.0.0.1:19092", "name": "broker"}, "offset": float64(1), "segments": float64(1), "startOffset": float64(0)},
120+
map[string]interface{}{"id": float64(1), "leader": map[string]interface{}{"addr": "127.0.0.1:19092", "name": "broker"}, "offset": float64(0), "segments": float64(0), "startOffset": float64(0)},
121+
},
122+
}},
123+
}
124+
125+
try.GetRequest(t, fmt.Sprintf("http://127.0.0.1:%v/api/services/kafka/A%%20sample%%20AsyncApi%%20Kafka%%20streaming%%20api", suite.cfg.Api.Port),
126+
nil,
127+
try.HasStatusCode(http.StatusOK),
128+
try.BodyContainsData(expected),
129+
)
130+
})
48131
}
49132

50133
func (suite *PetStoreSuite) TestJsHttpHandler() {
@@ -90,12 +173,12 @@ func (suite *PetStoreSuite) TestGetOrderById() {
90173
try.GetRequest(suite.T(), "http://127.0.0.1:18080/store/order/1",
91174
map[string]string{"Accept": "application/json"},
92175
try.HasStatusCode(http.StatusOK),
93-
try.HasBody(`{"id":98266,"petId":23377,"quantity":92,"shipDate":"1989-01-30T07:58:01Z","status":"approved","complete":false}`))
176+
try.HasBody(`{"id":98266,"petId":23377,"quantity":92,"shipDate":"2012-01-30T07:58:01Z","status":"approved","complete":false}`))
94177

95178
try.GetRequest(suite.T(), "https://localhost:18443/store/order/10",
96179
map[string]string{"Accept": "application/json"},
97180
try.HasStatusCode(http.StatusOK),
98-
try.HasBody(`{"id":12545,"petId":20895,"quantity":16,"shipDate":"1989-11-19T16:57:16Z","status":"approved","complete":true}`))
181+
try.HasBody(`{"id":12545,"petId":20895,"quantity":16,"shipDate":"2027-11-26T16:57:16Z","status":"approved","complete":true}`))
99182
}
100183

101184
func (suite *PetStoreSuite) TestKafka_TopicConfig() {

api/handler.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ type handler struct {
2525

2626
type info struct {
2727
Version string `json:"version"`
28+
BuildTime string `json:"buildTime"`
2829
ActiveServices []string `json:"activeServices,omitempty"`
2930
}
3031

@@ -181,7 +182,7 @@ func writeError(w http.ResponseWriter, err error, status int) {
181182
func (h *handler) getInfo(w http.ResponseWriter, _ *http.Request) {
182183
w.Header().Set("Content-Type", "application/json")
183184

184-
i := info{Version: h.app.Version}
185+
i := info{Version: h.app.Version, BuildTime: h.app.BuildTime}
185186
if len(h.app.Http) > 0 {
186187
i.ActiveServices = append(i.ActiveServices, "http")
187188
}

api/handler_fileserver_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ func TestHandler_FileServer(t *testing.T) {
3535
h,
3636
try.HasStatusCode(200),
3737
try.HasHeader("Content-Type", "application/json"),
38-
try.HasBody(`{"version":""}`))
38+
try.HasBody(`{"version":"","buildTime":""}`))
3939
},
4040
fileServer: http.HandlerFunc(func(writer http.ResponseWriter, request *http.Request) {
4141
if request.URL.Path != "/index.html" {

api/handler_http.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package api
22

33
import (
44
"mokapi/providers/openapi/parameter"
5+
"mokapi/providers/openapi/schema"
56
"mokapi/runtime"
67
"mokapi/runtime/metrics"
78
"mokapi/runtime/monitor"
@@ -50,7 +51,7 @@ type param struct {
5051
Deprecated bool `json:"deprecated"`
5152
Style string `json:"style,omitempty"`
5253
Exploded bool `json:"exploded"`
53-
Schema *schemaInfo `json:"schema"`
54+
Schema *schema.Ref `json:"schema"`
5455
}
5556

5657
type response struct {
@@ -63,7 +64,7 @@ type response struct {
6364
type header struct {
6465
Name string `json:"name"`
6566
Description string `json:"description"`
66-
Schema *schemaInfo `json:"schema"`
67+
Schema *schema.Ref `json:"schema"`
6768
}
6869

6970
type requestBody struct {
@@ -74,7 +75,7 @@ type requestBody struct {
7475

7576
type mediaType struct {
7677
Type string `json:"type"`
77-
Schema *schemaInfo `json:"schema"`
78+
Schema *schema.Ref `json:"schema"`
7879
}
7980

8081
type server struct {
@@ -184,7 +185,7 @@ func (h *handler) getHttpService(w http.ResponseWriter, r *http.Request, m *moni
184185
for ct, rb := range o.RequestBody.Value.Content {
185186
op.RequestBody.Contents = append(op.RequestBody.Contents, mediaType{
186187
Type: ct,
187-
Schema: getSchema(rb.Schema),
188+
Schema: rb.Schema,
188189
})
189190
}
190191
}
@@ -208,7 +209,7 @@ func (h *handler) getHttpService(w http.ResponseWriter, r *http.Request, m *moni
208209
for ct, r := range r.Value.Content {
209210
res.Contents = append(res.Contents, mediaType{
210211
Type: ct,
211-
Schema: getSchema(r.Schema),
212+
Schema: r.Schema,
212213
})
213214
}
214215
for name, h := range r.Value.Headers {
@@ -219,7 +220,7 @@ func (h *handler) getHttpService(w http.ResponseWriter, r *http.Request, m *moni
219220
hi := header{
220221
Name: name,
221222
Description: h.Value.Description,
222-
Schema: getSchema(h.Value.Schema),
223+
Schema: h.Value.Schema,
223224
}
224225
if len(h.Description) > 0 {
225226
hi.Description = h.Description
@@ -255,7 +256,7 @@ func getParameters(params parameter.Parameters) (result []param) {
255256
Deprecated: p.Value.Deprecated,
256257
Style: p.Value.Style,
257258
Exploded: p.Value.IsExplode(),
258-
Schema: getSchema(p.Value.Schema),
259+
Schema: p.Value.Schema,
259260
}
260261
if len(p.Description) > 0 {
261262
pi.Description = p.Description

api/handler_kafka.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66
"mokapi/runtime"
77
"mokapi/runtime/metrics"
88
"mokapi/runtime/monitor"
9-
jsonSchema "mokapi/schema/json/schema"
109
"net/http"
1110
"sort"
1211
"strings"
@@ -228,17 +227,22 @@ func newTopic(s *store.Store, t *store.Topic, config *asyncapi3.Channel, default
228227
Title: msg.Title,
229228
Summary: msg.Summary,
230229
Description: msg.Description,
231-
Payload: getSchemaFromAsyncAPI(msg.Payload),
232-
Header: getSchemaFromAsyncAPI(msg.Headers),
233230
ContentType: msg.ContentType,
234231
}
235232

233+
if msg.Payload != nil && msg.Payload.Value != nil {
234+
m.Payload = &schemaInfo{Schema: msg.Payload.Value.Schema, Format: msg.Payload.Value.Format}
235+
}
236+
if msg.Headers != nil && msg.Headers.Value != nil {
237+
m.Header = &schemaInfo{Schema: msg.Headers.Value.Schema, Format: msg.Headers.Value.Format}
238+
}
239+
236240
if m.ContentType == "" {
237241
m.ContentType = defaultContentType
238242
}
239243

240244
if msg.Bindings.Kafka.Key != nil {
241-
m.Key = getSchemaFromJson(msg.Bindings.Kafka.Key.Value.Schema.(*jsonSchema.Ref))
245+
m.Key = &schemaInfo{Schema: msg.Bindings.Kafka.Key.Value.Schema}
242246
}
243247
if result.Messages == nil {
244248
result.Messages = map[string]messageConfig{}

api/handler_kafka_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ func TestHandler_Kafka(t *testing.T) {
154154
}
155155
},
156156
requestUrl: "http://foo.api/api/services/kafka/foo",
157-
responseBody: `{"name":"foo","description":"bar","version":"1.0","topics":[{"name":"foo","description":"bar","partitions":[{"id":0,"startOffset":0,"offset":0,"leader":{"name":"","addr":""},"segments":0}],"messages":{"foo":{"payload":{"type":"string"},"contentType":"application/json"}}}]}`,
157+
responseBody: `{"name":"foo","description":"bar","version":"1.0","topics":[{"name":"foo","description":"bar","partitions":[{"id":0,"startOffset":0,"offset":0,"leader":{"name":"","addr":""},"segments":0}],"messages":{"foo":{"payload":{"schema":{"type":"string"}},"contentType":"application/json"}}}]}`,
158158
},
159159
{
160160
name: "get specific with group",

0 commit comments

Comments
 (0)