assertj-swagger icon indicating copy to clipboard operation
assertj-swagger copied to clipboard

0.9.0 is failing satisfiesContract on an enum member addition

Open vijayvepa opened this issue 2 years ago • 6 comments

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

vijayvepa avatar Apr 07 '22 15:04 vijayvepa

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

vijayvepa avatar Apr 07 '22 15:04 vijayvepa

We did some investigation and found that in 0.8.1, the check was completely being skipped.

image

  • 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 to containsAll

we can file a PR to 0.9.0/master for the same. Let us know if it is acceptable

vijayvepa avatar Apr 07 '22 17:04 vijayvepa

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

vijayvepa avatar Apr 13 '22 12:04 vijayvepa

Hi, fine for me. I can also transfer the project to you, since I don't have time to maintain it anymore

RobWin avatar Apr 13 '22 13:04 RobWin

Thanks Robert, I have pushed the above artifact now. I'm more than happy to take ownership. Let me know the next steps.

vijayvepa avatar Apr 14 '22 14:04 vijayvepa

I guess you can just endorse that the fork is the one to use going forward - in the readme.adoc.

vijayvepa avatar Apr 15 '22 11:04 vijayvepa