-
Notifications
You must be signed in to change notification settings - Fork 334
feat: add enum support in marker type #337
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,6 +15,7 @@ package simpleschema | |
|
|
||
| import ( | ||
| "fmt" | ||
| "strings" | ||
|
|
||
| extv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1" | ||
| ) | ||
|
|
@@ -203,6 +204,23 @@ func (tf *transformer) applyMarkers(schema *extv1.JSONSchemaProps, markers []*Ma | |
| schema.Default = &extv1.JSON{Raw: defaultValue} | ||
| case MarkerTypeDescription: | ||
| schema.Description = marker.Value | ||
| case MarkerTypeEnumeration: | ||
| enumValues := strings.Split(marker.Value, ",") | ||
| enumJSON := make([]extv1.JSON, 0, len(enumValues)) | ||
| for _, v := range enumValues { | ||
| v = strings.TrimSpace(v) | ||
| var enumVal []byte | ||
| switch schema.Type { | ||
| case "string": | ||
| enumVal = []byte(fmt.Sprintf("\"%s\"", v)) | ||
| case "integer", "number": | ||
| enumVal = []byte(v) | ||
|
Comment on lines
+214
to
+217
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we perform some validation here? thinking "strconv" to check whether the enumVal is indeed a number of integer |
||
| default: | ||
| enumVal = []byte(v) | ||
|
Comment on lines
+218
to
+219
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure if we should allow non integer/string values for now |
||
| } | ||
| enumJSON = append(enumJSON, extv1.JSON{Raw: enumVal}) | ||
| } | ||
| schema.Enum = enumJSON | ||
| } | ||
| } | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add some unit tests for enums cases in this package?