[python-fastapi][REQ] Add `Fastapi Request` parameter to api methods

オープン 初心者向け
#25,753 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
70/100
issue の種類
機能追加
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
fastapi, openapi, python

調査の方向性

まず、python-fastapi ジェネレーターのテンプレートにある api.mustache と base_api.mustache を、issue でリンクされている FastAPI Request のドキュメントと併せて読むことから始めてください。小さな FastAPI サンプルを再生成して、エンドポイントとベースメソッドがどのように出力されるかを確認し、次に両方のテンプレートシグネチャに Request パラメーターを追加して、実装に渡してください。生成されたエンドポイントが Request を受け取って転送し、ジェネレーターの python-fastapi サンプル/テストが引き続きビルドできれば完了です。

索引モデルが issue の本文から書いたものです。

説明

Enhancement: Feature
Need Fastapi Request in the implementation of the api

As the Fastapi documentation says here it would be good to have access to the request object in the implementation of the api.

Modify api.moustache and base_api.moustache

Add the request to the method in the moustache files, e.g.

async def {{operationId}}(
    request: Request,
    {{#allParams}}
    {{>endpoint_argument_definition}},
    {{/allParams}}
    {{#hasAuthMethods}}
    {{#authMethods}}
    token_{{name}}: TokenModel = Security(
        get_token_{{name}}{{#isOAuth}}, scopes=[{{#scopes}}"{{scope}}"{{^-last}}, {{/-last}}{{/scopes}}]{{/isOAuth}}
    ),
    {{/authMethods}}
    {{/hasAuthMethods}}
) -> {{returnType}}{{^returnType}}None{{/returnType}}:
    {{#notes}}"""{{.}}"""
    {{/notes}}if not Base{{classname}}.subclasses:
        raise HTTPException(status_code=500, detail="Not implemented")
    return await Base{{classname}}.subclasses[0]().{{operationId}}(request, {{#allParams}}{{>impl_argument}}{{^-last}}, {{/-last}}{{/allParams}})
{{^-last}}
class Base{{classname}}:
    subclasses: ClassVar[Tuple] = ()

    def __init_subclass__(cls, **kwargs):
        super().__init_subclass__(**kwargs)
        Base{{classname}}.subclasses = Base{{classname}}.subclasses + (cls,)
{{#operations}}
{{#operation}}
    async def {{operationId}}(
        self,
        request: Request,
        {{#allParams}}
        {{>impl_argument_definition}},
        {{/allParams}}
    ) -> {{returnType}}{{^returnType}}None{{/returnType}}:
        {{#notes}}"""{{.}}"""
        ...{{/notes}}{{^notes}}...{{/notes}}
主要言語
Java
スター
26.9k
フォーク
7.8k
平均マージ
2日 23分
マージ済み PR(30日)
177

環境構築

Codespaces で開く

このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

OpenAPITools/openapi-generator のほかの issue

OpenAPITools/openapi-generator の issue をすべて見る

似ている issue

Java の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。