Skip to content

Commit 850363c

Browse files
committed
Add test cases for OpenAPI
1 parent 4bd580c commit 850363c

15 files changed

+279
-0
lines changed

http/codegen/openapi/v2/files_test.go

+3
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ func TestSections(t *testing.T) {
4040
{"with-spaces", testdata.WithSpacesDSL},
4141
{"with-map", testdata.WithMapDSL},
4242
{"path-with-wildcards", testdata.PathWithWildcardDSL},
43+
{"path-with-multiple-wildcards", testdata.PathWithMultipleWildcardDSL},
44+
{"path-with-multiple-explicit-wildcards", testdata.PathWithMultipleExplicitWildcardDSL},
45+
{"headers", testdata.HeadersDSL},
4346
{"typename", testdata.TypenameDSL},
4447
{"not-generate-server", testdata.NotGenerateServerDSL},
4548
{"not-generate-host", testdata.NotGenerateHostDSL},
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"swagger":"2.0","info":{"title":"","version":"0.0.1"},"host":"localhost:80","consumes":["application/json","application/xml","application/gob"],"produces":["application/json","application/xml","application/gob"],"paths":{"/":{"post":{"tags":["test service"],"summary":"test endpoint test service","operationId":"test service#test endpoint","parameters":[{"name":"foo","in":"header","required":false,"type":"integer"},{"name":"bar","in":"header","required":false,"type":"integer"}],"responses":{"204":{"description":"No Content response."}},"schemes":["http"]}}}}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
swagger: "2.0"
2+
info:
3+
title: ""
4+
version: 0.0.1
5+
host: localhost:80
6+
consumes:
7+
- application/json
8+
- application/xml
9+
- application/gob
10+
produces:
11+
- application/json
12+
- application/xml
13+
- application/gob
14+
paths:
15+
/:
16+
post:
17+
tags:
18+
- test service
19+
summary: test endpoint test service
20+
operationId: test service#test endpoint
21+
parameters:
22+
- name: foo
23+
in: header
24+
required: false
25+
type: integer
26+
- name: bar
27+
in: header
28+
required: false
29+
type: integer
30+
responses:
31+
"204":
32+
description: No Content response.
33+
schemes:
34+
- http
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"swagger":"2.0","info":{"title":"","version":"0.0.1"},"host":"localhost:80","consumes":["application/json","application/xml","application/gob"],"produces":["application/json","application/xml","application/gob"],"paths":{"/{foo}/{bar}":{"post":{"tags":["test service"],"summary":"test endpoint test service","operationId":"test service#test endpoint","parameters":[{"name":"foo","in":"path","required":true,"type":"integer"},{"name":"bar","in":"path","required":true,"type":"integer"}],"responses":{"204":{"description":"No Content response."}},"schemes":["http"]}}}}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
swagger: "2.0"
2+
info:
3+
title: ""
4+
version: 0.0.1
5+
host: localhost:80
6+
consumes:
7+
- application/json
8+
- application/xml
9+
- application/gob
10+
produces:
11+
- application/json
12+
- application/xml
13+
- application/gob
14+
paths:
15+
/{foo}/{bar}:
16+
post:
17+
tags:
18+
- test service
19+
summary: test endpoint test service
20+
operationId: test service#test endpoint
21+
parameters:
22+
- name: foo
23+
in: path
24+
required: true
25+
type: integer
26+
- name: bar
27+
in: path
28+
required: true
29+
type: integer
30+
responses:
31+
"204":
32+
description: No Content response.
33+
schemes:
34+
- http
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"swagger":"2.0","info":{"title":"","version":"0.0.1"},"host":"localhost:80","consumes":["application/json","application/xml","application/gob"],"produces":["application/json","application/xml","application/gob"],"paths":{"/{foo}/{bar}":{"post":{"tags":["test service"],"summary":"test endpoint test service","operationId":"test service#test endpoint","parameters":[{"name":"foo","in":"path","required":true,"type":"integer"},{"name":"bar","in":"path","required":true,"type":"integer"}],"responses":{"204":{"description":"No Content response."}},"schemes":["http"]}}}}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
swagger: "2.0"
2+
info:
3+
title: ""
4+
version: 0.0.1
5+
host: localhost:80
6+
consumes:
7+
- application/json
8+
- application/xml
9+
- application/gob
10+
produces:
11+
- application/json
12+
- application/xml
13+
- application/gob
14+
paths:
15+
/{foo}/{bar}:
16+
post:
17+
tags:
18+
- test service
19+
summary: test endpoint test service
20+
operationId: test service#test endpoint
21+
parameters:
22+
- name: foo
23+
in: path
24+
required: true
25+
type: integer
26+
- name: bar
27+
in: path
28+
required: true
29+
type: integer
30+
responses:
31+
"204":
32+
description: No Content response.
33+
schemes:
34+
- http

http/codegen/openapi/v3/files_test.go

+3
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ func TestFiles(t *testing.T) {
4242
{"with-spaces", testdata.WithSpacesDSL},
4343
{"with-map", testdata.WithMapDSL},
4444
{"path-with-wildcards", testdata.PathWithWildcardDSL},
45+
{"path-with-multiple-wildcards", testdata.PathWithMultipleWildcardDSL},
46+
{"path-with-multiple-explicit-wildcards", testdata.PathWithMultipleExplicitWildcardDSL},
47+
{"headers", testdata.HeadersDSL},
4548
{"with-tags", testdata.WithTagsDSL},
4649
{"with-tags-swagger", testdata.WithTagsSwaggerDSL},
4750
{"typename", testdata.TypenameDSL},
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"openapi":"3.0.3","info":{"title":"Goa API","version":"0.0.1"},"servers":[{"url":"http://localhost:80","description":"Default server for test api"}],"paths":{"/":{"post":{"tags":["test service"],"summary":"test endpoint test service","operationId":"test service#test endpoint","parameters":[{"name":"foo","in":"header","allowEmptyValue":true,"schema":{"type":"integer","example":9176544974339886224,"format":"int64"},"example":1933576090881074823},{"name":"bar","in":"header","allowEmptyValue":true,"schema":{"type":"integer","example":2166276375441812184,"format":"int64"},"example":7595816812588075382}],"responses":{"204":{"description":"No Content response."}}}}},"components":{},"tags":[{"name":"test service"}]}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
openapi: 3.0.3
2+
info:
3+
title: Goa API
4+
version: 0.0.1
5+
servers:
6+
- url: http://localhost:80
7+
description: Default server for test api
8+
paths:
9+
/:
10+
post:
11+
tags:
12+
- test service
13+
summary: test endpoint test service
14+
operationId: test service#test endpoint
15+
parameters:
16+
- name: foo
17+
in: header
18+
allowEmptyValue: true
19+
schema:
20+
type: integer
21+
example: 9176544974339886224
22+
format: int64
23+
example: 1933576090881074823
24+
- name: bar
25+
in: header
26+
allowEmptyValue: true
27+
schema:
28+
type: integer
29+
example: 2166276375441812184
30+
format: int64
31+
example: 7595816812588075382
32+
responses:
33+
"204":
34+
description: No Content response.
35+
components: {}
36+
tags:
37+
- name: test service
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"openapi":"3.0.3","info":{"title":"Goa API","version":"0.0.1"},"servers":[{"url":"http://localhost:80","description":"Default server for test api"}],"paths":{"/{foo}/{bar}":{"post":{"tags":["test service"],"summary":"test endpoint test service","operationId":"test service#test endpoint","parameters":[{"name":"foo","in":"path","required":true,"schema":{"type":"integer","example":9176544974339886224,"format":"int64"},"example":1933576090881074823},{"name":"bar","in":"path","required":true,"schema":{"type":"integer","example":2166276375441812184,"format":"int64"},"example":7595816812588075382}],"responses":{"204":{"description":"No Content response."}}}}},"components":{},"tags":[{"name":"test service"}]}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
openapi: 3.0.3
2+
info:
3+
title: Goa API
4+
version: 0.0.1
5+
servers:
6+
- url: http://localhost:80
7+
description: Default server for test api
8+
paths:
9+
/{foo}/{bar}:
10+
post:
11+
tags:
12+
- test service
13+
summary: test endpoint test service
14+
operationId: test service#test endpoint
15+
parameters:
16+
- name: foo
17+
in: path
18+
required: true
19+
schema:
20+
type: integer
21+
example: 9176544974339886224
22+
format: int64
23+
example: 1933576090881074823
24+
- name: bar
25+
in: path
26+
required: true
27+
schema:
28+
type: integer
29+
example: 2166276375441812184
30+
format: int64
31+
example: 7595816812588075382
32+
responses:
33+
"204":
34+
description: No Content response.
35+
components: {}
36+
tags:
37+
- name: test service
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"openapi":"3.0.3","info":{"title":"Goa API","version":"0.0.1"},"servers":[{"url":"http://localhost:80","description":"Default server for test api"}],"paths":{"/{foo}/{bar}":{"post":{"tags":["test service"],"summary":"test endpoint test service","operationId":"test service#test endpoint","parameters":[{"name":"foo","in":"path","required":true,"schema":{"type":"integer","example":9176544974339886224,"format":"int64"},"example":1933576090881074823},{"name":"bar","in":"path","required":true,"schema":{"type":"integer","example":2166276375441812184,"format":"int64"},"example":7595816812588075382}],"responses":{"204":{"description":"No Content response."}}}}},"components":{},"tags":[{"name":"test service"}]}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
openapi: 3.0.3
2+
info:
3+
title: Goa API
4+
version: 0.0.1
5+
servers:
6+
- url: http://localhost:80
7+
description: Default server for test api
8+
paths:
9+
/{foo}/{bar}:
10+
post:
11+
tags:
12+
- test service
13+
summary: test endpoint test service
14+
operationId: test service#test endpoint
15+
parameters:
16+
- name: foo
17+
in: path
18+
required: true
19+
schema:
20+
type: integer
21+
example: 9176544974339886224
22+
format: int64
23+
example: 1933576090881074823
24+
- name: bar
25+
in: path
26+
required: true
27+
schema:
28+
type: integer
29+
example: 2166276375441812184
30+
format: int64
31+
example: 7595816812588075382
32+
responses:
33+
"204":
34+
description: No Content response.
35+
components: {}
36+
tags:
37+
- name: test service

http/codegen/testdata/openapi_dsls.go

+54
Original file line numberDiff line numberDiff line change
@@ -535,6 +535,60 @@ var PathWithWildcardDSL = func() {
535535
})
536536
}
537537

538+
var PathWithMultipleWildcardDSL = func() {
539+
Service("test service", func() {
540+
Method("test endpoint", func() {
541+
Payload(func() {
542+
Attribute("foo", Int)
543+
Attribute("bar", Int)
544+
})
545+
HTTP(func() {
546+
POST("/{bar}")
547+
})
548+
})
549+
HTTP(func() {
550+
Path("/{foo}")
551+
})
552+
})
553+
}
554+
555+
var PathWithMultipleExplicitWildcardDSL = func() {
556+
Service("test service", func() {
557+
Method("test endpoint", func() {
558+
Payload(func() {
559+
Attribute("foo", Int)
560+
Attribute("bar", Int)
561+
})
562+
HTTP(func() {
563+
POST("/{bar}")
564+
Param("bar")
565+
})
566+
})
567+
HTTP(func() {
568+
Path("/{foo}")
569+
Param("foo")
570+
})
571+
})
572+
}
573+
574+
var HeadersDSL = func() {
575+
Service("test service", func() {
576+
Method("test endpoint", func() {
577+
Payload(func() {
578+
Attribute("foo", Int)
579+
Attribute("bar", Int)
580+
})
581+
HTTP(func() {
582+
POST("/")
583+
Header("bar")
584+
})
585+
})
586+
HTTP(func() {
587+
Header("foo")
588+
})
589+
})
590+
}
591+
538592
var WithTagsDSL = func() {
539593
Service("test service", func() {
540594
HTTP(func() {

0 commit comments

Comments
 (0)