microsoft / microsoft/OpenAPI.NET
Regression: broken nullability after update to v3.9.0
Chưa có ai nhận issue này.
- Ngôn ngữ chính
- C#
- Star
- 1.6k
- Fork
- 286
- Merge trung bình
- 6 giờ 38 phút
- Pull request đã merge (30 ngày)
- 35
Mô tả
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
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Hướng nghiên cứu
Bắt đầu bằng cách chạy bản tái hiện C# được cung cấp thông qua SerializeAsJsonAsync(OpenApiSpecVersion.OpenApi3_0) và so sánh đầu ra của v3.7.0 với v3.9.0. Theo dõi quá trình tuần tự hóa schema OpenAPI 3.0 cho JsonSchemaType.Null trong additionalProperties và một schema được suy ra từ allOf; được xem là hoàn tất khi nullable được giữ nguyên trong cả hai trường hợp mà không thay đổi đầu ra được hiển thị cho các trường khác.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- csharp
- Lĩnh vực
- api
- Loại issue
- Lỗi
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức độ hoạt động
- Ít trao đổi
- Độ rõ ràng
- Khá rõ ràng
- Mức phù hợp với người mới
- 55/100