Skip to content

Conversation

@majchinmesh
Copy link

Pull Request

Thank you for contributing to swagger-parser!

Please fill out the following checklist to help us review your PR efficiently.


Description

This PR addresses the issue #2157. It resolves a problem related to the handling of additionalProperties in OpenAPI schemas that combine multiple schemas using allOf. Specifically, the changes ensure that the additionalProperties field is properly resolved when combined schemas are used in OpenAPI v3. This also includes additional test cases and YAML files to verify the fix across different versions.

Changes:

  • Added logic to correctly resolve additionalProperties when using allOf in OpenAPI schemas.
  • Updated the aggregateSchemaCombinators method in ResolverFully.java to handle additionalProperties correctly.
  • Added four new YAML test cases to cover different use cases of additionalProperties with allOf.
  • Added corresponding test cases in OpenAPIParserTest.java to verify the behavior.

Fixes: #2157

Type of Change

  • 🐛 Bug fix
  • ✨ New feature
  • ♻️ Refactor (non-breaking change)
  • 🧪 Tests
  • 📝 Documentation
  • 🧹 Chore (build or tooling)

Checklist

  • I have added/updated tests as needed
  • I have added/updated documentation where applicable
  • The PR title is descriptive
  • The code builds and passes tests locally
  • I have linked related issues (if any)

Screenshots / Additional Context

Changes in the Codebase:

  1. ResolverFully.java

    • Line 683, added logic to handle the additionalProperties field when resolving fully combined schemas.
  2. OpenAPIParserTest.java

    • Added 4 new tests for different versions (v1 to v4) of the additionalProperties feature:
      • testAdditionalPropertiesWithAllOfV1()
      • testAdditionalPropertiesWithAllOfV2()
      • testAdditionalPropertiesWithAllOfV3()
      • testAdditionalPropertiesWithAllOfV4()
  3. Test Resources:

    • Added the following YAML test files to ensure correctness:
      • additionalProperties_allOf_v1.yaml
      • additionalProperties_allOf_v2.yaml
      • additionalProperties_allOf_v3.yaml
      • additionalProperties_allOf_v4.yaml

Sample Test Case for Version v1:

openapi: 3.0.1
info:
  title: Test API
  version: 1.0.0
paths:
  /test:
    get:
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/TestSchema'
components:
  schemas:
    ObjectWithAdditionalProperties:
      type: object
      additionalProperties: true
      properties:
        name:
          type: string
    TestSchema:
      allOf:
        - $ref: '#/components/schemas/ObjectWithAdditionalProperties'

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.

additionalProperties inside ComposedSchema are resolved as null

2 participants