Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
1 of 3 tasks
julien-lenormand-se opened this issue Mar 7, 2024 · 2 comments
Open
1 of 3 tasks

Comments

@julien-lenormand-se
Copy link

Hello,

Checklist from your CONTRIBUTING files :

  • I have not found a matching issue, neither in swagger-api/swagger-codegen nor swagger-codegen-generators
  • I am using the latest master
    • kinda, I'm using the Docker version of 2 weeks ago : swaggerapi/swagger-codegen-cli-v3:3.0.54
  • test locally with the most recent jar
    • I'll try to do it soon

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
Copy link

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
Copy link

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

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

  • 🆗 36 to 41
  • 🐛 42 to 46
  • 😶 47 to 51 have an unrelated Java version error
  • 😶 52 and 53 have an unrelated path error
  • 🐛 54 to 57 (currently "latest")
  • 😶 current "unstable" has an unrelated path error

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants