Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion gen-apidocs/generators/markdown.go
Original file line number Diff line number Diff line change
Expand Up @@ -635,7 +635,7 @@ func (m *MarkdownWriter) classifyDefinitions() map[string]defClassification {
out := make(map[string]defClassification, len(m.Config.Definitions.All))
m.inlinedByParent = map[string][]*api.Definition{}
for _, d := range m.Config.Definitions.All {
if d.IsOldVersion || d.IsInlined || d.InToc {
if d.IsOldVersion || d.InToc {
out[d.Key()] = defClassification{Mode: classifySkip}
continue
}
Expand All @@ -648,6 +648,10 @@ func (m *MarkdownWriter) classifyDefinitions() map[string]defClassification {
m.inlinedByParent[home.Key()] = append(m.inlinedByParent[home.Key()], d)
continue
}
if d.IsInlined {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can closestTopLevelHome(d) return a valid parent for all d.IsInlined definitions? if not, what cases are expected to have IsInlined == true but no top-level home?

out[d.Key()] = defClassification{Mode: classifySkip}
continue
}
out[d.Key()] = defClassification{Mode: classifyStandalone}
}
return out
Expand Down
27 changes: 19 additions & 8 deletions gen-apidocs/generators/markdown_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,10 @@ func TestWritePipeTable(t *testing.T) {

func TestOperationSlug(t *testing.T) {
cases := map[string]string{
"listCoreV1Pod": "listcorev1pod",
"readAppsV1NamespacedDeployment": "readappsv1namespaceddeployment",
"watchCore.V1.Pod": "watchcore-v1-pod",
"Some/Weird ID": "some-weird-id",
"listCoreV1Pod": "listcorev1pod",
"readAppsV1NamespacedDeployment": "readappsv1namespaceddeployment",
"watchCore.V1.Pod": "watchcore-v1-pod",
"Some/Weird ID": "some-weird-id",
}
for in, want := range cases {
if got := operationSlug(in); got != want {
Expand Down Expand Up @@ -278,7 +278,8 @@ func TestClassifyDefinitions(t *testing.T) {

// Reference graph (parent --refs--> child; AppearsIn is reverse).
//
// Pod (InToc) --> PodSpec --> Container
// Pod (InToc) --> PodStatus --> ContainerStatus (pattern-inlined)
// --> PodSpec --> Container
// --> Volume --> AzureDiskVolumeSource
// <-- PodTemplateSpec (shared)
// Deployment (InToc) --> DeploymentSpec --> PodTemplateSpec
Expand All @@ -288,6 +289,10 @@ func TestClassifyDefinitions(t *testing.T) {
deployment := mkDef("Deployment", true)
podTemplate := mkDef("PodTemplate", true)
podSpec := mkDef("PodSpec", false)
podStatus := mkDef("PodStatus", false)
podStatus.IsInlined = true
containerStatus := mkDef("ContainerStatus", false)
containerStatus.IsInlined = true
deploymentSpec := mkDef("DeploymentSpec", false)
podTemplateSpec := mkDef("PodTemplateSpec", false)
container := mkDef("Container", false)
Expand All @@ -297,6 +302,8 @@ func TestClassifyDefinitions(t *testing.T) {

// Populate AppearsIn (= "who references me?").
podSpec.AppearsIn = api.SortDefinitionsByName{pod, podTemplateSpec}
podStatus.AppearsIn = api.SortDefinitionsByName{pod}
containerStatus.AppearsIn = api.SortDefinitionsByName{podStatus}
deploymentSpec.AppearsIn = api.SortDefinitionsByName{deployment}
podTemplateSpec.AppearsIn = api.SortDefinitionsByName{podTemplate, deploymentSpec}
container.AppearsIn = api.SortDefinitionsByName{podSpec}
Expand All @@ -307,7 +314,8 @@ func TestClassifyDefinitions(t *testing.T) {
all := map[string]*api.Definition{}
for _, d := range []*api.Definition{
pod, deployment, podTemplate,
podSpec, deploymentSpec, podTemplateSpec,
podSpec, podStatus, containerStatus,
deploymentSpec, podTemplateSpec,
container, volume, azureDisk, objectMeta,
} {
all[d.Key()] = d
Expand All @@ -331,6 +339,9 @@ func TestClassifyDefinitions(t *testing.T) {
{"AzureDiskVolumeSource inlines into Pod", azureDisk, classifyInline, pod},
// Volume is shared via PodSpec only; same winner as Container.
{"Volume inlines into Pod", volume, classifyInline, pod},
// ContainerStatus is pattern-inlined by name, but its reference chain
// still has a unique top-level home and must not be skipped.
{"ContainerStatus inlines into Pod", containerStatus, classifyInline, pod},
// ObjectMeta is at distance 1 from three InToc resources → tie → standalone.
{"ObjectMeta is standalone", objectMeta, classifyStandalone, nil},
// Pod itself is InToc → not classified (own resource page).
Expand Down Expand Up @@ -405,8 +416,8 @@ func TestLinkDefinitionsSkipsInlined(t *testing.T) {
m := &MarkdownWriter{
linkMap: map[string]linkInfo{},
classifications: map[string]defClassification{
azureDisk.Key(): {Mode: classifyInline}, // InlineInto irrelevant for this test
objectMeta.Key(): {Mode: classifyStandalone},
azureDisk.Key(): {Mode: classifyInline}, // InlineInto irrelevant for this test
objectMeta.Key(): {Mode: classifyStandalone},
},
}

Expand Down