8000 Add tests to verify OpenAPI extensions preservation in AnyPattern for oneOfs by Copilot · Pull Request #1911 · specmatic/specmatic · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

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

Merged
merged 6 commits into from
Jun 13, 2025

Conversation

Copilot
Copy link
Contributor
@Copilot Copilot AI commented Jun 13, 2025

Summary

This PR adds comprehensive tests to verify that OpenAPI extensions (x- properties) are properly preserved in AnyPattern for both nested and top-level oneOf 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 an allOf, and each oneOf option has its own extension:

ExtendedProduct:
  allOf:
    - type: object
      properties:
        data:
          type: string
    - type: object
      properties:
        characteristic:
          oneOf:
            - type: object
              x-property-1: value1
              properties:
                category:
                  type: string
                price:
                  type: number
            - type: object
              x-property-2: value2
              properties:
                category:
                  type: string
                price:
                  type: number

The test verifies that the resulting AnyPattern for the characteristic property preserves both x-property-1: value1 and x-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:

ExtendedProduct:
  oneOf:
    - type: object
      x-property-1: value1
      properties:
        category:
          type: string
        price:
          type: number
    - type: object
      x-property-2: value2
      properties:
        category:
          type: string
        price:
          type: number

The test verifies that the resulting AnyPattern preserves both extensions from all oneOf options.

Test 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() mechanism

Implementation Notes

  • No application code changes were made as per the requirements
  • Tests follow the existing patterns in OpenAPIExtensionsTest.kt
  • The existing AnyPattern.extractCombinedExtensions() mechanism already handles extension preservation correctly
  • Tests use resolvedHop() to resolve patterns consistently with existing test patterns
  • Both scenarios use proper OpenAPI schema structure with required fields and valid property definitions

Verification

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 implement PossibleJsonObjectPatternContainer.


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

… oneOfs

Co-authored-by: joelrosario <63343+joelrosario@users.noreply.github.com>
@Copilot Copilot AI changed the title [WIP] Test preservation of OpenAPI extensions in AnyPattern for nested and top-level oneOfs Add tests to verify OpenAPI extensions preservation in AnyPattern for oneOfs Jun 13, 2025
@Copilot Copilot AI requested a review from joelrosario June 13, 2025 07:30
Copilot finished work on behalf of joelrosario June 13, 2025 07:30
@joelrosario
Copy link
Contributor

@copilot

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>
Copy link
Contributor Author
Copilot AI commented Jun 13, 2025

@copilot

Test 3
...

I've added the third test case as requested. The test verifies the scenario where an allOf contains both a common extension (x-property-common) and a oneOf with individual extensions (x-property-1, x-property-2).

The test is currently failing because the current implementation preserves the common extension but doesn't combine it with the individual oneOf extensions as expected. This test documents the expected behavior and exposes this limitation. Commit: c286fca

Copilot finished work on behalf of joelrosario June 13, 2025 09:52
Copy link
Contributor
@joelrosario joelrosario left a 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>
Copy link
Contributor Author
Copilot AI commented Jun 13, 2025

Fix the assertion as described, then update the code so that the tests pass.

Fixed the assertion and updated the code to make the test pass. The implementation now correctly handles allOf+oneOf scenarios with empty top-level AnyPattern.extensions while preserving combined extensions in constituent patterns. Commit: d456f54

Copilot finished work on behalf of joelrosario June 13, 2025 10:43
@joelrosario joelrosario marked this pull request as ready for review June 13, 2025 11:23
@joelrosario joelrosario merged commit bfcda40 into main Jun 13, 2025
2 of 3 checks passed
@joelrosario joelrosario deleted the copilot/fix-9bea1ca5-6ee5-4af5-8d18-0a624048d571 branch June 13, 2025 11:24
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.

2 participants
0