# Optional headers serialised incorrectly by OpenAPI generated code

**URL:** <https://softwaremill.community/t/optional-headers-serialised-incorrectly-by-openapi-generated-code/391>\
**Category:** sttp client\
**Created:** [May 8, 2024, 12:25pm UTC](https://softwaremill.community/t/optional-headers-serialised-incorrectly-by-openapi-generated-code/391 "2024-05-08T12:25:18Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![jakub-nezasa](https://avatars.discourse-cdn.com/v4/letter/j/e79b87/32.png) [@jakub-nezasa](https://softwaremill.community/u/jakub-nezasa)\
**Post date:** [May 8, 2024, 12:25pm UTC](https://softwaremill.community/t/optional-headers-serialised-incorrectly-by-openapi-generated-code/391/1 "2024-05-08T12:25:18Z")

</div>

Hi,

We are generating Scala code with _scala-sttp_. The operation specification would contain:

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

```

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

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

```

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

Since the [sttp-openapi-generator](https://github.com/ghostbuster91/sttp-openapi-generator) has been archived, is there any workaround for the problem?

Wishes,  
Jakub

---

<div class="post-metadata">

**Author:** ![adamw](https://dub1.discourse-cdn.com/flex005/user_avatar/softwaremill.community/adamw/32/28_2.png) [@adamw](https://softwaremill.community/u/adamw)\
**Post date:** [May 9, 2024, 6:41am UTC](https://softwaremill.community/t/optional-headers-serialised-incorrectly-by-openapi-generated-code/391/2 "2024-05-09T06:41:04Z")

</div>

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)](https://github.com/OpenAPITools/openapi-generator)

---

<div class="post-metadata">

**Author:** ![jakub-nezasa](https://avatars.discourse-cdn.com/v4/letter/j/e79b87/32.png) [@jakub-nezasa](https://softwaremill.community/u/jakub-nezasa)\
**Post date:** [May 14, 2024, 7:50am UTC](https://softwaremill.community/t/optional-headers-serialised-incorrectly-by-openapi-generated-code/391/3 "2024-05-14T07:50:17Z")

</div>

> [@jakub-nezasa](#):
>
> We are generating Scala code with _scala-sttp_. The operation specification would contain:
> 
> ```auto
> 
> ```

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

---

<div class="post-metadata">

**Author:** ![adamw](https://dub1.discourse-cdn.com/flex005/user_avatar/softwaremill.community/adamw/32/28_2.png) [@adamw](https://softwaremill.community/u/adamw)\
**Post date:** [May 14, 2024, 8:06am UTC](https://softwaremill.community/t/optional-headers-serialised-incorrectly-by-openapi-generated-code/391/4 "2024-05-14T08:06:19Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![jakub-nezasa](https://avatars.discourse-cdn.com/v4/letter/j/e79b87/32.png) [@jakub-nezasa](https://softwaremill.community/u/jakub-nezasa)\
**Post date:** [May 14, 2024, 9:31am UTC](https://softwaremill.community/t/optional-headers-serialised-incorrectly-by-openapi-generated-code/391/5 "2024-05-14T09:31:33Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![adamw](https://dub1.discourse-cdn.com/flex005/user_avatar/softwaremill.community/adamw/32/28_2.png) [@adamw](https://softwaremill.community/u/adamw)\
**Post date:** [May 14, 2024, 4:43pm UTC](https://softwaremill.community/t/optional-headers-serialised-incorrectly-by-openapi-generated-code/391/6 "2024-05-14T16:43:43Z")

</div>

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)](https://github.com/OpenAPITools/openapi-generator) repo with a fix 🙂

---

<div class="post-metadata">

**Author:** ![adamw](https://dub1.discourse-cdn.com/flex005/user_avatar/softwaremill.community/adamw/32/28_2.png) [@adamw](https://softwaremill.community/u/adamw)\
**Post date:** [May 20, 2024, 9:31am UTC](https://softwaremill.community/t/optional-headers-serialised-incorrectly-by-openapi-generated-code/391/7 "2024-05-20T09:31:04Z")

</div>

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.
