Skip to content

fix(v3): don't inject empty webhooks: {} for OpenAPI 3.0 docs with a same-named scalar value#587

Open
asadtariq96 wants to merge 1 commit into
pb33f:mainfrom
asadtariq96:fix/webhooks-false-positive-3.0
Open

fix(v3): don't inject empty webhooks: {} for OpenAPI 3.0 docs with a same-named scalar value#587
asadtariq96 wants to merge 1 commit into
pb33f:mainfrom
asadtariq96:fix/webhooks-false-positive-3.0

Conversation

@asadtariq96

Copy link
Copy Markdown

What

extractWebhooks (in datamodel/low/v3/create_document.go) called low.ExtractMap[*PathItem](ctx, WebhooksLabel, root, idx) unconditionally and then guarded on the returned key/value nodes (if hooksN != nil && hooksL != nil).

When a document has no top-level webhooks key, ExtractMap resolves the label through the index and can match a same-named scalar value elsewhere in the document — e.g. the webhooks in x-foo: { service: webhooks }, or a server URL ending in /webhooks. That returns a non-nil empty map plus non-nil key/value nodes, so doc.Webhooks gets populated with an empty map, which the high-level model renders as webhooks: {}.

webhooks is an OpenAPI 3.1+ field, so emitting it into a rendered 3.0.x document produces output that fails strict 3.0 schema validation (e.g. Spectral oas3-schema).

Fix

Gate extraction on the genuine top-level webhooks node (nodes.webhooks, already collected by collectDocumentTopLevelNodes), mirroring extractServers / extractTags / extractPaths, which all resolve the real top-level key and guard on vn != nil. extractWebhooks was the only top-level extractor bypassing that.

Regression range

Bisected to cda65e2 ("more model refactoring and cleanup"), first released in v0.35.1. v0.34.4 and earlier are unaffected; v0.35.1v0.37.3 are affected.

Test

Added TestCreateDocument_WebHooks_NoFalsePositive covering a 3.0 doc whose only occurrence of webhooks is a vendor-extension scalar value; asserts doc.Webhooks is not populated. Existing webhooks tests (TestCreateDocument_WebHooks, TestCreateDocument_WebHooks_Error, the collectDocumentTopLevelNodes tests) still pass, and the full go test ./... suite is green.

Fixes #586

…amed scalar

extractWebhooks called ExtractMap unconditionally and guarded on the
returned key/value nodes. When a document has no top-level `webhooks`
key, ExtractMap resolves the label through the index and can match a
same-named scalar value elsewhere (e.g. `service: webhooks`), producing
a non-nil empty webhooks map that renders as `webhooks: {}` -- invalid
in OpenAPI 3.0.x.

Gate extraction on the genuine top-level `webhooks` node collected in
documentTopLevelNodes, mirroring extractServers/extractTags/extractPaths.

Fixes pb33f#586
@asadtariq96 asadtariq96 force-pushed the fix/webhooks-false-positive-3.0 branch from 50014f1 to acbc61c Compare June 11, 2026 18:36
@codecov

codecov Bot commented Jun 11, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.72%. Comparing base (ef151b6) to head (acbc61c).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #587   +/-   ##
=======================================
  Coverage   99.72%   99.72%           
=======================================
  Files         280      280           
  Lines       33894    33896    +2     
=======================================
+ Hits        33802    33804    +2     
  Misses         55       55           
  Partials       37       37           
Flag Coverage Δ
unittests 99.72% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@daveshanley daveshanley left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

lgtm, thanks.

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.

Empty webhooks: {} injected when rendering OpenAPI 3.0 docs containing a same-named scalar value (regression in v0.35.1)

2 participants