swagger-api/swagger-codegen

[Python] Incorrect code generated for integer properties with enum

Open

#3667 aperta il 29 ago 2016

Vedi su GitHub
 (5 commenti) (2 reazioni) (0 assegnatari)HTML (5474 fork)batch import
Client: PythonFeature: EnumIssue: Bughelp wanted

Metriche repository

Star
 (12.701 star)
Metriche merge PR
 (Nessuna PR mergiata in 30 g)

Descrizione

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)

Guida contributor