Optional headers serialised incorrectly by OpenAPI generated code

Hi,

We are generating Scala code with scala-sttp. The operation specification would contain:

  parameters:
    - in: header
      name: Contract-Id
      required: false
      schema:
        type: string

The generated code would then set the header on the request like:

...
    contractId: Option[String] = None
...
    basicRequest
...
      .header("Contract-Id", contractId.toString)
...

which prints “Some(value)” when “value” is expected

Since the sttp-openapi-generator has been archived, is there any workaround for the problem?

Wishes,
Jakub

Did you try the OpenAPI generator? There’s one for sttp: GitHub - OpenAPITools/openapi-generator: OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec (v2, v3)

1 Like

Aha, aha, did I find the wrong generator repository? We are in fact using: openapi-generator-cli generate.

So … is there a problem with the generator, or does it work? :slight_smile:

Hey, thanks!
The problem describes the scala-sttp generator of openapi-generator. The problem as in the thread description persists. Is this the right forum to discuss the problem?

Yes definitely. If there’s a problem with the official generator, the proper solution is a PR to the GitHub - OpenAPITools/openapi-generator: OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec (v2, v3) repo with a fix :slight_smile:

And if not a PR, can you open an issue either in sttp’s or OpenAPIGenerator’s GitHub to fix this? Along with all necessary information.