This is an automated email from the ASF dual-hosted git repository.

chenzhida pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/servicecomb-java-chassis.git


The following commit(s) were added to refs/heads/master by this push:
     new e97e90435 Update UnitTestSwaggerUtils to deterministic (#4984)
e97e90435 is described below

commit e97e90435588ee814b85749b37fa5f16a6e61402
Author: Peizhao Mei <[email protected]>
AuthorDate: Mon Oct 27 01:57:52 2025 -0500

    Update UnitTestSwaggerUtils to deterministic (#4984)
    
    Update TestSwagger without adding dependencies
    
    Update UnitTestSwaggerUtils.java
    
    Remove unused import
---
 .../generator/core/unittest/UnitTestSwaggerUtils.java | 19 ++++++++++++++++---
 1 file changed, 16 insertions(+), 3 deletions(-)

diff --git 
a/swagger/swagger-generator/generator-core/src/main/java/org/apache/servicecomb/swagger/generator/core/unittest/UnitTestSwaggerUtils.java
 
b/swagger/swagger-generator/generator-core/src/main/java/org/apache/servicecomb/swagger/generator/core/unittest/UnitTestSwaggerUtils.java
index 9448484b0..c3d627042 100644
--- 
a/swagger/swagger-generator/generator-core/src/main/java/org/apache/servicecomb/swagger/generator/core/unittest/UnitTestSwaggerUtils.java
+++ 
b/swagger/swagger-generator/generator-core/src/main/java/org/apache/servicecomb/swagger/generator/core/unittest/UnitTestSwaggerUtils.java
@@ -20,14 +20,16 @@ package 
org.apache.servicecomb.swagger.generator.core.unittest;
 import java.io.IOException;
 import java.net.URL;
 import java.nio.charset.StandardCharsets;
-import java.util.Objects;
 
 import org.apache.commons.io.IOUtils;
 import org.apache.servicecomb.swagger.generator.SwaggerGenerator;
 import org.junit.jupiter.api.Assertions;
 
 import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
 import com.fasterxml.jackson.databind.ObjectWriter;
+import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
 
 import io.swagger.v3.core.util.Yaml;
 import io.swagger.v3.oas.models.OpenAPI;
@@ -81,8 +83,19 @@ public final class UnitTestSwaggerUtils {
       expectSchema = expectSchema.substring(offset + 4);
     }
 
-    if (!Objects.equals(expectSchema, schema)) {
-      Assertions.assertEquals(expectSchema, schema);
+    try {
+      ObjectMapper yaml = new ObjectMapper(new YAMLFactory());
+      JsonNode expected = yaml.readTree(expectSchema);
+      JsonNode actual   = yaml.readTree(schema);
+
+      if (!actual.equals(expected)) {
+        ObjectMapper json = new ObjectMapper();
+        String expectedPretty = 
json.writerWithDefaultPrettyPrinter().writeValueAsString(expected);
+        String actualPretty   = 
json.writerWithDefaultPrettyPrinter().writeValueAsString(actual);
+        Assertions.fail("OpenAPI mismatch.\n=== EXPECTED ===\n" + 
expectedPretty + "\n=== ACTUAL ===\n" + actualPretty);
+      }
+    } catch (Exception e) {
+      Assertions.fail("Failed to parse/compare OpenAPI YAML: " + 
e.getMessage(), e);
     }
 
     return generator;

Reply via email to