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

[Python] Python generated client has a missing body for if statement

Open
#604 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

Hi.

I use your application for generating swagger clients for my Python project. Sadly versions 3.0.15 and 3.0.16 does not generate correct class. I put dockerfile and json below to help you recreate the problem.
If you run it there will be generated 2 clients. One of the valid (generated by 3.0.14) and one invalid (generated by 3.0.16).
In swagger_client.api.api_keys_api there is class ApiKeysApi. In line 105 there is if if 'secret' in params: and in the newest version this if does not has body. Version 3.0.14 produce this body and it looks like that form_params.append(('Secret', params['secret'])) # noqa: E501

Please confirm the problem.

Best regards
Damian

Dockerfile

FROM adoptopenjdk/openjdk11:x86_64-debianslim-jre-11.0.6_10

WORKDIR /swagger_env

RUN apt-get update && apt-get -y install wget

RUN wget https://repo1.maven.org/maven2/io/swagger/codegen/v3/swagger-codegen-cli/3.0.16/swagger-codegen-cli-3.0.16.jar -O\
	/usr/local/bin/swagger-codegen-cli-invalid.jar

RUN wget https://repo1.maven.org/maven2/io/swagger/codegen/v3/swagger-codegen-cli/3.0.14/swagger-codegen-cli-3.0.14.jar -O\
	/usr/local/bin/swagger-codegen-cli.jar

ENTRYPOINT java -jar /usr/local/bin/swagger-codegen-cli-invalid.jar generate \
	-i swagger.json \
	-l python \
	-o invalid_swagger_client \
	&& \
    java -jar /usr/local/bin/swagger-codegen-cli.jar generate \
	-i swagger.json \
	-l python \
	-o valid_swagger_client

JSON file

{
  "openapi": "3.0.1",
  "info": {
    "title": "Users Service",
    "version": "2.0"
  },
  "servers": [
    {
      "url": "/api/users"
    }
  ],
  "paths": {
    "/v2/namespace/{namespace}/api-keys/validate": {
      "post": {
        "tags": [
          "ApiKeys"
        ],
        "summary": "Validate Api-Key",
        "parameters": [
          {
            "name": "namespace",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "content": {
            "multipart/form-data": {
              "schema": {
                "required": [
                  "Secret"
                ],
                "type": "object",
                "properties": {
                  "Secret": {
                    "type": "string"
                  }
                }
              },
              "encoding": {
                "Secret": {
                  "style": "form"
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "text/plain": {
                "schema": {
                  "$ref": "#/components/schemas/ValidateApiKeyResult"
                }
              },
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ValidateApiKeyResult"
                }
              },
              "text/json": {
                "schema": {
                  "$ref": "#/components/schemas/ValidateApiKeyResult"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "ValidateApiKeyResult": {
        "type": "object",
        "properties": {
          "success": {
            "type": "boolean",
            "readOnly": true
          },
          "message": {
            "type": "string",
            "nullable": true,
            "readOnly": true
          },
          "code": {
            "allOf": [
              {
                "$ref": "#/components/schemas/HttpStatusCode"
              }
            ]
          },
          "status": {
            "type": "integer",
            "format": "int32",
            "readOnly": true
          },
          "owner": {
            "type": "string",
            "nullable": true
          }
        },
        "additionalProperties": false
      }
    }
  }
}

bat for help

docker build -t swagger_env . && docker run --network="host" --rm -it -v %cd%:/swagger_env swagger_env

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

Run the supplied Dockerfile with the provided swagger.json to generate the 3.0.16 and 3.0.14 clients. Compare swagger_client.api.api_keys_api around the if 'secret' in params: statement; done means the newer Python client includes the multipart Secret form parameter body as the older client does.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.