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
Open
Conversation
…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
50014f1 to
acbc61c
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. 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
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
extractWebhooks(indatamodel/low/v3/create_document.go) calledlow.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
webhookskey,ExtractMapresolves the label through the index and can match a same-named scalar value elsewhere in the document — e.g. thewebhooksinx-foo: { service: webhooks }, or a server URL ending in/webhooks. That returns a non-nil empty map plus non-nil key/value nodes, sodoc.Webhooksgets populated with an empty map, which the high-level model renders aswebhooks: {}.webhooksis 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. Spectraloas3-schema).Fix
Gate extraction on the genuine top-level
webhooksnode (nodes.webhooks, already collected bycollectDocumentTopLevelNodes), mirroringextractServers/extractTags/extractPaths, which all resolve the real top-level key and guard onvn != nil.extractWebhookswas 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.4and earlier are unaffected;v0.35.1–v0.37.3are affected.Test
Added
TestCreateDocument_WebHooks_NoFalsePositivecovering a 3.0 doc whose only occurrence ofwebhooksis a vendor-extension scalar value; assertsdoc.Webhooksis not populated. Existing webhooks tests (TestCreateDocument_WebHooks,TestCreateDocument_WebHooks_Error, thecollectDocumentTopLevelNodestests) still pass, and the fullgo test ./...suite is green.Fixes #586