Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions swagger/swagger-generator/generator-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -78,5 +78,10 @@
<artifactId>spring-web</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.skyscreamer</groupId>
<artifactId>jsonassert</artifactId>
<version>1.5.1</version>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,13 @@
import org.apache.commons.io.IOUtils;
import org.apache.servicecomb.swagger.generator.SwaggerGenerator;
import org.junit.jupiter.api.Assertions;
import org.skyscreamer.jsonassert.JSONAssert;
import org.skyscreamer.jsonassert.JSONCompareMode;

import com.fasterxml.jackson.core.JsonProcessingException;
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;
Expand Down Expand Up @@ -81,8 +85,14 @@ public static SwaggerGenerator testSwagger(String resPath, Class<?> cls, String.
expectSchema = expectSchema.substring(offset + 4);
}

if (!Objects.equals(expectSchema, schema)) {
Assertions.assertEquals(expectSchema, schema);
try {
ObjectMapper yaml = new ObjectMapper(new YAMLFactory());
String expectedJson = yaml.readTree(expectSchema).toString();
String actualJson = yaml.readTree(schema).toString();

JSONAssert.assertEquals(expectedJson, actualJson, JSONCompareMode.NON_EXTENSIBLE);
} catch (Exception e) {
Assertions.fail("Failed to parse/compare OpenAPI YAML: " + e.getMessage(), e);
}

return generator;
Expand Down
Loading