Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ModelMetadataType attributes are ignored if the target class is inherited #2507

Closed
whitebehemoth opened this issue Sep 26, 2022 · 4 comments
Closed
Labels
stale Stale issues or pull requests

Comments

@whitebehemoth
Copy link

whitebehemoth commented Sep 26, 2022

Version="6.4.0"
Steps to reproduce:

  1. Extend a base DTO and use metadata attributes to differentiate DTOs for different actions.
  2. Reference inherited classes and generate Swagger.json
  public class BaseDto
   {
       public Guid Id { get; set; }
       public Guid ProductId { get; set; }
       [StringLength(255)]
       public string? Name { get; set; }
   }

   [ModelMetadataType(typeof(CreateDtoMetadata))]
   public class CreateDto : BaseDto     {    }

   [ModelMetadataType(typeof(UpdateDtoMetadata))]
   public class UpdateDto : BaseDto    {    }

   public class CreateDtoMetadata
   {
       [Required]
       public Guid ProductId { get; set; }
       [Required]
       public string? Name { get; set; }
   }
   public class UpdateDtoMetadata
   {
       [Required]
       public Guid Id { get; set; }
       [Required]
       public string? Name { get; set; }
   }

Expected result: In generated swagger.json both CreateDto and UpdateDto schemas should be different and have the combination of the attributes from Base DTO class and from corresponded metadata classes:

"CreateDto": {
        "required": ["name","productId"],
        "type": "object",
        "properties": {
        "id": {"type": "string", "format": "uuid"},
        "productId": {"type": "string", "format": "uuid"},
        "name": {"maxLength": 255,"minLength": 0,"type": "string"}
},"additionalProperties": false}

"UpdateDto": {
        "required": ["id","name"],
        "type": "object",
        "properties": {"id": {"type": "string","format": "uuid"},
        "productId": {"type": "string","format": "uuid"},
        "name": {"maxLength": 255,"minLength": 0,"type": "string"}
},
"additionalProperties": false
},

Actual result: both inherited classes are identical, attributes from metadata classes are ignored

"CreateDto": {
        "type": "object",
        "properties": {
        "id": {"type": "string","format": "uuid"},
        "productId": {"type": "string","format": "uuid"},
        "name": {"maxLength": 255,"minLength": 0,"type": "string", "nullable": true}
},
"additionalProperties": false
},
Copy link
Contributor

This issue is stale because it has been open for 60 days with no activity. It will be automatically closed in 14 days if no further updates are made.

@github-actions github-actions bot added the stale Stale issues or pull requests label Apr 16, 2024
@martincostello
Copy link
Collaborator

Looks like this might be a duplicate of #1981.

Copy link
Contributor

This issue is stale because it has been open for 60 days with no activity. It will be automatically closed in 14 days if no further updates are made.

@github-actions github-actions bot added the stale Stale issues or pull requests label Jun 16, 2024
Copy link
Contributor

github-actions bot commented Jul 3, 2024

This issue was closed because it has been inactive for 14 days since being marked as stale.

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Jul 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stale Stale issues or pull requests
Projects
None yet
Development

No branches or pull requests

2 participants