Skip to content
Merged
Show file tree
Hide file tree
Changes from 10 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: 6 additions & 0 deletions changelog/v0.36.3/format-markdown-files.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
changelog:
- type: FIX
issueLink: https://github.com/solo-io/solo-projects/issues/6612
resolvesIssue: false
description: >-
Update the markdown templates to fit new formatting guidelines.
33 changes: 24 additions & 9 deletions pkg/code-generator/docgen/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,22 +147,37 @@ func (d *DocsGen) FileHeader(filename string) string {
return ".. Code generated by solo-kit. DO NOT EDIT."
}
if d.DocsOptions.Output == options.Hugo {
name := filepath.Base(filename)
if strings.HasSuffix(name, d.protoSuffix()) {
name = name[:len(name)-len(d.protoSuffix())]
}
return fmt.Sprintf(`
return d.hugoFileHeader(filename)
}
return `<!-- Code generated by solo-kit. DO NOT EDIT. -->
`
}

func (d *DocsGen) hugoFileHeader(filename string) string {
name := filepath.Base(filename)

var title string
if strings.HasSuffix(name, d.protoSuffix()) {
// Remove the "sk.md" extensions
name = name[:len(name)-len(d.protoSuffix())]

// Remove the ".proto" extension
extension := filepath.Ext(name)
title = strcase.ToCamel(name[0 : len(name)-len(extension)])
Copy link
Contributor

Choose a reason for hiding this comment

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

I noticed in the gloo PR this results in these titles: GatewaySoloIo, EnvoyGlooeSoloIo
Is that what we want?
Perhaps we only want to camelCase names that have no . remaining after stripping the extension?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

tbh, I'm not sure. This is a formatting change, and the request seemed to be focused mainly at our user-facing APIs. I'm leaning towards including them for consistency, rather than trying to come up with a more complex filter for which files this applies to. wdyt?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think this is primarily a product and docs question.
However, it's also a question about whether it's a strict improvement compared to the current state, and I'm concerned that while GatewaySoloIo is more aesthetic, it's also more confusing than gateway.solo.io.proto since it doesn't correspond to anything meaningful.

Copy link

@Nadine2016 Nadine2016 Nov 19, 2024

Choose a reason for hiding this comment

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

so I agree with @arianaw66 that in this case the name does not make sense. Only the ones that end in .proto I think should get the name change. the ones that end in .project should not. However, I also think we should not have any of these .project resources in our docs, especially since those are just overview pages with all the CRs. So what we could do is one of the following:

Option 1:

  • Not change the name for .project files.
  • Display them as-is in the docs.

Option 2:

  • Leave the change as-is and remove these references from the docs. We can do this manually on our end if it can't be done in the template or is too hard to implement.

} else {
// Not a file for a proto file, leave the title to match the name of the file
title = name
}

return fmt.Sprintf(`
---
title: "%s"
weight: 5
---

<!-- Code generated by solo-kit. DO NOT EDIT. -->

`, name)
}
return `<!-- Code generated by solo-kit. DO NOT EDIT. -->
`
`, title)
}

func (d *DocsGen) projectSuffix() string {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func ProtoFileTemplate(project *model.Project, docsOptions *options.DocsOptions)
{{ end }}

{{- if gt (len .Messages) 0 }}
#### Types:
**Types:**

{{ $linkMessage := "- [{{ printfptr \"%v\" .Name }}](#{{ toAnchorLink \"%v\" .Name }}) {{- if (resourceForMessage .) }} **Top-Level Resource**{{ end }}" }}
{{ $linkEnum := "- [{{ printfptr \"%v\" .Name }}](#{{ toAnchorLink \"%v\" .Name }})" }}
Expand All @@ -35,7 +35,7 @@ func ProtoFileTemplate(project *model.Project, docsOptions *options.DocsOptions)

{{- if gt (len .Enums) 0 }}

##### Enums:
**Enums:**

{{ range .Enums}}
- [{{ printfptr "%v" .Name }}](#{{ toAnchorLink "%v" .Name }})
Expand All @@ -44,7 +44,7 @@ func ProtoFileTemplate(project *model.Project, docsOptions *options.DocsOptions)

{{ end}}

##### Source File: {{ githubLinkForFile "main" .Name }}
**Source File: {{ githubLinkForFile "main" .Name }}**

{{ $msgLongInfo := ` + "`" + `
{{ $Message := . -}}
Expand Down
4 changes: 3 additions & 1 deletion pkg/code-generator/schemagen/crd.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ const (
v1 = "apiextensions.k8s.io/v1"
)

const crdFileHeader = `CRD ValidationSchema generated by solo-kit. DO NOT EDIT.`

var (
ApiVersionMismatch = func(expected, actual string) error {
return eris.Errorf("Expected ApiVersion [%s] but found [%s]", expected, actual)
Expand All @@ -37,7 +39,7 @@ func NewCrdWriter(crdDirectory string) *CrdWriter {
fileWriter: &writer.DefaultFileWriter{
Root: crdDirectory,
HeaderFromFilename: func(s string) string {
return fmt.Sprintf("# %s\n\n", writer.DefaultFileHeader)
return fmt.Sprintf("# %s\n\n", crdFileHeader)
},
},
}
Expand Down
2 changes: 1 addition & 1 deletion test/mocks/crds/testing.solo.io_v1_MockResource.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Code generated by solo-kit. DO NOT EDIT.
# CRD ValidationSchema generated by solo-kit. DO NOT EDIT.

apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
Expand Down
2 changes: 1 addition & 1 deletion test/mocks/crds/testing.solo.io_v1_SimpleMockResource.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Code generated by solo-kit. DO NOT EDIT.
# CRD ValidationSchema generated by solo-kit. DO NOT EDIT.

apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
Expand Down