Skip to content

feat(expander): add ExpandSchemaWithOptions for confined schema expansion - #291

Merged
fredbi merged 1 commit into
go-openapi:masterfrom
fredbi:feat/expand-schema-with-options
Jul 20, 2026
Merged

feat(expander): add ExpandSchemaWithOptions for confined schema expansion#291
fredbi merged 1 commit into
go-openapi:masterfrom
fredbi:feat/expand-schema-with-options

Conversation

@fredbi

@fredbi fredbi commented Jul 20, 2026

Copy link
Copy Markdown
Member

ExpandSchema expands a schema against an in-memory root but takes no ExpandOptions, so it always uses the package default (unsandboxed) document loader. Downstream consumers that expand a schema whose $ref may come from an untrusted source — go-openapi/analysis (schema analysis, flatten) and go-openapi/validate — had no way to inject a confined loader on this path, and could not reassemble the equivalent themselves because the root-to-base priming (baseForRoot / normalizeBase) is unexported.

Add ExpandSchemaWithOptions(schema, root, cache, opts): the option-aware form of ExpandSchema. It preserves the in-memory-root behavior (base derived from root, schemas always expanded) while honoring the caller's options — in particular PathLoaderWithOptions / PathLoader for a confined loader, plus ContinueOnError, AbsoluteCircularRef and MaxExpansionNodes. ExpandSchema is reimplemented as ExpandSchemaWithOptions(schema, root, cache, nil), so its behavior is unchanged.

Change type

Please select: 🆕 New feature or enhancement|🔧 Bug fix'|📃 Documentation update

Short description

Fixes

Full description

Checklist

  • I have signed all my commits with my name and email (see DCO. This does not require a PGP-signed commit
  • I have rebased and squashed my work, so only one commit remains
  • I have added tests to cover my changes.
  • I have properly enriched go doc comments in code.
  • I have properly documented any breaking change.

…sion

ExpandSchema expands a schema against an in-memory root but takes no
ExpandOptions, so it always uses the package default (unsandboxed) document
loader. Downstream consumers that expand a schema whose $ref may come from an
untrusted source — go-openapi/analysis (schema analysis, flatten) and
go-openapi/validate — had no way to inject a confined loader on this path, and
could not reassemble the equivalent themselves because the root-to-base priming
(baseForRoot / normalizeBase) is unexported.

Add ExpandSchemaWithOptions(schema, root, cache, opts): the option-aware form of
ExpandSchema. It preserves the in-memory-root behavior (base derived from root,
schemas always expanded) while honoring the caller's options — in particular
PathLoaderWithOptions / PathLoader for a confined loader, plus ContinueOnError,
AbsoluteCircularRef and MaxExpansionNodes. ExpandSchema is reimplemented as
ExpandSchemaWithOptions(schema, root, cache, nil), so its behavior is unchanged.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
@codecov

codecov Bot commented Jul 20, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 68.49%. Comparing base (5173965) to head (9d87b80).
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #291      +/-   ##
==========================================
+ Coverage   68.45%   68.49%   +0.03%     
==========================================
  Files          30       30              
  Lines        2435     2438       +3     
==========================================
+ Hits         1667     1670       +3     
  Misses        599      599              
  Partials      169      169              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

@fredbi
fredbi merged commit 9bfe732 into go-openapi:master Jul 20, 2026
21 checks passed
@fredbi
fredbi deleted the feat/expand-schema-with-options branch July 20, 2026 17:22
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