microsoft / microsoft/OpenAPI.NET
Regression: broken nullability after update to v3.9.0
未关闭
还没有人认领这个 Issue。
help wanted
type:feature
- 主要语言
- C#
- 星标
- 1.6k
- 派生
- 286
- 平均合并
- 6 小时 38 分钟
- 30 天内合并 PR
- 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 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
首先,通过 SerializeAsJsonAsync(OpenApiSpecVersion.OpenApi3_0) 运行提供的 C# 复现,并比较 v3.7.0 和 v3.9.0 的输出。跟踪 additionalProperties 中 JsonSchemaType.Null 以及由 allOf 派生的 schema 的 OpenAPI 3.0 schema 序列化;完成的标准是两种情况下都保留 nullable,同时不改变其他字段的显示输出。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- csharp
- 领域
- api
- Issue 类型
- 缺陷
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 活跃度
- 冷清
- 描述清晰度
- 基本清楚
- 新手友好度
- 55/100