From 1dce309d43576c221478f594ab84cf9a670a3bfa Mon Sep 17 00:00:00 2001 From: Viacheslav Poturaev Date: Sun, 14 Jun 2020 01:49:03 +0200 Subject: [PATCH] Update jsonschema-go library (#10) --- go.mod | 2 +- go.sum | 4 ++-- openapi3/_testdata/openapi_req_array.json | 3 ++- openapi3/example_test.go | 4 ++-- openapi3/reflect.go | 4 ++++ openapi3/reflect_test.go | 12 ++++++------ 6 files changed, 17 insertions(+), 12 deletions(-) diff --git a/go.mod b/go.mod index cefa517..ea91b30 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,7 @@ go 1.13 require ( github.com/stretchr/testify v1.5.1 github.com/swaggest/assertjson v1.0.0 - github.com/swaggest/jsonschema-go v0.3.2 + github.com/swaggest/jsonschema-go v0.3.4 github.com/swaggest/refl v0.1.3 github.com/swaggest/swgen v0.6.23 gopkg.in/yaml.v2 v2.3.0 diff --git a/go.sum b/go.sum index b6c1254..1f24f90 100644 --- a/go.sum +++ b/go.sum @@ -54,8 +54,8 @@ github.com/swaggest/assertjson v1.0.0/go.mod h1:mE5ltBbrB+Ya8Xar5OMITxya76vwLZMo github.com/swaggest/jsonschema-go v0.2.1 h1:SVg+zXQ46w6ewR7jZDRVbpKKC+V7Y6Xn/teC2pRS2bM= github.com/swaggest/jsonschema-go v0.2.1/go.mod h1:QFauBdPTrU1UltwocM5FzOWnVjVVtcWkJWG3NlK9sV0= github.com/swaggest/jsonschema-go v0.2.4/go.mod h1:m4VV88Gbi7lCrt9ckJzigK1rMlEeFjdZUkJr1o5MnDE= -github.com/swaggest/jsonschema-go v0.3.2 h1:k0s1XsyoXyY5hDY1ZHVEig8ROZTqPnEdKK4IhQtlWSw= -github.com/swaggest/jsonschema-go v0.3.2/go.mod h1:TrWgbug4p2ZgcxnHDz+CvYvEtJ5KckL/XOV4mSR6FGw= +github.com/swaggest/jsonschema-go v0.3.4 h1:VoD8ux21OyoSPvRHbWNE1I5SQZ6T6L+WLd2GWS+90X4= +github.com/swaggest/jsonschema-go v0.3.4/go.mod h1:TrWgbug4p2ZgcxnHDz+CvYvEtJ5KckL/XOV4mSR6FGw= github.com/swaggest/openapi-go v0.1.3/go.mod h1:Zx4ZgJ7XvlFH9wCOHE7u8RAjLfiHAnCHeaD5kUDujVM= github.com/swaggest/refl v0.1.0 h1:mz3skba8ewcPmxDryM9rETv4fSuAX4GqNxTuDfPyUM0= github.com/swaggest/refl v0.1.0/go.mod h1:kmYWhxNEvjfRDdMRqpaR/vLULk/SotJs9HFUCIVMK8o= diff --git a/openapi3/_testdata/openapi_req_array.json b/openapi3/_testdata/openapi_req_array.json index cef15c8..147a637 100644 --- a/openapi3/_testdata/openapi_req_array.json +++ b/openapi3/_testdata/openapi_req_array.json @@ -14,7 +14,8 @@ "type": "array", "items": { "$ref": "#/components/schemas/Openapi3TestGetReq" - } + }, + "nullable": true } } } diff --git a/openapi3/example_test.go b/openapi3/example_test.go index a349fb2..ee462b4 100644 --- a/openapi3/example_test.go +++ b/openapi3/example_test.go @@ -31,7 +31,7 @@ func ExampleReflector_SetJSONResponse() { Items []struct { Count uint `json:"count"` Name string `json:"name"` - } `json:"items"` + } `json:"items,omitempty"` } type resp struct { @@ -40,7 +40,7 @@ func ExampleReflector_SetJSONResponse() { Items []struct { Count uint `json:"count"` Name string `json:"name"` - } `json:"items"` + } `json:"items,omitempty"` UpdatedAt time.Time `json:"updated_at"` } diff --git a/openapi3/reflect.go b/openapi3/reflect.go index 417343d..303abc5 100644 --- a/openapi3/reflect.go +++ b/openapi3/reflect.go @@ -169,6 +169,10 @@ func (r *Reflector) parseParametersIn(o *Operation, input interface{}, in Parame s := SchemaOrRef{} s.FromJSONSchema(propertySchema.ToSchemaOrBool()) + if s.Schema != nil && s.Schema.Nullable != nil { + s.Schema.Nullable = nil + } + p := Parameter{ Name: name, In: in, diff --git a/openapi3/reflect_test.go b/openapi3/reflect_test.go index 284aab6..b9bfac8 100644 --- a/openapi3/reflect_test.go +++ b/openapi3/reflect_test.go @@ -46,14 +46,14 @@ type Resp struct { Foo string `json:"foo" default:"baz" required:"true" pattern:"\\d+"` Bar float64 `json:"bar" description:"This is Bar."` } `json:"info"` - Parent *Resp `json:"parent"` - Map map[string]int64 `json:"map"` - MapOfAnything map[string]interface{} `json:"mapOfAnything"` - ArrayOfAnything []interface{} `json:"arrayOfAnything"` + Parent *Resp `json:"parent,omitempty"` + Map map[string]int64 `json:"map,omitempty"` + MapOfAnything map[string]interface{} `json:"mapOfAnything,omitempty"` + ArrayOfAnything []interface{} `json:"arrayOfAnything,omitempty"` Whatever interface{} `json:"whatever"` NullableWhatever *interface{} `json:"nullableWhatever,omitempty"` - RecursiveArray []WeirdResp `json:"recursiveArray"` - RecursiveStructArray []Resp `json:"recursiveStructArray"` + RecursiveArray []WeirdResp `json:"recursiveArray,omitempty"` + RecursiveStructArray []Resp `json:"recursiveStructArray,omitempty"` CustomType ISOWeek `json:"customType"` UUID UUID `json:"uuid"` }