Skip to content

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

Merged
wing328 merged 1 commit intoOpenAPITools:masterfrom
pastuxso:fix/19929-openapi-yaml-byte-example-binary
Apr 27, 2026
Merged

[Fix][openapi-yaml] preserve format:byte examples instead of !!binary#23623
wing328 merged 1 commit intoOpenAPITools:masterfrom
pastuxso:fix/19929-openapi-yaml-byte-example-binary

Conversation

@pastuxso
Copy link
Copy Markdown
Contributor

@pastuxso pastuxso commented Apr 25, 2026

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 [BUG][OPENAPI-YAML] example with type string, format byte generates invalid yaml - !!binary #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.

Written for commit a7aaf1f. Summary will update on new commits. Review in cubic

@pastuxso pastuxso force-pushed the fix/19929-openapi-yaml-byte-example-binary branch from e628c14 to 7c8913d Compare April 25, 2026 18:41
Jackson's default YAMLMapper serializes byte[] values with a !!binary
tag and re-base64-encodes the payload. swagger-parser stores
`format: byte` examples as the raw bytes of the input base64 string,
so the default behavior produced double-encoded YAML, e.g.:

  example: !!binary |-
    YUdWc2JHOEs=

Register a ByteArraySerializer in the OpenAPIModule that writes
byte[] as its UTF-8 string representation, restoring the original
base64 literal in the regenerated YAML (e.g. `example: aGVsbG8K`).

Adds a regression test and fixture for issue OpenAPITools#19929.
@pastuxso pastuxso force-pushed the fix/19929-openapi-yaml-byte-example-binary branch from 7c8913d to a7aaf1f Compare April 27, 2026 12:50
@pastuxso pastuxso marked this pull request as ready for review April 27, 2026 13:05
Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 4 files

@wing328 wing328 merged commit c90cfa7 into OpenAPITools:master Apr 27, 2026
15 checks passed
@wing328
Copy link
Copy Markdown
Member

wing328 commented Apr 27, 2026

thanks for the PR which has been merged

@wing328 wing328 added this to the 7.22.0 milestone Apr 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG][OPENAPI-YAML] example with type string, format byte generates invalid yaml - !!binary

2 participants