Skip to content

Commit

Permalink
Updates kin/openapi to v0.126.0
Browse files Browse the repository at this point in the history
  • Loading branch information
EwenQuim committed Jul 17, 2024
1 parent 4795d10 commit 6cd4022
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 33 deletions.
14 changes: 7 additions & 7 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ module github.com/go-fuego/fuego
go 1.22.2

require (
github.com/getkin/kin-openapi v0.123.0
github.com/go-playground/validator/v10 v10.20.0
github.com/getkin/kin-openapi v0.126.0
github.com/go-playground/validator/v10 v10.22.0
github.com/golang-jwt/jwt/v5 v5.2.1
github.com/gomarkdown/markdown v0.0.0-20231222211730-1d6d20845b47
github.com/gomarkdown/markdown v0.0.0-20240626202925-2eda941fd024
github.com/gorilla/schema v1.4.1
github.com/hashicorp/golang-lru/v2 v2.0.7
github.com/stretchr/testify v1.9.0
Expand All @@ -27,8 +27,8 @@ require (
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 // indirect
github.com/perimeterx/marshmallow v1.1.5 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
golang.org/x/crypto v0.23.0 // indirect
golang.org/x/net v0.25.0 // indirect
golang.org/x/sys v0.20.0 // indirect
golang.org/x/text v0.15.0 // indirect
golang.org/x/crypto v0.25.0 // indirect
golang.org/x/net v0.27.0 // indirect
golang.org/x/sys v0.22.0 // indirect
golang.org/x/text v0.16.0 // indirect
)
14 changes: 14 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ github.com/gabriel-vasile/mimetype v1.4.4 h1:QjV6pZ7/XZ7ryI2KuyeEDE8wnh7fHP9YnQy
github.com/gabriel-vasile/mimetype v1.4.4/go.mod h1:JwLei5XPtWdGiMFB5Pjle1oEeoSeEuJfJE+TtfvdB/s=
github.com/getkin/kin-openapi v0.123.0 h1:zIik0mRwFNLyvtXK274Q6ut+dPh6nlxBp0x7mNrPhs8=
github.com/getkin/kin-openapi v0.123.0/go.mod h1:wb1aSZA/iWmorQP9KTAS/phLj/t17B5jT7+fS8ed9NM=
github.com/getkin/kin-openapi v0.126.0 h1:c2cSgLnAsS0xYfKsgt5oBV6MYRM/giU8/RtwUY4wyfY=
github.com/getkin/kin-openapi v0.126.0/go.mod h1:7mONz8IwmSRg6RttPu6v8U/OJ+gr+J99qSFNjPGSQqw=
github.com/go-openapi/jsonpointer v0.21.0 h1:YgdVicSA9vH5RiHs9TZW5oyafXZFc6+2Vc1rr/O9oNQ=
github.com/go-openapi/jsonpointer v0.21.0/go.mod h1:IUyH9l/+uyhIYQ/PXVA41Rexl+kOkAPDdXEYns6fzUY=
github.com/go-openapi/swag v0.23.0 h1:vsEVJDUo2hPJ2tu0/Xc+4noaxyEffXNIs3cOULZ+GrE=
Expand All @@ -16,12 +18,16 @@ github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJn
github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY=
github.com/go-playground/validator/v10 v10.20.0 h1:K9ISHbSaI0lyB2eWMPJo+kOS/FBExVwjEviJTixqxL8=
github.com/go-playground/validator/v10 v10.20.0/go.mod h1:dbuPbCMFw/DrkbEynArYaCwl3amGuJotoKCe95atGMM=
github.com/go-playground/validator/v10 v10.22.0 h1:k6HsTZ0sTnROkhS//R0O+55JgM8C4Bx7ia+JlgcnOao=
github.com/go-playground/validator/v10 v10.22.0/go.mod h1:dbuPbCMFw/DrkbEynArYaCwl3amGuJotoKCe95atGMM=
github.com/go-test/deep v1.0.8 h1:TDsG77qcSprGbC6vTN8OuXp5g+J+b5Pcguhf7Zt61VM=
github.com/go-test/deep v1.0.8/go.mod h1:5C2ZWiW0ErCdrYzpqxLbTX7MG14M9iiw8DgHncVwcsE=
github.com/golang-jwt/jwt/v5 v5.2.1 h1:OuVbFODueb089Lh128TAcimifWaLhJwVflnrgM17wHk=
github.com/golang-jwt/jwt/v5 v5.2.1/go.mod h1:pqrtFR0X4osieyHYxtmOUWsAWrfe1Q5UVIyoH402zdk=
github.com/gomarkdown/markdown v0.0.0-20231222211730-1d6d20845b47 h1:k4Tw0nt6lwro3Uin8eqoET7MDA4JnT8YgbCjc/g5E3k=
github.com/gomarkdown/markdown v0.0.0-20231222211730-1d6d20845b47/go.mod h1:JDGcbDT52eL4fju3sZ4TeHGsQwhG9nbDV21aMyhwPoA=
github.com/gomarkdown/markdown v0.0.0-20240626202925-2eda941fd024 h1:saBP362Qm7zDdDXqv61kI4rzhmLFq3Z1gx34xpl6cWE=
github.com/gomarkdown/markdown v0.0.0-20240626202925-2eda941fd024/go.mod h1:JDGcbDT52eL4fju3sZ4TeHGsQwhG9nbDV21aMyhwPoA=
github.com/gorilla/schema v1.4.1 h1:jUg5hUjCSDZpNGLuXQOgIWGdlgrIdYvgQ0wZtdK1M3E=
github.com/gorilla/schema v1.4.1/go.mod h1:Dg5SSm5PV60mhF2NFaTV1xuYYj8tV8NOPRo4FggUMnM=
github.com/hashicorp/golang-lru/v2 v2.0.7 h1:a+bsQ5rvGLjzHuww6tVxozPZFVghXaHOwFs4luLUK2k=
Expand Down Expand Up @@ -52,12 +58,20 @@ github.com/ugorji/go/codec v1.2.7 h1:YPXUKf7fYbp/y8xloBqZOw2qaVggbfwMlI8WM3wZUJ0
github.com/ugorji/go/codec v1.2.7/go.mod h1:WGN1fab3R1fzQlVQTkfxVtIBhWDRqOviHU95kRgeqEY=
golang.org/x/crypto v0.23.0 h1:dIJU/v2J8Mdglj/8rJ6UUOM3Zc9zLZxVZwwxMooUSAI=
golang.org/x/crypto v0.23.0/go.mod h1:CKFgDieR+mRhux2Lsu27y0fO304Db0wZe70UKqHu0v8=
golang.org/x/crypto v0.25.0 h1:ypSNr+bnYL2YhwoMt2zPxHFmbAN1KZs/njMG3hxUp30=
golang.org/x/crypto v0.25.0/go.mod h1:T+wALwcMOSE0kXgUAnPAHqTLW+XHgcELELW8VaDgm/M=
golang.org/x/net v0.25.0 h1:d/OCCoBEUq33pjydKrGQhw7IlUPI2Oylr+8qLx49kac=
golang.org/x/net v0.25.0/go.mod h1:JkAGAh7GEvH74S6FOH42FLoXpXbE/aqXSrIQjXgsiwM=
golang.org/x/net v0.27.0 h1:5K3Njcw06/l2y9vpGCSdcxWOYHOUk3dVNGDXN+FvAys=
golang.org/x/net v0.27.0/go.mod h1:dDi0PyhWNoiUOrAS8uXv/vnScO4wnHQO4mj9fn/RytE=
golang.org/x/sys v0.20.0 h1:Od9JTbYCk261bKm4M/mw7AklTlFYIa0bIp9BgSm1S8Y=
golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.22.0 h1:RI27ohtqKCnwULzJLqkv897zojh5/DwS/ENaMzUOaWI=
golang.org/x/sys v0.22.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/text v0.15.0 h1:h1V/4gjBv8v9cjcR6+AR5+/cIYK5N/WAgiv4xlsEtAk=
golang.org/x/text v0.15.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
golang.org/x/text v0.16.0 h1:a94ExnEXNtEwYLGJSIUxnWoxoRz/ZcCsV63ROupILh4=
golang.org/x/text v0.16.0/go.mod h1:GhwF1Be+LQoKShO3cGOHzqOgRrGaYc9AvblQOmPVHnI=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
Expand Down
7 changes: 2 additions & 5 deletions openapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,6 @@ func RegisterOpenAPIOperation[T, B any](s *Server, method, path string) (*openap
}

responseSchema := schemaTagFromType(s, *new(T))
slog.Info("responseSchema", "responseSchema", fmt.Sprintf("%#v", responseSchema), "new", *new(T))
content := openapi3.NewContentWithSchemaRef(&responseSchema.SchemaRef, []string{"application/json"})
response := openapi3.NewResponse().
WithDescription("OK").
Expand Down Expand Up @@ -247,10 +246,8 @@ func dive(s *Server, t reflect.Type, tag schemaTag, maxDepth int) schemaTag {
case reflect.Slice, reflect.Array:
item := dive(s, t.Elem(), tag, maxDepth-1)
tag.name = item.name
tag.Value = &openapi3.Schema{
Type: "array",
Items: &item.SchemaRef,
}
tag.Value = openapi3.NewArraySchema()
tag.Value.Items = &item.SchemaRef
return tag

default:
Expand Down
43 changes: 22 additions & 21 deletions openapi_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"os"
"testing"

"github.com/getkin/kin-openapi/openapi3"
"github.com/stretchr/testify/require"
)

Expand All @@ -28,7 +29,7 @@ type testCaseForTagType[V any] struct {
inputType V

expectedTagValue string
expectedTagValueType string
expectedTagValueType *openapi3.Types
}

func Test_tagFromType(t *testing.T) {
Expand All @@ -50,55 +51,55 @@ func Test_tagFromType(t *testing.T) {
inputType: MyStruct{},

expectedTagValue: "MyStruct",
expectedTagValueType: "object",
expectedTagValueType: &openapi3.Types{"object"},
},
{
name: "is_pointer",
description: "",
inputType: &MyStruct{},

expectedTagValue: "MyStruct",
expectedTagValueType: "object",
expectedTagValueType: &openapi3.Types{"object"},
},
{
name: "is_array",
description: "",
inputType: []MyStruct{},

expectedTagValue: "MyStruct",
expectedTagValueType: "array",
expectedTagValueType: &openapi3.Types{"array"},
},
{
name: "is_reference_to_array",
description: "",
inputType: &[]MyStruct{},

expectedTagValue: "MyStruct",
expectedTagValueType: "array",
expectedTagValueType: &openapi3.Types{"array"},
},
{
name: "is_deeply_nested",
description: "behind 4 pointers",
inputType: new(DeeplyNested),

expectedTagValue: "MyStruct",
expectedTagValueType: "array",
expectedTagValueType: &openapi3.Types{"array"},
},
{
name: "5_pointers",
description: "behind 5 pointers",
inputType: *new(MoreDeeplyNested),

expectedTagValue: "MyStruct",
expectedTagValueType: "array",
expectedTagValueType: &openapi3.Types{"array"},
},
{
name: "6_pointers",
description: "behind 6 pointers",
inputType: new(MoreDeeplyNested),

expectedTagValue: "default",
expectedTagValueType: "array",
expectedTagValueType: &openapi3.Types{"array"},
},
{
name: "7_pointers",
Expand All @@ -113,87 +114,87 @@ func Test_tagFromType(t *testing.T) {
inputType: "string",

expectedTagValue: "string",
expectedTagValueType: "string",
expectedTagValueType: &openapi3.Types{"string"},
},
{
name: "new_string",
description: "",
inputType: new(string),

expectedTagValue: "string",
expectedTagValueType: "string",
expectedTagValueType: &openapi3.Types{"string"},
},
{
name: "string_array",
description: "",
inputType: []string{},

expectedTagValue: "string",
expectedTagValueType: "array",
expectedTagValueType: &openapi3.Types{"array"},
},
{
name: "pointer_string_array",
description: "",
inputType: &[]string{},

expectedTagValue: "string",
expectedTagValueType: "array",
expectedTagValueType: &openapi3.Types{"array"},
},
{
name: "DataOrTemplate",
description: "",
inputType: DataOrTemplate[MyStruct]{},

expectedTagValue: "MyStruct",
expectedTagValueType: "object",
expectedTagValueType: &openapi3.Types{"object"},
},
{
name: "ptr to DataOrTemplate",
description: "",
inputType: &DataOrTemplate[MyStruct]{},

expectedTagValue: "MyStruct",
expectedTagValueType: "object",
expectedTagValueType: &openapi3.Types{"object"},
},
{
name: "DataOrTemplate of an array",
description: "",
inputType: DataOrTemplate[[]MyStruct]{},

expectedTagValue: "MyStruct",
expectedTagValueType: "array",
expectedTagValueType: &openapi3.Types{"array"},
},
{
name: "ptr to DataOrTemplate of an array of ptr",
description: "",
inputType: &DataOrTemplate[[]*MyStruct]{},

expectedTagValue: "MyStruct",
expectedTagValueType: "array",
expectedTagValueType: &openapi3.Types{"array"},
},
{
name: "ptr to DataOrTemplate of a ptr to an array",
description: "",
inputType: &DataOrTemplate[*[]MyStruct]{},

expectedTagValue: "MyStruct",
expectedTagValueType: "array",
expectedTagValueType: &openapi3.Types{"array"},
},
{
name: "ptr to DataOrTemplate of a ptr to an array of ptr",
description: "",
inputType: &DataOrTemplate[*[]*MyStruct]{},

expectedTagValue: "default",
expectedTagValueType: "array",
expectedTagValueType: &openapi3.Types{"array"},
},
}

for _, tc := range tcs {
t.Run(tc.name, func(t *testing.T) {
tag := schemaTagFromType(s, tc.inputType)
require.Equal(t, tc.expectedTagValue, tag.name, tc.description)
if tc.expectedTagValueType != "" {
if tc.expectedTagValueType != nil {
require.NotNil(t, tag.Value)
require.Equal(t, tc.expectedTagValueType, tag.Value.Type, tc.description)
}
Expand All @@ -217,12 +218,12 @@ func TestServer_generateOpenAPI(t *testing.T) {
require.NotNil(t, document.Paths.Find("/"))
require.Nil(t, document.Paths.Find("/unknown"))
require.NotNil(t, document.Paths.Find("/post"))
require.Equal(t, document.Paths.Find("/post").Post.Responses.Value("200").Value.Content["application/json"].Schema.Value.Type, "array")
require.Equal(t, document.Paths.Find("/post").Post.Responses.Value("200").Value.Content["application/json"].Schema.Value.Type, &openapi3.Types{"array"})
require.Equal(t, document.Paths.Find("/post").Post.Responses.Value("200").Value.Content["application/json"].Schema.Value.Items.Ref, "#/components/schemas/MyStruct")
require.NotNil(t, document.Paths.Find("/post/{id}").Get.Responses.Value("200"))
require.NotNil(t, document.Paths.Find("/post/{id}").Get.Responses.Value("200").Value.Content["application/json"])
require.Nil(t, document.Paths.Find("/post/{id}").Get.Responses.Value("200").Value.Content["application/json"].Schema.Value.Properties["unknown"])
require.Equal(t, document.Paths.Find("/post/{id}").Get.Responses.Value("200").Value.Content["application/json"].Schema.Value.Properties["quantity"].Value.Type, "integer")
require.Equal(t, document.Paths.Find("/post/{id}").Get.Responses.Value("200").Value.Content["application/json"].Schema.Value.Properties["quantity"].Value.Type, &openapi3.Types{"integer"})

t.Run("openapi doc is available through a route", func(t *testing.T) {
w := httptest.NewRecorder()
Expand Down

0 comments on commit 6cd4022

Please sign in to comment.