Skip to content
This repository has been archived by the owner on Mar 16, 2024. It is now read-only.

Commit

Permalink
Fix schema issues
Browse files Browse the repository at this point in the history
Signed-off-by: Darren Shepherd <darren@acorn.io>
  • Loading branch information
ibuildthecloud committed Nov 14, 2023
1 parent 152f48e commit 7435a4b
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 29 deletions.
5 changes: 2 additions & 3 deletions pkg/apis/internal.acorn.io/v1/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@ type FieldType struct {
}

type Constraint struct {
Op string `json:"op,omitempty"`
Right string `json:"right,omitempty"`
Type *FieldType `json:"type,omitempty"`
Op string `json:"op,omitempty"`
Right string `json:"right,omitempty"`
}

type Object struct {
Expand Down
9 changes: 1 addition & 8 deletions pkg/apis/internal.acorn.io/v1/zz_generated.deepcopy.go

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

35 changes: 24 additions & 11 deletions pkg/appdefinition/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func fromFields(in []value.ObjectSchemaField) (result []v1.Field) {
return
}

func anyToString(v any) string {
func getDefault(v any) string {
var (
ts *value.TypeSchema
)
Expand All @@ -66,9 +66,6 @@ func anyToString(v any) string {
if v == nil {
return ""
}
if s, ok := v.(string); ok {
return s
}
d, _ := json.Marshal(v)
return string(d)
}
Expand Down Expand Up @@ -124,16 +121,22 @@ func fromConstraints(s value.Schema) (result []v1.Constraint) {
for _, item := range in {
result = append(result, v1.Constraint{
Op: item.Op,
Right: anyToString(item.Right),
Type: anyToFieldType(item.Right),
Right: toString(item.Right),
})
}
return
}

func anyToFieldType(v any) *v1.FieldType {
rt, _ := v.(*v1.FieldType)
return rt
func toString(v any) string {
if v == nil {
return ""
}
ts, ok := v.(*value.TypeSchema)
if ok {
v = fromFieldType(ts)
}
s, _ := json.Marshal(v)
return string(s)
}

func fromAlternates(s value.Schema) (out []v1.FieldType) {
Expand All @@ -159,14 +162,24 @@ func fromFieldType(in value.Schema) *v1.FieldType {
if in == nil {
return nil
}
return &v1.FieldType{
result := &v1.FieldType{
Kind: string(in.TargetKind()),
Object: fromObject(in),
Array: fromArray(in),
Constraints: fromConstraints(in),
Default: anyToString(in),
Default: getDefault(in),
Alternates: fromAlternates(in),
}
if result.Default == "" {
for _, alt := range result.Alternates {
if alt.Default != "" {
result.Default = alt.Default
break
}
}
}

return result
}

func fromField(in value.ObjectSchemaField) v1.Field {
Expand Down
7 changes: 0 additions & 7 deletions pkg/openapi/generated/openapi_generated.go

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

0 comments on commit 7435a4b

Please sign in to comment.