Azure / Azure/azure-functions-openapi-extension

Validation, is it even working ?

オープン
#653 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る
主要言語
C#
スター
388
フォーク
202
PR マージ指標
30日以内にマージされた PR はありません

説明

I've created a class, below, which has been decorated to set the type and the maximum length.

public class Test
{
[OpenApiProperty(Nullable = true, Description = "The unique message id of the request")]
[DataType(DataType.Text)]
[StringLength(10, MinimumLength = 1, ErrorMessage = "Eeeek")]
public string ExternalRef { get; set; }
}

In the progam.cs if I set the Openapi version to Version 2

var options = new OpenApiConfigurationOptions()
{
OpenApiVersion = OpenApiVersionType.V2,
}

The Swagger GUI will let me enter a string up to the Maximum length, and pass the call to to the azure function. :)
If I exceed the Maximum length the the Swagger GUI does nothing, no errors or change of colour, nothing. :(

If I update the OpenApiVersion to Version 3
Then every time, whether the string is shorter or longer than the maximum length the call will be passed to the azure function :(

Just for completeness my function is below

[Function("Function2")]
[OpenApiOperation(operationId: "Function2")]
[OpenApiRequestBody(contentType: "application/json", bodyType: typeof(Test), Description = "Test Object", Required = true)]
[OpenApiResponseWithBody(statusCode: HttpStatusCode.OK, contentType: "text/plain", bodyType: typeof(string), Description = "The OK response")]
public HttpResponseData Function2([HttpTrigger(AuthorizationLevel.Anonymous, "post")] HttpRequestData req)
{
_logger.LogInformation("C# HTTP trigger function processed a request.");

using var bodyReader = new StreamReader(req.Body);
var body = bodyReader.ReadToEndAsync().Result;

var data = JsonConvert.DeserializeObject(body);

var response = req.CreateResponse(HttpStatusCode.OK);
response.WriteStringAsync("Hello!!! " + data.ExternalRef);
return response;
}

This is a Isolated Azure Function V4 .Net 8

What I'd like to know:-
1, How do I set my openapi configuration so that the swagger GUI obeys the schema restrictions.
2, How do I set the openapi configuration so that the swagger GUI will indicate that something is wrong.

Thanks

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

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

調査の方向性

Reproduce the report using the OpenApiConfigurationOptions in Program.cs, the Test model's OpenApiProperty, DataType, and StringLength attributes, and the Function2 HTTP trigger. Compare the generated Swagger UI behavior for OpenAPI V2 and V3, then inspect the resulting schema and request handling. Done means the documented length restriction and invalid-input indication behave as expected in the supported configuration.

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

評価

技術スタック
azure, csharp, openapi
領域
api, backend
issue の種類
バグ
難易度
4/5
見積もり時間
3〜5日
活発さ
停滞
明瞭さ
説明が足りない
初心者へのやさしさ
25/100

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

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