swagger-api / swagger-api/swagger-parser
Inconsistent behavior for byte array example (3.0.x vs 3.1.x)
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 867
- Forks
- 560
- Avg merge
- 2d 21h
- Merged PRs (30d)
- 7
Description
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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by comparing the ByteArraySchema.cast() and JsonSchema.cast() methods, which the report identifies as the likely source of the discrepancy. Trace how the example value is stored for the OpenAPI 3.0.x and 3.1 schema paths, then verify that the resulting representation is consistent in both scenarios.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- api
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100