Skip to content

Commit

Permalink
Add test cases for OpenAPI
Browse files Browse the repository at this point in the history
  • Loading branch information
tchssk committed May 6, 2024
1 parent 4bd580c commit 850363c
Show file tree
Hide file tree
Showing 15 changed files with 279 additions and 0 deletions.
3 changes: 3 additions & 0 deletions http/codegen/openapi/v2/files_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ func TestSections(t *testing.T) {
{"with-spaces", testdata.WithSpacesDSL},
{"with-map", testdata.WithMapDSL},
{"path-with-wildcards", testdata.PathWithWildcardDSL},
{"path-with-multiple-wildcards", testdata.PathWithMultipleWildcardDSL},
{"path-with-multiple-explicit-wildcards", testdata.PathWithMultipleExplicitWildcardDSL},
{"headers", testdata.HeadersDSL},
{"typename", testdata.TypenameDSL},
{"not-generate-server", testdata.NotGenerateServerDSL},
{"not-generate-host", testdata.NotGenerateHostDSL},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +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"]}}}}
34 changes: 34 additions & 0 deletions http/codegen/openapi/v2/testdata/TestSections/headers_file1.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
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 number Diff line number Diff line change
@@ -0,0 +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 number Diff line number Diff line change
@@ -0,0 +1,34 @@
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 number Diff line number Diff line change
@@ -0,0 +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 number Diff line number Diff line change
@@ -0,0 +1,34 @@
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
3 changes: 3 additions & 0 deletions http/codegen/openapi/v3/files_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ func TestFiles(t *testing.T) {
{"with-spaces", testdata.WithSpacesDSL},
{"with-map", testdata.WithMapDSL},
{"path-with-wildcards", testdata.PathWithWildcardDSL},
{"path-with-multiple-wildcards", testdata.PathWithMultipleWildcardDSL},
{"path-with-multiple-explicit-wildcards", testdata.PathWithMultipleExplicitWildcardDSL},
{"headers", testdata.HeadersDSL},
{"with-tags", testdata.WithTagsDSL},
{"with-tags-swagger", testdata.WithTagsSwaggerDSL},
{"typename", testdata.TypenameDSL},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +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"}]}
37 changes: 37 additions & 0 deletions http/codegen/openapi/v3/testdata/golden/headers_file1.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
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 number Diff line number Diff line change
@@ -0,0 +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 number Diff line number Diff line change
@@ -0,0 +1,37 @@
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 number Diff line number Diff line change
@@ -0,0 +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 number Diff line number Diff line change
@@ -0,0 +1,37 @@
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
54 changes: 54 additions & 0 deletions http/codegen/testdata/openapi_dsls.go
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,60 @@ var PathWithWildcardDSL = func() {
})
}

var PathWithMultipleWildcardDSL = func() {
Service("test service", func() {
Method("test endpoint", func() {
Payload(func() {
Attribute("foo", Int)
Attribute("bar", Int)
})
HTTP(func() {
POST("/{bar}")
})
})
HTTP(func() {
Path("/{foo}")
})
})
}

var PathWithMultipleExplicitWildcardDSL = func() {
Service("test service", func() {
Method("test endpoint", func() {
Payload(func() {
Attribute("foo", Int)
Attribute("bar", Int)
})
HTTP(func() {
POST("/{bar}")
Param("bar")
})
})
HTTP(func() {
Path("/{foo}")
Param("foo")
})
})
}

var HeadersDSL = func() {
Service("test service", func() {
Method("test endpoint", func() {
Payload(func() {
Attribute("foo", Int)
Attribute("bar", Int)
})
HTTP(func() {
POST("/")
Header("bar")
})
})
HTTP(func() {
Header("foo")
})
})
}

var WithTagsDSL = func() {
Service("test service", func() {
HTTP(func() {
Expand Down

0 comments on commit 850363c

Please sign in to comment.