swagger-api / swagger-api/swagger-codegen-generators

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

Open
#1,262 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Mustache
Stars
299
Forks
439
PR merge metrics
No merged PRs in 30d

Description

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the issue with openapi.yml, generate_server.bash, and the swaggerapi/swagger-codegen-cli-v3:3.0.54 Docker image, then inspect the generated swagger_server/controllers/init.py file. Trace the python-flask generator templates or generation path that produces this file; done means generated init.py files are empty or valid Python without NULL bytes.

Written by the indexing model from the issue text.

Assessment

Tech stack
docker, python
Domain
backend, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.