Skip to content

Custom JsonConverter causes OpenAPI request schema to be empty #63051

@Archanian

Description

@Archanian

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

In a .NET 9 (also happens in .NET 10 preview) web app (minimal API), when implementing a custom JsonConverter for a request model, the generated OpenAPI spec contains an empty object for the request body schema. If the converter is not registered, the request body schema is defined correctly.

Expected Behavior

The OpenAPI spec should contain a correctly defined schema for the request model in cases where a custom JsonConverter is defined.

Steps To Reproduce

Simple repro project repository can be found here:. Running this app will generate the following OpenAPI spec (note the empty schema for CreateChannelRequest):

{
  "openapi": "3.0.1",
  "info": {
    "title": "open-api-test | v1",
    "version": "1.0.0"
  },
  "servers": [
    {
      "url": "http://localhost:5161/"
    }
  ],
  "paths": {
    "/channels": {
      "post": {
        "tags": [
          "open-api-test"
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CreateChannelRequest"
              }
            }
          },
          "required": true
        },
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "text/plain": {
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "CreateChannelRequest": { }
    }
  },
  "tags": [
    {
      "name": "open-api-test"
    }
  ]
}

Removing the JsonConverter registration results in the following (correct) schema for CreateChannelRequest:

{
  "openapi": "3.0.1",
  "info": {
    "title": "open-api-test | v1",
    "version": "1.0.0"
  },
  "servers": [
    {
      "url": "http://localhost:5161/"
    }
  ],
  "paths": {
    "/channels": {
      "post": {
        "tags": [
          "open-api-test"
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CreateChannelRequest"
              }
            }
          },
          "required": true
        },
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "text/plain": {
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "CreateChannelRequest": {
        "required": [
          "name",
          "enabled"
        ],
        "type": "object",
        "properties": {
          "name": {
            "type": "string"
          },
          "enabled": {
            "type": "boolean"
          }
        }
      }
    }
  },
  "tags": [
    {
      "name": "open-api-test"
    }
  ]
}

Exceptions (if any)

No response

.NET Version

9.0.7 (but also fails in 10.0.100-preview.6.25358.103)

Anything else?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-minimalIncludes minimal APIs, endpoint filters, parameter binding, request delegate generator etcfeature-openapi

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions