swagger-api/swagger-codegen

[Python] Incorrect code generated for integer properties with enum

オープン

#3,667 opened on 2016/08/29

 (5 件のコメント) (2 件のリアクション) (0 人の担当者)HTML (5,474 件のフォーク)batch import
Client: PythonFeature: EnumIssue: Bughelp wanted

Repository metrics

Stars
 (12,701 個のスター)
PR merge metrics
 (PR metrics pending)

説明

Description

Data type of enum items in Python generated code for property setter does not match to given yaml/json datatype (and/or expected type of property). It leads to permanent validation failures.

Swagger-codegen version

2.2.1

Swagger declaration file content or url

yaml

baudrate:
  type: integer
  format: int32
  enum:
    - 1200
    - 2400
    - 4800
    - 9600
    - 19200

json

"baudrate" : {
    "type" : "integer",
    "format" : "int32",
    "enum" : [1200, 2400, 4800, 9600, 19200]
}
Produced code
@baudrate.setter
def baudrate(self, baudrate):
    """
    Sets the baudrate of this ModbusRtuSettings.

    :param baudrate: The baudrate of this ModbusRtuSettings.
    :type: int
    """
    allowed_values = ["1200", "2400", "4800", "9600", "19200"]
    if baudrate not in allowed_values:
        raise ValueError(
            "Invalid value for `baudrate` ({0}), must be one of {1}"
            .format(baudrate, allowed_values)
        )

    self._baudrate = baudrate
Expected code
    ...
    allowed_values = [1200, 2400, 4800, 9600, 19200]
    if baudrate not in allowed_values:
    ...
Command line used for generation

So far used/generated via swagger-editor (generator)

コントリビューターガイド