swagger-api / swagger-codegen-generators

Apache License 2.0
284 stars 421 forks source link

[python-flask] invalid content of a generated `__init__.py` file #1262

Open julien-lenormand-se opened 6 months ago

julien-lenormand-se commented 6 months ago

Hello,

Checklist from your CONTRIBUTING files :

Using the python-flask generator, I sometimes find myself with invalid __init__.py files, containing four NULL (0x00) bytes. When Python then tries to parse them, it fails (and thus the server does not start).

Minimal reproducible example :

openapi.yml

openapi: 3.0.3
info:
  title: Minimal Reproducible Example
  description: "."
  version: 0.0.0
paths:
  /foo:
    get:
      summary: Get
      responses:
        "200":
          description: Status details
      operationId: foo_123

generate_server.bash

set -euo pipefail  # check for errors

echo '(re-)create output directory'
rm -Rf ./output && mkdir ./output
echo 'copy the OpenAPI file into it'
cp ./openapi.yml ./output
echo 'generate the server files from the OpenAPI file'
docker run \
    --rm \
    -u "$(id -u):$(id -g)" \
    -v "${PWD}/output:/local" \
    swaggerapi/swagger-codegen-cli-v3:3.0.54 \
    generate \
    -l python-flask \
    -i /local/openapi.yml \
    -o /local
echo 'check the content of one of the generated __init__.py files'
hexdump -C ./output/swagger_server/controllers/__init__.py

It produces :

check the content of one of the generated __init__.py files
00000000  00 00 00 00                                       |....|
00000004

(if you are not familiar with hexdump, it prints the binary content of a file)
Here we can see that the file contains four 0x00 (NULL) bytes. This is not a valid Python file.

I don't know what causes it.

Expected content : empty (0 bytes), or valid Python content (like in some other generated __init__.py files)

Actual content : four NULL (0x00) bytes.

Lenormju commented 3 months ago

I'm not reproducing the issue when running directly the code from the Swagger Codegen v3.0.54 tag (*NOT** the most recent, but the one corresponding to the Docker version used in the initial report). But I'm reproducing when running the running the Docker image :

swaggerapi/swagger-codegen-cli-v3       3.0.54       17244ca249e8   4 months ago    291MB

I'll keep investigating.

Lenormju commented 3 months ago

cf https://hub.docker.com/r/swaggerapi/swagger-codegen-cli-v3/tags

Using the script provided to reproduce the issue, here are the results :