Skip to content
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

Type aliases are flattened to the underlying type. #180

Closed
jpeach opened this issue Jun 10, 2020 · 8 comments
Closed

Type aliases are flattened to the underlying type. #180

jpeach opened this issue Jun 10, 2020 · 8 comments
Labels
lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed.

Comments

@jpeach
Copy link
Contributor

jpeach commented Jun 10, 2020

Over in service-apis , I used https://github.com/ahmetb/gen-crd-api-reference-docs to generate the CRD API documentation. This project uses gengo to parse the Go types for the CRD, and generates HTML documentation.

In the service-apis CRD, we use type aliases like this:

type ConfigMapsDefaultLocalObjectReference struct {
...
}

type GatewayClassParametersObjectReference = ConfigMapsDefaultLocalObjectReference
type RouteHostExtensionObjectReference = ConfigMapsDefaultLocalObjectReference
type RouteActionExtensionObjectReference = ConfigMapsDefaultLocalObjectReference

The end result of this is that all the aliases get flattened to the underlying type ConfigMapsDefaultLocalObjectReference.

I'm not at all familiar with any of the machinery underlying this, but the only way I could see to detect the alias was using IsAlias on the type name before walking the type. Once you do this, it might be reasonable to emit the type alias as a type of Kind "Alias", but I'm not sure whether that's a good idea or not.

Here's a bit of a patch that I was messing with that is probably very naive about different type alias possibilities:

@@ -534,7 +535,22 @@ func (b *Builder) findTypesIn(pkgPath importPathString, u *types.Universe) error
                obj := s.Lookup(n)
                tn, ok := obj.(*tc.TypeName)
                if ok {
-                       t := b.walkType(*u, nil, tn.Type())
+                       var typeName *types.Name
+
+                       if tn.IsAlias() {
+                               log.Printf("found TypeName alias name=%q type.Name=%q pkg.Name=%q id=%q",
+                                       tn.Name(), tn.Type().String(), tn.Pkg().Path(), tn.Id())
+                               // typeName = tcNameToName(tn.Name())
+                               typeName = &types.Name{
+                                       Name: tn.Name(),
+                               }
+
+                               if tn.Pkg() != nil {
+                                       typeName.Package = tn.Pkg().Name()
+                               }
+                       }
+
+                       t := b.walkType(*u, typeName, tn.Type())
                        c1 := b.priorCommentLines(obj.Pos(), 1)
                        // c1.Text() is safe if c1 is nil
                        t.CommentLines = splitLines(c1.Text())
@lavalamp
Copy link
Member

This will be tricky to fix since I'm pretty sure the main repo types rely on this, especially for primitives.

@jpeach
Copy link
Contributor Author

jpeach commented Jun 10, 2020

This will be tricky to fix since I'm pretty sure the main repo types rely on this, especially for primitives.

Yup, I can imagine a lot of potential for nasty surprises if the semantics of the alias kind are changed.

@fejta-bot
Copy link

Issues go stale after 90d of inactivity.
Mark the issue as fresh with /remove-lifecycle stale.
Stale issues rot after an additional 30d of inactivity and eventually close.

If this issue is safe to close now please do so with /close.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/lifecycle stale

@k8s-ci-robot k8s-ci-robot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Sep 9, 2020
@jpeach
Copy link
Contributor Author

jpeach commented Sep 9, 2020

/remove-lifecycle stale

@k8s-ci-robot k8s-ci-robot removed the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Sep 9, 2020
@fejta-bot
Copy link

Issues go stale after 90d of inactivity.
Mark the issue as fresh with /remove-lifecycle stale.
Stale issues rot after an additional 30d of inactivity and eventually close.

If this issue is safe to close now please do so with /close.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/lifecycle stale

@k8s-ci-robot k8s-ci-robot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Dec 8, 2020
@fejta-bot
Copy link

Stale issues rot after 30d of inactivity.
Mark the issue as fresh with /remove-lifecycle rotten.
Rotten issues close after an additional 30d of inactivity.

If this issue is safe to close now please do so with /close.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/lifecycle rotten

@k8s-ci-robot k8s-ci-robot added lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. and removed lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. labels Jan 7, 2021
@fejta-bot
Copy link

Rotten issues close after 30d of inactivity.
Reopen the issue with /reopen.
Mark the issue as fresh with /remove-lifecycle rotten.

Send feedback to sig-contributor-experience at kubernetes/community.
/close

@k8s-ci-robot
Copy link
Contributor

@fejta-bot: Closing this issue.

In response to this:

Rotten issues close after 30d of inactivity.
Reopen the issue with /reopen.
Mark the issue as fresh with /remove-lifecycle rotten.

Send feedback to sig-contributor-experience at kubernetes/community.
/close

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed.
Projects
None yet
Development

No branches or pull requests

4 participants