dotnet/aspnetcore

Set `AdditionalProperties` if Type has `JsonExtensionData` attribute.

Open

#66,338 创建于 2026年4月16日

在 GitHub 查看
 (3 评论) (0 反应) (0 负责人)C# (37,933 star) (10,653 fork)batch import
area-minimalfeature-openapifeature-requesthelp wanted

描述

Is there an existing issue for this?

  • I have searched the existing issues

Is your feature request related to a problem? Please describe the problem.

No problem, just a nice to have.

Describe the solution you'd like

This was originally filed in Microsoft/OpenAPI.NET under #2809

If a schema has a field with the [JsonExtensionData] attribute it should specify AdditionalProperties: {} or AdditionalProperties: true to allow for a free-form object.

Describe alternatives you've considered I've setup my own SchemaTransformer that does this:

options.AddSchemaTransformer((schema, context, cancellationToken) =>
{
    var extensionDataProperty = context.JsonTypeInfo.Type
        .GetProperties(BindingFlags.Public | BindingFlags.Instance)
        .FirstOrDefault(p => Attribute.IsDefined(p, typeof(JsonExtensionDataAttribute)));

    if (extensionDataProperty is not null)
    {
        schema.AdditionalPropertiesAllowed = true;
        schema.AdditionalProperties = new OpenApiSchema();
    }

    return Task.CompletedTask;
});

Additional context

I believe it makes sense for this to be supported because if you have a model that has ExtensionData it accepts additional properties, but the OpenApi schema gen doesn't represent this without manual intervention.

贡献者指南

Set `AdditionalProperties` if Type has `JsonExtensionData` attribute. · dotnet/aspnetcore#66338 | Good First Issue