Skip to content

[Fix][scala-sttp][circe] Add NaN-tolerant Decoder[Double] for non-finite values#23611

Merged
wing328 merged 2 commits intoOpenAPITools:masterfrom
nikhilsu:scala-sttp/nan-tolerant-double-decoder
Apr 24, 2026
Merged

[Fix][scala-sttp][circe] Add NaN-tolerant Decoder[Double] for non-finite values#23611
wing328 merged 2 commits intoOpenAPITools:masterfrom
nikhilsu:scala-sttp/nan-tolerant-double-decoder

Conversation

@nikhilsu
Copy link
Copy Markdown
Contributor

@nikhilsu nikhilsu commented Apr 24, 2026

Fixes #23610.

Adds a NaN-tolerant Decoder[Double] to the scala-sttp + circe generator. The default Decoder.decodeDouble rejects the JSON strings "NaN", "Infinity", "-Infinity" - values many servers emit when Jackson encounters non-finite doubles. Generated clients hit DecodingFailure on any response containing such a value.

The new NanTolerantDoubleDecoder is added to AdditionalTypeSerializers so it applies to every generated model's Double fields. Strict numeric parsing stays as the first path; string fallback only handles the three non-finite IEEE 754 values.

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.

cc @chameleon82 (Scala sttp)


Summary by cubic

Adds a NaN-tolerant Decoder[Double] to the scala-sttp generator with circe to accept "NaN", "Infinity", and "-Infinity". Prevents response decoding failures when servers emit these non-finite numbers. Fixes #23610.

  • Bug Fixes
    • Added NanTolerantDoubleDecoder in AdditionalTypeSerializers; tries strict numeric first, then string fallback for the three IEEE 754 values.
    • Applies to all generated Double fields.
    • Updated tests and the petstore sample to cover the new decoder.

Written for commit 8641a01. Summary will update on new commits.

@nikhilsu nikhilsu changed the title Scala sttp/nan tolerant double decoder [Fix][scala-sttp][circe] Add NaN-tolerant Decoder[Double] for non-finite values Apr 24, 2026
@nikhilsu
Copy link
Copy Markdown
Contributor Author

@wing328 this is a relatively simple fix targeted only to scala-sttp3 with circe generator.

Do you think you can review and include it as part of v7.22.0 milestone? Thank you!

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 3 files

@wing328
Copy link
Copy Markdown
Member

wing328 commented Apr 24, 2026

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

@wing328 wing328 merged commit 6be478d into OpenAPITools:master Apr 24, 2026
24 checks passed
@wing328
Copy link
Copy Markdown
Member

wing328 commented Apr 24, 2026

just merged. thanks for the fix

please test with the latest master when you've time.

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] Decoder[Double] rejects NaN/Infinity JSON strings

2 participants