OpenAPITools / OpenAPITools/openapi-generator

[BUG][PYTHON-AIOHTTP] Boolean Headers Not Serialized Correctly Leading to aiohttp TypeError

Open
#21,161 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

Bug Report Checklist
  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Sponsorship to speed up the bug fix or feature request

Description

When using the python-aiohttp generator (with library: aiohttp in the config), boolean header parameters are passed without serialization, leading to an exception at runtime.
Since aiohttp strictly expects all header values to be strings, passing a boolean (True/False) causes:

TypeError: cannot serialize non-string key True

Thus, any endpoint expecting a boolean header becomes unusable with the generated SDK.

openapi-generator version
  • OpenAPI Generator CLI version: 7.12.0
OpenAPI declaration file content (testspec.yaml)
openapi: 3.0.3
info:
  title: Test Boolean Header
  version: 1.0.0
paths:
  /test:
    get:
      summary: Test boolean header
      parameters:
        - in: header
          name: X-Flag
          required: true
          schema:
            type: boolean
      responses:
        '200':
          description: OK
Generation Details

The following command was used to generate the client SDK:

openapi-generator-cli generate -c config.yaml

Contents of config.yaml:

inputSpec: testspec.yaml
generatorName: python
library: aiohttp
packageName: test_headers
Suggested fix

Modify the mustache template for boolean header serialization

In the current api.mustache template, the header parameters are assigned as follows:

if {{paramName}} is not None:
    _header_params['{{baseName}}'] = {{paramName}}
{{/headerParams}}

Suggested Modification:

Check if the parameter is of the boolean type (#isBoolean property) and convert that parameter to a string, else directly assign it to the _header_params

The fix ensures that booleans are correctly serialized in headers, which is a requirement for aiohttp and similar libraries that expect strings for header values.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with modules/openapi-generator/src/main/resources/python/api.mustache, especially the header parameter assignment shown in the issue. Generate the client using testspec.yaml and config.yaml with the python aiohttp library, then confirm the generated header serialization converts boolean values to strings without the reported aiohttp TypeError.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
api, tooling
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.