microsoft / microsoft/OpenAPI.NET
Regression: broken nullability after update to v3.9.0
オープン
まだ誰も着手していません。
help wanted
type:feature
- 主要言語
- C#
- スター
- 1.6k
- フォーク
- 286
- 平均マージ
- 6時間 38分
- マージ済み PR(30日)
- 35
説明
Describe the bug
After updating from v3.7.0 to v3.9.0, the nullable property disappears when writing an OpenAPI 3.0 document.
Repro steps
using Microsoft.OpenApi;
var metaSchema = new OpenApiSchema
{
Type = JsonSchemaType.Object,
AdditionalProperties = new OpenApiSchema
{
Type = JsonSchemaType.Null
}
};
var baseSchema = new OpenApiSchema
{
Type = JsonSchemaType.Object,
Id = "base",
Properties = new Dictionary<string, IOpenApiSchema>
{
["id"] = new OpenApiSchema
{
Type = JsonSchemaType.String
}
}
};
var derivedSchema = new OpenApiSchema
{
Type = JsonSchemaType.Null,
AllOf = new List<IOpenApiSchema>
{
new OpenApiSchemaReference(baseSchema.Id)
},
Properties = new Dictionary<string, IOpenApiSchema>
{
["kind"] = new OpenApiSchema
{
Type = JsonSchemaType.String
}
}
};
var doc = new OpenApiDocument();
doc.Components ??= new OpenApiComponents();
doc.Components.Schemas ??= new Dictionary<string, IOpenApiSchema>();
doc.Components.Schemas.Add("meta", metaSchema);
doc.Components.Schemas.Add("base", baseSchema);
doc.Components.Schemas.Add("derived", derivedSchema);
var result = await doc.SerializeAsJsonAsync(OpenApiSpecVersion.OpenApi3_0);
Console.WriteLine(result);
Using v3.7.0, this prints:
{
"openapi": "3.0.4",
"info": { },
"paths": { },
"components": {
"schemas": {
"meta": {
"type": "object",
"additionalProperties": {
"nullable": true
}
},
"base": {
"type": "object",
"properties": {
"id": {
"type": "string"
}
}
},
"derived": {
"allOf": [
{
"$ref": "#/components/schemas/base"
}
],
"properties": {
"kind": {
"type": "string"
}
},
"nullable": true
}
}
}
}
Using v3.9.0, this prints:
{
"openapi": "3.0.4",
"info": { },
"paths": { },
"components": {
"schemas": {
"meta": {
"type": "object",
"additionalProperties": {
"enum": [
null
]
}
},
"base": {
"type": "object",
"properties": {
"id": {
"type": "string"
}
}
},
"derived": {
"allOf": [
{
"$ref": "#/components/schemas/base"
}
],
"properties": {
"kind": {
"type": "string"
}
}
}
}
}
}
Screenshots/Code Snippets
View of the diff:
Originally reported at: https://github.com/domaindrivendev/Swashbuckle.AspNetCore/issues/4065
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
まず、提供された C# の再現コードを SerializeAsJsonAsync(OpenApiSpecVersion.OpenApi3_0) で実行し、v3.7.0 と v3.9.0 の出力を比較します。additionalProperties 内の JsonSchemaType.Null と allOf から派生したスキーマについて、OpenAPI 3.0 スキーマのシリアル化を追跡します。完了の条件は、他のフィールドに対して表示されている出力を変更せず、どちらの場合も nullable が保持されることです。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- csharp
- 領域
- api
- issue の種類
- バグ
- 難易度
- 3/5
- 見積もり時間
- 1〜2日
- 活発さ
- 静か
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 55/100