Skip to content

OpenApi components schema $ref may not correct #64048

@niltor

Description

@niltor

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

My Cshrap models:

public class SystemPermissionGroup : EntityBase
{
    /// <summary>
    /// 
    /// </summary>
    [MaxLength(30)]
    public required string Name { get; set; }
    /// <summary>
    /// 
    /// </summary>
    [MaxLength(1000)]
    public string? Description { get; set; }

    public ICollection<SystemPermission> Permissions { get; set; } = [];

    public ICollection<SystemRole> Roles { get; set; } = [];
}

OpenApi Json:

   "SystemPermissionGroup": {
        "required": [
          "name"
        ],
        "type": "object",
        "properties": {
          "name": {
            "maxLength": 30,
            "type": "string",
            "description": "权限名称标识"
          },
          "description": {
            "maxLength": 1000,
            "type": [
              "null",
              "string"
            ],
            "description": "权限说明"
          },
          "permissions": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/SystemPermission"
            }
          },
          "roles": {
            "$ref": "#/components/schemas/SystemUserInfoDto/properties/systemRoles/items/properties/permissionGroups/items/properties/permissions/items/properties/group/properties/roles"
          },
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "createdTime": {
            "type": "string",
            "format": "date-time"
          },
          "updatedTime": {
            "type": "string",
            "format": "date-time"
          },
          "isDeleted": {
            "type": "boolean"
          }
        }
      },

see the roles $ref:

 "roles": {
    "$ref": "#/components/schemas/SystemUserInfoDto/properties/systemRoles/items/properties/permissionGroups/items/properties/permissions/items/properties/group/properties/roles"
  }

💀💀 What's this?

But permissions schema is correct.

And I did have a SystemUserInfoDto model:

public class SystemUserInfoDto
{
    /// <summary>
    /// user name
    /// </summary>
    [MaxLength(30)]
    public required string UserName { get; set; }

    public Guid Id { get; set; }
    public ICollection<SystemRole> SystemRoles { get; set; } = [];
}

Expected Behavior

the roles schema should be like:

"roles": {
  "type": "array",
  "items": {
    "$ref": "#/components/schemas/SystemRole"
  }
},

Steps To Reproduce

No response

Exceptions (if any)

No response

.NET Version

.net10.rc1 .net10.rc2

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

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions