-
Notifications
You must be signed in to change notification settings - Fork 2
feat: vendor doc-gen tooling and build from the spec's openapi.yaml release asset #2
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| module github.com/gemaraproj/website/tools | ||
|
|
||
| go 1.25.0 | ||
|
|
||
| require ( | ||
| github.com/goccy/go-yaml v1.19.2 | ||
| github.com/spf13/cobra v1.10.1 | ||
| ) | ||
|
|
||
| require ( | ||
| github.com/inconshreveable/mousetrap v1.1.0 // indirect | ||
| github.com/spf13/pflag v1.0.9 // indirect | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| github.com/cpuguy83/go-md2man/v2 v2.0.6/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6NIQQ7OS05n1F4g= | ||
| github.com/goccy/go-yaml v1.19.2 h1:PmFC1S6h8ljIz6gMRBopkjP1TVT7xuwrButHID66PoM= | ||
| github.com/goccy/go-yaml v1.19.2/go.mod h1:XBurs7gK8ATbW4ZPGKgcbrY1Br56PdM69F7LkFRi1kA= | ||
| github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8= | ||
| github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw= | ||
| github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= | ||
| github.com/spf13/cobra v1.10.1 h1:lJeBwCfmrnXthfAupyUTzJ/J4Nc1RsHC/mSRU2dll/s= | ||
| github.com/spf13/cobra v1.10.1/go.mod h1:7SmJGaTHFVBY0jW4NXGluQoLvhqFQM+6XSKD+P4XaB0= | ||
| github.com/spf13/pflag v1.0.9 h1:9exaQaMOCwffKiiiYk6/BndUBv+iRViNW+4lEMi0PvY= | ||
| github.com/spf13/pflag v1.0.9/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= | ||
| gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= | ||
| gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,92 @@ | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| package cmd | ||
|
|
||
| import ( | ||
| "bytes" | ||
| "fmt" | ||
| "os" | ||
| "strings" | ||
| "text/template" | ||
|
|
||
| "github.com/goccy/go-yaml" | ||
| "github.com/spf13/cobra" | ||
| ) | ||
|
|
||
| type TemplateData struct { | ||
| Table string | ||
| } | ||
|
|
||
| var lexicon2MDCmd = &cobra.Command{ | ||
| Use: "lexicon2md", | ||
| Short: "Generate definitions table from lexicon YAML", | ||
| Long: `Generate a definitions table in Markdown format from a lexicon YAML file. | ||
| The lexicon file should contain an array of terms with their definitions and references. | ||
| The output will be written to a Markdown file using a template.`, | ||
| RunE: runLexicon2MD, | ||
| } | ||
|
|
||
| var lexicon2MDFlags struct { | ||
| lexiconFile string | ||
| outputFile string | ||
| } | ||
|
|
||
| func newLexicon2MDCmd() *cobra.Command { | ||
| lexicon2MDCmd.Flags().StringVarP(&lexicon2MDFlags.lexiconFile, "lexicon", "l", "lexicon.yaml", "Input lexicon YAML file") | ||
| lexicon2MDCmd.Flags().StringVarP(&lexicon2MDFlags.outputFile, "output", "o", "model/02-definitions.md", "Output markdown file") | ||
| return lexicon2MDCmd | ||
| } | ||
|
|
||
| func runLexicon2MD(cmd *cobra.Command, args []string) error { | ||
| data, err := os.ReadFile(lexicon2MDFlags.lexiconFile) | ||
| if err != nil { | ||
| return fmt.Errorf("Error reading lexicon file: %v", err) | ||
| } | ||
|
|
||
| var lexicon Lexicon | ||
| if err := yaml.Unmarshal(data, &lexicon); err != nil { | ||
| return fmt.Errorf("Error parsing lexicon YAML: %v", err) | ||
| } | ||
|
|
||
| var tableRows strings.Builder | ||
| for _, term := range lexicon.Terms { | ||
| slug := termToSlug(term.Title) | ||
|
|
||
| termName := fmt.Sprintf("<a id=\"%s\"></a>**%s**", slug, term.Title) | ||
|
|
||
| refs := make([]string, 0, len(term.References)) | ||
| for _, r := range term.References { | ||
| refs = append(refs, r.Citation) | ||
| } | ||
| appliesTo := strings.Join(refs, "<br>") | ||
|
|
||
| definition := strings.TrimSpace(strings.ReplaceAll(term.Definition, "|", "\\|")) | ||
|
|
||
| tableRows.WriteString(fmt.Sprintf("| %s | %s | %s |\n", termName, definition, appliesTo)) | ||
| } | ||
|
|
||
| templateContent, err := os.ReadFile(lexicon2MDFlags.outputFile) | ||
| if err != nil { | ||
| return fmt.Errorf("Error reading output file: %v", err) | ||
| } | ||
|
|
||
| tmpl, err := template.New("definitions").Parse(string(templateContent)) | ||
| if err != nil { | ||
| return fmt.Errorf("Error parsing template: %v", err) | ||
| } | ||
|
|
||
| var output bytes.Buffer | ||
| templateData := TemplateData{ | ||
| Table: strings.TrimSpace(tableRows.String()), | ||
| } | ||
| if err := tmpl.Execute(&output, templateData); err != nil { | ||
| return fmt.Errorf("Error executing template: %v", err) | ||
| } | ||
|
|
||
| if err := os.WriteFile(lexicon2MDFlags.outputFile, output.Bytes(), 0644); err != nil { | ||
| return fmt.Errorf("Error writing output file: %v", err) | ||
| } | ||
|
|
||
| fmt.Printf("Successfully generated definitions table in %s\n", lexicon2MDFlags.outputFile) | ||
| return nil | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit