Skip to content

Commit

Permalink
🐛 Add yaml:"inline" to Resource field tags (#543)
Browse files Browse the repository at this point in the history
The yaml encoder/decoder needs to be explicitly told inline the
`Resource` struct's fields on each of the API resources, otherwise
attempts to bind requests that include Resource fields (`id`,
`createTime`, `createUser`, `updateUser`) fail.

Signed-off-by: Sam Lucidi <slucidi@redhat.com>
  • Loading branch information
mansam authored Oct 27, 2023
1 parent c3a832b commit 66b56b5
Show file tree
Hide file tree
Showing 22 changed files with 31 additions and 31 deletions.
2 changes: 1 addition & 1 deletion api/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -1058,7 +1058,7 @@ func (h ApplicationHandler) AssessmentCreate(ctx *gin.Context) {
//
// Application REST resource.
type Application struct {
Resource
Resource `yaml:",inline"`
Name string `json:"name" binding:"required"`
Description string `json:"description"`
Bucket *Ref `json:"bucket"`
Expand Down
2 changes: 1 addition & 1 deletion api/archetype.go
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ func (h ArchetypeHandler) AssessmentCreate(ctx *gin.Context) {
//
// Archetype REST resource.
type Archetype struct {
Resource
Resource `yaml:",inline"`
Name string `json:"name" yaml:"name"`
Description string `json:"description" yaml:"description"`
Comments string `json:"comments" yaml:"comments"`
Expand Down
2 changes: 1 addition & 1 deletion api/assessment.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ func (h AssessmentHandler) Update(ctx *gin.Context) {
//
// Assessment REST resource.
type Assessment struct {
Resource
Resource `yaml:",inline"`
Application *Ref `json:"application,omitempty" yaml:",omitempty" binding:"excluded_with=Archetype"`
Archetype *Ref `json:"archetype,omitempty" yaml:",omitempty" binding:"excluded_with=Application"`
Questionnaire Ref `json:"questionnaire" binding:"required"`
Expand Down
2 changes: 1 addition & 1 deletion api/bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ func (h BucketHandler) BucketDelete(ctx *gin.Context) {
//
// Bucket REST resource.
type Bucket struct {
Resource
Resource `yaml:",inline"`
Path string `json:"path"`
Expiration *time.Time `json:"expiration,omitempty"`
}
Expand Down
2 changes: 1 addition & 1 deletion api/businessservice.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ func (h BusinessServiceHandler) Update(ctx *gin.Context) {
//
// BusinessService REST resource.
type BusinessService struct {
Resource
Resource `yaml:",inline"`
Name string `json:"name" binding:"required"`
Description string `json:"description"`
Stakeholder *Ref `json:"owner"`
Expand Down
6 changes: 3 additions & 3 deletions api/dependency.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,9 @@ func (h DependencyHandler) Delete(ctx *gin.Context) {
//
// Dependency REST resource.
type Dependency struct {
Resource
To Ref `json:"to"`
From Ref `json:"from"`
Resource `yaml:",inline"`
To Ref `json:"to"`
From Ref `json:"from"`
}

//
Expand Down
2 changes: 1 addition & 1 deletion api/group.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ func (h StakeholderGroupHandler) Update(ctx *gin.Context) {
//
// StakeholderGroup REST resource.
type StakeholderGroup struct {
Resource
Resource `yaml:",inline"`
Name string `json:"name" binding:"required"`
Description string `json:"description"`
Stakeholders []Ref `json:"stakeholders"`
Expand Down
2 changes: 1 addition & 1 deletion api/identity.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ func (h *IdentityHandler) setDecrypted(ctx *gin.Context) {
//
// Identity REST resource.
type Identity struct {
Resource
Resource `yaml:",inline"`
Kind string `json:"kind" binding:"required"`
Name string `json:"name" binding:"required"`
Description string `json:"description"`
Expand Down
2 changes: 1 addition & 1 deletion api/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ type Import map[string]interface{}
//
// ImportSummary REST resource.
type ImportSummary struct {
Resource
Resource `yaml:",inline"`
Filename string `json:"filename"`
ImportStatus string `json:"importStatus" yaml:"importStatus"`
ImportTime time.Time `json:"importTime" yaml:"importTime"`
Expand Down
2 changes: 1 addition & 1 deletion api/jobfunction.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ func (h JobFunctionHandler) Update(ctx *gin.Context) {
//
// JobFunction REST resource.
type JobFunction struct {
Resource
Resource `yaml:",inline"`
Name string `json:"name" binding:"required"`
Stakeholders []Ref `json:"stakeholders"`
}
Expand Down
2 changes: 1 addition & 1 deletion api/migrationwave.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ func (h MigrationWaveHandler) Delete(ctx *gin.Context) {
//
// MigrationWave REST Resource
type MigrationWave struct {
Resource
Resource `yaml:",inline"`
Name string `json:"name"`
StartDate time.Time `json:"startDate" yaml:"startDate"`
EndDate time.Time `json:"endDate" yaml:"endDate"`
Expand Down
2 changes: 1 addition & 1 deletion api/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ func (h ProxyHandler) Update(ctx *gin.Context) {
//
// Proxy REST resource.
type Proxy struct {
Resource
Resource `yaml:",inline"`
Enabled bool `json:"enabled"`
Kind string `json:"kind" binding:"oneof=http https"`
Host string `json:"host"`
Expand Down
2 changes: 1 addition & 1 deletion api/questionnaire.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ func (h QuestionnaireHandler) Update(ctx *gin.Context) {
}

type Questionnaire struct {
Resource
Resource `yaml:",inline"`
Name string `json:"name" yaml:"name" binding:"required"`
Description string `json:"description" yaml:"description"`
Required bool `json:"required" yaml:"required"`
Expand Down
2 changes: 1 addition & 1 deletion api/review.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ func (h ReviewHandler) CopyReview(ctx *gin.Context) {
//
// Review REST resource.
type Review struct {
Resource
Resource `yaml:",inline"`
BusinessCriticality uint `json:"businessCriticality" yaml:"businessCriticality"`
EffortEstimate string `json:"effortEstimate" yaml:"effortEstimate"`
ProposedAction string `json:"proposedAction" yaml:"proposedAction"`
Expand Down
4 changes: 2 additions & 2 deletions api/ruleset.go
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ func (h *RuleSetHandler) delete(ctx *gin.Context, id uint) (err error) {
//
// RuleSet REST resource.
type RuleSet struct {
Resource
Resource `yaml:",inline"`
Kind string `json:"kind,omitempty"`
Name string `json:"name"`
Description string `json:"description"`
Expand Down Expand Up @@ -380,7 +380,7 @@ func (r *RuleSet) HasRule(id uint) (b bool) {
//
// Rule - REST Resource.
type Rule struct {
Resource
Resource `yaml:",inline"`
Name string `json:"name,omitempty"`
Description string `json:"description,omitempty"`
Labels []string `json:"labels,omitempty"`
Expand Down
2 changes: 1 addition & 1 deletion api/stakeholder.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ func (h StakeholderHandler) Update(ctx *gin.Context) {
//
// Stakeholder REST resource.
type Stakeholder struct {
Resource
Resource `yaml:",inline"`
Name string `json:"name" binding:"required"`
Email string `json:"email" binding:"required"`
Groups []Ref `json:"stakeholderGroups" yaml:"stakeholderGroups"`
Expand Down
2 changes: 1 addition & 1 deletion api/tag.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ func (h TagHandler) Update(ctx *gin.Context) {
//
// Tag REST resource.
type Tag struct {
Resource
Resource `yaml:",inline"`
Name string `json:"name" binding:"required"`
Category Ref `json:"category" binding:"required"`
}
Expand Down
2 changes: 1 addition & 1 deletion api/tagcategory.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ func (h TagCategoryHandler) TagList(ctx *gin.Context) {
//
// TagCategory REST resource.
type TagCategory struct {
Resource
Resource `yaml:",inline"`
Name string `json:"name" binding:"required"`
Username string `json:"username"`
Rank uint `json:"rank"`
Expand Down
2 changes: 1 addition & 1 deletion api/target.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ func (h TargetHandler) Update(ctx *gin.Context) {
//
// Target REST resource.
type Target struct {
Resource
Resource `yaml:",inline"`
Name string `json:"name"`
Description string `json:"description"`
Provider string `json:"provider,omitempty" yaml:",omitempty"`
Expand Down
14 changes: 7 additions & 7 deletions api/taskgroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -354,13 +354,13 @@ func (h TaskGroupHandler) BucketDelete(ctx *gin.Context) {
//
// TaskGroup REST resource.
type TaskGroup struct {
Resource
Name string `json:"name"`
Addon string `json:"addon"`
Data interface{} `json:"data" swaggertype:"object" binding:"required"`
Bucket *Ref `json:"bucket,omitempty"`
State string `json:"state"`
Tasks []Task `json:"tasks"`
Resource `yaml:",inline"`
Name string `json:"name"`
Addon string `json:"addon"`
Data interface{} `json:"data" swaggertype:"object" binding:"required"`
Bucket *Ref `json:"bucket,omitempty"`
State string `json:"state"`
Tasks []Task `json:"tasks"`
}

//
Expand Down
2 changes: 1 addition & 1 deletion api/ticket.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ func (h TicketHandler) Delete(ctx *gin.Context) {

// Ticket API Resource
type Ticket struct {
Resource
Resource `yaml:",inline"`
Kind string `json:"kind" binding:"required"`
Reference string `json:"reference"`
Link string `json:"link"`
Expand Down
2 changes: 1 addition & 1 deletion api/tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ func (h TrackerHandler) ProjectIssueTypeList(ctx *gin.Context) {

// Tracker API Resource
type Tracker struct {
Resource
Resource `yaml:",inline"`
Name string `json:"name" binding:"required"`
URL string `json:"url" binding:"required"`
Kind string `json:"kind" binding:"required,oneof=jira-cloud jira-onprem"`
Expand Down

0 comments on commit 66b56b5

Please sign in to comment.