|
20 | 20 | import java.io.IOException; |
21 | 21 | import java.net.URL; |
22 | 22 | import java.nio.charset.StandardCharsets; |
23 | | -import java.util.Objects; |
24 | 23 |
|
25 | 24 | import org.apache.commons.io.IOUtils; |
26 | 25 | import org.apache.servicecomb.swagger.generator.SwaggerGenerator; |
27 | 26 | import org.junit.jupiter.api.Assertions; |
28 | 27 |
|
29 | 28 | import com.fasterxml.jackson.core.JsonProcessingException; |
| 29 | +import com.fasterxml.jackson.databind.JsonNode; |
| 30 | +import com.fasterxml.jackson.databind.ObjectMapper; |
30 | 31 | import com.fasterxml.jackson.databind.ObjectWriter; |
| 32 | +import com.fasterxml.jackson.dataformat.yaml.YAMLFactory; |
31 | 33 |
|
32 | 34 | import io.swagger.v3.core.util.Yaml; |
33 | 35 | import io.swagger.v3.oas.models.OpenAPI; |
@@ -81,8 +83,19 @@ public static SwaggerGenerator testSwagger(String resPath, Class<?> cls, String. |
81 | 83 | expectSchema = expectSchema.substring(offset + 4); |
82 | 84 | } |
83 | 85 |
|
84 | | - if (!Objects.equals(expectSchema, schema)) { |
85 | | - Assertions.assertEquals(expectSchema, schema); |
| 86 | + try { |
| 87 | + ObjectMapper yaml = new ObjectMapper(new YAMLFactory()); |
| 88 | + JsonNode expected = yaml.readTree(expectSchema); |
| 89 | + JsonNode actual = yaml.readTree(schema); |
| 90 | + |
| 91 | + if (!actual.equals(expected)) { |
| 92 | + ObjectMapper json = new ObjectMapper(); |
| 93 | + String expectedPretty = json.writerWithDefaultPrettyPrinter().writeValueAsString(expected); |
| 94 | + String actualPretty = json.writerWithDefaultPrettyPrinter().writeValueAsString(actual); |
| 95 | + Assertions.fail("OpenAPI mismatch.\n=== EXPECTED ===\n" + expectedPretty + "\n=== ACTUAL ===\n" + actualPretty); |
| 96 | + } |
| 97 | + } catch (Exception e) { |
| 98 | + Assertions.fail("Failed to parse/compare OpenAPI YAML: " + e.getMessage(), e); |
86 | 99 | } |
87 | 100 |
|
88 | 101 | return generator; |
|
0 commit comments