Skip to content

Commit 26ca35e

Browse files
authored
Merge pull request #518 from marle3003/develop
v0.14.5
2 parents 381eac9 + b040d27 commit 26ca35e

File tree

26 files changed

+358
-31
lines changed

26 files changed

+358
-31
lines changed

acceptance/petstore_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ func (suite *PetStoreSuite) TestApi() {
6666
"bindings": map[string]interface{}{"partitions": float64(2), "segmentMs": float64(30000), "valueSchemaValidation": true},
6767
"description": "",
6868
"messages": map[string]interface{}{
69-
"#/components/messages/order": map[string]interface{}{
69+
"order": map[string]interface{}{
70+
"name": "order",
7071
"contentType": "application/json",
7172
"header": map[string]interface{}{
7273
"schema": map[string]interface{}{
@@ -274,6 +275,6 @@ func (suite *PetStoreSuite) TestKafkaEventAndMetrics() {
274275
// test kafka events, header added by JavaScript event handler
275276
try.GetRequest(suite.T(), fmt.Sprintf("http://127.0.0.1:%s/api/events?namespace=kafka", suite.cfg.Api.Port), nil,
276277
try.BodyContains(`"headers":{"foo":{"value":"bar","binary":"YmFy"}`),
277-
try.BodyContains(`"messageId":"#/components/messages/order"`),
278+
try.BodyContains(`"messageId":"order"`),
278279
)
279280
}

api/handler_kafka.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,9 @@ func newTopic(s *store.Store, t *store.Topic, ch *asyncapi3.Channel, cfg *asynca
254254
Description: msg.Description,
255255
ContentType: msg.ContentType,
256256
}
257+
if m.Name == "" {
258+
m.Name = messageId
259+
}
257260

258261
if msg.Payload != nil && msg.Payload.Value != nil {
259262
m.Payload = &schemaInfo{Schema: msg.Payload.Value.Schema, Format: msg.Payload.Value.Format}

api/handler_kafka_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ func TestHandler_Kafka(t *testing.T) {
145145
}))
146146
},
147147
requestUrl: "http://foo.api/api/services/kafka/foo",
148-
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"}},"bindings":{"partitions":1,"valueSchemaValidation":true}}]}`,
148+
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":{"name":"foo","payload":{"schema":{"type":"string"}},"contentType":"application/json"}},"bindings":{"partitions":1,"valueSchemaValidation":true}}]}`,
149149
},
150150
{
151151
name: "get specific with topic and multi schema format",
@@ -168,7 +168,7 @@ func TestHandler_Kafka(t *testing.T) {
168168
}))
169169
},
170170
requestUrl: "http://foo.api/api/services/kafka/foo",
171-
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":{"format":"foo","schema":{"type":"string"}},"contentType":"application/json"}},"bindings":{"partitions":1,"valueSchemaValidation":true}}]}`,
171+
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":{"name":"foo","payload":{"format":"foo","schema":{"type":"string"}},"contentType":"application/json"}},"bindings":{"partitions":1,"valueSchemaValidation":true}}]}`,
172172
},
173173
{
174174
name: "get specific with group",
@@ -268,7 +268,7 @@ func TestHandler_Kafka(t *testing.T) {
268268
return app
269269
},
270270
requestUrl: "http://foo.api/api/services/kafka/foo",
271-
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":{"format":"foo","schema":{"type":"string"}},"contentType":"application/json"}},"bindings":{"partitions":1,"valueSchemaValidation":true}}]}`,
271+
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":{"name":"foo","payload":{"format":"foo","schema":{"type":"string"}},"contentType":"application/json"}},"bindings":{"partitions":1,"valueSchemaValidation":true}}]}`,
272272
},
273273
}
274274

api/handler_schema.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ func encodeExample(v interface{}, schema interface{}, schemaFormat string, conte
132132
case ct.Key() == "text/plain":
133133
case ct.Key() == "avro/binary" && isAvro(schemaFormat):
134134
case ct.Key() == "application/octet-stream" && isAvro(schemaFormat):
135+
case ct.Key() == "application/avro" && isAvro(schemaFormat):
135136
case ct.IsAny():
136137
ct = media.ParseContentType("application/json")
137138
default:
@@ -151,7 +152,7 @@ func encodeExample(v interface{}, schema interface{}, schemaFormat string, conte
151152
switch {
152153
case ct.Subtype == "json":
153154
data, err = encoding.NewEncoder(t.Convert()).Write(v, ct)
154-
case ct.Key() == "avro/binary" || ct.Key() == "application/octet-stream":
155+
case ct.Key() == "avro/binary" || ct.Key() == "application/avro" || ct.Key() == "application/octet-stream":
155156
data, err = t.Marshal(v)
156157
default:
157158
examples = append(examples, example{

api/handler_schema_asyncapi.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ func getAsyncApiExample(w http.ResponseWriter, r *http.Request, cfg *asyncapi3.C
8686
switch {
8787
case ct.Subtype == "json":
8888
data, err = encoding.NewEncoder(t.Convert()).Write(rnd, ct)
89-
case ct.Key() == "avro/binary" || ct.Key() == "application/octet-stream":
89+
case ct.Key() == "avro/binary" || ct.Key() == "application/avro" || ct.Key() == "application/octet-stream":
9090
data, err = t.Marshal(rnd)
9191
default:
9292
http.Error(w, fmt.Sprintf("unsupported schema type: %T", t), http.StatusBadRequest)

api/handler_schema_validate.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ func (h *handler) validate(w http.ResponseWriter, r *http.Request) {
2929
return
3030
}
3131

32-
if !(valReq.ContentType.Subtype == "json" || valReq.ContentType.Subtype == "xml" || valReq.ContentType.Key() == "avro/binary") {
32+
if !(valReq.ContentType.Subtype == "json" || valReq.ContentType.Subtype == "xml" || valReq.ContentType.Key() == "avro/binary" || valReq.ContentType.Key() == "application/avro") {
3333
http.Error(w, fmt.Sprintf("content-type %v not supported. Only json or xml are supported", valReq.ContentType), http.StatusBadRequest)
3434
return
3535
}

config/dynamic/asyncApi/convert.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ func convertChannels(cfg *asyncapi3.Config, channels map[string]*ChannelRef) err
6262
}
6363

6464
for name, orig := range channels {
65+
if orig == nil {
66+
continue
67+
}
6568
if len(orig.Ref) > 0 {
6669
cfg.Channels[name] = &asyncapi3.ChannelRef{Reference: dynamic.Reference{Ref: orig.Ref}}
6770
}
@@ -123,10 +126,12 @@ func addMessage(target *asyncapi3.Channel, msg *asyncapi3.MessageRef, opId, ref,
123126
var msgId string
124127
if len(opId) > 0 {
125128
msgId = opId
126-
} else if len(ref) > 0 {
129+
} else if msg.Ref != "" {
130+
msgId = path.Base(msg.Ref)
131+
} else if ref != "" {
127132
msgId = path.Base(ref)
128133
} else if len(opName) > 0 {
129-
msgId = opName
134+
msgId = path.Base(opName)
130135
}
131136

132137
target.Messages[msgId] = msg

config/dynamic/asyncApi/convert_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ func TestConfig_Convert(t *testing.T) {
4747
require.Equal(t, "The topic on which measured values may be produced and consumed.", channel.Description)
4848
param := channel.Parameters["streetlightId"].Value
4949
require.Equal(t, "The ID of the streetlight.", param.Description)
50+
require.Contains(t, channel.Messages, "receiveLightMeasurement")
5051

5152
// message
5253
msg := channel.Messages["receiveLightMeasurement"].Value

config/dynamic/resolve.go

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ func resolveResource(ref string, element interface{}, config *Config, reader Rea
239239
AddRef(config, sub)
240240
if _, ok := sub.Data.(Parser); ok && len(sub.Raw) > 0 {
241241
// parse again with parent scope hierarchy
242-
sub = &Config{Raw: sub.Raw, Data: sub.Data, Info: sub.Info}
242+
sub = &Config{Raw: sub.Raw, Data: copyData(sub.Data), Info: sub.Info}
243243
sub.Scope.SetParent(config.Scope)
244244
err = Parse(sub, reader)
245245
if err != nil {
@@ -300,3 +300,20 @@ func setResolved(element interface{}, val interface{}) (err error) {
300300

301301
return
302302
}
303+
304+
func copyData(input interface{}) interface{} {
305+
val := reflect.ValueOf(input)
306+
307+
if val.Kind() != reflect.Ptr {
308+
// Not a pointer — return the original or handle differently
309+
return input
310+
}
311+
312+
// Create a new object of the same type
313+
c := reflect.New(val.Elem().Type())
314+
315+
// Set the value of the new object to the original
316+
c.Elem().Set(val.Elem())
317+
318+
return c.Interface()
319+
}

docs/guides/smtp/overview.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,16 @@ your mailbox. You can also use different email addresses for testing, not just y
1010
This example demonstrates how to configure an SMTP server listen on port 587 on all available
1111
ip address.
1212

13-
```yaml
13+
```yaml tab=smtp
1414
smtp: '1.0'
1515
info:
1616
title: Mokapi's Mail Server
1717
server: smtp://:587
18+
```
19+
20+
```yaml tab=smtps
21+
smtp: '1.0'
22+
info:
23+
title: Mokapi's Mail Server
24+
server: smtps://:587
1825
```

0 commit comments

Comments
 (0)