Regression: broken nullability after update to v3.9.0

Offen
#2,967 18 Kommentare 1 Reaktion 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Bewertung

Schwierigkeit
3/5
Geschätzter Aufwand
1-2 Tage
Anfängerfreundlichkeit
55/100
Issue-Typ
Bug
Klarheit
Größtenteils klar
Aktivitätsstatus
Ruhig
Tech-Stack
csharp
Bereich
api

Rechercherichtung

Beginne damit, die bereitgestellte C#-Reproduktion über SerializeAsJsonAsync(OpenApiSpecVersion.OpenApi3_0) auszuführen und die Ausgaben von v3.7.0 und v3.9.0 zu vergleichen. Verfolge die Serialisierung von OpenAPI 3.0-Schemas für JsonSchemaType.Null in additionalProperties und ein aus allOf abgeleitetes Schema; als erledigt gilt die Aufgabe, wenn nullable in beiden Fällen erhalten bleibt, ohne die gezeigte Ausgabe für andere Felder zu ändern.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

help wanted type:feature

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:

Image

Originally reported at: https://github.com/domaindrivendev/Swashbuckle.AspNetCore/issues/4065

Vorherrschende Sprache
C#
Sterne
1.6k
Forks
286
Ø Merge
6 Std. 38 Min.
Gemergte PRs (30 T.)
35

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus microsoft/OpenAPI.NET

Alle Issues in microsoft/OpenAPI.NET

Ähnliche Issues

Weitere Issues zu C#

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.