mirror of
https://github.com/davidebianchi/gswagger.git
synced 2026-01-04 05:08:44 -05:00
Compare commits
28 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d7b5134200 | ||
|
|
31e40cedfd | ||
|
|
6f3dcc578c | ||
|
|
45cf385dec | ||
|
|
e5f3c438b4 | ||
|
|
047317ef17 | ||
|
|
b007e57092 | ||
|
|
6c9d0e579f | ||
|
|
f84327d424 | ||
|
|
085abe98d1 | ||
|
|
c5fff8f982 | ||
|
|
fee2444c96 | ||
|
|
24dfb293ea | ||
|
|
a5b9bd3dc4 | ||
|
|
7f7c92eaca | ||
|
|
2939f1027d | ||
|
|
3a4118844e | ||
|
|
3e72099700 | ||
|
|
9fac38a162 | ||
|
|
424779a7d8 | ||
|
|
d6a528ea28 | ||
|
|
909c58608a | ||
|
|
43c6e37a47 | ||
|
|
b9dc8ff83c | ||
|
|
1b95853d11 | ||
|
|
e8369933fc | ||
|
|
89d668771a | ||
|
|
0039a3f74f |
2
.github/workflows/test-builds.yml
vendored
2
.github/workflows/test-builds.yml
vendored
@@ -9,7 +9,7 @@ jobs:
|
||||
runs-on: ${{ matrix.os }}
|
||||
strategy:
|
||||
matrix:
|
||||
go_version: [1.16, 1.17]
|
||||
go_version: [1.16, 1.17, 1.18, 1.19]
|
||||
os: [ubuntu-latest]
|
||||
include:
|
||||
- go_version: 1.17
|
||||
|
||||
19
CHANGELOG.md
19
CHANGELOG.md
@@ -7,6 +7,25 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
|
||||
## Unreleased
|
||||
|
||||
## 0.6.1 - 17-11-2022
|
||||
|
||||
### Changed
|
||||
|
||||
- change jsonschema lib to `mia-platform/jsonschema v0.1.0`. This update removes the `patternProperties` with `additionalProperties` from all schemas
|
||||
- remove use of deprecated io/ioutil lib
|
||||
|
||||
## 0.6.0 - 04-11-2022
|
||||
|
||||
### Added
|
||||
|
||||
- Tags support to `router.AddRoute` accepted definition
|
||||
|
||||
## 0.5.1 - 03-10-2022
|
||||
|
||||
### Fixed
|
||||
|
||||
- upgrade deps
|
||||
|
||||
## v0.5.0 - 05-08-2022
|
||||
|
||||
### Added
|
||||
|
||||
23
Makefile
Normal file
23
Makefile
Normal file
@@ -0,0 +1,23 @@
|
||||
VERSION ?= latest
|
||||
|
||||
# Create a variable that contains the current date in UTC
|
||||
# Different flow if this script is running on Darwin or Linux machines.
|
||||
ifeq (Darwin,$(shell uname))
|
||||
NOW_DATE = $(shell date -u +%d-%m-%Y)
|
||||
else
|
||||
NOW_DATE = $(shell date -u -I)
|
||||
endif
|
||||
|
||||
all: test
|
||||
|
||||
.PHONY: test
|
||||
test:
|
||||
go test ./... -coverprofile coverage.out
|
||||
|
||||
.PHONY: version
|
||||
version:
|
||||
sed -i.bck "s|## Unreleased|## Unreleased\n\n## ${VERSION} - ${NOW_DATE}|g" "CHANGELOG.md"
|
||||
rm -fr "CHANGELOG.md.bck"
|
||||
git add "CHANGELOG.md"
|
||||
git commit -m "Upgrade version to v${VERSION}"
|
||||
git tag v${VERSION}
|
||||
@@ -169,7 +169,7 @@ see the [tags on this repository](https://github.com/davidebianchi/gswagger/tags
|
||||
|
||||
<!-- Reference -->
|
||||
[kin-openapi]: https://github.com/getkin/kin-openapi
|
||||
[jsonschema]: https://github.com/invopop/jsonschemaa
|
||||
[jsonschema]: https://github.com/mia-platform/jsonschema
|
||||
[github-actions]: https://github.com/davidebianchi/gswagger/actions
|
||||
[github-actions-svg]: https://github.com/davidebianchi/gswagger/workflows/Test%20and%20build/badge.svg
|
||||
[godoc-svg]: https://godoc.org/github.com/davidebianchi/gswagger?status.svg
|
||||
|
||||
11
go.mod
11
go.mod
@@ -3,15 +3,15 @@ module github.com/davidebianchi/gswagger
|
||||
go 1.17
|
||||
|
||||
require (
|
||||
github.com/getkin/kin-openapi v0.98.0
|
||||
github.com/getkin/kin-openapi v0.107.0
|
||||
github.com/ghodss/yaml v1.0.0
|
||||
github.com/go-openapi/swag v0.21.1 // indirect
|
||||
github.com/gorilla/mux v1.8.0
|
||||
github.com/iancoleman/orderedmap v0.2.0 // indirect
|
||||
github.com/invopop/jsonschema v0.6.0
|
||||
github.com/labstack/echo/v4 v4.7.2
|
||||
github.com/labstack/echo/v4 v4.9.1
|
||||
github.com/mailru/easyjson v0.7.7 // indirect
|
||||
github.com/stretchr/testify v1.8.0
|
||||
github.com/mia-platform/jsonschema v0.1.0
|
||||
github.com/stretchr/testify v1.8.1
|
||||
)
|
||||
|
||||
require (
|
||||
@@ -19,9 +19,10 @@ require (
|
||||
github.com/go-openapi/jsonpointer v0.19.5 // indirect
|
||||
github.com/invopop/yaml v0.2.0 // indirect
|
||||
github.com/josharian/intern v1.0.0 // indirect
|
||||
github.com/labstack/gommon v0.3.1 // indirect
|
||||
github.com/labstack/gommon v0.4.0 // indirect
|
||||
github.com/mattn/go-colorable v0.1.12 // indirect
|
||||
github.com/mattn/go-isatty v0.0.14 // indirect
|
||||
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 // indirect
|
||||
github.com/pmezard/go-difflib v1.0.0 // indirect
|
||||
github.com/valyala/bytebufferpool v1.0.0 // indirect
|
||||
github.com/valyala/fasttemplate v1.2.1 // indirect
|
||||
|
||||
22
go.sum
22
go.sum
@@ -2,8 +2,8 @@ github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ3
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/getkin/kin-openapi v0.98.0 h1:lIACvCG9cxmFsEywz+LCoVhcZHFLUy+Nv5QSkb43eAE=
|
||||
github.com/getkin/kin-openapi v0.98.0/go.mod h1:w4lRPHiyOdwGbOkLIyk+P0qCwlu7TXPCHD/64nSXzgE=
|
||||
github.com/getkin/kin-openapi v0.107.0 h1:bxhL6QArW7BXQj8NjXfIJQy680NsMKd25nwhvpCXchg=
|
||||
github.com/getkin/kin-openapi v0.107.0/go.mod h1:9Dhr+FasATJZjS4iOLvB0hkaxgYdulrNYm2e9epLWOo=
|
||||
github.com/ghodss/yaml v1.0.0 h1:wQHKEahhL6wmXdzwWG11gIVCkOv05bNOh+Rxn0yngAk=
|
||||
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
|
||||
github.com/go-openapi/jsonpointer v0.19.5 h1:gZr+CIYByUqjcgeLXnQu2gHYQC9o73G2XUeOFYEICuY=
|
||||
@@ -17,8 +17,6 @@ github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB7
|
||||
github.com/iancoleman/orderedmap v0.0.0-20190318233801-ac98e3ecb4b0/go.mod h1:N0Wam8K1arqPXNWjMo21EXnBPOPp36vB07FNRdD2geA=
|
||||
github.com/iancoleman/orderedmap v0.2.0 h1:sq1N/TFpYH++aViPcaKjys3bDClUEU7s5B+z6jq8pNA=
|
||||
github.com/iancoleman/orderedmap v0.2.0/go.mod h1:N0Wam8K1arqPXNWjMo21EXnBPOPp36vB07FNRdD2geA=
|
||||
github.com/invopop/jsonschema v0.6.0 h1:8e+xY8ZEn8gDHUYylSlLHy22P+SLeIRIHv3nM3hCbmY=
|
||||
github.com/invopop/jsonschema v0.6.0/go.mod h1:O9uiLokuu0+MGFlyiaqtWxwqJm41/+8Nj0lD7A36YH0=
|
||||
github.com/invopop/yaml v0.1.0/go.mod h1:2XuRLgs/ouIrW3XNzuNj7J3Nvu/Dig5MXvbCEdiBN3Q=
|
||||
github.com/invopop/yaml v0.2.0 h1:7zky/qH+O0DwAyoobXUqvVBwgBFRxKoQ/3FjcVpjTMY=
|
||||
github.com/invopop/yaml v0.2.0/go.mod h1:2XuRLgs/ouIrW3XNzuNj7J3Nvu/Dig5MXvbCEdiBN3Q=
|
||||
@@ -29,10 +27,10 @@ github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
|
||||
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
|
||||
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
|
||||
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
|
||||
github.com/labstack/echo/v4 v4.7.2 h1:Kv2/p8OaQ+M6Ex4eGimg9b9e6icoxA42JSlOR3msKtI=
|
||||
github.com/labstack/echo/v4 v4.7.2/go.mod h1:xkCDAdFCIf8jsFQ5NnbK7oqaF/yU1A1X20Ltm0OvSks=
|
||||
github.com/labstack/gommon v0.3.1 h1:OomWaJXm7xR6L1HmEtGyQf26TEn7V6X88mktX9kee9o=
|
||||
github.com/labstack/gommon v0.3.1/go.mod h1:uW6kP17uPlLJsD3ijUYn3/M5bAxtlZhMI6m3MFxTMTM=
|
||||
github.com/labstack/echo/v4 v4.9.1 h1:GliPYSpzGKlyOhqIbG8nmHBo3i1saKWFOgh41AN3b+Y=
|
||||
github.com/labstack/echo/v4 v4.9.1/go.mod h1:Pop5HLc+xoc4qhTZ1ip6C0RtP7Z+4VzRLWZZFKqbbjo=
|
||||
github.com/labstack/gommon v0.4.0 h1:y7cvthEAEbU0yHOf4axH8ZG2NH8knB9iNSoTO8dyIk8=
|
||||
github.com/labstack/gommon v0.4.0/go.mod h1:uW6kP17uPlLJsD3ijUYn3/M5bAxtlZhMI6m3MFxTMTM=
|
||||
github.com/mailru/easyjson v0.0.0-20190614124828-94de47d64c63/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc=
|
||||
github.com/mailru/easyjson v0.0.0-20190626092158-b2ccc519800e/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc=
|
||||
github.com/mailru/easyjson v0.7.6/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc=
|
||||
@@ -43,20 +41,26 @@ github.com/mattn/go-colorable v0.1.12 h1:jF+Du6AlPIjs2BiUiQlKOX0rt3SujHxPnksPKZb
|
||||
github.com/mattn/go-colorable v0.1.12/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb520KVy5xxl4=
|
||||
github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y=
|
||||
github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94=
|
||||
github.com/mia-platform/jsonschema v0.1.0 h1:tjQf7TaYROsAqk7SXTL+44TrfKk3bSEvhRGPS51IA5Y=
|
||||
github.com/mia-platform/jsonschema v0.1.0/go.mod h1:r2DJjPA/+6S+WPnXZt1xONMvO2b4hlhfXfUYV0po/Dk=
|
||||
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 h1:RWengNIwukTxcDr9M+97sNutRR1RKhG96O6jWumTTnw=
|
||||
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826/go.mod h1:TaXosZuwdSHYgviHp1DAtfrULt5eUgsSMsZf+YrPgl8=
|
||||
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWbfPhv4DMiApHyliiK5xCTNVSPiaAs=
|
||||
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
|
||||
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
|
||||
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
||||
github.com/stretchr/testify v1.3.1-0.20190311161405-34c6fa2dc709/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
||||
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
|
||||
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk=
|
||||
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
|
||||
github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk=
|
||||
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
|
||||
github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
|
||||
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
|
||||
github.com/valyala/fasttemplate v1.2.1 h1:TVEnxayobAdVkhQfrfes2IzOB6o+z4roRkPF52WA1u4=
|
||||
|
||||
@@ -3,7 +3,6 @@ package swagger_test
|
||||
import (
|
||||
"context"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"testing"
|
||||
@@ -171,7 +170,7 @@ func TestIntegration(t *testing.T) {
|
||||
func readBody(t *testing.T, requestBody io.ReadCloser) string {
|
||||
t.Helper()
|
||||
|
||||
body, err := ioutil.ReadAll(requestBody)
|
||||
body, err := io.ReadAll(requestBody)
|
||||
require.NoError(t, err)
|
||||
|
||||
return string(body)
|
||||
|
||||
16
main_test.go
16
main_test.go
@@ -4,9 +4,9 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"os"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
@@ -229,7 +229,7 @@ func TestGenerateAndExposeSwagger(t *testing.T) {
|
||||
require.True(t, strings.Contains(w.Result().Header.Get("content-type"), "application/json"))
|
||||
|
||||
body := readBody(t, w.Result().Body)
|
||||
actual, err := ioutil.ReadFile("testdata/users_employees.json")
|
||||
actual, err := os.ReadFile("testdata/users_employees.json")
|
||||
require.NoError(t, err)
|
||||
require.JSONEq(t, string(actual), body)
|
||||
})
|
||||
@@ -257,7 +257,7 @@ func TestGenerateAndExposeSwagger(t *testing.T) {
|
||||
require.True(t, strings.Contains(w.Result().Header.Get("content-type"), "application/json"))
|
||||
|
||||
body := readBody(t, w.Result().Body)
|
||||
actual, err := ioutil.ReadFile("testdata/users_employees.json")
|
||||
actual, err := os.ReadFile("testdata/users_employees.json")
|
||||
require.NoError(t, err)
|
||||
require.JSONEq(t, string(actual), body)
|
||||
})
|
||||
@@ -284,7 +284,7 @@ func TestGenerateAndExposeSwagger(t *testing.T) {
|
||||
require.True(t, strings.Contains(w.Result().Header.Get("content-type"), "text/plain"))
|
||||
|
||||
body := readBody(t, w.Result().Body)
|
||||
expected, err := ioutil.ReadFile("testdata/users_employees.yaml")
|
||||
expected, err := os.ReadFile("testdata/users_employees.yaml")
|
||||
require.NoError(t, err)
|
||||
require.YAMLEq(t, string(expected), body, string(body))
|
||||
})
|
||||
@@ -312,7 +312,7 @@ func TestGenerateAndExposeSwagger(t *testing.T) {
|
||||
require.True(t, strings.Contains(w.Result().Header.Get("content-type"), "text/plain"))
|
||||
|
||||
body := readBody(t, w.Result().Body)
|
||||
expected, err := ioutil.ReadFile("testdata/users_employees.yaml")
|
||||
expected, err := os.ReadFile("testdata/users_employees.yaml")
|
||||
require.NoError(t, err)
|
||||
require.YAMLEq(t, string(expected), body, string(body))
|
||||
})
|
||||
@@ -367,7 +367,7 @@ func TestGenerateAndExposeSwagger(t *testing.T) {
|
||||
require.True(t, strings.Contains(w.Result().Header.Get("content-type"), "application/json"))
|
||||
|
||||
body := readBody(t, w.Result().Body)
|
||||
actual, err := ioutil.ReadFile("testdata/subrouter.json")
|
||||
actual, err := os.ReadFile("testdata/subrouter.json")
|
||||
require.NoError(t, err)
|
||||
require.JSONEq(t, string(actual), body)
|
||||
})
|
||||
@@ -403,7 +403,7 @@ func TestGenerateAndExposeSwagger(t *testing.T) {
|
||||
require.True(t, strings.Contains(w.Result().Header.Get("content-type"), "application/json"))
|
||||
|
||||
body := readBody(t, w.Result().Body)
|
||||
actual, err := ioutil.ReadFile("testdata/router_with_prefix.json")
|
||||
actual, err := os.ReadFile("testdata/router_with_prefix.json")
|
||||
require.NoError(t, err)
|
||||
require.JSONEq(t, string(actual), body)
|
||||
})
|
||||
@@ -412,7 +412,7 @@ func TestGenerateAndExposeSwagger(t *testing.T) {
|
||||
func readBody(t *testing.T, requestBody io.ReadCloser) string {
|
||||
t.Helper()
|
||||
|
||||
body, err := ioutil.ReadAll(requestBody)
|
||||
body, err := io.ReadAll(requestBody)
|
||||
require.NoError(t, err)
|
||||
|
||||
return string(body)
|
||||
|
||||
4
route.go
4
route.go
@@ -9,7 +9,7 @@ import (
|
||||
|
||||
"github.com/davidebianchi/gswagger/apirouter"
|
||||
"github.com/getkin/kin-openapi/openapi3"
|
||||
"github.com/invopop/jsonschema"
|
||||
"github.com/mia-platform/jsonschema"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -73,6 +73,7 @@ type ContentValue struct {
|
||||
|
||||
// Definitions of the route.
|
||||
type Definitions struct {
|
||||
Tags []string
|
||||
PathParams ParameterValue
|
||||
Querystring ParameterValue
|
||||
Headers ParameterValue
|
||||
@@ -92,6 +93,7 @@ const (
|
||||
func (r Router) AddRoute(method string, path string, handler apirouter.HandlerFunc, schema Definitions) (interface{}, error) {
|
||||
operation := NewOperation()
|
||||
operation.Responses = make(openapi3.Responses)
|
||||
operation.Tags = schema.Tags
|
||||
|
||||
err := r.resolveRequestBodySchema(schema.RequestBody, operation)
|
||||
if err != nil {
|
||||
|
||||
@@ -3,9 +3,9 @@ package swagger
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/davidebianchi/gswagger/apirouter"
|
||||
@@ -422,6 +422,17 @@ func TestAddRoutes(t *testing.T) {
|
||||
testMethod: http.MethodPost,
|
||||
fixturesPath: "testdata/oneOf.json",
|
||||
},
|
||||
{
|
||||
name: "schema with tags",
|
||||
routes: func(t *testing.T, router *Router) {
|
||||
_, err := router.AddRoute(http.MethodGet, "/users", okHandler, Definitions{
|
||||
Tags: []string{"Tag1", "Tag2"},
|
||||
})
|
||||
require.NoError(t, err)
|
||||
},
|
||||
testPath: "/users",
|
||||
fixturesPath: "testdata/tags.json",
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
@@ -466,7 +477,7 @@ func TestAddRoutes(t *testing.T) {
|
||||
require.Equal(t, http.StatusOK, w.Result().StatusCode)
|
||||
|
||||
body := readBody(t, w.Result().Body)
|
||||
expected, err := ioutil.ReadFile(test.fixturesPath)
|
||||
expected, err := os.ReadFile(test.fixturesPath)
|
||||
require.NoError(t, err)
|
||||
require.JSONEq(t, string(expected), body, "actual json data: %s", body)
|
||||
})
|
||||
@@ -645,6 +656,14 @@ func TestResolveResponsesSchema(t *testing.T) {
|
||||
type TestStruct struct {
|
||||
Message string `json:"message,omitempty"`
|
||||
}
|
||||
type NestedTestStruct struct {
|
||||
Notification string `json:"notification"`
|
||||
NestedMapOfStructs map[string]TestStruct `json:"nestedMapOfStructs,omitempty"`
|
||||
}
|
||||
type ComplexTestStruct struct {
|
||||
Communication string `json:"communication"`
|
||||
MapOfStructs map[string]NestedTestStruct `json:"mapOfStructs,omitempty"`
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
responsesSchema map[int]ContentValue
|
||||
@@ -687,6 +706,79 @@ func TestResolveResponsesSchema(t *testing.T) {
|
||||
}
|
||||
}`,
|
||||
},
|
||||
{
|
||||
name: "with complex schema",
|
||||
responsesSchema: map[int]ContentValue{
|
||||
200: {
|
||||
Content: Content{
|
||||
jsonType: {Value: &ComplexTestStruct{
|
||||
Communication: "myCommunication",
|
||||
MapOfStructs: map[string]NestedTestStruct{
|
||||
"myProperty": {
|
||||
Notification: "myNotification",
|
||||
NestedMapOfStructs: map[string]TestStruct{
|
||||
"myNestedProperty": {
|
||||
Message: "myMessage",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}},
|
||||
},
|
||||
},
|
||||
},
|
||||
expectedErr: nil,
|
||||
expectedJSON: `{
|
||||
"responses": {
|
||||
"200": {
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"additionalProperties": false,
|
||||
"properties": {
|
||||
"communication": {
|
||||
"type": "string"
|
||||
},
|
||||
"mapOfStructs": {
|
||||
"additionalProperties": {
|
||||
"additionalProperties": false,
|
||||
"properties": {
|
||||
"nestedMapOfStructs": {
|
||||
"additionalProperties": {
|
||||
"additionalProperties": false,
|
||||
"properties": {
|
||||
"message": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"type": "object"
|
||||
},
|
||||
"type": "object"
|
||||
},
|
||||
"notification": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"notification"
|
||||
],
|
||||
"type": "object"
|
||||
},
|
||||
"type": "object"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"communication"
|
||||
],
|
||||
"type": "object"
|
||||
}
|
||||
}
|
||||
},
|
||||
"description": ""
|
||||
}
|
||||
}
|
||||
}`,
|
||||
},
|
||||
{
|
||||
name: "with more status codes",
|
||||
responsesSchema: map[int]ContentValue{
|
||||
|
||||
20
testdata/tags.json
vendored
Normal file
20
testdata/tags.json
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
{
|
||||
"components": {},
|
||||
"info": {
|
||||
"title": "test swagger title",
|
||||
"version": "test swagger version"
|
||||
},
|
||||
"openapi": "3.0.0",
|
||||
"paths": {
|
||||
"/users": {
|
||||
"get": {
|
||||
"tags": ["Tag1", "Tag2"],
|
||||
"responses": {
|
||||
"default": {
|
||||
"description": ""
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user