Skip to content

Conversation

@pem70
Copy link
Contributor

@pem70 pem70 commented Oct 20, 2025

Issue

The method testSwagger () in UnitTestSwaggerUtils from module swagger/swagger-generator/generator-core compares pretty-printed YAML strings to verify correctness. However, since the OpenAPI object is constructed with Map/Set iteration, the key order in the serialized YAML is non-deterministic. When the iteration order changes, the string comparison fails, resulting in flaky behavior.

This test was flagged by the NonDex tool, which detects unreliable tests caused by hidden assumptions in Java API ordering. To reproduce, run an upper test that calls testSwagger, for example:

mvn -pl swagger/swagger-generator/generator-core   edu.illinois:nondex-maven-plugin:2.1.7:nondex   -Dtest=org.apache.servicecomb.swagger.generator.core.TestSwaggerUtils#testSchemaMethod

Affected Tests

This change fixes the below tests:
org.apache.servicecomb.swagger.generator.core.TestPojo.testResponseEntity
org.apache.servicecomb.swagger.generator.core.TestSwaggerUtils.testSchemaMethod
org.apache.servicecomb.swagger.generator.core.TestPojoExample.testPojoExample1

Fix

Instead of comparing raw YAML strings or using JSONAssert as my previous PR, the new implementation parses both expected and actual OpenAPI YAML into JsonNode objects using Jackson’s ObjectMapper and YAMLFactory.
It then checks structural equality via JsonNode.equals(), ensuring order-insensitive comparison while preserving strict value matching.

Rerunning NonDex with this change shows a stable passing result.

PR Checklist

  • Github Issue: [BUG] - Flaky test in UnitTestSwaggerUtils#testSwagger (#4966 )
  • Each commit in the pull request should have a meaningful subject line and body.
  • Run mvn clean install -Pit to make sure basic checks pass. A more thorough check will be performed on your pull request automatically.
  • Format the pull request title like [SCB-XXX], where you replace SCB-XXX with the appropriate JIRA issue.
  • Write a pull request description that is detailed enough to understand what the pull request does, how, and why.

@pem70 pem70 marked this pull request as draft October 21, 2025 03:56
@pem70 pem70 force-pushed the fix-testSchemaMethod branch from 84cab4a to a5c1c20 Compare October 21, 2025 04:06
@pem70 pem70 marked this pull request as ready for review October 21, 2025 04:07
@SweetWuXiaoMei
Copy link
Member

ci跑错了,看下什么问题,然后看下格式问题,我们用的是Google Java style

@pem70 pem70 force-pushed the fix-testSchemaMethod branch from a5c1c20 to 856f2c7 Compare October 23, 2025 03:38
@pem70
Copy link
Contributor Author

pem70 commented Oct 23, 2025

ci跑错了,看下什么问题,然后看下格式问题,我们用的是Google Java style

格式问题已修改,我在本地验证了ci报错的那个测试用例,它在本地是通过的

Update TestSwagger without adding dependencies

Update UnitTestSwaggerUtils.java

Remove unused import
@pem70 pem70 force-pushed the fix-testSchemaMethod branch from 856f2c7 to 4823d3e Compare October 27, 2025 05:08
@pem70
Copy link
Contributor Author

pem70 commented Oct 27, 2025

已rebase, ci问题应已解决

@SweetWuXiaoMei SweetWuXiaoMei merged commit e97e904 into apache:master Oct 27, 2025
5 checks passed
@SweetWuXiaoMei
Copy link
Member

that's great

@pem70 pem70 deleted the fix-testSchemaMethod branch November 14, 2025 02: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