Skip to content

Issue 422 #771

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 1 commit into from
Apr 26, 2025
Merged

Issue 422 #771

merged 1 commit into from
Apr 26, 2025

Conversation

maksim-kosolapov
Copy link
Contributor

@maksim-kosolapov maksim-kosolapov commented Apr 20, 2025

Have fixed the StackOverflow issue. resolveComposedSchema populates properties from 'allOf/anyOf' refs and if they contain recursive reference it creates a recursive data structure which fails further.

But apart from StackOverflow issue the provided here openapi spec fails with detected changes for the response. That's weird, haven't managed to figure out why yet.

==========================================================================
==                            API CHANGE LOG                            ==
==========================================================================
           Smart Manufacturing Operation Management Service API           
--------------------------------------------------------------------------
--                            What's Changed                            --
--------------------------------------------------------------------------
- GET    /smartmom-svc/api/views/workorders/{id}
  Return Type:
    - Changed 200 OK
      Media types:
        - Changed application/json
          Schema: Backward compatible
--------------------------------------------------------------------------
--                                Result                                --
--------------------------------------------------------------------------
                   API changes are backward compatible                    
--------------------------------------------------------------------------

I think it makes sense to merge this fix and handle the response diff issue later.

closes #422

schema = addSchema(schema, composed);
if (composed.getProperties() != null
&& composed.getProperties().containsValue(composedSchema)) {
logger.warn(
Copy link
Contributor Author

@maksim-kosolapov maksim-kosolapov Apr 20, 2025

Choose a reason for hiding this comment

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

Shouldn't we fail in case of recursive refs? It's an invalid specification, isn't it

Copy link
Collaborator

Choose a reason for hiding this comment

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

@maksim-kosolapov thanks for your PR.
I would say cyclic refs are pretty normal for OpenAPI spec (meanwhile it's not convenient to handle them).

So based on code above this resolveComposedSchema method should handle cyclic refs
if (composed.get$ref() == null || !visitedRefs.contains(composed.get$ref())) so while diving into the properties processing cyclic refs should be skipped. Suppose there is an issue with how this method handle visitedRefs in recursion. Could you please check it from this perspective?

Copy link
Contributor Author

@maksim-kosolapov maksim-kosolapov Apr 26, 2025

Choose a reason for hiding this comment

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

@DrSatyr Didn't manage how to handle this back then. But now I think I got it. Passing keys from the RecursiveSchemaSet to resolveComposedSchema this way it should handle recursive refs up to the root.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yeah, looks reasonable. Thanks for your effort!

@DrSatyr
Copy link
Collaborator

DrSatyr commented Apr 22, 2025

BTW - I've just created #772, we have inconsistent behaviour for oneOf in comparison with anyOf/allOf. I would prefer oneOf approach. Just for now let's resolve StackOverFlow issue in terms of this PR.

@DrSatyr DrSatyr requested a review from Copilot April 22, 2025 19:56
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR addresses a StackOverflow error caused by recursive schema composition in the OpenAPI diff library by fixing the improper handling of schema keys and adding a circular reference check with a warning log.

  • Corrected the key assignment in RecursiveSchemaSet
  • Added a conditional check to log and prevent re-adding a schema that might cause recursion in SchemaDiff

Reviewed Changes

Copilot reviewed 2 out of 3 changed files in this pull request and generated no comments.

File Description
core/src/main/java/org/openapitools/openapidiff/core/model/deferred/RecursiveSchemaSet.java Corrected key assignment for right-hand schema parts
core/src/main/java/org/openapitools/openapidiff/core/compare/SchemaDiff.java Introduced a logging check to detect circular references in composed schemas
Files not reviewed (1)
  • core/src/test/resources/recursive_model_1.yaml: Language not supported
Comments suppressed due to low confidence (2)

core/src/main/java/org/openapitools/openapidiff/core/compare/SchemaDiff.java:102

  • [nitpick] The newly added circular reference check helps prevent recursion, but its logic might skip valid schema additions; consider refining the condition or handling the recursion explicitly to ensure no valid schema is omitted.
if (composed.getProperties() != null && composed.getProperties().containsValue(composedSchema)) {

core/src/main/java/org/openapitools/openapidiff/core/model/deferred/RecursiveSchemaSet.java:16

  • Changing the addition from leftKeys to rightKeys is correct; please ensure that all usages of these keys throughout the class are updated consistently to maintain proper behavior.
rightKeys.add(key.getRight());

@DrSatyr
Copy link
Collaborator

DrSatyr commented Apr 24, 2025

@maksim-kosolapov, this PR will resolve the last remaining issue for the 2.1.0 milestone. Let’s wrap it up and get 2.1.0 released!

@DrSatyr DrSatyr merged commit b661454 into OpenAPITools:master Apr 26, 2025
6 checks passed
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.

StackOverflowError during Processing
2 participants