OpenAPITools / OpenAPITools/openapi-generator

[BUG] [PYTHON] Empty security requirement generates code with syntax error

Open
#17,214 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

Bug Report Checklist
  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description

An API endpoint with empty security requirements generates code for Configuration.auth_settings() that contains a syntax error. This appears to be allowed in clause 4.8.30.1 and is given as an example in 4.8.30.2.1.

openapi-generator version

7.1.0

OpenAPI declaration file content or url
components:
  securitySchemes:
    openapi_authorization:
      in: HEADER
      name: Authorization
      type: apiKey
info:
  version: "1.0"
  title: Test
openapi: 3.0.0
paths:
  /foo:
    get:
      responses:
        "200":
          content:
            application/json: {}
          description: asdf
      security:
        - openapi_authorization: []
Generation Details
openapi-generator generate -g python -i schema.yml
Steps to reproduce
  1. Create a YAML file with the above content and run the CLI with the given settings and that file.
  2. In the generated client, go to the definition for Configuration.auth_settings()
Related issues/PRs

N/A

Suggest a fix

I think an empty list of requirements means the return value should be an empty dict? In any case, I think we need to fix this or change the code that calls it to make isApiKey equal to false if the security requirements list is empty.

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

Start with modules/openapi-generator/src/main/resources/python/configuration.mustache, especially the auth_settings() section referenced in the issue. Run the shown openapi-generator generate -g python command with the provided schema, then inspect the generated Configuration.auth_settings() output; done means the empty security requirement produces syntactically valid Python.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
api, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.