swagger-api/swagger-codegen

[Python] Incorrect code generated for integer properties with enum

Open

#3.667 aberto em 29 de ago. de 2016

Ver no GitHub
 (5 comments) (2 reactions) (0 assignees)HTML (5.474 forks)batch import
Client: PythonFeature: EnumIssue: Bughelp wanted

Métricas do repositório

Stars
 (12.701 stars)
Métricas de merge de PR
 (Nenhuma PRs mesclada em 30d)

Description

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)

Guia do colaborador