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

Inconsistent behavior for byte array example (3.0.x vs 3.1.x)

Open padamstx opened this issue 2 years ago • 0 comments

I'm using the latest version of swagger-parser (2.1.13) and I've noticed an inconsistency in how a byte array schema's example field is read in and stored on the Schema (openapi 3.0.x) or JsonSchema (openapi 3.1.x).

Here's an example of a byte array property within an object schema:

    Router:
      description: A network router.
      type: object
      properties:
        name:
          description: The name of the router.
          type: string
        firmware:
          description: The current firmware on the router.
          type: string
          format: byte
          example: RGVmaW5ldGVseSBub3QgYSBmaXJtd2FyZS4gQ2hlY2sgaHR0cHM6Ly9vcGVud3J0Lm9yZyAhIQ==

Within an OpenAPI 3.0.x document, the firmware property's example field is stored as a byte[], but if this same schema exists within an OpenAPI 3.1 document, the example field is stored as a String. It seems like these should be consistent. Pick one or the other and use it in each scenario in order to make it easier to write tooling code (i.e. SDK generator) that needs to deal with both versions of OpenAPI.

I think this inconsistency is rooted in the differences between the ByteArraySchema.cast() and JsonSchema.cast() methods.

padamstx avatar Apr 21 '23 18:04 padamstx