Skip to content

Conversation

mikhailshilkov
Copy link
Member

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

  • Has more than 200 types referenced from its property types (recursively)
  • That count increased between schema versions

We can look at those warnings and see if we can maybe optimize the type structure before it's shipped to end users.

@mikhailshilkov mikhailshilkov requested a review from a team April 18, 2024 16:55
Copy link
Member

@danielrbradley danielrbradley left a 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

Copy link
Member

@iwahbe iwahbe left a 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.

Comment on lines +52 to +56
if len(ts.OneOf) > 0 {
for _, t := range ts.OneOf {
countType(schema, &t, visitedTypes)
}
}
Copy link
Member

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).

Suggested change
if len(ts.OneOf) > 0 {
for _, t := range ts.OneOf {
countType(schema, &t, visitedTypes)
}
}
for _, t := range ts.OneOf {
countType(schema, &t, visitedTypes)
}

Comment on lines +57 to +58
if strings.HasPrefix(ts.Ref, "#/types/") {
typeName := strings.TrimPrefix(ts.Ref, "#/types/")
Copy link
Member

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.

Suggested change
if strings.HasPrefix(ts.Ref, "#/types/") {
typeName := strings.TrimPrefix(ts.Ref, "#/types/")
if typeName, ok := strings.CutPrefix(ts.Ref, "#/types/") {

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants