A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/swagger-api/swagger-codegen/issues/9612 below:

[Python] number type cast to nonexistent BigDecimal instead of float · Issue #9612 · swagger-api/swagger-codegen · GitHub

Description

This is coming out of a python flask app, but we are using --lang python:

A number type in our swagger.json gets incorrectly mapped to BigDecimal rather than float, which is a nonexistent model:

will cause you to hit this line in the parent model

from my_client.models.big_decimal import BigDecimal  # noqa: F401,E501

which will result in

ModuleNotFoundError: No module named 'my_client.models.big_decimal'

because my_client.models.big_decimal is never generated.

Swagger-codegen version

3.0.10

Swagger declaration file content or url
{
  "OffendingSchema": {
    "additionalProperties": false,
    "properties": {
      "some_object": {
        "items": {
          "items": {
            "type": "number"  // this is the offending type
          },
          "type": "array"
        },
        "type": "array"
      }
    },
    "required": [
      "some_object"
    ],
    "title": "OffendingSchema",
    "type": "object"
  }
}
Command line used for generation
java -jar swagger-codegen-cli.jar generate \
                --lang python \
                --input-spec clients/swagger.json \
                -c clients/swagger-config.json \
                -o clients/python/generated;
Steps to reproduce Related issues/PRs

#8855
#9353

Suggest a fix/enhancement

I think this may be because the following line present in the python-flask generator is not present in the python generator:

typeMapping.put("BigDecimal", "float");

https://github.com/swagger-api/swagger-codegen-generators/blob/781c5a407c831130285c16eac735d56c0f9edd76/src/main/java/io/swagger/codegen/v3/generators/python/PythonFlaskConnexionCodegen.java#L78

absent in

https://github.com/swagger-api/swagger-codegen-generators/blob/781c5a407c831130285c16eac735d56c0f9edd76/src/main/java/io/swagger/codegen/v3/generators/python/PythonClientCodegen.java#L94

Temporary workaround

I was able to get around this by passing in --import-mappings BigDecimal=float to swagger-codegen-cli


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4