Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

0.9.0 is failing satisfiesContract on an enum member addition #62

Open
vijayvepa opened this issue Apr 7, 2022 · 6 comments
Open

0.9.0 is failing satisfiesContract on an enum member addition #62

vijayvepa opened this issue Apr 7, 2022 · 6 comments

Comments

@vijayvepa
Copy link

vijayvepa commented Apr 7, 2022

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
Copy link
Author

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
Copy link
Author

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
Copy link
Author

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

@RobWin
Copy link
Owner

RobWin commented Apr 13, 2022

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

@vijayvepa
Copy link
Author

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

@vijayvepa
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants