Regression: broken nullability after update to v3.9.0
還沒有人認領這個 Issue。
評估
研究方向
首先,透過 SerializeAsJsonAsync(OpenApiSpecVersion.OpenApi3_0) 執行提供的 C# 重現,並比較 v3.7.0 與 v3.9.0 的輸出。追蹤 additionalProperties 中的 JsonSchemaType.Null 以及由 allOf 衍生的 schema 的 OpenAPI 3.0 schema 序列化;完成的條件是兩種情況下都保留 nullable,且不變更其他欄位所顯示的輸出。
由索引模型根據 Issue 內容生成。
描述
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
- 主要語言
- C#
- 星號
- 1.6k
- 分支
- 286
- 平均合併
- 6 小時 38 分鐘
- 30 天內合併 PR
- 35
貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
microsoft/OpenAPI.NET 的其他 Issue
-
難度 2/5 1-3 小時 新手友好度 72/100
microsoft/OpenAPI.NET#2798 ·
-
microsoft/OpenAPI.NET#3056 · 1 則留言 · 1 個 reaction · 已指派 2 人 ·
-
type:breaking-change
難度 4/5 3-5 天 新手友好度 52/100
microsoft/OpenAPI.NET#3014 · 2 則留言 ·
-
help wanted
難度 5/5 一週以上 新手友好度 35/100
microsoft/OpenAPI.NET#2989 · 3 則留言 ·
-
help wanted
難度 5/5 一週以上 新手友好度 35/100
microsoft/OpenAPI.NET#2963 · 5 則留言 ·
查看 microsoft/OpenAPI.NET 的全部 Issue
相似的 Issue
-
effort:S P3 refactor
難度 2/5 1-3 小時 新手友好度 75/100
nightscout/nocturne#1532 ·
-
core dependencies
難度 1/5 1 小時以內 新手友好度 80/100
-
documentation
難度 2/5 1-3 小時 新手友好度 75/100
-
難度 2/5 1-3 小時 新手友好度 70/100
-
難度 2/5 1-3 小時 新手友好度 75/100
DotNetNext/SqlSugar#1458 ·