Skip to content

Commit 4688308

Browse files
committed
Add test cases about Any type
1 parent bc2aac0 commit 4688308

File tree

7 files changed

+201
-0
lines changed

7 files changed

+201
-0
lines changed

http/codegen/openapi/v2/files_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ func TestSections(t *testing.T) {
3939
{"server-host-with-variables", testdata.ServerHostWithVariablesDSL},
4040
{"with-spaces", testdata.WithSpacesDSL},
4141
{"with-map", testdata.WithMapDSL},
42+
{"with-any", testdata.WithAnyDSL},
4243
{"path-with-wildcards", testdata.PathWithWildcardDSL},
4344
{"path-with-multiple-wildcards", testdata.PathWithMultipleWildcardDSL},
4445
{"path-with-multiple-explicit-wildcards", testdata.PathWithMultipleExplicitWildcardDSL},
Lines changed: 1 addition & 0 deletions
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":["testService"],"summary":"testEndpoint testService","operationId":"testService#testEndpoint","parameters":[{"name":"TestEndpointRequestBody","in":"body","required":true,"schema":{"$ref":"#/definitions/TestServiceTestEndpointRequestBody"}}],"responses":{"200":{"description":"OK response.","schema":{"$ref":"#/definitions/TestServiceTestEndpointResponseBody"}}},"schemes":["http"]}}},"definitions":{"TestServiceTestEndpointRequestBody":{"title":"TestServiceTestEndpointRequestBody","type":"object","properties":{"any":{"example":""},"any_array":{"type":"array","items":{"example":""},"example":["","","",""]},"any_map":{"type":"object","example":{"":""},"additionalProperties":true}},"example":{"any":"","any_array":["","",""],"any_map":{"":""}}},"TestServiceTestEndpointResponseBody":{"title":"TestServiceTestEndpointResponseBody","type":"object","properties":{"any":{"example":""},"any_array":{"type":"array","items":{"example":""},"example":["","","",""]},"any_map":{"type":"object","example":{"":""},"additionalProperties":true}},"example":{"any":"","any_array":["",""],"any_map":{"":""}}}}}
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
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+
- testService
19+
summary: testEndpoint testService
20+
operationId: testService#testEndpoint
21+
parameters:
22+
- name: TestEndpointRequestBody
23+
in: body
24+
required: true
25+
schema:
26+
$ref: '#/definitions/TestServiceTestEndpointRequestBody'
27+
responses:
28+
"200":
29+
description: OK response.
30+
schema:
31+
$ref: '#/definitions/TestServiceTestEndpointResponseBody'
32+
schemes:
33+
- http
34+
definitions:
35+
TestServiceTestEndpointRequestBody:
36+
title: TestServiceTestEndpointRequestBody
37+
type: object
38+
properties:
39+
any:
40+
example: ""
41+
any_array:
42+
type: array
43+
items:
44+
example: ""
45+
example:
46+
- ""
47+
- ""
48+
- ""
49+
- ""
50+
any_map:
51+
type: object
52+
example:
53+
"": ""
54+
additionalProperties: true
55+
example:
56+
any: ""
57+
any_array:
58+
- ""
59+
- ""
60+
- ""
61+
any_map:
62+
"": ""
63+
TestServiceTestEndpointResponseBody:
64+
title: TestServiceTestEndpointResponseBody
65+
type: object
66+
properties:
67+
any:
68+
example: ""
69+
any_array:
70+
type: array
71+
items:
72+
example: ""
73+
example:
74+
- ""
75+
- ""
76+
- ""
77+
- ""
78+
any_map:
79+
type: object
80+
example:
81+
"": ""
82+
additionalProperties: true
83+
example:
84+
any: ""
85+
any_array:
86+
- ""
87+
- ""
88+
any_map:
89+
"": ""

http/codegen/openapi/v3/files_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ func TestFiles(t *testing.T) {
4141
{"server-host-with-variables", testdata.ServerHostWithVariablesDSL},
4242
{"with-spaces", testdata.WithSpacesDSL},
4343
{"with-map", testdata.WithMapDSL},
44+
{"with-any", testdata.WithAnyDSL},
4445
{"path-with-wildcards", testdata.PathWithWildcardDSL},
4546
{"path-with-multiple-wildcards", testdata.PathWithMultipleWildcardDSL},
4647
{"path-with-multiple-explicit-wildcards", testdata.PathWithMultipleExplicitWildcardDSL},
Lines changed: 1 addition & 0 deletions
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":["testService"],"summary":"testEndpoint testService","operationId":"testService#testEndpoint","requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/TestEndpointRequestBody"},"example":{"any":"","any_array":["","","",""],"any_map":{"":""}}}}},"responses":{"200":{"description":"OK response.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/TestEndpointRequestBody"},"example":{"any":"","any_array":["","",""],"any_map":{"":""}}}}}}}}},"components":{"schemas":{"TestEndpointRequestBody":{"type":"object","properties":{"any":{"example":""},"any_array":{"type":"array","items":{"example":""},"example":["","","",""]},"any_map":{"type":"object","example":{"":""},"additionalProperties":true}},"example":{"any":"","any_array":["",""],"any_map":{"":""}}}}},"tags":[{"name":"testService"}]}
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
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+
- testService
13+
summary: testEndpoint testService
14+
operationId: testService#testEndpoint
15+
requestBody:
16+
required: true
17+
content:
18+
application/json:
19+
schema:
20+
$ref: '#/components/schemas/TestEndpointRequestBody'
21+
example:
22+
any: ""
23+
any_array:
24+
- ""
25+
- ""
26+
- ""
27+
- ""
28+
any_map:
29+
"": ""
30+
responses:
31+
"200":
32+
description: OK response.
33+
content:
34+
application/json:
35+
schema:
36+
$ref: '#/components/schemas/TestEndpointRequestBody'
37+
example:
38+
any: ""
39+
any_array:
40+
- ""
41+
- ""
42+
- ""
43+
any_map:
44+
"": ""
45+
components:
46+
schemas:
47+
TestEndpointRequestBody:
48+
type: object
49+
properties:
50+
any:
51+
example: ""
52+
any_array:
53+
type: array
54+
items:
55+
example: ""
56+
example:
57+
- ""
58+
- ""
59+
- ""
60+
- ""
61+
any_map:
62+
type: object
63+
example:
64+
"": ""
65+
additionalProperties: true
66+
example:
67+
any: ""
68+
any_array:
69+
- ""
70+
- ""
71+
any_map:
72+
"": ""
73+
tags:
74+
- name: testService

http/codegen/testdata/openapi_dsls.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -522,6 +522,40 @@ var WithMapDSL = func() {
522522
})
523523
}
524524

525+
var WithAnyDSL = func() {
526+
Service("testService", func() {
527+
Method("testEndpoint", func() {
528+
Payload(func() {
529+
Attribute("any", Any, func() {
530+
Example("")
531+
})
532+
Attribute("any_array", ArrayOf(Any, func() {
533+
Example("")
534+
}))
535+
Attribute("any_map", MapOf(String, Any), func() {
536+
Key(func() { Example("") })
537+
Elem(func() { Example("") })
538+
})
539+
})
540+
Result(func() {
541+
Attribute("any", Any, func() {
542+
Example("")
543+
})
544+
Attribute("any_array", ArrayOf(Any, func() {
545+
Example("")
546+
}))
547+
Attribute("any_map", MapOf(String, Any), func() {
548+
Key(func() { Example("") })
549+
Elem(func() { Example("") })
550+
})
551+
})
552+
HTTP(func() {
553+
POST("/")
554+
})
555+
})
556+
})
557+
}
558+
525559
var PathWithWildcardDSL = func() {
526560
Service("test service", func() {
527561
Method("test endpoint", func() {

0 commit comments

Comments
 (0)