[BUG] python-aiohttp incorrect defaults with large integers
Created by: LesnyRumcajs
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/