Skip to content

Variable json_json_body assigned but not used #139

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

Closed
pawamoy opened this issue Aug 6, 2020 · 3 comments · Fixed by #147
Closed

Variable json_json_body assigned but not used #139

pawamoy opened this issue Aug 6, 2020 · 3 comments · Fixed by #147
Labels
🐞bug Something isn't working
Milestone

Comments

@pawamoy
Copy link

pawamoy commented Aug 6, 2020

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
@pawamoy pawamoy added the 🐞bug Something isn't working label Aug 6, 2020
@pawamoy pawamoy changed the title Variable assigned but not used Variable json_json_body assigned but not used Aug 6, 2020
@pawamoy
Copy link
Author

pawamoy commented Aug 10, 2020

So, in the above example, it should really be:

    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_json_body,)

Same for sync api endpoints.
Not sure if the templates are faulty, or how to fix it yet.

@dbanty dbanty added this to the 0.5.3 milestone Aug 10, 2020
dbanty added a commit that referenced this issue Aug 10, 2020

Unverified

This commit is not signed, but one or more authors requires that any commit attributed to them is signed.
dbanty added a commit that referenced this issue Aug 10, 2020

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
@dbanty
Copy link
Collaborator

dbanty commented Aug 10, 2020

All set on main, will be available in the next release.

@pawamoy
Copy link
Author

pawamoy commented Aug 11, 2020

Thanks a lot for your work and your fast replies @dbanty!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐞bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants