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

Commit

Permalink
fix profile and catalog generation discrepancy
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew Weiss committed Jan 14, 2019
1 parent dbb4520 commit 9474f52
Show file tree
Hide file tree
Showing 10 changed files with 610 additions and 23 deletions.
2 changes: 2 additions & 0 deletions metaschema/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"text/template"

"github.com/iancoleman/strcase"
"github.com/jinzhu/inflection"
wordwrap "github.com/mitchellh/go-wordwrap"
)

Expand Down Expand Up @@ -37,6 +38,7 @@ func GenerateTypes(metaschema *Metaschema) error {
"toLower": strings.ToLower,
"toCamel": strcase.ToCamel,
"toLowerCamel": strcase.ToLowerCamel,
"plural": inflection.Plural,
"wrapString": wrapString,
"parseDatatype": parseDatatype,
"commentFlag": commentFlag,
Expand Down
8 changes: 4 additions & 4 deletions metaschema/types.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ type {{toCamel .Name}} struct {
{{- end}}

{{- range .Model.Fields}}
{{toCamel .GroupAs}} []{{packageImport .Named $m}}{{toCamel .Named}} `xml:"{{ .Named }},omitempty" json:"{{toLowerCamel .GroupAs}},omitempty"`
{{toCamel .GroupAs}} []{{packageImport .Named $m}}{{toCamel .Named}} `xml:"{{ .Named }},omitempty" json:"{{plural .Named}},omitempty"`
{{- end}}

{{- range .Model.Assembly}}
{{toCamel .Named}} *{{packageImport .Named $m}}{{toCamel .Named}} `xml:"{{ .Named }},omitempty" json:"{{toLowerCamel .Named}},omitempty"`
{{- end}}

{{- range .Model.Assemblies}}
{{toCamel .GroupAs}} []{{packageImport .Named $m}}{{toCamel .Named}} `xml:"{{ .Named }},omitempty" json:"{{toLowerCamel .GroupAs}},omitempty"`
{{toCamel .GroupAs}} []{{packageImport .Named $m}}{{toCamel .Named}} `xml:"{{ .Named }},omitempty" json:"{{plural .Named}},omitempty"`
{{- end}}

{{- range .Model.Choice}}
Expand All @@ -44,15 +44,15 @@ type {{toCamel .Name}} struct {
{{- end}}

{{- range .Fields}}
{{toCamel .GroupAs}} []{{packageImport .Named $m}}{{toCamel .Named}} `xml:"{{ .Named }},omitempty" json:"{{toLowerCamel .GroupAs}},omitempty"`
{{toCamel .GroupAs}} []{{packageImport .Named $m}}{{toCamel .Named}} `xml:"{{ .Named }},omitempty" json:"{{plural .Named}},omitempty"`
{{- end}}

{{- range .Assembly}}
{{toCamel .Named}} *{{packageImport .Named $m}}{{toCamel .Named}} `xml:"{{ .Named }},omitempty" json:"{{toLowerCamel .Named}},omitempty"`
{{- end}}

{{- range .Assemblies}}
{{toCamel .GroupAs}} []{{packageImport .Named $m}}{{toCamel .Named}} `xml:"{{ .Named }},omitempty" json:"{{toLowerCamel .GroupAs}},omitempty"`
{{toCamel .GroupAs}} []{{packageImport .Named $m}}{{toCamel .Named}} `xml:"{{ .Named }},omitempty" json:"{{plural .Named}},omitempty"`
{{- end}}
{{- end}}

Expand Down
6 changes: 3 additions & 3 deletions types/oscal/catalog/catalog.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,10 @@ type Param struct {
// Another parameter invoking this one
DependsOn string `xml:"depends-on,attr,omitempty" json:"dependsOn,omitempty"`
Label Label `xml:"label,omitempty" json:"label,omitempty"`
Descriptions []Desc `xml:"desc,omitempty" json:"descriptions,omitempty"`
Descriptions []Desc `xml:"desc,omitempty" json:"descs,omitempty"`
Constraints []Constraint `xml:"constraint,omitempty" json:"constraints,omitempty"`
Links []Link `xml:"link,omitempty" json:"links,omitempty"`
Guidance []Guideline `xml:"guideline,omitempty" json:"guidance,omitempty"`
Guidance []Guideline `xml:"guideline,omitempty" json:"guidelines,omitempty"`
Value Value `xml:"value,omitempty" json:"value,omitempty"`
Select *Select `xml:"select,omitempty" json:"select,omitempty"`
}
Expand All @@ -110,7 +110,7 @@ type Select struct {

// When selecting, a requirement such as one or more
HowMany string `xml:"how-many,attr,omitempty" json:"howMany,omitempty"`
Alternatives []Choice `xml:"choice,omitempty" json:"alternatives,omitempty"`
Alternatives []Choice `xml:"choice,omitempty" json:"choices,omitempty"`
}

// A partition or component of a control, subcontrol or part
Expand Down
26 changes: 10 additions & 16 deletions types/oscal/profile/profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (

// Each OSCAL profile is defined by a Profile element
type Profile struct {
ID string `xml:"id,attr,omitempty" json:"id,omitempty"`
XMLName xml.Name `xml:"http://csrc.nist.gov/ns/oscal/1.0 profile" json:"-"`
Merge *Merge `xml:"merge,omitempty" json:"merge,omitempty"`
Modify *Modify `xml:"modify,omitempty" json:"modify,omitempty"`
Expand All @@ -34,45 +33,45 @@ type Merge struct {
// resolution.
type Custom struct {
IdSelectors []Call `xml:"call,omitempty" json:"calls,omitempty"`
PatternSelectors []Match `xml:"match,omitempty" json:"patternSelectors,omitempty"`
PatternSelectors []Match `xml:"match,omitempty" json:"matches,omitempty"`
Groups []Group `xml:"group,omitempty" json:"groups,omitempty"`
}

// As in catalogs, a group of (selected) controls or of groups of controls
type Group struct {
Groups []Group `xml:"group,omitempty" json:"groups,omitempty"`
IdSelectors []Call `xml:"call,omitempty" json:"calls,omitempty"`
PatternSelectors []Match `xml:"match,omitempty" json:"patternSelectors,omitempty"`
PatternSelectors []Match `xml:"match,omitempty" json:"matches,omitempty"`
}

// Set parameters or amend controls in resolution
type Modify struct {
ParamSettings []SetParam `xml:"set-param,omitempty" json:"paramSettings,omitempty"`
Alterations []Alter `xml:"alter,omitempty" json:"alterations,omitempty"`
ParamSettings []SetParam `xml:"set-param,omitempty" json:"set-params,omitempty"`
Alterations []Alter `xml:"alter,omitempty" json:"alters,omitempty"`
}

// Specifies which controls and subcontrols to include from the resource (source
// catalog) being imported
type Include struct {
All *All `xml:"all,omitempty" json:"all,omitempty"`
IdSelectors []Call `xml:"call,omitempty" json:"calls,omitempty"`
PatternSelectors []Match `xml:"match,omitempty" json:"patternSelectors,omitempty"`
PatternSelectors []Match `xml:"match,omitempty" json:"matches,omitempty"`
}

// Which controls and subcontrols to exclude from the resource (source catalog)
// being imported
type Exclude struct {
IdSelectors []Call `xml:"call,omitempty" json:"calls,omitempty"`
PatternSelectors []Match `xml:"match,omitempty" json:"patternSelectors,omitempty"`
PatternSelectors []Match `xml:"match,omitempty" json:"matches,omitempty"`
}

// A parameter setting, to be propagated to points of insertion
type SetParam struct {
Id string `xml:"param-id,attr,omitempty" json:"id,omitempty"`
Id string `xml:"id,attr,omitempty" json:"id,omitempty"`
Class string `xml:"class,attr,omitempty" json:"class,omitempty"`
DependsOn string `xml:"depends-on,attr,omitempty" json:"dependsOn,omitempty"`
Label catalog.Label `xml:"label,omitempty" json:"label,omitempty"`
Descriptions []catalog.Desc `xml:"desc,omitempty" json:"descriptions,omitempty"`
Descriptions []catalog.Desc `xml:"desc,omitempty" json:"descs,omitempty"`
Constraints []catalog.Constraint `xml:"constraint,omitempty" json:"constraints,omitempty"`
Links []catalog.Link `xml:"link,omitempty" json:"links,omitempty"`
Parts []catalog.Part `xml:"part,omitempty" json:"parts,omitempty"`
Expand All @@ -88,8 +87,8 @@ type Alter struct {
ControlId string `xml:"control-id,attr,omitempty" json:"controlId,omitempty"`
// Value of the 'id' flag on a target subcontrol
SubcontrolId string `xml:"subcontrol-id,attr,omitempty" json:"subcontrolId,omitempty"`
Removals []Remove `xml:"remove,omitempty" json:"removals,omitempty"`
Additions []Add `xml:"add,omitempty" json:"additions,omitempty"`
Removals []Remove `xml:"remove,omitempty" json:"removes,omitempty"`
Additions []Add `xml:"add,omitempty" json:"adds,omitempty"`
}

// Specifies contents to be added into controls or subcontrols, in resolution
Expand Down Expand Up @@ -118,11 +117,6 @@ type Combine struct {
// elements or attributes.
type AsIs string

func (a *AsIs) UnmarshalJSON(b []byte) error {
*a = AsIs(string(b))
return nil
}

// Include all controls from the imported resource (catalog)
type All struct {
// Whether subcontrols should be implicitly included, if not called.
Expand Down
6 changes: 6 additions & 0 deletions types/oscal/profile/unmarshalers.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package profile

func (a *AsIs) UnmarshalJSON(b []byte) error {
*a = AsIs(string(b))
return nil
}
21 changes: 21 additions & 0 deletions vendor/github.com/jinzhu/inflection/LICENSE

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

55 changes: 55 additions & 0 deletions vendor/github.com/jinzhu/inflection/README.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 9474f52

Please sign in to comment.