Repository navigation
fix(datamodel): don't build an operation from a non-mapping value - #711
Open
Tjmstudios wants to merge 1 commit into
Open
Tjmstudios wants to merge 1 commit into
Tjmstudios wants to merge 1 commit into
Conversation
PathItem.Build built every operation slot with BuildModel and stored a
pointer to the result whatever the value was. "get:", "get: null" or
"FOO: null" under additionalOperations therefore came out as a non-nil,
empty Operation, the same as a real one with no fields. The high model
then reported a GET the document never declared.
Skip an operation whose value, after $ref resolution, is not a mapping.
In v3 this covers the fixed slots, additionalOperations entries and
root-level additional operations whose $ref resolves to a non-mapping.
The v2 PathItem.Build had the same defect and gets the same check. An
empty mapping ("get: {}") is still an operation.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #711 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 315 315
Lines 39758 39764 +6
=========================================
+ Hits 39758 39764 +6
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.
Summary
A null operation (
get:,get: null,FOO: nullunderadditionalOperations) builds into a non-nil, emptyOperation, so the model reports an operation the document never declared. This skips operation values that aren't mappings, in the v3 and v2 path item builders.Problem
pathItem.Postis non-nil,GetOperations()returnsget,postandFOO, and nothing on the high model tellspostandFOOapart from real operations with no fields. Only the YAML tag on the lowRootNode(!!null) shows the difference.v3
PathItem.BuildrunsBuildModelon whatever the slot holds and stores&opunconditionally, for the fixed slots (path_item.go:321) and for eachadditionalOperationsentry (:383). A root-level additional operation is only checked for being a mapping before its$refis resolved (:309), soFOO: {$ref: '#/x-null'}ends up as an empty operation keyed"null". The v2PathItem.Build(datamodel/low/v2/path_item.go:114) has the same unconditional build.Changes
PathItem.Buildskips an operation whose value, after$refresolution, is not a mapping: fixed slots,additionalOperationsentries and root-level additional operations. The slot stays empty and the high field stays nil.PathItem.Buildgets the same check. It doesn't resolve operation$refs, so it checks the value as written.additionalOperationsare all null ends up with noAdditionalOperations, the same as when they are absent.get: {}is still an (empty) operation.Effects of a null operation now being absent from the model:
Hash()of a path item withget: nullequals the hash withoutget.get: nullinstead of writingget: {}.put: null→ absent as a removed operation.$refwhose target isn't a mapping is dropped as well, on render and in the bundler too. Before, render kept the$refand the bundler wroteput: {}.Tests
main:TestPathItem_Build_NonMappingOperations,TestPathItem_Build_OnlyNullAdditionalOperationsandTestPathItem_Hash_NullOperationindatamodel/low/v3/path_item_test.goTestPathItem_NullOperationsindatamodel/high/v3/path_item_test.goTestPathItem_Build_NonMappingOperationsindatamodel/low/v2/path_item_test.goget: null,put:,post: ~, a scalar, an empty string or a sequence$refthat resolves to null, as a fixed slot, anadditionalOperationsentry and a root-level additional operationadditionalOperationsentriesget: nullagainst an absent and an emptygetgo test ./...passes.