From 36a16b298cba65555aaa54f5fdc7811bfdb3eb4d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergen=20Yal=C3=A7=C4=B1n?= Date: Tue, 19 Mar 2024 15:26:10 +0300 Subject: [PATCH] Add doc for RequiredFields function MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Sergen Yalçın (cherry picked from commit 845dbf6b1b11cdcc329cea004fc29e2d23c5343b) --- pkg/config/resource.go | 1 + pkg/types/builder.go | 5 +---- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/pkg/config/resource.go b/pkg/config/resource.go index 160ca70f..58bec39b 100644 --- a/pkg/config/resource.go +++ b/pkg/config/resource.go @@ -495,6 +495,7 @@ type Resource struct { requiredFields []string } +// RequiredFields returns slice of the marked as required fieldpaths. func (r *Resource) RequiredFields() []string { return r.requiredFields } diff --git a/pkg/types/builder.go b/pkg/types/builder.go index dfbe1cc3..1afb68d8 100644 --- a/pkg/types/builder.go +++ b/pkg/types/builder.go @@ -380,10 +380,7 @@ func newTopLevelRequiredParam(path string, includeInit bool) *topLevelRequiredPa } func (r *resource) addParameterField(f *Field, field *types.Var) { - requiredBySchema := !f.Schema.Optional - if f.Required { - requiredBySchema = f.Required - } + requiredBySchema := !f.Schema.Optional || f.Required // Note(turkenh): We are collecting the top level required parameters that // are not identifier fields. This is for generating CEL validation rules for // those parameters and not to require them if the management policy is set