swagger-api / swagger-api/swagger-codegen

[Python]Client library does not generate auth_settings with multiple definitions

Open
#3,435 16 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Client: Python help wanted Issue: Invalid spec
Dominant language
Mustache
Stars
17.8k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

Description

I am using swagger-codegen to generate a python client library based on a spec with multiple security definitions. The generated library is both not generating all the security definitions, and doesn't even attempt to use the one that was generated.

Security definitions in configuration.py. Note the lack of "knurld_auth" OAuth definition:

    def auth_settings(self):
        """
        Gets Auth Settings dict for api client.

        :return: The Auth Settings information dict.
        """
        return {
            'developer_id':
                {
                    'type': 'api_key',
                    'in': 'header',
                    'key': 'Developer-id: Bearer:',
                    'value': self.get_api_key_with_prefix('Developer-id: Bearer:')
                },

        }

Contents of all methods in api_client.py indicate no security definition being used:

# Authentication setting
        auth_settings = []
Swagger-codegen version

2.0

Swagger declaration file content or url

https://gist.github.com/ianseyer/f3610a13702aaee9dd4b2d804222512f

The relevant part:

  "securityDefinitions": {
    "developer_id": {
      "type": "apiKey",
      "name": "Developer-id: Bearer:",
      "in": "header"
    },
    "knurld_auth": {
      "type": "oauth2",
      "authorizationUrl": "https://api.knurld.io/oauth/client_credential/accesstoken?grant_type=client_credentials",
      "tokenUrl": "https://api.knurld.io/oauth/client_credential/accesstoken?grant_type=client_credentials",
      "flow": "application"
    }
  }
Command line used for generation

swagger-codegen generate -i swagger.compiled.json -o python/ -l python

Steps to reproduce

Download swagger spec, generate, browse the source.

Suggest a Fix

Check for proper definitions within swagger-codegen. No errors or warnings were thrown.

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 with the linked Swagger declaration and swagger-codegen generate -i swagger.compiled.json -o python/ -l python. Compare the generated configuration.py and api_client.py with both security definitions in the specification; done means all definitions are generated and the relevant API methods populate their authentication settings.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
api, authentication
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.