From ab669464609ccf4f5fac4fdbe3a1365377950cfc Mon Sep 17 00:00:00 2001 From: Jian Zhang Date: Fri, 13 Feb 2026 12:30:32 +0800 Subject: [PATCH] fix: add OpenAPIModelName for all types referenced in OpenAPI schemas --- pkg/lib/version/model_name.go | 24 +++ pkg/lib/version/model_name_test.go | 29 ++++ pkg/operators/v1alpha1/model_name.go | 163 ++++++++++++++++++++ pkg/operators/v1alpha1/model_name_test.go | 173 ++++++++++++++++++++++ 4 files changed, 389 insertions(+) create mode 100644 pkg/lib/version/model_name.go create mode 100644 pkg/lib/version/model_name_test.go create mode 100644 pkg/operators/v1alpha1/model_name.go create mode 100644 pkg/operators/v1alpha1/model_name_test.go diff --git a/pkg/lib/version/model_name.go b/pkg/lib/version/model_name.go new file mode 100644 index 000000000..76f129aad --- /dev/null +++ b/pkg/lib/version/model_name.go @@ -0,0 +1,24 @@ +/* +Copyright Red Hat, Inc. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package version + +// OpenAPIModelName returns the OpenAPI model name for this type. +// This ensures the OpenAPI schema uses the canonical name format (com.github...) +// instead of the URL-encoded Go import path format that causes lookup failures. +func (OperatorVersion) OpenAPIModelName() string { + return "com.github.operator-framework.api.pkg.lib.version.OperatorVersion" +} diff --git a/pkg/lib/version/model_name_test.go b/pkg/lib/version/model_name_test.go new file mode 100644 index 000000000..d7f4fb153 --- /dev/null +++ b/pkg/lib/version/model_name_test.go @@ -0,0 +1,29 @@ +/* +Copyright Red Hat, Inc. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package version + +import ( + "testing" + + "github.com/stretchr/testify/require" +) + +func TestOperatorVersionOpenAPIModelName(t *testing.T) { + v := OperatorVersion{} + expected := "com.github.operator-framework.api.pkg.lib.version.OperatorVersion" + require.Equal(t, expected, v.OpenAPIModelName()) +} diff --git a/pkg/operators/v1alpha1/model_name.go b/pkg/operators/v1alpha1/model_name.go new file mode 100644 index 000000000..d618d3c7b --- /dev/null +++ b/pkg/operators/v1alpha1/model_name.go @@ -0,0 +1,163 @@ +/* +Copyright Red Hat, Inc. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package v1alpha1 + +// OpenAPIModelName methods for all types that are referenced in OpenAPI schemas. +// This ensures the OpenAPI schema uses the canonical name format (com.github...) +// instead of the URL-encoded Go import path format that causes lookup failures. +// +// When Kubernetes serves OpenAPI schemas, "/" in type references gets URL-encoded +// to "~1". If the schema definition keys don't match, lookups fail with errors like: +// unknown model in reference: "github.com~1operator-framework~1api~1..." +// +// Adding OpenAPIModelName() makes openapi-gen use the canonical format for both +// the definition key and references, ensuring they match. + +// OpenAPIModelName returns the OpenAPI model name for this type. +func (APIResourceReference) OpenAPIModelName() string { + return "com.github.operator-framework.api.pkg.operators.v1alpha1.APIResourceReference" +} + +// OpenAPIModelName returns the OpenAPI model name for this type. +func (APIServiceDefinitions) OpenAPIModelName() string { + return "com.github.operator-framework.api.pkg.operators.v1alpha1.APIServiceDefinitions" +} + +// OpenAPIModelName returns the OpenAPI model name for this type. +func (APIServiceDescription) OpenAPIModelName() string { + return "com.github.operator-framework.api.pkg.operators.v1alpha1.APIServiceDescription" +} + +// OpenAPIModelName returns the OpenAPI model name for this type. +func (ActionDescriptor) OpenAPIModelName() string { + return "com.github.operator-framework.api.pkg.operators.v1alpha1.ActionDescriptor" +} + +// OpenAPIModelName returns the OpenAPI model name for this type. +func (AppLink) OpenAPIModelName() string { + return "com.github.operator-framework.api.pkg.operators.v1alpha1.AppLink" +} + +// OpenAPIModelName returns the OpenAPI model name for this type. +func (CRDDescription) OpenAPIModelName() string { + return "com.github.operator-framework.api.pkg.operators.v1alpha1.CRDDescription" +} + +// OpenAPIModelName returns the OpenAPI model name for this type. +func (CleanupSpec) OpenAPIModelName() string { + return "com.github.operator-framework.api.pkg.operators.v1alpha1.CleanupSpec" +} + +// OpenAPIModelName returns the OpenAPI model name for this type. +func (CleanupStatus) OpenAPIModelName() string { + return "com.github.operator-framework.api.pkg.operators.v1alpha1.CleanupStatus" +} + +// OpenAPIModelName returns the OpenAPI model name for this type. +func (ClusterServiceVersionCondition) OpenAPIModelName() string { + return "com.github.operator-framework.api.pkg.operators.v1alpha1.ClusterServiceVersionCondition" +} + +// OpenAPIModelName returns the OpenAPI model name for this type. +func (ClusterServiceVersionSpec) OpenAPIModelName() string { + return "com.github.operator-framework.api.pkg.operators.v1alpha1.ClusterServiceVersionSpec" +} + +// OpenAPIModelName returns the OpenAPI model name for this type. +func (ClusterServiceVersionStatus) OpenAPIModelName() string { + return "com.github.operator-framework.api.pkg.operators.v1alpha1.ClusterServiceVersionStatus" +} + +// OpenAPIModelName returns the OpenAPI model name for this type. +func (CustomResourceDefinitions) OpenAPIModelName() string { + return "com.github.operator-framework.api.pkg.operators.v1alpha1.CustomResourceDefinitions" +} + +// OpenAPIModelName returns the OpenAPI model name for this type. +func (DependentStatus) OpenAPIModelName() string { + return "com.github.operator-framework.api.pkg.operators.v1alpha1.DependentStatus" +} + +// OpenAPIModelName returns the OpenAPI model name for this type. +func (Icon) OpenAPIModelName() string { + return "com.github.operator-framework.api.pkg.operators.v1alpha1.Icon" +} + +// OpenAPIModelName returns the OpenAPI model name for this type. +func (InstallMode) OpenAPIModelName() string { + return "com.github.operator-framework.api.pkg.operators.v1alpha1.InstallMode" +} + +// OpenAPIModelName returns the OpenAPI model name for this type. +func (Maintainer) OpenAPIModelName() string { + return "com.github.operator-framework.api.pkg.operators.v1alpha1.Maintainer" +} + +// OpenAPIModelName returns the OpenAPI model name for this type. +func (NamedInstallStrategy) OpenAPIModelName() string { + return "com.github.operator-framework.api.pkg.operators.v1alpha1.NamedInstallStrategy" +} + +// OpenAPIModelName returns the OpenAPI model name for this type. +func (RelatedImage) OpenAPIModelName() string { + return "com.github.operator-framework.api.pkg.operators.v1alpha1.RelatedImage" +} + +// OpenAPIModelName returns the OpenAPI model name for this type. +func (RequirementStatus) OpenAPIModelName() string { + return "com.github.operator-framework.api.pkg.operators.v1alpha1.RequirementStatus" +} + +// OpenAPIModelName returns the OpenAPI model name for this type. +func (ResourceInstance) OpenAPIModelName() string { + return "com.github.operator-framework.api.pkg.operators.v1alpha1.ResourceInstance" +} + +// OpenAPIModelName returns the OpenAPI model name for this type. +func (ResourceList) OpenAPIModelName() string { + return "com.github.operator-framework.api.pkg.operators.v1alpha1.ResourceList" +} + +// OpenAPIModelName returns the OpenAPI model name for this type. +func (SpecDescriptor) OpenAPIModelName() string { + return "com.github.operator-framework.api.pkg.operators.v1alpha1.SpecDescriptor" +} + +// OpenAPIModelName returns the OpenAPI model name for this type. +func (StatusDescriptor) OpenAPIModelName() string { + return "com.github.operator-framework.api.pkg.operators.v1alpha1.StatusDescriptor" +} + +// OpenAPIModelName returns the OpenAPI model name for this type. +func (StrategyDeploymentPermissions) OpenAPIModelName() string { + return "com.github.operator-framework.api.pkg.operators.v1alpha1.StrategyDeploymentPermissions" +} + +// OpenAPIModelName returns the OpenAPI model name for this type. +func (StrategyDeploymentSpec) OpenAPIModelName() string { + return "com.github.operator-framework.api.pkg.operators.v1alpha1.StrategyDeploymentSpec" +} + +// OpenAPIModelName returns the OpenAPI model name for this type. +func (StrategyDetailsDeployment) OpenAPIModelName() string { + return "com.github.operator-framework.api.pkg.operators.v1alpha1.StrategyDetailsDeployment" +} + +// OpenAPIModelName returns the OpenAPI model name for this type. +func (WebhookDescription) OpenAPIModelName() string { + return "com.github.operator-framework.api.pkg.operators.v1alpha1.WebhookDescription" +} diff --git a/pkg/operators/v1alpha1/model_name_test.go b/pkg/operators/v1alpha1/model_name_test.go new file mode 100644 index 000000000..163e65fcb --- /dev/null +++ b/pkg/operators/v1alpha1/model_name_test.go @@ -0,0 +1,173 @@ +/* +Copyright Red Hat, Inc. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package v1alpha1 + +import ( + "testing" + + "github.com/stretchr/testify/require" +) + +func TestOpenAPIModelName(t *testing.T) { + tests := []struct { + name string + typeFunc func() string + expected string + }{ + { + name: "APIResourceReference", + typeFunc: func() string { return APIResourceReference{}.OpenAPIModelName() }, + expected: "com.github.operator-framework.api.pkg.operators.v1alpha1.APIResourceReference", + }, + { + name: "APIServiceDefinitions", + typeFunc: func() string { return APIServiceDefinitions{}.OpenAPIModelName() }, + expected: "com.github.operator-framework.api.pkg.operators.v1alpha1.APIServiceDefinitions", + }, + { + name: "APIServiceDescription", + typeFunc: func() string { return APIServiceDescription{}.OpenAPIModelName() }, + expected: "com.github.operator-framework.api.pkg.operators.v1alpha1.APIServiceDescription", + }, + { + name: "ActionDescriptor", + typeFunc: func() string { return ActionDescriptor{}.OpenAPIModelName() }, + expected: "com.github.operator-framework.api.pkg.operators.v1alpha1.ActionDescriptor", + }, + { + name: "AppLink", + typeFunc: func() string { return AppLink{}.OpenAPIModelName() }, + expected: "com.github.operator-framework.api.pkg.operators.v1alpha1.AppLink", + }, + { + name: "CRDDescription", + typeFunc: func() string { return CRDDescription{}.OpenAPIModelName() }, + expected: "com.github.operator-framework.api.pkg.operators.v1alpha1.CRDDescription", + }, + { + name: "CleanupSpec", + typeFunc: func() string { return CleanupSpec{}.OpenAPIModelName() }, + expected: "com.github.operator-framework.api.pkg.operators.v1alpha1.CleanupSpec", + }, + { + name: "CleanupStatus", + typeFunc: func() string { return CleanupStatus{}.OpenAPIModelName() }, + expected: "com.github.operator-framework.api.pkg.operators.v1alpha1.CleanupStatus", + }, + { + name: "ClusterServiceVersionCondition", + typeFunc: func() string { return ClusterServiceVersionCondition{}.OpenAPIModelName() }, + expected: "com.github.operator-framework.api.pkg.operators.v1alpha1.ClusterServiceVersionCondition", + }, + { + name: "ClusterServiceVersionSpec", + typeFunc: func() string { return ClusterServiceVersionSpec{}.OpenAPIModelName() }, + expected: "com.github.operator-framework.api.pkg.operators.v1alpha1.ClusterServiceVersionSpec", + }, + { + name: "ClusterServiceVersionStatus", + typeFunc: func() string { return ClusterServiceVersionStatus{}.OpenAPIModelName() }, + expected: "com.github.operator-framework.api.pkg.operators.v1alpha1.ClusterServiceVersionStatus", + }, + { + name: "CustomResourceDefinitions", + typeFunc: func() string { return CustomResourceDefinitions{}.OpenAPIModelName() }, + expected: "com.github.operator-framework.api.pkg.operators.v1alpha1.CustomResourceDefinitions", + }, + { + name: "DependentStatus", + typeFunc: func() string { return DependentStatus{}.OpenAPIModelName() }, + expected: "com.github.operator-framework.api.pkg.operators.v1alpha1.DependentStatus", + }, + { + name: "Icon", + typeFunc: func() string { return Icon{}.OpenAPIModelName() }, + expected: "com.github.operator-framework.api.pkg.operators.v1alpha1.Icon", + }, + { + name: "InstallMode", + typeFunc: func() string { return InstallMode{}.OpenAPIModelName() }, + expected: "com.github.operator-framework.api.pkg.operators.v1alpha1.InstallMode", + }, + { + name: "Maintainer", + typeFunc: func() string { return Maintainer{}.OpenAPIModelName() }, + expected: "com.github.operator-framework.api.pkg.operators.v1alpha1.Maintainer", + }, + { + name: "NamedInstallStrategy", + typeFunc: func() string { return NamedInstallStrategy{}.OpenAPIModelName() }, + expected: "com.github.operator-framework.api.pkg.operators.v1alpha1.NamedInstallStrategy", + }, + { + name: "RelatedImage", + typeFunc: func() string { return RelatedImage{}.OpenAPIModelName() }, + expected: "com.github.operator-framework.api.pkg.operators.v1alpha1.RelatedImage", + }, + { + name: "RequirementStatus", + typeFunc: func() string { return RequirementStatus{}.OpenAPIModelName() }, + expected: "com.github.operator-framework.api.pkg.operators.v1alpha1.RequirementStatus", + }, + { + name: "ResourceInstance", + typeFunc: func() string { return ResourceInstance{}.OpenAPIModelName() }, + expected: "com.github.operator-framework.api.pkg.operators.v1alpha1.ResourceInstance", + }, + { + name: "ResourceList", + typeFunc: func() string { return ResourceList{}.OpenAPIModelName() }, + expected: "com.github.operator-framework.api.pkg.operators.v1alpha1.ResourceList", + }, + { + name: "SpecDescriptor", + typeFunc: func() string { return SpecDescriptor{}.OpenAPIModelName() }, + expected: "com.github.operator-framework.api.pkg.operators.v1alpha1.SpecDescriptor", + }, + { + name: "StatusDescriptor", + typeFunc: func() string { return StatusDescriptor{}.OpenAPIModelName() }, + expected: "com.github.operator-framework.api.pkg.operators.v1alpha1.StatusDescriptor", + }, + { + name: "StrategyDeploymentPermissions", + typeFunc: func() string { return StrategyDeploymentPermissions{}.OpenAPIModelName() }, + expected: "com.github.operator-framework.api.pkg.operators.v1alpha1.StrategyDeploymentPermissions", + }, + { + name: "StrategyDeploymentSpec", + typeFunc: func() string { return StrategyDeploymentSpec{}.OpenAPIModelName() }, + expected: "com.github.operator-framework.api.pkg.operators.v1alpha1.StrategyDeploymentSpec", + }, + { + name: "StrategyDetailsDeployment", + typeFunc: func() string { return StrategyDetailsDeployment{}.OpenAPIModelName() }, + expected: "com.github.operator-framework.api.pkg.operators.v1alpha1.StrategyDetailsDeployment", + }, + { + name: "WebhookDescription", + typeFunc: func() string { return WebhookDescription{}.OpenAPIModelName() }, + expected: "com.github.operator-framework.api.pkg.operators.v1alpha1.WebhookDescription", + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + require.Equal(t, tt.expected, tt.typeFunc()) + }) + } +}