15 Commits

Author SHA1 Message Date
Davide Bianchi
d7b5134200 Upgrade version to v0.6.1 2022-11-17 09:34:39 +01:00
Davide Bianchi
31e40cedfd Merge pull request #90 from davidebianchi/fix/remove-deprecated-lib 2022-11-17 09:34:11 +01:00
Davide Bianchi
6f3dcc578c update go version in github actions 2022-11-17 09:32:13 +01:00
Davide Bianchi
45cf385dec docs: update CHANGELOG 2022-11-17 09:30:28 +01:00
Davide Bianchi
e5f3c438b4 fix: remove use of the deprecated io/ioutil lib 2022-11-17 09:29:43 +01:00
Federico Maggi
047317ef17 Merge pull request #89 from FilippoRezzonico/fix/RJMR-254-jsonschema-lib-without-patternProperties
Fix/rjmr 254 jsonschema lib without pattern properties
2022-11-16 18:40:44 +01:00
filippo.rezzonico
b007e57092 updated changelog 2022-11-16 18:27:28 +01:00
filippo.rezzonico
6c9d0e579f added test 2022-11-16 18:24:10 +01:00
filippo.rezzonico
f84327d424 changed jsonschema 2022-11-16 18:22:24 +01:00
Davide Bianchi
085abe98d1 Merge pull request #83 from davidebianchi/dependabot/go_modules/github.com/stretchr/testify-1.8.1 2022-11-06 12:08:46 +01:00
Davide Bianchi
c5fff8f982 Merge pull request #84 from davidebianchi/dependabot/go_modules/github.com/getkin/kin-openapi-0.107.0 2022-11-06 12:08:37 +01:00
Davide Bianchi
fee2444c96 Merge pull request #80 from davidebianchi/dependabot/go_modules/github.com/labstack/echo/v4-4.9.1 2022-11-06 12:08:21 +01:00
dependabot[bot]
2939f1027d chore(deps): bump github.com/getkin/kin-openapi from 0.103.0 to 0.107.0
Bumps [github.com/getkin/kin-openapi](https://github.com/getkin/kin-openapi) from 0.103.0 to 0.107.0.
- [Release notes](https://github.com/getkin/kin-openapi/releases)
- [Commits](https://github.com/getkin/kin-openapi/compare/v0.103.0...v0.107.0)

---
updated-dependencies:
- dependency-name: github.com/getkin/kin-openapi
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-10-28 03:10:41 +00:00
dependabot[bot]
3a4118844e chore(deps): bump github.com/stretchr/testify from 1.8.0 to 1.8.1
Bumps [github.com/stretchr/testify](https://github.com/stretchr/testify) from 1.8.0 to 1.8.1.
- [Release notes](https://github.com/stretchr/testify/releases)
- [Commits](https://github.com/stretchr/testify/compare/v1.8.0...v1.8.1)

---
updated-dependencies:
- dependency-name: github.com/stretchr/testify
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-10-24 03:11:45 +00:00
dependabot[bot]
3e72099700 chore(deps): bump github.com/labstack/echo/v4 from 4.9.0 to 4.9.1
Bumps [github.com/labstack/echo/v4](https://github.com/labstack/echo) from 4.9.0 to 4.9.1.
- [Release notes](https://github.com/labstack/echo/releases)
- [Changelog](https://github.com/labstack/echo/blob/master/CHANGELOG.md)
- [Commits](https://github.com/labstack/echo/compare/v4.9.0...v4.9.1)

---
updated-dependencies:
- dependency-name: github.com/labstack/echo/v4
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-10-13 03:09:18 +00:00
10 changed files with 121 additions and 30 deletions

View File

@@ -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

View File

@@ -7,6 +7,13 @@ 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

View File

@@ -13,7 +13,6 @@ all: test
.PHONY: test
test:
go test ./... -coverprofile coverage.out
$(MAKE) clean
.PHONY: version
version:

View File

@@ -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
View File

@@ -3,15 +3,15 @@ module github.com/davidebianchi/gswagger
go 1.17
require (
github.com/getkin/kin-openapi v0.103.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.9.0
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
View File

@@ -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.103.0 h1:F5wAtaQvPWxKCAYZ69LgHAThgu16p4u41VQtbn1U8LA=
github.com/getkin/kin-openapi v0.103.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.9.0 h1:wPOF1CE6gvt/kmbMR4dGzWvHMPT+sAEUJOwOTtvITVY=
github.com/labstack/echo/v4 v4.9.0/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=

View File

@@ -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)

View File

@@ -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)

View File

@@ -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 (

View File

@@ -3,9 +3,9 @@ package swagger
import (
"context"
"fmt"
"io/ioutil"
"net/http"
"net/http/httptest"
"os"
"testing"
"github.com/davidebianchi/gswagger/apirouter"
@@ -477,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)
})
@@ -656,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
@@ -698,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{