← back to Cli Printing Press
feat(cli): auto-calibrate endpoint-per-resource limit from spec
dd5abb1fc13425e3143bcd596e6b03d3fe077944 · 2026-04-05 14:51:34 -0700 · Trevin Chow
Pre-scans the spec to find the largest resource or sub-resource and
bumps the limit to accommodate it. Well-formed specs no longer have
endpoints silently skipped. The --max-endpoints-per-resource flag
still works as an explicit override when set.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Files touched
M internal/openapi/parser.go
Diff
commit dd5abb1fc13425e3143bcd596e6b03d3fe077944
Author: Trevin Chow <trevin@trevinchow.com>
Date: Sun Apr 5 14:51:34 2026 -0700
feat(cli): auto-calibrate endpoint-per-resource limit from spec
Pre-scans the spec to find the largest resource or sub-resource and
bumps the limit to accommodate it. Well-formed specs no longer have
endpoints silently skipped. The --max-endpoints-per-resource flag
still works as an explicit override when set.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
---
internal/openapi/parser.go | 34 ++++++++++++++++++++++++++++++----
1 file changed, 30 insertions(+), 4 deletions(-)
diff --git a/internal/openapi/parser.go b/internal/openapi/parser.go
index e94bdea4..4bcc8576 100644
--- a/internal/openapi/parser.go
+++ b/internal/openapi/parser.go
@@ -21,15 +21,16 @@ import (
var (
maxResources = 50
maxEndpointsPerResource = 50
+ endpointLimitExplicit = false // true when user set --max-endpoints-per-resource
)
-// SetMaxEndpointsPerResource overrides the default limit of 50 endpoints per
-// resource. Use this when generating from large specs (e.g., Cal.com organizations
-// which has 50+ endpoints). The limit prevents runaway generation from malformed
-// specs while allowing legitimate large resources to be fully covered.
+// SetMaxEndpointsPerResource overrides the default limit and disables
+// auto-calibration. When not called, the parser auto-calibrates the limit
+// from the spec so well-formed specs never have endpoints silently skipped.
func SetMaxEndpointsPerResource(n int) {
if n > 0 {
maxEndpointsPerResource = n
+ endpointLimitExplicit = true
}
}
@@ -754,6 +755,31 @@ func mapResources(doc *openapi3.T, out *spec.APISpec, basePath string) {
sort.Strings(pathKeys)
commonPrefix := detectCommonPrefix(pathKeys, basePath)
+ // Auto-calibrate endpoint limit unless the user explicitly set it.
+ // Pre-scans the spec to find the largest resource or sub-resource,
+ // then bumps the limit so well-formed specs never have endpoints silently
+ // skipped. The limit is checked per endpoint map (resource.Endpoints or
+ // sub.Endpoints), so we count per (primary, sub) pair to find the true max.
+ if !endpointLimitExplicit {
+ type resourceKey struct{ primary, sub string }
+ endpointCounts := map[resourceKey]int{}
+ for _, path := range pathKeys {
+ primaryName, subName := resourceAndSubFromPath(path, basePath, commonPrefix)
+ if primaryName == "" {
+ continue
+ }
+ pathItem := doc.Paths.Value(path)
+ if pathItem != nil {
+ endpointCounts[resourceKey{primaryName, subName}] += len(pathItem.Operations())
+ }
+ }
+ for _, count := range endpointCounts {
+ if count > maxEndpointsPerResource {
+ maxEndpointsPerResource = count
+ }
+ }
+ }
+
for _, path := range pathKeys {
pathItem := doc.Paths.Value(path)
if pathItem == nil {
← 95c96c4d fix(cli): address Cal.com retro findings — scoring, template
·
back to Cli Printing Press
·
chore(main): release 1.0.0 (#45) 3e9ac6d8 →