pem70 opened a new pull request, #4984: URL: https://github.com/apache/servicecomb-java-chassis/pull/4984
### 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**](https://github.com/TestingResearchIllinois/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: ```bash 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](https://github.com/apache/servicecomb-java-chassis/pull/4967), 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 - [x] **Github Issue:** [[BUG] - Flaky test in ``UnitTestSwaggerUtils#testSwagger`` (#4966 )](https://github.com/apache/servicecomb-java-chassis/issues/4966) - [x] Each commit in the pull request should have a meaningful subject line and body. - [x] Run `mvn clean install -Pit` to make sure basic checks pass. A more thorough check will be performed on your pull request automatically. - [x] Format the pull request title like `[SCB-XXX]`, where you replace `SCB-XXX` with the appropriate JIRA issue. - [x] Write a pull request description that is detailed enough to understand what the pull request does, how, and why. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
