Skip to content

Bug: ObsoleteAttribute is not applied to classes that have a base class. #1820

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

Open
SebastianStehle opened this issue May 3, 2025 · 0 comments

Comments

@SebastianStehle
Copy link
Contributor

I have a class with a base class in C# and the following schema is generated in my API:

{
   "WebhookRuleActionDto":{
      "allOf":[
         {
            "$ref":"#/components/schemas/RuleActionDto"
         },
         {
            "type":"object",
            "deprecated":true,
            "x-deprecatedMessage":"Has been replaced by flows.",
            "additionalProperties":false,
            "required":[
               "url",
               "method"
            ],
            "properties":{
               
            }
         }
      ]
   }
}

(I have simplified it a little bit).

By default the class has no Obsolete attribute because the model only checks at the root schema:

public bool IsDeprecated => _schema.IsDeprecated;

I solved it with a little bit of postprocessing, but I think it should just work.

public static void AddDeprecations(OpenApiDocument document)
{
    foreach (var (name, scheme) in document.Components.Schemas)
    {
        if (scheme.IsDeprecated)
        {
            continue;
        }

        if (scheme.AllOf != null && scheme.AllOf.Count > 0)
        {
            foreach (var allOf in scheme.AllOf)
            {
                if (!string.IsNullOrWhiteSpace(allOf.DeprecatedMessage))
                {
                    Console.WriteLine($"Add Deprecation to: {name}");
                    scheme.DeprecatedMessage = allOf.DeprecatedMessage;
                    scheme.IsDeprecated = true;
                    break;
                }
            }
        }
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant