feat: add external reference inspection, export ErrExternalRefNotAllowed, and recover linter rule panics
TH
2d ago+548+548+012345678901234567890123456789-6-6-0123456789
Summary
- Export
references.ErrExternalRefNotAllowed(references/resolution.go): Replaces the inlineerrors.New("external reference not allowed")sentinel so callers usingResolveOptions.DisableExternalRefscan match the error viaerrors.Is. - Add zero-I/O external reference inspection on
*openapi.OpenAPI(openapi/external_refs.go):FindExternalRefs(ctx) ([]ExternalReference, error)walks modeled OpenAPI referenceable nodes (Walk) without performing filesystem or network I/O and returns every$refwith a non-empty URI alongside a clonedLocationsslice. Respects context cancellation cleanly.ValidateNoExternalRefs(ctx) errorjoins errors wrappingreferences.ErrExternalRefNotAllowedfor each external reference found.
- Recognize YAML merge keys on Reference Objects (
openapi/core/reference.go): Expands<<merge keys viayml.ResolveMergeKeysbefore checking for$refso merged references on non-schema Reference Objects (e.g. responses, parameters, path items) are unmarshaled as references rather than inline objects. - Guard nil elements in walkers (
openapi/walk_tags_servers.go,jsonschema/oas3/walk.go): Avoid nil-pointer dereferences when walking programmatically constructed documents containing nilServerVariablemap values or zero-valueJSONSchemawrappers. - Recover panics in concurrent linter rule goroutines (
linter/linter.go): Pre-captures the rule ID before launching each goroutine and converts any recovered panic into avalidation.Errorrather than terminating the caller process.
Verification
mise cipassed locally (format check,go.modtidy across workspace modules,golangci-lintwith 0 issues,nilaway, examples check, unit tests with-race, CLI integration tests, and build).
Summary by cubic
Adds zero-I/O external reference inspection for OpenAPI documents and makes the linter recover from rule panics instead of crashing.
New Features
OpenAPI.FindExternalRefs(ctx)walks all modeled references without filesystem or network I/O and returns external$refURIs with their locations.OpenAPI.ValidateNoExternalRefs(ctx)returns an error wrappingreferences.ErrExternalRefNotAllowed, with each reference's location in the error message.- Exports
references.ErrExternalRefNotAllowedso callers can match it witherrors.Is.
Bug Fixes
- Recovered panics in concurrent linter rule goroutines: panics are now converted to
validation.Errorresults with stack traces rather than terminating the process. - YAML merge keys (
<<) are expanded before$refdetection on Reference Objects, so merged references unmarshal as references instead of inline objects. - Walkers no longer panic on nil
ServerVariablevalues or zero-valueJSONSchemawrappers in programmatically built documents.