[Fix][openapi-yaml] preserve format:byte examples instead of !!binary

Merged
PA
7mo ago
+92-0

Fixes #19929.

Problem

When the openapi-yaml generator processes a spec with a type: string, format: byte property carrying an example (e.g. 'aGVsbG8K'), the regenerated YAML emits an invalid, double-encoded payload:

example: !!binary |-
  YUdWc2JHOEs=

This breaks downstream tools that expect the standard OpenAPI representation (a quoted base64 string), and YUdWc2JHOEs= is base64("aGVsbG8K") — i.e. the original example has been base64-re-encoded.

Root cause

SerializerUtils.toYamlString(...) uses Jackson's YAMLMapper. swagger-parser stores format: byte examples as the raw bytes of the input base64 string (not the decoded content). Jackson's default byte[] YAML serializer then emits those bytes with a !!binary tag and re-base64-encodes them.

Fix

Register a ByteArraySerializer (StdSerializer<byte[]>) in the existing OpenAPIModule that writes byte[] as its UTF-8 string representation. This restores the user's original base64 literal in the regenerated YAML:

example: aGVsbG8K

The fix is purely at the serializer layer; no template or generator changes are needed.

Validation

  • New regression test YamlGeneratorTest#testIssue19929 (asserts no !!binary, original aGVsbG8K preserved, round-trips through TestUtils.parseSpec).
  • Full module test suite: Tests run: 3954, Failures: 0, Errors: 0, Skipped: 7.
  • Reproduced the original CLI command from the issue against the new fixture; output openapi.yaml contains example: aGVsbG8K and no !!binary.
  • ./bin/generate-samples.sh ./bin/configs/*.yaml produced zero diff in samples/, confirming the change is backward-compatible.

PR checklist

  • Read the contribution guidelines.
  • Pull Request title clearly describes the work in the pull request and Pull Request description provides details about how to validate the work.
  • Run the following to build the project and update samples:
    ./mvnw clean package || exit
    ./bin/generate-samples.sh ./bin/configs/*.yaml || exit
    ./bin/utils/export_docs_generators.sh || exit
    
    All three completed successfully with no resulting diff in samples or docs.
  • File the PR against the correct branch: master.
  • If your PR solves a reported issue, reference it (fixes #19929).
  • If your PR is targeting a particular programming language, @mention the technical committee — N/A, this is a fix in the shared YAML serializer used by the openapi-yaml generator.

Summary by cubic

Preserves format: byte examples in openapi-yaml by serializing byte[] as UTF‑8 strings, avoiding !!binary and double base64 in YAML. Fixes #19929.

  • Bug Fixes
    • Adds ByteArraySerializer and registers it in SerializerUtils to write byte[] as the original base64 literal (e.g., aGVsbG8K).
    • Ensures YAML emits a string for format: byte; never emits !!binary.
    • Adds regression test and fixture; verifies round-trip via TestUtils.parseSpec; samples unchanged.