Add underOpenAPIExamplePath function to filter schema IDs in examples#549
Add underOpenAPIExamplePath function to filter schema IDs in examples#549LukasParke wants to merge 4 commits intopb33f:mainfrom
Conversation
LukasParke
commented
Mar 24, 2026
- Introduced underOpenAPIExamplePath function to determine if a path is under OpenAPI example or examples payload.
- Updated ExtractRefs method to skip processing nodes under example paths.
- Added tests to ensure schema IDs in examples are not registered, confirming correct behavior for both example and examples payloads.
- Introduced underOpenAPIExamplePath function to determine if a path is under OpenAPI example or examples payload. - Updated ExtractRefs method to skip processing nodes under example paths. - Added tests to ensure schema IDs in examples are not registered, confirming correct behavior for both example and examples payloads.
- Introduced a new test function, TestUnderOpenAPIExamplePath, to validate the behavior of underOpenAPIExamplePath. - Added various test cases to check for correct identification of paths under OpenAPI example and examples segments. - Ensured comprehensive coverage for edge cases, including empty paths and paths not fully under example segments.
|
|
||
| // underOpenAPIExamplePath reports whether seenPath is under OpenAPI example or examples payload | ||
| // (sample data, not schema). Matches description/summary and properties skipping in this file. | ||
| func underOpenAPIExamplePath(seenPath []string) bool { |
There was a problem hiding this comment.
This helper is too broad. seenPath includes ordinary schema property names, so treating any segment equal to example or examples as an OpenAPI sample payload will incorrectly suppress valid $id extraction for schemas under properties with those names.
| // Check if THIS node has a $id and update scope for processing children | ||
| // This must happen before iterating children so they see the updated scope | ||
| if node.Kind == yaml.MappingNode { | ||
| if node.Kind == yaml.MappingNode && !underOpenAPIExamplePath(seenPath) { |
There was a problem hiding this comment.
Skipping the node-level $id scope update here causes the same false positive: any real schema reached through a property named example or examples will no longer establish its own $id base URI for child traversal.
| assert.Contains(t, petEntry.DefinitionPath, "Pet") | ||
| } | ||
|
|
||
| func TestSchemaId_IgnoredUnderExampleAndExamples(t *testing.T) { |
There was a problem hiding this comment.
These tests only cover $id inside actual OpenAPI example and examples payloads, so they miss the regression where a legitimate schema under properties.example or properties.examples is now incorrectly ignored.
daveshanley
left a comment
There was a problem hiding this comment.
There is a regression with this code. left a few comments.
…I keywords The previous implementation matched any path segment named "example" or "examples", which incorrectly suppressed $id extraction for schemas under properties with those names. Now checks the preceding segment — if it is "properties" or "patternProperties", the segment is a property name and not an OpenAPI example keyword. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
Hey @daveshanley, The regression should be addressed. Are there better ways to expand the tests to cover all of these kinds of situations? Or are most of the edge cases that should be ignored already handled here? |