diff --git a/go.mod b/go.mod index 9ecc336f..3a425319 100644 --- a/go.mod +++ b/go.mod @@ -3,15 +3,15 @@ module github.com/MarkRosemaker/openapi-codegen go 1.27 require ( - github.com/MarkRosemaker/cassette v0.0.0-20261126020934-32283f081e24 + github.com/MarkRosemaker/cassette v0.0.0-20261126230209-577d7f661401 github.com/MarkRosemaker/errpath v0.0.0-20261118230255-99e20cb3445a github.com/MarkRosemaker/openapi v0.0.0-20261126020940-b4a1ac5f1801 github.com/MarkRosemaker/openapi-compress v0.0.0-20261126021444-b9b31c694973 github.com/MarkRosemaker/openapi-edit v0.0.0-20261126021107-af2eb25df397 - github.com/MarkRosemaker/openapi-flatten v0.0.0-20261126034255-0c495ba4f188 + github.com/MarkRosemaker/openapi-flatten v0.0.0-20261126230236-930e862e696c github.com/MarkRosemaker/ordmap v0.0.0-20261124050216-f3096eb875be github.com/ettle/strcase v0.2.0 - github.com/go-api-libs/api v0.0.0-20261125182139-0f507257dcd7 + github.com/go-api-libs/api v0.0.0-20261126230233-f729199ffb88 github.com/spf13/afero v1.15.0 mvdan.cc/gofumpt v0.12.0 ) diff --git a/go.sum b/go.sum index 52efe3db..8760389f 100644 --- a/go.sum +++ b/go.sum @@ -1,7 +1,7 @@ cloud.google.com/go v0.123.0 h1:2NAUJwPR47q+E35uaJeYoNhuNEM9kM8SjgRgdeOJUSE= cloud.google.com/go v0.123.0/go.mod h1:xBoMV08QcqUGuPW65Qfm1o9Y4zKZBpGS+7bImXLTAZU= -github.com/MarkRosemaker/cassette v0.0.0-20261126020934-32283f081e24 h1:UI3qHWOSyJa0JEBybE7zih14KSdT818AGN6YHqFh1bs= -github.com/MarkRosemaker/cassette v0.0.0-20261126020934-32283f081e24/go.mod h1:TbKuVXTWnsYOmDrmhEqsDaBBjzOVVRd3QblXQNFe0ZE= +github.com/MarkRosemaker/cassette v0.0.0-20261126230209-577d7f661401 h1:2/81bS/PFdF1wK6Y2XrytlC2m2jXe83Sys+hLNDKASg= +github.com/MarkRosemaker/cassette v0.0.0-20261126230209-577d7f661401/go.mod h1:TbKuVXTWnsYOmDrmhEqsDaBBjzOVVRd3QblXQNFe0ZE= github.com/MarkRosemaker/errpath v0.0.0-20261118230255-99e20cb3445a h1:C7Oyg94gPC6/nfCR8ev9FqyxQb5d+GEpU4Oz+rGcoww= github.com/MarkRosemaker/errpath v0.0.0-20261118230255-99e20cb3445a/go.mod h1:VnXpUlsS3n1gSToedcQl2FCARGoA16CyitbCanUIv+I= github.com/MarkRosemaker/json2yaml v0.0.0-20261118230255-853c75cf2bf9 h1:NVTLiOVHTQ/PSq3ihG3kT/P1UqNjJiBHHCGbgNq2rP8= @@ -18,8 +18,8 @@ github.com/MarkRosemaker/openapi-edit v0.0.0-20261126021107-af2eb25df397 h1:ubJ+ github.com/MarkRosemaker/openapi-edit v0.0.0-20261126021107-af2eb25df397/go.mod h1:Ll8I/87SBa69SUo6L92uDGfNoRDTz9SEm1lVpM8mJ40= github.com/MarkRosemaker/openapi-enrich v0.0.0-20261010200623-3b942fefdf03 h1:RHXZfeyefM1V/GaxZJ+RAUVGBpAtdb2u6k6f7grWLiw= github.com/MarkRosemaker/openapi-enrich v0.0.0-20261010200623-3b942fefdf03/go.mod h1:autrmEPWisPks3aJzJHcxKf8K6Mpk1Ph3jg1XywizDk= -github.com/MarkRosemaker/openapi-flatten v0.0.0-20261126034255-0c495ba4f188 h1:XdAmgNmIhf04XAQiw+5MsCkE0rlMwpRBuxHhZQEXt1M= -github.com/MarkRosemaker/openapi-flatten v0.0.0-20261126034255-0c495ba4f188/go.mod h1:P0XjkMH+/5nYg/gVdnlotmMsJCxIdYjaiih4WqV+SGw= +github.com/MarkRosemaker/openapi-flatten v0.0.0-20261126230236-930e862e696c h1:sLDXcIGf3xWZ3Eii/kU3LN3tNk16eY8sB0tiblQ2tDA= +github.com/MarkRosemaker/openapi-flatten v0.0.0-20261126230236-930e862e696c/go.mod h1:P0XjkMH+/5nYg/gVdnlotmMsJCxIdYjaiih4WqV+SGw= github.com/MarkRosemaker/openapi-merge v0.0.0-20261009220258-57c4bc8ba894 h1:fK6ld3zdSy1tJcVa7S9kixkn5e/IyLVQHowed2yLLOU= github.com/MarkRosemaker/openapi-merge v0.0.0-20261009220258-57c4bc8ba894/go.mod h1:JAAF3M82LuQyQ7+ByxhADsiy9e8ZxJQ8viAOsjrwS0c= github.com/MarkRosemaker/ordmap v0.0.0-20261124050216-f3096eb875be h1:yz+tf9ONFOoo2hDWkRSjP9NZSvWyS986bs/WAy+jNus= @@ -30,8 +30,8 @@ github.com/MarkRosemaker/yaml2json v0.0.0-20261118230255-06c4fe76a5b8 h1:D4cujGs github.com/MarkRosemaker/yaml2json v0.0.0-20261118230255-06c4fe76a5b8/go.mod h1:DxNA9SDFrzw+RHsnxjIxjUzHy0I4+3hZg7R13u3SBvE= github.com/ettle/strcase v0.2.0 h1:fGNiVF21fHXpX1niBgk0aROov1LagYsOwV/xqKDKR/Q= github.com/ettle/strcase v0.2.0/go.mod h1:DajmHElDSaX76ITe3/VHVyMin4LWSJN5Z909Wp+ED1A= -github.com/go-api-libs/api v0.0.0-20261125182139-0f507257dcd7 h1:BMgkSz7tviqSK2Gg3ZQeyuMYgi4G33RK/UcqiozHfoE= -github.com/go-api-libs/api v0.0.0-20261125182139-0f507257dcd7/go.mod h1:dHyiZnevRGCtsIQZlq9LKKJyNQGizbsac/IEG7/qeSo= +github.com/go-api-libs/api v0.0.0-20261126230233-f729199ffb88 h1:ZoBVGHnipgjH7f93CCRwx1AFkrC7M4AM4qBgvw5QKPc= +github.com/go-api-libs/api v0.0.0-20261126230233-f729199ffb88/go.mod h1:vnR08tllarZMwkb9x97eTdDllfjOyowesQ0NGEeFEFI= github.com/go-api-libs/types v0.0.0-20261118230255-0e16a3d7de5d h1:WJpz1GJEMd/4zdJ1ElOXCSswW8BQzsWGRz27Y1TivrI= github.com/go-api-libs/types v0.0.0-20261118230255-0e16a3d7de5d/go.mod h1:z0z6qkZc45AvoRnluq7PkVSlSSF25sT0diJ+vrubYfA= github.com/go-quicktest/qt v1.102.0 h1:HSQxCeh5YZH3EL3W39ixjtyaEhcWSXQHtHnMBzSs474= diff --git a/vendor/github.com/MarkRosemaker/cassette/devtool.json b/vendor/github.com/MarkRosemaker/cassette/devtool.json index fcf1c272..1e41bed6 100644 --- a/vendor/github.com/MarkRosemaker/cassette/devtool.json +++ b/vendor/github.com/MarkRosemaker/cassette/devtool.json @@ -9,8 +9,8 @@ "testing", "vcr" ], - "coverage": 86.6, - "devtoolVersion": "v0.0.0-20261125231030-6e2de7adec56", + "coverage": 86.4, + "devtoolVersion": "v0.0.0-20261126050834-392641a9add6", "kind": "library", "tools": { "golangci-lint": "v2.15.0", diff --git a/vendor/github.com/MarkRosemaker/cassette/replay.go b/vendor/github.com/MarkRosemaker/cassette/replay.go index 874d02b9..141c8198 100644 --- a/vendor/github.com/MarkRosemaker/cassette/replay.go +++ b/vendor/github.com/MarkRosemaker/cassette/replay.go @@ -209,7 +209,6 @@ type MatchOption func(*matcher) type matcher struct { headers bool ignore map[string]bool - optional map[string]bool optionalAuth func(*http.Request) bool } @@ -247,21 +246,6 @@ func OptionalAuthorization(optional func(*http.Request) bool) MatchOption { return func(m *matcher) { m.optionalAuth = optional } } -// OptionalHeaders makes [MatchRequest] match a recording without the headers named to a request that has them, and -// compare them where the recording has them: a header a client has begun to send, such as Accept, is missing from what -// was recorded before. -func OptionalHeaders(names ...string) MatchOption { - return func(m *matcher) { - if m.optional == nil { - m.optional = map[string]bool{} - } - - for _, name := range names { - m.optional[http.CanonicalHeaderKey(name)] = true - } - } -} - func (m *matcher) match(req *http.Request, rec Request) error { got, err := NewRequest(req) if err != nil { @@ -318,12 +302,6 @@ func (m *matcher) matchHeaders(req *http.Request, got http.Header, rec Request) want.Del(name) } - for name := range m.optional { - if _, ok := want[name]; !ok { - got.Del(name) - } - } - got.Del("Authorization") want.Del("Authorization") diff --git a/vendor/github.com/MarkRosemaker/openapi-flatten/README.md b/vendor/github.com/MarkRosemaker/openapi-flatten/README.md index e415bccf..397c0616 100644 --- a/vendor/github.com/MarkRosemaker/openapi-flatten/README.md +++ b/vendor/github.com/MarkRosemaker/openapi-flatten/README.md @@ -87,8 +87,10 @@ Inline schemas are moved to `components/schemas` when they contain meaningful st - a **string** or **array of strings** with `enum` values - an **array of objects** - an **array of a component**, named the component's plural: a list of `Order` becomes - `Orders`, or refers to an `Orders` that already lists `Order` and nothing else, the - list's description then staying beside the reference + `Orders`, or refers to an `Orders` that is the same list but for its description, which + then stays beside the reference; a list of a list, or of a name that takes no s such as + `PageWithChildren`, is named the component and `List`; where another list, with other + bounds, holds that name, the list is named after its property The entries of an `allOf` and the alternatives of a `oneOf` or `anyOf` are moved by the same rules, so each shaped one gets a name of its own, and so are the schema of diff --git a/vendor/github.com/MarkRosemaker/openapi-flatten/devtool.json b/vendor/github.com/MarkRosemaker/openapi-flatten/devtool.json index ae0bd0df..43b77642 100644 --- a/vendor/github.com/MarkRosemaker/openapi-flatten/devtool.json +++ b/vendor/github.com/MarkRosemaker/openapi-flatten/devtool.json @@ -12,8 +12,8 @@ "schema", "swagger" ], - "coverage": 95, - "devtoolVersion": "v0.0.0-20261126021605-f1cbae86a052", + "coverage": 95.5, + "devtoolVersion": "v0.0.0-20261126050834-392641a9add6", "kind": "cli", "tools": { "golangci-lint": "v2.15.0", diff --git a/vendor/github.com/MarkRosemaker/openapi-flatten/schema.go b/vendor/github.com/MarkRosemaker/openapi-flatten/schema.go index 92874b54..37531776 100644 --- a/vendor/github.com/MarkRosemaker/openapi-flatten/schema.go +++ b/vendor/github.com/MarkRosemaker/openapi-flatten/schema.go @@ -4,6 +4,7 @@ import ( "bytes" "encoding/json/v2" "fmt" + "slices" "strings" "github.com/MarkRosemaker/errpath" @@ -35,7 +36,7 @@ func inlineSchema(d *openapi.Document, s *openapi.Schema, name string, alwaysMov } else if items := s.Items; items != nil && items.Ref != nil { // a list of a component is named after it, so the component's list reads the same wherever it is if item, ok := strings.CutPrefix(items.Ref.Identifier, "#/components/schemas/"); ok { - s = moveListToComponents(d, s, item) + s = moveListToComponents(d, s, item, name) } } else if items != nil { // no items when only ever seen empty switch items.Type { @@ -165,42 +166,65 @@ func moveSchemaToComponents(d *openapi.Document, name string, s *openapi.Schema) return &moved } -// moveListToComponents makes s, a list of the component schema item, a reference to the component listing it, which is -// named the plural of item: an existing one, if it lists item and nothing else, or else a new one. It returns the -// component. -func moveListToComponents(d *openapi.Document, s *openapi.Schema, item string) *openapi.Schema { - name := plural(item) +// moveListToComponents makes s, a list of the component schema item, a reference to the component listing it. It is +// named after item by [listName], else by name, where it would hold it: the first of the two that is free or is s but +// for what each says of itself, which it then refers to. A list whose names are both taken by others gets the first +// with a number. It returns the component. +func moveListToComponents(d *openapi.Document, s *openapi.Schema, item, name string) *openapi.Schema { + names := []string{listName(d, item), name} + + for _, n := range names { + existing, ok := d.Components.Schemas[n] + if !ok { + return moveSchemaToComponents(d, n, s) + } - if existing, ok := d.Components.Schemas[name]; ok && isListOf(existing, newRef("schemas", item).Identifier) { - s.Replace(&openapi.Schema{ - Ref: &openapi.SchemaRef{Identifier: newRef("schemas", name).Identifier, Value: existing}, - Description: s.Description, - }) + if sameButDocs(existing, s) { + s.Replace(&openapi.Schema{ + Ref: &openapi.SchemaRef{Identifier: newRef("schemas", n).Identifier, Value: existing}, + Description: s.Description, + }) - return existing + return existing + } } - return moveSchemaToComponents(d, name, s) + return moveSchemaToComponents(d, names[0], s) } -// isListOf reports whether s is a list of the component schema at ref and nothing else, but for what it says of itself: -// its title, description, examples and extensions. -func isListOf(s *openapi.Schema, ref string) bool { - if s.Type != openapi.TypeArray || s.Items == nil || s.Items.Ref == nil || s.Items.Ref.Identifier != ref { - return false +// sameButDocs reports whether a and b are the same schema but for what each says of itself: its title, description, +// examples and extensions. +func sameButDocs(a, b *openapi.Schema) bool { + bare := func(s *openapi.Schema) ([]byte, error) { + rest := *s + rest.Title, rest.Description, rest.Example, rest.Examples, rest.Extensions = "", "", nil, nil, nil + + return json.Marshal(&rest) } - rest := *s - rest.Title, rest.Description, rest.Example, rest.Examples, rest.Extensions = "", "", nil, nil, nil + x, errA := bare(a) + y, errB := bare(b) - got, err := json.Marshal(&rest) - if err != nil { - return false + return errA == nil && errB == nil && bytes.Equal(x, y) +} + +// uncountable are the endings of a name that adding s does not make plural, lower-cased. +var uncountable = []string{"children", "data", "info", "media", "news", "people", "series"} + +// listName is the name of a list of the component schema item: its plural, or item and List where item is a list +// itself or ends in a word that takes no s, such as RichTextsList of RichTexts and PageWithChildrenList of +// PageWithChildren. +func listName(d *openapi.Document, item string) string { + if s, ok := d.Components.Schemas[item]; ok && s.Type == openapi.TypeArray { + return item + "List" } - want, err := json.Marshal(&openapi.Schema{Type: s.Type, Items: s.Items}) + lower := strings.ToLower(item) + if slices.ContainsFunc(uncountable, func(end string) bool { return strings.HasSuffix(lower, end) }) { + return item + "List" + } - return err == nil && bytes.Equal(got, want) + return plural(item) } // plural is the English plural of a name, such as Orders of Order, Entries of Entry and Statuses of Status. diff --git a/vendor/github.com/go-api-libs/api/apitest/replay.go b/vendor/github.com/go-api-libs/api/apitest/replay.go index 70b74813..2ff0cd8c 100644 --- a/vendor/github.com/go-api-libs/api/apitest/replay.go +++ b/vendor/github.com/go-api-libs/api/apitest/replay.go @@ -21,9 +21,9 @@ func OptionalAuth(ctx context.Context) context.Context { } // Replay is a transport that answers calls with the interactions recorded in the file at path. Every call must be the -// next recording, with its headers as recorded but the User-Agent, which names whatever tool made the recording, and an -// Accept its recording lacks, as one made before clients sent it; a call marked with [OptionalAuth] may have credentials -// its recording lacks. A request body may hold a tag its recording leaves out, which a client fills in (see +// next recording, with its headers as recorded but the User-Agent, which names whatever tool made the recording, and +// Accept, which clients do not send though a recording may hold it; a call marked with [OptionalAuth] may have +// credentials its recording lacks. A request body may hold a tag its recording leaves out, which a client fills in (see // jsonSameButTags). The test fails if a recording was never called. func Replay(t testing.TB, path string) http.RoundTripper { t.Helper() @@ -34,8 +34,7 @@ func Replay(t testing.TB, path string) http.RoundTripper { } match := cassette.MatchRequest( - cassette.CompareHeaders("User-Agent"), - cassette.OptionalHeaders("Accept"), + cassette.CompareHeaders("User-Agent", "Accept"), cassette.OptionalAuthorization(func(req *http.Request) bool { return req.Context().Value(optionalAuthKey{}) != nil }), ) diff --git a/vendor/modules.txt b/vendor/modules.txt index e8095c97..6d2ab42f 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -1,7 +1,7 @@ # cloud.google.com/go v0.123.0 ## explicit; go 1.24.0 cloud.google.com/go/civil -# github.com/MarkRosemaker/cassette v0.0.0-20261126020934-32283f081e24 +# github.com/MarkRosemaker/cassette v0.0.0-20261126230209-577d7f661401 ## explicit; go 1.27 github.com/MarkRosemaker/cassette # github.com/MarkRosemaker/errpath v0.0.0-20261118230255-99e20cb3445a @@ -25,7 +25,7 @@ github.com/MarkRosemaker/openapi-compress # github.com/MarkRosemaker/openapi-edit v0.0.0-20261126021107-af2eb25df397 ## explicit; go 1.27 github.com/MarkRosemaker/openapi-edit -# github.com/MarkRosemaker/openapi-flatten v0.0.0-20261126034255-0c495ba4f188 +# github.com/MarkRosemaker/openapi-flatten v0.0.0-20261126230236-930e862e696c ## explicit; go 1.27 github.com/MarkRosemaker/openapi-flatten # github.com/MarkRosemaker/ordmap v0.0.0-20261124050216-f3096eb875be @@ -40,7 +40,7 @@ github.com/MarkRosemaker/yaml2json # github.com/ettle/strcase v0.2.0 ## explicit; go 1.12 github.com/ettle/strcase -# github.com/go-api-libs/api v0.0.0-20261125182139-0f507257dcd7 +# github.com/go-api-libs/api v0.0.0-20261126230233-f729199ffb88 ## explicit; go 1.27 github.com/go-api-libs/api github.com/go-api-libs/api/apitest