[Fix][openapi-yaml] preserve format:byte examples instead of !!binary#23623
Merged
wing328 merged 1 commit intoOpenAPITools:masterfrom Apr 27, 2026
Merged
Conversation
e628c14 to
7c8913d
Compare
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.
7c8913d to
a7aaf1f
Compare
Member
|
thanks for the PR which has been merged |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #19929.
Problem
When the
openapi-yamlgenerator processes a spec with atype: string, format: byteproperty carrying anexample(e.g.'aGVsbG8K'), the regenerated YAML emits an invalid, double-encoded payload:This breaks downstream tools that expect the standard OpenAPI representation (a quoted base64 string), and
YUdWc2JHOEs=isbase64("aGVsbG8K")— i.e. the original example has been base64-re-encoded.Root cause
SerializerUtils.toYamlString(...)uses Jackson'sYAMLMapper. swagger-parser storesformat: byteexamples as the raw bytes of the input base64 string (not the decoded content). Jackson's defaultbyte[]YAML serializer then emits those bytes with a!!binarytag and re-base64-encodes them.Fix
Register a
ByteArraySerializer(StdSerializer<byte[]>) in the existingOpenAPIModulethat writesbyte[]as its UTF-8 string representation. This restores the user's original base64 literal in the regenerated YAML:The fix is purely at the serializer layer; no template or generator changes are needed.
Validation
YamlGeneratorTest#testIssue19929(asserts no!!binary, originalaGVsbG8Kpreserved, round-trips throughTestUtils.parseSpec).Tests run: 3954, Failures: 0, Errors: 0, Skipped: 7.openapi.yamlcontainsexample: aGVsbG8Kand no!!binary../bin/generate-samples.sh ./bin/configs/*.yamlproduced zero diff insamples/, confirming the change is backward-compatible.PR checklist
master.openapi-yamlgenerator.Summary by cubic
Preserves
format: byteexamples inopenapi-yamlby serializingbyte[]as UTF‑8 strings, avoiding!!binaryand double base64 in YAML. Fixes #19929.ByteArraySerializerand registers it inSerializerUtilsto writebyte[]as the original base64 literal (e.g.,aGVsbG8K).format: byte; never emits!!binary.TestUtils.parseSpec; samples unchanged.Written for commit a7aaf1f. Summary will update on new commits. Review in cubic