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

False positive Comparing Strict #512

Open
elysrivero99 opened this issue Apr 24, 2023 · 1 comment
Open

False positive Comparing Strict #512

elysrivero99 opened this issue Apr 24, 2023 · 1 comment

Comments

@elysrivero99
Copy link

I have a task in which I have to check if out spec is updated. But I want to compare not only if the specs are compatible, I want to check if there are "identical".

Given this yaml:

openapi: 3.0.1
info:
  title: Test API
  description: Test API
  version: v1
servers:
- url: http://localhost:8080
paths:
  /payments/{paymentId}:
    get:
      operationId: getPayment
      parameters:
      - name: paymentId
        in: path
        required: true
        schema:
          type: string
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ExampleResponse'
components:
  schemas:
    ExampleResponse:
      type: object
      properties:
        paymentId:
          type: string
        amount:
          type: integer
          format: int64

I was doing this unit test in java

@SpringBootTest
class OpenApiDocumentationIT {

    @Value("classpath:/openapi.yaml") Resource openapiGenerated;

    @Test
    @SneakyThrows
    void openapi_yaml_should_be_equal() {

        String newContent = openapiGenerated.getContentAsString(Charset.defaultCharset());
        String oldContent = openapiGenerated.getContentAsString(Charset.defaultCharset());

        ChangedOpenApi changedOpenApi = OpenApiCompare.fromContents(oldContent, newContent);

        assertThat(changedOpenApi.isDifferent()).isFalse(); //OK

        OpenAPI newSpecOpenApi = changedOpenApi.getNewSpecOpenApi();
        OpenAPI oldSpecOpenApi = changedOpenApi.getOldSpecOpenApi();

        assertThat(newSpecOpenApi).isEqualTo(oldSpecOpenApi); // Fail
        assertThat(newSpecOpenApi.getPaths().get("/payments/{paymentId}")).isEqualTo(
            oldSpecOpenApi.getPaths().get("/payments/{paymentId}"));  //Fail
    }
}

Turns out that comparing the exact yaml with itself it said that they aren't equals. I'm using version 2.0.1

Is there any option to validate that two specs are the same?

@elysrivero99
Copy link
Author

After doing some tests I figured out that this has been resolved in 2.0.2-SNAPSHOT is there any plan to release this version?

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

1 participant