-
Notifications
You must be signed in to change notification settings - Fork 1
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
Count types referenced from resources and warn about excessive ones #68
base: master
Are you sure you want to change the base?
Conversation
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.
There's one minor lint failure if you fancy fixing it up
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.
I'd love to see some tests before we merge. This needs to correctly handle recursive schema and while it looks like it does, we should verify.
if len(ts.OneOf) > 0 { | ||
for _, t := range ts.OneOf { | ||
countType(schema, &t, visitedTypes) | ||
} | ||
} |
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.
This is a pointless check, since it is safe to range over []T{}
and []T(nil)
.
if len(ts.OneOf) > 0 { | |
for _, t := range ts.OneOf { | |
countType(schema, &t, visitedTypes) | |
} | |
} | |
for _, t := range ts.OneOf { | |
countType(schema, &t, visitedTypes) | |
} |
if strings.HasPrefix(ts.Ref, "#/types/") { | ||
typeName := strings.TrimPrefix(ts.Ref, "#/types/") |
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 standard library has a function for exactly this purpose.
if strings.HasPrefix(ts.Ref, "#/types/") { | |
typeName := strings.TrimPrefix(ts.Ref, "#/types/") | |
if typeName, ok := strings.CutPrefix(ts.Ref, "#/types/") { |
Our docs currently have a limitation of displaying max 200 types on a resource API page.
This PR introduces a new types of check for the situation when a given resource
We can look at those warnings and see if we can maybe optimize the type structure before it's shipped to end users.