Skip to content

Commit ab66946

Browse files
committed
fix: add OpenAPIModelName for all types referenced in OpenAPI schemas
1 parent 884ff95 commit ab66946

4 files changed

Lines changed: 389 additions & 0 deletions

File tree

pkg/lib/version/model_name.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
Copyright Red Hat, Inc.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package version
18+
19+
// OpenAPIModelName returns the OpenAPI model name for this type.
20+
// This ensures the OpenAPI schema uses the canonical name format (com.github...)
21+
// instead of the URL-encoded Go import path format that causes lookup failures.
22+
func (OperatorVersion) OpenAPIModelName() string {
23+
return "com.github.operator-framework.api.pkg.lib.version.OperatorVersion"
24+
}

pkg/lib/version/model_name_test.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
Copyright Red Hat, Inc.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package version
18+
19+
import (
20+
"testing"
21+
22+
"github.com/stretchr/testify/require"
23+
)
24+
25+
func TestOperatorVersionOpenAPIModelName(t *testing.T) {
26+
v := OperatorVersion{}
27+
expected := "com.github.operator-framework.api.pkg.lib.version.OperatorVersion"
28+
require.Equal(t, expected, v.OpenAPIModelName())
29+
}
Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
1+
/*
2+
Copyright Red Hat, Inc.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package v1alpha1
18+
19+
// OpenAPIModelName methods for all types that are referenced in OpenAPI schemas.
20+
// This ensures the OpenAPI schema uses the canonical name format (com.github...)
21+
// instead of the URL-encoded Go import path format that causes lookup failures.
22+
//
23+
// When Kubernetes serves OpenAPI schemas, "/" in type references gets URL-encoded
24+
// to "~1". If the schema definition keys don't match, lookups fail with errors like:
25+
// unknown model in reference: "github.com~1operator-framework~1api~1..."
26+
//
27+
// Adding OpenAPIModelName() makes openapi-gen use the canonical format for both
28+
// the definition key and references, ensuring they match.
29+
30+
// OpenAPIModelName returns the OpenAPI model name for this type.
31+
func (APIResourceReference) OpenAPIModelName() string {
32+
return "com.github.operator-framework.api.pkg.operators.v1alpha1.APIResourceReference"
33+
}
34+
35+
// OpenAPIModelName returns the OpenAPI model name for this type.
36+
func (APIServiceDefinitions) OpenAPIModelName() string {
37+
return "com.github.operator-framework.api.pkg.operators.v1alpha1.APIServiceDefinitions"
38+
}
39+
40+
// OpenAPIModelName returns the OpenAPI model name for this type.
41+
func (APIServiceDescription) OpenAPIModelName() string {
42+
return "com.github.operator-framework.api.pkg.operators.v1alpha1.APIServiceDescription"
43+
}
44+
45+
// OpenAPIModelName returns the OpenAPI model name for this type.
46+
func (ActionDescriptor) OpenAPIModelName() string {
47+
return "com.github.operator-framework.api.pkg.operators.v1alpha1.ActionDescriptor"
48+
}
49+
50+
// OpenAPIModelName returns the OpenAPI model name for this type.
51+
func (AppLink) OpenAPIModelName() string {
52+
return "com.github.operator-framework.api.pkg.operators.v1alpha1.AppLink"
53+
}
54+
55+
// OpenAPIModelName returns the OpenAPI model name for this type.
56+
func (CRDDescription) OpenAPIModelName() string {
57+
return "com.github.operator-framework.api.pkg.operators.v1alpha1.CRDDescription"
58+
}
59+
60+
// OpenAPIModelName returns the OpenAPI model name for this type.
61+
func (CleanupSpec) OpenAPIModelName() string {
62+
return "com.github.operator-framework.api.pkg.operators.v1alpha1.CleanupSpec"
63+
}
64+
65+
// OpenAPIModelName returns the OpenAPI model name for this type.
66+
func (CleanupStatus) OpenAPIModelName() string {
67+
return "com.github.operator-framework.api.pkg.operators.v1alpha1.CleanupStatus"
68+
}
69+
70+
// OpenAPIModelName returns the OpenAPI model name for this type.
71+
func (ClusterServiceVersionCondition) OpenAPIModelName() string {
72+
return "com.github.operator-framework.api.pkg.operators.v1alpha1.ClusterServiceVersionCondition"
73+
}
74+
75+
// OpenAPIModelName returns the OpenAPI model name for this type.
76+
func (ClusterServiceVersionSpec) OpenAPIModelName() string {
77+
return "com.github.operator-framework.api.pkg.operators.v1alpha1.ClusterServiceVersionSpec"
78+
}
79+
80+
// OpenAPIModelName returns the OpenAPI model name for this type.
81+
func (ClusterServiceVersionStatus) OpenAPIModelName() string {
82+
return "com.github.operator-framework.api.pkg.operators.v1alpha1.ClusterServiceVersionStatus"
83+
}
84+
85+
// OpenAPIModelName returns the OpenAPI model name for this type.
86+
func (CustomResourceDefinitions) OpenAPIModelName() string {
87+
return "com.github.operator-framework.api.pkg.operators.v1alpha1.CustomResourceDefinitions"
88+
}
89+
90+
// OpenAPIModelName returns the OpenAPI model name for this type.
91+
func (DependentStatus) OpenAPIModelName() string {
92+
return "com.github.operator-framework.api.pkg.operators.v1alpha1.DependentStatus"
93+
}
94+
95+
// OpenAPIModelName returns the OpenAPI model name for this type.
96+
func (Icon) OpenAPIModelName() string {
97+
return "com.github.operator-framework.api.pkg.operators.v1alpha1.Icon"
98+
}
99+
100+
// OpenAPIModelName returns the OpenAPI model name for this type.
101+
func (InstallMode) OpenAPIModelName() string {
102+
return "com.github.operator-framework.api.pkg.operators.v1alpha1.InstallMode"
103+
}
104+
105+
// OpenAPIModelName returns the OpenAPI model name for this type.
106+
func (Maintainer) OpenAPIModelName() string {
107+
return "com.github.operator-framework.api.pkg.operators.v1alpha1.Maintainer"
108+
}
109+
110+
// OpenAPIModelName returns the OpenAPI model name for this type.
111+
func (NamedInstallStrategy) OpenAPIModelName() string {
112+
return "com.github.operator-framework.api.pkg.operators.v1alpha1.NamedInstallStrategy"
113+
}
114+
115+
// OpenAPIModelName returns the OpenAPI model name for this type.
116+
func (RelatedImage) OpenAPIModelName() string {
117+
return "com.github.operator-framework.api.pkg.operators.v1alpha1.RelatedImage"
118+
}
119+
120+
// OpenAPIModelName returns the OpenAPI model name for this type.
121+
func (RequirementStatus) OpenAPIModelName() string {
122+
return "com.github.operator-framework.api.pkg.operators.v1alpha1.RequirementStatus"
123+
}
124+
125+
// OpenAPIModelName returns the OpenAPI model name for this type.
126+
func (ResourceInstance) OpenAPIModelName() string {
127+
return "com.github.operator-framework.api.pkg.operators.v1alpha1.ResourceInstance"
128+
}
129+
130+
// OpenAPIModelName returns the OpenAPI model name for this type.
131+
func (ResourceList) OpenAPIModelName() string {
132+
return "com.github.operator-framework.api.pkg.operators.v1alpha1.ResourceList"
133+
}
134+
135+
// OpenAPIModelName returns the OpenAPI model name for this type.
136+
func (SpecDescriptor) OpenAPIModelName() string {
137+
return "com.github.operator-framework.api.pkg.operators.v1alpha1.SpecDescriptor"
138+
}
139+
140+
// OpenAPIModelName returns the OpenAPI model name for this type.
141+
func (StatusDescriptor) OpenAPIModelName() string {
142+
return "com.github.operator-framework.api.pkg.operators.v1alpha1.StatusDescriptor"
143+
}
144+
145+
// OpenAPIModelName returns the OpenAPI model name for this type.
146+
func (StrategyDeploymentPermissions) OpenAPIModelName() string {
147+
return "com.github.operator-framework.api.pkg.operators.v1alpha1.StrategyDeploymentPermissions"
148+
}
149+
150+
// OpenAPIModelName returns the OpenAPI model name for this type.
151+
func (StrategyDeploymentSpec) OpenAPIModelName() string {
152+
return "com.github.operator-framework.api.pkg.operators.v1alpha1.StrategyDeploymentSpec"
153+
}
154+
155+
// OpenAPIModelName returns the OpenAPI model name for this type.
156+
func (StrategyDetailsDeployment) OpenAPIModelName() string {
157+
return "com.github.operator-framework.api.pkg.operators.v1alpha1.StrategyDetailsDeployment"
158+
}
159+
160+
// OpenAPIModelName returns the OpenAPI model name for this type.
161+
func (WebhookDescription) OpenAPIModelName() string {
162+
return "com.github.operator-framework.api.pkg.operators.v1alpha1.WebhookDescription"
163+
}
Lines changed: 173 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,173 @@
1+
/*
2+
Copyright Red Hat, Inc.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package v1alpha1
18+
19+
import (
20+
"testing"
21+
22+
"github.com/stretchr/testify/require"
23+
)
24+
25+
func TestOpenAPIModelName(t *testing.T) {
26+
tests := []struct {
27+
name string
28+
typeFunc func() string
29+
expected string
30+
}{
31+
{
32+
name: "APIResourceReference",
33+
typeFunc: func() string { return APIResourceReference{}.OpenAPIModelName() },
34+
expected: "com.github.operator-framework.api.pkg.operators.v1alpha1.APIResourceReference",
35+
},
36+
{
37+
name: "APIServiceDefinitions",
38+
typeFunc: func() string { return APIServiceDefinitions{}.OpenAPIModelName() },
39+
expected: "com.github.operator-framework.api.pkg.operators.v1alpha1.APIServiceDefinitions",
40+
},
41+
{
42+
name: "APIServiceDescription",
43+
typeFunc: func() string { return APIServiceDescription{}.OpenAPIModelName() },
44+
expected: "com.github.operator-framework.api.pkg.operators.v1alpha1.APIServiceDescription",
45+
},
46+
{
47+
name: "ActionDescriptor",
48+
typeFunc: func() string { return ActionDescriptor{}.OpenAPIModelName() },
49+
expected: "com.github.operator-framework.api.pkg.operators.v1alpha1.ActionDescriptor",
50+
},
51+
{
52+
name: "AppLink",
53+
typeFunc: func() string { return AppLink{}.OpenAPIModelName() },
54+
expected: "com.github.operator-framework.api.pkg.operators.v1alpha1.AppLink",
55+
},
56+
{
57+
name: "CRDDescription",
58+
typeFunc: func() string { return CRDDescription{}.OpenAPIModelName() },
59+
expected: "com.github.operator-framework.api.pkg.operators.v1alpha1.CRDDescription",
60+
},
61+
{
62+
name: "CleanupSpec",
63+
typeFunc: func() string { return CleanupSpec{}.OpenAPIModelName() },
64+
expected: "com.github.operator-framework.api.pkg.operators.v1alpha1.CleanupSpec",
65+
},
66+
{
67+
name: "CleanupStatus",
68+
typeFunc: func() string { return CleanupStatus{}.OpenAPIModelName() },
69+
expected: "com.github.operator-framework.api.pkg.operators.v1alpha1.CleanupStatus",
70+
},
71+
{
72+
name: "ClusterServiceVersionCondition",
73+
typeFunc: func() string { return ClusterServiceVersionCondition{}.OpenAPIModelName() },
74+
expected: "com.github.operator-framework.api.pkg.operators.v1alpha1.ClusterServiceVersionCondition",
75+
},
76+
{
77+
name: "ClusterServiceVersionSpec",
78+
typeFunc: func() string { return ClusterServiceVersionSpec{}.OpenAPIModelName() },
79+
expected: "com.github.operator-framework.api.pkg.operators.v1alpha1.ClusterServiceVersionSpec",
80+
},
81+
{
82+
name: "ClusterServiceVersionStatus",
83+
typeFunc: func() string { return ClusterServiceVersionStatus{}.OpenAPIModelName() },
84+
expected: "com.github.operator-framework.api.pkg.operators.v1alpha1.ClusterServiceVersionStatus",
85+
},
86+
{
87+
name: "CustomResourceDefinitions",
88+
typeFunc: func() string { return CustomResourceDefinitions{}.OpenAPIModelName() },
89+
expected: "com.github.operator-framework.api.pkg.operators.v1alpha1.CustomResourceDefinitions",
90+
},
91+
{
92+
name: "DependentStatus",
93+
typeFunc: func() string { return DependentStatus{}.OpenAPIModelName() },
94+
expected: "com.github.operator-framework.api.pkg.operators.v1alpha1.DependentStatus",
95+
},
96+
{
97+
name: "Icon",
98+
typeFunc: func() string { return Icon{}.OpenAPIModelName() },
99+
expected: "com.github.operator-framework.api.pkg.operators.v1alpha1.Icon",
100+
},
101+
{
102+
name: "InstallMode",
103+
typeFunc: func() string { return InstallMode{}.OpenAPIModelName() },
104+
expected: "com.github.operator-framework.api.pkg.operators.v1alpha1.InstallMode",
105+
},
106+
{
107+
name: "Maintainer",
108+
typeFunc: func() string { return Maintainer{}.OpenAPIModelName() },
109+
expected: "com.github.operator-framework.api.pkg.operators.v1alpha1.Maintainer",
110+
},
111+
{
112+
name: "NamedInstallStrategy",
113+
typeFunc: func() string { return NamedInstallStrategy{}.OpenAPIModelName() },
114+
expected: "com.github.operator-framework.api.pkg.operators.v1alpha1.NamedInstallStrategy",
115+
},
116+
{
117+
name: "RelatedImage",
118+
typeFunc: func() string { return RelatedImage{}.OpenAPIModelName() },
119+
expected: "com.github.operator-framework.api.pkg.operators.v1alpha1.RelatedImage",
120+
},
121+
{
122+
name: "RequirementStatus",
123+
typeFunc: func() string { return RequirementStatus{}.OpenAPIModelName() },
124+
expected: "com.github.operator-framework.api.pkg.operators.v1alpha1.RequirementStatus",
125+
},
126+
{
127+
name: "ResourceInstance",
128+
typeFunc: func() string { return ResourceInstance{}.OpenAPIModelName() },
129+
expected: "com.github.operator-framework.api.pkg.operators.v1alpha1.ResourceInstance",
130+
},
131+
{
132+
name: "ResourceList",
133+
typeFunc: func() string { return ResourceList{}.OpenAPIModelName() },
134+
expected: "com.github.operator-framework.api.pkg.operators.v1alpha1.ResourceList",
135+
},
136+
{
137+
name: "SpecDescriptor",
138+
typeFunc: func() string { return SpecDescriptor{}.OpenAPIModelName() },
139+
expected: "com.github.operator-framework.api.pkg.operators.v1alpha1.SpecDescriptor",
140+
},
141+
{
142+
name: "StatusDescriptor",
143+
typeFunc: func() string { return StatusDescriptor{}.OpenAPIModelName() },
144+
expected: "com.github.operator-framework.api.pkg.operators.v1alpha1.StatusDescriptor",
145+
},
146+
{
147+
name: "StrategyDeploymentPermissions",
148+
typeFunc: func() string { return StrategyDeploymentPermissions{}.OpenAPIModelName() },
149+
expected: "com.github.operator-framework.api.pkg.operators.v1alpha1.StrategyDeploymentPermissions",
150+
},
151+
{
152+
name: "StrategyDeploymentSpec",
153+
typeFunc: func() string { return StrategyDeploymentSpec{}.OpenAPIModelName() },
154+
expected: "com.github.operator-framework.api.pkg.operators.v1alpha1.StrategyDeploymentSpec",
155+
},
156+
{
157+
name: "StrategyDetailsDeployment",
158+
typeFunc: func() string { return StrategyDetailsDeployment{}.OpenAPIModelName() },
159+
expected: "com.github.operator-framework.api.pkg.operators.v1alpha1.StrategyDetailsDeployment",
160+
},
161+
{
162+
name: "WebhookDescription",
163+
typeFunc: func() string { return WebhookDescription{}.OpenAPIModelName() },
164+
expected: "com.github.operator-framework.api.pkg.operators.v1alpha1.WebhookDescription",
165+
},
166+
}
167+
168+
for _, tt := range tests {
169+
t.Run(tt.name, func(t *testing.T) {
170+
require.Equal(t, tt.expected, tt.typeFunc())
171+
})
172+
}
173+
}

0 commit comments

Comments
 (0)