Skip to content

[openapi] specific ProducesResponseType's SchemaReferenceId(name) by ProducesResponseTypeAttribute #61837

@ngyyuusora

Description

@ngyyuusora

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.

Like https://github.com/dotnet/aspnetcore/pull/58193/files

Describe the solution you'd like

Usage in mvc controller

[ProducesResponseType<PaginatedResponseResult<GetAdminUserDto>>(StatusCodes.Status200OK, SchemaId = "PaginatedGetAdminUserDto")]

Output schema: PaginatedGetAdminUserDto

Additional context

add a schemaId filed. then we can read customized schemaId in there,

internal static string? GetSchemaReferenceId(this JsonTypeInfo jsonTypeInfo, bool isTopLevel = true)
    {
        var type = jsonTypeInfo.Type;
        var underlyingType = Nullable.GetUnderlyingType(type);
        if (isTopLevel && OpenApiConstants.PrimitiveTypes.Contains(underlyingType ?? type))
        {
            return null;
        }

        // Short-hand if the type we're generating a schema reference ID for is
        // one of the simple types defined above.
        if (_simpleTypeToName.TryGetValue(type, out var simpleName))
        {
            return simpleName;
        }

        // Although arrays are enumerable types they are not encoded correctly
        // with JsonTypeInfoKind.Enumerable so we handle the Enumerable type
        // case here.
        if (jsonTypeInfo is JsonTypeInfo { Kind: JsonTypeInfoKind.Enumerable } || type.IsArray)
        {
            return null;
        }

        if (jsonTypeInfo is JsonTypeInfo { Kind: JsonTypeInfoKind.Dictionary })
        {
            return null;
        }

        return type.GetSchemaReferenceId(jsonTypeInfo.Options);
    }

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    ✔️ Resolution: AnsweredResolved because the question asked by the original author has been answered.Status: Resolvedarea-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