Skip to content

Conversation

@pielas
Copy link
Contributor

@pielas pielas commented Dec 12, 2025

Fixes #22047

Summary

The scala-sttp4-jsoniter generator produces non-compiling Scala 3 code when separateErrorChannel=false is set. The generated code uses .getRight which was removed from STTP4 between versions 4.0.0-M1 and 4.0.0-RC1.

Motivation

STTP library changed its API between milestone and RC releases:

  • Removed: .getRight and .getEither extension methods
  • Replaced with: .orFail and .orFailDeserialization methods
  • Reference: STTP v3 to v4 Migration Guide

The openapi-generator templates were not updated to reflect this breaking change, causing compilation failures for all generated clients using STTP 4.0.0-RC1+.

Changes

  • Updated api.mustache template in modules/openapi-generator/src/main/resources/scala-sttp4-jsoniter/ and replaced .getRight with .orFail when separateErrorChannel=false

Reproduction Steps

  1. Create test spec (test-api.yaml):
openapi: 3.0.0
info:
  title: Test API
  version: 1.0.0
servers:
  - url: https://api.example.com
paths:
  /test:
    post:
      operationId: testOperation
      responses:
        '204':
          description: No content
        '400':
          description: Bad request
          content:
            application/json:
              schema:
                type: object
  1. Config file (config.yaml):
    separateErrorChannel: false

  2. Generate client:

openapi-generator generate \
   -i test-api.yaml \
   -g scala-sttp4-jsoniter \
   -o generated \
   -c config.yaml
  1. Compile (fails before fix):
    cd generated && sbt compile

@pielas pielas changed the title Fix scala-sttp4-jsoniter compilation error: replace .getRight with .orFail Fixed scala-sttp4-jsoniter compilation error: replace .getRight with .orFail Dec 12, 2025
@wing328 wing328 added this to the 7.18.0 milestone Dec 13, 2025
@wing328
Copy link
Member

wing328 commented Dec 13, 2025

thanks for the fix

i could repeat the issue locally

$ sbt compile
[info] welcome to sbt 1.9.9 (Eclipse Adoptium Java 17.0.16)
[info] loading project definition from C:\Users\User\AppData\Local\Temp\sc\project
[info] loading settings for project sc from build.sbt ...
[info] set current project to openapi-client (in build file:/C:/Users/User/AppData/Local/Temp/sc/)
[info] Executing in batch mode. For better performance use sbt's shell
[info] compiling 1 Scala source to C:\Users\User\AppData\Local\Temp\sc\target\scala-3.3.4\classes ...
[error] -- [E008] Not Found Error: C:\Users\User\AppData\Local\Temp\sc\src\main\scala\org\openapitools\client\api\DefaultApi.scala:64:95
[error] 64 |      .response(asString.mapWithMetadata(ResponseAs.deserializeRightWithError(_ => Right(()))).getRight)
[error]    |                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[error]    |value getRight is not a member of sttp.client4.ResponseAs[Either[sttp.client4.ResponseException[String], Unit]] - did you mean sttp.client4.ResponseAs[Either[sttp.client4.ResponseException[String], Unit]].mapRight
[error] one error found
[error] (Compile / compileIncremental) Compilation failed
[error] Total time: 3 s, completed Dec 13, 2025, 6:49:00 PM

and confirmed the fix

@wing328 wing328 merged commit 5f28987 into OpenAPITools:master Dec 13, 2025
14 checks passed
lucy66hw pushed a commit to lucy66hw/openapi-generator that referenced this pull request Dec 16, 2025
rajvesh pushed a commit to rajvesh/openapi-generator that referenced this pull request Dec 25, 2025
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.

scala3-sttp4-jsoniter - code does compile when separateErrorChannel=false

2 participants