From 66b56b5771bf16a73433307f566c4999564be7c1 Mon Sep 17 00:00:00 2001 From: Samuel Lucidi Date: Fri, 27 Oct 2023 12:10:09 -0400 Subject: [PATCH] :bug: Add `yaml:"inline"` to Resource field tags (#543) 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 --- api/application.go | 2 +- api/archetype.go | 2 +- api/assessment.go | 2 +- api/bucket.go | 2 +- api/businessservice.go | 2 +- api/dependency.go | 6 +++--- api/group.go | 2 +- api/identity.go | 2 +- api/import.go | 2 +- api/jobfunction.go | 2 +- api/migrationwave.go | 2 +- api/proxy.go | 2 +- api/questionnaire.go | 2 +- api/review.go | 2 +- api/ruleset.go | 4 ++-- api/stakeholder.go | 2 +- api/tag.go | 2 +- api/tagcategory.go | 2 +- api/target.go | 2 +- api/taskgroup.go | 14 +++++++------- api/ticket.go | 2 +- api/tracker.go | 2 +- 22 files changed, 31 insertions(+), 31 deletions(-) diff --git a/api/application.go b/api/application.go index 93195c5c7..7b3a26050 100644 --- a/api/application.go +++ b/api/application.go @@ -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"` diff --git a/api/archetype.go b/api/archetype.go index eda389694..5ed78309a 100644 --- a/api/archetype.go +++ b/api/archetype.go @@ -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"` diff --git a/api/assessment.go b/api/assessment.go index edc4fa843..d069c5329 100644 --- a/api/assessment.go +++ b/api/assessment.go @@ -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"` diff --git a/api/bucket.go b/api/bucket.go index 20483debd..0f789f510 100644 --- a/api/bucket.go +++ b/api/bucket.go @@ -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"` } diff --git a/api/businessservice.go b/api/businessservice.go index b506ddb06..8cf8025d2 100644 --- a/api/businessservice.go +++ b/api/businessservice.go @@ -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"` diff --git a/api/dependency.go b/api/dependency.go index 525a5ec4a..bb92bc1e9 100644 --- a/api/dependency.go +++ b/api/dependency.go @@ -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"` } // diff --git a/api/group.go b/api/group.go index 4d88b067a..4d9f54e21 100644 --- a/api/group.go +++ b/api/group.go @@ -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"` diff --git a/api/identity.go b/api/identity.go index b882573ce..7f81eabf0 100644 --- a/api/identity.go +++ b/api/identity.go @@ -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"` diff --git a/api/import.go b/api/import.go index 17a03b39c..48ddf4af2 100644 --- a/api/import.go +++ b/api/import.go @@ -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"` diff --git a/api/jobfunction.go b/api/jobfunction.go index e5ce1e0aa..a11a7115a 100644 --- a/api/jobfunction.go +++ b/api/jobfunction.go @@ -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"` } diff --git a/api/migrationwave.go b/api/migrationwave.go index 16ea85fca..a2290d8bc 100644 --- a/api/migrationwave.go +++ b/api/migrationwave.go @@ -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"` diff --git a/api/proxy.go b/api/proxy.go index e7aecaf8f..cf7144e1f 100644 --- a/api/proxy.go +++ b/api/proxy.go @@ -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"` diff --git a/api/questionnaire.go b/api/questionnaire.go index cc7d3699e..754f10aa3 100644 --- a/api/questionnaire.go +++ b/api/questionnaire.go @@ -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"` diff --git a/api/review.go b/api/review.go index 102cdbdb3..481149a33 100644 --- a/api/review.go +++ b/api/review.go @@ -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"` diff --git a/api/ruleset.go b/api/ruleset.go index fd1d99915..0eff69062 100644 --- a/api/ruleset.go +++ b/api/ruleset.go @@ -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"` @@ -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"` diff --git a/api/stakeholder.go b/api/stakeholder.go index f9f5afdcd..975dc5757 100644 --- a/api/stakeholder.go +++ b/api/stakeholder.go @@ -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"` diff --git a/api/tag.go b/api/tag.go index d2e385450..115cdeb42 100644 --- a/api/tag.go +++ b/api/tag.go @@ -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"` } diff --git a/api/tagcategory.go b/api/tagcategory.go index 4c87cbf3d..75caff13c 100644 --- a/api/tagcategory.go +++ b/api/tagcategory.go @@ -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"` diff --git a/api/target.go b/api/target.go index 4c619ea4f..877200d2a 100644 --- a/api/target.go +++ b/api/target.go @@ -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"` diff --git a/api/taskgroup.go b/api/taskgroup.go index 74cbcad6b..49a123202 100644 --- a/api/taskgroup.go +++ b/api/taskgroup.go @@ -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"` } // diff --git a/api/ticket.go b/api/ticket.go index 0a9e4d0cc..11d284598 100644 --- a/api/ticket.go +++ b/api/ticket.go @@ -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"` diff --git a/api/tracker.go b/api/tracker.go index 4f130de0a..34d475674 100644 --- a/api/tracker.go +++ b/api/tracker.go @@ -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"`