Skip to content

Add underOpenAPIExamplePath function to filter schema IDs in examples#549

Open
LukasParke wants to merge 4 commits intopb33f:mainfrom
LukasParke:skip-$id-example
Open

Add underOpenAPIExamplePath function to filter schema IDs in examples#549
LukasParke wants to merge 4 commits intopb33f:mainfrom
LukasParke:skip-$id-example

Conversation

@LukasParke
Copy link
Copy Markdown

  • 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.

luke-hagar-sp and others added 2 commits March 24, 2026 12:53
- 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 {
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.

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) {
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.

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) {
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.

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.

Copy link
Copy Markdown
Member

@daveshanley daveshanley left a comment

Choose a reason for hiding this comment

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

There is a regression with this code. left a few comments.

luke-hagar-sp and others added 2 commits March 30, 2026 10:14
…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>
@luke-hagar-sp
Copy link
Copy Markdown

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?

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.

3 participants