Security key doesn't respect endpoint explicitly setting anonymous access (via `{}`)
まだ誰も着手していません。
評価
- 難易度
- 2/5
- 見積もり時間
- 1〜3時間
- 初心者へのやさしさ
- 55/100
調査の方向性
parser/openapi.py の、423 行前後にある参照された行から始めます。そこでは endpoint の security value が requires-security-check result に変換されています。Issue にある 4 つの security configurations、特に {} を含むリストを比較します。生成されたクライアントの引数に関する期待値が、真に匿名のエンドポイント、明示的に匿名のエンドポイント、認証が任意のエンドポイント、認証が必須のエンドポイントを正しく区別できれば完了です。Issue ではテストファイルは指定されていません。
索引モデルが issue の本文から書いたものです。
説明
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 permitted in an endpoint's security list, as allowed in spec:
An empty Security Requirement Object ({}) indicates anonymous access is supported. [ref, with examples]
Example:
/auth-optional-explicit:
get:
summary: Requires auth but has empty object
security: # <--- client: AuthenticatedClient (EXPECTED: Client | AuthenticatedClient)
- {}
- ApiKeyAuth: []
responses:
'200':
description: OK
This is due to this line
>>> bool([])
False
>>> bool([{"ApiKeyAuth": []}])
True
>>> bool([{"ApiKeyAuth": []}, {}])
True
>>> bool([{}])
True
We would want the last two to return False. We should check if {} is anywhere in a list (when it's a list).
This would do the trick:
requires_security_check = lambda sec: bool(sec or []) and {} not in (sec or [])
OpenAPI Spec File
openapi: 3.1.0
info:
title: Security Test API
version: 1.0.0
servers:
- url: https://example.com
paths:
/no-auth-specified:
get:
summary: Truly anonymous
security: [] # client: Client | AuthenticatedClient (EXPECTED: same)
responses:
'200':
description: OK
/explicit-anon:
get:
summary: Requires auth but has empty object
security: # <--- client: AuthenticatedClient (EXPECTED: not sure, but def not this)
- {}
responses:
'200':
description: OK
/auth-optional-explicit:
get:
summary: Requires auth but has empty object
security: # <--- client: AuthenticatedClient (EXPECTED: Client | AuthenticatedClient)
- {}
- ApiKeyAuth: []
responses:
'200':
description: OK
/auth-required:
get:
summary: Requires API key
security: # <--- client: AuthenticatedClient
- ApiKeyAuth: []
responses:
'200':
description: OK
components:
securitySchemes:
ApiKeyAuth:
type: apiKey
in: header
name: X-API-Key
Desktop (please complete the following information):
- OS: [e.g. macOS 10.15.1]
- Python Version: [e.g. 3.8.0]
- openapi-python-client version [e.g. 0.1.0]
Additional context
...
- 主要言語
- Python
- スター
- 2k
- フォーク
- 293
- 平均マージ
- 34分
- マージ済み PR(30日)
- 1
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
openapi-generators/openapi-python-client のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
-
難易度 3/5 1〜2日 初心者へのやさしさ 72/100
openapi-generators/openapi-python-client#1451 · コメント 1 件 ·
-
難易度 3/5 1〜2日 初心者へのやさしさ 52/100
-
難易度 3/5 1〜2日 初心者へのやさしさ 64/100
openapi-generators/openapi-python-client#1435 · コメント 1 件 ·
openapi-generators/openapi-python-client の issue をすべて見る
似ている issue
-
link-check link-check:sphinx-theme
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
qgis/QGIS-Documentation#11275 ·
-
bug priority:normal ready-for-dev
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
OpenHands/extensions#626 · コメント 1 件 ·
-
難易度 1/5 1時間未満 初心者へのやさしさ 90/100
CSCfi/sd-search-api#39 ·
-
難易度 1/5 1時間未満 初心者へのやさしさ 90/100