-
Notifications
You must be signed in to change notification settings - Fork 78
fix: add OpenAPIModelName for all types referenced in OpenAPI schemas #476
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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" | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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()) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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" | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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()) | ||
| }) | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We do not add license in this project
So I think we should keep all as it is in the other files.
Could you please remove from all? And keep the current standards
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The root Apache license should be sufficient. As pointed out, there's no copyright/licensing in individual files.