Title: Security key doesn't respect endpoint explicitly setting anonymous access (via `{}`) · Issue #1372 · openapi-generators/openapi-python-client · GitHub
Open Graph Title: Security key doesn't respect endpoint explicitly setting anonymous access (via `{}`) · Issue #1372 · openapi-generators/openapi-python-client
X Title: Security key doesn't respect endpoint explicitly setting anonymous access (via `{}`) · Issue #1372 · openapi-generators/openapi-python-client
Description: Thanks for this wonderful library! It's been SO helpful :) Describe the bug The client args in generated methods (Client vs AuthenticatedClient) don't match those described by security in the spec, when explicitly anonymous access is per...
Open Graph Description: Thanks for this wonderful library! It's been SO helpful :) Describe the bug The client args in generated methods (Client vs AuthenticatedClient) don't match those described by security in the spec,...
X Description: Thanks for this wonderful library! It's been SO helpful :) Describe the bug The client args in generated methods (Client vs AuthenticatedClient) don't match those described by security in t...
Opengraph URL: https://github.com/openapi-generators/openapi-python-client/issues/1372
X: @github
Domain: patch-diff.githubusercontent.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Security key doesn't respect endpoint explicitly setting anonymous access (via `{}`)","articleBody":"Thanks for this wonderful library! It's been SO helpful :)\n\n**Describe the bug**\nThe client args in generated methods (Client vs AuthenticatedClient) don't match those described by security in the spec, when explicitly anonymous access is permitted in an endpoint's security list, as allowed in spec:\n\n\u003e An empty Security Requirement Object ({}) indicates anonymous access is supported. [[ref, with examples]](https://swagger.io/specification/?sbsearch=-a-n-o-n-y-m-o-u-s#security-requirement-object:~:text=An%20empty%20Security%20Requirement%20Object%20(%7B%7D)%20indicates%20anonymous%20access%20is%20supported.)\n\nExample:\n\n```\n /auth-optional-explicit:\n get:\n summary: Requires auth but has empty object\n security: # \u003c--- client: AuthenticatedClient (EXPECTED: Client | AuthenticatedClient)\n - {}\n - ApiKeyAuth: []\n responses:\n '200':\n description: OK\n```\n\nThis is due to this line\n\nhttps://github.com/openapi-generators/openapi-python-client/blob/49fa8fc076a5733e68029ba36f4672759c4ac52b/openapi_python_client/parser/openapi.py#L423\n\n```\n\u003e\u003e\u003e bool([])\nFalse\n\u003e\u003e\u003e bool([{\"ApiKeyAuth\": []}])\nTrue\n\u003e\u003e\u003e bool([{\"ApiKeyAuth\": []}, {}])\nTrue\n\u003e\u003e\u003e bool([{}])\nTrue\n```\n\nWe would want the last two to return False. We should check if `{}` is anywhere in a list (when it's a list).\n\nThis would do the trick:\n\n```py\nrequires_security_check = lambda sec: bool(sec or []) and {} not in (sec or [])\n```\n\n**OpenAPI Spec File**\n\n```yml\nopenapi: 3.1.0\ninfo:\n title: Security Test API\n version: 1.0.0\nservers:\n - url: https://example.com\npaths:\n /no-auth-specified:\n get:\n summary: Truly anonymous\n security: [] # client: Client | AuthenticatedClient (EXPECTED: same)\n responses:\n '200':\n description: OK\n /explicit-anon:\n get:\n summary: Requires auth but has empty object\n security: # \u003c--- client: AuthenticatedClient (EXPECTED: not sure, but def not this)\n - {}\n responses:\n '200':\n description: OK\n /auth-optional-explicit:\n get:\n summary: Requires auth but has empty object\n security: # \u003c--- client: AuthenticatedClient (EXPECTED: Client | AuthenticatedClient)\n - {}\n - ApiKeyAuth: []\n responses:\n '200':\n description: OK\n /auth-required:\n get:\n summary: Requires API key\n security: # \u003c--- client: AuthenticatedClient\n - ApiKeyAuth: []\n responses:\n '200':\n description: OK\ncomponents:\n securitySchemes:\n ApiKeyAuth:\n type: apiKey\n in: header\n name: X-API-Key\n```\n\n**Desktop (please complete the following information):**\n - OS: [e.g. macOS 10.15.1]\n - Python Version: [e.g. 3.8.0]\n - openapi-python-client version [e.g. 0.1.0]\n\n**Additional context**\n...\n","author":{"url":"https://github.com/patcon","@type":"Person","name":"patcon"},"datePublished":"2025-12-06T19:22:35.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":0},"url":"https://github.com/1372/openapi-python-client/issues/1372"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:257dd871-c74d-61f6-36ee-dbfcdaa81e5e |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 87D0:BA2A1:981B75:C114A6:697FC9D3 |
| html-safe-nonce | f6639a954751cfc2b28134da395d2bb09117c86e4a332d1bed46ac3e04223410 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4N0QwOkJBMkExOjk4MUI3NTpDMTE0QTY6Njk3RkM5RDMiLCJ2aXNpdG9yX2lkIjoiNTgyNTE3MDgwNzEwNTUwNTc0OCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 6a7483ce8941b607807b726dffafc5cb9f18ce2f0a5670628b71c28924483ec5 |
| hovercard-subject-tag | issue:3702240847 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/openapi-generators/openapi-python-client/1372/issue_layout |
| twitter:image | https://opengraph.githubassets.com/6c408fd6ba93a54d7bb55014f2f63b69804017918c4dfb74afd4c306e14bd158/openapi-generators/openapi-python-client/issues/1372 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/6c408fd6ba93a54d7bb55014f2f63b69804017918c4dfb74afd4c306e14bd158/openapi-generators/openapi-python-client/issues/1372 |
| og:image:alt | Thanks for this wonderful library! It's been SO helpful :) Describe the bug The client args in generated methods (Client vs AuthenticatedClient) don't match those described by security in the spec,... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | patcon |
| hostname | github.com |
| expected-hostname | github.com |
| None | 60279d4097367e16897439d16d6bbe4180663db828c666eeed2656988ffe59f6 |
| turbo-cache-control | no-preview |
| go-import | github.com/openapi-generators/openapi-python-client git https://github.com/openapi-generators/openapi-python-client.git |
| octolytics-dimension-user_id | 84925606 |
| octolytics-dimension-user_login | openapi-generators |
| octolytics-dimension-repository_id | 240776275 |
| octolytics-dimension-repository_nwo | openapi-generators/openapi-python-client |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 240776275 |
| octolytics-dimension-repository_network_root_nwo | openapi-generators/openapi-python-client |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 7c85641c598ad130c74f7bcc27f58575cac69551 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width