Skip to content

feat: add external reference inspection, export ErrExternalRefNotAllowed, and recover linter rule panics - #337

Open
ThomasRooney wants to merge 2 commits into
mainfrom
feat/external-ref-inspection
Open

ThomasRooney wants to merge 2 commits into
mainfrom
feat/external-ref-inspection

Conversation

@ThomasRooney

@ThomasRooney ThomasRooney commented Nov 28, 2026 •

Copy link
Copy Markdown
Member

Summary

  • Export references.ErrExternalRefNotAllowed (references/resolution.go): Replaces the inline errors.New("external reference not allowed") sentinel so callers using ResolveOptions.DisableExternalRefs can match the error via errors.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 $ref with a non-empty URI alongside a cloned Locations slice. Respects context cancellation cleanly.
    • ValidateNoExternalRefs(ctx) error joins errors wrapping references.ErrExternalRefNotAllowed for each external reference found.
  • Recognize YAML merge keys on Reference Objects (openapi/core/reference.go): Expands << merge keys via yml.ResolveMergeKeys before checking for $ref so 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 nil ServerVariable map values or zero-value JSONSchema wrappers.
  • 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 a validation.Error rather than terminating the caller process.

Verification

  • mise ci passed locally (format check, go.mod tidy across workspace modules, golangci-lint with 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 $ref URIs with their locations.
  • OpenAPI.ValidateNoExternalRefs(ctx) returns an error wrapping references.ErrExternalRefNotAllowed, with each reference's location in the error message.
  • Exports references.ErrExternalRefNotAllowed so callers can match it with errors.Is.

Bug Fixes

  • Recovered panics in concurrent linter rule goroutines: panics are now converted to validation.Error results with stack traces rather than terminating the process.
  • YAML merge keys (<<) are expanded before $ref detection on Reference Objects, so merged references unmarshal as references instead of inline objects.
  • Walkers no longer panic on nil ServerVariable values or zero-value JSONSchema wrappers in programmatically built documents.

Written for commit 66ed455. Summary will update on new commits.

View guided diff Turn on auto-fix

@ThomasRooney
ThomasRooney requested a review from a team as a code owner November 28, 2026 23:49

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 9 files

Shadow auto-approve: would not auto-approve because issues were found.

View guided diff | Turn on auto-fix | Re-trigger cubic

Comment thread openapi/external_refs.go Resolved
Comment thread linter/linter.go Resolved
Comment thread openapi/external_refs_test.go Resolved
Comment thread openapi/external_refs_test.go Resolved
@codecov

codecov Bot commented Nov 29, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 85.05747% with 13 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
openapi/external_refs.go 82.43% 10 Missing and 3 partials ⚠️

📢 Thoughts on this report? Let us know!

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0 issues found across 4 files (changes from recent commits).

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Shadow auto-approve: would auto-approve. Adds a tested zero-I/O external-reference inspection API and exported sentinel, with linter panic recovery, YAML merge-key ref detection, and nil-guard fixes; all are bounded additive/bug-fix changes covered by tests.

View guided diff | Turn on auto-fix | Re-trigger cubic

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.

1 participant