Skip to content

Variable json_json_body assigned but not used #139

Closed
@pawamoy

Description

@pawamoy

Describe the bug
I'm running flake8 on the generated code and I get a lot of these "variable assigned but not used" for the json_json_body variable:

async def create_or_update_version(*, client: Client, json_body: CreateVersion) -> Union[
    BusinessModel, None, None, None, None, None,
]:
    """My description."""
    url = "{}/api/v1/resource/versions".format(client.base_url,)

    json_json_body = json_body.to_dict()

    async with httpx.AsyncClient() as _client:
        response = await _client.post(url=url, headers=client.get_headers(), json=json_body,)

    if response.status_code == 200:
        return BusinessModel.from_dict(cast(Dict[str, Any], response.json()))
    if response.status_code == 400:
        return None
    if response.status_code == 401:
        return None
    if response.status_code == 403:
        return None
    if response.status_code == 404:
        return None
    if response.status_code == 500:
        return None
    else:
        raise ApiResponseError(response=response)

As you can see the json_json_body variable is not used.

To Reproduce
It seems to happen for every client I generate from a spec file.

Expected behavior
Not sure. The variable should not be declared if it is not used.

OpenAPI Spec File
The interesting parts might be:

    "/api/v1/resource/versions": {
      "post": {
        "operationId": "create_or_update_version",
        "description": "My description.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CreateVersion"
              }
            }
          }
        },

and

      "CreateVersion": {
        "type": "object",
        "properties": {
          "Comment": {
            "type": "string"
          },
          "ParentId": {
            "type": "string",
            "format": "uuid"
          },
          "solutionGUID": {
            "type": "string",
            "format": "uuid"
          },
          "versionName": {
            "type": "string"
          },
          "versionNumber": {
            "type": "integer"
          }
        }
      },

Desktop (please complete the following information):

  • OS: RedHat 7
  • Python Version: 3.7.8
  • openapi-python-client version 0.5.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    🐞bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions