Skip to content

Commit ac8334d

Browse files
authored
chore: accept event streaming (#1992)
* accept event streaming * update docs and tests
1 parent 63bd818 commit ac8334d

File tree

5 files changed

+16
-10
lines changed

5 files changed

+16
-10
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -471,6 +471,7 @@ Besides that, `swag` also accepts aliases for some MIME Types as follows:
471471
| png | image/png |
472472
| jpeg | image/jpeg |
473473
| gif | image/gif |
474+
| event-stream | text/event-stream |
474475
475476
476477
@@ -963,7 +964,7 @@ If the struct is defined in a dependency package, use `--parseDependency`.
963964
964965
If the struct is defined in your main project, use `--parseInternal`.
965966
966-
if you want to include both internal and from dependencies use both flags
967+
if you want to include both internal and from dependencies use both flags
967968
```
968969
swag init --parseDependency --parseInternal
969970
```

README_pt.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,7 @@ Além disso, `swag` também aceita pseudónimos para alguns tipos de MIME, como
445445
| png | image/png |
446446
| jpeg | image/jpeg |
447447
| gif | image/gif |
448+
| event-stream | text/event-stream |
448449

449450

450451

README_zh-CN.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
[![Go Report Card](https://goreportcard.com/badge/github.com/swaggo/swag)](https://goreportcard.com/report/github.com/swaggo/swag)
1010
[![codebeat badge](https://codebeat.co/badges/71e2f5e5-9e6b-405d-baf9-7cc8b5037330)](https://codebeat.co/projects/mygithub.libinneed.workers.dev-swaggo-swag-master)
1111
[![Go Doc](https://godoc.org/github.com/swaggo/swagg?status.svg)](https://godoc.org/github.com/swaggo/swag)
12-
[![Backers on Open Collective](https://opencollective.com/swag/backers/badge.svg)](#backers)
12+
[![Backers on Open Collective](https://opencollective.com/swag/backers/badge.svg)](#backers)
1313
[![Sponsors on Open Collective](https://opencollective.com/swag/sponsors/badge.svg)](#sponsors) [![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fswaggo%2Fswag.svg?type=shield)](https://app.fossa.io/projects/git%2Bgithub.com%2Fswaggo%2Fswag?ref=badge_shield)
1414
[![Release](https://img.shields.io/github/release/swaggo/swag.svg?style=flat-square)](https://github.com/swaggo/swag/releases)
1515

@@ -299,7 +299,7 @@ swag init
299299

300300
## 格式化说明
301301

302-
可以针对Swag的注释自动格式化,就像`go fmt`
302+
可以针对Swag的注释自动格式化,就像`go fmt`
303303
此处查看格式化结果 [here](https://github.com/swaggo/swag/tree/master/example/celler).
304304

305305
示例:
@@ -417,6 +417,7 @@ Example [celler/controller](https://github.com/swaggo/swag/tree/master/example/c
417417
| png | image/png |
418418
| jpeg | image/jpeg |
419419
| gif | image/gif |
420+
| event-stream | text/event-stream |
420421

421422
## 参数类型
422423

operation.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ var mimeTypeAliases = map[string]string{
4747
"png": "image/png",
4848
"jpeg": "image/jpeg",
4949
"gif": "image/gif",
50+
"event-stream": "text/event-stream",
5051
}
5152

5253
var mimeTypePattern = regexp.MustCompile("^[^/]+/[^/]+$")

parser_test.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -488,9 +488,10 @@ func TestParser_ParseAcceptComment(t *testing.T) {
488488
"image/gif",
489489
"application/xhtml+xml",
490490
"application/health+json",
491+
"text/event-stream",
491492
}
492493

493-
comment := `@Accept json,xml,plain,html,mpfd,x-www-form-urlencoded,json-api,json-stream,octet-stream,png,jpeg,gif,application/xhtml+xml,application/health+json`
494+
comment := `@Accept json,xml,plain,html,mpfd,x-www-form-urlencoded,json-api,json-stream,octet-stream,png,jpeg,gif,application/xhtml+xml,application/health+json,event-stream`
494495

495496
parser := New()
496497
assert.NoError(t, parseGeneralAPIInfo(parser, []string{comment}))
@@ -521,9 +522,10 @@ func TestParser_ParseProduceComment(t *testing.T) {
521522
"image/gif",
522523
"application/xhtml+xml",
523524
"application/health+json",
525+
"text/event-stream",
524526
}
525527

526-
comment := `@Produce json,xml,plain,html,mpfd,x-www-form-urlencoded,json-api,json-stream,octet-stream,png,jpeg,gif,application/xhtml+xml,application/health+json`
528+
comment := `@Produce json,xml,plain,html,mpfd,x-www-form-urlencoded,json-api,json-stream,octet-stream,png,jpeg,gif,application/xhtml+xml,application/health+json,event-stream`
527529

528530
parser := New()
529531
assert.NoError(t, parseGeneralAPIInfo(parser, []string{comment}))
@@ -3400,14 +3402,14 @@ func TestParseFunctionScopedComplexStructDefinition(t *testing.T) {
34003402
src := `
34013403
package main
34023404
3403-
// @Param request body main.Fun.request true "query params"
3405+
// @Param request body main.Fun.request true "query params"
34043406
// @Success 200 {object} main.Fun.response
34053407
// @Router /test [post]
34063408
func Fun() {
34073409
type request struct {
34083410
Name string
34093411
}
3410-
3412+
34113413
type grandChild struct {
34123414
Name string
34133415
}
@@ -3544,16 +3546,16 @@ package main
35443546
35453547
type PublicChild struct {
35463548
Name string
3547-
}
3549+
}
35483550
3549-
// @Param request body main.Fun.request true "query params"
3551+
// @Param request body main.Fun.request true "query params"
35503552
// @Success 200 {object} main.Fun.response
35513553
// @Router /test [post]
35523554
func Fun() {
35533555
type request struct {
35543556
Name string
35553557
}
3556-
3558+
35573559
type grandChild struct {
35583560
Name string
35593561
}

0 commit comments

Comments
 (0)