dotnet / docfx

Static site generator for .NET API documentation.
https://dotnet.github.io/docfx/
MIT License
4.04k stars 858 forks source link

Cannot use fullName in inheritance and implements lists #3769

Open segfaultxavi opened 5 years ago

segfaultxavi commented 5 years ago

DocFX Version Used: 2.40.4.0

Template used: default trying to customize it

Steps to Reproduce: I would like the names in the Inheritance and Implements sections to be fully-qualified. I have tried with a custom template like this (in partials/class.header.tmpl.partial):

<div class="inheritance">
  <h5>{{__global.inheritance}}</h5>
  {{#inheritance}}
  <div class="level{{index}}"><xref uid="{{uid}}" text="{{fullName.0.value}}"/></div>
  {{/inheritance}}
  <div class="level{{level}}"><span class="xref"><b>{{fullName.0.value}}</b></span></div>
  {{#derivedClasses}}
    <div class="level{{index}}"><xref href="{{uid}}" fullName="{{fullName.0.value}}" name="{{fullName.0.value}}"/></div>
  {{/derivedClasses}}
</div>

This works for parent classes, but I am hitting very weird behavior in the child classes, where instead of the full name of the children I get the full name of the current class. The default template uses specName instead of fullName and everything works as expected, but I lose the namespace.

Why is that?

Is there another way to get fully-qualified Inheritance and Implements sections?

stale[bot] commented 5 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in a week if no further activity occurs.

segfaultxavi commented 5 years ago

I am still interested in a solution to this problem. Plus, this looks like there's a bug somewhere...

superyyrrzz commented 5 years ago

Hi @segfaultxavi , Sorry for the late reply.

The reason is that the derived class lacks fullName information. The mustache template has a weird behavior: if it cannot find the property in current level, it will look up in parent level...

You can try appending --exportRawModel --exportViewModel to see the model feeded into template. You will find the derivedClassess lacks fullName, while inheritance and current class has.

So this is like a bug that YAML file lacks information of derived classes in reference section, which makes it not self-contained.

segfaultxavi commented 5 years ago

Ok, understood. Is there any workaround you can suggest? I am already postprocessing yml files to add ?displayProperty=fullName to links, so I can add more things if I need to.

superyyrrzz commented 5 years ago

I can only think of a dirty workaround to fix YAML:

If you have a class have a derived class, you will find this in YAML file:

  derivedClasses:
  - CatLibrary.TomFromBaseClass

The data fix is to add the missing reference to reference section, like:

references:
- uid: CatLibrary.TomFromBaseClass
  name: TomFromBaseClass
  nameWithType: TomFromBaseClass
  fullName: CatLibrary.TomFromBaseClass

Thank try it again. With this YAML change, your custom template should work.

segfaultxavi commented 5 years ago

Thank you very much, with a bit of grep and sed I added:

references:
- uid: $fullClassName
  fullName: $fullClassName

To every entry in the derivedClasses: list. Now I can use {{fullName}} in the template without issues.