Skip to content

Commit 720590f

Browse files
authored
Merge pull request #3227 from fredbi/fix/panic-type-alias-2
Upgrade to go 1.24 with support for type aliases This PR was initially motivated by the (modest) need to upgrade to go1.24. This quickly turned out into a big change in the codescan package (that generates specs from code). To achieve the upgrade, additional support for type aliases was needed. That part is mostly complete for schema models. However, support for aliases in responses and parameters is still incomplete (but should not panic). I hope I'll be able to bring a more thorough approach to aliases for responses and parameters in a follow-up PR. On top of that, the arrival of go1.25 did bring new incompatibilities, such as a few generated code gen templates no longer passing go vet... This PR reverts the "CI masking workaround" e8a445dc58cc96dc42fe8d36867affc1abe6b399 and brings an actual upgrade. * fixes #3220 * fixes #3174 * fixes #3131 * fixes #3129 * fixes #3062 * supersedes #3137 * supersedes #3221 * supersedes #3218
2 parents ff8364d + 743378e commit 720590f

8 files changed

Lines changed: 604 additions & 0 deletions

File tree

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
// Copyright 2015 go-swagger maintainers
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
//go:build testscanner
16+
17+
package schema
18+
19+
// swagger:model iface_embedded
20+
type IfaceEmbedded interface {
21+
Iface
22+
23+
Dump() []byte
24+
error
25+
}
26+
27+
// swagger:model iface_embedded_with_alias
28+
type IfaceEmbeddedWithAlias interface {
29+
IfaceAlias
30+
AnonymousIface
31+
32+
Dump() []byte
33+
}
34+
35+
// swagger:model iface_embedded_empty
36+
type IfaceEmpty interface {
37+
interface{}
38+
any
39+
}
40+
41+
// swagger:model iface_embedded_anonymous
42+
type IfaceEmbeddedAnonymous interface {
43+
interface{ String() string }
44+
interface{ Error() string }
45+
interface{}
46+
error
47+
}
48+
49+
// ExtendedID should be discovered through dependency analysis.
50+
type ExtendedID struct {
51+
Empty
52+
53+
More string `json:"more"`
54+
EvenMore any
55+
StillMore interface{}
56+
_ struct{}
57+
}
58+
59+
// swagger:model embedded_with_alias
60+
type EmbeddedWithAlias struct {
61+
Anything
62+
UUID
63+
64+
More string `json:"more"`
65+
EvenMore any
66+
StillMore interface{}
67+
}
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
// Copyright 2015 go-swagger maintainers
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
//go:build testscanner
16+
17+
package schema
18+
19+
// swagger:model void
20+
type Void = Empty
21+
22+
// swagger:model empty_redefinition
23+
type EmptyRedefinition struct{}
24+
25+
// swagger:model anonymous_struct
26+
type AnonymousStruct struct {
27+
A struct {
28+
B int
29+
}
30+
}
31+
32+
// swagger:model whatnot
33+
type WhatNot any
34+
35+
// swagger:model aliased_id
36+
type AliasedID = ExtendedID
37+
38+
// swagger:model whatnot_alias
39+
type WhatNotAlias = any
40+
41+
// swagger:model iface
42+
type Iface interface {
43+
Get() string
44+
Set(string)
45+
}
46+
47+
// swagger:model iface_alias
48+
type IfaceAlias = Iface
49+
50+
// swagger:model iface_redefinition
51+
type IfaceRedefinition Iface
52+
53+
// swagger:model anonymous_iface
54+
type AnonymousIface interface{ String() string }
55+
56+
// swagger:model anonymous_iface_alias
57+
type AnonymousIfaceAlias = AnonymousIface
58+
59+
// swagger:model whatnot2
60+
//
61+
// This is a type redefinition.
62+
type WhatNot2 interface{}
63+
64+
// swagger:model whatnot2_alias
65+
//
66+
// This is a syntactic alias.
67+
type WhatNot2Alias = interface{}
68+
69+
// swagger:model slice_type
70+
type Slice []any
71+
72+
// swagger:model slice_alias
73+
type SliceAlias = []any
74+
75+
// swagger:model slice_to_slice
76+
type SliceToSlice = Slice
77+
78+
// swagger:model slice_of_structs
79+
//
80+
// SliceOfStructs is an slice of anonymous structs.
81+
type SliceOfStructs []struct{}
82+
83+
// swagger:model slice_of_structs_alias
84+
type SliceOfStructsAlias = []struct{}
85+
86+
// swagger:model
87+
type ShouldSee bool
88+
89+
type ShouldNotSee bool
90+
type ShouldNotSeeSlice []int
91+
type ShouldNotSeeMap map[string]int
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
// Copyright 2015 go-swagger maintainers
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
//go:build testscanner
16+
17+
package schema
18+
19+
// UUID should be discovered through dependency analysis.
20+
type UUID = int64
21+
22+
// Anything should be discovered through dependency analysis.
23+
type Anything = any
24+
25+
// Empty should be discovered through dependency analysis.
26+
type Empty = struct{}
27+
28+
// # StoreOrder represents an order in this application.
29+
//
30+
// An order can either be created, processed or completed.
31+
//
32+
// swagger:model order
33+
type StoreOrder struct {
34+
// the id for this order
35+
//
36+
// required: true
37+
// min: 1
38+
ID UUID `json:"id"`
39+
40+
EID ExtendedID `json:"extended_id"`
41+
42+
// the name for this user
43+
//
44+
// required: true
45+
// min length: 3
46+
UserID int64 `json:"userId"`
47+
48+
// the category of this user
49+
//
50+
// required: true
51+
// default: bar
52+
// enum: foo,bar,none
53+
Category string `json:"category"`
54+
55+
// the items for this order
56+
Items []struct {
57+
ID int32 `json:"id"`
58+
Quantity int16 `json:"quantity"`
59+
ExtraOptions any `json:"extra_options"`
60+
} `json:"items"`
61+
62+
Extras any
63+
64+
MoreExtras interface{}
65+
DeliveryOption Anything
66+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
* circular $ref
2+
* $ref with name conflict
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// Copyright 2015 go-swagger maintainers
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
/*//go:build testscanner*/
16+
17+
package special
18+
19+
// swagger:model generic_constraint
20+
type Constraint interface {
21+
~uint16
22+
interface{ Uint() uint16 }
23+
}
24+
25+
// swagger:model numerical_constraint
26+
type Numerical interface {
27+
~uint16 | ~int16
28+
}
29+
30+
// swagger:model union_alias
31+
type Union = Numerical
32+
33+
// swagger:model generic_map
34+
type GenericMap[K comparable, V any] map[K]V
35+
36+
// swagger:model generic_map_alias
37+
type GenericMapAlias[K comparable, V any] = map[K]V
38+
39+
// swagger:model generic_indirect
40+
type GenericIndirect[K comparable, V any] = GenericMapAlias[K, V]
41+
42+
// swagger:model generic_slice
43+
type GenericSlice[T any] []T
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
// Copyright 2015 go-swagger maintainers
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
/*//go:build testscanner*/
16+
17+
package special
18+
19+
import (
20+
"encoding/json"
21+
"math/big"
22+
"reflect"
23+
"time"
24+
"unsafe"
25+
26+
"github.com/go-openapi/strfmt"
27+
)
28+
29+
// swagger:model primitive
30+
type Primitive string
31+
32+
// swagger:model unsafe_pointer_alias
33+
type Unsafe = unsafe.Pointer
34+
35+
// swagger:model upointer_alias
36+
type UIntPtr = uintptr
37+
38+
// swagger:model go_map
39+
type GoMap map[string]uint16
40+
41+
type GoStruct struct {
42+
A *float32
43+
}
44+
45+
// swagger:model index_map
46+
type UnsupportedMap map[int]struct{}
47+
48+
// swagger:model go_error
49+
type Error error
50+
51+
// swagger:model special_types
52+
type SpecialTypes struct {
53+
PtrStruct *GoStruct
54+
ShouldBeStringTime time.Time
55+
ShouldAlsoBeStringTime *time.Time
56+
Error error
57+
Marshaler IsATextMarshaler
58+
Message json.RawMessage
59+
Duration time.Duration
60+
FormatDate strfmt.Date
61+
FormatTime strfmt.DateTime
62+
FormatUUID strfmt.UUID
63+
PtrFormatUUID *strfmt.UUID
64+
Err error
65+
Map map[string]*GoStruct
66+
67+
// and what not
68+
WhatNot struct {
69+
unexported int
70+
AA complex128
71+
A complex64
72+
B chan int
73+
C func()
74+
D func() string
75+
E unsafe.Pointer
76+
F uintptr
77+
G *big.Float
78+
H *big.Int
79+
I [5]byte
80+
J reflect.Type
81+
K reflect.Value
82+
}
83+
}
84+
85+
// swagger:model unexported
86+
type unexported struct{}
87+
88+
type IsATextMarshaler struct {
89+
unexported string
90+
}
91+
92+
func (m IsATextMarshaler) MarshalText() ([]byte, error) {
93+
return []byte(m.unexported), nil
94+
}
95+
96+
// swagger:model go_array
97+
type GoArray [3]int64

0 commit comments

Comments
 (0)