-
Notifications
You must be signed in to change notification settings - Fork 43
Open
Description
Previous Contract in Yaml
definitions:
'SampleObjectCM':
type: object
required:
- executionPlanStepId
- supportType
supportType:
type: string
enum:
- Foo
- BarNew Yaml:
definitions:
'SampleObjectCM':
type: object
required:
- executionPlanStepId
- supportType
supportType:
type: string
enum:
- Foo
- Bar
- ZooBuild.gradle
testImplementation group: 'io.github.robwin', name: 'assertj-swagger', version: '0.9.0'
SwaggerTest class
class SwaggerTests extends AbstractControllerTest {
@Test
void validateImplementationAgainstDesignSpec() throws Exception {
String projectPath = new File(".").getAbsoluteFile().getParentFile().getParentFile().getPath();
String currContractLocation = projectPath + "/api/Contract-Provider-V1-1.yaml";
String prevContractLocation = projectPath + "/api/Contract-Provider-V1-0.yaml";
MvcResult mvcResult = this.mockMvc.perform(get("/v2/api-docs")
.accept(MediaType.APPLICATION_JSON))
.andExpect(status().isOk())
.andReturn();
assertNotNull(mvcResult);
assertNotNull(mvcResult.getResponse());
Swagger actualSwagger = new Swagger20Parser().parse(mvcResult.getResponse().getContentAsString());
SwaggerAssertions.assertThat(actualSwagger).isEqualTo(currContractLocation);
SwaggerAssertions.assertThat(actualSwagger).satisfiesContract(prevContractLocation);
}
}Expected Output: Test Passed
Actual Output:
java.lang.AssertionError:
Expecting ArrayList:
["Foo",
"Bar",
"Zoo"]
to contain only:
["Foo", "Bar"]
but the following element(s) were unexpected:
["Zoo"]
at PropertyValidator.validateEnumPropertyFeatures(PropertyValidator.java:94)
at io.github.robwin.swagger.test.PropertyValidator.validateEnumPropertyFeatures(PropertyValidator.java:94)
at io.github.robwin.swagger.test.PropertyValidator.validateProperty(PropertyValidator.java:48)
at io.github.robwin.swagger.test.ConsumerDrivenValidator.validateProperty(ConsumerDrivenValidator.java:214)
at io.github.robwin.swagger.test.ConsumerDrivenValidator.validateDefinitionProperties(ConsumerDrivenValidator.java:205)
at io.github.robwin.swagger.test.ConsumerDrivenValidator.validateDefinition(ConsumerDrivenValidator.java:152)
at io.github.robwin.swagger.test.ConsumerDrivenValidator.validateDefinitions(ConsumerDrivenValidator.java:131)
at io.github.robwin.swagger.test.ConsumerDrivenValidator.validateSwagger(ConsumerDrivenValidator.java:85)
at io.github.robwin.swagger.test.SwaggerAssert.satisfiesContract(SwaggerAssert.java:111)
at io.github.robwin.swagger.test.SwaggerAssert.satisfiesContract(SwaggerAssert.java:123)
at SwaggerTests.validateImplementationAgainstDesignSpec(SwaggerTests.java:53)
...
NOTE that same test passes with version 0.8.1
Metadata
Metadata
Assignees
Labels
No labels