-
Notifications
You must be signed in to change notification settings - Fork 57
Add tests to verify OpenAPI extensions preservation in AnyPattern for oneOfs #1911
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add tests to verify OpenAPI extensions preservation in AnyPattern for oneOfs #1911
Conversation
… oneOfs Co-authored-by: joelrosario <63343+joelrosario@users.noreply.github.com>
Test 3 In the following example, openapi: 3.0.3
info:
title: Product API
version: 1.0.0
paths:
/product:
get:
responses:
'200':
description: Product retrieved successfully
content:
application/json:
schema:
${'$'}ref: '#/components/schemas/ExtendedProduct'
components:
schemas:
ExtendedProduct:
allOf:
- type: object
x-property-common: valueCommn
properties:
info:
type: string
required:
- info
- oneOf:
- type: object
x-property-1: value1
properties:
category:
type: string
required:
- category
- type: object
x-property-2: value2
properties:
price:
type: number
required:
- price The response should result an AnyPattern, with two objects, the ifrst of which has x-propertyCommon and x-property-1, and the second of which has x-propertyCommon and x-property-2. |
…rently failing Co-authored-by: joelrosario <63343+joelrosario@users.noreply.github.com>
I've added the third test case as requested. The test verifies the scenario where an The test is currently failing because the current implementation preserves the common extension but doesn't combine it with the individual |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix the assertion as described, then update the code so that the tests pass.
…rn extensions empty while preserving combined extensions in constituent patterns Co-authored-by: joelrosario <63343+joelrosario@users.noreply.github.com>
Fixed the assertion and updated the code to make the test pass. The implementation now correctly handles allOf+oneOf scenarios with empty top-level |
Summary
This PR adds comprehensive tests to verify that OpenAPI extensions (x- properties) are properly preserved in
AnyPattern
for both nested and top-leveloneOf
scenarios, as requested in the issue.Changes Made
Added two new test cases to
OpenAPIExtensionsTest.kt
:1.
should preserve extensions from oneOf options within allOf
Tests the scenario where a
oneOf
is nested inside anallOf
, and eachoneOf
option has its own extension:The test verifies that the resulting
AnyPattern
for thecharacteristic
property preserves bothx-property-1: value1
andx-property-2: value2
.2.
should preserve extensions from top-level oneOf options
Tests the scenario where a top-level
oneOf
has extensions on each option:The test verifies that the resultingoneOf options.
AnyPattern
preserves both extensions from allTest Results
✅ All existing tests continue to pass (no regression)
✅ Both new tests pass, confirming that extension preservation works correctly
✅ Extensions are properly combined using the existing
extractCombinedExtensions()
mechanismImplementation Notes
OpenAPIExtensionsTest.kt
AnyPattern.extractCombinedExtensions()
mechanism already handles extension preservation correctlyresolvedHop()
to resolve patterns consistently with existing test patternsVerification
The tests confirm that Specmatic's existing implementation correctly preserves OpenAPI extensions through the
AnyPattern
constructor, which automatically extracts and combines extensions from constituent patterns that implementPossibleJsonObjectPatternContainer
.💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.