microsoft / microsoft/OpenAPI.NET

Consider returning reference type from `AddComponent` API

オープン
#2,162 コメント 3 件 リアクション 0 件 担当者 0 名 GitHub で見る

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

主要言語
C#
スター
1.6k
フォーク
286
平均マージ
6時間 38分
マージ済み PR(30日)
35

説明

The AddComponent API currently returns a boolean that indicates if the addition of the component to the document registry succeeded.

It would be nice if the API returned a reference to the item that was just constructed. In an M.A.OpenAPI transformer, I currently need to write:

options.AddOperationTransformer((operation, context, cancellationToken) =>
{
    var schemaService = context.ApplicationServices.GetRequiredKeyedService<IOpenApiSchemaService>(context.DocumentName);
    if (context.Description.RelativePath == "error")
    {
        var errorSchema = schemaService.GetOrCreateSchema(typeof(ProblemDetails));
        context.Document.AddComponent("Error", errorSchema);
        operation.Responses["500"] = new OpenApiResponse
        {
            Description = "Error",
            Content =
            {
                ["application/problem+json"] = new OpenApiMediaType
                {
                    Schema = new OpenApiSchemaReference("Error", context.Document),
                },
            },
        };
    }
    return Task.CompletedTask;
});

but would like to write:

options.AddOperationTransformer((operation, context, cancellationToken) =>
{
    var schemaService = context.ApplicationServices.GetRequiredKeyedService<IOpenApiSchemaService>(context.DocumentName);
    if (context.Description.RelativePath == "error")
    {
        var errorSchema = schemaService.GetOrCreateSchema(typeof(ProblemDetails));
        var insertedSchema = context.Document.AddComponent("Error", errorSchema);
        operation.Responses["500"] = new OpenApiResponse
        {
            Description = "Error",
            Content =
            {
                ["application/problem+json"] = new OpenApiMediaType
                {
                    Schema = insertedSchema,
                },
            },
        };
    }
    return Task.CompletedTask;
});

cc: @baywet I couldn't see if an API that did this existed already and figured I'd add the proposal.

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

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

調査の方向性

まず、AddComponent API の実装と、ドキュメントコンポーネントの登録に関する既存のカバレッジを確認します。現在の boolean 結果を AddOperationTransformer の例と比較し、返された参照が挿入されたスキーマを表していることを確認するとともに、既存の登録動作が維持されていることを確認します。

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

評価

技術スタック
csharp
領域
api, backend-api-design
issue の種類
機能追加
難易度
3/5
見積もり時間
1〜2日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
45/100

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

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