OpenAPITools / openapi-diff

Utility for comparing two OpenAPI specifications.
Apache License 2.0
810 stars 154 forks source link

False positive Comparing Strict #512

Open elysrivero99 opened 1 year ago

elysrivero99 commented 1 year ago

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 commented 1 year ago

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?