Skip to content
This repository has been archived by the owner on Aug 20, 2021. It is now read-only.

Commit

Permalink
Fix broken comments for flag values
Browse files Browse the repository at this point in the history
Previously, for some reason, this was not returning any comments on latest OSCAL
  • Loading branch information
isimluk committed Dec 18, 2019
1 parent afcfead commit 799cef8
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 17 deletions.
7 changes: 7 additions & 0 deletions metaschema/metaschema.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,13 @@ type Flag struct {
Def *DefineFlag
}

func (f *Flag) GoComment() string {
if f.Description != "" {
return f.Description
}
return f.Def.Description
}

type Choice struct {
Field []Field `xml:"field"`
Assembly []Assembly `xml:"assembly"`
Expand Down
9 changes: 0 additions & 9 deletions metaschema/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ func GenerateTypes(metaschema *Metaschema) error {
"plural": inflection.Plural,
"wrapString": wrapString,
"parseDatatype": parseDatatype,
"commentFlag": commentFlag,
"packageImport": packageImport,
"getImports": getImports,
"requiresPointer": requiresPointer,
Expand Down Expand Up @@ -90,14 +89,6 @@ func parseDatatype(datatype string, packageName string) string {
return datatypes[Datatype(datatype)]
}

func commentFlag(flagName string, metaschema Metaschema) []string {
df, err := metaschema.GetDefineFlag(flagName)
if err == nil {
return wrapString(df.Description)
}
return nil
}

func packageImport(named string, metaschema Metaschema) string {
for _, df := range metaschema.DefineFlag {
if df.Name == named {
Expand Down
10 changes: 2 additions & 8 deletions metaschema/types.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,7 @@ type {{toCamel .Name}} struct {
Title string `xml:"title,omitempty" json:"title,omitempty"`
{{- end}}
{{- range .Flags}}
{{- $cf := commentFlag .Name $m}}
{{- range $cf}}
// {{ . }}
{{- end}}
// {{ .GoComment }}
{{- $dt := parseDatatype .Datatype $packageName}}
{{- if and (eq "id" .Name) (eq "profile" $packageName)}}
Id string `xml:"param-id,attr,omitempty" json:"id,omitempty"`
Expand Down Expand Up @@ -85,10 +82,7 @@ type {{toCamel .Name}} struct {
{{- end}}
type {{toCamel .Name}} struct {
{{- range .Flags}}
{{- $cf := commentFlag .Name $m -}}
{{range $cf}}
// {{ . }}
{{end -}}
// {{ .GoComment }}
{{- $dt := parseDatatype .Datatype $packageName -}}
{{toCamel .Name}} {{if eq "" $dt}}string{{else}}{{$dt}}{{end}} `xml:"{{ .Name }},attr,omitempty" json:"{{toLowerCamel .Name}},omitempty"`
{{end -}}
Expand Down

0 comments on commit 799cef8

Please sign in to comment.