Hi @karthik4,
If you want to validate the swagger contract, you can try to validate the Yaml file generated by Swagger.
Please see below code for the same
import io.github.robwin.swagger.test.SwaggerAssertions;
import io.swagger.models.Swagger;
import io.swagger.models.auth.AuthorizationValue;
import io.swagger.parser.SwaggerParser;
private SwaggerParser swaggerParser = new SwaggerParser();
@Test
public void validateImplementationMatchesDocumentation() {
AuthorizationValue authorizationValue = new AuthorizationValue("Authorization", swaggerApiToken, "header");
Swagger remoteSwagger = swaggerParser.read(swaggerApiPath, Collections.singletonList(authorizationValue), false);
SwaggerAssertions.assertThat(remoteSwagger).isEqualTo("MOCKED VALUE");
}
You need to pass Swagger API Token and API Path like -
https://api.swaggerhub.com/apis/organization/service-name/${swagger.api.version}/swagger.yaml
<dependency>
<groupId>io.github.robwin</groupId>
<artifactId>assertj-swagger</artifactId>
<version>${assertj-swagger.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.swagger.core.v3</groupId>
<artifactId>swagger-models</artifactId>
<version>${swagger.models.version}</version>
<scope>provided</scope>
</dependency>