OpenAPITools / OpenAPITools/openapi-generator

[BUG] python-aiohttp incorrect defaults with large integers

Open
#11,138 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug Server: Python
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 (example)?
  • 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 (example)
Description

If the default integer value is too high, namely above INT32_MAX (i.e. 2^31 - 1) the python-aiohttp generator produces a constructor with an incorrect, None signature. For values below 2^31 it works fine, the default is respected.

Specifying format: int64 doesn't help.

Example:
with this object:

    Memory:
      type: object
      properties:
        ram_installed:
          type: "integer"
          default: 2147483647

the generated c-tor signature in openapi_server/models/memory.py is:

    def __init__(self, ram_installed: int=2147483647):

Bug:
with this object:

    Memory:
      type: object
      properties:
        ram_installed:
          type: "integer"
          default: 2147483648

the generated c-tor signature in openapi_server/models/memory.py is:

    def __init__(self, ram_installed: int=None):
openapi-generator version
openapi-generator-cli 5.3.1-SNAPSHOT
  commit : cee5f75
  built  : 2021-12-10T22:16:21Z
  source : https://github.com/openapitools/openapi-generator
  docs   : https://openapi-generator.tech/
OpenAPI declaration file content or url
openapi: 3.0.0
info:
  title: Sample API
  version: 0.1.9
paths:
  /users:
    get:
      summary: Returns installed RAM.
      responses:
        200:    # status code
          description: ok
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Memory'
components:
  schemas:
    Memory:
      type: object
      properties:
        ram_installed:
          type: "integer"
          default: 2147483648

Generation Details
[main] INFO  o.o.codegen.DefaultGenerator - Generating with dryRun=false
[main] INFO  o.o.codegen.DefaultGenerator - OpenAPI Generator: python-aiohttp (server)
[main] INFO  o.o.codegen.DefaultGenerator - Generator 'python-aiohttp' is considered stable.
[main] INFO  o.o.c.l.AbstractPythonCodegen - Environment variable PYTHON_POST_PROCESS_FILE not defined so the Python code may not be properly formatted. To de
fine it, try 'export PYTHON_POST_PROCESS_FILE="/usr/local/bin/yapf -i"' (Linux/Mac)
[main] INFO  o.o.c.l.AbstractPythonCodegen - NOTE: To enable file post-processing, 'enablePostProcessFile' must be set to `true` (--enable-post-process-file f
or CLI).
[main] WARN  o.o.codegen.DefaultCodegen - Empty operationId found for path: GET /users. Renamed to auto-generated operationId: usersGET
[main] INFO  o.o.codegen.utils.URLPathUtils - 'host' (OAS 2.0) or 'servers' (OAS 3.0) not defined in the spec. Default to [http://localhost] for server URL [h
ttp://localhost/]
[main] INFO  o.o.codegen.utils.URLPathUtils - 'host' (OAS 2.0) or 'servers' (OAS 3.0) not defined in the spec. Default to [http://localhost] for server URL [h
ttp://localhost/]
[main] INFO  o.o.codegen.TemplateManager - writing file /local/out/openapi_server/models/memory.py
[main] INFO  o.o.codegen.utils.URLPathUtils - 'host' (OAS 2.0) or 'servers' (OAS 3.0) not defined in the spec. Default to [http://localhost] for server URL [h
ttp://localhost/]
[main] INFO  o.o.codegen.TemplateManager - writing file /local/out/openapi_server/controllers/default_controller.py
[main] INFO  o.o.codegen.TemplateManager - Skipped /local/out/tests/test_default_controller.py (Test files never overwrite an existing file of the same name.)
[main] INFO  o.o.codegen.utils.URLPathUtils - 'host' (OAS 2.0) or 'servers' (OAS 3.0) not defined in the spec. Default to [http://localhost] for server URL [h
ttp://localhost/]
[main] INFO  o.o.codegen.TemplateManager - writing file /local/out/README.md
[main] INFO  o.o.codegen.TemplateManager - writing file /local/out/test-requirements.txt
[main] INFO  o.o.codegen.TemplateManager - writing file /local/out/requirements.txt
[main] INFO  o.o.codegen.TemplateManager - writing file /local/out/openapi_server/__main__.py
[main] INFO  o.o.codegen.TemplateManager - writing file /local/out/openapi_server/util.py
[main] INFO  o.o.codegen.TemplateManager - writing file /local/out/openapi_server/typing_utils.py
[main] INFO  o.o.codegen.TemplateManager - writing file /local/out/openapi_server/controllers/__init__.py
[main] INFO  o.o.codegen.TemplateManager - writing file /local/out/openapi_server/controllers/security_controller_.py
[main] INFO  o.o.codegen.TemplateManager - writing file /local/out/openapi_server/models/__init__.py
[main] INFO  o.o.codegen.TemplateManager - writing file /local/out/openapi_server/models/base_model_.py
[main] INFO  o.o.codegen.TemplateManager - writing file /local/out/openapi_server/openapi/openapi.yaml
[main] INFO  o.o.codegen.TemplateManager - writing file /local/out/tests/conftest.py
[main] INFO  o.o.codegen.TemplateManager - writing file /local/out/tests/__init__.py
[main] INFO  o.o.codegen.TemplateManager - writing file /local/out/openapi_server/__init__.py
[main] INFO  o.o.codegen.TemplateManager - writing file /local/out/setup.py
[main] INFO  o.o.codegen.TemplateManager - writing file /local/out/tox.ini
[main] INFO  o.o.codegen.TemplateManager - writing file /local/out/.gitignore
[main] INFO  o.o.codegen.TemplateManager - Skipped /local/out/.openapi-generator-ignore (Skipped by supportingFiles options supplied by user.)
[main] INFO  o.o.codegen.TemplateManager - writing file /local/out/.openapi-generator/VERSION
[main] INFO  o.o.codegen.TemplateManager - writing file /local/out/.openapi-generator/FILES
Steps to reproduce

Generate a server with python-aiohttp using docker.

❯ docker run --rm -v "$PWD:/local" openapitools/openapi-generator-cli generate \                                                                      
          -i /local/example.yml \
          -g python-aiohttp \
          -o /local/out/
Related issues/PRs
Suggest a fix

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

Run the supplied Docker generation command with the OpenAPI declaration and the python-aiohttp generator, then inspect the generated openapi_server/models/memory.py output for values around 2147483647 and 2147483648. Trace the python-aiohttp generator path or template that renders the constructor default, and verify that large integer defaults remain unchanged in the generated signature.

Written by the indexing model from the issue text.

Assessment

Tech stack
docker, python
Domain
api, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.