OpenAPITools / openapi-diff

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

allOf : `type` of property contained in multiple subschemas is not correctly determined. #392

Open thake opened 2 years ago

thake commented 2 years ago

Given the following schema V1:

Foo:
  allOf:
    - properties:
        propA:
          type: string
    - properties:
        propA:
          example: "YEEHAA"

is changed to the following schema V2:

Foo:  
  properties:
    propA:
      type: string

openapi-diff incorrectly detects the following incompatible change: Changed property type (object -> string)

It seems to me that the type of a property that is contained in multiple subschemas of an allOf is not correctly determined. Openapi-diff recognized the type of propA in schema V1 as an object, but this is not correct.

Chexpir commented 2 years ago

Here another example, where oas-diff errored with:

[2022-08-03T07:43:21.358Z] - POST   /v1/....
[2022-08-03T07:43:21.358Z]   Request:
[2022-08-03T07:43:21.358Z]         - Changed application/json
[2022-08-03T07:43:21.358Z]           Schema: Broken compatibility
[2022-08-03T07:43:21.358Z]           Changed property type: aPropertyName (string -> string)
Quarkus 2.10.2
        aPropertyName:
          format: date-time
          description: .........
          type: string
          example: 2022-02-22T22:00:47.720Z
        otherPropertyName:
          format: date-time
          type: string
Quarkus 2.11.1
        aPropertyName:
          allOf:
          - $ref: '#/components/schemas/OffsetDateTime'
          - description: ......
            example: **2022-02-22T22:00:47.720Z**
        otherPropertyName:
          $ref: '#/components/schemas/OffsetDateTime'
....
    Instant:
      format: date-time
      type: string
      example: 2022-03-10T16:15:50Z
    OffsetDateTime:
      format: date-time
      type: string
      example: 2022-03-10T12:15:50-04:00
Pyth0ff commented 1 year ago

I ran into the same issue that my examples are like that:

...
"timestamp": {
  "type": "string",
  "format": "date-time",
  "example": "2022-04-20T11:28:33.894Z"
},
...

Produces the following exception:

Caused by: com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Java 8 date/time type `java.time.OffsetDateTime` not supported by default: add Module "com.fasterxml.jackson.datatype:jackson-datatype-jsr310" to enable handling
joschi commented 1 year ago

@Pyth0ff Does it still fail with the latest version? https://github.com/OpenAPITools/openapi-diff/releases/tag/2.1.0-beta.4

Pyth0ff commented 1 year ago

@joschi Thank you for the quick answer and yes the latest beta helps to solve my issue. :)