[Fix][scala-sttp][circe] Circe codecs do not preserve original JSON field names for non-camelCase properties#23465
Conversation
There was a problem hiding this comment.
3 issues found across 18 files
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="samples/client/petstore/scala-sttp-circe/src/main/scala/org/openapitools/client/core/AdditionalTypeSerializers.scala">
<violation number="1" location="samples/client/petstore/scala-sttp-circe/src/main/scala/org/openapitools/client/core/AdditionalTypeSerializers.scala:28">
P2: `FileDecoder` registers every temp file with `deleteOnExit`, causing runtime accumulation of temp files and JVM exit-cleanup bookkeeping in long-lived processes.</violation>
<violation number="2" location="samples/client/petstore/scala-sttp-circe/src/main/scala/org/openapitools/client/core/AdditionalTypeSerializers.scala:44">
P2: AnyEncoder converts all non-Json `Any` values into JSON strings, corrupting numeric/boolean/object JSON types.</violation>
</file>
<file name="modules/openapi-generator/src/main/resources/scala-sttp/model.mustache">
<violation number="1" location="modules/openapi-generator/src/main/resources/scala-sttp/model.mustache:44">
P1: Decoder template can generate invalid Scala for models with no properties due to an empty `for`-comprehension.</violation>
</file>
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
There was a problem hiding this comment.
1 issue found across 1 file (changes from recent commits).
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="samples/yaml/user.yml">
<violation number="1">
P2: `userStatus` is typed as `integer` but its enum values are strings, creating an inconsistent schema contract.</violation>
</file>
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
|
@wing328 could you also review this. Thank you! |
|
please follow step 3 to fix https://github.com/OpenAPITools/openapi-generator/actions/runs/24111536296/job/70440385683?pr=23465 |
Sorry missed regenerating samples after I incorporated a couple of cubic AI suggestions. It's updated now. |
…ield names for non-camelCase properties
e19b737 to
09c7821
Compare
|
thanks for the fix, which has been merged. |
Thank you. How often do you cut a release version? |
|
Do you think you can include this commit in 7.22.0? |
|
yes as it's already merged you can use the snapshot version (e.g. docker cli) for the time being |
Summary
This PR fixes: #23464
The
scala-sttpgenerator withjsonLibrary=circerelies on circe'sAutoDerivationto deriveEncoder/Decoderinstances. This derives codecs from Scala field names (camelCase), not the original JSON property names from the OpenAPI spec - breaking the wire contract for kebab-case, snake_case, and PascalCase properties.This PR replaces
AutoDerivationwith explicit per-modelEncoder/Decoderinstances that usebaseName(the original JSON property name), following the same pattern already used by thescala-http4sgenerator.What changed
AutoDerivationwith explicit per-modelEncoder/DecoderusingbaseNamefor JSON keys (followingscala-http4spattern)File,Any, andURIinAdditionalTypeSerializerstype: objecttoio.circe.Jsoninstead ofAnyfor circe (fix was also needed inprocessOpts()since user config isn't available in the constructor)Example
Given a spec with
first-name,phone_number,ZipCode,lastName,addressproperties:Before (broken): circe serializes using Scala field names
{"firstName": "John", "phoneNumber": "555-1234", "zipCode": "90210"}After (fixed): circe serializes using original JSON names
{"first-name": "John", "phone_number": "555-1234", "ZipCode": "90210"}PR checklist
This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master.
These must match the expectations made by your contribution.
You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example
./bin/generate-samples.sh bin/configs/java*.IMPORTANT: Do NOT purge/delete any folders/files (e.g. tests) when regenerating the samples as manually written tests may be removed.
master(upcoming7.x.0minor release - breaking changes with fallbacks),8.0.x(breaking changes without fallbacks)"fixes #123"present in the PR description)cc @chameleon82 (Scala sttp), @flsh86 (Scala sttp4), @JennyLeahy (Scala http4s - this PR follows the http4s pattern)
How to validate