Validating a stringy UUID #3237
-
I'd like to validate strings which hold UUIDs, so e.g.,
Of course the Introducing a hidden helper value with some My actual problem involves the follow structure: import (
"uuid"
"strings"
)
// data, which in the original problem is actually json
records: {
"record-will-have-uuid-x": {
name: "0f72ceb0-b566-4f3e-9bd1-e197c751ad1e.xxx"
}
"record-will-have-uuid": {
name: "0f72ceb0-b566-4f3e-9bd1-1234566666ee.xxx"
}
"record-will-not-have-uuid": {
name: "no-uuid.xxx"
}
}
records: [string]: _record
_record: {
name: string
...
}
// the check cue here:
records: [=~".*will-have-uuid.*"]: _record & {
_uuid: strings.Split(name, ".")
_uuid: uuid.valid
} however the following when evaluating:
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 6 replies
-
You probably want an alias: https://cuelang.org/docs/reference/spec/#aliases In your case I think it would look like this: records: RecordName=[=~".*will-have-uuid.*"]: _record & {
_uuid: strings.Split(RecordName, ".")
_uuid: uuid.valid
} Edit: Or maybe |
Beta Was this translation helpful? Give feedback.
You probably want an alias: https://cuelang.org/docs/reference/spec/#aliases
In your case I think it would look like this:
Edit: Or maybe
[RecordName=~".*will-have-uuid.*"]
.