Skip to content

[Fix][scala-sttp][circe] Add Base64OrArrayByteDecoder for format:byte and format:binary JSON properties#23619

Merged
wing328 merged 2 commits intoOpenAPITools:masterfrom
nikhilsu:nsulegaon/base64-encoded-byte-arrau
Apr 25, 2026
Merged

[Fix][scala-sttp][circe] Add Base64OrArrayByteDecoder for format:byte and format:binary JSON properties#23619
wing328 merged 2 commits intoOpenAPITools:masterfrom
nikhilsu:nsulegaon/base64-encoded-byte-arrau

Conversation

@nikhilsu
Copy link
Copy Markdown
Contributor

@nikhilsu nikhilsu commented Apr 24, 2026

Fixes #23618.

cc @clasnake (2017/07), @shijinkui (2018/01), @ramzimaalej (2018/03), @chameleon82 (2020/03), @Bouillie (2020/04) @Fish86 (2023/06)

Adds FlexibleByteArrayDecoder: Decoder[Array[Byte]] to additionalTypeSerializers.mustache for the scala-sttp circe generator.

Problem: Properties with format: byte generate Option[Array[Byte]], but circe's derived Decoder[Array[Byte]] expects a JSON number array. Jackson serializes byte[] fields as Base64 strings, so decoding always fails at runtime with DecodingFailure at .field: Array[Byte]. The existing FileDecoder (used for format: binary JSON properties) is also broken for the same reason, since it delegates to Decoder[Array[Byte]].

Fix: The new decoder tries JSON array first (strict OAS compliance), then falls back to Base64 string decoding

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. Missing information here may result in delayed response from the community.
  • 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
    
  • File the PR against the correct branch: master
  • If your PR solves a reported issue, reference it using GitHub's linking syntax (e.g., having "fixes #123" present in the PR description)
  • If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.

Summary by cubic

Fixes #23618. Adds Base64OrArrayByteDecoder to the scala-sttp circe generator so format: byte and format: binary fields decode from JSON arrays or Base64 strings without runtime failures.

  • Bug Fixes
    • Implemented Base64OrArrayByteDecoder: Decoder[Array[Byte]] (array-first, Base64 fallback).
    • Updated additionalTypeSerializers.mustache with the decoder and java.util.Base64 import.
    • Extended tests and samples to assert decoder emission and map checksum: byte to Option[Array[Byte]].

Written for commit caffe64. Summary will update on new commits.

@nikhilsu
Copy link
Copy Markdown
Contributor Author

@wing328 Here is another targeted bug fix which is low risk.

I know 7.22.0 is due today. Can this PR make it or is it too late? :)

Thank you so much for all the reviews so far, btw 🙏

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

@nikhilsu nikhilsu changed the title [Fix][scala-sttp][circe] Add FlexibleByteArrayDecoder for format:byte and format:binary JSON properties [Fix][scala-sttp][circe] Add Base64OrArrayByteDecoder for format:byte and format:binary JSON properties Apr 24, 2026
@nikhilsu nikhilsu force-pushed the nsulegaon/base64-encoded-byte-arrau branch from 613205f to caffe64 Compare April 24, 2026 23:21
@wing328 wing328 merged commit e866657 into OpenAPITools:master Apr 25, 2026
23 checks passed
@wing328 wing328 added this to the 7.22.0 milestone Apr 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG][scala-sttp][circe] format: byte (Base64) properties fail to deserialize - Decoder[Array[Byte]] expects JSON array

2 participants