dotnet / docfx

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

[Bug] Ignoring global namespace prevents metadata to generate api folder #9978

Open GarfieldJiang opened 1 month ago

GarfieldJiang commented 1 month ago

Describe the bug

I'm using Unity and making common libraries. I hope to generate docs using the C# source code, cuz current dotnet version won't well restore Unity csprojs. (dotnet restore will output Nothing to do or something alike, and docFX will freeze there, but this is not a problem to me).

I use filterConfig.yml and exclude Global namespace in it (I have "globalNamespaceId": "Global" in docfx.json), but this prevents the metadata to generate the destination dir.

The content of my filterConfig.yml

apiRules:
- include:
    uidRegex: ^MyNamespace$
    type: Namespace
- exclude:
    uidRegex: Global
    type: Namespace

Things work quite well if I don't have this exclude part.

To Reproduce Steps to reproduce the behavior:

  1. Create a unity project and set the docfx.json, filterConfig.yml as follows. The dir that contains docfx.json should be parallel to the Assets/ folder of the unity project. However I don't think this is fully necessary. One can just create similar folder structures as a Unity project.
  2. Write some code in the global namespace, and some other code in MyNamespace namespace.
  3. After initializing the docFX folder, run docFX docfx.json --serve or things alike.

Expected behavior The destination folder (api) should exist but doesn't.

Context (please complete the following information):

{
    "metadata": [
        {
            "allowCompilationErrors": true,
            "src": [
                {
                    "src": "..",
                    "files": [
                        "Assets/MyScriptFolder/**/*.cs"
                    ],
                    "exclude": [
                        "Assets/MyScriptFolder/**/Demo/"
                    ]
                }
            ],
            "globalNamespaceId": "Global",
            "filter": "filterConfig.yml",
            "dest": "api"
        }
    ],
    "build": {
        "globalMetadata": {
            "_appTitle": "MyTitle",
            "_appFooter": "MyFooter",
            "_enableSearch": true
        },
        "content": [
            {
                "files": [
                    "**/*.md",
                    "**/toc.yml",
                    "api/**.yml"
                ],
                "exclude": [
                    "obj/**",
                    "_site/**"
                ]
            }
        ],
        "dest": "_site",
        "globalMetadataFiles": [],
        "fileMetadataFiles": [],
        "template": null,
        "postProcessors": [],
        "noLangKeyword": false
    }
}
// Paste the full exception with stacktrace here, remove sensitive info
// Paste warnings or errors related to this bug here, remove sensitive info
❯ dotnet --info
.NET SDK:
 Version:           8.0.301
 Commit:            1a0e9c0300
 Workload version:  8.0.300-manifests.f6879a9a
 MSBuild version:   17.10.4+10fbfbf2e

Runtime Environment:
 OS Name:     Mac OS X
 OS Version:  14.4
 OS Platform: Darwin
 RID:         osx-x64
 Base Path:   /usr/local/share/dotnet/sdk/8.0.301/

.NET workloads installed:
There are no installed workloads to display.

Host:
  Version:      8.0.6
  Architecture: x64
  Commit:       3b8b000a0e

.NET SDKs installed:
  8.0.301 [/usr/local/share/dotnet/sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.App 8.0.6 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 8.0.6 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]

Other architectures found:
  None

Environment variables:
  Not set

global.json file:
  Not found

Learn more:
  https://aka.ms/dotnet/info

Download .NET:
  https://aka.ms/dotnet/download

Additional context Add any other context about the problem here.

filzrev commented 1 month ago

What's happens when using following regex?

- exclude:
    uidRegex: ^Global\.
    type: Type

It seems when excluding global namespace. All types are excluded from metadata generations.

GarfieldJiang commented 1 month ago

I'll give it a try tomorrow!

GarfieldJiang commented 1 month ago

What's happens when using following regex?

- exclude:
    uidRegex: ^Global\.
    type: Type

It seems when excluding global namespace. All types are excluded from metadata generations.

It works with a little glitch. When clicking the 'API' link on the home page, I go to the api/toc.yml page, which is correct. However, the addr localhost:8080/api leads me to a stylesheet like page, listing all the htmls in the generated api folder.

filzrev commented 1 month ago

However, the addr localhost:8080/api leads me to a stylesheet like page, listing all the htmls in the generated api folder.

It thought these pages are generated by ASP.NET DefaultFilesMiddleware.

This middleware will provide a default index page if the index.html file does not exist in the specified directory. So it's not relevant to the filterconfig settings.

There is an existing [Feature Request] issue to generate index.html file on docfx build phase (#2865) But it's not implemented yet.

GarfieldJiang commented 1 month ago

However, the addr localhost:8080/api leads me to a stylesheet like page, listing all the htmls in the generated api folder.

It thought these pages are generated by ASP.NET DefaultFilesMiddleware.

This middleware will provide a default index page if the index.html file does not exist in the specified directory. So it's not relevant to the filterconfig settings.

There is an existing [Feature Request] issue to generate index.html file on docfx build phase (#2865) But it's not implemented yet.

Thanks for the explanation.