assertj-swagger
assertj-swagger copied to clipboard
0.9.0 is failing satisfiesContract on an enum member addition
Previous Contract in Yaml
definitions:
'SampleObjectCM':
type: object
required:
- executionPlanStepId
- supportType
supportType:
type: string
enum:
- Foo
- Bar
New Yaml:
definitions:
'SampleObjectCM':
type: object
required:
- executionPlanStepId
- supportType
supportType:
type: string
enum:
- Foo
- Bar
- Zoo
Build.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
NOTE: We cannot use 0.8.1 with the newer versions of spring-boot (2.5.+) as spring-boot enforces an incompatible newer version of assertj-core
dependency
We did some investigation and found that in 0.8.1, the check was completely being skipped.
- in line 236, the actualStringProperty was being loaded from expectedProperty
- the test would've passed even if enum values are removed
The expected behavior is, line 239
- change
hasSameElementsAs
tocontainsAll
we can file a PR to 0.9.0/master for the same. Let us know if it is acceptable
Here's the fork with the update.
I have filed a ticket on OSSRH to publish the fork as io.github.vijayvepa:assertj-swagger:0.9.1
.
Please let me know if there are any objections to proceeding with the publishing of the fork.
I will publish it on April 20, 2022, If I do not hear back.
Regards, vijayvepa
Hi, fine for me. I can also transfer the project to you, since I don't have time to maintain it anymore
Thanks Robert, I have pushed the above artifact now. I'm more than happy to take ownership. Let me know the next steps.
I guess you can just endorse that the fork is the one to use going forward - in the readme.adoc.